Recent Topics

1 Dec 17, 2004 18:29    

EDIT: This is the second version of this plugin (ignore the version number - it's my idea of funny). This version, thanks to the help in this thread, uses the author's prefered name as the alt text AND the title for the avatar. IE was willing to use alt for a mouseover, but Mozilla didn't like it. Mozilla does it on the title tag, so anyway now you know.

I suggest this be a very high priority number, which puts it last on the list of renderers. Credit to mattbta for the topicon plugin. This was that once upon a time. Without further ado, copy this whole deal as _avatar.renderer.php and save it in your plugins/renderers folder. Tweak the tweakables that begin at line, and you absolutely must change $avatar_full_path to reflect your installation.

<?php 
/*
 * Plugin Name: Author Avatar, Version: .6.a.null.IV.eight
 * The query-free version (in case your doctor recommends less queries)
 * 
 * Author: Ed Bennett - http://wonderwinds.com
 * Cloned from the work of Matt Brotherson - http://www.brotherson.com/
 *
 * STEP ONE: Save this as _avatar.renderer.php and upload it to your 
 * plugins/renderers folder
 *
 * BEFORE YOU DO THAT: Scroll down a wee bit and set your parameters described
 * at the beginning of function author_avatar() - lines 73 to 84 in my editor.
 * each parameter has a little bit of info above it to help you set it correctly.
 *
 * As written, avatars can be .jpg or .gif or .png up to 100 pixels wide and 
 * 100 pixels tall and 6Kbytes (6144 bytes).  If it can not find a matching
 * file it doesn't do anything.  If it finds a matching file that is too wide
 * or tall or big it ignores it.
 *
 * I intend/hope to release a hacked version of b2upload.php that will 
 * automatically name the file according to what this plugin expects, 
 * and to allow a user to over-write their own avatar.  No promises!
 */
if( !defined('DB_USER') ) die( 'Please, do not access this page directly.' );

/**
 * Includes:
 */
require_once dirname(__FILE__).'/../renderer.class.php';

/**
 * @package plugins
 */
class b2evotar_Rendererplugin extends RendererPlugin
{
	var $code = 'b2evotar';
	var $name = 'Author Avatar';
	var $priority = 125;
	var $apply_when = 'opt-out';
	var $apply_to_html = true; 
	var $apply_to_xml = false;  // strip the BBcode
	var $short_desc = 'inserts an avatar in your post';
	var $long_desc = 'This checks the media folder for an avatar image and inserts it in the post.  Avatar files are named "avatar_loginname.jpg (or gif or png), can not be more than 100 pixels tall, can not be more than 100 pixels wide, and can not be over 6Kbytes.  Avatars can be uploaded via the image upload utility.  To replace an avatar you have to get the admin to delete your existing avatar first.';

	/**
	 * Constructor
   *
	 * {@internal b2evotar_Rendererplugin::b2evotar_Rendererplugin(-)}} 
	 */
	function b2evotar_Rendererplugin()
	{
		$this->short_desc = T_('inserts an avatar in your post');
		$this->long_desc = T_('This checks the media folder for an avatar image and inserts it in the post.  Avatar files are named "avatar_loginname.jpg (or gif or png), can not be more than 100 pixels tall, can not be more than 100 pixels wide, and can not be over 6Kbytes.  Avatars can be uploaded via the image upload utility.  To replace an avatar you have to get the admin to delete your existing avatar first.');
	}

	function render( & $content, $format )
	{
		if( ! parent::render( $content, $format ) )
		{	// We cannot render the required format
			return false;
		}
		$content = author_avatar($content);
		return true;
	}

}

function author_avatar($text)
{
	global $Item, $DB, $tableusers;

	// $media_full_path MUST be the full absolute URL to your media folder
	$media_full_path = "http://your_domain_name.xyz/whatever/path/media/";
	// $max_width and $max_height are in pixels, $max_bytes is in bytes - set as desired
	$max_width = 100;
	$max_height = 100;
	$max_bytes = 6144;
	// rightmargin and leftmargin exist in rsc/img.css, or create your own class in your css
	$class = "rightmargin";
	// change if you want to but I can't imagine why
	$prefix = "avatar_";
	// $avatar_dir should not need to be changed, but hey what do I know?
	$avatar_dir = $DOC_ROOT."media/";
	
	$content = '';

	$author_login = $Item->Author->get('login');

	// lets see if a jpg exists
	$filetype = '.jpg';
	$filename = $avatar_dir.$prefix.strtolower($author_login).$filetype;
	if (file_exists($filename)) {
		$imagename = $media_full_path.$prefix.strtolower($author_login).$filetype;
		} else {
		$filetype = 'unknown';
		}
	// if not lets try for a gif
	if( $filetype == 'unknown' ) {
		$filetype = ".gif";
		$filename = $avatar_dir.$prefix.strtolower($author_login).$filetype;
		if (file_exists($filename)) {
			$imagename = $media_full_path.$prefix.strtolower($author_login).$filetype;
			} else {
			$filetype = 'unknown';
			}
		}
	// no jpg, no gif: lets try png
	if( $filetype == 'unknown' ) {
		$filetype = ".png";
		$filename = $avatar_dir.$prefix.strtolower($author_login).$filetype;
		if (file_exists($filename)) {
			$imagename = $media_full_path.$prefix.strtolower($author_login).$filetype;
			} else {
			$filetype = 'unknown';
			}
		}

	// you can add additional image types by repeating this sequence as desired
	// getimagesize() supports multiple image types, depending on your php version

	// if we have an imagename lets make sure it's not too big
	if ($imagename) {
		list($width, $height, $type, $attr) = getimagesize($filename);
		if( $width > $max_width ) { // someone wasn't following instructions!
			$imagename = false;
			}
		if( $height > $max_height ) { // someone wasn't following instructions!
			$imagename = false;
			}
		if( filesize($filename) > $max_bytes ) { // someone wasn't following instructions!
			$imagename = false;
			}
		}

	// if we still have an imagename lets make an avatar out of it
	if ($imagename) {
		$img_alt_text = $Item->Author->get('preferedname');
		$content .= '<img src="'.$imagename;
		$content .= '" alt="'.$img_alt_text;
		$content .= '" title="'.$img_alt_text;
		$content .= '" class="'.$class;
		$content .= '" '.$attr.' />';
		$content .= "\n";
		} else {
		$content = "<!--no avatar-->";
		}

	$text = $content.$text;

	return $text;

} // end function author_avatar

// Register the plugin:
$this->register( new b2evotar_Rendererplugin() );

?>

It's also on my blog but I think I covered all you need here.

2 Dec 17, 2004 19:40

Looks good. Thanks for the credits!

On to your quest... have you tried


$img_alt_text = 'Avatar for: '.$Item->Author->login;

or


$img_alt_text = $Item->'Avatar for: '.Author->nickname;

I haven't verified, but I think that should work if you want to spit out the login name or the nickname. If that doesn't work or you want a full name type deal, I can try and figure out how to access the user class and get that info.

3 Dec 17, 2004 20:02

I had thought about querying for the nickname field, but there's no certainty that the nickname field has content. That's why I wanted to go with 'prefered name' - there has to be something prefered because at it's simplest level prefered name will default to login. Plus once the user says "I prefer this" it makes sense to identify them that way. It occurs to me now that if I

SELECT user_login, user_firstname, user_lastname, user_nickname, user_idmode FROM $tableusers WHERE ID = $author_id (or whatever I called it)

I could then use user_idmode to tell me which of the other values builds the prefered name. Maybe not exactly this, but fairly close.

Gosh now it seems easy. Why was it so hard last night? On the bright side this means I get to do a new rev! I always wanted to do a rev using Roman Numerals :)

4 Dec 17, 2004 20:10

You could do that, but it adds one more query on top of the queries we're doing. (I'm trying to figure out a way to reuse the Item object in my topicon plugin to avoid sql.)

I'm at work and can't relly test, but does $Item->Author->firstname and $Item->Author->lastname work?

or perhaps $Item->get('preferedname') ?

5 Dec 17, 2004 20:48

mattbta wrote:

You could do that, but it adds one more query on top of the queries we're doing...
(snip)
...or perhaps $Item->get('preferedname') ?

I'll try the last, but I don't think it works. For some reason it appears that the assumption is prefered name is only useful for displaying. I always forget if it's get or dget, but I'll try it both ways and see what happens.

At present I'm intending to replace the query that gets me login name because that was another one I couldn't just grab without displaying. It's possible and probable I was just working it incorrectly, but in the end I went with a query based on current user ID.

No biggie really. A functional avatar system exists even if it's not the most optimumized personalized doodad ever made. Even so, I appreciate your help with this because optimizing and personalizing are good things to do.

EDIT: Oh that was too easy! If you want to get something use 'get'. I'll rewrite the gizmo using preferedname as the avatar alt text, and using a get to get the login id in the first place. THANKS!

6 Dec 17, 2004 21:52

Cool. Thanks mattbta for your help on this. As far as I care, I'm done with an avatar plugin. It's set up for three types of images and tests the image to meet admin-assignable criteria. It looks in media, which is where uploading goes. It organizes avatars by the naming convention, and it gives a nice mouse-over across multiple browsers.

One day it might be nice to link the avatar to something, but what? I don't know if it's still here or not, but the user/member/other version of _profile.php would be a good candidate.

7 Dec 17, 2004 22:25

Theoretically, this plugin version doesn't exist. ;):D

8 Jan 19, 2005 14:00

I just added this plugin ... I think I did it correctly... but now Im getting a weird bit of code appearing on every page just BEFORE the first post of every page and also just before the list of Renderers on the Write Tab and the Settings>Plugins Tab in the admin area.
It looks like this:

? 

Any ideas why?

9 Jan 19, 2005 15:19

Nope. Are you using the newest release (v0.9.0.10 or .11)? Just curious. Also, and I don't know if it really matters, you might want to make sure there is no white space at the end of the plugin file.

10 Jan 19, 2005 15:43

Im using v0.9.0.10 .
When you say to check the whitespace in the plugin file do you mean the _avatar.renderer.php file or plugin.class.php file?

11 Jan 19, 2005 17:08

Both I guess. I couldn't remember the other file that had to be edited, and I wasn't even sure there was one. Once I do one of these hacks I sort of brain-dump it and move on.

Anyway it's best to go over all files associated. The final ?> should have nothing after it - not even a next line. Some editors do funny things so it could be the editor you're using adding something you don't see. Check it with notepad if you haven't, though personally I'm not into using notepad to hack. I like the free version of html-kit, but that's just me.

Also make sure the other file "looks" proper in the area you did the hack. To add a chunk of junk to where your plugins are listed in the back office is weird and probably not coming from the actual plugin file.

Dunno though. Didn't have this problem when writing it or on the two blogs I use it on.

12 Jan 21, 2005 00:54

Instead of having the plugin link to the avatar stored on your site, would it be possible to link it to the avatar stored on the gravatar.com site?

13 Jan 21, 2005 01:04

Probably, but I don't know anything about gravatars. Gravity and tar is a gravatar? Can't be. Gotta be groovy avatar. Most of the plugin, if I recall correctly, was dealing with "does this author have an avatar and if so I'll use it". Anyway if a gravatar has a nice naming convention that can easily associate a blogger to a file or path then yeah I reckon it could. I'd have to also look at the plugin again since once I'm done with a hack I delete it from my personal memory. (Both hard storage and ram since I don't have enough of either.)

14 Jan 25, 2005 22:13

the gravatar.com site just deals with avatars. You sign up, and upload one to their server, then if you go to a site that is gravatar enabled and you leave a comment, your avatar is displayed on the site where you left the comment!

It works generally on the email address of the poster, which helps form the gravatar.com url to their stored location of the avatar image. on their website they provide the following code, but I have little php knowledge myself and when I tried to fiddle with my comments files, they didn't work anymore 8|

Implementing gravatars with PHP is quite simple. PHP provides both md5() and urlencode() functions, allowing us to create the gravatar URL with ease. Assume the following data:

$email = "someone@somewhere.com";
$default = "http://www.somewhere.com/homestar.jpg";
$size = 40;

You can construct your gravatar url with the following php code:

$grav_url = "http://www.gravatar.com/avatar.php?
gravatar_id=".md5($email).
"&amp;default=".urlencode($default).
"&amp;size=".$size;

Once the gravatar URL is created, you can output it whenever you please:

<img src="<?php echo $grav_url; ?>" alt="" />

15 Feb 01, 2005 05:25

hi! I'm the only one who uses my blogsite so what i am thinking is showing an avatar based on the "main" category of the post.

i have seen the code already and stuck in $Item->get(

can't find the proper var/function to call the "main" category of the post.

help? thanks!

17 Feb 01, 2005 06:19

hehe.. =) my bad. thanks for the help EdB!

19 Feb 02, 2005 05:56

=) thanks mattbta for the nice plugin.. =) i have installed it already but i don't have topicons yet.. hehe.. thanks guys!

20 Apr 01, 2005 11:45

I might have missed something, in that case, pardon my post, but after I uploaded the edited _avatar.renderer.php file, how do I set an avatar for a user and how do I display it?

21 May 20, 2005 19:30

I copied it to the correct directory, but I get this error:

Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/saberco/public_html/b2evolution/plugins/renderers/_avatar.renderer.php on line 37

which is:

36  class b2evotar_Rendererplugin extends RendererPlugin
37  {
38  	var $code = 'b2evotar';
39  	var $name = 'Author Avatar';

What's wrong? Thanks, Colin

22 Jul 05, 2005 10:49

Iceline: in the folder you have set for the avatars to live, a user's avatar is set by naming the image file avatar_user.gif(or jpg or png) where user is the username.

24 Sep 24, 2005 16:49

I've just done a fresh install of the latest version, and I've not been able to get this renderer to work, I get these two errors.


Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/orta/public_html/b2evolution/blogs/plugins/renderers/_avatar.renderer.php on line 2

Parse error: parse error, unexpected T_STRING in /home/orta/public_html/b2evolution/blogs/plugins/renderers/_avatar.renderer.php on line 2

25 Sep 24, 2005 17:59

I have not given any thought to updating this plugin to be compatible with the 0.9.1 (dawn) release. Sorry, but I got too much on my plate to right now to get to some of these things. There are a lot of oldies I'd love to bring into the new world. Just can't :(

I suggest you add the plugins page to your feed reader so that when someone does come up with a dawn-friendly version of this (or any other hack that rises to the level of the plugins page) you'll know right away.

26 Oct 09, 2005 01:19

ok so let me see if I've got this right-

all I have to do is copy the code in the first post and paste it onto the html code of my blog and save it in my plugins/renderers folder.

27 Nov 05, 2005 18:48

Hey my skin Lightality (will be published soon) supports three user customizable styles of avatars: Category, Author, and Blog

You can check it out here:
http://blog.balupton.nghosting.org/index.php

And the topic is here:
http://forums.b2evolution.net//viewtopic.php?p=28300

Heres some sample code:


$AvatarStyles = array("Blog","Author");//array("Category","Blog","Author");
if(IndexExists($_GET,"AvatarStyle")){
	if(ValueExists($AvatarStyles, $_GET["AvatarStyle"])){	
		setcookie("AvatarStyle", $_GET["AvatarStyle"]);
		$Lightality->AvatarStyle = $_GET["AvatarStyle"];
		
	}else{
		setcookie("AvatarStyle", $AvatarStyles[0]);
		$Lightality->AvatarStyle = $AvatarStyles[0];
	}
}else{
	if(!IndexExists($_COOKIE, "AvatarStyle")){
		setcookie("AvatarStyle", $AvatarStyles[0]);
		$Lightality->AvatarStyle = $AvatarStyles[0];
	}else{
		$Lightality->AvatarStyle = $_COOKIE["AvatarStyle"];
	}
}

	switch($Lightality->AvatarStyle){
		case "Author":
			$Avatar = "avatars/".$Lightality->AvatarStyle."/".$Item->Author->login.".jpg";
			break;
		case "Blog":
			$Avatar = "avatars/".$Lightality->AvatarStyle."/".$Item->blog_ID.".jpg";
			break;
		case "Category":				
			$Avatar = "avatars/".$Lightality->AvatarStyle."/".$Item->main_cat_ID.".jpg";
			break;
		case "default":				
			$Avatar = "avatars/noimage.jpg";
			break;
	}
	if(file_exists(dirname(__FILE__)."/../".$Avatar))
		$Avatar = "$baseurl/Lightality/$Avatar";
	else
		$Avatar = "";

28 Jan 04, 2006 16:51

Someone pleeeeeease update this for v0.9.1!

Me love you long time.

29 Feb 05, 2006 08:05

Is there any info on how to get this to work on Pheonix?. I searched the forums, but don't see it anywhere. Am I missing something?

Thanks in advance.

30 Feb 17, 2006 11:01

No Point in writing a Plugin for 1.6 while it is in Alpha or Beta, or whatever as the Plugin Structure is always getting makeovers.

I will be releasing my skin Lightality soon which features Avatars, so you can wait for that if you want.

31 Feb 17, 2006 14:32

Promises are worth what it costs to join the forums, but I've every intention of doing an Avatars plugin for the future release(s) of b2evolution. I'm in the same boat as balupton is though: why do it for 1.6 when we already know the 1.7CVS world is different and have every reason to expect the beta and finally releases to be even differenter?

QUESTION for those looking forward:
The first Avatar plugin expected users to upload images with specific file names into the media folder. Since any blog will be able to have either blog or user specific folders (but not both) what would be the best way for your bloggers to submit avatars? Maybe they upload a file and ask you (as admin) to make it be their avatar? Maybe a completely different upload utility that puts avatars (and only avatars) into the media folder?

The existing avatar plugin allows for jpg or gif or png formats (but not jpeg!). Technically that means an extra load on your server for every post, though I reckon it's a small load. Is the option desirable or would y'all prefer to tell your bloggers they must use a specific format?

32 Feb 17, 2006 14:37

Ok EdB, I'll start up dreamweaver, give you some sourcecode and some of my ideas ;)

Just give me a few minutes.

33 Feb 17, 2006 15:00

Heres the best way to do a image check:

function getExtension($link){
        //you owe balupton for this one
	return strtolower(substr($link,strrpos($link,'.')+1));
}


	
//you owe balupton for this one
//	If the file is a image then append it to the array
$extension = getExtension($file);
$goodExtensions = "[jpg][png][jpeg][tiff][gif][bmp]";
if(strstr($goodExtensions,"[$extension]") != false){

As for the how should they submit images, y not use the file/image upload in the backoffice, make a folder called 'Avatars' and then make it so if the avatar exists 'Avatars/PostTitle.ext' display it.....

Now if your doing it so each user has a avatar you could get the user to upload a image into their directory called 'avatar.ext', and use that.

This is not how i did it in Lightality, but i guess it is just as logical.
I will also be adding Avatars for Posts in Lightality soon.

But then here is the biggest problem i faced when i was thinking of how to do it;
The background or color theme of the images - Each Skin has a Different Background or Color Scheme, which means that either you have Unmatching Avatars or Avatars for each Skin.

Actually u just got me thinking on how i'm actually gonna do this new avatar style, and the Post Avatars in Lightality.....

34 Jul 22, 2006 11:01

Not any chance that you could release this as a standard 1.8 plugin? Would appriciate that much.

Cheers

35 Jul 22, 2006 11:45

Eh? Huh? ......

It won't be dependent on anything.... meaning that it will be a 'standard plugin for 1.8'....

Actually... How does a plugin become not a standard plugin?

36 Jul 23, 2006 10:22

Well maybe I was not clear in my reply. How do I implement the code you have written above? In the top icon plugin? Or in some other way? Since I'm no code guru I might need some hinters... cough cough :D

37 Jul 23, 2006 12:06

<?php $Plugins->Plugins['Avatars']->DisplayAvatar($Item); ?>

Thats the current plan, and then item will be referenced, and the appropriate avatar will be displayed based on the users preference.

To force a avatar display u could also do
<?php $Plugins->Plugins['Avatars']->DisplayAvatar($Item,'Style','Skin'); ?>

Not sure wether the calling is correct, but you get the idea.

Edit: Thought this was about the [url=http://forums.b2evolution.net//viewtopic.php?p=39821#39821]Avatar/Icon plugin[/url] i'm working on ;) My bad.

38 Aug 15, 2006 19:59

EdB and mattbta...you two are brilliant. Period.

I've been reading this thread for about 20 minutes trying to make sense of your instructions. It's almost like Greek to me.

Considering...

Tweak the tweakables that begin at line, and you absolutely must change $avatar_full_path to reflect your installation.

What are the tweakables?

Where is the $avatar_full_path to change and what would the full path encompass?

...please

forever the newbie,

kat

39 Aug 15, 2006 23:55

Looks like I have a text error in the very first post. Oopsie!

First you change this line to be the full URL to your media folder:

// $media_full_path MUST be the full absolute URL to your media folder
$media_full_path = "http://your_domain_name.xyz/whatever/path/media/";

Next you can mandate some details about the avatar files

// $max_width and $max_height are in pixels, $max_bytes is in bytes - set as desired
$max_width = 100;
$max_height = 100;
$max_bytes = 6144;

Avatar on the right? For left make this be 'leftmargin'

// rightmargin and leftmargin exist in rsc/img.css, or create your own class in your css
$class = "rightmargin";

BTW this is a very old plugin for a very old version. I never tested it with 0.9.2 and always recommend anyone using 0.9.0.* do the upgrade thing. 0.9.2 is way better than all the dot-nines before it that it's worth losing whatever plugins and hacks aren't compatible. To me anyway!

40 Aug 16, 2006 00:22

Thanks :)

So is "must change $avatar_full_path to reflect your installation" a mistake then and it should just read $media_full_path?

I'm using v 0.9.2 with Kubrickb2gemublogs skin (if that makes any difference or not).

41 Aug 16, 2006 01:58

Correct: avatar_full_path should be media_full_path. "Tweaking" simply refers to the minor changes you might want to make to some of the details about how big avatars can be and where the get aligned in your skin.

I haven't tried this plugin with 0.9.2 but your skin selection shouldn't matter. Let us know if it works for you in 0.9.2, and if not let us know what type of error (or whatever) you get. Balupton is working on an avatar plugin for the 1.8 generation, so if this one doesn't work I can try to make it be 0.9.2 compatible and put out the final ever version of this file.

42 Aug 25, 2006 12:02

want to use the plugin @ 1.8 must I activate the plugin in the backoffice? canĀ“t find the plugin in the backoffice :(

43 Aug 25, 2006 17:12

This version won't work in 1.anything because of how b2evolution is totally different on the inside. Sorry, but the only way we'll see an Avatar plugin for 1.8 is when balupton makes one.

44 Sep 02, 2006 19:59

Is there a 1.8 version of this plugin? (sorry, I had my list set to oldest first. DIdn't see the previous posts)

45 Sep 06, 2006 05:39

Ya I'm waiting for Balupton to finish the coding. I tried taking a look at it myself and remembered something, I dont' know jack.

I miss my avatar... :'(

46 Sep 06, 2006 06:37

I could provide a skin hack if you want, i made that back in january... It's what i'm going to port over to the plugin. But yeh, you would need to manually add it into your skin.

47 Sep 06, 2006 21:21

that would be wonderful, i certainly wouldn't mind having to manually add it to my skin. So please, provide away!

49 Oct 06, 2006 16:31

Totally a noob here, I installed b2e, i'm used to running wordpress, i installed the avatars plugin (not balupton's) for ver 0.9.0.12 how to I call it in the skin?


Form is loading...