summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStalski2011-12-10 20:02:23 (GMT)
committer Stalski2011-12-10 20:02:23 (GMT)
commitbee131088a095e85e0bc179e55139b19991d01bb (patch)
tree7b96c1e82d0f5ae9a0879b2bf8de2e94524164ce
parentfa9afb87dd2fc9c15b93b88129788ae57795b5d1 (diff)
#992766 by osopolar, naught101: Added Allow to change the stream name.
-rwxr-xr-xmodules/heartbeat_ui/heartbeat_ui.module512
-rw-r--r--modules/heartbeat_ui/plugins/export_ui/ctools_export_ui_heartbeat_stream.class.php264
-rw-r--r--modules/heartbeat_ui/plugins/export_ui/ctools_export_ui_heartbeat_template.class.php257
-rwxr-xr-xmodules/heartbeat_ui/plugins/export_ui/heartbeat_streams.export_ui.inc6
-rwxr-xr-xmodules/heartbeat_ui/plugins/export_ui/heartbeat_templates.export_ui.inc8
5 files changed, 522 insertions, 525 deletions
diff --git a/modules/heartbeat_ui/heartbeat_ui.module b/modules/heartbeat_ui/heartbeat_ui.module
index 1c29881..659160a 100755
--- a/modules/heartbeat_ui/heartbeat_ui.module
+++ b/modules/heartbeat_ui/heartbeat_ui.module
@@ -129,514 +129,4 @@ function heartbeat_ui_admin_menu_map() {
*/
function _heartbeat_activity_get_time($time) {
return format_interval($time, 6, $GLOBALS['language']->language);
-}
-
-/**
- * Form for exportable heartbeat message template objects.
- * @param Array $form
- * @param Array $form_state
- */
-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');
-
- // Add extra css.
- $form['#attached']['css'][] = drupal_get_path('module', 'heartbeat_ui') . '/heartbeat_ui.css';
-
- // Required form elements.
- $form['hid'] = array(
- '#type' => 'hidden',
- '#default_value' => empty($template->hid) ? 0 : $template->hid,
- );
- $form['general'] = array(
- '#type' => 'fieldset',
- '#title' => t('Definition'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- '#group' => 'general-tab',
- );
- $form['general']['description'] = array(
- '#type' => 'textarea',
- '#title' => t('Description of the message'),
- '#description' => t('(most of the time you already have an event in mind)'),
- '#cols' => 60,
- '#rows' => 1,
- '#required' => TRUE,
- '#default_value' => empty($template->description) ? '' : t($template->description),
- );
-
- $form['permissions'] = array(
- '#type' => 'fieldset',
- '#title' => t('Access'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- '#group' => 'general-tab',
- );
- $form['permissions']['perms'] = array(
- '#type' => 'select',
- '#title' => t('Message display access'),
- '#description' => t('Defines to whom the message is meant for and who is entitled to see the message.'),
- '#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'),
- '#description' => t('Select the roles to filter activity. Leaving empty means the messages will always be shown.'),
- '#options' => user_roles(),
- '#default_value' => empty($template->roles) ? array() : $template->roles,
- );
-
- // Examples with variables
- $form['examples'] = array(
- '#type' => 'fieldset',
- '#title' => t('Examples'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- '#group' => 'general-tab',
- );
- $form['examples']['tokens']['#type'] = 'markup';
- $form['examples']['tokens']['#markup'] = '<p>'. t('Here are a few examples of usage of variables in heartbeat messages:') .'</p><div>';
- $form['examples']['tokens']['#markup'] .= '<small>'. t('!username has updated !node_title') .' (for a single message)</small><br />';
- $form['examples']['tokens']['#markup'] .= '<small>'. t('!username has added %node_title%') .' (for grouped messages with variable summary)</small><br />';
-
- // Extended example, specific to friendlist
- if (module_exists('friendlist_api')) {
- $form['examples']['tokens']['#markup'] .= '<small>'. t('!user1 is now !relation_type with !user2') .' (use %user2% if user1 becomes friends with lots of users in last timespan)</small><br />';
- }
- $form['examples']['tokens']['#markup'] .= '</div><p>'. t('Always append your variables with ! or embed the word in %\'s to group several instances of one part of a message.') .'</p>';
-
- $form['content'] = array(
- '#type' => 'fieldset',
- '#title' => t('Content'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- '#group' => 'general-tab',
- );
-
- $form['content']['message'] = array(
- '#type' => 'textarea',
- '#title' => t('Single message'),
- '#cols' => 60,
- '#rows' => 1,
- '#default_value' => empty($template->message) ? '' : $template->message,
- '#description' => t('Message is a special field in the Heartbeat Activity entity. The message is a phrase / sentence that contains variables to be replaced at runtime. Such variables should be prefixed with "!", much like the asis placeholders. You could also leave this field empty if you are working the the normal entity field storage.<br />Note that the actor variable of the message should be <strong>!username</strong>.'),
- );
-
- $desc = t('Type of message when it comes to grouping messages together.<br />
- <strong>Single</strong> is when you want to repeat messages without merging them together. These messages
- are standalone and they dont take notice on previous and upcoming messages.<br />
- <strong>Count</strong> means you want to merge the messages together so you know the occurrency.
- Only one message in its single format will be displayed.<br />
- A <strong>summary</strong> is when you want to group the same instance of several messages together.
- For this you will summarize a part of the message and use it as substitional variables (with separators) to
- form the merged messages. The occurrency of the message instance is also known as the count.<br />');
-
- /**
- * The group type of the message. Other form elements will
- * depend on this setting to hide/show.
- */
- $form['content']['group_type'] = array(
- '#id' => 'heartbeat_message_type',
- '#type' => 'select',
- '#title' => t('Type of message'),
- '#description' => $desc,
- '#options' => array(
- 'single' => t('Single: Treat all activity instances as standalone messages'),
- 'count' => t('Count: only add counter variable, merging only identical activity'),
- 'summary' => t('Summary: Merge recurrent activity together')
- ),
- '#required' => TRUE,
- '#default_value' => $template->group_type,
- );
-
- /**
- * Container for the concatenation or group arguments.
- */
- $form['content']['type_summary'] = array(
- '#type' => 'container',
- '#states' => array(
- 'visible' => array(
- ':input[name="group_type"]' => array('value' => 'summary'),
- ),
- ),
- );
- $form['content']['type_summary']['message_concat'] = array(
- '#type' => 'textarea',
- '#title' => t('Message to group instances'),
- '#description' => t('You can use "%" to indicate that a variable word needs to be replaced with multiple instances of another variable (target variable). This is used when messages are merged together.<br />! is still available'),
- '#cols' => 60,
- '#rows' => 2,
- '#default_value' => empty($template->message_concat) ? '' : $template->message_concat,
- // Add Prefix to improve UX.
- '#prefix' => '<div class="heartbeat-conf-indent">',
- );
-
- /**
- * The concatenation arguments.
- */
- $form['content']['type_summary']['concat_args'] = array(
- '#tree' => TRUE,
- '#type' => 'container',
- );
- $group_by = !empty($template->concat_args['group_by']) ? $template->concat_args['group_by'] : 'none';
- $form['content']['type_summary']['concat_args']['group_by'] = array(
- '#type' => 'select',
- '#options' => array(
- 'none' => t('No grouping'),
- 'user' => t('Group by user to summarize nodes'),
- 'node' => t('Group by node to summarize users'),
- 'node-target' => t('Group by target object id to summarize nodes'),
- 'user-user' => t('Group by user to summarize users'),
- ),
- '#title' => t('Group by'),
- '#description' => t('<strong>Required for types summary. </strong>Messages with parts that merge together are grouped by user or node.
- E.g. Group by node if you want to summarize users and vice versa.<br />In some cases where the activity uses a relation
- between two users, then set the group by to "user-user". A good example is a friend-relation.'),
- '#required' => FALSE,
- '#default_value' => $group_by,
- );
- $desc = t('<blockquote>
- Grouped message: !username added %images%.
- Single message: !username added an !image and a nice one.
- Then you will group by user and build a summary of images. The grouping variable here is "image".
- </blockquote>');
- $form['content']['type_summary']['concat_args']['group_target'] = array(
- '#type' => 'textfield',
- '#title' => t('Variable to summarize'),
- '#description' => t('If you used a word between %-signs, you have to fill in the variable you want to summarize.') .'<br /> e.g.:'. $desc,
- '#required' => FALSE,
- '#default_value' => empty($template->concat_args['group_target']) ? '' : $template->concat_args['group_target'],
- );
- // The wrapper for special user-user mapping.
- $form['content']['type_summary']['concat_args']['group_by_target'] = array(
- '#type' => 'textfield',
- '#title' => t('The group by variable.'),
- '#description' => t('This is the variable you want to summarize on. Group by parameter indicates your intensions. Note that it can never be the same as the group variable.'),
- '#required' => FALSE,
- '#default_value' => empty($template->concat_args['group_by_target']) ? '' : $template->concat_args['group_by_target'],
- );
- $form['content']['type_summary']['concat_args']['group_num_max'] = array(
- '#title' => 'Maximum number of messages to group',
- '#type' => 'textfield',
- '#size' => 5,
- '#default_value' => empty($template->concat_args['group_num_max']) ? '' : $template->concat_args['group_num_max'],
- '#description' => 'Maximum number of items that can be grouped to create one summarized message.',
- );
- $form['content']['type_summary']['concat_args']['merge_separator'] = array(
- '#type' => 'textfield',
- '#title' => t('Fill in the target separator'),
- '#description' => t('Separators between the targets, like a colon. E.g. "title1<strong>,</strong> title2 and title3"'),
- '#required' => FALSE,
- '#default_value' => empty($template->concat_args['merge_separator']) ? '' : $template->concat_args['merge_separator'],
- );
- $form['content']['type_summary']['concat_args']['merge_end_separator'] = array(
- '#type' => 'textfield',
- '#title' => t('Fill in the target end separator.'),
- '#description' => t('Separators finishing listed targets. E.g. "title1, title2 <strong>and</strong> title3"'),
- '#required' => FALSE,
- '#default_value' => empty($template->concat_args['merge_end_separator']) ? '' : $template->concat_args['merge_end_separator'],
- // Add Suffix to improve UX only.
- '#suffix' => '</div>',
- );
-
- /**
- * Add container for other saveable data.
- */
- if (module_exists('heartbeat_plugins')) {
- $form['attachments'] = array(
- '#tree' => TRUE,
- '#type' => 'fieldset',
- '#title' => t('Attachments'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- '#group' => 'general-tab'
- );
- }
-}
-
-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, 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'];
-
-}
-
-/**
- * Form for exportable heartbeat message stream objects.
- * @param Array $form
- * @param Array $form_state
- */
-function heartbeat_streams_ui_ctools_export_ui_form(&$form, &$form_state) {
-
- $heartbeatStreamConfig = $form_state['item'];
- _heartbeat_stream_config_unpack($heartbeatStreamConfig);
-
- $cloning = preg_match("/clone_of_/", $heartbeatStreamConfig->class);
-
- $form['path'] = array(
- '#type' => 'hidden',
- '#title' => t('Path'),
- '#default_value' => $heartbeatStreamConfig->path,
- );
- $form['module'] = array(
- '#type' => 'hidden',
- '#title' => t('Module'),
- '#default_value' => $heartbeatStreamConfig->module,
- );
-
- $heartbeatStreamConfig->real_class = empty($heartbeatStreamConfig->real_class) ? $heartbeatStreamConfig->class : $heartbeatStreamConfig->real_class;
- if ($cloning) {
- $heartbeatStreamConfig->real_class = preg_replace("/clone_of_/", "", $heartbeatStreamConfig->class);
- }
- $form['real_class'] = array(
- '#type' => 'hidden',
- '#title' => t('Real class'),
- '#default_value' => $heartbeatStreamConfig->real_class,
- '#description' => t('Real class to load for clones'),
- );
-
- $form['title'] = array(
- '#type' => 'hidden',
- '#title' => t('Title'),
- '#default_value' => t($heartbeatStreamConfig->title),
- '#description' => t('Used in page titles'),
- );
- if ($cloning) {
- $form['title']['#type'] = 'textfield';
- $form['title']['#default_value'] = t('Clone of @title', array('@title' => $heartbeatStreamConfig->title));
- }
-
- $form['settings'] = array(
- '#type' => 'vertical_tabs',
- '#tree' => TRUE,
- '#weight' => 50,
- );
-
- // Permissions, allow/deny message templates.
- $form['settings']['fs_perms'] = array(
- '#type' => 'fieldset',
- '#collapsible' => TRUE,
- '#collapsed' => FALSE,
- '#title' => t('Permissions'),
- );
-
- // Fetch message objects.
- ctools_include('export');
- $options = array();
- foreach (ctools_export_load_object('heartbeat_messages', 'all') as $template) {
- $options[$template->message_id] = $template->description;
- }
- $form['settings']['fs_perms']['messages_denied'] = array(
- '#type' => 'checkboxes',
- '#title' => t('Choose message types you want to deny from display'),
- '#multiple' => TRUE,
- '#default_value' => $heartbeatStreamConfig->messages_denied,
- '#options' => $options,
- );
-
- // Stream settings.
- $form['settings']['fs_settings'] = array(
- '#type' => 'fieldset',
- '#title' => t('Settings'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- );
-
- // Configuration can be simple for some heartbeat requirements and thus exceptions.
- if (in_array($heartbeatStreamConfig->class, array('singleactivity', 'viewsactivity'))) {
-
- $form['settings']['fs_settings']['stream_path'] = array(
- '#type' => 'textfield',
- '#default_value' => '',
- '#title' => t('Path to the page stream'),
- '#disabled' => TRUE,
- );
- $form['settings']['fs_settings']['stream_profile_path'] = array(
- '#type' => 'textfield',
- '#default_value' => '',
- '#title' => t('Path to the user stream'),
- '#disabled' => TRUE,
- );
-
- }
- else {
-
- $form['settings']['fs_settings']['skip_active_user'] = array(
- '#title' => t('Skip the active user'),
- '#type' => 'checkbox',
- '#default_value' => $heartbeatStreamConfig->skip_active_user,
- );
- $form['settings']['fs_settings']['show_message_times'] = array(
- '#title' => t('Show the time of action in message displays'),
- '#type' => 'checkbox',
- '#default_value' => $heartbeatStreamConfig->show_message_times,
- );
- $form['settings']['fs_settings']['show_message_times_grouped'] = array(
- '#title' => t('Show the time of action with messages are grouped together'),
- '#type' => 'checkbox',
- '#default_value' => $heartbeatStreamConfig->show_message_times_grouped,
- );
- $form['settings']['fs_settings']['poll_messages'] = array(
- '#type' => 'select',
- '#options' => array(
- 0 => t('No'),
- 10 => t('Every 10 seconds'),
- 20 => t('Every 20 seconds'),
- 30 => t('Every 30 seconds'),
- 45 => t('Every 45 seconds'),
- 60 => t('Every minute'),
- ),
- '#title' => t('Poll every x seconds for newer messages to prepend the stream.'),
- '#default_value' => $heartbeatStreamConfig->poll_messages,
- );
-
- $form['settings']['fs_settings']['num_load_max'] = array(
- '#title' => t('Fetch a maximum of logged messages '),
- '#type' => 'textfield',
- '#size' => 20,
- '#description' => t('Heartbeat loads a maximum number of activity messages to keep a final number.
- This number has to be bigger than the number of max items in blocks and pages. This is needed because
- streams can have messages that are denied, grouped or inhibited by permission. In
- order to make sure we have enough messages for display and to keep the performance to a high level, this
- odd way is needed.'),
- '#default_value' => $heartbeatStreamConfig->num_load_max,
- );
-
- if (!empty($form_state['values']['settings']['grouping_seconds'])) {
- $value = $form_state['values']['settings']['grouping_seconds'];
- }
- elseif (isset($heartbeatStreamConfig->grouping_seconds)) {
- $value = $heartbeatStreamConfig->grouping_seconds;
- }
- else {
- $value = variable_get('heartbeat_activity_grouping_seconds', 7200);
- }
- $form['settings']['fs_settings']['grouping_seconds'] = array(
- '#title' => t('Maximum gap (in seconds)'),
- '#type' => 'select',
- '#options' => array(300 => t('5 minutes'), 600 => t('10 minutes'), 1200 => t('20 minutes'), 1800 => t('30 minutes'), 3600 => t('1 hour'), 7200 => t('2 hours'), 14400 => t('4 hours'), 86400 => t('24 hours')),
- '#default_value' => $value,
- '#description' => t('Maximum gap for the same activity to be grouped together and before an identical activity can be logged again'),
- );
-
- // Blocks settings.
- $form['settings']['fs_blocks'] = array(
- '#type' => 'fieldset',
- '#title' => t('Blocks'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- );
- $form['settings']['fs_blocks']['has_block'] = array(
- '#title' => t('Enable block'),
- '#type' => 'checkbox',
- '#default_value' => $heartbeatStreamConfig->has_block,
- '#attributes' => array()
- );
- if ($heartbeatStreamConfig->class == 'singleactivity') {
- $form['settings']['fs_blocks']['has_block']['#attributes'] = array('readlonly' => 'readonly');
- }
- $form['settings']['fs_blocks']['block_items_max'] = array(
- '#title' => t('Maximum items in the @name blocks', array('@name' => $heartbeatStreamConfig->name)),
- '#type' => 'textfield',
- '#size' => 20,
- '#default_value' => $heartbeatStreamConfig->block_items_max,
- );
- $options = array(
- 0 => t('No more link'),
- 1 => t('Display "full list" link in block display'),
- 2 => t('Display an ajax-driven older messages link')
- );
- $form['settings']['fs_blocks']['block_show_pager'] = array(
- '#title' => t('Show "older messages" link in block display'),
- '#type' => 'radios',
- '#options' => $options,
- '#default_value' => $heartbeatStreamConfig->block_show_pager,
- );
-
- // Page settings.
- $form['settings']['fs_pages'] = array(
- '#type' => 'fieldset',
- '#title' => t('Pages'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- );
- $form['settings']['fs_pages']['stream_path'] = array(
- '#title' => t('Path to the stream page'),
- '#type' => 'textfield',
- '#default_value' => $heartbeatStreamConfig->stream_path,
- '#description' => t('Leave empty to disable the page.'),
- );
- $form['settings']['fs_pages']['stream_profile_path'] = array(
- '#title' => t('Path to the user profile stream page'),
- '#type' => 'textfield',
- '#default_value' => $heartbeatStreamConfig->stream_profile_path,
- '#description' => t('Leave empty to disable the user page at user/%user/PATH.'),
- );
- $form['settings']['fs_pages']['page_items_max'] = array(
- '#title' => t('Maximum items in the @name pages', array('@name' => $heartbeatStreamConfig->name)),
- '#type' => 'textfield',
- '#size' => 20,
- '#default_value' => $heartbeatStreamConfig->page_items_max,
- );
- $form['settings']['fs_pages']['page_show_pager'] = array(
- '#title' => t('Display "older messages" link in page displays'),
- '#type' => 'checkbox',
- '#default_value' => $heartbeatStreamConfig->page_show_pager,
- );
- $form['settings']['fs_pages']['page_pager_ajax'] = array(
- '#title' => t('Display "older messages" link in page displays with Ajax'),
- '#type' => 'checkbox',
- '#default_value' => $heartbeatStreamConfig->page_pager_ajax,
- );
- }
-
- // Let other contribs save in the variables data.
- $form['variables'] = array(
- '#tree' => TRUE,
- );
-
-}
-
-function heartbeat_streams_ui_ctools_export_ui_form_validate(&$form, &$form_state) {
-
-}
-
-function heartbeat_streams_ui_ctools_export_ui_form_submit(&$form, &$form_state) {
-
- foreach ($form_state['values']['settings'] as $name => $setting) {
- if (is_array($setting)) {
- foreach ($setting as $key => $value) {
- $form_state['values']['settings'][$key] = $value;
- }
- unset($form_state['values']['settings'][$name]);
- }
- }
-
- heartbeat_stream_config_reset();
-
- drupal_set_message(t('Heartbeat streams cache has been cleared and menu is rebuild.'));
-
-}
-
-/**
- * eof().
- */ \ No newline at end of file
+} \ No newline at end of file
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
index 337d5cf..12c2923 100644
--- 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
@@ -9,6 +9,270 @@
class ctools_export_ui_heartbeat_stream extends ctools_export_ui {
/**
+ * Helper function with element for the settings editing form.
+ */
+ function _edit_form(&$form, &$form_state) {
+
+ $heartbeatStreamConfig = $form_state['item'];
+ _heartbeat_stream_config_unpack($heartbeatStreamConfig);
+
+ $cloning = $form_state['form type'] == 'clone';
+
+ $form['path'] = array(
+ '#type' => 'hidden',
+ '#title' => t('Path'),
+ '#default_value' => $heartbeatStreamConfig->path,
+ );
+ $form['module'] = array(
+ '#type' => 'hidden',
+ '#title' => t('Module'),
+ '#default_value' => $heartbeatStreamConfig->module,
+ );
+
+ $heartbeatStreamConfig->real_class = empty($heartbeatStreamConfig->real_class) ? $heartbeatStreamConfig->class : $heartbeatStreamConfig->real_class;
+ if ($cloning) {
+ $heartbeatStreamConfig->real_class = preg_replace("/clone_of_/", "", $heartbeatStreamConfig->class);
+ }
+ $form['real_class'] = array(
+ '#type' => 'hidden',
+ '#title' => t('Real class'),
+ '#default_value' => $heartbeatStreamConfig->real_class,
+ '#description' => t('Real class to load for clones'),
+ );
+
+ $form['title'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Title'),
+ '#default_value' => isset($heartbeatStreamConfig->title) ? $heartbeatStreamConfig->title : '',
+ '#description' => t('Used in page titles'),
+ );
+ if ($cloning) {
+ $form['title']['#default_value'] = t('Clone of @title', array('@title' => $heartbeatStreamConfig->title));
+ }
+
+ $form['settings'] = array(
+ '#type' => 'vertical_tabs',
+ '#tree' => TRUE,
+ '#weight' => 50,
+ );
+
+ // Permissions, allow/deny message templates.
+ $form['settings']['fs_perms'] = array(
+ '#type' => 'fieldset',
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE,
+ '#title' => t('Permissions'),
+ );
+
+ // Fetch message objects.
+ ctools_include('export');
+ $options = array();
+ foreach (ctools_export_load_object('heartbeat_messages', 'all') as $template) {
+ $options[$template->message_id] = $template->description;
+ }
+ $form['settings']['fs_perms']['messages_denied'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('Choose message types you want to deny from display'),
+ '#multiple' => TRUE,
+ '#default_value' => $heartbeatStreamConfig->messages_denied,
+ '#options' => $options,
+ );
+
+ // Stream settings.
+ $form['settings']['fs_settings'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Settings'),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ );
+
+ // Configuration can be simple for some heartbeat requirements and thus exceptions.
+ if (in_array($heartbeatStreamConfig->class, array('singleactivity', 'viewsactivity'))) {
+
+ $form['settings']['fs_settings']['stream_path'] = array(
+ '#type' => 'textfield',
+ '#default_value' => '',
+ '#title' => t('Path to the page stream'),
+ '#disabled' => TRUE,
+ );
+ $form['settings']['fs_settings']['stream_profile_path'] = array(
+ '#type' => 'textfield',
+ '#default_value' => '',
+ '#title' => t('Path to the user stream'),
+ '#disabled' => TRUE,
+ );
+
+ }
+ else {
+
+ $form['settings']['fs_settings']['skip_active_user'] = array(
+ '#title' => t('Skip the active user'),
+ '#type' => 'checkbox',
+ '#default_value' => $heartbeatStreamConfig->skip_active_user,
+ );
+ $form['settings']['fs_settings']['show_message_times'] = array(
+ '#title' => t('Show the time of action in message displays'),
+ '#type' => 'checkbox',
+ '#default_value' => $heartbeatStreamConfig->show_message_times,
+ );
+ $form['settings']['fs_settings']['show_message_times_grouped'] = array(
+ '#title' => t('Show the time of action with messages are grouped together'),
+ '#type' => 'checkbox',
+ '#default_value' => $heartbeatStreamConfig->show_message_times_grouped,
+ );
+ $form['settings']['fs_settings']['poll_messages'] = array(
+ '#type' => 'select',
+ '#options' => array(
+ 0 => t('No'),
+ 10 => t('Every 10 seconds'),
+ 20 => t('Every 20 seconds'),
+ 30 => t('Every 30 seconds'),
+ 45 => t('Every 45 seconds'),
+ 60 => t('Every minute'),
+ ),
+ '#title' => t('Poll every x seconds for newer messages to prepend the stream.'),
+ '#default_value' => $heartbeatStreamConfig->poll_messages,
+ );
+
+ $form['settings']['fs_settings']['num_load_max'] = array(
+ '#title' => t('Fetch a maximum of logged messages '),
+ '#type' => 'textfield',
+ '#size' => 20,
+ '#description' => t('Heartbeat loads a maximum number of activity messages to keep a final number.
+ This number has to be bigger than the number of max items in blocks and pages. This is needed because
+ streams can have messages that are denied, grouped or inhibited by permission. In
+ order to make sure we have enough messages for display and to keep the performance to a high level, this
+ odd way is needed.'),
+ '#default_value' => $heartbeatStreamConfig->num_load_max,
+ );
+
+ if (!empty($form_state['values']['settings']['grouping_seconds'])) {
+ $value = $form_state['values']['settings']['grouping_seconds'];
+ }
+ elseif (isset($heartbeatStreamConfig->grouping_seconds)) {
+ $value = $heartbeatStreamConfig->grouping_seconds;
+ }
+ else {
+ $value = variable_get('heartbeat_activity_grouping_seconds', 7200);
+ }
+ $form['settings']['fs_settings']['grouping_seconds'] = array(
+ '#title' => t('Maximum gap (in seconds)'),
+ '#type' => 'select',
+ '#options' => array(300 => t('5 minutes'), 600 => t('10 minutes'), 1200 => t('20 minutes'), 1800 => t('30 minutes'), 3600 => t('1 hour'), 7200 => t('2 hours'), 14400 => t('4 hours'), 86400 => t('24 hours')),
+ '#default_value' => $value,
+ '#description' => t('Maximum gap for the same activity to be grouped together and before an identical activity can be logged again'),
+ );
+
+ // Blocks settings.
+ $form['settings']['fs_blocks'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Blocks'),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ );
+ $form['settings']['fs_blocks']['has_block'] = array(
+ '#title' => t('Enable block'),
+ '#type' => 'checkbox',
+ '#default_value' => $heartbeatStreamConfig->has_block,
+ '#attributes' => array()
+ );
+ if ($heartbeatStreamConfig->class == 'singleactivity') {
+ $form['settings']['fs_blocks']['has_block']['#attributes'] = array('readlonly' => 'readonly');
+ }
+ $form['settings']['fs_blocks']['block_items_max'] = array(
+ '#title' => t('Maximum items in the @name blocks', array('@name' => $heartbeatStreamConfig->name)),
+ '#type' => 'textfield',
+ '#size' => 20,
+ '#default_value' => $heartbeatStreamConfig->block_items_max,
+ );
+ $options = array(
+ 0 => t('No more link'),
+ 1 => t('Display "full list" link in block display'),
+ 2 => t('Display an ajax-driven older messages link')
+ );
+ $form['settings']['fs_blocks']['block_show_pager'] = array(
+ '#title' => t('Show "older messages" link in block display'),
+ '#type' => 'radios',
+ '#options' => $options,
+ '#default_value' => $heartbeatStreamConfig->block_show_pager,
+ );
+
+ // Page settings.
+ $form['settings']['fs_pages'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Pages'),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ );
+ $form['settings']['fs_pages']['stream_path'] = array(
+ '#title' => t('Path to the stream page'),
+ '#type' => 'textfield',
+ '#default_value' => $heartbeatStreamConfig->stream_path,
+ '#description' => t('Leave empty to disable the page.'),
+ );
+ $form['settings']['fs_pages']['stream_profile_path'] = array(
+ '#title' => t('Path to the user profile stream page'),
+ '#type' => 'textfield',
+ '#default_value' => $heartbeatStreamConfig->stream_profile_path,
+ '#description' => t('Leave empty to disable the user page at user/%user/PATH.'),
+ );
+ $form['settings']['fs_pages']['page_items_max'] = array(
+ '#title' => t('Maximum items in the @name pages', array('@name' => $heartbeatStreamConfig->name)),
+ '#type' => 'textfield',
+ '#size' => 20,
+ '#default_value' => $heartbeatStreamConfig->page_items_max,
+ );
+ $form['settings']['fs_pages']['page_show_pager'] = array(
+ '#title' => t('Display "older messages" link in page displays'),
+ '#type' => 'checkbox',
+ '#default_value' => $heartbeatStreamConfig->page_show_pager,
+ );
+ $form['settings']['fs_pages']['page_pager_ajax'] = array(
+ '#title' => t('Display "older messages" link in page displays with Ajax'),
+ '#type' => 'checkbox',
+ '#default_value' => $heartbeatStreamConfig->page_pager_ajax,
+ );
+ }
+
+ // Let other contribs save in the variables data.
+ $form['variables'] = array(
+ '#tree' => TRUE,
+ );
+ }
+
+ /**
+ * Implements edit_form().
+ */
+ function edit_form(&$form, &$form_state) {
+ parent::edit_form($form, $form_state);
+ $this->_edit_form($form, $form_state);
+ }
+
+ /**
+ * Implements edit_form_submit().
+ */
+ function edit_form_submit(&$form, &$form_state) {
+
+ // First change the values.
+ foreach ($form_state['values']['settings'] as $name => $setting) {
+ if (is_array($setting)) {
+ foreach ($setting as $key => $value) {
+ $form_state['values']['settings'][$key] = $value;
+ }
+ unset($form_state['values']['settings'][$name]);
+ }
+ }
+
+ heartbeat_stream_config_reset();
+
+ // Let CTools prepare the "item" variable as normal.
+ parent::edit_form_submit($form, $form_state);
+
+ drupal_set_message(t('Heartbeat streams cache has been cleared and menu is rebuild.'));
+
+ }
+
+ /**
* Page callback to delete an exportable item.
*/
function delete_page($js, $input, $item) {
diff --git a/modules/heartbeat_ui/plugins/export_ui/ctools_export_ui_heartbeat_template.class.php b/modules/heartbeat_ui/plugins/export_ui/ctools_export_ui_heartbeat_template.class.php
index 0bad008..52c8ab1 100644
--- a/modules/heartbeat_ui/plugins/export_ui/ctools_export_ui_heartbeat_template.class.php
+++ b/modules/heartbeat_ui/plugins/export_ui/ctools_export_ui_heartbeat_template.class.php
@@ -9,6 +9,263 @@
class ctools_export_ui_heartbeat_template extends ctools_export_ui {
/**
+ * Helper function with element for the settings editing form.
+ */
+ function _edit_form(&$form, &$form_state) {
+
+ // 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');
+
+ // Add extra css.
+ $form['#attached']['css'][] = drupal_get_path('module', 'heartbeat_ui') . '/heartbeat_ui.css';
+
+ // Required form elements.
+ $form['hid'] = array(
+ '#type' => 'hidden',
+ '#default_value' => empty($template->hid) ? 0 : $template->hid,
+ );
+ $form['general'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Definition'),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ '#group' => 'general-tab',
+ );
+ $form['general']['description'] = array(
+ '#type' => 'textarea',
+ '#title' => t('Description of the message'),
+ '#description' => t('(most of the time you already have an event in mind)'),
+ '#cols' => 60,
+ '#rows' => 1,
+ '#required' => TRUE,
+ '#default_value' => empty($template->description) ? '' : t($template->description),
+ );
+
+ $form['permissions'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Access'),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ '#group' => 'general-tab',
+ );
+ $form['permissions']['perms'] = array(
+ '#type' => 'select',
+ '#title' => t('Message display access'),
+ '#description' => t('Defines to whom the message is meant for and who is entitled to see the message.'),
+ '#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'),
+ '#description' => t('Select the roles to filter activity. Leaving empty means the messages will always be shown.'),
+ '#options' => user_roles(),
+ '#default_value' => empty($template->roles) ? array() : $template->roles,
+ );
+
+ // Examples with variables
+ $form['examples'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Examples'),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ '#group' => 'general-tab',
+ );
+ $form['examples']['tokens']['#type'] = 'markup';
+ $form['examples']['tokens']['#markup'] = '<p>'. t('Here are a few examples of usage of variables in heartbeat messages:') .'</p><div>';
+ $form['examples']['tokens']['#markup'] .= '<small>'. t('!username has updated !node_title') .' (for a single message)</small><br />';
+ $form['examples']['tokens']['#markup'] .= '<small>'. t('!username has added %node_title%') .' (for grouped messages with variable summary)</small><br />';
+
+ // Extended example, specific to friendlist
+ if (module_exists('friendlist_api')) {
+ $form['examples']['tokens']['#markup'] .= '<small>'. t('!user1 is now !relation_type with !user2') .' (use %user2% if user1 becomes friends with lots of users in last timespan)</small><br />';
+ }
+ $form['examples']['tokens']['#markup'] .= '</div><p>'. t('Always append your variables with ! or embed the word in %\'s to group several instances of one part of a message.') .'</p>';
+
+ $form['content'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Content'),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ '#group' => 'general-tab',
+ );
+
+ $form['content']['message'] = array(
+ '#type' => 'textarea',
+ '#title' => t('Single message'),
+ '#cols' => 60,
+ '#rows' => 1,
+ '#default_value' => empty($template->message) ? '' : $template->message,
+ '#description' => t('Message is a special field in the Heartbeat Activity entity. The message is a phrase / sentence that contains variables to be replaced at runtime. Such variables should be prefixed with "!", much like the asis placeholders. You could also leave this field empty if you are working the the normal entity field storage.<br />Note that the actor variable of the message should be <strong>!username</strong>.'),
+ );
+
+ $desc = t('Type of message when it comes to grouping messages together.<br />
+ <strong>Single</strong> is when you want to repeat messages without merging them together. These messages
+ are standalone and they dont take notice on previous and upcoming messages.<br />
+ <strong>Count</strong> means you want to merge the messages together so you know the occurrency.
+ Only one message in its single format will be displayed.<br />
+ A <strong>summary</strong> is when you want to group the same instance of several messages together.
+ For this you will summarize a part of the message and use it as substitional variables (with separators) to
+ form the merged messages. The occurrency of the message instance is also known as the count.<br />');
+
+ /**
+ * The group type of the message. Other form elements will
+ * depend on this setting to hide/show.
+ */
+ $form['content']['group_type'] = array(
+ '#id' => 'heartbeat_message_type',
+ '#type' => 'select',
+ '#title' => t('Type of message'),
+ '#description' => $desc,
+ '#options' => array(
+ 'single' => t('Single: Treat all activity instances as standalone messages'),
+ 'count' => t('Count: only add counter variable, merging only identical activity'),
+ 'summary' => t('Summary: Merge recurrent activity together')
+ ),
+ '#required' => TRUE,
+ '#default_value' => $template->group_type,
+ );
+
+ /**
+ * Container for the concatenation or group arguments.
+ */
+ $form['content']['type_summary'] = array(
+ '#type' => 'container',
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="group_type"]' => array('value' => 'summary'),
+ ),
+ ),
+ );
+ $form['content']['type_summary']['message_concat'] = array(
+ '#type' => 'textarea',
+ '#title' => t('Message to group instances'),
+ '#description' => t('You can use "%" to indicate that a variable word needs to be replaced with multiple instances of another variable (target variable). This is used when messages are merged together.<br />! is still available'),
+ '#cols' => 60,
+ '#rows' => 2,
+ '#default_value' => empty($template->message_concat) ? '' : $template->message_concat,
+ // Add Prefix to improve UX.
+ '#prefix' => '<div class="heartbeat-conf-indent">',
+ );
+
+ /**
+ * The concatenation arguments.
+ */
+ $form['content']['type_summary']['concat_args'] = array(
+ '#tree' => TRUE,
+ '#type' => 'container',
+ );
+ $group_by = !empty($template->concat_args['group_by']) ? $template->concat_args['group_by'] : 'none';
+ $form['content']['type_summary']['concat_args']['group_by'] = array(
+ '#type' => 'select',
+ '#options' => array(
+ 'none' => t('No grouping'),
+ 'user' => t('Group by user to summarize nodes'),
+ 'node' => t('Group by node to summarize users'),
+ 'node-target' => t('Group by target object id to summarize nodes'),
+ 'user-user' => t('Group by user to summarize users'),
+ ),
+ '#title' => t('Group by'),
+ '#description' => t('<strong>Required for types summary. </strong>Messages with parts that merge together are grouped by user or node.
+ E.g. Group by node if you want to summarize users and vice versa.<br />In some cases where the activity uses a relation
+ between two users, then set the group by to "user-user". A good example is a friend-relation.'),
+ '#required' => FALSE,
+ '#default_value' => $group_by,
+ );
+ $desc = t('<blockquote>
+ Grouped message: !username added %images%.
+ Single message: !username added an !image and a nice one.
+ Then you will group by user and build a summary of images. The grouping variable here is "image".
+ </blockquote>');
+ $form['content']['type_summary']['concat_args']['group_target'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Variable to summarize'),
+ '#description' => t('If you used a word between %-signs, you have to fill in the variable you want to summarize.') .'<br /> e.g.:'. $desc,
+ '#required' => FALSE,
+ '#default_value' => empty($template->concat_args['group_target']) ? '' : $template->concat_args['group_target'],
+ );
+ // The wrapper for special user-user mapping.
+ $form['content']['type_summary']['concat_args']['group_by_target'] = array(
+ '#type' => 'textfield',
+ '#title' => t('The group by variable.'),
+ '#description' => t('This is the variable you want to summarize on. Group by parameter indicates your intensions. Note that it can never be the same as the group variable.'),
+ '#required' => FALSE,
+ '#default_value' => empty($template->concat_args['group_by_target']) ? '' : $template->concat_args['group_by_target'],
+ );
+ $form['content']['type_summary']['concat_args']['group_num_max'] = array(
+ '#title' => 'Maximum number of messages to group',
+ '#type' => 'textfield',
+ '#size' => 5,
+ '#default_value' => empty($template->concat_args['group_num_max']) ? '' : $template->concat_args['group_num_max'],
+ '#description' => 'Maximum number of items that can be grouped to create one summarized message.',
+ );
+ $form['content']['type_summary']['concat_args']['merge_separator'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Fill in the target separator'),
+ '#description' => t('Separators between the targets, like a colon. E.g. "title1<strong>,</strong> title2 and title3"'),
+ '#required' => FALSE,
+ '#default_value' => empty($template->concat_args['merge_separator']) ? '' : $template->concat_args['merge_separator'],
+ );
+ $form['content']['type_summary']['concat_args']['merge_end_separator'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Fill in the target end separator.'),
+ '#description' => t('Separators finishing listed targets. E.g. "title1, title2 <strong>and</strong> title3"'),
+ '#required' => FALSE,
+ '#default_value' => empty($template->concat_args['merge_end_separator']) ? '' : $template->concat_args['merge_end_separator'],
+ // Add Suffix to improve UX only.
+ '#suffix' => '</div>',
+ );
+
+ /**
+ * Add container for other saveable data.
+ */
+ if (module_exists('heartbeat_plugins')) {
+ $form['attachments'] = array(
+ '#tree' => TRUE,
+ '#type' => 'fieldset',
+ '#title' => t('Attachments'),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ '#group' => 'general-tab'
+ );
+ }
+ }
+
+ /**
+ * Implements edit_form().
+ */
+ function edit_form(&$form, &$form_state) {
+ parent::edit_form($form, $form_state);
+ $this->_edit_form($form, $form_state);
+ }
+
+ /**
+ * Implements edit_form_submit().
+ */
+ function edit_form_submit(&$form, &$form_state) {
+
+ // 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'];
+
+ // Let CTools prepare the "item" variable as normal.
+ parent::edit_form_submit($form, $form_state);
+
+ drupal_set_message(t('Heartbeat streams cache has been cleared and menu is rebuild.'));
+
+ }
+
+ /**
* Page callback to delete an exportable item.
*/
function delete_page($js, $input, $item) {
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 de8f613..8b99118 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
@@ -22,12 +22,6 @@ $plugin = array(
'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',
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 e61438f..bdde014 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
@@ -21,14 +21,6 @@ $plugin = array(
'title plural' => t('Heartbeat templates'),
'title plural proper' => t('Heartbeat templates'),
- // $form_state['values'] to $form_state['item'].
- // All callbacks will accept &$form and &$form_state as arguments.
- 'form' => array(
- 'settings' => 'heartbeat_ui_ctools_export_ui_form',
- 'validate' => 'heartbeat_ui_ctools_export_ui_form_validate',
- 'submit' => 'heartbeat_ui_ctools_export_ui_form_submit',
- ),
-
'handler' => array(
'class' => 'ctools_export_ui_heartbeat_template',
'parent' => 'ctools_export_ui',