I just upgraded to 5.x-4.x-dev, thinking it had a solution to this problem:

Display the activity information consistently in a block / panels embed in the user profile
+ I am using Advanced Profile & Panels 2

I have the same problem as 3.x --> the activity information displays for the logged in user
"You updated the user profile [node-title-link]"
but it does not display correctly for other users viewing the profile page
"Admin updated the user profile [node-title-link]"

Additionally, the logged in user's activity will display on the block of other user's profiles, rather than the information related to the profile user ID being viewed.

Feature request / documentation request is - how to configure this correctly for profiles, panels, using the "activity mine" block or custom code.

I reviewed / tested most of the other issues and posts on this but did not find the solution.

Note: I had some installation issues & now problems with token substitution in 4.x-dev, so I may downgrade to 3.x again, unless the solution is contingent on the new version.

Comments

jaydub’s picture

There is an (My) activity block which shows the activity of the logged in user.

There is a list of a user's activity that shows on the user's profile page which will reflect the activity of the user profile in question which would be your activity (You) if you are viewing your own profile and the respective user's activity (Username) if you are viewing another user's profile.

There isn't any working integration with APK and activity at this point but if you can get user profile data in a panel via APK and/or panels, then you can get the user's activity via the profile already.

hope that makes sense...

regarding problems with token substitution there are a lot of changes in tokens and other areas of the various contrib modules and until we get to a beta release upgrades of old data are not yet in place.

jaydub’s picture

Component: Documentation » Code
alfaguru’s picture

There is a simple solution to this issue: add a new token to replace the word "you" in the messages, then return either "you" or the username depnding on what the current user is. Here's some sample code I put in an in-development activity_panels module to save patching the core activity module:

function activity_panels_token_list($type = 'activity') {
  if ($type == 'activity') {
    $tokens['activity'] = array(
      'maybe-You' => t("The name of the user or the word 'You' if it's you"),
      'maybe-you' => t("The name of the user or the word 'you' if it's you"),
    );
    return $tokens;
  }
}

function activity_panels_token_values($type, $data = NULL, $options = array()) {
  if ($type == 'activity' && !empty($data)) {
    global $user;
    $is_you = $user->uid == $data['author-uid'];
    $tokens = array(
      'maybe-You' => $is_you? t('You'): $data['author-name'],
      'maybe-you' => $is_you? t('you'): $data['author-name'],
    );
    return $tokens;
  }
}

function bulk_update() {
  $variables = variable_init();
  foreach ($variables as $name=>$value) {
    if(is_string($value) && strpos($name, 'activity') !== false && substr($value, 0, 4) == 'You ') {
      $value = '[maybe-You] '.substr($value, 4);
      variable_set($name, $value);
    }
  }
}

The bulk_update function performs a one-time only migration of the relevant variables. Call it from some convenient place in the code then remove it.

timmillwood’s picture

I have just created a small module ("activity_block") which displays the activity for the user who's profile is being viewed. I have then put this block in as a panel pane.

function activity_block_block($op = 'list', $delta = 0, $edit = array()) {
  global $user;

  switch ($op) {
    case 'list':
      $block['users']['info'] = t("Activity: users: show the user's being viewed activity.");
      return $block;
      break;

    case 'configure':
      $form['items'] = array(
        '#type' => 'select',
        '#title' => t('Number of activity items to display'),
        '#default_value' => variable_get('activity_block_'. $delta, 5),
        '#options' => drupal_map_assoc(range(1, 50)),
      );
      return $form;
      break;

    case 'save':
      variable_set('activity_block_'. $delta, $edit['items']);
      break;

    case 'view':
      switch ($delta) {
        case 'users':
          if (user_access('view own activity')) {
            // Grab the number of requested activities plus one. We use this one
            // to determine whether or not to show the "more" link and only display
            // the correct number of items.
            $activity = activity_get_activity(arg(1), NULL, variable_get('activity_block_'. $delta, 5) + 1);
            if ($count = count($activity)) {
              drupal_add_css(drupal_get_path('module', 'activity') .'/activity.css');
              
              $activities = array();
              foreach ($activity as $item) {
                $activities[] = theme('activity', activity_token_replace($item), $item) . activity_delete_link($item);
              }
              return array(
                'subject' => t('Users activity'),
                'content' => theme('activity_block', $activities, $more_link)
              );
            }
          }
          break;
      }
      break;
  }
}
bflora’s picture

Is it possible to use this code in the last post somehow without creating a whole new module to slow down my Drupal site? can I toss this code in my template.tpl.php file and do something with it there?

I was using the following code with Activity 5.2 to create an activity feed on user profiles:

 <?php
if (module_exists('activity')) { ?>   
         <?php
//PRINT RECENT ACTIVITY
  $activities = activity_get_activity(arg(1), NULL, 5);
  $table = activity_table($activities);
  
  print ('<div>'.theme('activity_page', $activities, $table).'</div>');
?><?php } ?>

But it doesn't appear to work anymore now that I've upgraded to 5.4. A lightweight solution like this would be tremendous. Thanks

sirkitree’s picture

Status: Active » Closed (won't fix)

5.x unsupported please see 6.x-2