You are here

function activity_feed in Activity 5.4

Same name and namespace in other branches
  1. 5 activity.module \activity_feed()
  2. 5.2 activity.module \activity_feed()
  3. 5.3 activity.module \activity_feed()
  4. 6 activity.module \activity_feed()

Menu callback for displaying site or user activity as an RSS feed.

1 string reference to 'activity_feed'
activity_menu in ./activity.module
Implementation of hook_menu().

File

./activity.module, line 735
activity.module

Code

function activity_feed($arg) {
  global $locale;
  if ($arg == ACTIVITY_ALL) {
    $activities = activity_get_activity(ACTIVITY_ALL, NULL, variable_get('activity_page_pager', 20));
    $url = url('activity/all', NULL, NULL, TRUE);
    $feed_title = t('All activity');
  }
  else {
    if (is_numeric($arg)) {
      $user = db_fetch_object(db_query('SELECT uid, name FROM {users} WHERE uid = %d', $arg));
      if ($user) {
        $activities = activity_get_activity($arg, NULL, variable_get('activity_page_pager', 20));
        $url = url('activity/' . $user->uid, NULL, NULL, TRUE);
        $feed_title = t('Activity for @username', array(
          '@username' => $user->name,
        ));
      }
    }
  }
  if (count($activities) > 0) {
    foreach ($activities as $activity) {
      $function = $activity['module'] . '_format_rss_item';
      if (function_exists($function)) {

        // Each module gets a chance to build its own feed item.
        // They should use the $activity to prepare variables and
        // call format_rss_item($title, $link, $item_text, $extra);
        $items .= $function($activity);
      }
      else {
        $message = activity_token_replace($activity);
        $items .= format_rss_item(strip_tags($message), url('activity/' . $user->uid, NULL, NULL, TRUE), format_date($activity['created']) . '<p>' . $message . '</p>');
      }
    }
  }
  $channel = array(
    'version' => '2.0',
    'title' => variable_get('site_name', 'Drupal') . ' - ' . $feed_title,
    'link' => $url,
    'description' => variable_get('site_mission', ''),
    'language' => $locale,
  );

  // @todo Figure out what the right namespace should be.
  $namespaces = array(
    'xmlns:dc="http://purl.org/dc/elements/1.1/"',
  );
  $output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
  $output .= "<rss version=\"" . $channel["version"] . "\" xml:base=\"" . $url . "\" " . implode(' ', $namespaces) . ">\n";
  $output .= format_rss_channel($channel['title'], $channel['link'], $channel['description'], $items, $channel['language']);
  $output .= "</rss>\n";
  drupal_set_header('Content-Type: application/rss+xml; charset=utf-8');
  print $output;
}