Simple Colorizer

Started by Diego Andrés, June 26, 2011, 10:03:48 PM

Previous topic - Next topic

Aome

Hello guys!

I installed this mod, I use smf 2.0.4, but its not working. The subs.simplecolorizer.php file is there in sources but apparently does nothing, the name of the users appears with the regular color of the theme, not with the colour of their membergroup, do I need to change something? Thank you in advance.  :-*
I always appreciate the help, thank you!

hcfwesker

does the membergroup name color change to what color you edit it to be?  like when viewing the Membergroups page in Admin in the Ex below.  are you using html colors like,   #ff9933

Aome

Quote from: hcfwesker on April 14, 2013, 11:59:01 PM
does the membergroup name color change to what color you edit it to be?  like when viewing the Membergroups page in Admin in the Ex below.  are you using html colors like,   #ff9933

Hello!

Yes, the membergroups name appear in the color I set for them, using hex codes like cd0000 red for the banned and blue for the admin group. In the boards, where it says Topic started by Aome, the name Aome does appear with the color, but once in, seeing the actual posts, the username has no color :(

Im thinking might have something to do with other mods I have installed... I will check them and post them here as a reference. Thank you
I always appreciate the help, thank you!

hcfwesker

as long as you have no other MODs that affect membergroup color that shouldn't be the issue.  The MOD uses Hook Integrations, maybe your hosting's php is out of date and isn't calling for the hooks.  I've heard this happen before.

Aome

Hello, I detected these that somehow do something to the membergroups style, in some way. I think the second and third may be canceling one to another, but one of them works in part, because I can see the colour in the members username in the main forum part, but not in the posts and profile, that is why I have not uninstalled any of them, cause I don't know which one is working... :)

   Slashout Banned Members    1.2 
   Group Color in Posts and Profile    1.4 
   SimpleColorizer    1.0 
I always appreciate the help, thank you!

hcfwesker

Quote from: Aome on April 15, 2013, 09:12:37 AMGroup Color in Posts and Profile    1.4

I'd start with removing that one first ( Uinstall).  That's why colors dont show on post or profiles, but does elsewhere, cause that MOD is interferring.

Aome

Quote from: hcfwesker on April 15, 2013, 09:28:09 AM
Quote from: Aome on April 15, 2013, 09:12:37 AMGroup Color in Posts and Profile    1.4

I'd start with removing that one first ( Uinstall).  That's why colors dont show on post or profiles, but does elsewhere, cause that MOD is interferring.

I removed it, and it was good since apparently wasn't doing anything :) and I still have the colors in the main forum, doesn't show the colours in the posts or in the profile though... but hey, is not that bad...

I noticed in my code that the style is not showing in that part only calls the link to View the profile, but doesn't show the style for that piece of code...

Anyway, thank you, at least I got rid of an extra mod :)
I always appreciate the help, thank you!

Chen Zhen

#67
grafitus,

  I'm not positive if you are still supporting/updating this mod but I was debugging someone's forum today and noticed an issue. Where a user link already has style attributes, this mod adds a second style tag that causes a html warning/error.

  Imo a suggested fix would be to use the dom parser to only insert style tags within user profile hyperlinks that are void of style tags to begin with.

ie.
file: Subs-SimpleColorizer.php

possibly replace your ob_colorizer function with the following:

function ob_colorizer($buffer)
{
global $context, $scripturl, $sourcedir, $modSettings;

if (isset($_REQUEST['xml']))
return $buffer;

$regex = array(
'~href="' . preg_quote($scripturl) . '\?action=profile;u=(\d+)"~',
'~(href="' . preg_quote($scripturl) . '\?action=profile\;u={$user_id}"[^>]*)~'
);

$user_ids = preg_match_all($regex[0], $buffer, $matches) ? array_unique($matches[1]) : array();

if (empty($user_ids))
return $buffer;

if (($user_colors = sc_loadColors($user_ids)) !== false)
{
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTML($buffer);
libxml_use_internal_errors(false);
$xp = new DOMXpath($dom);

foreach ($user_colors as $user_id => $user_color)
{
foreach ($xp->query('//a[@style]') as $item)
{
if (strpos($item->getAttribute("href"), $scripturl . '?action=profile;u='.$user_id) !== false && strpos($item->getAttribute("style"), 'color') === false)
$buffer = preg_replace(str_replace('{$user_id}', $user_id, $regex[1]), '$1 style="color: ' . $user_color . ';"', $buffer);
}

}
}

return $buffer;
}
   

  One could refine the dom query a little better to only gather the hyperlink href matching the user id whilst in the loop but I think my example shows the general idea.

My SMF Mods & Plug-Ins

WebDev

SMF support staff should be shaping a positive community experience & not provoking an argument or emotional reaction.

FireDitto

I wonder if anyone would be able to help me? I've installed this mod - 'Group color to CSS Class - but I don't know how to make it work nicely with this mod, which I love dearly xD

They seem to use different classes in the coding; eg, 'user_color' and the Group CSS uses 'online_color' - how can I make them view the same? Is it possible?

Thank you!
Second Pass Weyr<br />An AU Pernse RPG<br /><br />SMF 2.0.6 with SP 2.3.5

All Colours Sam

Well, essentially, you only need the css stuff from the "group color to class" mod, all the other template edits are pretty much redundant since simpleColorizer will take care of it.

So, first thing you need is to uninstall that css mod and just leave the code in index.css file then open Subs-SimpleColorizer.php and find:

         $buffer = preg_replace(str_replace('{$user_id}', $user_id, $regex[1]), '$1 style="color: ' . $user_color . ';"', $buffer);


and replace with:

$buffer = preg_replace(str_replace('{$user_id}', $user_id, $regex[1]), '$1 class="group-member' . (empty($user_color) ? '' : ' group-' . $user_color) . '"', $buffer);


This is totally untested so do a back up first.


Theres also one bug on this mod, the regex also caches the canonical link tag in the profile page, haven't had the time to make a proper fix for it.
Oh, wouldn't it be great if I *was* crazy? ...then the world would be okay
Suki

FireDitto

Worked  beautifully!

Only thing it isn't changing is the Group Legend in the index, and it doesn't colour the membergroups in the Admin page where you add/edit them.

Thank you!
Second Pass Weyr<br />An AU Pernse RPG<br /><br />SMF 2.0.6 with SP 2.3.5

FireDitto

Ahh, came across another thing that isn't colouring any more.

I use the [user] BBC Tag. It used to colour the links the same colour as their group through the SimpleColorizer; it no longer is. Would you happen to know where I'd need to edit to make that work again?

Thank you so much!
Second Pass Weyr<br />An AU Pernse RPG<br /><br />SMF 2.0.6 with SP 2.3.5

All Colours Sam

In Subs.php find


array(
'tag' => 'user',
'type' => 'unparsed_content',
'content' => '<a href="' . $scripturl . '?action=profile;user=$1" class="bbc_link">$1</a>',
'validate' => create_function('&$tag, &$data, $disabled', '$data = strtr($data, array(\'<br />\' => \'\'));'),
),
array(
'tag' => 'user',
'type' => 'unparsed_equals',
'before' => '<a href="' . $scripturl . '?action=profile;user=$1" class="bbc_link">',
'after' => '</a>',
'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
'disabled_after' => ' ($1)',
),
array(
'tag' => 'id',
'type' => 'unparsed_content',
'content' => '<a href="' . $scripturl . '?action=profile;u=$1" class="bbc_link">$1</a>',
'validate' => create_function('&$tag, &$data, $disabled', '$data = strtr($data, array(\'<br />\' => \'\'));'),
),
array(
'tag' => 'id',
'type' => 'unparsed_equals',
'before' => '<a href="' . $scripturl . '?action=profile;u=$1" class="bbc_link">',
'after' => '</a>',
'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
'disabled_after' => ' ($1)',


and on each content key you will see theres an class="bbc"  just remove that part, simplecolizer should be able to pick the link.


As for the other parts where the mod no longer works, just manually apply the group class mod to those specific parts. basically you just add the class group-member followed by the group Id:

class="group-member'. $some_var_wth the group_id .'"

Or follow the parser for that mod and only apply the changes to those specific parts.
Oh, wouldn't it be great if I *was* crazy? ...then the world would be okay
Suki

FireDitto

Worked beautifully; thank you for all your help, I really appreciate it!
Second Pass Weyr<br />An AU Pernse RPG<br /><br />SMF 2.0.6 with SP 2.3.5

Dave J


Quote from: maxtor on November 12, 2011, 04:18:22 PM
i get this error:

Apply Filter: Only show the error messages of this URL
http://....../forum/index.php?action=admin;area=forumfirewall
Apply Filter: Only show the errors with the same message
2: preg_match_all() [<a href='function.preg-match-all'>function.preg-match-all</a>]: Unknown modifier 'c'
Apply Filter: Only show the errors from this file
File: /home/......./public_html/forum/Sources/Subs-SimpleColorizer.php
Line: 18

I'm getting the same error except my unknown modifier is 'g'. Did anyone find out what is causing his?

Dave J

Quote from: -Underdog- on April 18, 2013, 12:03:13 AM
grafitus,

  I'm not positive if you are still supporting/updating this mod but I was debugging someone's forum today and noticed an issue. Where a user link already has style attributes, this mod adds a second style tag that causes a html warning/error.

  Imo a suggested fix would be to use the dom parser to only insert style tags within user profile hyperlinks that are void of style tags to begin with.

ie.
file: Subs-SimpleColorizer.php

possibly replace your ob_colorizer function with the following:

function ob_colorizer($buffer)
{
global $context, $scripturl, $sourcedir, $modSettings;

if (isset($_REQUEST['xml']))
return $buffer;

$regex = array(
'~href="' . preg_quote($scripturl) . '\?action=profile;u=(\d+)"~',
'~(href="' . preg_quote($scripturl) . '\?action=profile\;u={$user_id}"[^>]*)~'
);

$user_ids = preg_match_all($regex[0], $buffer, $matches) ? array_unique($matches[1]) : array();

if (empty($user_ids))
return $buffer;

if (($user_colors = sc_loadColors($user_ids)) !== false)
{
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTML($buffer);
libxml_use_internal_errors(false);
$xp = new DOMXpath($dom);

foreach ($user_colors as $user_id => $user_color)
{
foreach ($xp->query('//a[@style]') as $item)
{
if (strpos($item->getAttribute("href"), $scripturl . '?action=profile;u='.$user_id) !== false && strpos($item->getAttribute("style"), 'color') === false)
$buffer = preg_replace(str_replace('{$user_id}', $user_id, $regex[1]), '$1 style="color: ' . $user_color . ';"', $buffer);
}

}
}

return $buffer;
}
   

  One could refine the dom query a little better to only gather the hyperlink href matching the user id whilst in the loop but I think my example shows the general idea.

I tried this fix and the colour stopped showing altogether. Would it need to be changed proir to install or, as I did, just replace the code in the php file.

Quote from: davejo on October 23, 2013, 04:45:09 PM

Quote from: maxtor on November 12, 2011, 04:18:22 PM
i get this error:

Apply Filter: Only show the error messages of this URL
http://....../forum/index.php?action=admin;area=forumfirewall
Apply Filter: Only show the errors with the same message
2: preg_match_all() [<a href='function.preg-match-all'>function.preg-match-all</a>]: Unknown modifier 'c'
Apply Filter: Only show the errors from this file
File: /home/......./public_html/forum/Sources/Subs-SimpleColorizer.php
Line: 18

I'm getting the same error except my unknown modifier is 'g'. Did anyone find out what is causing his?

Can anyone help with this error please?  My php version is 5.2.17

PokémonS

I tried -Underdog-'s code, but like Davejo said that the the color stopped showing altogether.
Someone can help me to remove the duplicate style?
きみと手をつなごう つらいときはもっと
ゼロからはじめよう ほら ほら 手をつなごう
みんな手をつなごう つらいときはもっと
力を合わせよう ほら ほら 手をつなごう

PokémonS

#77
Ah, I finally find my own solution for my previous post.

If you're using SimpleColorizer forever, just delete member color code from Subs-MembersOnline.php and Display.php.

SimplePortal has ability to disable member color, but it doesn't affect for Shoutbox.
So, If you're using it, delete member color code from Subs-Portal.php and Portal.js.

And finally, I valid my W3C.
きみと手をつなごう つらいときはもっと
ゼロからはじめよう ほら ほら 手をつなごう
みんな手をつなごう つらいときはもっと
力を合わせよう ほら ほら 手をつなごう

Michael Pfaff

Amazing mod! Thank you.

One question:

Is there any way to tweak this slightly so that on posts the color changes the color of the membergroup title and not the username? I love that it changes the color of the username everywhere else, but on posts it's clashing with my theme.

Arantor

Pretty much impossible because this looks for a *link* to the profile, the member group name is not a link.
Holder of controversial views, all of which my own.


Advertisement: