summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xheartbeat.module36
-rwxr-xr-xheartbeat.pages.inc17
-rwxr-xr-xheartbeat.streams.inc44
-rwxr-xr-xmodules/heartbeat_example/heartbeat_example.module16
-rwxr-xr-xmodules/heartbeat_ui/heartbeat_ui.module23
-rw-r--r--modules/heartbeat_ui/plugins/export_ui/ctools_export_ui_heartbeat_stream.class.php42
-rwxr-xr-xmodules/heartbeat_ui/plugins/export_ui/heartbeat_streams.export_ui.inc9
-rwxr-xr-xmodules/heartbeat_ui/plugins/export_ui/heartbeat_templates.export_ui.inc6
8 files changed, 142 insertions, 51 deletions
diff --git a/heartbeat.module b/heartbeat.module
index 361a7ef..e226f39 100755
--- a/heartbeat.module
+++ b/heartbeat.module
@@ -125,7 +125,7 @@ function heartbeat_menu() {
$items = array();
// Menu page callbacks for each heartbeat stream.
- $streams = heartbeat_stream_config_load_all();
+ $streams = heartbeat_stream_config_load_all(TRUE);
foreach ($streams as $class => $stream) {
if ($stream->page_disabled == TRUE) {
continue;
@@ -135,7 +135,7 @@ function heartbeat_menu() {
'description' => $stream->name . ' page',
'page callback' => 'heartbeat_messages_page',
'page arguments' => array(1),
- 'access callback' => '_heartbeat_stream_has_access',
+ 'access callback' => 'heartbeat_stream_has_access',
'access arguments' => array(1),
'file' => 'heartbeat.pages.inc',
);
@@ -145,7 +145,7 @@ function heartbeat_menu() {
'title' => $stream->title,
'page callback' => 'heartbeat_messages_page',
'page arguments' => array($stream->class, '0', 1),
- 'access callback' => '_heartbeat_stream_has_access',
+ 'access callback' => 'heartbeat_stream_has_access',
'access arguments' => array($stream->class),
'type' => MENU_LOCAL_TASK,
'file' => 'heartbeat.pages.inc',
@@ -957,6 +957,7 @@ function heartbeat_message_template_delete(HeartbeatMessageTemplate $template) {
/**
* Function to load heartbeat message templates.
+ *
* @param $id Int/String The target value to delete on
* @param $type String The key field to perform delete query on
* message : default
@@ -1129,7 +1130,7 @@ abstract class HeartbeatCtoolsObject {
/**
- * Theme functions and their helpers.
+ * Theme functions and helpers.
*/
/**
@@ -1177,15 +1178,30 @@ function theme_heartbeat_list($variables) {
global $user, $language;
$content = '';
- $content .= '<div id="heartbeat-stream-' . $heartbeatStream->config->class . '" class="heartbeat-' . ($heartbeatStream->isPage() ? 'page' : 'block') . ' heartbeat-stream heartbeat-stream-' . $heartbeatStream->config->class . '">';
- $content .= '<div class="heartbeat-messages-wrapper">';
- if (empty($heartbeatStream->messages)) {
- $content .= '<p><em>' . t('No activity yet.') . '</em></p>';
+ if (!isset($heartbeatStream->config) || empty($heartbeatStream->config->class)) {
+
+ $content .= drupal_render($variables['content']);
+
}
else {
- $content .= drupal_render($variables['content']);
+
+ $content .= '<div id="heartbeat-stream-' . $heartbeatStream->config->class . '" class="heartbeat-' . ($heartbeatStream->isPage() ? 'page' : 'block') . ' heartbeat-stream heartbeat-stream-' . $heartbeatStream->config->class . '">';
+ $content .= '<div class="heartbeat-messages-wrapper">';
+
+ if (empty($heartbeatStream->messages)) {
+
+ $content .= '<p><em>' . t('No activity yet.') . '</em></p>';
+
+ }
+ else {
+
+ $content .= drupal_render($variables['content']);
+
+ }
+
+ $content .= '</div></div>';
+
}
- $content .= '</div></div>';
return $content;
}
diff --git a/heartbeat.pages.inc b/heartbeat.pages.inc
index faf62e4..fda79dd 100755
--- a/heartbeat.pages.inc
+++ b/heartbeat.pages.inc
@@ -8,10 +8,15 @@
/**
* Page callback function to load an activity stream page
*
- * @param array $access_type
- * @return string Themed list of messages
+ * @param String $stream_name
+ * Stream class name.
+ * @param Integer $offset_time
+ * The Offset timestamp to fetch activity.
+ * @param stdClass $account
+ * Optional user account object. If none given, global user will be used
+ * as "viewer" of the stream.
*/
-function heartbeat_messages_page($access_type, $offset_time = 0, $account = NULL) {
+function heartbeat_messages_page($stream_name, $offset_time = 0, $account = NULL) {
// Messages have to loaded by ajax if the url contains an offset
// variable AND a post variable ajax is defined.
@@ -20,7 +25,7 @@ function heartbeat_messages_page($access_type, $offset_time = 0, $account = NULL
// For block updates by ajax displayed on the user
// profile page, we want to show the account requested.
- if (!$page && is_numeric($account) && $account > 0 && variable_get('heartbeat_show_user_profile_messages_' . $access_type, 0)) {
+ if (!$page && is_numeric($account) && $account > 0 && variable_get('heartbeat_show_user_profile_messages_' . $stream_name, 0)) {
$account = user_load($account);
}
// For blocks calling this page in general.
@@ -28,7 +33,7 @@ function heartbeat_messages_page($access_type, $offset_time = 0, $account = NULL
$account = user_load(arg(1));
}
- if ($heartbeatStream = heartbeat_stream($access_type, $page, $account)) {
+ if ($heartbeatStream = heartbeat_stream($stream_name, $page, $account)) {
// Changes at runtime.
$heartbeatStream->setOffsetTime($offset_time);
@@ -47,7 +52,7 @@ function heartbeat_messages_page($access_type, $offset_time = 0, $account = NULL
$build = heartbeat_stream_view($heartbeatStream);
}
else {
- $build = t('You are not allowed to see this activity stream.');
+ $build = t('You don\'t have access to this stream.');
}
// Ajax calls may directly render the content. No extra wrapping needed.
diff --git a/heartbeat.streams.inc b/heartbeat.streams.inc
index f1d147b..640ca4b 100755
--- a/heartbeat.streams.inc
+++ b/heartbeat.streams.inc
@@ -172,7 +172,7 @@ function heartbeat_stream_config_load($class) {
}
/**
- * Implmentation of the Ctools load function.
+ * Implements Ctools load function.
*/
function _heartbeat_stream_config_load($name) {
@@ -184,6 +184,22 @@ function _heartbeat_stream_config_load($name) {
}
/**
+ * Helper function to reset cached streams and attached menu entries.
+ */
+function heartbeat_stream_config_reset($streamConfig = NULL) {
+
+ // Clear the heartbeat stream cache.
+ cache_clear_all('heartbeat_streams', 'cache');
+ drupal_static_reset('heartbeat_streams');
+
+ // This is the only way we can let the menu system know that the
+ // menu needs to be rebuild. Just calling menu_rebuild here is too
+ // soon and would result in not clearing the menu later on.
+ variable_set('menu_rebuild_needed', TRUE);
+
+}
+
+/**
* Helper function to unpack the settings into the root of the object.
*/
function _heartbeat_stream_config_unpack(HeartbeatStreamConfig & $streamConfig) {
@@ -195,20 +211,24 @@ function _heartbeat_stream_config_unpack(HeartbeatStreamConfig & $streamConfig)
}
/**
- * Helper function to check access on activity stream
+ * Helper function to check access on activity stream by name.
+ *
+ * @param String $stream
+ * The ClassName of the stream.
*/
-function _heartbeat_stream_has_access($stream) {
-
- if (is_string($stream)) {
- ctools_include('export');
- $streamConfig = ctools_export_crud_load('heartbeat_streams', $stream);
- }
- else {
- $streamConfig = $stream;
- }
+function heartbeat_stream_has_access($stream) {
+ $streamConfig = heartbeat_stream_config_load($stream);
+ return _heartbeat_stream_has_access($streamConfig);
+}
+/**
+ * Helper function to check access on activity stream.
+ *
+ * @param HeartbeatStreamConfig $streamConfig
+ * A Heartbeat stream configuration object.
+ */
+function _heartbeat_stream_has_access(HeartbeatStreamConfig $streamConfig) {
return user_access('view heartbeat messages') && user_access('view ' . $streamConfig->name . ' stream');
-
}
/**
diff --git a/modules/heartbeat_example/heartbeat_example.module b/modules/heartbeat_example/heartbeat_example.module
index 1e1b914..fe4e69d 100755
--- a/modules/heartbeat_example/heartbeat_example.module
+++ b/modules/heartbeat_example/heartbeat_example.module
@@ -15,10 +15,10 @@
*/
function heartbeat_example_node_insert($node) {
heartbeat_api_log('heartbeat_add_node', $node->uid, 0, $node->nid, 0, array(
- '@node_title' => l($node->title, 'node/'. $node->nid),
- '@username'=> l(user_load($node->uid)->name, 'user/'. $node->uid),
- '@node_type' => $node->type,
- '@types' => $node->type .'s'
+ '!node_title' => l($node->title, 'node/'. $node->nid),
+ '!username'=> l(user_load($node->uid)->name, 'user/'. $node->uid),
+ '!node_type' => $node->type,
+ '!types' => $node->type .'s'
), HEARTBEAT_PUBLIC_TO_ALL, $node->created);
}
@@ -29,10 +29,10 @@ function heartbeat_example_node_insert($node) {
*/
function heartbeat_example_node_update($node) {
heartbeat_api_log('heartbeat_edit_node', $node->uid, 0, $node->nid, 0, array(
- '@node_title' => l($node->title, 'node/'. $node->nid),
- '@username'=> l(user_load($node->uid)->name, 'user/'. $node->uid),
- '@node_type' => $node->type,
- '@types' => $node->type .'s'
+ '!node_title' => l($node->title, 'node/'. $node->nid),
+ '!username'=> l(user_load($node->uid)->name, 'user/'. $node->uid),
+ '!node_type' => $node->type,
+ '!types' => $node->type .'s'
), HEARTBEAT_PUBLIC_TO_ALL);
} \ No newline at end of file
diff --git a/modules/heartbeat_ui/heartbeat_ui.module b/modules/heartbeat_ui/heartbeat_ui.module
index 5a7753a..964949c 100755
--- a/modules/heartbeat_ui/heartbeat_ui.module
+++ b/modules/heartbeat_ui/heartbeat_ui.module
@@ -140,6 +140,9 @@ function heartbeat_ui_ctools_export_ui_form(&$form, &$form_state) {
// '#theme' => 'heartbeat_template_form'
+ // The template object is filled by ctools export. This means that
+ // we don't have an complete object like Heartbeat expects it.
+ // E.g. concat_arg[roles] which are stored and filtered by setRoles().
$template = $form_state['item'];
$form['general-tab'] = array('#type' => 'vertical_tabs');
@@ -176,12 +179,6 @@ function heartbeat_ui_ctools_export_ui_form(&$form, &$form_state) {
'#collapsed' => TRUE,
'#group' => 'general-tab',
);
- $form['permissions']['disabled'] = array(
- '#type' => 'checkbox',
- '#title' => t('Disable the message'),
- '#description' => t('Defines whether this message template is disabled from logging and viewing.'),
- '#default_value' => empty($template->disabled) ? 0 : $template->disabled,
- );
$form['permissions']['perms'] = array(
'#type' => 'select',
'#title' => t('Message display access'),
@@ -189,6 +186,11 @@ function heartbeat_ui_ctools_export_ui_form(&$form, &$form_state) {
'#options' => _heartbeat_perms_options(),
'#default_value' => !isset($template->perms) ? HEARTBEAT_PUBLIC_TO_ALL : $template->perms,
);
+
+ if (!empty($template->concat_args['roles'])) {
+ $template->setRoles($template->concat_args['roles']);
+ }
+
$form['permissions']['roles'] = array(
'#type' => 'checkboxes',
'#title' => t('Limit this message with roles'),
@@ -372,9 +374,10 @@ function heartbeat_ui_ctools_export_ui_form_validate(&$form, &$form_state) {
function heartbeat_ui_ctools_export_ui_form_submit(&$form, &$form_state) {
- // Reformat the variables and attachments section.
+ // Reformat the variables, attachments and concat args to fit the storage.
$form_state['values']['variables'] = HeartbeatMessageTemplate::getVariablesFromMessage($form_state['values']['message'], $form_state['values']['message_concat']);
$form_state['values']['attachments'] = empty($form_state['values']['attachments']) ? array() : $form_state['values']['attachments'];
+ $form_state['values']['concat_args']['roles'] = $form_state['values']['roles'];
}
@@ -622,11 +625,7 @@ function heartbeat_streams_ui_ctools_export_ui_form_submit(&$form, &$form_state)
}
}
- cache_clear_all('heartbeat_streams', 'cache');
- drupal_static_reset('heartbeat_streams');
-
- // Rebuild the menu.
- menu_rebuild();
+ heartbeat_stream_config_reset();
drupal_set_message(t('Heartbeat streams cache has been cleared and menu is rebuild.'));
diff --git a/modules/heartbeat_ui/plugins/export_ui/ctools_export_ui_heartbeat_stream.class.php b/modules/heartbeat_ui/plugins/export_ui/ctools_export_ui_heartbeat_stream.class.php
new file mode 100644
index 0000000..00924cf
--- /dev/null
+++ b/modules/heartbeat_ui/plugins/export_ui/ctools_export_ui_heartbeat_stream.class.php
@@ -0,0 +1,42 @@
+<?php
+
+/**
+ * @file
+ * Ctools export UI for a heartbeat stream.
+ * @author stalski
+ *
+ */
+class ctools_export_ui_heartbeat_stream extends ctools_export_ui {
+
+ /**
+ * Page callback to delete an exportable item.
+ */
+ function delete_page($js, $input, $item) {
+
+ $form_state = array(
+ 'plugin' => $this->plugin,
+ 'object' => &$this,
+ 'ajax' => $js,
+ 'item' => $item,
+ 'op' => $item->export_type & EXPORT_IN_CODE ? 'revert' : 'delete',
+ 'rerender' => TRUE,
+ 'no_redirect' => TRUE,
+ );
+
+ $output = drupal_build_form('ctools_export_ui_delete_confirm_form', $form_state);
+
+ if (!empty($form_state['executed'])) {
+ ctools_export_crud_delete($this->plugin['schema'], $item);
+ $export_key = $this->plugin['export']['key'];
+ $message = str_replace('%title', check_plain($item->{$export_key}), $this->plugin['strings']['confirmation'][$form_state['op']]['success']);
+ drupal_set_message($message);
+
+ heartbeat_stream_config_reset($item);
+
+ drupal_goto(ctools_export_ui_plugin_base_path($this->plugin));
+ }
+
+ return $output;
+ }
+
+} \ No newline at end of file
diff --git a/modules/heartbeat_ui/plugins/export_ui/heartbeat_streams.export_ui.inc b/modules/heartbeat_ui/plugins/export_ui/heartbeat_streams.export_ui.inc
index f4451c7..de8f613 100755
--- a/modules/heartbeat_ui/plugins/export_ui/heartbeat_streams.export_ui.inc
+++ b/modules/heartbeat_ui/plugins/export_ui/heartbeat_streams.export_ui.inc
@@ -9,20 +9,29 @@ $plugin = array(
'schema' => 'heartbeat_streams',
'access' => 'admin heartbeat streams',
+
'menu' => array(
'menu prefix' => 'admin/structure/heartbeat', // default
'menu item' => 'streams', // default
'menu title' => 'Heartbeat streams',
'menu description' => 'Administer heartbeat streams.',
),
+
'title singular' => t('Heartbeat stream'),
'title singular proper' => t('Heartbeat stream'),
'title plural' => t('Heartbeat streams'),
'title plural proper' => t('Heartbeat streams'),
+
'form' => array(
'settings' => 'heartbeat_streams_ui_ctools_export_ui_form',
'validate' => 'heartbeat_streams_ui_ctools_export_ui_form_validate',
'submit' => 'heartbeat_streams_ui_ctools_export_ui_form_submit',
),
+ // A handler to override some methods for advanced UI.
+ 'handler' => array(
+ 'class' => 'ctools_export_ui_heartbeat_stream',
+ 'parent' => 'ctools_export_ui',
+ ),
+
);
diff --git a/modules/heartbeat_ui/plugins/export_ui/heartbeat_templates.export_ui.inc b/modules/heartbeat_ui/plugins/export_ui/heartbeat_templates.export_ui.inc
index 4f8c572..32e899a 100755
--- a/modules/heartbeat_ui/plugins/export_ui/heartbeat_templates.export_ui.inc
+++ b/modules/heartbeat_ui/plugins/export_ui/heartbeat_templates.export_ui.inc
@@ -31,8 +31,8 @@ $plugin = array(
),
'handler' => array(
- 'class' => 'ctools_export_ui_heartbeat_template',
- 'parent' => 'ctools_export_ui',
- ),
+ 'class' => 'ctools_export_ui_heartbeat_template',
+ 'parent' => 'ctools_export_ui',
+ ),
);