i've added a block which shows the activity for a particular user, as well as the site-wide activity streams.

CommentFileSizeAuthor
#2 users_stream.patch1.3 KBGeorge2
users_stream.patch1.29 KBGeorge2

Comments

akalsey’s picture

Status: Needs review » Needs work

Looks good. I'd suggesting using the activitystream_user_load() function instead of user_load. The module loads user details quite often and user_load() isn't cached. For this reason, the module provides activitystream_user_load() as a wrapper around user_load().

In the case of this patch, we'd only need to call user_load once instead of twice.

It takes one parameter, a uid, and returns the user object for that uid.

<?php
$user = activitystream_user_load($uid);
?>
George2’s picture

StatusFileSize
new1.3 KB
George2’s picture

Status: Needs work » Needs review
akalsey’s picture

Version: 6.x-1.0-beta2 » 6.x-2.x-dev
Status: Needs review » Fixed

Applied to 6.x-2.0

pribeh’s picture

K, last time I'm asking for help porting stuff back to good old Drupal 5. I'm trying to get this working with 5.x-1.3 (along with panels and APK). I've managed to patch "hook_block()" in D5 AS with the patch here (almost) successfully. I've selected the block to be shown on user profiles (via panels interface) and I get the following error message whilst viewing a user profile:

warning: Missing argument 1 for arg(), called in activitymodule on line 793 - which is:

 $arg = arg();
        if (count($arg) == 2 && $arg[0] == 'user' && is_numeric($arg[1]) && ($user = activitystream_user_load($arg[1]))) {
          $block['subject'] = t('My activity');
          $block['content'] = block_activitystream_content(1, $user);
        }
      
    }
    return $block;
  }
}

.. defined in /includes/path.inc on line 148 - which is:

function arg($index) {
  static $arguments, $q;

  if (empty($arguments) || $q != $_GET['q']) {
    $arguments = explode('/', $_GET['q']);
    $q = $_GET['q'];
  }

  if (isset($arguments[$index])) {
    return $arguments[$index];
  }
}

I promise, last time. If you'd like me to file this as a separate issue I will.

George2’s picture

you've got your problem (and answer) right there - in 5, arg() demands an argument and only returns one part of q, unlike 6.

so, use the value of $_GET['q'] just like the function and explode, just like that function

pribeh’s picture

Thanks for helping George,

I figured that out by looking through my php book, threw $_GET['q] inside the brackets, which fixed the error message but I still don't get a block appearing on profile pages. Sorry, I'm horrible at php still. What am I doing wrong? Here's what my hook_block looks like:

function activitystream_block($op = 'list', $delta = 0) {
  if ($op == 'list') {
    $blocks[0]['info'] = variable_get('activitystream_title', 'Activity Stream');
    $blocks[1]['info'] = t('User\'s activity stream');
   
    return $blocks;
  }
  else if ($op == 'view') {
    $block = array();
    switch ($delta) {
      case 0:
        $title = variable_get('activitystream_title', 'Activity Stream');
        $block['subject'] = t($title);
        $block['content'] = block_activitystream_content(0);
        break;

      case 1:
        // basic validation
        $arg = arg($_GET['q']);
        if (count($arg) == 2 && $arg[0] == 'user' && is_numeric($arg[1]) && ($user = activitystream_user_load($arg[1]))) {
          $block['subject'] = t('My activity');
          $block['content'] = block_activitystream_content(1, $user);
        }
      
    }
    return $block;
  }
}

 
function block_activitystream_content($which_block) {
  switch ($which_block) {
    case 0:
      $items = _activitystream_get_activity();
      return theme('activitystream', $items);
    case 1:
      $args = func_get_args();
      $items = _activitystream_get_activity($args[1]);
      return theme('activitystream', $items);
  }
}
George2’s picture

i think it's best to start up a new issue, and if you're new to php, maybe you shouldn't be working on a module yet ;)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.