PDA

View Full Version : Show avatar in PM, I wrote the plugin but there is error !


sadiq6210
06-16-2013, 08:43 AM
Hi dears,
I want to write a plugin to show the user avatars in PM list (inbox/outbox....etc)

I added this plugin:

require_once('./includes/functions_user.php');
if (THIS_SCRIPT == 'private')
{
$pm[avatarurl] = fetch_avatar_url($pm['fromuserid']);
if (!$pm[avatarurl]) {
$pm[avatarurl] = $stylevar['imgdir_misc'] . 'images/misc/unknown.gif';
} else {
$pm[avatarurl] = $vbulletin->options['bburl'] . '/' . $pm[avatarurl][0];
}
}


Then I added this to template(pm_messagelistbit)
<img src="{vb:raw pm.avatarurl}" />


It is working and the avatar shows but only in first row !
I mean there is avatar only in FIRST pm (one avatar in each page).

Any help?

kh99
06-16-2013, 11:06 AM
Which hook did you use for your plugin?

sadiq6210
06-16-2013, 02:28 PM
Which hook did you use for your plugin?


private_messagelist_messagebit

Lynne
06-16-2013, 03:30 PM
It works just fine for me (although the avatars are huge - you probably want the thumbnail size ones).

sadiq6210
06-17-2013, 08:38 AM
It works just fine for me (although the avatars are huge - you probably want the thumbnail size ones).

It was from a mod, this issue solved after I disable this mod
https://vborg.vbsupport.ru/showthread.php?t=277502

I will contact with Joe

Thanks Lynne. Thanks Kevin :)

sadiq6210
06-17-2013, 09:05 AM
I faced another issue

In inbox it is working perfect
but in (send folder / outbox) it shows the avatar for sender (my avatar)

I want to show the avatar for the user who will receive the message.

This is the Inbox (OK)

https://vborg.vbsupport.ru/attachment.php?attachmentid=145472&stc=1&d=1371463500



This is the send folder (All shows my avatar only!)

https://vborg.vbsupport.ru/attachment.php?attachmentid=145473&stc=1&d=1371463500

kh99
06-17-2013, 12:01 PM
Maybe you could do something like:
$avid = $pm['fromuserid'];
if ($avid == $vbulletin->userinfo['userid'])
{
$avid = $pm['touserid']
}

Then use $avid in place of $pm['fromuserid'] in the rest of your plugin code.

sadiq6210
06-18-2013, 07:08 PM
Maybe you could do something like:
$avid = $pm['fromuserid'];
if ($avid == $vbulletin->userinfo['userid'])
{
$avid = $pm['touserid']
}

Then use $avid in place of $pm['fromuserid'] in the rest of your plugin code.

I am confused
Sorry Kevin but could you please explain this more?
Should I add the previous code to the same plugin?

Thanks very much

Lynne
06-18-2013, 08:12 PM
You would add it above this line:
$pm[avatarurl] = fetch_avatar_url($pm['fromuserid']);

But also change that line to:
$pm[avatarurl] = fetch_avatar_url($avid);

sadiq6210
06-19-2013, 05:59 AM
You would add it above this line:
$pm[avatarurl] = fetch_avatar_url($pm['fromuserid']);

But also change that line to:
$pm[avatarurl] = fetch_avatar_url($avid);

So I need to modify the plugin only?
I did but it is not working, all avatars is broken and I got this error above the page



Parse error: syntax error, unexpected '}' in /home/userhere/public_html/forum/private.php(2274) : eval()'d code on line 8

Parse error: syntax error, unexpected '}' in /home/userhere/public_html/forum/private.php(2274) : eval()'d code on line 8

Parse error: syntax error, unexpected '}' in /home/userhere/public_html/forum/private.php(2274) : eval()'d code on line 8

Parse error: syntax error, unexpected '}' in /home/userhere/public_html/forum/private.php(2274) : eval()'d code on line 8

Parse error: syntax error, unexpected '}' in /home/userhere/public_html/forum/private.php(2274) : eval()'d code on line 8

Parse error: syntax error, unexpected '}' in /home/userhere/public_html/forum/private.php(2274) : eval()'d code on line 8

Parse error: syntax error, unexpected '}' in /home/userhere/public_html/forum/private.php(2274) : eval()'d code on line 8

Parse error: syntax error, unexpected '}' in /home/userhere/public_html/forum/private.php(2274) : eval()'d code on line 8

Parse error: syntax error, unexpected '}' in /home/userhere/public_html/forum/private.php(2274) : eval()'d code on line 8

Parse error: syntax error, unexpected '}' in /home/userhere/public_html/forum/private.php(2274) : eval()'d code on line 8

Parse error: syntax error, unexpected '}' in /home/userhere/public_html/forum/private.php(2274) : eval()'d code on line 8

Parse error: syntax error, unexpected '}' in /home/userhere/public_html/forum/private.php(2274) : eval()'d code on line 8

Parse error: syntax error, unexpected '}' in /home/userhere/public_html/forum/private.php(2274) : eval()'d code on line 8

Parse error: syntax error, unexpected '}' in /home/userhere/public_html/forum/private.php(2274) : eval()'d code on line 8

Parse error: syntax error, unexpected '}' in /home/userhere/public_html/forum/private.php(2274) : eval()'d code on line 8

Parse error: syntax error, unexpected '}' in /home/userhere/public_html/forum/private.php(2274) : eval()'d code on line 8

Parse error: syntax error, unexpected '}' in /home/userhere/public_html/forum/private.php(2274) : eval()'d code on line 8

Parse error: syntax error, unexpected '}' in /home/userhere/public_html/forum/private.php(2274) : eval()'d code on line 8

Parse error: syntax error, unexpected '}' in /home/userhere/public_html/forum/private.php(2274) : eval()'d code on line 8

Parse error: syntax error, unexpected '}' in /home/userhere/public_html/forum/private.php(2274) : eval()'d code on line 8

Parse error: syntax error, unexpected '}' in /home/userhere/public_html/forum/private.php(2274) : eval()'d code on line 8

Parse error: syntax error, unexpected '}' in /home/userhere/public_html/forum/private.php(2274) : eval()'d code on line 8

Parse error: syntax error, unexpected '}' in /home/userhere/public_html/forum/private.php(2274) : eval()'d code on line 8

Parse error: syntax error, unexpected '}' in /home/userhere/public_html/forum/private.php(2274) : eval()'d code on line 8

Parse error: syntax error, unexpected '}' in /home/userhere/public_html/forum/private.php(2274) : eval()'d code on line 8



This is the plugin after modified

require_once('./includes/functions_user.php');
if (THIS_SCRIPT == 'private')
{
$avid = $pm['fromuserid'];
if ($avid == $vbulletin->userinfo['userid'])
{
$avid = $pm['touserid']
}
$pm[avatarurl] = fetch_avatar_url($avid);
if (!$pm[avatarurl]) {
$pm[avatarurl] = $stylevar['imgdir_misc'] . 'images/misc/unknown.gif';
} else {
$pm[avatarurl] = $vbulletin->options['bburl'] . '/' . $pm[avatarurl][0];
}
}

:erm:

Zachery
06-19-2013, 06:06 AM
Good document markup helps, looks like you were missing a ; on your line 7, I added it, formatted it, and moved the require_once inside of the conditional.



if (THIS_SCRIPT == 'private')
{
require_once('./includes/functions_user.php');
$avid = $pm['fromuserid'];
if ($avid == $vbulletin->userinfo['userid'])
{
$avid = $pm['touserid'];
}
$pm[avatarurl] = fetch_avatar_url($avid);
if (!$pm[avatarurl])
{
$pm[avatarurl] = $stylevar['imgdir_misc'] . 'images/misc/unknown.gif';
}
else
{
$pm[avatarurl] = $vbulletin->options['bburl'] . '/' . $pm[avatarurl][0];
}
}

sadiq6210
06-19-2013, 09:10 AM
Thanks Zachery :)

The error gone but in sent folder all avatars is (unknown.gif)
see the screen-shot for sent folder

https://vborg.vbsupport.ru/attachment.php?attachmentid=145498&stc=1&d=1371636569


In inbox, the username shown under the PM title is for the person who sent the PM for me. so I want to show the avatar for that username (who sent the PM for me)

In sent folder, the username shown under the PM title is for the person who will receive my PM, so I want to show the avatar for that username (who will receive my PM)

kh99
06-19-2013, 09:54 AM
Thanks Zachery :)

The error gone but in sent folder all avatars is (unknown.gif)
see the screen-shot for sent folder

That's my fault. After all that, it turns out my solution is wrong. There is actually an array of "to" users, so I don't know what you would want to display if the message has been sent to more than one user. But a better way to check if you are viewing the Sent folder is to check the folder id, so you could do something like this:

if (THIS_SCRIPT == 'private')
{
require_once('./includes/functions_user.php');
if ($folderid != -1)
{
$avid = $pm['fromuserid'];
}
else
{
// This is the Sent folder, so find the first userid
// that is not the viewing user, checking first 'cc'
// then 'bcc' users.
$tousers = unserialize($pm['touserarray']);
if (!empty($tousers))
{
$toids = (empty($tousers['cc']) ? array() : $tousers['cc']);
if (!empty($tousers['bcc']))
{
$toids = array_merge($toids, $tousers['bcc']);
}
foreach ($toids AS $id => $username)
{
if ($id != $vbulletin->userinfo['userid'])
{
$avid = $id;
break;
}
}
}
}
$pm[avatarurl] = fetch_avatar_url($avid);
if (!$pm[avatarurl])
{
$pm[avatarurl] = $stylevar['imgdir_misc'] . 'images/misc/unknown.gif';
}
else
{
$pm[avatarurl] = $vbulletin->options['bburl'] . '/' . $pm[avatarurl][0];
}
}

sadiq6210
06-19-2013, 10:40 AM
That's my fault. After all that, it turns out my solution is wrong. There is actually an array of "to" users, so I don't know what you would want to display if the message has been sent to more than one user. But a better way to check if you are viewing the Sent folder is to check the folder id, so you could do something like this:

if (THIS_SCRIPT == 'private')
{
require_once('./includes/functions_user.php');
if ($folderid != -1)
{
$avid = $pm['fromuserid'];
}
else
{
// This is the Sent folder, so find the first userid
// that is not the viewing user, checking first 'cc'
// then 'bcc' users.
$tousers = unserialize($pm['touserarray']);
if (!empty($tousers))
{
$toids = (empty($tousers['cc']) ? array() : $tousers['cc']);
if (!empty($tousers['bcc']))
{
$toids = array_merge($toids, $tousers['bcc']);
}
foreach ($toids AS $id => $username)
{
if ($id != $vbulletin->userinfo['userid'])
{
$avid = $id;
break;
}
}
}
}
$pm[avatarurl] = fetch_avatar_url($avid);
if (!$pm[avatarurl])
{
$pm[avatarurl] = $stylevar['imgdir_misc'] . 'images/misc/unknown.gif';
}
else
{
$pm[avatarurl] = $vbulletin->options['bburl'] . '/' . $pm[avatarurl][0];
}
}

Wow :up: working perfect as a charm

Thanks dear
Can I use your code in my mod that I will release to the public here in vb.org?

kh99
06-19-2013, 10:42 AM
Can I use your code in my mod that I will release to the public here in vb.org?

You can use that code in your mod. But you might want to come up with some way to indicate if a message was sent to more than one user. (or not, if it doesn't bother you :) ).

sadiq6210
06-19-2013, 10:50 AM
You can use that code in your mod. But you might want to come up with some way to indicate if a message was sent to more than one user. (or not, if it doesn't bother you :) ).

Although it is not bothering me, I will try to find a solution because I want to release it to the public.

Thanks Kevin

You must 'Like' someone else's post before liking any more by kh99. :)

kh99
06-19-2013, 11:23 AM
Although it is not bothering me, I will try to find a solution because I want to release it to the public.

You could release it and wait to see if anyone else cares. Maybe no one will request it.