bbPress

Simple, fast, elegant

bbPress Plugin Browser »

Avatar Upload (0.8.3)

Download

Version: 0.8.3

Other Versions

Last Updated: 2007-9-9

Requires bbPress Version: 0.8.2 or higher

Compatible up to: 0.8.2.1

Author Homepage »

Plugin Homepage »

Average Rating

5 stars
4 stars
3 stars
2 stars
1 star
(18)

Your Rating

Author: Louise Dade


  1. i am having a problem activating the plugin itself. when i click activate, the page doesn't refresh to tell me it has been activated, and just hangs there blank. i don't understand what the problem could be.

    Posted: 2 years ago #
  2. i seem to have resolved the issue with activating the plugin and i've uploaded my own, but now when i add the code given to the post.php file, it breaks somehow. the page still displays, but the image appears above the name (i have it set to below) and the RSS Feed link that should appear at the end, now appears above the author's name as well. it is also not showing the replies to the post.

    here is the code for my post.php (just kakumei with the avatarupload code added)

    <div class="threadauthor">
    			<strong><?php post_author_link(); ?></strong>
    			<?php avatarupload_display(get_post_author_id()); ?>
    			  <small><?php post_author_title(); ?></small>
    
    		</div>
    
    		<div class="threadpost">
    			<div class="post"><?php post_text(); ?></div>
    			<div class="poststuff"><?php printf( __('Posted %s ago'), bb_get_post_time() ); ?> <a href="<?php post_anchor_link(); ?>">#</a> <?php post_ip_link(); ?> <?php post_edit_link(); ?> <?php post_delete_link(); ?></div>
    		</div>

    you may need to copy and paste into notepad to see the whole code.

    here is my forum to see what is happening: http://www.bringyourjacket.com/forums/topic/your-first-topic?replies=1

    it also now appears that my avatar is not sticking to my userID. I know that I have uploaded an avatar and it is in the avatars folder, however my avatar page says i have not uploaded one.

    Posted: 2 years ago #
  3. Hi antonskey, the problem you are having regarding the positioning of the avatar is a cascading style sheets issue.

    The thread author div (.threadauthor) is set with overflow: hidden; in the CSS, which means that it can never be longer than the post content div (.threadpost). This means that the extra content in the post author div gets cut-off. Unfortunately, the avatar image does not get cut-off and overhangs into the next post in the thread.

    In the example posts you linked to, the post content is not long enough to push the bottom of the post container beyond the height of the post author container when it has an avatar in it.

    You can solve this by changing the kakumei CSS file a little.

    Oh, but first of all, you might want to add line-breaks to the code you posted (in the post.php template), like so...

    <div class="threadauthor">
      <strong><?php post_author_link(); ?></strong><br />
      <?php avatarupload_display(get_post_author_id()); ?><br />
      <small><?php post_author_title(); ?></small>
    </div>

    .
    Then in style.css, scroll down to #thread li and add a line, so it looks like this:

    #thread li {
        min-height: 200px; /* <-- add this line */
        padding: 1.5em 1.0em;
        line-height: 1.5em;
    }

    .
    This sets a minimum height for the post content div - I made it 200px to be sure it stretches beyond the height of the thread author div. Warning: this will only in fully standards compliant browsers. Certain "Browsers Which Shall Remain Nameless" will not understand min-width -- there are hacks to circumvent this somewhere, but you'll need to look them up yourself, I'm afraid.

    Can you show me the error you are getting on your avatar page (take a screen shot maybe)? And by 'avatar page' do you mean the upload screen?

    Posted: 2 years ago #
  4. Everything works very nicely for regular members, but when I try to upload an avatar for an admin or moderator (logged in as such, for that specific account), I get an error: "You do not have permission to upload an avatar for this user." Have any ideas for me?

    Thanks for writing this great plugin!

    Posted: 2 years ago #
  5. arlenbyrd, I think you have actually come across a deliberate limitation of the bbPress capabilities for member levels. Moderators can not edit another user's profile, therefore they also can not edit another members' avatar.

    Admins, however, should be able to edit other members' profiles and avatars -- and indeed I got no errors when I tested it as an administrator. Maybe it is a bozo problem? In the past some installations of bbPress have had a bit of a problem with users wrongly being labelled as bozos.

    Can you upload admin/moderator avatars when logged in as keymaster?

    Posted: 2 years ago #
  6. Interestingly, no, when logged in as keymaster I cannot even upload the keymaster's avatar. And yet, when logged in as a regular member I can modify that member's avatar. But when logged in as a moderator I cannot upload an avatar for that moderator (just like as keymaster). Hrm.

    Posted: 2 years ago #
  7. I get this error when trying to upload avatars (the plugin is installed and activated)

    The file could not be saved to the 'avatars' folder.

    I changed the permissions of the avatars folder ot '666' as the information file explained, but to no avail. Doe's anyone have any idea of why this might be happening, and how to fix it?

    I also tried leaving the folder permissions as is but this did not work either.

    Posted: 2 years ago #
  8. arlenbryd: Hrm indeed! I have no idea what is happening, but I can't shake the feeling that it's connected to some sort of moderator/admin/keymaster capabilities problem.

    Can you create a brand new admin user (register a clean user - you can remove them afterwards) and see if that user can upload their own and others' avatars?

    Also, is there anybody else out there having the same problem, or anybody with an intimate knowledge of bbPress know what could be the problem???

    RatherBeBiking: I've reponsed to your query in the bbPress forum "Plugin: Avatar Upload" topic.

    Posted: 2 years ago #
  9. Ah-hah! You were right - somehow the admin/moderator users were set as bozos :P Now it's working just fine. Thank you for your help and insight!

    Posted: 2 years ago #
  10. _ck_

    5 stars
    4 stars
    3 stars
    2 stars
    1 star

    Moderator

    Thanks for a great plugin! Feature requests for next version perhaps?

    1. filename requirements are too overwhelming, why not rename the file after upload (good idea for safety anyway) and let them upload anything - I've already got lots of confused members...

    2. automatic/optional resize if the file is too large

    3. allow a copy from a url, not just an upload

    I have most of these requested routines in code already after hacking up the gravatars plugin to my needs (which I have now abandoned as it has too many problems) so just ask if you'd like to see them (I warn you my code is unprofessional however, sorry)

    Posted: 2 years ago #
  11. @_ck_ - already responded to your queries in the main forum, but just to say the file is renamed after uploading anyway (it's given the username as a filename -- lowercase), so yes, I could relax the filenaming requirements.

    Resize is coming up in the next version.

    There is another Avatar plugin that allows users to enter a url -- it works different to this plugin, but can be used in conjunction -- the only confusing thing is that the location for entering the url is on a different page (the main profile edit page) for the other plugin.

    Posted: 2 years ago #
  12. _ck_

    5 stars
    4 stars
    3 stars
    2 stars
    1 star

    Moderator

    I have been tinkering with your code and I have a few suggestions/improvements that I've done.

    1. uploaded imags are displayed post-processing too quickly on fast servers before they are fully copied by the filesystem from the temporary area - this causes images to not appear in the member's browser and confuses them, even after a successful upload - you need to sleep for a few seconds ie:

    sleep(3); bb_load_template( 'avatar.php', array('success_message', 'config') );

    2. I absolutely hate the bbpress die method since it's a unthemed page and useless until they hit the back button, especially in cases like this - <b>you should take advantage of the fact you are re-loading the avatar template</b> and give the message in red there with a chance to re-upload

    Posted: 2 years ago #
  13. _ck_

    5 stars
    4 stars
    3 stars
    2 stars
    1 star

    Moderator

    3. I have a working resize method, though it's rough without a proper reduction calculation for now - just forces the max width/height
    NOTES: you must re-order how error #2 is calculated AFTER #10 is checked (and after this new routine)
    you also MUST change the upload form to allow much larger MAX_FILE_SIZE - I hard coded it to 150000 (~150k)

    This added routine changes any image uploaded that is too large in dimensions to the max width x height as a jpeg @ 90% quality.

    I'll add proper dimension resizing over the next night or two. Also there is no sharpness performed after the resize which makes overly large images look fuzzy when reduced.

    replaces code in avatar-upload.php

    // Are file dimensions greater than max_width/max_height allowed?
    	if  ($img_errs == 0)
    	{
    		// Get the dimensions
    		$dims = @getimagesize($img_temp);
    		$img_w = $dims[0];
    		$img_h = $dims[1];
    
    		if ($img_w > $config->max_width || $img_h > $config->max_height)
    		{
    			$img_errs = 10;
    		}
    	}
    
    	if (($img_errs==10) && ($img_size<200000)) {
    		$img_new = imagecreatetruecolor( $config->max_width, $config->max_height);
    		$img_up = imagecreatefromstring(file_get_contents($img_temp));
    		if (imagecopyresampled($img_new, $img_up, 0, 0, 0, 0, $config->max_width, $config->max_height, $img_w, $img_h)) {
    			if (@unlink($img_temp)) {
    				if (imagejpeg($img_new, $img_temp, 90)) {
    					$img_errs=0;
    					$img_size = filesize($img_temp);
    					list($img_w, $img_h) =  getimagesize($img_temp);
    				 }
    			 }  //  memory cleanup
    		imagedestroy($img_up);
    		imagedestroy($img_new);
    		}
    	}
    
    	// Does filesize exceeds max_bytes? You can't trust MAX_FILE_SIZE form field.
    	if ($img_errs == 0 && $img_size > $config->max_bytes)
    	{
    		$img_errs = 2;
    	}
    Posted: 2 years ago #
  14. _ck_

    5 stars
    4 stars
    3 stars
    2 stars
    1 star

    Moderator

    4. I found a HUGE problem in the way this plugin re-uses the same filename over and over even if the user changes the graphic - if the server is set to try to cache the image and the browser obeys, you'll never see the graphic change on the screen. I've got members whining all over the place that their image never changes.

    But because you use metadata for storage and don't bother to store the last uploaded avatar date or bytesize in there, the only way to track the change is the file's physical date, so I hope most filesystems cache this info, otherwise my fix is a big performance hit

    to force the browser to see the new change, yet still cache the image change this line in the main plugin around line 118

    $a[0] = bb_get_option('uri') . $config->avatar_dir . $a[0] . '?'.filemtime(BBPATH . $config->avatar_dir . $a[0]);

    also, the "?new" has to be taken out around line 76

    // echo ($status == 'new') ? '?'.time() : '';

    the problem with your logic is that most browsers see
    imagename.jpg?new and imagename.jpg as two different images. It will never force a refresh permanently.

    To fix this and cache it better, I *HIGHLY* recommend you rename and store the filename with the appended unix timestamp in a future version.

    Posted: 2 years ago #
  15. _ck_

    5 stars
    4 stars
    3 stars
    2 stars
    1 star

    Moderator

    Oh and that sleep(3) suggestion is in the wrong place. Apparently it will get called for *every* template load, not just after the successful uploads. So I moved it to right after when the string is set for a successful upload and it works properly.

    Do you really think storing the avatar in the user metadata is a good idea? Unserializing data has to be a HUGE performance hit since it has to be done every, single, time, every, single, avatar is loaded.

    Posted: 2 years ago #
  16. Where do you propose it is stored, then? Outside of the database? Especially if the name is not determinable from the poster's details, as you suggested earlier when saying the filename must be changed every time, it has to be stored somewhere. Serialisation and unserialisation only occurs if the data stored was an array; I'm not sure if it is or not in the latest version, but that's not really avoidable if you want to store it in the database.

    Posted: 2 years ago #
  17. The avatar details are stored as 'user meta' data because it was the simplest way to do it. That is where all the other user profile info is stored and it I did not have to create a new table.

    It is not serialised (in the proper sense), but stored as a pipe-delimited string in the format:

    username.jpg|image width|image height|avatar-upload

    The "avatar-upload" bit is a flag used to distinguish between a user-uploaded avatar and an Identicon (automatically created avatar).

    That's one single DB call to add to or update the database and zero additional calls to extract data from the database (because all user meta data is called within the bbPress core code) - except for special cases, such as when a new avatar is uploaded or user meta is unavailable, when it calls from the database.

    The resulting string is then made usable with $array = explode("|", $string).

    I understand you point about the caching of images - and will consider a unique naming convention, but there are already a couple of poeple who have written their own extensions/plugins that rely on the fact that the avatars are named fairly consistantly (the filename is consistant at least, but the extension might change, but that is trival to deal with).

    As the other issues

    1. Images being shown too quickly -- I have not encountered this personally, but it certainly makes sense to cover the eventuality.

    2. I don't why I didn't think of that. Couldn't see the wood for the trees I suppose -- "that's how bbPress does it, so that's how I'll do it".

    3. Resize code -- thanks.

    Right... must work on next version this weekend!

    Posted: 2 years ago #
  18. _ck_

    5 stars
    4 stars
    3 stars
    2 stars
    1 star

    Moderator

    As far as the naming, you can continue to use the same method, just add the filename.ext?fileunixtimestamp to the name to make caching behave. I just have to benchmark at some point the speed difference between fetching the filedate through the OS vs. storing it in the meta data. I hope I am not giving the server hard drive a workout.

    I'm a stickler for logging and feel it should be in the meta. I believe any user action, login, upload, etc. should be stored with the timestamp and ip. WP & BB do that for posts, but for the life of me I have no understanding why after years they still don't store that data upon logging in!

    My next trick, which will require much more research is to patch uploaded GIFs so they only loop a certain number of times. I have many users with very fast animated gifs that annoy the heck out of me when scrolling through posts. There's a byte near the end of the file that controls how many times it will loop. Browsers like firefox can control that but most people don't know.

    Oh and I think I will write some code pull down any existing gravatar for the users email and ask them if they just want to use that. I've got a few hundreds people on the wordpress side using gravatars but that service is horribly unreliable. The plugin I have for them keeps wiping out the locally stored images too :( Nice to have a real avatar plugin.

    Posted: 2 years ago #
  19. Version 0.5 has been released. This is an important updatre and includes the following changes:

    * Added an auto resizing functions. If the image dimensions are greater than the maximum allowed then it automatically gets resized maintaining the image's aspect ratio and image type.

    * Improved mime-type handling. Using getimagesize() to ascertain if the file is a valid image, removing the need to maintain the mime-type array in the config section.

    * Error messages are now shown on the template itself, not the bb_die() method (I haven't bothered to add extra CSS to kakumei theme to highlight an "error", I'm reusing another style).

    * Added 3 second sleep to enable the server to do its 'thing' before the browser tries to display the image for those lucky enough to have speedy servers!

    What I haven't done in this version:

    * anything about the caching issue. Although I did add a clumsy, kludgy note about refreshing the browser if the avatar doesn't appear to have changed. This problem is not unique to file uploads such as this, I've lost track of the number of times I've had to tell a client to refresh their browser when they can't see changes I've made to their website (e.g. CSS caching is horrendous in "certain browsers" *cough IE cough*).

    I see what you mean now, _ck_ and I'll add that shortly (so that'll be version 0.5.1) coming up later - or tomorrow.

    Posted: 2 years ago #
  20. OK, I've bumped to version 0.6 because I've incorporated Identicons into the trunk - so there is no need for the branch.

    I've also implented the filename.jpg?timestamp DB storage trick to combat browser cache problems.

    I know, you wait weeks for an update and then two come along at once ;-P

    Posted: 2 years ago #

RSS feed for this topic

Add a Comment »

You must log in to post.

Code is Poetry.