diff --git a/sites/all/modules/contrib/activitystream/activitystream.install b/sites/all/modules/contrib/activitystream/activitystream.install index 42c6b64..195706b 100644 --- a/sites/all/modules/contrib/activitystream/activitystream.install +++ b/sites/all/modules/contrib/activitystream/activitystream.install @@ -35,6 +35,7 @@ function activitystream_schema() { $schema['activitystream'] = array( 'fields' => array( 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), + 'nid_ref' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'default' => 0, 'disp-width' => '10'), 'module' => array('type' => 'varchar', 'length' => '255', 'not null' => FALSE), 'guid' => array('type' => 'varchar', 'length' => '32', 'not null' => TRUE), 'link' => array('type' => 'varchar', 'length' => '255'), @@ -54,6 +55,16 @@ function activitystream_schema() { 'feed' => array('type' => 'varchar', 'length' => '255', 'not null' => FALSE), 'lastfetch' => array('type' => 'datetime', 'not null' => FALSE)), ); + + $schema['activitystream_node_accounts'] = array( + 'fields' => array( + 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), + 'module' => array('type' => 'varchar', 'length' => '255', 'not null' => FALSE), + 'userid' => array('type' => 'varchar', 'length' => '255', 'not null' => FALSE), + 'password' => array('type' => 'varchar', 'length' => '255', 'not null' => FALSE), + 'feed' => array('type' => 'varchar', 'length' => '255', 'not null' => FALSE), + 'lastfetch' => array('type' => 'datetime', 'not null' => FALSE)), + ); return $schema; } diff --git a/sites/all/modules/contrib/activitystream/activitystream.module b/sites/all/modules/contrib/activitystream/activitystream.module index 2453209..01515f7 100644 --- a/sites/all/modules/contrib/activitystream/activitystream.module +++ b/sites/all/modules/contrib/activitystream/activitystream.module @@ -70,6 +70,30 @@ function activitystream_menu() { 'access arguments' => array('access administration pages'), 'type' => MENU_NORMAL_ITEM, ); + + $items['node/%node/activitystream'] = array( + 'title' => variable_get('activitystream_title', 'Activity Stream'), + 'page callback' => 'activitystream_node', + 'page arguments' => array(1), + 'access callback' => 'activitystream_node_type_access', + 'access arguments' => array(1), + 'type' => MENU_LOCAL_TASK, + ); + + $items['node/%node/edit/main'] = array( + 'title' => t('Main'), + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'weight' => -100, + ); + + $items['node/%node/edit/activitystream'] = array( + 'title' => variable_get('activitystream_title', 'Activity Stream'), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('activitystream_node_edit'), + 'access callback' => 'activitystream_node_type_access', + 'access arguments' => array(1), + 'type' => MENU_LOCAL_TASK, + ); $items['stream/feed'] = array( 'title' => 'Activity Stream Feed', @@ -172,8 +196,12 @@ function activitystream_form(&$node) { * Implementation of hook_user() */ function activitystream_user($op, &$edit, &$account, $category = NULL) { + $types = variable_get('activitystream_node_types', array('user' => 'user')); + if (!$types['user']) { + return FALSE; + } switch ($op) { - case 'categories': + case 'categories': return array( array( 'name' => 'activitystream', @@ -579,6 +607,18 @@ function activitystream_settings() { '#attributes' => array('onchange' => 'activitystream_vocabulary_check_new(this)') ); } + $options = array('user' => 'User'); + $options = array_merge($options, node_get_types('names')); + unset($options['activitystream']); + + $form['activitystream_node_types'] = array( + '#type' => 'checkboxes', + '#title' => t('Node Types'), + '#default_value' => variable_get('activitystream_node_types', array('user')), + '#description' => t('Node types to associate with an Activity Stream.'), + '#options' => $options, + ); + $form['advanced'] = array( '#type' => 'fieldset', @@ -853,3 +893,148 @@ function block_activitystream_content($which_block) { return theme('activitystream_block', $items, array('uid' => $args[1])); } } + +/* + * Get Activity Stream content + */ +function activitystream_get_node_activity($node, $count = NULL) { + if ($count == NULL) { + $count = variable_get('default_nodes_main', 10); + } + + $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 s.nid_ref = " . $node->nid . " ORDER BY n.created DESC"; + $countquery = "SELECT count(*) FROM {activitystream} s, {node} n WHERE s.nid=n.nid AND n.status =1 AND s.nid_ref = " . $node->nid; + + $items = array(); + $stream = pager_query($query, $count, 0, $countquery); + while ($action = db_fetch_object($stream)) { + $items[] = $action; + } + + $return = array(); + $datehead = ''; // initialize to blank so date header will appear on first item + foreach ($items as $action) { + if (date('Ymd', $action->created) != $datehead) { + $datehead = date('Ymd', $action->created); + $return[$datehead]['title'] = theme('activitystream_header', $action); + } + + if (function_exists('theme_'. $action->module .'_item')) { + $theme_function = $action->module .'_item'; + } + else { + $theme_function = 'activitystream_item'; + } + + $return[$datehead]['items'][] = theme($theme_function, $action); + } + return $return; +} + +/** + * Access callback for node local task. + */ + +function activitystream_node_type_access($node) { + $types = variable_get('activitystream_node_types',array('user' => 'user')); + return ($types[$node->type] && user_access('access administration pages')); +} + +/** + * View the Activity Stream for a node + */ + +function activitystream_node($node) { + $items = activitystream_get_node_activity($node); + $title = variable_get('activitystream_title', 'Activity Stream'); + + return theme('activitystream', $items); +} + +/** + * Edit the Activity Stream settings for a node + */ + +function activitystream_node_edit() { + $form = array(); + + foreach (module_implements('activitystream_settings') as $name) { + if (user_access('use '. $name)) { + $function = $name .'_activitystream_settings'; + $elements = $function($edit); + foreach ($elements as $key => $value) { + $form[$key] = $value; + } + } + } + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Save'), + ); + + return $form; +} + +/** + * Save the Activity Stream settings for a node + */ + +function activitystream_node_edit_submit($form, $form_state) { + $nid = arg(1); + foreach (module_implements('activitystream_settings') as $name) { + $arrdetails = array(); + $arrdetails['userid'] = (array_key_exists($name .'_userid', $form_state['values'])) ? $form_state['values'][$name .'_userid'] : NULL; + $arrdetails['password'] = (array_key_exists($name .'_password', $form_state['values'])) ? ($form_state['values'][$name .'_password']) : NULL; + $arrdetails['feed'] = (array_key_exists($name .'_feed', $form_state['values'])) ? $form_state['values'][$name .'_feed'] : NULL; + activitystream_node_save_account($name, $nid, $arrdetails); + } +} + +/* + * Copy of activitystream_save_account() for node implementation + */ +function activitystream_node_save_account($module, $nid, $params) { + if (count($params) == 0) { + return FALSE; + } + $result = db_query('DELETE FROM {activitystream_node_accounts} WHERE module = \'%s\' and nid = %d', $module, $nid); + if (empty($params['userid']) && empty($params['password']) && empty($params['feed'])) { + return; + } + // Save multiline feed fields each to a different feed + $arrfeeds = split("\n", $params['feed']); + $nodes = array(); + foreach ($arrfeeds as $url) { + $params['feed'] = $url; + $result = db_query('INSERT INTO {activitystream_node_accounts} (module, uid, userid, password, feed) VALUES (\'%s\', %d, \'%s\', \'%s\', \'%s\')', $module, 1, $params['userid'], $params['password'], $params['feed']); + $node = (object) array( + 'nid' => $nid, + 'uid' => 1, + 'userid' => $params['userid'], + 'password' => $params['password'], + 'feed' => $params['feed'], + 'module' => $module + ); + $nodes[] = $node; + } + $num_nodes = activitystream_update_streams($nodes, FALSE); + return TRUE; +} + + +function activitystream_update_node_streams(&$nodes, $use_queue = TRUE) { + $use_job_queue = module_exists('job_queue') ? TRUE : FALSE; + $processed_nodes = array(); + foreach ($nodes as $node) { + if ($use_job_queue && $use_queue) { + job_queue_add('activitystream_invoke_streamapi', 'Activiq!:qqqty Stream Update for '. $node->nid, array($node), '', TRUE); + } else { + activitystream_invoke_streamapi($user); + } + // Update the last fetch time for this user and module. + db_query('UPDATE {activitystream_node_accounts} set lastfetch = now() where nid = %d AND module = \'%s\'', $node->nid, $node->module); + $processed_nodes[$node->nid] = $node->userid; + } + return count($processed_nodes); +} \ No newline at end of file