You are here

function activity_json in Activity 5.4

Same name and namespace in other branches
  1. 5.3 activity.module \activity_json()
  2. 6 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 794
activity.module

Code

function activity_json($arg) {
  global $locale;
  $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', NULL, NULL, TRUE);
    $feed_title = t('All activity');
  }
  else {
    if (is_numeric($args[0])) {
      $user = db_fetch_object(db_query('SELECT uid, name FROM {users} WHERE uid = %d', $args[0]));
      if ($user) {

        // get the latest activity posted pertaining to this user
        $activities = activity_get_activity($arg[0], NULL, $args[1]);
        $url = url('activity/' . $user->uid, NULL, NULL, TRUE);
        $feed_title = t('Activity for @username', array(
          '@username' => theme('username', $user),
        ));
      }
    }
  }
  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, NULL, NULL, TRUE) . '</url>';
      $items .= '<message>' . $message . '</message></item>';
    }
  }
  drupal_set_header('Content-Type: application/x-javascript');
  print drupal_to_js($items);
  die;
}