Skip to main content
Topic: Adding Buddy BG (Read 3452 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Adding Buddy BG

Hi,

I attempting to port another simple mod of mine (HLBM) here. This mod will need to change this line:
Code: [Select]
<div class="post_wrapper ', $message['approved'] ? ($message['alternate'] == 0 ? 'windowbg' : 'windowbg2') : 'approvebg', '">
To:
Code: [Select]
<div class="post_wrapper ', $message['approved'] && $message['member']['is_buddy'] ? 'buddybg' : ($message['approved'] ? ($message['alternate'] == 0 ? 'windowbg' : 'windowbg2') : 'approvebg'), '">

I cannot see is_buddy anywhere in display controller. Is there any is_buddy in Elk? Can this be done via hook? How?

Re: Adding Buddy BG

Reply #1

is_buddy is loaded in loadMemberContext, so, yes it's available.

Not that I can see.
Bugs creator.
Features destroyer.
Template killer.

Re: Adding Buddy BG

Reply #2

I think it may be in the $message array, $message['is_buddy'] perhaps?

The only way I can think to do it without edits would be with some JS.  In a hook you keep track of the is buddy flags and output a JS object with the id's, and then have some JS function that on load reads that and changes the backgrounds.  Thats just a thought.

Re: Adding Buddy BG

Reply #3

Thank you @emanuele and @Spuds . I think I get the idea a bit. Javascript may be the only solution to avoid modifying the message tempalte.

I am thinking rather than injecting script in the header, it will be better to add it via template layer somewhere after the message itself at the bottom.

Current idea of template code:
Code: [Select]
function template_HLBM_below()
{
// I don't think $message can be used here. Help!!! I cannot get it to work.
if ($message['approved'] && $message['member']['is_buddy']) {
echo '
<script>
function changeColor(buddybg) {
var hlbm = document.getElementById('forumposts').getElementsByClassName('post_wrapper windowbg');
hlbm.style.color = buddybg;
// Not finish. Then what? What about windowbg2? Repeat this again?
// Or use this one instead???
document.getElementById('forumposts').className = post_wrapper windowbg
document.getElementById('forumposts').className.replace(post_wrapper buddybg)
// If correct, repeat for windowbg2???
document.getElementById('forumposts').className = post_wrapper windowbg2
document.getElementById('forumposts').className.replace(post_wrapper buddybg)
}
</script>';
}
}

The javascript is supposed to get the class windowbg and windowbg2 if the message is approved and is a buddy message. But I cannot test it as I don't think $message can be simply used just like that. Anything that can make it global and use here?

Re: Adding Buddy BG

Reply #4

Add a hook in elkarte_settings for
 
Code: [Select]
integrate_prepare_display_context
Example:
Code: [Select]
colorize_buddy|SUBSDIR/ColorizeBuddy.subs.php

Code: (ColorizeBuddy.subs.php) [Select]
<?php
function colorize_buddy(&$output, &$message)
{
global $user_info;

if (in_array($message['id_member'], $user_info['buddies']))
{
addInlineJavascript('
$( "#msg'. $message['id_msg'] . '" ).parent().css( "background-color", "#ccc" );
', true);
}
}
Thorsten "TE" Eurich
------------------------

Re: Adding Buddy BG

Reply #5

Or:
Code: [Select]
<?php
function colorize_buddy(&$output, &$message)
{
global $user_info;

if (in_array($message['id_member'], $user_info['buddies']))
{
addInlineJavascript('
$( "#msg'. $message['id_msg'] . '" ).parent().addClass("buddybg");
', true);
}
}
So that styling can go to the css. ;)

I would be tempted to do something more complex, but probably is not worth at the moment. O:-)

Though, that could be an interesting spot to "do some changes"... O:-) O:-) O:-) O:-)
Bugs creator.
Features destroyer.
Template killer.

Re: Adding Buddy BG

Reply #6

You are all very wonderful and helpful indeed. Thank you very much guys.

Re: Adding Buddy BG

Reply #7

After testing the code, I realize that the code is targeting this code's parent:
Code: [Select]
<a class="post_anchor" id="msg' . $message['id'] . '"></a>

Unfortunately, if the said buddy message is on the top of the display page, it ends up wrongly changing this code's parent:
Code: [Select]
<a id="msg', $context['first_message'], '">

How to avoid it?
Last Edit: November 27, 2014, 08:00:28 am by ahrasis

Re: Adding Buddy BG

Reply #8

Ah, sorry.. didn't knew the anchor wasn't present there... You can also use the ID #info_xx (that's the post's header) and jump from there to the parent three levels up.

Code: [Select]
$( "#info_'. $message['id_msg'] . '" ).parent().parent().parent().css( "background-color", "#ccc" );
Thorsten "TE" Eurich
------------------------

Re: Adding Buddy BG

Reply #9

Work like a charm. Thank you TE.

Addon is ready and already posted in the addon board.


Re: Adding Buddy BG

Reply #11

Great!

But how do I make use of this? And just out of my curiosity, why is $message['classes'] positioned before the default class? Shouldn't it be after to override it?

Re: Adding Buddy BG

Reply #12

You don't need the JS part anymore, just modify the $Output Array..

Code: [Select]
function colorize_buddy(&$output, &$message)
{
global $user_info;

if (in_array($message['id_member'], $user_info['buddies']))
$output['classes'] = array("buddybg");
}
Untested though  :D
Thorsten "TE" Eurich
------------------------

Re: Adding Buddy BG

Reply #13

Ok. That easier. But will that replaces the default class or adds a new class? I kinda think it adds a new class but shouldn't it be after and not before the default class (windowbg / windowbg2 / approvebg) for it to work?

 

Re: Adding Buddy BG

Reply #14

Just to be picky:
Code: [Select]
function colorize_buddy(&$output, &$message)
{
global $user_info;

if (in_array($message['id_member'], $user_info['buddies']))

$output['classes'][] = "buddybg";
}
:D

Quote from: ahrasis – But will that replaces the default class or adds a new class?
Adds new.

Quote from: ahrasis – I kinda think it adds a new class but shouldn't it be after and not before the default class (windowbg / windowbg2 / approvebg) for it to work?
AFAIK the order of the classes are used is not relevant.
What is relevant is the order the classes are declared in the stylesheet (i.e. in index.css for example). ;)
Bugs creator.
Features destroyer.
Template killer.