2012-12-02, 09:28 PM
I asked a while ago in the Support forum a solution for my target which was display the user's basic informations (formatted username and avatar) in editpost view.
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:
with
2. Format usernames, avatar and dateline
Straight before the last eval (eval("\$editpost = \"".$templates->get("editpost")."\";"), add the following code:
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.
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")."\";"), 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.