heartbeat_example.module in Heartbeat 6.4
Same filename and directory in other branches
File
modules/heartbeat_example/heartbeat_example.moduleView source
<?php
/**
* @file
* Heartbeat example module
*
* Created on Sep 14, 2009
*
* @author
* Jochen Stals (Stalski)
*
* @remarks
* - THIS MODULE IS NOT FOR PRODUCTION USAGE!!
* I won't support question on this in the drupal.org issue queue.
* - comments are limited to 10 and a more button is displayed if number
* exceeds the maximum number of comments, redirecting the user to the node
* - users are prohibited to see some links like join group if the group is
* closed or not applicable to this user. user and node access are doing their
* job.
* - Are their pages as group post pages where the heartbeat has to load with
* the group and friend filter set and specific to this group as well?
*
*/
include 'custom.heartbeat_filters.inc';
/**
* Implementation of hook_theme().
*/
function heartbeat_example_theme() {
return array(
// Theme article heartbeat node
'heartbeat_content' => array(
'arguments' => array(
'message' => NULL,
'node' => NULL,
),
),
);
}
/**
* Implementation of hook_nodeapi().
*/
function heartbeat_example_nodeapi(&$node, $op, $arg = 0) {
// When a story is inserted, log user activity
// Compare this approach with page. The latter works
// with rules doing the same as this example.
if ($op == 'insert' && $node->type == 'story') {
$message_id = 'heartbeat_add_node';
$variables = array(
'@username' => l(heartbeat_user_load($node->uid)->name, 'user/' . $node->uid),
'@node_type' => 'page',
'@node_title' => l($node->title, 'node/' . $node->nid),
// You could easily set the the time of the activity with
// the time of node creation. (devel generate, imports, ...)
'time' => $node->created,
);
heartbeat_api_log($message_id, $node->uid, 0, $node->nid, 0, $variables);
}
// When a page or story is updated, log activity for it.
if ($op == 'update' && in_array($node->type, array(
'page',
'story',
))) {
$message_id = 'heartbeat_edit_node';
$variables = array(
'@username' => l(heartbeat_user_load($node->uid)->name, 'user/' . $node->uid),
'@node_type' => $node->type,
'@nodetypes' => $node->type . '\'s',
'@node_title' => l($node->title, 'node/' . $node->nid),
);
heartbeat_api_log($message_id, $node->uid, 0, $node->nid, 0, $variables);
}
}
/**
* Implementation of hook_heartbeat_message_info().
*/
function heartbeat_example_heartbeat_message_info() {
$info = array(
0 => array(
'message' => '!user added !article.',
'message_concat' => '%user% added !article.',
'message_id' => 'og_add_article_content',
'concat_args' => array(
'type' => 'summary',
'group_by' => 'node',
'group_target' => 'user',
'group_by_target' => '',
'group_num_max' => '3',
'merge_separator' => ',',
'merge_end_separator' => ' and ',
'roles' => array(
0 => '0',
1 => '0',
2 => '0',
3 => '0',
4 => '0',
),
),
'description' => 'Add article',
'perms' => '1',
'custom' => HEARTBEAT_MESSAGE_DEFAULT,
'variables' => array(
'@user' => '[author:user-name-url]',
'@article' => '[node:title-link]',
),
),
);
return $info;
}
/**
* Implementation of hook_heartbeat_register_access_types().
*/
function heartbeat_example_heartbeat_register_access_types() {
return array(
// Site activity stream is kind of a copy of HeartbeatPublic.
// It is only to show you how it's done.
0 => array(
'name' => 'Site activity',
'class' => 'SiteActivity',
'path' => 'siteactivity.inc',
'module' => 'heartbeat_example',
),
);
}
/**
* Implementation of hook_heartbeat_messages_alter().
*
* @param $messages Array of raw heartbeat activity messages
* @param $stream HeartbeatAccess as the object that holds the current stream scope
*/
function heartbeat_example_heartbeat_messages_alter(&$messages, HeartbeatAccess $stream) {
// Here you can loop through messages to delete (unset) activity messages
// rather than changing them. Changes to messages are most of the time
// theme issues and should be done in "hook_heartbeat_theme_alter".
}
/**
* Implementation of hook_heartbeat_theme_alter().
*
* Take out messages you want to retheme.
* This can be by adding buttons, html controls, repositioning elements, ...
* In this example we add buttons and place icons for some message types.
* In other cases, a custom avatar is used.
*
* @param $messages Array of heartbeat activity messages
* @param $stream HeartbeatAccess as the object that holds the current stream scope
*/
/*function heartbeat_example_heartbeat_theme_alter(&$messages, HeartbeatAccess $stream) {
foreach ($messages as $key => $message) {
$messages[$key]->display_time = FALSE;
if ($message->nid > 0) {
// $node could be build here like in other examples, but too lazy right now :)
$node = node_load($message->nid);
// Catch normal story posts
if ($node->type == 'story') {
$messages[$key]->message = theme('heartbeat_content', $message, $node);
}
}
}
}*/
/**
* Implementation of hook_heartbeat_stream_filters().
* Define filters which can be called to return the
* messages that meet the condition of the filter.
*
* @see custom.heartbeat_filters.inc
*/
function heartbeat_example_heartbeat_stream_filters() {
return array(
'stories' => array(
'name' => t('Stories'),
),
);
}
/**
* Theme function for heartbeat comments
* @param $comments Array of comment/reaction objects
* @param $type Boolean to indicate whether it is a node comment or not
* @return String Themed output for comments
*/
function phptemplate_heartbeat_comments($comments, $uaid, $node_comment = FALSE, $has_more = FALSE) {
$output = '';
$comment = current($comments);
$output .= '<ul class="summary" id="heartbeat-comments-list-' . $uaid . '">';
if (!empty($comments)) {
$i = 1;
foreach ($comments as $comment) {
$last = count($comments) == $i ? TRUE : FALSE;
$i++;
$output .= theme('heartbeat_comment', $comment, $node_comment, $last);
}
}
// Add more button.
if ($has_more) {
$link = heartbeat_comments_load_more_link($uaid, $node_comment, isset($comment->nid) ? $comment->nid : 0);
$output .= '<li class="heartbeat-comment heartbeat-comment-more">' . $link . '</li>';
}
$output .= '</ul>';
return $output;
}
/**
* OVERRIDE of theme function for heartbeat comment
* @param $comment Object comment with user in it
* @param $type Boolean to indicate whether it is a node comment or not
* @return String Themed output for a comment
*/
function phptemplate_heartbeat_comment($comment, $node_comment = FALSE, $last = FALSE) {
$output = '';
if ($last == TRUE) {
$class = "heartbeat-comment-last";
}
else {
$class = "";
}
$output .= '<li class="heartbeat-comment" id="heartbeat-comment-' . ($node_comment ? $comment->cid : $comment->hcid) . '">';
if ($comment->uid) {
$account = heartbeat_user_load($comment->uid);
$name = $account->name;
$avatar = l(theme('imagecache', 'icon', $account->picture), 'user/' . $account->uid, array(
'html' => TRUE,
));
}
else {
$name = t('Anonymous');
$avatar = '<span class="user-default"></span>';
}
$output .= '<span class="avatar">' . $avatar . '</span>';
$comment->comment = filter_xss($comment->comment);
$output .= '<div class="heartbeat-teaser">';
$output .= l($name, 'user/' . $comment->uid, array(
'attributes' => array(
'class' => 'user',
),
));
$output .= $comment->comment . '<br />';
$output .= _theme_time_ago(isset($comment->time) ? strtotime($comment->time) : $comment->timestamp);
$output .= '</div>';
// For node comments link to the standard Drupal comment deletion form under comment/delete/%
// Only users who have the right permissions should see the delete link.
// Permissions are provided by the "Comment Delete" module.
global $user;
if ($node_comment) {
if (user_access('delete any comment') || $user->uid == $comment->uid && user_access('delete own comments')) {
$output .= l(t('Delete'), 'heartbeat/nodecomment/delete/' . $comment->cid, array(
'attributes' => array(
'class' => 'heartbeat-comment-delete',
),
'query' => drupal_get_destination(),
'alias' => TRUE,
));
}
}
elseif (user_access('administer heartbeat comments') || $comment->uid && $user->uid && $comment->uid == $user->uid) {
$output .= l(t('Delete'), 'heartbeat/comment/delete/' . $comment->hcid, array(
'attributes' => array(
'class' => 'heartbeat-comment-delete',
),
'query' => drupal_get_destination(),
'alias' => TRUE,
));
}
$output .= '</li>';
return $output;
}
/**
* Theme function for a heartbeat_content
*/
function theme_heartbeat_content($message, $node) {
$output = '';
$user = heartbeat_user_load($message->uid);
$output .= '<div class="icon-left-margin">';
$output .= '<span class="avatar">' . l(theme('imagecache', 'tiny_picture', $user->picture), 'user/' . $user->uid, array(
'html' => TRUE,
)) . '</span>';
$output .= '</div>';
// If the message has to be shown anyway (inside the message)
$output .= '<div class="heartbeat-indent">';
$output .= $message->message;
//$output .= $message->rebuild_message();
$output .= '</div>';
return $output;
}
Functions
Name | Description |
---|---|
heartbeat_example_heartbeat_messages_alter | Implementation of hook_heartbeat_messages_alter(). |
heartbeat_example_heartbeat_message_info | Implementation of hook_heartbeat_message_info(). |
heartbeat_example_heartbeat_register_access_types | Implementation of hook_heartbeat_register_access_types(). |
heartbeat_example_heartbeat_stream_filters | Implementation of hook_heartbeat_stream_filters(). Define filters which can be called to return the messages that meet the condition of the filter. |
heartbeat_example_nodeapi | Implementation of hook_nodeapi(). |
heartbeat_example_theme | Implementation of hook_theme(). |
phptemplate_heartbeat_comment | OVERRIDE of theme function for heartbeat comment |
phptemplate_heartbeat_comments | Theme function for heartbeat comments |
theme_heartbeat_content | Theme function for a heartbeat_content |