| 1 |
<?php
|
| 2 |
// $Id: activitystream.module,v 1.1.2.14 2008/08/12 04:58:25 akalsey Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Invoke a node hook.
|
| 6 |
*
|
| 7 |
* @param $module
|
| 8 |
* The name of your module
|
| 9 |
*
|
| 10 |
* @param &$user
|
| 11 |
* A user object containing the user that you're saving account info
|
| 12 |
* for.
|
| 13 |
*
|
| 14 |
* @param $params
|
| 15 |
* An array containing the user's account info. All fields are
|
| 16 |
* optional, but if you don't send anything, nothing will be saved
|
| 17 |
* Fields:
|
| 18 |
* userid: The user's account id on the remote site
|
| 19 |
* password: The user's password on the remote site. Don't
|
| 20 |
* ask for and store the users's password unless it's
|
| 21 |
* neccessary. You can often get read access to the
|
| 22 |
* site's data with just their username.
|
| 23 |
* feed: An RSS or Atom feed URL containing that user's
|
| 24 |
* stream from the remote site
|
| 25 |
* @return
|
| 26 |
* True if the information was saved
|
| 27 |
*/
|
| 28 |
function activitystream_save_account($module, &$user, $params) {
|
| 29 |
if (count($params) == 0) {
|
| 30 |
return false;
|
| 31 |
}
|
| 32 |
$result = db_query('DELETE FROM {activitystream_accounts} WHERE module = \'%s\' and uid = %d', $module, $user->uid);
|
| 33 |
if (empty($params['userid']) && empty($params['password']) && empty($params['feed'])) {
|
| 34 |
return;
|
| 35 |
}
|
| 36 |
// Save multiline feed fields each to a different feed
|
| 37 |
$arrFeeds = split("\n", $params['feed']);
|
| 38 |
foreach ($arrFeeds as $url) {
|
| 39 |
$params['feed'] = $url;
|
| 40 |
$result = db_query('INSERT INTO {activitystream_accounts} (module, uid, userid, password, feed) VALUES (\'%s\', %d, \'%s\', \'%s\', \'%s\')', $module, $user->uid, $params['userid'], $params['password'], $params['feed']);
|
| 41 |
}
|
| 42 |
return true;
|
| 43 |
}
|
| 44 |
|
| 45 |
function activitystream_menu() {
|
| 46 |
$items = array();
|
| 47 |
|
| 48 |
$items[] = array(
|
| 49 |
'path' => 'admin/settings/activitystream',
|
| 50 |
'title' => t('Activity Stream'),
|
| 51 |
'description' => t('Administer settings for activity feeds'),
|
| 52 |
'callback' => 'drupal_get_form',
|
| 53 |
'callback arguments' => 'activitystream_settings',
|
| 54 |
'access' => user_access('access administration pages'),
|
| 55 |
'type' => MENU_NORMAL_ITEM,
|
| 56 |
);
|
| 57 |
|
| 58 |
$items[] = array('path' => 'stream',
|
| 59 |
'title' => t('Activity Stream'),
|
| 60 |
'callback' => 'activitystream_page',
|
| 61 |
'access' => user_access('access content'),
|
| 62 |
'type' => MENU_CALLBACK
|
| 63 |
);
|
| 64 |
|
| 65 |
return $items;
|
| 66 |
}
|
| 67 |
|
| 68 |
/**
|
| 69 |
* Implementation of hook_node_info().
|
| 70 |
*/
|
| 71 |
function activitystream_node_info() {
|
| 72 |
return array(
|
| 73 |
'activitystream' => array(
|
| 74 |
'name' => t('Activity Stream Item'),
|
| 75 |
'module' => 'activitystream',
|
| 76 |
'description' => t('A node type to contain items from your activity stream. You shouldn\'t create these nodes directly.'),
|
| 77 |
'help' => t('A node type to contain items from your activity stream. You shouldn\'t create these nodes directly.'),
|
| 78 |
'body_label' => t('Body'),
|
| 79 |
)
|
| 80 |
);
|
| 81 |
}
|
| 82 |
|
| 83 |
/**
|
| 84 |
* Implementation of hook_nodeapi().
|
| 85 |
* When a node is deleted, also delete the associated record in the stream table.
|
| 86 |
*/
|
| 87 |
function activitystream_nodeapi(&$node, $op, $arg = 0) {
|
| 88 |
switch ($op) {
|
| 89 |
case 'delete':
|
| 90 |
$result = db_query('DELETE FROM {activitystream} WHERE nid = %d', $node->nid);
|
| 91 |
}
|
| 92 |
}
|
| 93 |
|
| 94 |
/**
|
| 95 |
* Implementation of hook_form().
|
| 96 |
* Build the node edit form for a Activity Stream node.
|
| 97 |
*/
|
| 98 |
function activitystream_form(&$node) {
|
| 99 |
$type = node_get_types('type', $node);
|
| 100 |
|
| 101 |
$form['title'] = array(
|
| 102 |
'#type' => 'textfield',
|
| 103 |
'#title' => check_plain($type->title_label),
|
| 104 |
'#required' => TRUE,
|
| 105 |
'#default_value' => $node->title,
|
| 106 |
'#weight' => -5
|
| 107 |
);
|
| 108 |
$form['body_field'] = array(
|
| 109 |
'#type' => 'textarea',
|
| 110 |
'#title' => check_plain($type->body_label),
|
| 111 |
'#default_value' => $node->body,
|
| 112 |
'#required' => FALSE
|
| 113 |
);
|
| 114 |
|
| 115 |
return $form;
|
| 116 |
}
|
| 117 |
|
| 118 |
/*
|
| 119 |
* Calls an API hook that allows activitystream modules to add admin form
|
| 120 |
* items to the Activity Stream settings page.
|
| 121 |
*/
|
| 122 |
function activitystream_form_alter($form_id, &$form) {
|
| 123 |
unset($form['Activity Stream']);
|
| 124 |
if ($form_id == 'activitystream_settings') {
|
| 125 |
foreach (module_implements('activitystream_admin') as $name) {
|
| 126 |
$function = $name .'_activitystream_admin';
|
| 127 |
$elements = $function();
|
| 128 |
foreach ($elements as $key => $value) {
|
| 129 |
$form[$key] = $value;
|
| 130 |
}
|
| 131 |
}
|
| 132 |
}
|
| 133 |
}
|
| 134 |
|
| 135 |
/**
|
| 136 |
* Implementation of hook_user()
|
| 137 |
*/
|
| 138 |
function activitystream_user($op, &$edit, &$account, $category = NULL) {
|
| 139 |
switch ($op) {
|
| 140 |
case 'categories':
|
| 141 |
return array('activitystream' => array('name' => 'activitystream', 'title' => variable_get('activitystream_title', 'Activity Stream'), 'weight' => 2));
|
| 142 |
break;
|
| 143 |
case 'form':
|
| 144 |
if ($category == 'activitystream') {
|
| 145 |
foreach (module_implements('activitystream_settings') as $name) {
|
| 146 |
$function = $name .'_activitystream_settings';
|
| 147 |
$elements = $function($edit);
|
| 148 |
foreach ($elements as $key => $value) {
|
| 149 |
$form[$key] = $value;
|
| 150 |
}
|
| 151 |
}
|
| 152 |
}
|
| 153 |
return $form;
|
| 154 |
break;
|
| 155 |
case 'update':
|
| 156 |
foreach (module_implements('activitystream_settings') as $name) {
|
| 157 |
$arrDetails = array();
|
| 158 |
$arrDetails['userid'] = array_key_exists($name . '_userid', $edit) ? $edit[$name . '_userid'] : null;
|
| 159 |
$arrDetails['password'] = array_key_exists($name . '_password', $edit) ? $edit[$name . '_password'] : null;
|
| 160 |
$arrDetails['feed'] = array_key_exists($name . '_feed', $edit) ? $edit[$name . '_feed'] : null;
|
| 161 |
activitystream_save_account($name, $account, $arrDetails);
|
| 162 |
}
|
| 163 |
break;
|
| 164 |
case 'view':
|
| 165 |
$items = _activitystream_get_activity($account);
|
| 166 |
$title = variable_get('activitystream_title', 'Activity Stream');
|
| 167 |
$output = theme('activitystream', $items);
|
| 168 |
if (!empty($output)) {
|
| 169 |
return array($title => array(array('value' => $output, 'class' => 'user')));
|
| 170 |
}
|
| 171 |
break;
|
| 172 |
}
|
| 173 |
}
|
| 174 |
|
| 175 |
function activitystream_page($uid = 0) {
|
| 176 |
drupal_add_css(drupal_get_path('module', 'activitystream') .'/activitystream.css');
|
| 177 |
$title = variable_get('activitystream_title', 'Activity Stream');
|
| 178 |
if ($uid) {
|
| 179 |
$user = activitystream_user_load($uid);
|
| 180 |
drupal_set_title(check_plain($user->name .'\'s ' . $title));
|
| 181 |
$items = _activitystream_get_activity($user);
|
| 182 |
drupal_set_breadcrumb(array(l(t('Home'), NULL), l(t('Activity Stream'), 'stream')));
|
| 183 |
}
|
| 184 |
else {
|
| 185 |
drupal_set_title(check_plain('All user\'s ' . $title . 's'));
|
| 186 |
$items = _activitystream_get_activity();
|
| 187 |
}
|
| 188 |
$output = theme('activitystream', $items);
|
| 189 |
|
| 190 |
// Breadcrumb navigation
|
| 191 |
$breadcrumb[] = array('path' => 'stream', 'title' => t($title));
|
| 192 |
drupal_set_breadcrumb($breadcrumb);
|
| 193 |
$pager = theme('pager', NULL, 15, 0);
|
| 194 |
if (!empty($pager)) {
|
| 195 |
$output .= $pager;
|
| 196 |
}
|
| 197 |
|
| 198 |
return $output;
|
| 199 |
}
|
| 200 |
|
| 201 |
/*
|
| 202 |
hook_view
|
| 203 |
*/
|
| 204 |
function activitystream_view($node, $teaser = FALSE, $page = FALSE) {
|
| 205 |
$user = activitystream_user_load($node->uid);
|
| 206 |
$title = variable_get('activitystream_title', 'Activity Stream');
|
| 207 |
$node->body = check_markup($node->body, $node->format, FALSE);
|
| 208 |
|
| 209 |
$result = db_query('SELECT s.module, s.link, s.data, s.nid FROM {activitystream} s WHERE s.nid=%d LIMIT 1', $node->nid);
|
| 210 |
$action = db_fetch_object($result);
|
| 211 |
$node->body .= theme('activitystream_view', $action);
|
| 212 |
|
| 213 |
$node->content['body'] = array(
|
| 214 |
'#value' => $node->body,
|
| 215 |
'#weight' => 0,
|
| 216 |
);
|
| 217 |
|
| 218 |
if ($page) {
|
| 219 |
// Breadcrumb navigation
|
| 220 |
$breadcrumb[] = array('path' => 'stream', 'title' => t($title));
|
| 221 |
$breadcrumb[] = array('path' => 'stream/'.$user->uid, 'title' => check_plain($user->name) .'\'s ' . $title);
|
| 222 |
$breadcrumb[] = array('path' => 'node/'. $node->nid);
|
| 223 |
menu_set_location($breadcrumb);
|
| 224 |
}
|
| 225 |
return $node;
|
| 226 |
}
|
| 227 |
|
| 228 |
function activitystream_get_activity($user = null, $show_buddies = false, $count = null) {
|
| 229 |
$items = _activitystream_get_activity($user, $show_buddies, $count);
|
| 230 |
return theme('activitystream',$items);
|
| 231 |
}
|
| 232 |
|
| 233 |
function _activitystream_get_activity($user = null, $show_buddies = false, $count = null) {
|
| 234 |
if ($count == null) {
|
| 235 |
$count = variable_get('default_nodes_main', 10);
|
| 236 |
}
|
| 237 |
if (module_exists('buddylist') && $show_buddies) {
|
| 238 |
$buddies = db_query('SELECT bl.buddy as bid FROM {buddylist} bl WHERE bl.uid = %d',$user->uid);
|
| 239 |
// Since a number of items might be from the same buddy, load the users now and stuff them
|
| 240 |
// into an array for later. This avoids loading the same user multiple times.
|
| 241 |
while ($buddy = db_fetch_object($buddies)) {
|
| 242 |
$objBuddy = activitystream_user_load($buddy->bid);
|
| 243 |
}
|
| 244 |
if (count($arrUsers) == 0) {
|
| 245 |
// No buddies
|
| 246 |
return;
|
| 247 |
}
|
| 248 |
|
| 249 |
$query = 'SELECT n.title, n.nid, s.module, s.link, s.data, n.created FROM {activitystream} s, {node} n WHERE s.nid=n.nid AND n.status =1 AND n.uid in ('.join(',',array_keys($arrUsers)).') ORDER BY n.created DESC';
|
| 250 |
$countquery = 'SELECT count(*) FROM {activitystream} s, {node} n WHERE s.nid=n.nid AND n.status =1 AND n.uid in ('.join(',',array_keys($arrUsers)).')';
|
| 251 |
} elseif ($user) {
|
| 252 |
$query = "SELECT n.title, n.nid, s.module, s.link, s.data, n.created FROM {activitystream} s, {node} n WHERE s.nid=n.nid AND n.status =1 AND n.uid = " . $user->uid . " ORDER BY n.created DESC";
|
| 253 |
$countquery = "SELECT count(*) FROM {activitystream} s, {node} n WHERE s.nid=n.nid AND n.status =1 AND n.uid = " . $user->uid;
|
| 254 |
} else {
|
| 255 |
$query = 'SELECT n.title, n.nid, s.module, s.link, s.data, n.created FROM {activitystream} s LEFT JOIN {node} n on s.nid=n.nid WHERE n.status = 1 ORDER BY n.created DESC';
|
| 256 |
$countquery = 'SELECT count(*) FROM {activitystream} s, {node} n WHERE s.nid=n.nid AND n.status = 1';
|
| 257 |
}
|
| 258 |
$datehead = '';
|
| 259 |
$items = array();
|
| 260 |
$stream = pager_query($query, $count, 0, $countquery);
|
| 261 |
while ($action = db_fetch_object($stream)) {
|
| 262 |
if (date('Ymd', $action->created) != $datehead) {
|
| 263 |
$datehead = date('Ymd', $action->created);
|
| 264 |
$items[] = theme('activitystream_header', $action);
|
| 265 |
}
|
| 266 |
|
| 267 |
if (function_exists('theme_' . $action->module .'_item')) {
|
| 268 |
$theme_function = $action->module .'_item';
|
| 269 |
}
|
| 270 |
else {
|
| 271 |
$theme_function = 'activitystream_item';
|
| 272 |
}
|
| 273 |
$items[] = theme($theme_function,$action);
|
| 274 |
}
|
| 275 |
return $items;
|
| 276 |
}
|
| 277 |
|
| 278 |
function theme_activitystream_header(&$action) {
|
| 279 |
return '<h3 class="datehead">' . format_date($action->created, 'medium') . '</h3>';
|
| 280 |
}
|
| 281 |
|
| 282 |
function theme_activitystream_item($action) {
|
| 283 |
$node = node_load($action->nid);
|
| 284 |
$date = theme('activitystream_date',$node->created);
|
| 285 |
$user = activitystream_user_load($node->uid);
|
| 286 |
$name = theme('activitystream_username',$user);
|
| 287 |
if (function_exists('theme_'.$action->module .'_icon')) {
|
| 288 |
$theme_function = $action->module .'_icon';
|
| 289 |
}
|
| 290 |
else {
|
| 291 |
$theme_function = 'activitystream_icon';
|
| 292 |
}
|
| 293 |
return '<span class="activitystream-item">' . theme($theme_function) . " <span>$name " . l($node->title, 'node/'. $node->nid) . " <span class=\"activitystream-created\">$date</span></span>" . l('#', 'node/' . $node->nid, array('class' => 'permalink')) . "</span>\n";
|
| 294 |
}
|
| 295 |
|
| 296 |
|
| 297 |
function theme_activitystream($items) {
|
| 298 |
drupal_add_css(drupal_get_path('module', 'activitystream') .'/activitystream.css');
|
| 299 |
if (!count($items)) {
|
| 300 |
$items = array(t('There are no activities to show.'));
|
| 301 |
}
|
| 302 |
return '<div id="activitystream">' . "\n" . theme('item_list',$items) . "\n</div>";
|
| 303 |
}
|
| 304 |
|
| 305 |
function theme_activitystream_date($date) {
|
| 306 |
$date = format_date($date,'custom','g:ia');
|
| 307 |
return $date;
|
| 308 |
}
|
| 309 |
|
| 310 |
function theme_activitystream_username($user) {
|
| 311 |
$arrNames = split(' ',$user->name);
|
| 312 |
if (user_access('access user profiles')) {
|
| 313 |
return l($arrNames[0],'user/' . $user->uid);
|
| 314 |
} else {
|
| 315 |
return $arrNames[0];
|
| 316 |
}
|
| 317 |
}
|
| 318 |
|
| 319 |
function theme_activitystream_view($activity) {
|
| 320 |
$node = node_load($activity->nid);
|
| 321 |
$icon_theme = $activity->module.'_icon';
|
| 322 |
$return = '<p class="activitystream-original">See original: ';
|
| 323 |
$return .= theme($icon_theme,$activity->data) . ' ' . l($node->title, $activity->link);
|
| 324 |
$return .= '</p>';
|
| 325 |
return $return;
|
| 326 |
}
|
| 327 |
|
| 328 |
|
| 329 |
function activitystream_cron() {
|
| 330 |
$result = db_query('SELECT uid, userid, password, feed, module from {activitystream_accounts}');
|
| 331 |
while ($user = db_fetch_object($result)) {
|
| 332 |
activitystream_invoke_streamapi($user);
|
| 333 |
}
|
| 334 |
}
|
| 335 |
|
| 336 |
|
| 337 |
/**
|
| 338 |
* Implementation of hook_settings()
|
| 339 |
*/
|
| 340 |
function activitystream_settings() {
|
| 341 |
$form['activitystream_title'] = array(
|
| 342 |
'#type' => 'textfield',
|
| 343 |
'#title' => t('Title'),
|
| 344 |
'#default_value' => variable_get('activitystream_title', 'Activity Stream'),
|
| 345 |
'#description' => t('The title of the Activiy Stream in blocks and User Profiles.')
|
| 346 |
);
|
| 347 |
|
| 348 |
return system_settings_form($form);
|
| 349 |
}
|
| 350 |
|
| 351 |
|
| 352 |
function activitystream_invoke_streamapi($user) {
|
| 353 |
$return = array();
|
| 354 |
if (module_hook($user->module, 'streamapi')) {
|
| 355 |
$items = array();
|
| 356 |
$function = $user->module .'_streamapi';
|
| 357 |
$items = $function($user);
|
| 358 |
if (is_array($items)) {
|
| 359 |
foreach ($items as $activity) {
|
| 360 |
$return[] = _activitystream_save($activity, $user, $user->module);
|
| 361 |
}
|
| 362 |
}
|
| 363 |
}
|
| 364 |
return $return;
|
| 365 |
}
|
| 366 |
|
| 367 |
/**
|
| 368 |
* Shortcut the user_load function if we already have loaded this user.
|
| 369 |
*/
|
| 370 |
function activitystream_user_load($uid) {
|
| 371 |
static $arr_users;
|
| 372 |
if (!is_array($arr_users)) {
|
| 373 |
$arr_users = array();
|
| 374 |
}
|
| 375 |
if ($arr_users[$uid]) {
|
| 376 |
return $arr_users[$uid];
|
| 377 |
} else {
|
| 378 |
$user = user_load(array('uid' => $uid));
|
| 379 |
$arr_users[$uid] = $user;
|
| 380 |
return $user;
|
| 381 |
}
|
| 382 |
}
|
| 383 |
|
| 384 |
function _activitystream_save($activity, $user, $name) {
|
| 385 |
// Find old-style activity guids. We changed to include the uid in the
|
| 386 |
// guid so that we could have multiple users with the same activity.
|
| 387 |
// But this meant that we'd duplicate items. So if we have an old-style
|
| 388 |
// guid, delete the item and re-create it.
|
| 389 |
// This check will be removed in a future version.
|
| 390 |
if (empty($activity['guid']) || !array_key_exists('guid',$activity)) {
|
| 391 |
$activity['guid'] = md5($name,$activity['link']);
|
| 392 |
}
|
| 393 |
else {
|
| 394 |
$activity['guid'] = md5($activity['guid']);
|
| 395 |
}
|
| 396 |
$node = db_fetch_object(db_query("SELECT nid FROM {activitystream} WHERE guid = '%s'", $activity['guid']));
|
| 397 |
if ($node->nid) {
|
| 398 |
node_delete($node->nid);
|
| 399 |
}
|
| 400 |
// End old-style guid check.
|
| 401 |
|
| 402 |
if (empty($activity['guid']) || !array_key_exists('guid',$activity)) {
|
| 403 |
$activity['guid'] = md5($name.$activity['link'].$user->uid);
|
| 404 |
}
|
| 405 |
else {
|
| 406 |
$activity['guid'] = md5($activity['guid'].$user->uid);
|
| 407 |
}
|
| 408 |
if (empty($activity['link'])) {
|
| 409 |
$activity['link'] = '';
|
| 410 |
}
|
| 411 |
if (empty($activity['data'])) {
|
| 412 |
$activity['data'] = '';
|
| 413 |
}
|
| 414 |
$node = db_fetch_object(db_query("SELECT nid, changed FROM {activitystream} WHERE guid = '%s'",$activity['guid']));
|
| 415 |
if ($node->nid) {
|
| 416 |
$changed = $node->changed;
|
| 417 |
$node = node_load($node->nid);
|
| 418 |
if ($changed != $node->changed) {
|
| 419 |
return $node->nid;
|
| 420 |
}
|
| 421 |
$new = false;
|
| 422 |
}
|
| 423 |
else {
|
| 424 |
$node = new stdClass();
|
| 425 |
$new = true;
|
| 426 |
$options = variable_get('node_options_activitystream', FALSE);
|
| 427 |
if (is_array($options)) {
|
| 428 |
$node->status = in_array('status', $options) ? 1 : 0;
|
| 429 |
$node->promote = in_array('promote', $options) ? 1 : 0;
|
| 430 |
$node->sticky = in_array('sticky', $options) ? 1 : 0;
|
| 431 |
}
|
| 432 |
else {
|
| 433 |
$node->status = 1;
|
| 434 |
}
|
| 435 |
}
|
| 436 |
// Has the source changed? If not, we don't want to update the node
|
| 437 |
$source_changed = ($node->title == $activity['title'] && $node->body == $activity['body']) ? false : true;
|
| 438 |
if ($source_changed || $new) {
|
| 439 |
// Only save if if the source has changed or this is a new item
|
| 440 |
$node->title = $activity['title'];
|
| 441 |
$node->body = $activity['body'];
|
| 442 |
$node->created = $activity['timestamp'];
|
| 443 |
$node->uid = $user->uid;
|
| 444 |
$node->type = 'activitystream';
|
| 445 |
if ($new) {
|
| 446 |
node_object_prepare($node);
|
| 447 |
node_save($node);
|
| 448 |
$actions = db_query('INSERT into {activitystream} (nid, module, guid, link, data, changed) VALUES (%d,\'%s\', \'%s\',\'%s\',\'%s\', %d)', $node->nid, $name, $activity['guid'], $activity['link'], $activity['data'], $node->changed);
|
| 449 |
watchdog('activitystream', t('Added %title from %name', array('%title' => $node->title, '%name' => $name)));
|
| 450 |
} else {
|
| 451 |
node_save($node);
|
| 452 |
watchdog('activitystream', t('Updated %title from %name', array('%title' => $node->title, '%name' => $name)));
|
| 453 |
$actions = db_query('UPDATE {activitystream} SET changed = %d', $node->changed);
|
| 454 |
}
|
| 455 |
}
|
| 456 |
return $node->nid;
|
| 457 |
}
|
| 458 |
|
| 459 |
function activitystream_views_tables() {
|
| 460 |
$tables = array();
|
| 461 |
$tables['activitystream'] = array(
|
| 462 |
'name' => 'activitystream',
|
| 463 |
'provider' => 'internal',
|
| 464 |
'join' => array(
|
| 465 |
'left' => array(
|
| 466 |
'table' => 'node',
|
| 467 |
'field' => 'nid'
|
| 468 |
),
|
| 469 |
'right' => array(
|
| 470 |
'table' => 'activitystream',
|
| 471 |
'field' => 'nid'
|
| 472 |
)
|
| 473 |
),
|
| 474 |
'fields' => array(
|
| 475 |
'source' => array(
|
| 476 |
'name' => t('Activity Stream: Source'),
|
| 477 |
'handler' => array(
|
| 478 |
'views_handler_field_profile_default' => t('Source')
|
| 479 |
)
|
| 480 |
),
|
| 481 |
'data' => array(
|
| 482 |
'name' => t('Activity Stream: Icon'),
|
| 483 |
'handler' => array(
|
| 484 |
'activitystream_views_handler_field_icon' => t('Icon')
|
| 485 |
)
|
| 486 |
),
|
| 487 |
'link' => array(
|
| 488 |
'name' => t('Activity Stream: Link'),
|
| 489 |
'handler' => array(
|
| 490 |
'activitystream_views_handler_field_link' => t('Link')
|
| 491 |
)
|
| 492 |
)
|
| 493 |
),
|
| 494 |
'filters' => array(
|
| 495 |
'module' => array(
|
| 496 |
'name' => t('Activity Stream: Type'),
|
| 497 |
'list' => '_activitystream_views_handler_filter_type',
|
| 498 |
'list-type' => 'list',
|
| 499 |
'operator' => 'views_handler_operator_or',
|
| 500 |
'value-type' => 'array',
|
| 501 |
'help' => t('Include or exclude streams of the selected types.')
|
| 502 |
)
|
| 503 |
)
|
| 504 |
);
|
| 505 |
|
| 506 |
return $tables;
|
| 507 |
}
|
| 508 |
|
| 509 |
function _activitystream_views_handler_filter_type() {
|
| 510 |
$sources = array();
|
| 511 |
$module_list = module_rebuild_cache();
|
| 512 |
$implementing_modules = module_implements('streamapi');
|
| 513 |
foreach ($implementing_modules as $module_name) {
|
| 514 |
$sources[$module_name] = $module_list[$module_name]->info['name'];
|
| 515 |
}
|
| 516 |
return $sources;
|
| 517 |
}
|
| 518 |
|
| 519 |
function activitystream_views_handler_field_link($fieldinfo, $fielddata, $value, $data) {
|
| 520 |
return l($value, $value);
|
| 521 |
}
|
| 522 |
|
| 523 |
function activitystream_views_handler_field_icon($fieldinfo, $fielddata, $value, $data) {
|
| 524 |
$stream = unserialize($value);
|
| 525 |
$output = sprintf('<img src="%s"/>', $stream['favicon']);
|
| 526 |
return $output;
|
| 527 |
}
|
| 528 |
|
| 529 |
function activitystream_views_style_plugins() {
|
| 530 |
return array(
|
| 531 |
'activitystream' => array(
|
| 532 |
'name' => t('Activity Stream'),
|
| 533 |
'theme' => 'activitystream_views_view'
|
| 534 |
)
|
| 535 |
);
|
| 536 |
}
|
| 537 |
|
| 538 |
function theme_activitystream_views_view($view, $nodes, $type) {
|
| 539 |
$datehead = '';
|
| 540 |
$items = array();
|
| 541 |
foreach ($nodes as $node) {
|
| 542 |
$action = node_load($node->nid);
|
| 543 |
if (date('Ymd', $action->created) != $datehead) {
|
| 544 |
$datehead = date('Ymd', $action->created);
|
| 545 |
$items[] = theme('activitystream_header', $action);
|
| 546 |
}
|
| 547 |
|
| 548 |
if (function_exists('theme_' . $action->module .'_item')) {
|
| 549 |
$theme_function = $action->module .'_item';
|
| 550 |
}
|
| 551 |
else {
|
| 552 |
$theme_function = 'activitystream_item';
|
| 553 |
}
|
| 554 |
$items[] = theme($theme_function, $action);
|
| 555 |
}
|
| 556 |
return theme('activitystream', $items);
|
| 557 |
}
|
| 558 |
|
| 559 |
function activitystream_views_default_views() {
|
| 560 |
$view = new stdClass();
|
| 561 |
$view->name = 'activity_stream_delicious';
|
| 562 |
$view->description = t('Displays the activity stream for Delicious only.');
|
| 563 |
$view->access = array();
|
| 564 |
$view->view_args_php = '';
|
| 565 |
$view->page = TRUE;
|
| 566 |
$view->page_title = 'Delicious Activity';
|
| 567 |
$view->page_header = '';
|
| 568 |
$view->page_header_format = '1';
|
| 569 |
$view->page_footer = '';
|
| 570 |
$view->page_footer_format = '1';
|
| 571 |
$view->page_empty = '';
|
| 572 |
$view->page_empty_format = '1';
|
| 573 |
$view->page_type = 'activitystream';
|
| 574 |
$view->url = 'users/$arg/delicious';
|
| 575 |
$view->use_pager = FALSE;
|
| 576 |
$view->nodes_per_page = '50';
|
| 577 |
$view->sort = array (
|
| 578 |
);
|
| 579 |
$view->argument = array (
|
| 580 |
array (
|
| 581 |
'type' => 'uid',
|
| 582 |
'argdefault' => '1',
|
| 583 |
'title' => '',
|
| 584 |
'options' => '',
|
| 585 |
'wildcard' => '',
|
| 586 |
'wildcard_substitution' => '',
|
| 587 |
),
|
| 588 |
);
|
| 589 |
$view->field = array (
|
| 590 |
);
|
| 591 |
$view->filter = array (
|
| 592 |
array (
|
| 593 |
'tablename' => 'node',
|
| 594 |
'field' => 'status',
|
| 595 |
'operator' => '=',
|
| 596 |
'options' => '',
|
| 597 |
'value' => '1',
|
| 598 |
),
|
| 599 |
array (
|
| 600 |
'tablename' => 'node',
|
| 601 |
'field' => 'type',
|
| 602 |
'operator' => 'OR',
|
| 603 |
'options' => '',
|
| 604 |
'value' => array (
|
| 605 |
0 => 'activitystream',
|
| 606 |
),
|
| 607 |
),
|
| 608 |
array (
|
| 609 |
'tablename' => 'activitystream',
|
| 610 |
'field' => 'module',
|
| 611 |
'operator' => 'OR',
|
| 612 |
'options' => '',
|
| 613 |
'value' => array (
|
| 614 |
0 => 'activitystream_delicious',
|
| 615 |
),
|
| 616 |
),
|
| 617 |
);
|
| 618 |
$view->exposed_filter = array();
|
| 619 |
$view->requires = array('node', 'activitystream');
|
| 620 |
$views[$view->name] = $view;
|
| 621 |
|
| 622 |
$view = new stdClass();
|
| 623 |
$view->name = 'activity_stream_digg';
|
| 624 |
$view->description = t('Displays the activity stream for Digg only.');
|
| 625 |
$view->access = array();
|
| 626 |
$view->view_args_php = '';
|
| 627 |
$view->page = TRUE;
|
| 628 |
$view->page_title = 'Digg Activity';
|
| 629 |
$view->page_header = '';
|
| 630 |
$view->page_header_format = '1';
|
| 631 |
$view->page_footer = '';
|
| 632 |
$view->page_footer_format = '1';
|
| 633 |
$view->page_empty = '';
|
| 634 |
$view->page_empty_format = '1';
|
| 635 |
$view->page_type = 'activitystream';
|
| 636 |
$view->url = 'users/$arg/digg';
|
| 637 |
$view->use_pager = TRUE;
|
| 638 |
$view->nodes_per_page = '50';
|
| 639 |
$view->sort = array();
|
| 640 |
$view->argument = array (
|
| 641 |
array (
|
| 642 |
'type' => 'uid',
|
| 643 |
'argdefault' => '1',
|
| 644 |
'title' => '',
|
| 645 |
'options' => '',
|
| 646 |
'wildcard' => '',
|
| 647 |
'wildcard_substitution' => '',
|
| 648 |
),
|
| 649 |
);
|
| 650 |
$view->field = array (
|
| 651 |
);
|
| 652 |
$view->filter = array (
|
| 653 |
array (
|
| 654 |
'tablename' => 'node',
|
| 655 |
'field' => 'status',
|
| 656 |
'operator' => '=',
|
| 657 |
'options' => '',
|
| 658 |
'value' => '1',
|
| 659 |
),
|
| 660 |
array (
|
| 661 |
'tablename' => 'node',
|
| 662 |
'field' => 'type',
|
| 663 |
'operator' => 'OR',
|
| 664 |
'options' => '',
|
| 665 |
'value' => array (
|
| 666 |
0 => 'activitystream',
|
| 667 |
),
|
| 668 |
),
|
| 669 |
array (
|
| 670 |
'tablename' => 'activitystream',
|
| 671 |
'field' => 'module',
|
| 672 |
'operator' => 'OR',
|
| 673 |
'options' => '',
|
| 674 |
'value' => array (
|
| 675 |
0 => 'activitystream_digg',
|
| 676 |
),
|
| 677 |
),
|
| 678 |
);
|
| 679 |
$view->exposed_filter = array();
|
| 680 |
$view->requires = array('node', 'activitystream');
|
| 681 |
$views[$view->name] = $view;
|
| 682 |
|
| 683 |
$view = new stdClass();
|
| 684 |
$view->name = 'activity_stream_twitter';
|
| 685 |
$view->description = t('Displays the activity stream for Twitter only.');
|
| 686 |
$view->access = array();
|
| 687 |
$view->view_args_php = '';
|
| 688 |
$view->page = TRUE;
|
| 689 |
$view->page_title = 'Twitter Activity';
|
| 690 |
$view->page_header = '';
|
| 691 |
$view->page_header_format = '1';
|
| 692 |
$view->page_footer = '';
|
| 693 |
$view->page_footer_format = '1';
|
| 694 |
$view->page_empty = '';
|
| 695 |
$view->page_empty_format = '1';
|
| 696 |
$view->page_type = 'activitystream';
|
| 697 |
$view->url = 'users/$arg/twitter';
|
| 698 |
$view->use_pager = TRUE;
|
| 699 |
$view->nodes_per_page = '50';
|
| 700 |
$view->sort = array();
|
| 701 |
$view->argument = array (
|
| 702 |
array (
|
| 703 |
'type' => 'uid',
|
| 704 |
'argdefault' => '1',
|
| 705 |
'title' => '',
|
| 706 |
'options' => '',
|
| 707 |
'wildcard' => '',
|
| 708 |
'wildcard_substitution' => '',
|
| 709 |
),
|
| 710 |
);
|
| 711 |
$view->field = array (
|
| 712 |
array (
|
| 713 |
'tablename' => 'node',
|
| 714 |
'field' => 'title',
|
| 715 |
'label' => '',
|
| 716 |
'handler' => 'views_handler_field_nodelink',
|
| 717 |
'options' => 'link',
|
| 718 |
),
|
| 719 |
array (
|
| 720 |
'tablename' => 'node',
|
| 721 |
'field' => 'created',
|
| 722 |
'label' => '',
|
| 723 |
'handler' => 'views_handler_field_since',
|
| 724 |
),
|
| 725 |
array (
|
| 726 |
'tablename' => 'activitystream',
|
| 727 |
'field' => 'data',
|
| 728 |
'label' => '',
|
| 729 |
'handler' => 'activitystream_views_handler_field_feed_icon',
|
| 730 |
),
|
| 731 |
);
|
| 732 |
$view->filter = array (
|
| 733 |
array (
|
| 734 |
'tablename' => 'node',
|
| 735 |
'field' => 'status',
|
| 736 |
'operator' => '=',
|
| 737 |
'options' => '',
|
| 738 |
'value' => '1',
|
| 739 |
),
|
| 740 |
array (
|
| 741 |
'tablename' => 'node',
|
| 742 |
'field' => 'type',
|
| 743 |
'operator' => 'OR',
|
| 744 |
'options' => '',
|
| 745 |
'value' => array (
|
| 746 |
0 => 'activitystream',
|
| 747 |
),
|
| 748 |
),
|
| 749 |
array (
|
| 750 |
'tablename' => 'activitystream',
|
| 751 |
'field' => 'module',
|
| 752 |
'operator' => 'OR',
|
| 753 |
'options' => '',
|
| 754 |
'value' => array (
|
| 755 |
0 => 'activitystream_twitter',
|
| 756 |
),
|
| 757 |
),
|
| 758 |
);
|
| 759 |
$view->exposed_filter = array();
|
| 760 |
$view->requires = array('node', 'activitystream');
|
| 761 |
$views[$view->name] = $view;
|
| 762 |
|
| 763 |
return $views;
|
| 764 |
}
|