heartbeataccess.inc in Heartbeat 6.3
File
includes/heartbeataccess.inc
View source
<?php
abstract class HeartbeatAccess {
protected $_whoisuser_types = array(
self::TYPE_ACTOR => 'Acting user',
self::TYPE_USER_PROFILE => 'Requested user (from url)',
);
protected $_whoisuser_type = self::TYPE_ACTOR;
protected $_uid = 0;
protected $_errors = array();
protected $_has_errors = FALSE;
const TYPE_ACTOR = 0;
const TYPE_USER_PROFILE = 1;
public function __construct() {
global $user;
$this->_whoisuser_type = variable_get('heartbeat_show_user_profile_messages_' . strtolower(get_class($this)), self::TYPE_ACTOR);
if ($this->_whoisuser_type == self::TYPE_USER_PROFILE) {
if (arg(0) == 'user' && is_numeric(arg(1)) && arg(1) > 0 && arg(2) != 'edit') {
$this->_uid = arg(1);
}
else {
$this
->setError(t('Error found in heartbeat activity block for user in url. No user id found in url. Make sure this type of block is only active on the user page.'));
}
}
else {
$this->_uid = $user->uid;
}
$user->heartbeat_relations = heartbeat_get_related_uids($this->_uid);
}
protected function setError($text) {
$this->_errors[] = $text;
$this->_has_errors = TRUE;
}
public function hasErrors() {
return $this->_has_errors;
}
public function getErrors() {
return $this->_errors;
}
public function fetchMessages() {
$heartbeat = $this
->prepareHeartbeatInfo();
$heartbeat = $this
->dressUpMessages($heartbeat);
return $this
->finishMessages($heartbeat);
}
protected function prepareHeartbeatInfo() {
global $user, $language;
$full_timespan = variable_get('heartbeat_activity_no_duplicate_seconds', 172800) - 1;
$heartbeatInfo = new HeartbeatInfo();
$heartbeatInfo->uid = $this->_uid;
$heartbeatInfo->access = $this
->getAccess();
$heartbeatInfo->user_relations = $user->heartbeat_relations;
$heartbeatInfo->limit_sql = variable_get('heartbeat_block_items_max', 250);
$heartbeatInfo->language = $language->language;
$heartbeatInfo->start_time = $_SERVER['REQUEST_TIME'] - (int) $full_timespan;
$heartbeatInfo->time_span = date("G", $full_timespan) . ' hours';
$heartbeatInfo->sql_start = "SELECT\n hm.message AS 'message_orig', hm.message_concat AS 'message_concat_orig',\n hm.concat_args, hm.module, hm.perms, ua.*, 1 AS 'count'\n FROM {heartbeat_activity} ua\n LEFT JOIN {heartbeat_messages} hm ON ua.message_id = hm.message_id\n WHERE ua.language = '%s' ";
$heartbeatInfo->sql_end = " AND timestamp > %d ORDER BY timestamp DESC";
$heartbeat = HeartbeatParser::instantiate($this
->getAccess());
$heartbeat
->set_info($heartbeatInfo);
return $heartbeat;
}
protected abstract function dressUpMessages(HeartbeatParser $heartbeat);
protected function finishMessages(HeartbeatParser $heartbeat) {
if (count($heartbeat->raw_messages) > 0) {
$duplicates = array();
$args = array(
$heartbeat->raw_messages,
$this,
);
$hook = 'heartbeat_messages_alter';
$return = array();
foreach (module_implements($hook) as $module) {
$function = $module . '_' . $hook;
$module_duplicates = call_user_func_array($function, $args);
if (isset($module_duplicates) && is_array($module_duplicates)) {
foreach ($module_duplicates as $key => $value) {
$duplicates[$key] = $value;
}
}
}
$messages = $heartbeat->raw_messages;
if (!empty($duplicates)) {
$messages = array_diff_key($messages, $duplicates);
}
$heartbeat->raw_messages = $messages;
}
return $heartbeat;
}
protected final function getAccess() {
return get_class($this);
}
}
Classes
Name |
Description |
HeartbeatAccess |
Abstract class heartbeataccess
This base class has final template methods which are
used by the derived concretes. The HeartbeatAccess is a
state object that is given to the HeartbeatMessageBuilder to
set the access to the current request. |