Skip to:
Content
Pages
Categories
Search
Top
Bottom

bbpress / wordpress avatar?


  • t0v3
    Member

    @t0v3

    Does anyone know of a plugin with which i can use on both the aforementioned sites? I’ve integrated both bbpress & wordpress so they use the same profile, and i just want to include a way for users to upload an avatar. and for it to show next to comments. their posts, and in their profile. Any help much appreciated!

Viewing 25 replies - 1 through 25 (of 35 total)

  • fel64
    Member

    @fel64

    I think the easiest thing to do is to use Louisedade’s avatar plugin ( http://bbpress.org/forums/topic/1027?replies=3 ), and then using a simple MySQL query on the WordPress side to get that data to use next to comments.

    How did you integrate profiles?


    Trent Adams
    Member

    @trent

    If you use services like MyBlogLog or Gravatar, you can use that plugin for bbPress and WordPress has a couple of plugins that also bring in those avatars into your comments. Good question fel64! How did you do it?

    Trent


    Vili
    Member

    @vilimaunula

    I have modified Dan’s Avatar Thingy to work on both WordPress and bbPress (the avatar is set in the WordPress user interface). It’s really rather easy to do.

    I actually also modified the plugin so that instead of always resizing an image to a certain size, it instead checks that the image is not bigger than X*Y, and only acts if it is.

    Tell me, if you are interested, and I can e-mail you the source for my modified Avatar Thingy. Note, though, that I made the modifications with my own website in mind, so it isn’t really an “out-of-the-box” solution, and you will most certainly need to do some coding to get it work for you (much depends on how exactly your bbPress is intergrated with WordPress).

    Why don’t you copy the code here or upload and link to it? If anyone’s interested they can modify it then.


    Vili
    Member

    @vilimaunula

    Ok, here’s what I have, commented. The comments that start with “VILI” are mine.

    Please keep in mind two things:

    a) This is strictly speaking a WordPress plugin, not a bbPress one. The functionality is simply extended to also cover an integrated bbPress installation. (And yes, this means that you need to install this in your WordPress, not your bbPress.)

    b) I hacked this for my own purposes, so it may not be pretty, and it certainly won’t be ready for use without you reading through the code. If someone is interested in working to make it functional as an “out of the box” solution, then by all means go ahead.

    Finally, the original Dan’s Avatar Thingy can be found here.

    <?php
    /*
    Plugin Name: Vili's Avatar Thingy
    Plugin URI: http://www.vertebratesilence.com/
    Description: Displays an avatar next to posts or comments based on username. Based on Dan's Avatar Thingy (http://www.cheesemasterdan.com/).
    Version: 0.1
    Author: Vili Maunula
    Author URI: http://www.vertebratesilence.com/
    */

    // Variable declarations
    // VILI: These were changed from Dan's Avatar Thingy, in which you only had default
    // size settings into which all avatars were resized.

    $avatar_max_width = 100; // Max avatar width
    $avatar_max_height = 100; // Max avatar height
    $avatar_max_upload_size = 15360; // Max file size in bytes
    $avatars_path = ABSPATH."wp-content/avatars";

    function cmd_show_avatar()
    {
    global $wpdb;
    global $avatars_path;

    // VILI: The following is a boolean setting I use to detect whether the page
    // being served is a forum page. In practice, I have
    // <?php global $forumpage;
    // $forumpage = TRUE; ?>
    // at the beginning of each forum page (I use WordPress headers in my integrated
    // setup, but if your bbPress uses its own headers, just stick it there). If
    // anyone knows a more cost-efficient way of detecting whether a page shown is
    // a forum page, let me know.
    global $forumpage;

    if ($forumpage == FALSE) {
    $the_author_name = get_comment_author();
    if($the_author_name == "" or $the_author_name == __('Anonymous'))
    { // Avatar for posts
    $the_author = get_the_author_id();
    $the_author_name = get_the_author();
    } else { // Avatar for comments - only for registered users
    $the_comment_ID = get_comment_ID();
    $the_author = $wpdb->get_var("SELECT user_ID FROM $wpdb->comments WHERE comment_ID='$the_comment_ID'");
    }
    } else {
    $the_author_name = get_post_author();
    $the_author = get_post_author_id();
    }

    $image_path = get_bloginfo('wpurl')."/wp-content/avatars/";
    $the_avatar = $image_path.$the_author.".jpg";
    if(file_exists("$avatars_path/$the_author.jpg"))
    {
    echo '<img src="' . $the_avatar. '" alt="' . $the_author_name . '" class="cmd-avatar" />';
    } elseif(file_exists("$avatars_path/default.jpg")) {
    echo '<img src="' . $image_path . 'default.jpg" alt="Unregistered" class="cmd-avatar" />';
    }
    // If the file doesn't exist then return nothing...
    }

    add_action ('admin_menu', 'cmd_avatar_menu');

    function cmd_avatar_menu()
    {
    add_submenu_page('profile.php', '', 'Your Avatar', 0, __FILE__, 'cmd_avatar_profile');
    }

    function cmd_avatar_profile()
    {
    global $userdata;
    global $avatar_max_width;
    global $avatar_max_height;
    global $avatar_max_upload_size;
    global $avatars_path;
    get_currentuserinfo();

    if(!file_exists($avatars_path))
    {
    $mkdir_result = @mkdir($avatars_path, "0755");
    if(!$mkdir_result)
    {
    echo '<div id="message" class="error fade">The folder' . $avatars_path . ' does not exist and could not be created automatically. Please create it and assign 0755 permissions then try using this plugin again.
    </div>';
    die();
    }
    }

    if ($_POST['cmd_action'] == 'upload_avatar')
    {
    if ($_FILES['cmd_avatar_file']['size'] > 0 && $_FILES['cmd_avatar_file']['size'] < $_POST['MAX_FILE_SIZE'])
    {
    $uploaddir = ABSPATH."wp-content/avatars/";
    $uploadfile = $uploaddir . $userdata->ID . '.jpg';
    list($width, $height, $type, $attr) = getimagesize($_FILES['cmd_avatar_file']['tmp_name']);

    // VILI: The following calculates the size into which the
    // image needs to be put. If it's under the MAX limits, nothing
    // is done, otherwise resizing takes place. This probably
    // could be written more elegantly.

    $widthratio = $width / $avatar_max_width;
    $heightratio = $height / $avatar_max_height;
    if ($widthratio > 1 && $heightratio > 1 && $widthratio > $heightratio) {
    $usewidth = $width / $widthratio;
    $useheight = $height / $widthratio;
    } elseif ($widthratio > 1 && $heightratio > 1 && $widthratio < $heightratio) {
    $useheight = $height / $heightratio;
    $usewidth = $width / $heightratio;
    } elseif ($widthratio > 1) {
    $usewidth = $width / $widthratio;
    $useheight = $height / $widthratio;
    } elseif ($heightratio > 1) {
    $useheight = $height / $heightratio;
    $usewidth = $width / $heightratio;
    } else {
    $usewidth = $width;
    $useheight = $height;
    }

    $cmd_avatar_image = imagecreatetruecolor ($usewidth, $useheight);
    switch ($type)
    {
    case 1: // GIF
    $image = imagecreatefromgif($_FILES['cmd_avatar_file']['tmp_name']);
    imagecopyresampled($cmd_avatar_image, $image, 0, 0, 0, 0, $usewidth, $useheight, $width, $height);
    $avatar_created = (imagejpeg($cmd_avatar_image, $uploadfile, 100) ? TRUE : FALSE);
    imagedestroy($image);
    imagedestroy($cmd_avatar_image);
    break;
    case 2: // JPEG
    $image = imagecreatefromjpeg($_FILES['cmd_avatar_file']['tmp_name']);
    imagecopyresampled($cmd_avatar_image, $image, 0, 0, 0, 0, $usewidth, $useheight, $width, $height);
    $avatar_created = (imagejpeg($cmd_avatar_image, $uploadfile, 100) ? TRUE : FALSE);
    imagedestroy($image);
    imagedestroy($cmd_avatar_image);
    break;
    case 3: // PNG
    $image = imagecreatefrompng($_FILES['cmd_avatar_file']['tmp_name']);
    imagecopyresampled($cmd_avatar_image, $image, 0, 0, 0, 0, $usewidth, $useheight, $width, $height);
    $avatar_created = (imagejpeg($cmd_avatar_image, $uploadfile, 100) ? TRUE : FALSE);
    imagedestroy($image);
    imagedestroy($cmd_avatar_image);
    break;
    default:
    $avatar_created = FALSE;
    break;
    }
    if ($avatar_created) {
    echo '<div id="message" class="updated fade">File uploaded successfully.
    </div>';
    } else {
    echo '<div id="message" class="error fade">File upload failed.
    </div>';
    }
    }
    }
    echo '
    <div class="wrap">
    <h2>Your Avatar</h2>
    <form name="cmd_avatar" id="your-profile" action="' . $PHP_SELF . '" method="post" enctype="multipart/form-data">
    <fieldset>
    <legend>Avatar</legend>';

    $the_user = $userdata->ID;

    $avatars_path = ABSPATH."wp-content/avatars";
    $image_path = get_bloginfo('wpurl')."/wp-content/avatars/";
    $the_avatar = $image_path.$the_user.".jpg";

    if(file_exists("$avatars_path/$the_user.jpg")){
    echo '
    <img src="' . $the_avatar . '" alt="' . $userdata->user_login . '" class="cmd-avatar">';
    } else {
    echo 'No avatar found...';
    }
    echo '

    <label>Filename: </label>
    <input type="file" accept="Pictures" name="cmd_avatar_file" />

    <input type="hidden" name="MAX_FILE_SIZE" value="' . $avatar_max_upload_size . '" />
    <input type="hidden" name="cmd_action" value="upload_avatar" />
    Click browse to find your avatar image. It can be JPG, GIF or PNG and should be ' . $avatar_max_width . ' x ' . $avatar_max_height . ' pixels or less (if bigger, it will be resized).Images should also be no larger than ' . $avatar_max_upload_size / 1024 . 'KBCurrently animated GIFs are not supported.
    </fieldset>
    <br clear="all" />
    <p class="submit">
    <input type="submit" name="cmd_avatar_update" value="Update Profile &raquo;" />

    </form>
    </div>';
    }

    ?>

    Thank you!

    For testing if it’s bb it might be easiest to do exactly what you did but with a global variable bb uses anyway, such as $bbdb or whatever you feel like – saves you having to put in the declarations.


    Vili
    Member

    @vilimaunula

    Indeed, would save some work. :)

    Hey this is cool. But, what tags does one put in the bbpress template to get the avatar from Dan’s Avatar thing to show up? Or do I have to have the bbpress avatar upload plugin installed and add it via this?


    Vili
    Member

    @vilimaunula

    daddy, you will need to use the “Vili’s avatar thingy” code that I posted above, and then just use the same function as with WordPress:

    <?php if(function_exists('cmd_show_avatar')){ cmd_show_avatar(); } ?>

    And what needs to be installed? The above as a bbpress plugin, then use Dan’s (also installed) as per usual?

    Installed it as a bbpress plugin and now:

    Parse error: parse error, unexpected $ in /homepages/27/d120217802/htdocs/forums/my-plugins/bb-avatar.php on line 192

    Vili said it was a WP plugin.

    If this is the case, how does it work with bbpress?

    Do I need to install the avatar-upload thing as well? I am confused….

    Thanks for the help so far.


    Vili
    Member

    @vilimaunula

    Sorry for the confusion. :)

    It’s a WordPress plugin. And no, you don’t need to install any avatar-upload thing, or indeed any other extra plugin to get this to work.

    The function works both on WordPress and bbPress, but since it is a WordPress plugin (and thus a WordPress function) you will need to make WordPress functions available to bbPress. This is covered in the Integration with WordPress page in the bbPress documentation (see the last section, “Functions”).

    I hope this clears things up a little.

    Works great vilimaunula! I really love Dans/Vili avatar thingy :) It’s a nice solution.

    Got ya! Thanks a lot.

    Still giving me that error – Parse error: parse error, unexpected $ in /homepages/27/d120217802/htdocs/wp-content/plugins/cmdavatar.php on line 193

    I just replaced Dan’s plugin with yours.

    Thanks.


    Vili
    Member

    @vilimaunula

    Is this on a WordPress or a bbPress page, dyaddydad? Have you done a full bbPress integration, including the “functions” section? Do you use the $forumpage variable as suggested in my post with the code? Did you uninstall Dan’s plugin before uploading mine?

    WordPress. I have deleted Dan’s. When I try to activate it or on every single page when it is activated. Can you e-mail me the code so that I have the exact version or post it in the plugins bit. Awgandrews ATHIS gmail.com .

    Same again through:

    Parse error: parse error, unexpected $ in /homepages/27/d120217802/htdocs/wp-content/plugins/cmdavatar.php on line 193

    I haven’t intergrated it with bbpress yet, but since I can’t get it to activate, this doesn’t seem to be the problem.

    Thanks!

    Why don’t you open the file, go to line 193, and systematically take out one $ at a time until it works?


    Vili
    Member

    @vilimaunula

    There’s something odd there, as the code is 193 lines long, i.e. the line 193 includes only “?>”.

    Anyway, I’ll send you the code in a sec by email.


    Vili
    Member

    @vilimaunula

    Hmm. Actually, the code that I copy-pasted from the above seems to be different from what I have on my hard drive. At least a number of “<p>” tags appear to be missing.

    Hi!

    If you use the avatar plugin from Suleiman (here) on a WPMU install, you can use this plugin. I’m using it with bbpress 0.8.1 and the Crystal theme. Instructions in the file.

    HTH

    Regards,

    Rune

    Hi guys,

    “Small” problem: when I try to activate Vili’s plugin in my WordPress plugin admin pannel, I get the following message:

    “The plugin could not be activated for it’s causing a fatal error.”

    :’( Any clue what the problem might be?

    I’m using Wordpres 2.2 and BBpress 0.8.1, French install.

    I didn’t change anything in Vili’s PHP, but maybe I should have?

    I’m not programmer, so please help me :) Thank you so much in advance!


    scienceprodigy
    Member

    @scienceprodigy

    Vili. I have Dan’s avatar thing working on my wordpress blog, and I have installed bbpress and have been having the hardest time getting the integration to work. I am not very familiar with php, so if you could tell me what I am doing wrong, I would be grateful.

    I have bbpress installed in a subfolder one level up from my wordpress install in a folder called ‘forums’. I read all the comments here, and have looked at the Function integration part of the “Integration with WordPress” post per your suggestion. I added the code:

    require_once(‘path/to/wp-blog-header.php’);

    to the bbpress config.php file, and it throws an error when I load bbpress. I have tried using ‘wp-blog-header.php’ and ‘/wp-blog-header.php’ and ‘/’ and even ‘ ‘ as the path to the file, and nothing works, it throws an error every time. I even tried a backslash! lol

Viewing 25 replies - 1 through 25 (of 35 total)

You must be logged in to reply to this topic.