' . t('About') . ''; return $output; case 'admin/structure/heartbeat': return '
' . t('Heartbeat activity lets you create streams, composed together with message templates that are parsed into activity messages.') . '
'; } } /** * Implements hook_init(). */ function heartbeat_init() { drupal_add_js(array('heartbeat_language' => $GLOBALS['language']->language), "setting"); } /** * Implements hook_cron(). * Delete too old message if this option is set and logs where * the node does not exist anymore. */ function heartbeat_cron() { $uaids = array(); $cron_delete_time = variable_get('heartbeat_activity_log_cron_delete', 2678400); $keep_latest_number = variable_get('heartbeat_activity_records_per_user', 10); $microseconds = microtime(); // Delete activity older than the expiration date, while // keeping the latest X for each user. if ($cron_delete_time) { $expire = $_SERVER['REQUEST_TIME'] - $cron_delete_time; // Activity Ids that can not be removed (latest activity per user) $keep_uaids = array(0 => 0); // Calculate the latest activity for each user. $result = db_query("SELECT t1.uid, t1.uaid as 'uaid', COUNT(*) as 'rows_per_user', t1.timestamp as 'real_date', MIN(t2.timestamp) as 'oldest_date', count(t2.uid) AS 'count' FROM {heartbeat_activity} AS t1 INNER JOIN {heartbeat_activity} AS t2 ON t1.uid = t2.uid AND t2.timestamp >= t1.timestamp WHERE (t1.timestamp, t1.uaid) < (t2.timestamp, t2.uaid) GROUP BY t1.uid, t1.uaid HAVING COUNT(t2.uid) <= :latest ORDER BY t1.uid, t1.uaid, t1.timestamp DESC", array(':latest' => $keep_latest_number)); // $users = db_query("SELECT uid FROM {users} WHERE status = 1"); // $query = array(); // $args = array(); // foreach ($users as $key => $account) { // $query[] = " ( SELECT uid, uaid FROM {heartbeat_activity} WHERE uid = :uid_$key ORDER BY uaid DESC LIMIT 0, :latest ) "; // $args[':uid_' . $key] = $account->uid; // $args[':latest'] = (int) $keep_latest_number; // } // // $result = db_query(implode("UNION", $query), $args); foreach ($result as $row) { $keep_uaids[$row->uaid] = $row->uaid; } //$arguments = array_merge(array($expire), $keep_uaids); $delete_result = db_query("SELECT uaid FROM {heartbeat_activity} WHERE timestamp < :expire AND uaid NOT IN (:uaids) ", array(':expire' => $expire, ':uaids' => $keep_uaids)); foreach ($delete_result as $row) { $uaids[] = $row->uaid; } } if (!empty($uaids)) { heartbeat_activity_delete($uaids); } $microseconds_final = microtime(); watchdog('cron', 'Cron finished in %secs seconds', array('%secs' => $microseconds_final - $microseconds)); } /** * Implements hook_menu(). */ function heartbeat_menu() { $items = array(); // Menu page callbacks for each heartbeat stream. $streams = heartbeat_stream_config_load_all(TRUE); foreach ($streams as $class => $stream) { if (!empty($stream->stream_path)) { $items[$stream->stream_path] = array( 'title' => $stream->title, 'description' => $stream->name . ' page', 'page callback' => 'heartbeat_messages_page', 'page arguments' => array($stream->class), 'access callback' => 'heartbeat_stream_has_access', 'access arguments' => array($stream->class), 'file' => 'heartbeat.pages.inc', 'type' => MENU_CALLBACK, ); } if (!empty($stream->stream_profile_path)) { $items['user/%user/' . $stream->stream_profile_path] = array( 'title' => $stream->title, 'page callback' => 'heartbeat_messages_page', 'page arguments' => array($stream->class, '0', 1), 'access callback' => 'heartbeat_stream_has_access', 'access arguments' => array($stream->class), 'type' => MENU_LOCAL_TASK, 'file' => 'heartbeat.pages.inc', 'weight' => 50, ); } } // Display one activity entity. $items['heartbeat/message/%heartbeat_activity'] = array( 'title' => 'Single message', 'description' => 'Activity message', 'page callback' => 'heartbeat_message_activity', 'page arguments' => array(2), 'access callback' => '_heartbeat_message_has_access', 'access arguments' => array(2), 'file' => 'heartbeat.pages.inc', ); // Ajax driven callback to delete activity $items['heartbeat/%ctools_js/activity/delete/%heartbeat_activity'] = array( 'title' => 'Delete activity', 'page callback' => 'heartbeat_activity_modal_delete', 'page arguments' => array(1, 4), 'access callback' => '_heartbeat_message_delete_access', 'access arguments' => array(4), 'file' => 'heartbeat.pages.inc', 'type' => MENU_CALLBACK, ); $items['heartbeat/js/poll'] = array( 'page callback' => 'heartbeat_activity_poll', 'access callback' => 'user_access', 'access arguments' => array('view heartbeat messages'), 'type' => MENU_CALLBACK, 'file' => 'heartbeat.pages.inc', ); $items['heartbeat/js/older'] = array( 'page callback' => 'heartbeat_activity_older', 'access callback' => 'user_access', 'access arguments' => array('view heartbeat messages'), 'type' => MENU_CALLBACK, 'file' => 'heartbeat.pages.inc', ); return $items; } /** * Implements hook_permission(). */ function heartbeat_permission() { $permissions = array( 'admin heartbeat templates' => array( 'title' => t('Administer heartbeat templates'), 'description' => t('Manage the heartbeat templates.') ), 'admin heartbeat delete all' => array( 'title' => t('Delete all activity'), 'description' => t('Master permission to delete all activity.') ), 'admin heartbeat delete own' => array( 'title' => t('Delete own activity'), 'description' => t('Permission for the actor to delete own activity.') ), 'view heartbeat messages' => array( 'title' => t('View activity'), 'description' => t('Global permission to view heartbeat activity.') ), 'access heartbeat activity profiles' => array( 'title' => t('Access heartbeat activity profiles'), 'description' => t('Permission to see user profiles or links to the user profile.') ), ); foreach (heartbeat_stream_config_load_all() as $streamConfig) { $permissions['view ' . $streamConfig->name . ' stream'] = array( 'title' => t('View activity in ' . $streamConfig->name), 'description' => t('Stream access: ' . $streamConfig->name . '.') ); } return $permissions; } /** * Implements hook_theme(). */ function heartbeat_theme() { return array( 'heartbeat_activity' => array( 'render element' => 'elements', 'template' => 'heartbeat-activity' ), 'heartbeat_activity_avatar' => array( 'variables' => array('heartbeatactivity' => NULL, 'uri' => NULL), ), 'activity_pager' => array( 'variables' => array('stream' => NULL), ), 'heartbeat_list' => array( 'variables' => array('stream' => NULL, 'content' => NULL), ), 'heartbeat_buttons' => array( 'variables' => array('message' => NULL), ), 'heartbeat_time_ago' => array( 'variables' => array('message' => NULL), ), 'heartbeat_message_user_select_form' => array( 'render element' => 'form', ), ); } /** * Implements hook_block_info(). */ function heartbeat_block_info() { $blocks = array(); $streams = heartbeat_stream_config_load_all(TRUE); // A block for each stream. foreach ($streams as $key => $stream_config) { if ($stream_config->has_block) { $blocks[$stream_config->class]['info'] = drupal_ucfirst($stream_config->title); } } // Heartbeat most active users. $blocks['heartbeat_active_users']['info'] = t('Heartbeat most active users'); return $blocks; } /** * Implements hook_block_view(). */ function heartbeat_block_view($delta = '') { if ($delta == 'heartbeat_active_users') { $block['subject'] = t('Most active users');; $block['content'] = drupal_render(heartbeat_api_most_active_users(variable_get('heartbeat_active_users', 'default'))); return $block; } // For blocks calling this page in general. $account = NULL; if ($uid = heartbeat_context_uid($delta)) { $account = user_load($uid); } if ($heartbeatStream = heartbeat_stream($delta, FALSE, $account)) { heartbeat_stream_build($heartbeatStream); $block_content = heartbeat_stream_view($heartbeatStream); if (!empty($block_content)) { $content = array(); $content['#theme'] = 'heartbeat_list'; $content['#stream'] = $heartbeatStream; $content['#content'] = $block_content; $block['content'] = $content; } $block['subject'] = t($heartbeatStream->config->title); } else { $block['subject'] = ''; $block['content'] = t('You are not allowed to see this activity stream.'); return $block; } $link = ''; if ($heartbeatStream->hasMoreMessages(FALSE)) { $last_message = end($heartbeatStream->messages); $link = heartbeat_stream_more_link($heartbeatStream, $last_message->timestamp); } return $block; } /** * Implements hook_block_configure(). */ function heartbeat_block_configure($delta = '') { if ($delta == 'heartbeat_active_users') { $info = entity_get_info('user'); $options = array('default' => t('default')) + drupal_map_assoc(array_keys($info['view modes'])); $form = array('view_mode' => array( '#type' => 'select', '#title' => t('Select view mode to render the users.'), '#default_value' => variable_get('heartbeat_active_users', 'default'), '#options' => $options, )); } else { $stream = heartbeat_stream_config_load($delta); $form = array('items' => array( '#type' => 'checkbox', '#title' => t('Show activity for the displayed user on the user profile page'), '#description' => t('By default heartbeat will show activity in relation to the currently logged in user. With this setting enabled and only on the user profile page, the messages will be shown in relation to the user profile.'), '#default_value' => variable_get('heartbeat_show_user_profile_messages_' . drupal_strtolower($stream->class), 0), )); } return $form; } /** * Implements hook_block_save(). */ function heartbeat_block_save($delta = '', $edit = array()) { if ($delta == 'heartbeat_active_users') { variable_set('heartbeat_active_users', (isset($edit['view_mode']) ? $edit['view_mode'] : 'default')); return; } $stream = heartbeat_stream_config_load($delta); variable_set('heartbeat_show_user_profile_messages_' . drupal_strtolower($stream->class), $edit['items']); } /** * Implements hook_node_delete(). */ function heartbeat_node_delete($node) { // Delete messages from deleted nodes. $query = db_select('heartbeat_activity', 'ha'); $query->addField('ha', 'uaid'); $query->condition('nid', $node->nid); foreach ($query->execute() as $row_object) { $uaids[] = $row_object->uaid; } if (!empty($uaids)) { heartbeat_activity_delete($uaids); } } /** * Implements hook_form_FORM_ID_alter(). */ function heartbeat_form_user_profile_form_alter(&$form, &$form_state) { if ($form['#user_category'] == 'account') { $profile_templates = variable_get('heartbeat_profile_message_templates', array()); if (count($profile_templates)) { $form_state['heartbeat_templates'] = array(); foreach (heartbeat_templates_names() as $id => $description) if (isset($profile_templates[$id])) { $form_state['heartbeat_templates'][$id] = $description; } heartbeat_user_templates($form, $form_state); } return $form; } } /** * Add the heartbeat template field to the user edit form. */ function heartbeat_user_templates(&$form, &$form_state) { $account = $form['#user']; $form['heartbeat'] = array( '#type' => 'fieldset', '#title' => t('Activity settings'), '#weight' => 7, '#collapsible' => TRUE, ); $form['heartbeat']['templates'] = array('#tree' => TRUE); $templates = heartbeat_user_templates_load($account->uid); foreach ($form_state['heartbeat_templates'] as $template_id => $description) { $template = heartbeat_message_template_load($template_id); $form['heartbeat']['templates'][$template_id] = array( '#type' => 'select', '#title' => $description, '#default_value' => isset($templates[$template_id]) ? $templates[$template_id]->status : HEARTBEAT_PUBLIC_TO_ALL, '#options' => _heartbeat_perms_options(TRUE, $template->perms), ); } $form['#submit'][] = 'heartbeat_user_templates_submit'; } /** * Submit handler to save a users profile templates. */ function heartbeat_user_templates_submit($form, $form_state) { // Message templates for user will have the options: // HEARTBEAT_NONE, HEARTBEAT_PRIVATE, HEARTBEAT_PUBLIC_TO_ALL, HEARTBEAT_PUBLIC_TO_CONNECTED. db_delete('heartbeat_user_templates') ->condition('uid', $form['#user']->uid) ->execute(); foreach ($form_state['values']['templates'] as $template_id => $permission) { db_insert('heartbeat_user_templates') ->fields(array('uid', 'message_id', 'status'), array($form['#user']->uid, $template_id, $permission)) ->execute(); } } /** * Helper function to load heartbeat user template settings. */ function heartbeat_user_templates_load($uid) { $result = db_query("SELECT message_id, status FROM {heartbeat_user_templates} WHERE uid = :uid ", array(':uid' => $uid)); $templates = array(); foreach ($result as $row) { $templates[$row->message_id] = $row; } return $templates; } /** * Implements hook_ctools_plugin_api(). */ function heartbeat_ctools_plugin_api($owner, $api) { if ($owner == 'heartbeat' && $api == 'heartbeat') { return array('version' => 1); } } /** * Implementation of hook_views_api(). */ function heartbeat_views_api() { return array( 'api' => 3, 'path' => drupal_get_path('module', 'heartbeat'), ); } /** * heartbeat_activity_view(). * * @param String $message * The activity message object. */ function heartbeat_activity_view($message, $view_mode = NULL) { if (isset($view_mode)) { $message->view_mode = $view_mode; } // Remove previously built content, if exists. $message->content = array(); // Build fields content. field_attach_prepare_view('heartbeat_activity', array($message->uaid => $message), $message->view_mode, $message->language); entity_prepare_view('heartbeat_activity', array($message->uaid => $message), $message->language); $build = array( '#theme' => 'heartbeat_activity', '#message' => $message, '#view_mode' => $message->view_mode, '#language' => $message->language, ); $build += field_attach_view('heartbeat_activity', $message, $message->view_mode, $message->language); // Populate $message->content with a render() array. $hook = 'heartbeat_activity_view'; foreach (module_implements($hook) as $module) { $function = $module . '_' . $hook; if (function_exists($function)) { $result = $function($message, $message->view_mode, $message->language); } } $build += $message->content; // We don't need duplicate rendering info in $message->content. unset($message->content); // Allow modules to modify the structured activity message. $type = 'heartbeat_activity'; drupal_alter(array('heartbeat_activity_view', 'entity_view'), $build, $type); return $build; } /** * Implements hook_heartbeat_activity_view(). * * @param HeartbeatActivity $heartbeatActivity * The activity message object. */ function heartbeat_heartbeat_activity_view(HeartbeatActivity $heartbeatActivity, $view_mode = 'full', $language = NULL) { if ($heartbeatActivity->actor->picture) { $uri = (is_numeric($heartbeatActivity->actor->picture)) ? file_load($heartbeatActivity->actor->picture)->uri : $heartbeatActivity->actor->picture->uri; $heartbeatActivity->content['avatar'] = theme('heartbeat_activity_avatar', array('heartbeatactivity' => $heartbeatActivity, 'uri' => $uri)); } $heartbeatActivity->content['message'] = array( '#attributes' => array('class' => array('activity-message')), '#title' => t('Heartbeat activity message'), '#markup' => $heartbeatActivity->message, ); $heartbeatActivity->content['time'] = array( '#title' => t('Activity on'), '#markup' => theme('heartbeat_time_ago', array('message' => $heartbeatActivity)), ); $heartbeatActivity->content['buttons'] = array( '#markup' => theme('heartbeat_buttons', array('message' => $heartbeatActivity)), ); } /** * Process variables for heartbeat-activity.tpl.php. */ function template_preprocess_heartbeat_activity(&$variables) { $variables['view_mode'] = $variables['elements']['#view_mode']; $variables['message'] = $variables['elements']['#message']; $message = $variables['message']; $variables['content'] = array(); // Prepare $content variable for template file. foreach (element_children($variables['elements']) as $key) { $variables['content'][$key] = $variables['elements'][$key]; } $variables['classes_array'][] = $variables['zebra']; $variables['classes_array'][] = 'heartbeat-activity-' . $message->uaid; $variables['classes_array'][] = $message->message_id; $variables['attributes_array']['id'] = 'heartbeat-activity-' . $message->uaid; // Preprocess fields. field_attach_preprocess('heartbeat_activity', $message, $variables['elements'], $variables); } /** * Implements hook_image_default_styles(). */ function heartbeat_image_default_styles() { $styles = array(); $styles['activity_avatar'] = array( 'effects' => array( array( 'name' => 'image_scale', 'data' => array('width' => 50, 'height' => 50, 'upscale' => 1), 'weight' => 0, ), ) ); return $styles; } /** * Implements hook_ds_layout_info(). */ function heartbeat_ds_layout_info() { $layouts = array( 'heartbeat_2col' => array( 'label' => t('Template with left/right for activity'), 'path' => drupal_get_path('module', 'heartbeat') . '/layouts/heartbeat_2col', 'regions' => array( 'heartbeat_left' => t('Left'), 'heartbeat_content' => t('Content'), 'heartbeat_footer' => t('Footer'), ), 'css' => TRUE, ), ); return $layouts; } /** * Preprocess the primary theme implementation for a view. */ function heartbeat_preprocess_views_view(&$vars) { $view = $vars['view']; if ($view->base_table == 'heartbeat_activity') { $vars['classes_array'][] = 'heartbeat-stream'; $vars['classes_array'][] = 'heartbeat-messages-wrapper'; $vars['classes_array'][] = 'heartbeat-stream-viewsactivity'; } } /** * Heartbeat API functions. */ /** * API function to retrieve the most active users. * * @param String $language * The language for the activity. * @param Integer $count * The count number / limit. */ function heartbeat_api_most_active_users($view_mode, $count = 5, $language = NULL) { /*if (!isset($language)) { $language = $GLOBALS['language']->language; }*/ $uids = array(); $result = db_query_range("SELECT uid, COUNT(uaid) AS 'count' FROM {heartbeat_activity} WHERE uid > 0 GROUP BY uid ORDER BY count DESC ", 0, $count); foreach ($result as $row) { $uids[$row->uid] = $row->count; } $accounts = user_load_multiple(array_keys($uids)); $users = array(); foreach ($accounts as $account) { $users[$account->uid . '_' . $uids[$account->uid]] = user_view($account, $view_mode, $language); } return $users; } /** * API function to log a message from custom code * * @param string $message_id * Id of the message that is known in the message * @param integer $uid * Actor or user performing the activity * @param integer $uid_target [optional] * user id of the target user if present. Target users can be an addresse or a * user relation transaction with the actor $uid * @param integer $nid [optional] * Node id for content (for context node) * @param integer $nid_target [optional] * Node id for content that is related to other content * @param array $variables [optional] * Variables can be used if you used them in the used message. Take care to use * the @-sign for words that are prefix with the question mark sign in the messages * @param integer $access * The access to restrict the message */ function heartbeat_api_log($message_id, $uid, $uid_target = 0, $nid = 0, $nid_target = 0, $variables = array(), $access = HEARTBEAT_PUBLIC_TO_ALL, $time = 0) { $data = array(); // Normal form values $data['message_id'] = $message_id; $data['uid'] = $uid; $data['uid_target'] = $uid_target; $data['nid'] = $nid; $data['nid_target'] = $nid_target; $data['access'] = $access; $data['timestamp'] = $time == 0 ? $_SERVER['REQUEST_TIME'] : $time; $data['variables'] = $variables; return heartbeat_log($data); } /** * User activity logger function * @param The data to add one row */ function heartbeat_log($data, $args = array()) { // Relational message of heartbeat messages $template = heartbeat_message_template_load($data['message_id']); $heartbeatactivity = new HeartbeatActivity($data, $template); // Prepare the fields. field_attach_presave('heartbeat_activity', $heartbeatactivity); module_invoke_all('heartbeat_activity_presave', $heartbeatactivity); // Save the record to the activity table. $saved = $heartbeatactivity->save($args); // Save fields. field_attach_insert("heartbeat_activity", $heartbeatactivity); // Invoke the heartbeat activity hooks. module_invoke_all("entity_insert", $heartbeatactivity, 'heartbeat_activity'); module_invoke_all("heartbeat_activity_insert", $heartbeatactivity); return $saved; } /** * Returns a set of users related to a central user. */ function heartbeat_related_uids($uid) { static $uids; if (!isset($uids[$uid])) { $uids[$uid] = array($uid => $uid); foreach (module_implements('heartbeat_related_uids') as $module) { $function = $module . '_heartbeat_related_uids'; if (function_exists($function)) { $uids[$uid] += $function($uid); } } $uids[$uid] = array_unique($uids[$uid]); } return $uids[$uid]; } /** * Function to load one activity message. */ function heartbeat_activity_load($uaid) { return HeartbeatMessagePool::getInstance()->getMessage($uaid); } /** * Implements hook_forms(). * All heartbeat template forms share the same form handler. */ function heartbeat_forms() { $forms = array(); if ($types = heartbeat_templates_names()) { foreach (array_keys($types) as $type) { $forms[$type . '_heartbeat_activity_form']['callback'] = 'heartbeat_activity_form'; } } return $forms; } /** * Class to keep HeartbeatActivity messages in a pool so * plugins and such can get the message instead of reloading them. */ class HeartbeatMessagePool { private static $instance = NULL; private $activity = array(); /** * Constructor. */ private function __construct() { } /** * getInstance(). */ static public function getInstance() { if (!isset(self::$instance)) { self::$instance = new HeartbeatMessagePool(); } return self::$instance; } /** * getMessage(). */ public function getMessage($uaid) { if (!isset($this->activity[$uaid])) { $this->addMessage(_heartbeat_activity_load($uaid)); } return $this->activity[$uaid]; } /** * addMessage(). */ public function addMessage($heartbeatActivity) { if (isset($heartbeatActivity)) { if (!isset($this->activity[$heartbeatActivity->uaid])) { $this->activity[$heartbeatActivity->uaid] = $heartbeatActivity; } } } } /** * Function to load one activity message. */ function _heartbeat_activity_load($uaid) { if (is_numeric($uaid)) { $activities = heartbeat_activity_load_multiple(array($uaid), array()); return $activities ? $activities[$uaid] : $activities; } return FALSE; } /** * Load multiple activity records by user activity ID's. */ function heartbeat_activity_load_multiple($uaids = array(), $conditions = array()) { $entities = entity_load('heartbeat_activity', $uaids, $conditions); $activities = array(); foreach ($uaids as $uaid) { $activity = $entities[$uaid]; if ($template = heartbeat_message_template_load($activity->message_id)) { $message = new HeartbeatActivity($activity, $template); $message->count = 1; $activities[$uaid] = $message; HeartbeatMessagePool::getInstance()->addMessage($message); } } return $activities; } /** * Deletes a heartbeat activity messages. * @param Array $uaids * User activity IDs * @param Boolean $all * Indicates whether all activity should be deleted. */ function heartbeat_activity_delete($uaids = array(), $all = FALSE) { // We don't delete all messages when not intended. if (empty($uaids) && $all == FALSE) { return; } $query = db_delete('heartbeat_activity'); if (!empty($uaids) && $all == FALSE) { $query->condition('uaid', $uaids, 'IN'); } $query->execute(); //->where(" ha.message_id NOT IN (:messages) ", array(':messages' => $denied_messages)); // Allow modules to respond to the deleting of a heartbeat activity message. module_invoke_all('heartbeat_activity_delete', $uaids, $all); } /** * Get the heartbeat template messages names. */ function heartbeat_templates_names() { $names = array(); ctools_include('export'); foreach(ctools_export_crud_load_all('heartbeat_messages') as $template) { $names[$template->message_id] = $template->description; } return $names; } /** * Function to delete 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 * module : only defined by that module */ function heartbeat_message_template_delete(HeartbeatMessageTemplate $template) { $template->delete(); field_attach_delete_bundle('heartbeat_activity_template', $template->message_id); entity_get_controller('heartbeat_activity_template')->resetCache(); cache_clear_all(); } /** * 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 * module : only defined by that module */ function heartbeat_message_template_load($message_id) { ctools_include('export'); return ctools_export_crud_load('heartbeat_messages', $message_id); } /** * Function to load the title of message template pages. */ function heartbeat_message_id_title($template) { return $template->message_id; } /** * Set the default values for a heartbeat_template. * * The defaults are for a type defined through hook_heartbeat_template_info(). * When populating a custom template $info should have the 'custom' * key set to 1. * * @param $info * An object or array containing values to override the defaults. * * @return * A heartbeat template object. */ function heartbeat_template_set_defaults($info = array()) { $template = &drupal_static(__FUNCTION__); if (!isset($template)) { $template = new HeartbeatMessageTemplate(); } $new_template = clone $template; $info = (array) $info; foreach ($info as $key => $data) { $new_template->$key = $data; } if (empty($new_template->module)) { $new_template->module = $new_template->base == 'heartbeat_content' ? 'heartbeat' : ''; } $new_template->orig_type = isset($info['template']) ? $info['template'] : ''; return $new_template; } /** * Query extender for heartbeat pager queries. * */ class PagerActivity extends SelectQueryExtender { public $lastActivityId = 0; /** * The limit for this pager. */ protected $limit = 0; public function __construct(SelectQueryInterface $query, DatabaseConnection $connection) { parent::__construct($query, $connection); // Add pager tag. Do this here to ensure that it is always added before // preExecute() is called. $this->addTag('pager'); } /** * Override the execute method. * * Before we run the query, we need to add pager-based range() instructions * to it. */ public function execute() { // Add convenience tag to mark that this is an extended query. We have to // do this in the constructor to ensure that it is set before preExecute() // gets called. if (!$this->preExecute($this)) { return NULL; } // A NULL limit is the "kill switch" for pager queries. if (empty($this->limit)) { return; } //$total_items = $this->getCountQuery()->execute()->fetchField(); //$current_page = pager_default_initialize($total_items, $this->limit, $this->element); $this->range(0, $this->limit); // Now that we've added our pager-based range instructions, run the query normally. return $this->query->execute(); } /** * Sets the last uaid */ public function setLastActivityId($lastActivityId) { $this->lastActivityId = $lastActivityId; $this->query->condition('ha.uaid', $this->lastActivityId, '>'); } /** * Sets the offset timestamps. */ public function setOffsetTime($before, $after = 0) { $this->query->condition('ha.timestamp', $before, '<'); if ($after > 0) { $this->query->condition('ha.timestamp', $_SERVER['REQUEST_TIME'] - $after, '>'); } } /** * Specify the maximum number of elements per page for this query. * * The default if not specified is 10 items per page. * * @param $limit * An integer specifying the number of elements per page. If passed a false * value (FALSE, 0, NULL), the pager is disabled. */ public function limit($limit = 10) { $this->limit = $limit; return $this; } } /** * Class HeartbeatCtoolsObject * * Ctools abstract class to inherit base properties. * */ abstract class HeartbeatCtoolsObject { // The API version that this object implements. public $api_version = 1; // A boolean for whether the object is disabled. public $disabled = FALSE; // For objects that live in code, the module which provides the default object. public $export_module = ''; // A bitmask representation of an object current storage. You can use this bitmask // in combination with the EXPORT_IN_CODE and EXPORT_IN_DATABASE constants to test // for an object's storage in your code. public $export_type = 0; // A boolean for whether the object lives only in code. public $in_code_only = FALSE; // The schema API table that this object belongs to. public $table = ''; // A string representing the storage type of this object. Can be one of the following: // * Normal is an object that lives only in the database. // * Overridden is an object that lives in the database and is overriding the exported // configuration of a corresponding object in code. // * Default is an object that lives only in code. public $type = 'Overridden'; } /** * Theme functions and helpers. */ /** * The function for the avatar in a heartbeat activity message. */ function theme_heartbeat_activity_avatar($variables) { return array( '#markup' => theme('image_style', array( 'style_name' => 'activity_avatar', 'path' => $variables['uri'], 'attributes' => array('class' => 'avatar'))), ); } /** * Theme function for a list of heartbeat activity messages. */ function theme_heartbeat_list($variables) { $heartbeatStream = $variables['stream']; if (!$heartbeatStream->hasAccess()) { return ''; } global $user, $language; $content = ''; $content .= $heartbeatStream->prefix; if (!isset($heartbeatStream->config) || empty($heartbeatStream->config->class)) { $content .= drupal_render($variables['content']); } else { $content .= '