function activity_json in Activity 5.3
Same name and namespace in other branches
- 5.4 activity.module \activity_json()
- 6 activity.module \activity_json()
output our activity as json $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 579 - Activity module: Allow users to see their friends' activity on the site.
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;
}