MyBB Community Forums

Full Version: Post avatar in editpost
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
I'm building up my own newthread/newreply/editpost and I need to show poster avatar. In newthread/newreply cases this is really easy just because the poster is the currently logged in user and I can use {$mybb->user['avatar']} variable, but in editpost I need to fetch the "attached-to-post poster avatar": for normal users this is not a problem because they are able to edit only their own posts and so {$mybb->user['avatar']} is ok. But what if a moderator or admin edit an user's post?

How can I achieve this? I took a look at showthread.php {$post['useravatar']} variable and tried to replicate it in editpost.php but didn't succeeded.

REgards,
Shade

Also, I would like to know why my threads are always being visited ab. 4000 times in few hours when others only 60 or 70 times. There might be a bug in the visit counter.
Bump. I'm really in a hurry so it would be appreciated if someone could solve my issue ASAP.
Bump again. Smile
Bump...
Since it is not completely clear what you wish to do i think nobody has responded yet.
So to get it right you want to display the avatar for the person that last edited your thread/post?
Or do you want to display the avatar from the user who posted the thread/ post
(2012-10-19, 08:04 PM)anori Wrote: [ -> ]Or do you want to display the avatar from the user who posted the thread/ post

This is what I'm aiming to do. I'm sorry for the misunderstanding, I'm not english so I probably didn't explained myself properly.
You will need a plugin then to do that. That would run a query that uses the post id (pid) to determine the user name and then a query that would retrieve the avatar of that user.

As far as i know that would be the only way.
I see. Is there someone who could develop this feature for me?
I finally succeeded after a long developing period to have a working solution that doesn't affect too much the database. I used the awesome Patches plugin by frostschutz to edit editpost.php file within the following steps: I recommend using it.

1. Edit the query

Since editpost.php executes a simple_select query to fetch the post data from posts table, we have to edit it to include (LEFT JOIN) the users table to fetch the user data relative to the post. Around line 42, find and replace:

$query = $db->simple_select("posts", "*", "pid='$pid'");

with

$query = $db->query("
                  SELECT p.*, u.username AS userusername, u.avatar AS useravatar, u.usergroup AS userusergroup, u.displaygroup AS dispusergroup, u.uid AS useruid
                  FROM ".TABLE_PREFIX."posts p
                  LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)
                  WHERE p.pid='".$pid."'
              ");

2. Format usernames, avatar and dateline

Straight before the last eval (eval("\$editpost = \"".$templates->get("editpost")."\";")Wink, add the following code:

$post['avatar'] = $post['useravatar'];
$post['profilelink'] = format_name($post['userusername'], $post['userusergroup'], $post['dispusergroup']);
$post['profilelink'] = build_profile_link($post['profilelink'], $post['useruid']);
$post['postdate'] = my_date($mybb->settings['dateformat'], $post['dateline']);
$post['posttime'] = my_date($mybb->settings['timeformat'], $post['dateline']);

You can adapt it to your needs.

3. Edit editpost template

Now that we've edited editpost.php we have to include our new variables into our editpost templates. {$post['profilelink']}, for example, will display the formatted username (with link) of the user who posted the post. Just place them where you want them to appear and that's it!

Feel free to contribute to a better method if you have one. I don't know how to avoid querying the database at the moment so this is the best I can do.