You are here

function activity_json in Activity 6

Same name and namespace in other branches
  1. 5.4 activity.module \activity_json()
  2. 5.3 activity.module \activity_json()

Output activity as JSON.

Parameters

$arg: An array of the following: $arg[0] = ACTIVITY_ALL or $uid $arg[1] = number of activities to retreive

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

File

./activity.module, line 952
activity.module

Code

function activity_json($arg) {
  global $language;
  $args = func_get_args();
  if ($args[0] == ACTIVITY_ALL) {

    // get the latest activity posted
    $activities = activity_get_activity(ACTIVITY_ALL, NULL, $args[1]);
    $url = url('activity/all', array(
      'absolute' => TRUE,
    ));
    $feed_title = t('All activity');
  }
  else {
    if (is_object($args[0])) {

      // get the latest activity posted pertaining to this user
      $activities = activity_get_activity($arg->uid, NULL, $args[1]);
      $url = url('activity/' . $arg->uid, array(
        'absolute' => TRUE,
      ));
      $feed_title = t('Activity for @username', array(
        '@username' => theme('username', $arg),
      ));
    }
  }
  if (count($activities) > 0) {
    foreach ($activities as $activity) {
      $message = activity_token_replace($activity);
      $items .= '<item><date>' . format_date($activity['created'], 'small') . '</date>';
      $items .= '<url>' . url('activity/' . $user->uid, array(
        'absolute' => TRUE,
      )) . '</url>';
      $items .= '<message>' . $message . '</message></item>';
    }
  }
  drupal_set_header('Content-Type: application/x-javascript');
  print drupal_to_js($items);
  die;
}