Is it possible to show an image next to the activity being displayed depending on the node type?.

Kind of what facebook does. Example, if a new 'event' content type is created then I would like to show "calendar.png" next to the activity message. I know this it's possible with css just to show the same image for every message.

but how to show a different image for every content type?

Thanks in advance,

Luis

CommentFileSizeAuthor
#76 dashboard_screenshot.jpg106.24 KBlelizondo

Comments

jaydub’s picture

This is really all about theming the activity output and there are a number of other issues that are similar to this. To that end I am going to rework the default activity output pages to make them themable to a greater degree than they are now.

I'll revisit this issue once those changes have gone into the new branches.

zilla’s picture

could even just pull user picture to start (if present)

lelizondo’s picture

I couldn't find anything really helpful about how to accomplish this... I've found at least 2 similar posts but none of them were really useful.

Can anyone post an example or something? Since I couldn't find any documentation available.

Thanks

Luis

zilla’s picture

@lelizondob - if you DO find something, please let us know! just pulling a user picture would be extremely cool and would make the layout look really nice...

lelizondo’s picture

I found http://drupal.org/node/302216 and http://drupal.org/node/197521 and I would be glad to change this issue to duplicate but none of them were really helpful.

Pulling a user picture would be nice too.

Luis

kleale’s picture

Please help me!! I can't theme user pictures on activity page. All I made was default picture. Plese give some example with theming...

lelizondo’s picture

I'm also asking for some examples. Hope someone finds a solution and share it.

zilla’s picture

i'm beginning to think that for some reason it is the taxonomy image module that will bridge this path - specifically for the 'show a calendar icon' comment way up above in original post

..and alongside that, a call to the user picture - privatemsg module is now doing this for messages, perhaps a quick look into their code will show how it was done? i can't understand it, but the original thread is here: http://drupal.org/node/170387

but activity module - unlike privatemsg - has nothing like "theme_privatemsg_username" to override directly, we'd need a theme_activity_username to override that would inherit for all contrib modules

here are the core d6 themeable elements: http://api.drupal.org/api/group/themeable

here's one possible solution, but it's a HEAVY hackup: http://drupal.org/node/170387#comment-879371

jaydub’s picture

Ok for the activity pages as seen in /activity or /activity/mine you can now customize the output of the table by using a theme override.

The table is generated in the latest snapshots by the theme_activity_table() function as invoked by activity_page() as seen here:

 ...snip...
  else if ($page == 'all') {
    $activities = activity_get_activity(ACTIVITY_ALL, NULL, variable_get('activity_page_pager', 20));
    $table = theme('activity_table', $activities);
    $feed_url =  url('activity/all/feed');
    drupal_add_feed($feed_url);
    $feed = theme('feed_icon', $feed_url);
    return theme('activity_page', $activities, $table);
  }
 ...snip...

theme_activity_table() was formerly just activity_table() and so was not able to overridden:

function theme_activity_table($activities) {
  $display_headers = array(
    'created' => array('field' => 'created', 'data' => t('Date')),
    t('Message'),
  );

  $rows = array();
  foreach ($activities as $activity) {
    if ($activity_message = activity_token_replace($activity)) {
      $rows[] = array(
        theme('activity_timestamp', $activity['created']),
        theme('activity', $activity_message, $activity),
      );
    }
  }
  $output = theme('table', $display_headers, $rows);
  $output .= theme('pager');
  return $output;
}

So if you wanted to say remove the table header, add in a picture and move the time to the end of the activity record then you could add a theme override to your template.php like this:

function phptemplate_activity_table($activities) {
  $rows = array();
  foreach ($activities as $activity) {
    if ($activity_message = activity_token_replace($activity)) {
      $rows[] = array(
        theme('user_picture', $activity['data']['author-uid']),
        theme('activity', $activity_message, $activity) .' - <em>'. format_interval(time() - $activity['created']) .'ago</em>',
      );
    }
  }
  $output = theme('table', array(), $rows);
  $output .= theme('pager');
  return $output;
}
jaydub’s picture

You'd probably want to use something other than theme('user_picture') to draw your user avatars if they are as big as one would normally have. Instead you might have your own custom theme override for theme_user_picture so that you can make use of imagecache for example.

zilla’s picture

this is excellent, though i'm a bit of a novice when it comes to this - some quick questions:

is this in current dev/release (or over coming days)? for D6 or D5 (this original thread is all about the D5 version)

where is that template.php file? is this the main core template.php file or within a theme folder for site theme?

within template.php, where should such a snippet be pasted? top, bottom, does it matter?

jaydub’s picture

The change in the activity page to allow for better theming is changed in both d5 and d6. As far as theming goes and how to handle adding theme overrides to your theme, that's outside the scope of this issue. I suggest you start with the Drupal documentation for theming.

http://drupal.org/theme-guide

And specifically for theme override concepts:

http://drupal.org/node/173880

@lelizondob

with the new theme override possibilities you could change the output as you mentioned to show any arbitrary image based on each row in the table of activity records. For example you could show an image for activity entries for votes, another image for buddylist/User relationships actions, create/update/delete of nodes or comments or even for specific node types.

zilla’s picture

thanks - it's a bit beyond me so i'll need to read up on it...if it winds up in here as a contrib module (like 'display user pictures in activity'), that would be sweeeeet.....

lelizondo’s picture

maybe I'm missing something here

theme_activity_table() was formerly just activity_table() and so was not able to overridden:

are we talking about version 3.0-beta2 or 4? since I couldn't find theme_activity_table

lelizondo’s picture

As I supposed, this only work with version 4.

lelizondo’s picture

Thanks Jeff for the answer, just one more thing.. I finally could theme the activity page to add an image in a new column, but can someone please explain a little bit how to get the node type for:

function theme_activity($message, $item) {
  // $item is the unprocessed activity item so that themers can do more with it.
  return '<span class="activity">'. $message .'</span>';
}

to get something like this:

return '<span class="mynodetype">'. $message .'</span>';

since I can't get this to work for the blocks..

Thanks in advance,

Luis

jaydub’s picture

You can get access to the tokens available for a particular activity message type from the activity array that is available in the last example theme override

function phptemplate_activity_table($activities) {
  $rows = array();
  foreach ($activities as $activity) {
    if ($activity_message = activity_token_replace($activity)) {
      $rows[] = array(
        theme('user_picture', $activity['data']['author-uid']),
        theme('activity', $activity_message, $activity) .' - <em>'. format_interval(time() - $activity['created']) .'ago</em>',
      );
    }
  }
  $output = theme('table', array(), $rows);
  $output .= theme('pager');
  return $output;
}

For example if I dump the values of the $activity array that is part of this loop:


  foreach ($activities as $activity) {
    // $activity array is full of data for this record and available to the theme function here

    if ($activity_message = activity_token_replace($activity)) {
      $rows[] = array(
        theme('user_picture', $activity['data']['author-uid']),

        // $activity array is also passed to theme_activity_message() so that theme function also gets the full data of the record
        theme('activity', $activity_message, $activity) .' - <em>'. format_interval(time() - $activity['created']) .'ago</em>',

      );
    }
  }

I have access to these values (for this particular activity record which happens to be votingapiactivity):

array
  'aid' => string '324' (length=3)
  'module' => string 'votingapiactivity' (length=17)
  'type' => string 'vote' (length=4)
  'operation' => string 'mark' (length=4)
  'created' => string '1224519711' (length=10)
  'data' => 
    array
      'author-uid' => string '1' (length=1)
      'content-id' => string '52' (length=2)
      'content-type' => string 'blog entry' (length=10)
      'content-title' => string 'Wisi Olim Pertineo Brevitas' (length=27)
      'content-link' => string '<a href="/node/52">Wisi Olim Pertineo Brevitas</a>' (length=50)
      'created' => string '1224519711' (length=10)
      'activity_id' => string '324' (length=3)
      'module' => string 'votingapiactivity' (length=17)
      'type' => string 'vote' (length=4)
      'operation' => string 'mark' (length=4)
  'target_uid' => string '-1' (length=2)
  'target_role' => string 'all' (length=3)
  'activity_history_new' => string '' (length=0)

So when you are in theme_activity_table or theme_activity_message you have access to all the data that is available for a particular activity record.

lelizondo’s picture

Thanks a lot Jeff, knowing the values of the array is what I was looking for..

I leave the solution if anyone is interested, it is actually really simple..

function theme_activity($message, $item) {    
  return '<span class="' . $item['type'] .'">'. $message . '</span>';
}

this outputs

<span class="comment">Message</span> 

or

<span calss="nodetype">Mesasage</span>

Which lets me use css to add an image next to the message. Maybe this should go somewhere in the documentation of the module or the handbook..

Thanks again, great module.

Luis

DerTobi75’s picture

I cannot get this work with D6, I copied the phptemplate function into template.php, but it does not overright the existing one :(

Edit: Got it work, sorry, was a caching problem...

minesota’s picture

Well, I avoided touching any of the files (which perhaps has some advantage) but just do it via the administrative interface.

For example :

come to /admin/settings/activity

click Tokens for nodeactivity

click on Messages visible to the "All" role.

come to Blog entry: Create:

Fill the box with something like

<image align=absmiddle src=whatever_path/whatever.gif> [author] penned [node-title-link] [time-ago] ago

lost305’s picture

I do not get this at all. I placed the phptemplate_activity_table function in my template.php and all it did was switch up my /activity page a little and not add the user's picture.

Just to test i took off the

        theme('user_picture', $activity['data']['author-uid']),

in the

function phptemplate_activity_table($activities) {
  $rows = array();
  foreach ($activities as $activity) {
    if ($activity_message = activity_token_replace($activity)) {
      $rows[] = array(
        theme('user_picture', $activity['data']['author-uid']),
        theme('activity', $activity_message, $activity) .' - <em>'. format_interval(time() - $activity['created']) .'ago</em>',
      );
    }
  }
  $output = theme('table', array(), $rows);
  $output .= theme('pager');
  return $output;
}

And no difference. The user name stayed on there.

What am I doing wrong?

Also what I'm looking for is to change this in the block not the page. Doesn't matter to me if it shows it or not on the page but in the block is where I could like to see this change

Please help.

:o(

bflora’s picture

So what's the best way to do this? I'm stunned that no one's worked out a way to do this yet. Activity feeds are becoming widespread on the web....and Drupal doesn't seem to have one that can do it just yet. Check out the one on the home page of http://www.faniq.com to see a pretty nice one. Would be great to be able to replicate that in Drupal.

jaydub’s picture

Did you read the details in #9?

lost305’s picture

Jaydub,

I did exactly that. Please read #21 and the picture didn't show up.

What can I be doing wrong?

bflora’s picture

Do we need to rewrite the "phptemplate" part in the function declaration when adding it to our template.tpl.php file?

I pasted in the code from #9 and saw no change on my /activity page or my activity block.

lost305’s picture

@bflora
I saw a change but I didn't see any user picture and I only saw it in my Activity PAGE, not the block.

What I did was just past that code from #9 in my template.php. Nothing else.

I wish Jaydub would stop ignoring me.
:o(

lost305’s picture

Can someone tell me what I'm doing wrong?

lost305’s picture

Can someone tell me how to do this correctly?

jaydub’s picture

#28 I know it's hard for you to wait but the reality is that the developers are busy right now with their day jobs. I myself will have a window of time to work on activity over the holiday so if you can be patient and wait for development to proceed eventually you'll get what you need :)

michelle’s picture

Thanks, jaydub. This will be an awesome addition to the module. I see this is tagged for 5.x. Is it planned for 6.x as well?

Michelle

jaydub’s picture

Version: 5.x-3.0-beta2 » 5.x-4.x-dev

Both 5 and 6. The Version drop-down only allows for selecting a single item so what can you do...

michelle’s picture

Yeah, I have the same problem. AF is getting developed in parallel between the branches so I just set them all to 6.x.

Thanks for the info. I'll be watching for it.

Michelle

Rosamunda’s picture

subscribing

michelle’s picture

I'm going to be working on the APK / activity integration later today and this is something I need. If you had a chance to work on anything that isn't committed, I'd appreciate a heads up. The more already done, the less I have to do. ;)

Michelle

jaydub’s picture

I'm working through the holidays on this and others. I've added user pictures as a feature but the actual implementation of a user image is most likely going to have to be a custom theme override for the average site since all activity can fall back on in the base module is theme('user_picture') which out of the box will likely return a fairly large size avatar.

michelle’s picture

Oh, good, because I only got as far as the panels integration yesterday. Didn't have as much time to work as I'd hoped.

What I plan on doing with my modules (advanced forum, advanced profile kit) is to make use of imagecache if the site has it installed. I haven't decided, yet, if I just want to set a preset name in code or make it an option in settings. Probably the latter. At any rate, wherever I do theme_user_picture, I would check for imagecache and use imagecache instead if it's set. You might want to consider that for this. Then someone just needs to make an "activity" preset with a smaller avatar.

Totally OT to this issue but thought you might be interested in http://groups.drupal.org/node/17847

Michelle

jaydub’s picture

Yeah the way I've got it is to define an activity theme function for images:

function theme_activity_user_picture($account) {
  return theme('user_picture', $account);
}

So a site can provide whatever image implementation they want by overriding the theme function. I don't want to get into having to account for whether or not imagecache is installed, what is an appropriate imagecache preset etc...

This leaves it all in the hands of the site which is where it belongs I think.

michelle’s picture

That makes sense. It does "belong" on the site but I was planning on adding it to my modules just because it makes it easier for the end user and anything that makes it easier cuts down on support requests. :)

Thanks for adding this. I'll grab the latest dev and give it a whirl.

Michelle

[Edit: Actually... The last dev was on Dec 15th and there's no commit messages since then. Am I missing something?]

jaydub’s picture

not committed to CVS yet! still working on UR integration and other stuff before I do a code dump...

michelle’s picture

Code dump? Tsk... Whatever happened to discrete commits? :P

Ok. Will wait. Hope it's soon, though. I've got to get this project done this weekend. Got a Monday deadline and my son's having surgery on Monday so I won't be working that day.

Michelle

jaydub’s picture

New -dev snapshot has better support for activity user pictures now. Please checkout the handbook page on theming activity: http://drupal.org/node/353445 for details.

Flying Drupalist’s picture

Component: Miscellaneous » Documentation
Category: feature » support

Hi jaydub, thanks for the great module. Can you give me a little more instruction on how to use this please? :D

I have:

function myzensubtheme_activity_user_picture($account) {
return theme('imagecache', 'tinyavatar', 'user_picture', $account);
}

in my template.php.

I see no changes at all.

The imagecache stuff comes from imagecache profiles: http://drupal.org/project/imagecache_profiles

What am I doing wrong? Thanks.

Flying Drupalist’s picture

Version: 5.x-4.x-dev » 6.x-1.x-dev

Ahh I get it, I didn't refresh cache.

But still, my return theme is incorrect. It looks in the imagecache folder but doesn't grab the picture.

I tried return theme('imagecache', 'tinyavatar', $user->picture); as well, but that's also a no go. What are the correct settings?

Thanks.

jaydub’s picture

Well rather than try to delve into your specific problem, here is an example theme override that I used. This is basically a tweak of what you might see in the old default theme_user_picture theme function.

function phptemplate_activity_user_picture($account) {
  if (variable_get('user_pictures', 0)) {
    // If there is a user image then fetch it
    if ($account->picture && file_exists($account->picture)) {
      $alt = t("@user's picture", array('@user' => $account->name ? $account->name : variable_get('anonymous', t('Anonymous'))));
      $picture = theme('imagecache', 'user_picture_tiny_square', $account->picture, $alt, $alt);
    }
    // otherwise check for a default image and fetch it
    else if ($picture = variable_get('user_picture_default', '')) {
      $picture = theme('imagecache', 'user_picture_tiny_square', $picture, $alt, $alt);
    }

    // If we have a picture then make it link to the profile and return it
    if (isset($picture)) {
      if (!empty($account->uid) && user_access('access user profiles')) {
        $picture = l($picture, "user/$account->uid", array('attributes' => array('class' => 'user-picture-link', 'title' => t('View user profile.')), 'html' => TRUE));
      }
      return $picture;
    }
  }
}

of course you would substitute your own imagecache preset where applicable.

Flying Drupalist’s picture

Thanks, exactly what I need.

Flying Drupalist’s picture

Status: Active » Fixed
michelle’s picture

re #44: If this is for D6, you don't want to use phptemplate_user_picture() or you'll prevent any preprocesses from running.

Edit: Nevermind that. I just realized this is overriding the activity theme function, not the core theme function. Sorry.

Michelle

michelle’s picture

To prevent anyone else from spending an obscene amount of time missing the obvious, you actually have to add the "[author-picture]" token for this to work. Doh! I can't believe I missed that.

On the plus side, I'm a lot more familiar with the activity codebase now...

Michelle

jaydub’s picture

Actually no you don't HAVE to use the [author-picture] token to show a user picture but you CAN use it to show a picture. It's provided as a convenience in case you want the picture to be inside or at the beginning or end of the activity message, i.e. as part of the message.

If you wanted the picture outside of the message such as in a different table cell or in front of both the activity timestamp and the activity message then you can show the picture as described in this issue and in the theming docs.

michelle’s picture

Well, my mistake was that, when you said you added picture support, I assumed you had added a call to theme('user_picture') in the code somewhere. And I couldn't figure out where you had done that. Then it finally dawned on me that what you added was the token. So to use this without the token, we'd need to add theme('user_picture') to theme_activity, I'm assuming? That's where I originally looked and got totally confused that theme_activity is never called. Took me a lot of hunting thru code before I finally realized it was because I have Morbus's comment activity on that same site. So it's been a crazy trip thru the activity source code today. LOL

Michelle

jaydub’s picture

I added the theme function theme_activity_user_picture() to be used in any case where you want to get a user picture. The implementation is left up to the user as stated in this issue since there is no one solution that is going to work for everyone. The author-picture token simply calls this theme('activity_user_picture') with a minimal user object returned from activity_user_load().

In the theming docs: http://drupal.org/node/353445 you can see an example at the bottom where the user picture is shown via the theme call rather than as a token.

walker2238’s picture

I know this is for version 6.x but how could I add this for 5 beta 2?

lelizondo’s picture

version 5.x-beta2 is old.. why don't you update? this is working for 5.x-4.x-dev..

jaydub’s picture

The issue is set as 6.x branch but the same applies for 5.x. The Drupal project module only allows for a single 'Version' tag so when an issue concerns a 5 and 6 branch of a module one has to go ahead and select one even if both apply....

lost305’s picture

Has anyone.. that's NOT a developer, gotten this to work?

I mean I'm able to get the user-picture to display in the list on the activity page but on the block all it shows is 1 image and no activities.

???????? :o(

bflora’s picture

To build on that last comment, can someone sum up the steps to add images to activity for D5. There are now 50+ posts in this thread, and it appears a solution has been posted, but I'm not sure exactly what it is or where the solution is in the thread.

michelle’s picture

I know jaydub wants to leave this up to the themer but, given that it can be confusing for a non dev, I thought I'd toss in the code I just added to advanced forum that could easily be adapted to activity. Pretty much just S/R for 'advanced_forum' to 'activity'.

On the settings form:

  if (module_exists('imagecache')) {
    $options = array('' => '');
    $presets = imagecache_presets();
    foreach ($presets AS $preset) {
      $options[$preset['presetname']] = $preset['presetname'];
    }

    $form['advanced_forum_user_picture_preset'] = array(
      '#type' => 'select',
      '#title' => t('User picture preset'),
      '#options' => $options,
      '#description' => t('Imagecache preset to use for forum avatars. Leave blank to not use this feature.'),
      '#default_value' => variable_get('advanced_forum_user_picture_preset', ''),  
    );
  }

This lets them choose what preset, if any, to use for the avatars in the forum.

Then the specialized theme function, which already exists in Activity:

/**
 * Theme function to return user picture.
 */
function theme_advanced_forum_user_picture($account) {
  $preset = variable_get('advanced_forum_user_picture_preset', '');
  if (variable_get('user_pictures', 0) && !empty($preset) && module_exists('imagecache')) {
    if ($account->picture && file_exists($account->picture)) {
      $picture = theme('imagecache', $preset, $account->picture);
    }
    return '<div class="picture">' . $picture . '</div>';
  }  
  else {
    return theme('user_picture', $account);
  }
}

So what this does is lets the admin pick a preset on the settings page if they have imagecache installed. When it's time to theme the user picture for the activity item, it checks that picture support is enabled, that the user has chosen a preset, and that imagecache is enabled. If these things aren't true, then it just does the normal core function.

There is a slight gotcha here if they select a preset in AF, then go delete that preset, so a case could be made for checking that the preset still exists. But given the amount of times this function can be called on a given page, I decided to risk an error for foolishness. ;)

Michelle

Flying Drupalist’s picture

@bflora and others asking about pictures. The code posted here are only about using imagecache with pictures or theming pictures in general. To simply add a picture it's one of the tokens available in the activity settings. Just look at the token list and include it, quite simple.

lost305’s picture

i tried installing imagecache but it says there's a problem with my php version

no solution without imagecache installed?

lelizondo’s picture

yo don't need imagecache to use activity with images as you can see in Michelle's code:

<?php
if (module_exists('imagecache')) {
...

?>

but if you want to use it, version 1.x needs php 4.x and version 2.x needs 5.x

michelle’s picture

@lost305: You could use CSS to squish the images smaller.

Michelle

lelizondo’s picture

imagecache_profiles is also a good choice

michelle’s picture

@lelizondob: And that started working without imagecache when? ;)

Michelle

lelizondo’s picture

my bad, what I wanned to say is that imagecache_profiles is also a good choice to have different image sizes, instead of using css like you said

michelle’s picture

@lelizondob: Yes, but I was directing that at the person who said they are unable to use imagecache. So telling him to use imagecache_profiles really isn't going to do him any good.

Michelle

lelizondo’s picture

@Michelle: I think the original problem could be solved as I said with:

but if you want to use it, version 1.x needs php 4.x and version 2.x needs 5.x

I don't think we should be discussing this anymore, but I do agree with some of the users who posted in this issue, seems easy to add images to activity but maybe it's not that easy, or that obvious, maybe we should be working on improving the doc, because http://drupal.org/node/353445 isn't that clear for a non dev.

What I'm saying is that the doc could be a little more straight forward, explaining how to use imagecache, imagecache_profiles, and activity, with and without advanced_profile (great module by the way!).

Too much code could be confusing for a non dev, and let's face it, not everyone here knows how to write code.

Luis

michelle’s picture

@lelizondob: I didn't even see your post as it was at the same time as mine. Anyway, my #57 was intended as an addition to activity, not something for the average person to be writing. If they add that to activity, then people would be able to choose an imagecache preset from settings and then just add the token to their activity line, also in settings, and be good to go. Docs are nice but easier to use modules are better.

Michelle

lost305’s picture

@Michelle

Thanks I finally got it working. I didn't know I had to add the IMG to the previous stated class and then I was able to manage the size of the picture.

Now for the initial dilema...

How do I get the user image to display block function?

lost305’s picture

I'm still trying to add the user picture to the activity block.

In the following code found in the activity.module file....

        case 'all':
          if (user_access('view public activity')) {
            $activity =  activity_get_activity(ACTIVITY_ALL, NULL, variable_get('activity_block_'. $delta, 5) + 1);
            if ($count = count($activity)) {
              drupal_add_css(drupal_get_path('module', 'activity') .'/activity.css');
              if ($count > variable_get('activity_block_'. $delta, 5)) {
                $more_link = theme('activity_more_link', 'activity');
                array_pop($activity);
              }
              $activities = array();
              foreach ($activity as $item) {
                $activities[] = theme('activity', activity_token_replace($item), $item) . activity_delete_link($item);
              }
              return array(
                'subject' => t('Recent activity'),
                'content' => theme('activity_block', $activities, $more_link)
              );
            }
          }
          break;

I added 'user_picture' to the line
$activities[] = theme('activity', activity_token_replace($item), $item) . activity_delete_link($item);

like this
$activities[] = theme('user_picture', 'activity', activity_token_replace($item), $item) . activity_delete_link($item);

and the picture shows up in the block but not the activity. So it's the user picture plus the X to delete the activity.

Can anyone tell me what I'm doing wrong?

Thanks for you time.

jaydub’s picture

Status: Fixed » Active

Setting back to active since there are still a lot of folks needing help with this

jaydub’s picture

Issue tags: +activity-6.x-1-0-rc1

tagging

jaydub’s picture

Assigned: Unassigned » jaydub
burn2149’s picture

would anyone be able to give an example of correct code to pull user picture if present, and where to put it?

thx

liliplanet’s picture

Hi,

This is so close to being perfect ..

I've added the following to template.php, but the delete activity link is missing, as well as the image_cache preset, in my case called 'profile_small'.

Please how do I alter the following to add activity link and image_cache preset?

function phptemplate_activity_table($activities) {
  $rows = array();
  foreach ($activities as $activity) {
    if ($activity_message = activity_token_replace($activity)) {
      $rows[] = array(
        theme('user_picture', $activity['data']['author-uid']),
        theme('activity', $activity_message, $activity) .' - <em>'. format_interval(time() - $activity['created']) .' ago</em>',
      );
    }
  }
  $output = theme('table', array(), $rows);
  $output .= theme('pager');
  return $output;
}

Look forward to any reply, and thank you!
Lilian

lelizondo’s picture

This is what I've done, it's not perfect and I could use some help but it works.

First, to make use of imagecache I'll used #44, I have something like this:

<?php
function phptemplate_activity_user_picture($account) {
  if (variable_get('user_pictures', 0)) {
    // If there is a user image then fetch it
    if ($account->picture && file_exists($account->picture)) {
      $alt = t("@user's picture", array('@user' => $account->name ? $account->name : variable_get('anonymous', t('Anonymous'))));
      $picture = theme('imagecache', 'tiny_20x20', $account->picture, $alt, $alt);
    }
    // otherwise check for a default image and fetch it
    else if ($picture = variable_get('user_picture_default', '')) {
      $picture = theme('imagecache', 'tiny_20x20', $picture, $alt, $alt);
    }

    // If we have a picture then make it link to the profile and return it
    if (isset($picture)) {
      if (!empty($account->uid) && user_access('access user profiles')) {
        $picture = l($picture, "user/$account->uid", array('attributes' => array('class' => 'user-picture-link', 'title' => t('View user profile.')), 'html' => TRUE));
      }
      return $picture;
    }
  }
}
?>

For the page (theme_activity_table) something like this works:

function phptemplate_activity_table($activities) {
  $rows = array();
  foreach ($activities as $activity) {
    if ($activity_message = activity_token_replace($activity)) {
      $activity['delete-link'] = activity_delete_link($activity);
      $row = array(
        array('data' => theme('activity_user_picture', activity_user_load($activity['uid'])), 'class' => 'activity-table-user-picture'),
        array('data' => theme('activity', $activity_message, $activity), 'class' => 'activity-table-message'),
      );
      $rows[] = $row;
    }
  }
  $output = theme('table', $display_headers, $rows, array('class' => 'activity-list-table'));
  $output .= theme('pager');
  return $output;
}

Now the part I haven't figured out yet it's the indivicual activity message (theme_activity) I tried adding:

  $author = activity_user_load($data['uid']);
  $picture = theme('activity_user_picture', $getuid);
  $output .= $picture;

But that only showed the default picture for everyone.

Then, I tried a rudimentary solution:

  $author = $item['data']['uid'];
  $output .= '<img src="' . base_path() . 'sites/default/files/imagecache/small_60x60/pictures/picture-' . $author . '.jpg">' ;

The complete code it's:

function phptemplate_activity($message, $item) {
  
  $author = $item['data']['uid'];
  $output = '<div class="activity_userimage"><img src="' . base_path() . 'sites/default/files/imagecache/small_60x60/pictures/picture-' . $author . '.jpg"></div>' ;
  
  $output .= '<div class="activity_message">' . $item['mark'] .'<span class="activity-'. $item['module'] .'-'. $item['type'] .'-'. $item['operation'] .'">'. $message .'</span></div>';

  $output .= '<span class="activity-links">';

  // If logged in user, then show link to add a comment to the activity record. 
  // Click here displays the activity comment form.
  if (!user_is_anonymous()) {
    // Also note that the js looks for this specific class name 'activity-comments-click-to-show', so don't remove it
    $output .= '&nbsp;&ndash;&nbsp;<span class="activity-comments-click-to-show">'. t('Comentar') .'</span>';
  }

  $output .= '</span>';
  // If the user has permission to delete the activity record, display the delete link
      if ($item['delete-link']) {
       $output .= '&nbsp;&nbsp;'. $item['delete-link'];
      }
 
  $comments = theme('activity_comments', $item['comments']);
  if ($comments) {
    $output .= '<div class="clear"></div>';
    $output .= theme('item_list', $comments, NULL, 'ul', array('class' => 'activity-comments-list'));
  }

  if (!user_is_anonymous()) {
    $output .= '<div class="clear"></div>';
    $output .= '<div class="activity-comments-form-hidden clear-block">'. drupal_get_form('activity_comment_form', $item['aid']) .'</div>';
  }  
  
  
  $output .= '<div class="clear"></div>';
  $output .= '<div class="activity_line"></div>';
    
  return $output;
}

This one works, I'm sure there's a better solution but I'm gonna need some help. I know this doesn't cover *all* the possible uses but giving some easy examples doesn't hurt.

The only problem is when adding the user picture to theme_activity and theme_activity_table, you'll have two images.

lelizondo’s picture

StatusFileSize
new106.24 KB

screenshot of #75

sirkitree’s picture

@lelizondob - Thank you for contributing your solution! Hopefully we'll get this all summarized and properly documented at some point.

lelizondo’s picture

I'll do it as soon as I found a better way to do this:

<?php
  $author = $item['data']['uid'];
  $output = '<div class="activity_userimage"><img src="' . base_path() . 'sites/default/files/imagecache/small_60x60/pictures/picture-' . $author . '.jpg"></div>' ;
?>

I'm sure there's a way but I'm going to need some help.

michelle’s picture

@lelizondob: You could adapt the second bit of code in http://drupal.org/node/323380#comment-1217686

Michelle

lelizondo’s picture

Thanks Michelle, I'll give it a try.

lelizondo’s picture

I'm using in phptemplate_activity:

if ($account->picture) {
      $picture = theme('imagecache', mypresetname, $account->picture);
      $output = '<div class="picture">' . $picture . '</div>';
  }
  else {
    	$output = theme('user_picture', $account);
  }

All I'm getting is the default picture. If I remove the default core function I get nothing.

What am I doing wrong? Is it possible that $account->picture is empty and that's why I'm getting the default picture?

michelle’s picture

Are you loading the $account variable with a user object before running that code? If not, that's the problem.

Michelle

lelizondo’s picture

Thanks Michelle, but how do I do that?

this is what I'm doing:

        global $user;
	$account = user_load(array('uid' => $user->uid));
	if (variable_get('user_pictures', 0) && module_exists('imagecache')) {
		if ($account->picture) {
	      $picture = theme('imagecache', small_60x60, $account->picture);
	      $output = '<div class="picture">' . $picture . '</div>';
	  }
	  else {
	    $output = theme('user_picture', $account);
	  }
	}

But I'm just getting the current user picture. I guess my problem is with:

	$account = user_load(array('uid' => $user->uid));
michelle’s picture

Yes, that would be the problem. global $user gets you the user object for the logged in user, which you are then re-loading into the $account variable. You need to load the $account variable with the user object of the person you want the picture for. For that, you need their ID. I can't tell you how to get that without knowing what variables are available to that snippet.

Michelle

lelizondo’s picture

Thanks Michelle, I realized that $item has the uid of the user who generated the activity, so:

$account = user_load(array('uid' => $item['data']['uid']));

prints the right picture

likewhoa’s picture

subscribing

liliplanet’s picture

Hi lelizondob,

Your screenshot is beautiful and wondering if you perhaps have an updated phptemplate override for 6.x-2.x-dev?

I've tried #75, but has made no difference and presuming it's to do with a newer version.

Look most forward to your reply.
Lilian

Scott Reynolds’s picture

phptemplate override for 6.x-2.x-dev?

Because 2.x uses Views, you should use the Views theme information link to figure out how to theme it. The first step is to add the Activity: User relationship. Then add the User: Picture field. Then you can use the theme: Information to figure out how to theme up the picture. For information on how to theme up Views: http://drupal.org/node/352970

http://skitch.com/supermanscott/dy4ei/picture

You can also look into using: http://drupal.org/project/imagecache_profiles

You also shouldn't write a phptemplate_X function, it should be MY_THEME_X function.

Michsk’s picture

I've seen a lot of code pass by, this is a solution to get this done trough views.

  • Create a new activity view
  • Add the field: Customfield: PHP code
  • Add the field: Activity: Type

In the Customfield: PHP code, set the following php code.

<?php
if( $data->activity_type== 'node' ):
  $img = '/sites/all/themes/yourtheme/assets/img/icons/image1.png';
elseif( $data->activity_type== 'comment' ):
    $img = '/sites/all/themes/yourtheme/assets/img/icons/image2.png';
else:
  $img = '/sites/all/themes/yourtheme/assets/img/icons/image3.png';
endif;

return '<img src="'. $img .'">';
?>

In the Activity: Type field, check the Exclude from display option.

Now if you want to add another option, let's say user relationships. You just alter the code in the php code field and add another elseif().

<?php
if( $data->activity_type== 'node' ):
  $img = '/sites/all/themes/yourtheme/assets/img/icons/image1.png';
elseif( $data->activity_type== 'comment' ):
    $img = '/sites/all/themes/yourtheme/assets/img/icons/image2.png';
elseif( $data->activity_type== 'user_relationships' ): // OR whatever the activity_type is called
    $img = '/sites/all/themes/yourtheme/assets/img/icons/image4.png';
else:
  $img = '/sites/all/themes/yourtheme/assets/img/icons/image3.png';
endif;

return '<img src="'. $img .'">';
?>

How to know what the activity_type is? Just uncheck the Exclude from display option in the Activity: Type field and it will show what type it is.

youkho’s picture

Subscribe

thelocaltourist’s picture

subscribe

sirkitree’s picture

Status: Active » Closed (won't fix)

closing. 1.x no longer supported.