Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to add user avatar to activity excerpts

  • Avatar of Kieran
    Kieran
    Participant

    @cozzie

    Hi Guys

    I’m trying to add the user avatar’s to any activities with excerpts, can anyone tell me how I can do this? I think it will draw the eye of the user in to the activities.

    Also, is it at all possible to show the activities of a user + their friends combined? I think this combination of activities on a user’s profile page it would be more useful. I have checked the loops and see their is 1. Site-wide 2. Personal 3. Friends. But is there any way to show Personal + Friends combined?

    Thanks a lot for any help!!!

Viewing 17 replies - 1 through 17 (of 17 total)
  • Avatar of r-a-y
    r-a-y
    Moderator

    @r-a-y

    Ooh… good question, cozzie.

    I don’t think there’s a parameter that combines both the “personal” and “friends” type.

    For the avatar, I’m guessing you would need to either hack the “/buddypress/bp-activity/bp-activity-templatetags.php” file or write a filter to override one of the existing ones in bp-activity, which would include the avatar.

    Avatar of Mariusooms
    Mariusooms
    Participant

    @mariusooms

    Avatar support would be a very nice feature. I looked at the activity code, but couldn’t make much of it. According to the roadmap the code will change in 1.1, so we have:

    Grouping of similar activities by one user within X amount of time

    http://buddypress.org/about/roadmap/

    I really do hope there is an option in the future to liven up the activity stream in this media centered age. I’m surprised it is not included in the roadmap even up to 1.4?

    Also, the roadmap also has this nice addition in store for 1.1:

    Profile picture updated entry on activity streams

    So it would only make sense the new profile picture would be visible in the activity stream as well, since we can’t expect members visiting each listed profile to just see the new profile picture?

    Avatar of Kieran
    Kieran
    Participant

    @cozzie

    thanks for the response fellas

    If the combination of friends + personal is not currently possible I wonder is there an ‘if’ statement I could use in the profile page so that if you are viewing your own page you are shown your friends activity but if you are viewing another users’ page you see their activity.

    Right now the main point of becoming friends with somebody is so that you can view their activity but unless that activity is on your main profile page it is quite ‘buried’ and unlikely to be viewed.

    I’ve looked at: bp-themes/bpmember/profile/index.php and there is a line of code:

    <?php if ( bp_has_activities( ‘type=personal&max=5′ ) ) : ?>

    Is there a way to change this so that it says ‘”If user_is_owner type = friends else type=personal”?

    This would be great

    For avatars, like you Mariusooms I’ve looked at the code but can’t see how to add avatars to the activities with excerpts so if anyone can offer any tips on this as well I’ll be in 7th heaven

    Cheers!

    Avatar of Kieran
    Kieran
    Participant

    @cozzie

    Just to say if anyone is interested in making this change the if statement is:

    <?php if ( bp_is_home()&& bp_profile_activities( ‘type=friends&max=10′ ) ) : ?>

    Plus this change is required: http://buddypress.org/forums/topic/how-to-have-friends-activity-on-profile-page

    This will allow users to see their friends activity on their own profile page.

    BUT I still can’t figure out how to add Avatars to the activity templates. I think it would look great if, for activities with excerpts (blog posts, forum posts, wire posts etc), the users avatar is shown (a la facebook).

    Can anyone help or is this a major change to attempt?

    Thanks a lot!

    Avatar of Jan M.
    Jan M.
    Participant

    @jotem

    It’s not that hard to add user avatars to the activity stream, but it involves core-hacking. So as always, be warned that you won’t be able to update your BP automatically after changing core funcionality.

    This takes place in bp-activity-templatetags.php

    This is what your could should look like at the moment:

    function bp_get_activity_content() {
    global $activities_template, $allowed_tags;

    if ( bp_is_home() && $activities_template->activity_type == 'personal' ) {
    $content = bp_activity_content_filter( $activities_template->activity->content, $activities_template->activity->date_recorded, $activities_template->full_name );
    } else {
    $activities_template->activity->content = bp_activity_insert_time_since( $activities_template->activity->content, $activities_template->activity->date_recorded );
    $content = $activities_template->activity->content;
    }

    return apply_filters( 'bp_get_activity_content', $content );
    }

    You’ll have to add these two lines of code at the end of the else-part

    $content = bp_core_get_avatar($activities_template->activity->user_id) . $content;
    return $content;

    The first line adds the avatar-image, the second line returns the content.

    Second line is necessary because the

    return apply_filters( 'bp_get_activity_content', $content );

    in the last line of the function filters out any images.

    Remember: The BP-Devs had something in mind when implementing this functionality, so you may encounter security-risks…

    Avatar of Kieran
    Kieran
    Participant

    @cozzie

    Thanks so much Jotem!

    When I did it however the only image returned is the mysteryman avatar (for people who haven’t uploaded an avatar). Even for activity made by people with their own avatars only the mysteryman is returned.

    Here’s the full code I put in:

    function bp_get_activity_content() {

    global $activities_template, $allowed_tags;

    if ( bp_is_home() && $activities_template->activity_type == ‘personal’ ) {

    $content = bp_activity_content_filter( $activities_template->activity->content, $activities_template->activity->date_recorded, $activities_template->full_name );

    } else {

    $activities_template->activity->content = bp_activity_insert_time_since( $activities_template->activity->content, $activities_template->activity->date_recorded );

    $content = $activities_template->activity->content;

    $content = bp_core_get_avatar($activities_template->activity->user_id) . $content;

    return $content;

    }

    return apply_filters( ‘bp_get_activity_content’, $content );

    }

    Avatar of Jan M.
    Jan M.
    Participant

    @jotem

    In bp-activity-classes.php try to add this line of code to the get_activity_for_user() function (There are a couple of very similar code lines, just add it after those)

    $activities_formatted[$i]['user_id'] = $activities[$i]->user_id;

    Also I just recognized that the hackdescribed in this thread won’t work in BP 1.0.3 as there were some core changes.

    Avatar of Kieran
    Kieran
    Participant

    @cozzie

    Ooohh! I’m on BP 1.0.3 so that’s a shame, thanks for the effort anyway Jotem!

    So if anyone knows how to get this working on 1.0.3 and upwards and I’d be V grateful!

    Avatar of Jan M.
    Jan M.
    Participant

    @jotem

    OK, I took a quick look at BP 1.0.3 and it should work like this:

    In bp-activity-classes.php add

    $activities_formatted[$i]['user_id'] = $activities[$i]->user_id;

    just as described above.

    In bp-activity-widgets.php search for the line

    <?php echo apply_filters( 'bp_get_activity_content', bp_activity_content_filter( $item['content'], $item['date_recorded'], '', true, false, true ) ); ?>

    and change it to

    <?php echo bp_core_get_avatar($item['user_id']) . apply_filters( 'bp_get_activity_content', bp_activity_content_filter( $item['content'], $item['date_recorded'], '', true, false, true ) ); ?>

    You don’t need the other changes described in my previous posts, so just roll them back.

    Avatar of Mariusooms
    Mariusooms
    Participant

    @mariusooms

    The trunk has changed activity code, but I was able to get it going with the help of your instructions. Next step it to see If I can have the bpPicture Album record the activity in the stream and display the picture thumbnail.

    If I can figure that out, I would finally be happy with the activity stream…well…that and flickr/youtube media in the activity stream.

    Could be wise and wait ’till 1.1 end of August to say how the activity stream will evolve.

    Avatar of Michael Berra
    Michael Berra
    Participant

    @miguael

    WOW – great!!! That was what I was searching for!

    Can you tell me, how to implement that in my Custom-Friends-Activity?

    (I am using this to get the friends activity for logged in users to the start-page)

    <?php if ( bp_has_activities('type=friends&user_id='.$user_ID.'&per_page=10&max=10&timeframe=-4 Weeks') ) : ?>

    <div class="activity-list">
    <ul id="activity-list">
    <?php while ( bp_activities() ) : bp_the_activity(); ?>

    <li class="<?php bp_activity_css_class() ?>">
    <?php bp_activity_content() ?>
    </li>

    <?php endwhile; ?>
    </ul>
    </div>

    Would be great – thanks!

    Avatar of Kieran
    Kieran
    Participant

    @cozzie

    Brilliant thanks Jotem!

    This maybe pushing it but is there any way to have the avatars display only for activity which has excerpts? So blog posts, wire posts forum posts which all have text excerpts would include the avatar but updates such as Jim and John are now friends would not.

    thanks for all the help!

    Avatar of Gpo1
    gpo1
    Participant

    @gpo1

    @Jotem, Can you amend the code as a plugin,cos of BP updates ?

    Avatar of Mariusooms
    Mariusooms
    Participant

    @mariusooms

    @Michael Berra

    This is my implementation that should work for you. It only requires one line of core hacking.

    in bp-activity-classes.php add the line as described by Jotem:

    $activities_formatted[$i]['user_id'] = $activities[$i]->user_id;

    Then create this new function in your bp-custom.php. If you don’t have that file, you can create it in your plugins folder and it will be automatically loaded by bp.

    // **** Avatar support for activity stream ****
    function bp_activity_avatar() {
    echo bp_get_activity_avatar();
    }
    function bp_get_activity_avatar() {
    global $activities_template;
    $activity_avatar = bp_core_get_avatar( $activities_template->activity->user_id, 1 );
    return apply_filters( 'bp_get_activity_avatar', $activity_avatar );
    }

    Now you can use this function in your template tags which will diplay the acting user avatar. So in your case it could look like:

    ...
    <div class="activity-list">
    <ul id="activity-list">
    <?php while ( bp_activities() ) : bp_the_activity(); ?>

    <li class="<?php bp_activity_css_class() ?>">
    <?php bp_activity_avatar() ?>
    <?php bp_activity_content() ?>
    </li>

    <?php endwhile; ?>
    </ul>
    </div>
    ...

    The nice part of doing it this way is it leaves you some options on how to style and implement this new function.

    @cozzie I haven’t looked at filtering depending on activity type, but imagine you could this as well by studying the activity class. Shouldn’t be too hard, but would be specefic function depending on your needs.

    Avatar of rustybroomhandle
    rustybroomhandle
    Participant

    @rustybroomhandle

    Awesome suggestions, this is helping me understand a bit about how this thing was put together. However, implementing any of the code suggested above,for me, results in all activities having exactly the same avatar. Colour me confused.

    Avatar of Jan M.
    Jan M.
    Participant

    @jotem

    @cozzie Well, you could implement some sort of filter. Every activity has a certain component_name and a component_action (e.g. ‘groups’ and ‘new_wire_post’) that can be accessed like the ‘user_id’ property in the above examples.

    @ Gpo1 I’m going to check that, already thought about it…

    @Marius: You are my HERO!!! Works like a charm! and – yes, now I’m understanding also a little bit more, how stuff like that could work (as a non programmer…) :-) THANKS ALOT!

Viewing 17 replies - 1 through 17 (of 17 total)

You must be logged in to reply to this topic.