PDA

View Full Version : How to get 'userid' in bbcode_quote template?


oldz442
08-25-2012, 12:44 PM
I am trying to get the userid# of the quoted user so I can display a mini avatar beside the quote in the bbcode_quote template. I can get the username fine, but not the id. {vb:raw postid.userid} seems to get the original poster id # which is no good. I have the below so far. vB 4.2.0.


<a href="member.php/{vb:raw userid}-{vb:raw username}">
<img src="image.php?u={vb:raw userid}" style="width:27px; height:27px" alt="{vb:raw username}" title="{vb:raw username}" /></a>

kh99
08-25-2012, 01:06 PM
The user id of the quoted user isn't available - the username of the quoted user comes from the [quote] tag option, but it doesn't include the userid.

You could look it up in the database, but offhand I don't see a good place to do that (and of course it would require a plugin or some other way of modifying the code).

oldz442
08-25-2012, 03:37 PM
Thx. Used member.php?username={vb:raw username} instead for the link part which works fine. Just need to figure out displaying the avatar img now.

Scanu
08-25-2012, 04:06 PM
I don't know what exactly hook you should use, but trough a vb function you can fetch the userid of the "username" (bbcode option [quote="option"]) and then register the userid in the bbcode_quote template

--------------- Added 1345915367 at 1345915367 ---------------

Oh i just remembed that you can just get username from a userid using fetch_userinfo, so this is useless

oldz442
08-26-2012, 01:34 AM
Thanks.

I am completely new to this hook/template thing, and never touched it before. I have the below plugin so far, but it is wrong of course, as it gives errors in the weblogs (PHP Fatal error: Only variables can be passed by reference...). What am I missing? All I need really is the User ID returned to bbcode_quote so I can complete a URL so it displays the avatar (ie. ...src="image.php?u={vb:raw quote_userid}...)

require_once('./includes/functions_user.php');

$userid = fetch_userinfo(1);
$quote_userid = $userid;

$templater = vB_Template::create('bbcode_quote');
$templater->register('quote_userid', $quote_userid);
$templater->render();

Scanu
08-26-2012, 10:06 AM
Thanks.

I am completely new to this hook/template thing, and never touched it before. I have the below plugin so far, but it is wrong of course, as it gives errors in the weblogs (PHP Fatal error: Only variables can be passed by reference...). What am I missing? All I need really is the User ID returned to bbcode_quote so I can complete a URL so it displays the avatar (ie. ...src="image.php?u={vb:raw quote_userid}...)

require_once('./includes/functions_user.php');

$userid = fetch_userinfo(1);
$quote_userid = $userid;

$templater = vB_Template::create('bbcode_quote');
$templater->register('quote_userid', $quote_userid);
$templater->render();
Why are you using 1 as paramater? As i said you don't need fetch_userinfo function as it requires the userid (that you don't know) all you need to do is a query something like

SELECT+userid+from+user+WHERE+username+=+$option

Where option is what the user put after = (quote="option"), but i don't how you can get it and in what hook.. +

oldz442
08-30-2012, 07:57 AM
Tried something else. First, I changed to file based avatars instead of dbase based. I then edited class_bbcode.php with code below in the 'handle_bbcode_quote' function to get the userid (which worked fine).

$result = $vbulletin->db->query_read("SELECT * FROM " . TABLE_PREFIX . "post");

while ($row = $vbulletin->db->fetch_array($result)) {
if ($row['postid'] == $postid) {
$userid = $row['userid'];
}
}


I also added the below code to display the avatar (underneath the above code). It 'works'. However, the avatar is not updated if the user changes their avatar. ie. avatar1_9.gif is the new avatar, but is still trying to display avatar1_8.gif.

require_once(DIR . '/includes/functions_user.php');
$quote_avatar_url = fetch_avatar_url($userid);

if ($quote_avatar_url) {
$quote_avatar_url = $quote_avatar_url[0];
} else {
$quote_avatar_url = "images/misc/unknown.gif";
}