Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search Results for 'bp_core_fetch_avatar'

Viewing 25 results - 276 through 300 (of 304 total)
  • Author
    Search Results
  • #81290
    Anna Ladoshkina
    Participant

    @justbishop I also use the subdirectories – so filters should be OK in this case
    but probably you have some custom avatar upload path or constant BP_ROOT_BLOG is not defined in your installation?
    another possible reason – the function that fetch avatars for members blogs does not use bp_core_fetch_avatar() but some other mechanism

    #12044
    _
    Participant

    Hi everyone!

    I coded two widgets, one to list the most active blogs on the website home, and another to show up a profile on blogs.

    The weird thing is that using the same method for both widgets, they display different avatars. In my blog home I got the right avatar, but on blog profiles sidebar widget I get a gravatar “smiling square” generated one, not the one uploaded via Buddypress.

    The method (exactly the same in both widgets) is something like:
    —-
    global $blog_id;
    $user = get_blog_owner ($blog_id) // function to not get site admin users
    echo get avatar ($user->ID, 96); // bp_core_fetch_avatar(‘item_id=’.$user->ID) does not work, either
    —-

    Hope someone can help me on this.
    Thanks in advance.

    #79670
    r-a-y
    Keymaster

    Your pastie link doesn’t work.

    This is working for me:
    $myslug = 'my-test-group';
    if ( bp_has_groups('type=single-group&slug='.$myslug) )

    For some reason, you have to add the type as “single-group” as well.

    If you’re just trying to get the group avatar of one group… just use bp_group_avatar() (view the params in bp-groups-templatetags.php) or bp_core_fetch_avatar() (view params in bp-core-avatars.php).

    #11735
    kiwipearls
    Participant

    I use latest Buddypress on my Latest WordPress MU site but get this error on a member blog:

    Code:
    Warning: Missing argument 5 for bp_core_fetch_avatar_filter() in /senilityguild.com/public_html/wp-content/plugins/buddypress/bp-core/bp-core-avatars.php on line 345

    Avatars work great on the main blog, but anyone whom creates a blog gets this error. I can’t figure it out.

    I look forward to hearing from you.

    tinabeans
    Member

    Nevermind, I googled for that function and found the SVN repo where that function is defined: http://bp-dev.org/phpxref/nav.html?_functions/index.html

    The params it takes are:

    $defaults = array(
    ‘item_id’ => false,
    ‘object’ => ‘user’, // user OR group OR blog OR custom type (if you use filters)
    ‘type’ => ‘thumb’,
    ‘avatar_dir’ => ‘avatars’,
    ‘width’ => false,
    ‘height’ => false,
    ‘class’ => ‘avatar’,
    ‘id’ => false,
    ‘alt’ => __( ‘Avatar Image’, ‘buddypress’ ),
    );

    … and the params can be fed into bp_core_fetch_avatar() in the form of “name=value&name=value” pairs as a string.

    Hope this helps someone else who is having the same issue. =)

    tinabeans
    Member

    YOU ARE AMAZING! You know, you just redeemed my whole afternoon of work. Hooray =) I owe you a beer for that one!

    Well… here’s the postscript. It all comes back to one thing I’ve been frustrated with: why is there no good documentation on BP or BBpress template tags? I had to search the code repo to find a hint that bp_core_get_avatar() was deprecated in favor of bp_core_fetch_avatar(), and after that still didn’t know that I had to put “item_id=” before the ID in the argument string. Not sure how I would have figured that one out on my own, given my apparent lack of PHP reading skills.

    If someone knows a secret source of well-documented template tags, do let me know. All I’ve found so far is https://codex.buddypress.org/developer-discussions/buddypress-template-tags/ for Buddypress (which doesn’t even have bp_core_fetch_avatar() listed). Bummer.

    Okay, I do have one last question for you: what other params does bp_core_fetch_avatar() take, and how can I find out? for instance, can I specify a different size of avatar?

    r-a-y
    Keymaster

    @tinabeans – just tested the following snippet:

    echo bp_core_fetch_avatar( 'item_id='.get_post_author_id() );

    This is working for me on a deep-integrated external bbPress install. Let me know if this works for you.

    tinabeans
    Member

    I know there have been a million and one posts/questions about this. The trouble is, there is a lot of conflicting instructions… and it is scattered all over the place. I feel like I am very close, but cannot for the life of me get this to work…

    So far, I’ve successfully done the WordPress “deep integration.” I tested this by putting some random Buddypress tags in BBpress template files. They worked fine. Here’s where I’m running into some trouble:

    I am trying to display the exact same avatar that appears in Buddypress for a particular user in BBPress as well. I tested the following template tags on my profile.php (in my BBpress theme):

    bp_member_avatar(); no result (blank)
    bp_core_fetch_avatar(userid); -> no result (blank)
    bp_core_get_avatar(userid); -> function undefined
    get_avatar(userid); -> this shows the wordpress avatar, not the buddypress one

    Help. Which is the correct tag to use? I need to be able to display an avatar based on user id. That is all. Surely that’s not impossible?

    If there are no existing tags that will do this, can someone just tell me how to do a database query? I found this post http://buddypress.org/community/groups/how-to-and-troubleshooting/forum/topic/where-are-the-avatars/ but don’t know where to go from there…

    Thanks in advance!

    Running: WP MU 2.9.2, Buddypress 1.2.3, and BBPress 1.0.2

    #72050

    In reply to: WP-FB connect profile.

    joshmac
    Participant

    Ok, this is what I’ve come up with so far in order to get the user’s facebook profile pic. However, they disappear when you log in. If anyone is willing to add to this to give it the finishing touch it needs or can tell me what to add that would be great.

    add_action('wpfb_login', 'bp_jfb_get_avatar');

    function bp_jfb_get_avatar($avatar, $id_or_email='') {
    global $comment; $id_or_email;

    if(is_object($comment)) {
    $user_id = $comment->user_id;
    }

    if (is_object($id_or_email)) {
    $user_id = $id_or_email->user_id;
    }

    if (is_array($id_or_email)) {
    if ($id_or_email['object']=='user') {
    $user_id = $id_or_email['item_id'];
    }
    }

    if (get_usermeta($user_id, 'facebook_uid')) {
    $user_info = get_userdata($user_id);
    $jfb_suffix = '';

    if ( $id_or_email['width'] ) {
    $jfb_size = $id_or_email['width'];
    if( $jfb_size < 32 ) {
    $jfb_suffix = 'm';
    } else if ( $jfb_suffix < 64 ) {
    $jfb_suffix = 'n';
    } else {
    $jfb_suffix = 'b';
    }
    } else if ( 'full' == $id_or_email['type'] ) {
    $jfb_size = BP_AVATAR_FULL_WIDTH;
    $jfb_suffix = 'b';
    } else if ( 'thumb' == $id_or_email['type'] ) {
    $jfb_size = BP_AVATAR_THUMB_WIDTH;
    $jfb_suffix = 'n';
    }
    $avatar = '<fb:profile-pic uid="'.$user_info->facebook_uid.'" facebook-logo="true" size="'.$jfb_size.'" width="'.$jfb_size.'" linked="true" class="avatar"></fb:profile-pic>';
    return $avatar;

    } else {
    return $avatar;
    }

    }
    add_filter( 'bp_core_fetch_avatar', 'bp_jfb_get_avatar',10,4);

    This code should go in a bp-custom.php file and uploaded to the mu-plugins directory.

    #71717
    rich! @ etiviti
    Participant

    what redirect chain is that?

    only thing i see in

    function bp_core_fetch_avatar( $args = '' ) {

    which might slow down the process is checking for

    if ( file_exists( $avatar_folder_dir ) ) {

    if you have disabled avatar uploads for members.

    #71615
    jivany
    Participant

    What if you removed the existing bp_core_fetch_avatar_filter from get_avatar and then created your own copy that passed ‘no_grav’=>true into the bp_core_fetch_avatar function?

    I think this should kill the attempt to use Gravatar to fetch an avatar. I’m assuming that bp_core_fetch_avatar isn’t being called directly anywhere. If you do find anywhere that does, it should probably have a ticket raised against it.

    #71610
    oberstet
    Participant

    thanks for helping.

    @r-a-y

    i’ve already hacked bp_core_fetch_avatar() as described in https://buddypress.org/forums/topic/how-to-disable-gravatar-completely

    however, a quick grep for gravatar.com over all wp/bb reveals more places. i am a total wwp/bb/php idiot and have no aspirations to become even mildy involved with the codebase. i was looking for a on-place “checkbox solution”.

    @DJPaul

    ah, ok;) it’s ok to have such commerically motivated “defaults” … in the end its a pretty impressing piece of tool and its nice to share anyway. on the other hand, it would be nice to have a big “this is a private site” switch which turns off this, and other things (like the dashboard fetching stuff from outside … i “disabled” that one using a firewall rule;)

    #71606
    r-a-y
    Keymaster

    This isn’t hard at all.

    Apply a filter to:

    bp_gravatar_url

    Return a url to a default image.

    [EDIT]

    Just noticed that bp_gravatar_url only changes the domain… the params are still added at the end of the URL.

    Might try applying a filter to:

    bp_core_fetch_avatar

    Write a function to see if “gravatar.com” exists in the image URL, if so, return a default image.

    #70945

    In reply to: error codes with 1.2

    kiwipearls
    Participant

    I too am getting this error, not on my main blog, but just one of my user blogs. I thought it could have been the theme, but my personal blog uses the same theme as this user.

    I have ust moved my site over to a new domain, everthing is working great on the main blog. but on my user blogs I am running into a problem with comments – they have an error…

    Warning: Missing argument 5 for bp_core_fetch_avatar_filter() in senilityguild.com/public_html/wp-content/plugins/buddypress/bp-core/bp-core-avatars.php on line 345

    The user blog with comment post is: http://senilityguild.com/ledsoul/2010/03/14/new-senilily-banner/

    And my personal blog is(using same theme): http://senilityguild.com/kiwipearls/2010/03/maggotyanne/

    And the main blog is http://senilityguild.com

    So what has broken on this users theme? And what can I do to fix this? Wondering if I should just import that users db over again? (as i had to import the 3 user blogs separately to the main blog, as I think the main blog was a little bit corrupted as the old site had lots of problems)

    Using most recent Buddypress 1.2.3 ?(get my numbers mixed up)and MU 2.9.2

    #70322
    3sixty
    Participant

    re: forum index

    etiviti (rich!), I spiffed up the forum index by adding Group/Forum avatars beside the forum title/description (see code below)

    Question: can you think of an easy way to include a link to the last active post, say, in a final column? I looked at the code last night didn’t get that far.

    Add Avatar to BP Forum Extras – Forum Index

    Under:

    <td class=”num td-title”>

    Add:

    <div class=”item-avatar”>

    <?php $width=50;$height=50;$type=’thumb’; echo bp_core_fetch_avatar( array( ‘item_id’ => $listing->id, ‘object’ => ‘group’, ‘type’ => $type, ‘avatar_dir’ => ‘group-avatars’, ‘width’ => $width, ‘height’ => $height ) ) ?>

    </div>

    #64421
    r-a-y
    Keymaster

    Look into the bp_core_fetch_avatar() function in bp-core/bp-core-avatars.php.

    Sounds good to me. Not sure if there’s a better way performance-wise.

    #8903
    cotfbstone
    Member

    So I have a custom theme for wordpress 9.1 and I was looking forward to BuddyPress 1.2 for a long itme. I downloaded it, followed theinstructions to make my theme compatable but I found that there were a few issues.

    1) My default avatar system is Gravatar, and even allowing users to upload their own avatars got me this annoying GIANT error code above every avatar – [phpBB Debug] PHP Notice: in file /home/clanfan/public_html/wp-content/plugins/buddypress/bp-core/bp-core-avatars.php on line 345: Missing argument 5 for bp_core_fetch_avatar_filter()

    2) It also does not allow you to register for the site for some reason.

    3) Once a group is created, the option to create a new group disappears.

    I need a dynamic theme like the one I have until I can make a new one, so a) are there any fixes for these issues anyone knows about cause they have them too or b) is there a great place to get buddypress themes?

    #60421
    Mike Pratt
    Participant

    @djpaul don’t worry, I don’t think he’ll do it :-)

    @bowe Here is an example of what’s in 1.2 right now (@Andy – is this what you were talking about?)

    from single.php

    <div class=”author-box”>

    <?php echo get_avatar( get_the_author_email(), ’50’ ); ?>

    <p><?php printf( __( ‘by %s’, ‘buddypress’ ), bp_core_get_userlink( $post->post_author ) ) ?></p>

    </div>

    So in the same code block we get the WP based avatar while getting the BP based Name. Hmm. Not sure why but I am going to use either bp_loggedin_user_avatar() or bp_member_avatar() instead, or possibly bp_core_fetch_avatar() feeding in the id via bp_core_fetch_avatar($post->post_author) but I am just flying by the seat of my pants and have not tried it yet.

    I do know this. We know who the post author is. We know he has a username. That username is the same in WP or BP, so we can get his BP avatar and other info via that route. The rest is theming.

    #60217
    Brajesh Singh
    Participant

    The code for fetching avatar resides in buddypress/bp-core/bp-core-avatar.php

    checkout this function there

    bp_core_fetch_avatar

    There are several filters there and you can use those filters to manipulate the things better.

    #59372

    In reply to: Blog post avatar help

    Brajesh Singh
    Participant

    replace that line with this one

    <?php
    global $post;
    echo bp_core_fetch_avatar( array( 'item_id' => $post->post_author, 'type' => 'thumb', 'width' => 50, 'height' => 50));
    ?>

    Hope it helps

    #58950
    Brajesh Singh
    Participant

    The reason is bp_get_group_avatar_thumb() assumes you are inside group loop and simply ignores the $group,which you passed.

    A possible solution will use this method instead.

    //code edited from here

    Edit:checked my template, It seems ,It does not work. Instead use

    bp_core_fetch_avatar( array( 'item_id' =>YOURGROUPID, 'object' => 'group', 'type' => 'thumb', 'width' => 64 ,'height' => 64 ) )

    Hope It helps.

    #58159

    You shouldn’t have to edit the core files at all. I had to whip up something similar today for a client which you may find helpful.

    What it does is replace the email that is used to access the gravatar with a different one. I recommend you replace the default email template with your domain, so, the gravatar will remain persistant if it’s an identicon or wavatar:

    class DisableUserGravatar {

    var $email_template = "member.%USER%@yourwebsite.com";

    function DisableUserGravatar(){
    add_filter('get_avatar', array(&$this, 'wp_avatar'), 1, 5);
    add_filter( 'bp_core_fetch_avatar', array(&$this, 'bp_avatar'), 1, 3);
    }

    function wp_avatar( $content, $id_or_email){
    if( preg_match( "/gravatar.com/", $content ) ){
    if ( is_numeric($id_or_email) ) {
    $id = (int) $id_or_email;
    $user = get_userdata($id);
    } elseif ( is_object($id_or_email) ) {
    if ( !empty($id_or_email->user_id) ) {
    $id = (int) $id_or_email->user_id;
    $user = get_userdata($id);
    } elseif ( !empty($id_or_email->comment_author_email) ) {
    return $content; //Commenters not logged in don't need filtering
    }
    } else {
    $user = get_user_by_email($id_or_email);
    }
    if(!$user) return $content;
    $username = $user->user_login;
    $email = md5( str_replace('%USER%', $username, $this->email_template) );
    return preg_replace("/gravatar.com\/avatar\/(.+)\?/", "gravatar.com/avatar/{$email}?", $content);
    }
    return $content;
    }

    function bp_avatar( $content, $params ){
    if( is_array($params) && $params['object'] == 'user' ){
    return $this->wp_avatar($content, $params['item_id']);
    }
    return $content;
    }

    }

    global $DisableUserGravatar;
    $DisableUserGravatar = new DisableUserGravatar();

    Create a file in wp-content/mu-plugins with the content above.

    I’ll put this up on wordpress.org as a plugin.

    #58089
    buddypresser
    Participant

    Ok finally fixed it with some core code hacking :P

    Here’s my patch solution for anyone wanting to replace default avatars and disable gravatars:

    in bp-core-avatars.php, function bp_core_fetch_avatar():

    I replaced this:

    $gravatar = apply_filters( 'bp_gravatar_url', 'https://secure.gravatar.com/avatar/' ) . md5( $grav_email ) . '?d=' . $default_grav . '&s=' . $grav_size;

    with this line:

    $gravatar = get_bloginfo('template_directory') . '/images/new-default.jpg';

    then in bp-core-templatetags.php, function bp_get_signup_avatar():

    replaced this line:

    return apply_filters( 'bp_get_signup_avatar', '<img src="' . $gravatar_url . md5( $_POST['signup_email'] ) . '?d=' . $default_grav . '&s=' . $size ) . '" width="' . $size . '" height="' . $size . '" alt="' . $alt . '" class="' . $class . '" />';

    with these:

    $default_grav = get_bloginfo('template_directory') . '/images/new-default.jpg';
    return apply_filters( 'bp_get_signup_avatar', '<img src="' . $default_grav . '"' ) . '" width="' . $size . '" height="' . $size . '" alt="' . $alt . '" class="' . $class . '" />';

    Also added a filter to functions.php as it was sometimes returning an image tag with an empty src (broken avatars) – it checks for the empty tag and replaces it with the default:

    Note: BP_AVATAR_DEFAULT was defined in my bp-custom.php file.

    function no_empty_avatar($avatar_link) {
    if ( strpos( $avatar_link, "src=''" ) ) {
    $avatar_link = str_replace("src=''", "src='" . BP_AVATAR_DEFAULT . "'", $avatar_link );
    }
    return $avatar_link;
    }
    add_filter( 'bp_core_fetch_avatar', 'no_empty_avatar' );

    Hope this helps someone in future..

    If anyone has a better solution without hacking the core files, please let me know!

    #57009
    Brajesh Singh
    Participant

    For avatar, you can specify custom avatar size using bp_core_fetch_avatar() function,but in that case either you will have to edit the sitewide activity widget(Not a good idea) or use custom loops.

    for images inside activity content,I will suggest,use css for that.You can target images inside activity using css and set a height/width.

    It is just an easy workaround,I can recall for now.There may be other approaches using php.

    #56389
    Sven Lehnert
    Participant

    @ John James Jacoby,

    I had a look in the bp-events-avatar.php to understand more what’s going on there.

    I’m thinking the avatar part could be like it is now.

    It would be enough, if the original resized image would be available.

    I did some changes to the bp-events-avatar.php and make a plugin from it.

    For the moment, I will use the modified functions in custom components until you offer a better way to do it. I think it would be really great if the original resized image would be saved by the core.

    Be careful!

    This Plugin is just a play around on a fun buddypress installation.

    <?php
    /*
    Plugin Name:bp-events-avatar
    Description: This plugin add a template tag bp_event_flyer() to display the event flyer
    Version: 0.0.1
    License: GPL
    */

    function bp_event_flyer( $args = '' ) {
    echo bp_get_event_flyer( $args );
    }
    function bp_get_event_flyer( $args = '' ) {
    global $bp, $events_template;

    $defaults = array(
    'type' => 'org',
    'width' => 'auto',
    'height' => 'auto',
    'class' => 'avatar',
    'id' => false,
    'alt' => __( 'Event avatar', 'bp-events' )
    );

    $r = wp_parse_args( $args, $defaults );
    extract( $r, EXTR_SKIP );

    /* Fetch the avatar from the folder, if not provide backwards compat. */
    if ( !$avatar = bp_event_fetch_avatar( array( 'item_id' => $events_template->event->id, 'object' => 'event', 'type' => $type, 'avatar_dir' => 'event-avatars', 'alt' => $alt, 'css_id' => $id, 'class' => $class, 'width' => $width, 'height' => $height ) ) )
    $avatar = '<img src="' . attribute_escape( $events_template->event->avatar_thumb ) . '" class="avatar" alt="' . attribute_escape( $events_template->event->name ) . '" />';

    return apply_filters( 'bp_get_event_flyer', $avatar );
    }

    /*
    Based on contributions from: Beau Lebens - http://www.dentedreality.com.au/
    Modified for BuddyPress by: Andy Peatling - http://apeatling.wordpress.com/
    */

    /***
    * Set up the constants we need for avatar support
    */

    if ( !defined( 'BP_AVATAR_THUMB_WIDTH' ) )
    define( 'BP_AVATAR_THUMB_WIDTH', 50 );

    if ( !defined( 'BP_AVATAR_THUMB_HEIGHT' ) )
    define( 'BP_AVATAR_THUMB_HEIGHT', 50 );

    if ( !defined( 'BP_AVATAR_FULL_WIDTH' ) )
    define( 'BP_AVATAR_FULL_WIDTH', 150 );

    if ( !defined( 'BP_AVATAR_FULL_HEIGHT' ) )
    define( 'BP_AVATAR_FULL_HEIGHT', 150 );

    if ( !defined( 'BP_AVATAR_ORIGINAL_MAX_WIDTH' ) )
    define( 'BP_AVATAR_ORIGINAL_MAX_WIDTH', 450 );

    if ( !defined( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE' ) )
    define( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE', get_site_option( 'fileupload_maxk' ) * 1024 );

    if ( !defined( 'BP_AVATAR_DEFAULT' ) )
    define( 'BP_AVATAR_DEFAULT', BP_PLUGIN_URL . '/bp-xprofile/images/none.gif' );

    if ( !defined( 'BP_AVATAR_DEFAULT_THUMB' ) )
    define( 'BP_AVATAR_DEFAULT_THUMB', BP_PLUGIN_URL . '/bp-xprofile/images/none-thumbnail.gif' );

    function bp_event_fetch_avatar( $args = '' ) {
    global $bp, $current_blog;

    $defaults = array(
    'item_id' => false,
    'object' => 'user', // user OR group OR blog OR custom type (if you use filters)
    'type' => 'thumb',
    'avatar_dir' => false,
    'width' => false,
    'height' => false,
    'class' => 'avatar',
    'css_id' => false,
    'alt' => __( 'Avatar Image', 'buddypress' ),
    'no_grav' => false // If there is no avatar found, return false instead of a grav?
    );

    $params = wp_parse_args( $args, $defaults );
    extract( $params, EXTR_SKIP );

    if ( !$item_id ) {
    if ( 'user' == $object )
    $item_id = $bp->displayed_user->id;
    else if ( 'group' == $object )
    $item_id = $bp->groups->current_group->id;
    else if ( 'blog' == $object )
    $item_id = $current_blog->id;

    $item_id = apply_filters( 'bp_core_avatar_item_id', $item_id, $object );

    if ( !$item_id ) return false;
    }

    if ( !$avatar_dir ) {
    if ( 'user' == $object )
    $avatar_dir = 'avatars';
    else if ( 'group' == $object )
    $avatar_dir = 'group-avatars';
    else if ( 'blog' == $object )
    $avatar_dir = 'blog-avatars';

    $avatar_dir = apply_filters( 'bp_core_avatar_dir', $avatar_dir, $object );

    if ( !$avatar_dir ) return false;
    }

    if ( !$css_id )
    $css_id = $object . '-' . $item_id . '-avatar';

    if ( $width )
    $html_width = " width='{$width}'";
    else
    $html_width = ( 'thumb' == $type ) ? ' width="' . BP_AVATAR_THUMB_WIDTH . '"' : ' width="' . BP_AVATAR_FULL_WIDTH . '"';

    if ( $height )
    $html_height = " height='{$height}'";
    else
    $html_height = ( 'thumb' == $type ) ? ' height="' . BP_AVATAR_THUMB_HEIGHT . '"' : ' height="' . BP_AVATAR_FULL_HEIGHT . '"';

    $avatar_folder_url = apply_filters( 'bp_core_avatar_folder_url', get_blog_option( BP_ROOT_BLOG, 'siteurl' ) . '/' . basename( WP_CONTENT_DIR ) . '/blogs.dir/' . BP_ROOT_BLOG . '/files/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
    $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', WP_CONTENT_DIR . '/blogs.dir/' . BP_ROOT_BLOG . '/files/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );

    /* If no avatars have been uploaded for this item, display a gravatar */
    if ( !file_exists( $avatar_folder_dir ) && !$no_grav ) {

    if ( empty( $bp->grav_default->{$object} ) )
    $default_grav = 'wavatar';
    else if ( 'mystery' == $bp->grav_default->{$object} )
    $default_grav = BP_PLUGIN_URL . '/bp-core/images/mystery-man.jpg';
    else
    $default_grav = $bp->grav_default->{$object};

    if ( $width ) $grav_size = $width;
    else if ( 'full' == $type ) $grav_size = BP_AVATAR_FULL_WIDTH;
    else if ( 'thumb' == $type ) $grav_size = BP_AVATAR_THUMB_WIDTH;

    if ( 'user' == $object ) {
    $ud = get_userdata( $item_id );
    $grav_email = $ud->user_email;
    } else if ( 'group' == $object || 'blog' == $object ) {
    $grav_email = "{$item_id}-{$object}@{$bp->root_domain}";
    }

    $grav_email = apply_filters( 'bp_core_gravatar_email', $grav_email, $item_id, $object );
    $gravatar = apply_filters( 'bp_gravatar_url', 'https://secure.gravatar.com/avatar/' ) . md5( $grav_email ) . '?d=' . $default_grav . '&s=' . $grav_size;

    return apply_filters( 'bp_core_fetch_avatar', "<img src='{$gravatar}' alt='{$alt}' id='{$css_id}' class='{$class}'{$html_width}{$html_height} />", $params );

    } else if ( !file_exists( $avatar_folder_dir ) && $no_grav )
    return false;

    /* Set the file names to search for to select the full size or thumbnail image. */
    $avatar_name = ( 'org' == $type ) ? '-bporg' : '-bpthumb';
    $avatar_name = ( 'full' == $type ) ? '-bpfull' : $avatar_name;
    $legacy_user_avatar_name = ( 'full' == $type ) ? '-avatar2' : '-avatar1';
    $legacy_group_avatar_name = ( 'full' == $type ) ? '-groupavatar-full' : '-groupavatar-thumb';

    if ( $av_dir = opendir( $avatar_folder_dir ) ) {
    while ( false !== ( $avatar_file = readdir($av_dir) ) ) {
    if ( preg_match( "/{$avatar_name}/", $avatar_file ) || preg_match( "/{$legacy_user_avatar_name}/", $avatar_file ) || preg_match( "/{$legacy_group_avatar_name}/", $avatar_file ) )
    $avatar_url = $avatar_folder_url . '/' . $avatar_file;
    }
    }
    closedir($av_dir);

    return apply_filters( 'bp_core_fetch_avatar', "<img src='{$avatar_url}' alt='{$alt}' id='{$css_id}' class='{$class}'{$html_width}{$html_height} />", $params );
    }

    function bp_events_delete_existing_avatar( $args = '' ) {
    global $bp;

    $defaults = array(
    'item_id' => false,
    'object' => 'user', // user OR group OR blog OR custom type (if you use filters)
    'avatar_dir' => false
    );

    $args = wp_parse_args( $args, $defaults );
    extract( $args, EXTR_SKIP );

    if ( !$item_id ) {
    if ( 'user' == $object )
    $item_id = $bp->displayed_user->id;
    else if ( 'group' == $object )
    $item_id = $bp->groups->current_group->id;
    else if ( 'blog' == $object )
    $item_id = $current_blog->id;

    $item_id = apply_filters( 'bp_core_avatar_item_id', $item_id, $object );

    if ( !$item_id ) return false;
    }

    if ( !$avatar_dir ) {
    if ( 'user' == $object )
    $avatar_dir = 'avatars';
    else if ( 'group' == $object )
    $avatar_dir = 'group-avatars';
    else if ( 'blog' == $object )
    $avatar_dir = 'blog-avatars';

    $avatar_dir = apply_filters( 'bp_core_avatar_dir', $avatar_dir, $object );

    if ( !$avatar_dir ) return false;
    }

    if ( 'user' == $object ) {
    /* Delete any legacy meta entries if this is a user avatar */
    delete_usermeta( $item_id, 'bp_core_avatar_v1_path' );
    delete_usermeta( $item_id, 'bp_core_avatar_v1' );
    delete_usermeta( $item_id, 'bp_core_avatar_v2_path' );
    delete_usermeta( $item_id, 'bp_core_avatar_v2' );
    }

    $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', WP_CONTENT_DIR . '/blogs.dir/' . BP_ROOT_BLOG . '/files/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );

    if ( !file_exists( $avatar_folder_dir ) )
    return false;

    if ( $av_dir = opendir( $avatar_folder_dir ) ) {
    while ( false !== ( $avatar_file = readdir($av_dir) ) ) {
    if ( ( preg_match( "/-bpfull/", $avatar_file ) || preg_match( "/-bpthumb/", $avatar_file ) || preg_match( "/-bporg/", $avatar_file ) ) && '.' != $avatar_file && '..' != $avatar_file )
    @unlink( $avatar_folder_dir . '/' . $avatar_file );
    }
    }
    closedir($av_dir);

    @rmdir( $avatar_folder_dir );

    do_action( 'bp_core_delete_existing_avatar', $args );

    return true;
    }

    function bp_events_avatar_handle_crop( $args = '' ) {
    global $bp;
    $defaults = array(
    'object' => 'user',
    'avatar_dir' => 'avatars',
    'item_id' => false,
    'original_file' => false,
    'crop_w' => BP_AVATAR_FULL_WIDTH,
    'crop_h' => BP_AVATAR_FULL_HEIGHT,
    'crop_x' => 0,
    'crop_y' => 0
    );

    $r = wp_parse_args( $args, $defaults );
    extract( $r, EXTR_SKIP );

    if ( !$original_file )
    return false;

    if ( !file_exists( WP_CONTENT_DIR . '/' . $original_file ) )
    return false;

    if ( !$item_id )
    $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', WP_CONTENT_DIR . dirname( $original_file ), $item_id, $object, $avatar_dir );
    else
    $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', WP_CONTENT_DIR . '/blogs.dir/' . BP_ROOT_BLOG . '/files/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );

    if ( !file_exists( $avatar_folder_dir ) )
    return false;

    require_once( ABSPATH . '/wp-admin/includes/image.php' );
    require_once( ABSPATH . '/wp-admin/includes/file.php' );

    /* Delete the existing avatar files for the object */
    bp_core_delete_existing_avatar( array( 'object' => $object, 'avatar_path' => $avatar_folder_dir ) );

    /* Make sure we at least have a width and height for cropping */
    if ( !(int)$crop_w )
    $crop_w = BP_AVATAR_FULL_WIDTH;

    if ( !(int)$crop_h )
    $crop_h = BP_AVATAR_FULL_HEIGHT;

    /* Set the full and thumb filenames */
    $full_filename = wp_hash( $original_file . time() ) . '-bpfull.jpg';
    $thumb_filename = wp_hash( $original_file . time() ) . '-bpthumb.jpg';
    $org_filename = wp_hash( $original_file . time() ) . '-bporg.jpg';

    /* Crop the image */
    $full_cropped = wp_crop_image( WP_CONTENT_DIR . $original_file, (int)$crop_x, (int)$crop_y, (int)$crop_w, (int)$crop_h, BP_AVATAR_FULL_WIDTH, BP_AVATAR_FULL_HEIGHT, false, $avatar_folder_dir . '/' . $full_filename );
    $thumb_cropped = wp_crop_image( WP_CONTENT_DIR . $original_file, (int)$crop_x, (int)$crop_y, (int)$crop_w, (int)$crop_h, BP_AVATAR_THUMB_WIDTH, BP_AVATAR_THUMB_HEIGHT, false, $avatar_folder_dir . '/' . $thumb_filename );
    rename (WP_CONTENT_DIR . $original_file, $avatar_folder_dir . '/' . $org_filename );
    /* Remove the original */
    @unlink( WP_CONTENT_DIR . $original_file );

    return true;
    }
    ?>

Viewing 25 results - 276 through 300 (of 304 total)
Skip to toolbar