View source
<?php
function ogactivity_activity_info() {
return array(
'ops' => array(
'join' => t('Join'),
'leave' => t('Leave'),
),
'types' => array(
'ogaction' => t('Group Action'),
),
'roles' => array(
'author' => array(
'#name' => t('Author'),
'#description' => t('The person who joined or left a group.'),
'#default' => array(
'join' => '[author] joined the [node-link] group',
'leave' => '[author] left the [node-link] group',
),
),
'all' => array(
'#name' => t('All'),
'#description' => t('The general public.'),
'#default' => array(
'join' => '[author-all] joined the [node-link] group',
'leave' => '[author-all] left the [node-link] group',
),
),
),
);
}
function ogactivity_activityapi(&$activity, $op) {
if ($op == 'load') {
if ($activity['data']['module'] == 'ogactivity' && !node_access('view', node_load($activity['data']['node-id']))) {
$activity = array();
}
}
}
function ogactivity_token_list($type = 'all') {
if ($type == 'ogactivity') {
$tokens['ogactivity'] = array(
'node-id' => t('Id of the node of the group that was joined or left'),
'node-title' => t('Title of the group that was joined or left'),
'node-link' => t('Link to the group that was joined or left'),
'node-type' => t('The node type of the group that was joined or left'),
);
return $tokens;
}
}
function ogactivity_token_values($type, $data = NULL, $options = array()) {
if ($type == 'ogactivity' && !empty($data)) {
$data['node-type'] = theme('activity_node_type', $data['node-type']);
$data['node-link'] = l($data['node-title'], 'node/' . $data['node-id']);
return $data;
}
}
function ogactivity_og($op, $gid, $uid, $args) {
switch ($op) {
case 'user insert':
case 'user delete':
if (array_key_exists('is_active', $args) && $args['is_active'] == 0) {
return FALSE;
}
$node = node_load($gid);
$type = 'ogaction';
$op = $op == 'user delete' ? 'leave' : 'join';
if (!in_array($type, variable_get('ogactivity_token_types', array(
$type,
)), TRUE) || !in_array($op, variable_get('ogactivity_op_types', array(
$op,
)), TRUE)) {
return FALSE;
}
$user = user_load(array(
'uid' => $uid,
));
if (activity_user_privacy_optout($user)) {
return FALSE;
}
if (user_access('hide activity', $user)) {
return FALSE;
}
$data = array(
'operation' => $op,
'node-id' => $node->nid,
'node-title' => $node->title,
'node-type' => $node->type,
);
$target_users_roles = array(
ACTIVITY_ALL => 'all',
$user->uid => 'author',
);
activity_insert($user->uid, 'ogactivity', $type, $op, $data, $target_users_roles);
break;
}
}
function ogactivity_menu() {
$items = array();
$items['activity/og'] = array(
'title' => 'My groups activity',
'page callback' => 'ogactivity_page',
'type' => MENU_LOCAL_TASK,
'access callback' => 'user_access',
'access arguments' => array(
'view own activity',
),
);
return $items;
}
function ogactivity_page() {
global $user;
$result = db_query("\nSELECT \n DISTINCT(og.uid) \nFROM \n {og_uid} og \nINNER JOIN \n {og_uid} og2 ON og.nid = og2.nid AND \n og.uid != %d AND \n og2.uid = %d \nINNER JOIN \n {activity_targets} at ON og.uid = at.target_uid \nINNER JOIN \n {activity} a ON at.aid = a.aid \nWHERE \n at.target_role = 'author'", $user->uid, $user->uid);
while ($row = db_fetch_object($result)) {
$users[] = $row->uid;
}
$activities = array();
if ($users) {
$activities = activity_get_activity($users, NULL, variable_get('activity_page_pager', 20));
}
$table = theme('activity_table', $activities);
return theme('activity_page', $activities, $table);
}
function ogactivity_block($op = 'list', $delta = 0, $edit = array()) {
global $user;
switch ($op) {
case 'list':
$block['og']['info'] = t("Activity - Groups: show activity in user's groups.");
return $block;
break;
case 'configure':
$form['items'] = array(
'#type' => 'select',
'#title' => t('Number of items'),
'#default_value' => variable_get('activity_block_' . $delta, 5),
'#options' => drupal_map_assoc(range(1, 50)),
);
return $form;
break;
case 'save':
variable_set('activity_block_' . $delta, $edit['items']);
break;
case 'view':
switch ($delta) {
case 'og':
$result = db_query("\nSELECT \n DISTINCT(og.uid) \nFROM \n {og_uid} og \nINNER JOIN \n {og_uid} og2 ON og.nid = og2.nid AND \n og.uid != %d AND \n og2.uid = %d \nINNER JOIN \n {activity_targets} at ON og.uid = at.target_uid \nINNER JOIN \n {activity} a ON at.aid = a.aid \nWHERE \n at.target_role = 'author'", $user->uid, $user->uid);
while ($row = db_fetch_object($result)) {
$users[] = $row->uid;
}
$activity = array();
if ($users) {
$activity = activity_get_activity($users, NULL, variable_get('activity_block_' . $delta, 5) + 1);
}
if ($count = count($activity)) {
drupal_add_css(drupal_get_path('module', 'activity') . '/activity.css');
if ($count > variable_get('activity_block_' . $delta, 5)) {
$more_link = theme('activity_more_link', 'activity/og');
array_pop($activity);
}
$activites = array();
foreach ($activity as $item) {
$activities[] = theme('activity', activity_token_replace($item), $item) . activity_delete_link($item);
}
return array(
'subject' => t('My groups activity'),
'content' => theme('activity_block', $activities, $more_link),
);
}
break;
}
break;
}
}