Skip to:
Content
Pages
Categories
Search
Top
Bottom

Plugin: Avatar Upload


  • louisedade
    Member

    @louisedade

    Although there are already two avatar plugins available, they require that users either have their own webspace to store an avatar or use one of the avatar services (e.g. Gravatar).

    My users do not have either of those things, so I wrote an avatar upload plugin. Besides offering avatar hosting, it also allows you more control over the type and content of avatars than simply providing a link to an offsite image.

    Features

    • Bozos can not upload avatars.
    • Admins can configure the maximum allowed file size (bytes) and dimensions (pixels) of images.

      • Currently done from within the script (no Admin page interface at this time).

    • Anybody with the ‘moderate’ capability can upload another user’s avatar.

      • This ensures that inappropriate images can be removed.
      • There is no “delete avatar” function at this time, but an inappropriate image can be removed by uploading a ’safe’ image (e.g. a blank 1×1 pixel image) to replace it (you could then manually set that user as a bozo to stop them re-uploading inappropriate images.

    • File checking is carried out to ensure that:

      • The file has a valid extension (.gif, .jpeg, .jpeg, .png)
      • The file has a valid content-type (’image/gif’, ‘image/jpeg’, ‘image/png’)
      • The file extension and content-type actually match.
      • Other checks for filesize, image dimensions, etc.

    More info and ZIP download: bbPress Plugin: Avatar Upload

    I will be submitting this avatar to the bbPRess Plugin Repositry too.

Viewing 25 replies - 51 through 75 (of 128 total)

  • Sam Bauers
    Participant

    @sambauers

    @louisedade

    I’ve made a few additions to the plugin which I think will help with a few of these issues that are coming up. They are:

    1. Added an admin page for configuration.

    2. Moved the actual plugin files to the root of the plugin.

    3. Moved all other files except the readme.txt to an “additional-files” folder.

    4. Removed the plugin header from the file “avatar-upload.php”, this can now be kept only in the main plugin file (this was the root cause of the activation error that Trent reported).

    5. Updated readme.txt to reflect these changes.

    Grab it here and review it, I think it is a good first step to easing installation of the plugin, and making it more compatible with the Plugin Browser.

    http://www.network.net.au/bbpress/avatar-upload.0.7.zip


    Sam Bauers
    Participant

    @sambauers

    I have also added the ability to view installed plugins readme.txt files in the Plugin Browser. This should help with plugins like this one that have extra installation instructions.

    Sounds great Sam! Wow!

    Trent

    awesome update, thanks!


    louisedade
    Member

    @louisedade

    Thanks Sam! That’s awsome. I’ve downloaded and reviewed the code and I’ve made a couple of small modifications – added an option to the admin page and a tiny bit of validating (so that you can’t have a non-numerical or zero max_width etc — actually setting the sizes to zero will now reset the options to their “factory defaults”).

    @Plugin Users: I’m adding an unsharp mask routine to the reszing code before I commit the updates, so it might not be ready until tomorrow. If you’ve downloaded Sam’s update, you will have to do another update later.


    M
    Member

    @box87

    @louisedade – I found an image upload class the other day… it allows watermarking, resizing, bunches of other stuff, rather simple implementation. Looks pretty decent.

    http://www.verot.net/php_class_upload.htm

    I integrated it into your plugin ages ago, as well as an account picture upload feature with custom-definable dimensions for both avatar and account picture. I didn’t really want to upload it here, as there are oodles of plugins that have similar features. Would you like a peek at the source?


    _ck_
    Participant

    @_ck_

    @box87, be aware that single upload class is larger than most of the the entire bbpress core code itself – massive overkill unless you really, really really need it’s extra features?

    @louisedade – I found a major caching bug where you are not taking advantage of user meta data that has already been loaded previously in the same execution – this causes 10-30 extra mysql queries for every topic that is displayed depending on how many posts are displayed at once.

    Here’s a hacked workaround, though I am not sure it’s a good idea to tap into the user_cache directly. I’d otherwise suggest nicely using bb_get_user() as it checks the cache first but the problem with that is it fetches ALL the data if not in the cache which is overkill. Too bad there isn’t a bb_get_user_meta($id,’metaname’) but oh well – for now replace this top section of code:

    function avatarupload_get_avatar($id, $fulluri=1, $force_db=0)
    {
    global $bbdb, $user, $bb_user_cache;

    if ($force_db == 0 && ($id == $user->ID || !empty($bb_user_cache[$id])) )
    {
    if (!empty($user->avatar_file)) {
    $a = explode("|", $user->avatar_file);
    } else {
    if (!empty($bb_user_cache[$id]->avatar_file)) {
    $a = explode("|", $bb_user_cache[$id]->avatar_file);
    }
    else {return false;}
    }
    }
    else

    Drops my topic queries by 20 per page while still functioning correctly in all other cases.

    Discovered this problem via bb-benchmark


    louisedade
    Member

    @louisedade

    Ok, version 0.7 is released: including the changes by SamBauers as well as an image sharpening (unsharp mask) function.

    @Sam – Using the latest version of your plugin, I tried installing the new version of Avatar Uplaod, but it still wouldn’t read the additional-files directory. This is what it looks like over FTP: screenshot (NOTE: if there is a problem viewing it — error 403 — try cutting and pasting the URL instead – it’s probably my over-zealous image-hotlinking prevention).


    louisedade
    Member

    @louisedade

    @Box87 – thanks, but I think the class has far too many features for an avatar upload script. It would be fantastic for a fully-fledged image/photo album/file-browser plugin, but I’m not interested in going down that route.

    Avatar Upload now already has the two chief functions it lacked: resizing (including maintaining aspect ratio) and sharpening of resized truecolor images (unsharp mask). I want to keep it as simple as possible.

    I onced used a forum where the avatar feature was integrated with a generic image upload browser and my users got a bit confused. They didn’t realise it was one and the same place (they hardly EVER uploaded anything that wasn’t an avatar) – you uploaded an image and had to select the one to use as an avatar – it was possible to select an image that was too big etc. So I hacked the plugin to make it more specifically for avatars (making my own for this particular forum would have been a right-Royal pain in the [gr]ass), but I was never really happy with the forum software and ditched it for another one — until bbPress arrived!

    @_ck_ thanks, I’ll look into it. My primary concern right now is getting the plugin to play nicely with the Plugin Browser plugin.

    Here’s a hacked workaround, though I am not sure it’s a good idea to tap into the user_cache directly. I’d otherwise suggest nicely using bb_get_user() as it checks the cache first but the problem with that is it fetches ALL the data if not in the cache which is overkill. Too bad there isn’t a bb_get_user_meta($id,’metaname’) but oh well – for now replace this top section of code:

    The user _must_ be in the cache at this point if his details are being displayed next to the post, right? Implying that bb_get_user would never need to use a single query.

    There _is_ a bb_get_usermeta() already: http://trac.bbpress.org/ticket/691. It’s in the latest.


    _ck_
    Participant

    @_ck_

    Ah good to know fel64. But considering it’s not in 0.8.2.1 and we’re not altering the cache data (just reading it) my technique should be okay until everyone is using the newer core. Which might be awhile.

    (Yeah I suspected the user meta was in the cache. I really was happy to find a straightforward way to reduce those queries!)

    how does one revert back to the default identicon after they’ve uploaded a custom image?


    louisedade
    Member

    @louisedade

    On “Avatar” page in the user’s profile area, just select the “Use your identicon instead?” checkbox and press the “Use Identicon” button. You can do it for other members too if you are a moderator.

    i’m missing that option on my avatar page for some reason, i may have deleted that line by mistake. any thoughts on how i might get it back?

    Download the plugin again, substitute the old file for the new file.

    i did that and did a diff on all the files and they’re all the same. where do i get the code for avatar.php?


    louisedade
    Member

    @louisedade

    How are you installing the plugin? Are you downloading it directly or are you using the ‘Plugin browser for bbPress’ plugin? If the latter, then I think it’s not downloading properly, you need to do it manually by downloading the current ZIP file, unzipping it and follow the instructions in the readme.txt file.

    Here is the Avatar Upload plugin in the bbPRess Plugin Browser, the newest version of the code is always to be found on that page:

    http://bbpress.org/plugins/topic/46

    Click on the link “Download latest version” — or just click the following download link for now:

    http://bbpress.org/plugins/download/avatar-upload.0.7.zip

    i’m trying to reinstall it but i still seem to be missing the avatar.php file. is that in the .zip somewhere? i don’t see it, although when i unzip the file, things don’t look quite right. i have two files that are 0kb:

    Screenshot

    are “avatars” and “my-templates” supposed to be folders?

    also, i have a version of avatar.php but i’m not sure where it came from, i thought maybe i cut and pasted it from a forum post but i can’t be sure. you can see it here


    Sam Bauers
    Participant

    @sambauers

    > Using the latest version of your plugin, I tried installing the new version of Avatar Uplaod, but it still wouldn’t read the additional-files directory.

    If you don’t have the CURL library functions installed it falls back to fopen. fopen was failing to retrieve sub-directories.

    I’m fixing it now.


    louisedade
    Member

    @louisedade

    Oh! I see, the sub-sub folders are empty, I just downloaded it from here myself to check.

    When I browsed bbPress’ Subversion repository, the files ARE there — I didn’t forget to commit them! — so somehow the bbPress Plugin Browser (the one on this site, NOT Sam’s plugin) has messed up the ZIP download.

    The question is, whether it is a one-off or a systematic problem? Admins? Coders? Any ideas?

    To solve your problem outchy (and yes, somehow the identicon section got deleted in your avatar.php file), you can download files directly from the Trac browser.

    Here is the avatar.php file (long url, sorry):

    http://plugins-dev.bbpress.org/browser/avatar-upload/trunk/additional-files/my-templates/avatar.php

    You can not save that page itself, but scroll right to the bottom of it and you’ll see “Download in other formats” – just click on “Original Format” and you’ll be prompted to save a PHP file.

    You can do it for any other files you’re missing.

    perfect, the new avatar.php did the trick! thank you very, very much.


    Sam Bauers
    Participant

    @sambauers

    New Plugin Browser now in SVN.

    Fixes the subdirectory problem for non-CURL PHP installs that affects this plugin.


    HowToGeek
    Member

    @howtogeek

    This plugin is great…. I’m just having one small issue.

    If I upload a PNG image with transparency, it always ends up with black color behind it instead of being transparent. I’m assuming it’s because it’s being resized, but it’s still a little annoying.

    Is there a way to fix this?


    _ck_
    Participant

    @_ck_

    Since all resized images are changed to jpegs (I think?) the answer would be no, unless you upload an exact size so it doesn’t get resized.


    louisedade
    Member

    @louisedade

    No, the resized images keep the same image type they had originally. So a PNG will remain a PNG after being resized.

    There are some transparancy functions that can be used with GIFs and for PNGs there are also alpha channel functions.

    This is now on the “To Do” list.

    For now correctly sizing the image before upload will preserve any transparency.

Viewing 25 replies - 51 through 75 (of 128 total)

You must be logged in to reply to this topic.