Skip to main content
Topic: Trying To Find Fully Hook Solution For Offline Avatar Addon (Read 2636 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Trying To Find Fully Hook Solution For Offline Avatar Addon

As you know I have prepared an addon that turn offline member's avatar to gray. However, the addon is not fully hook because I cannot make the following hook to work.

The hook:
Code: [Select]
'integrate_prepare_display_context' => 'Bola_Main|SOURCEDIR/addons/BOLA.subs.php',

The main code (tested as correct):
Code: [Select]
		// Add blur_avatars class to offline avatar in display page
addInlineJavascript('
$( "#info_'. $message['id_msg'] . '" ).parent().parent().parent().find(".avatar").addClass("blur_avatars");
', true);

The problematic, conditional, non-working code:
Code: [Select]
if (!empty($modSettings['bola_enable']) && !$message['member']['online']['is_online'])
Code: [Select]
if (!empty($modSettings['bola_enable']) && in_array($message['id_member'], !$user['is_online']))

Both of the above code are aimed to be conditions so that if the addon are enable and the said user are not online, the avatar will be blurred / grayed via blur_avatars css class. However, I cannot get either one to work which of course due to wrong coding.

In the manual modification, I change the default avatar injection to $poster_div to this:
Code: [Select]
		if (!empty($settings['show_user_images']) && empty($options['show_no_avatars']) && !empty($message['member']['avatar']['image']) && $message['member']['online']['is_online'])
$poster_div .= '
<li class="listlevel1 poster_avatar">
<a class="linklevel1" href="' . $scripturl . '?action=profile;u=' . $message['member']['id'] . '">
' . $message['member']['avatar']['image'] . '
</a>
</li>';

if (!empty($settings['show_user_images']) && empty($options['show_no_avatars']) && !empty($message['member']['avatar']['image']) && !$message['member']['online']['is_online'])
$poster_div .= '
<li class="listlevel1 poster_avatar">
<a class="linklevel1 blur_avatars" href="' . $scripturl . '?action=profile;u=' . $message['member']['id'] . '">
' . $message['member']['avatar']['image'] . '
</a>
</li>';

Or is it wise to override avatar css img class if user is offline by using call_integration_hook('integrate_avatar', array(&$avatar, $profile)); in Load.php instead?

I was thinking if !$profile['is_online'] then $avatar['image'] should then be <img class="avatar avatarresize blur_avatars or something like that but not sure how yet.

Any suggestions to make this thing fully work using hook and without any direct file modification are highly appreciated.

Thank you.

Re: Trying To Find Fully Hook Solution For Offline Avatar Addon

Reply #1

First, where does:
Code: [Select]
$user['is_online']
come from?
The same for:
Code: [Select]
$message['member']['online']['is_online']
I don't think $message has a "member" index, I think you mixed it with $output, so:
Code: [Select]
$output['member']['online']['is_online']

One suggestion: when you have situations like this where you try things and you don't get the expected result, the first thing to do is "print_r" or "var_dump" the variable and see if what you are using is actually there or not. If it is there, you can understand why the condition is not working, if it is not there, you can find out where is gone. ;)
Alternatively, I'm pretty sure these two lines of code are both generating errors in your log, so if you run a page and go have a look at the error log you'll find some undefined indexes. ;)
Bugs creator.
Features destroyer.
Template killer.

Re: Trying To Find Fully Hook Solution For Offline Avatar Addon

Reply #2

Quote from: emanuele –
Code: [Select]
$output['member']['online']['is_online']
Thank you @emanuele . All your helps and advises in making this hook and others work, are very much appreciated.

Quote from: emanuele – Alternatively, I'm pretty sure these two lines of code are both generating errors in your log, so if you run a page and go have a look at the error log you'll find some undefined indexes.
Oh yes. I sure see the errors but I am not so sure on how to resolve them.

Quote from: emanuele – One suggestion: when you have situations like this where you try things and you don't get the expected result, the first thing to do is "print_r" or "var_dump" the variable and see if what you are using is actually there or not. If it is there, you can understand why the condition is not working, if it is not there, you can find out where is gone.
And how can I actually (specifically) do that? I merely based my assumption on logic I know  :( , which in other other words, I do not know a lot of many many other things.  :'(  Do guide step by step if you could and hopefully I will remember and it will be useful to other newcomers to do the same too. :D

Thanks again.

Re: Trying To Find Fully Hook Solution For Offline Avatar Addon

Reply #3

A little OT: Thank you @ahrasis for this addon! Don't give up!  ;)

Re: Trying To Find Fully Hook Solution For Offline Avatar Addon

Reply #4

Quote from: ahrasis – And how can I actually (specifically) do that? I merely based my assumption on logic I know  :(
First thing, read the code (unfortunately there is not much documentation, but there isn't even much code to read, so it should be fine :P).
You are using "integrate_prepare_display_context", so, where is it called?
In Display.controller.php at:
https://github.com/elkarte/Elkarte/blob/e7e6d32ca24365a11dde18f936dc2ff86dd52dc7/sources/controllers/Display.controller.php#L1004
So, what are the two variables you have available?
$output and $message.
What do they contain?
First read:
https://github.com/elkarte/Elkarte/blob/e7e6d32ca24365a11dde18f936dc2ff86dd52dc7/sources/controllers/Display.controller.php#L955
https://github.com/elkarte/Elkarte/blob/d210298c7a53f0ed94ecd04b291f4ab0240528f6/sources/subs/Messages.subs.php#L605

And then, in your function can use:
Code: [Select]
print_r($output);
Well, for better reading experience:
Code: [Select]
echo '<pre>';
print_r($output);
echo '</pre>';
Bugs creator.
Features destroyer.
Template killer.

Re: Trying To Find Fully Hook Solution For Offline Avatar Addon

Reply #5

Ok. That is much clearer. Before this, I was trying to copy what HLBM addon was doing, hence, the confusion. I think below is the part that I really need to understand all the other elkarte codes and how they work, better.

Quote from: emanuele – And then, in your function can use:
Code: [Select]
print_r($output);
Well, for better reading experience:
Code: [Select]
echo '<pre>';
print_r($output);
echo '</pre>';

Thank you very much, this is a very useful tip to me.