Simple Machines Community Forum

Customizing SMF => Modifications and Packages => Topic started by: winrules on October 24, 2006, 04:58:21 PM

Title: Use [color] Tags in [code] Mod
Post by: winrules on October 24, 2006, 04:58:21 PM
Link to Mod (http://mods.simplemachines.org/index.php?mod=510)
Rate this Mod (http://mods.simplemachines.org/index.php?action=review;sa=add;mod=510)

This mod will allow the use of [color] tags within [code] tags. It can be usefull when pointing out a specific change you made to some code.
Title: Re: Use [color] Tags in [code] Mod
Post by: nitins60 on October 25, 2006, 01:15:14 PM
Can you make a mod such that, certain groups can only use color codes n topic titles?
Title: Re: Use [color] Tags in [code] Mod
Post by: winrules on October 25, 2006, 03:53:28 PM
Quote from: nitins60 on October 25, 2006, 01:15:14 PM
Can you make a mod such that, certain groups can only use color codes n topic titles?
That is a completly different mod. And PMing me and posting about it twice isn't going to help you get it made.
Title: Re: Use [color] Tags in [code] Mod
Post by: wibo on October 27, 2006, 02:56:24 AM
Quote from: winrules on October 24, 2006, 04:58:21 PM
Link to Mod (http://mods.simplemachines.org/index.php?mod=510)
Rate this Mod (http://mods.simplemachines.org/index.php?action=review;sa=add;mod=510)

This mod will allow the use of [color] tags within [code] tags. It can be usefull when pointing out a specific change you made to some code.

I don't understand what this mod does?
If I change html code in an .php file am I enable to see what I've changed?
Where do I have to add the [color] tags? (around the changes?)
Title: Re: Use [color] Tags in [code] Mod
Post by: Rasyr on November 11, 2006, 10:11:51 AM
I am running 1.1 RC3, and I just installed this Mod. Unfortunately, it doesn't seem to be working properly.

If I try the following:

This is a test of [color=maroon]Color [/color]within Code


I end up with


[/color]within Code


The Mod said that it installed properly, and gave me no errors. Any idea what may be causing this?

Title: Re: Use [color] Tags in [code] Mod
Post by: winrules on November 11, 2006, 11:05:47 AM
Could I have a link to your site and a test account?
Title: Re: Use [color] Tags in [code] Mod
Post by: Rasyr on November 11, 2006, 01:34:12 PM

My site is found at http://www.ironcrown.com/ICEforums

Username: test
Password: testtest

Title: Re: Use [color] Tags in [code] Mod
Post by: winrules on November 11, 2006, 05:19:31 PM
Quote from: Rasyr on November 11, 2006, 01:34:12 PM

My site is found at http://www.ironcrown.com/ICEforums

Username: test
Password: testtest


Strange. Could you send my your Subs.php?
Title: Re: Use [color] Tags in [code] Mod
Post by: Mark Thomas on January 03, 2007, 02:35:26 PM
Great mod! Really makes it easy to describe certain things in code.

thanks
Title: Re: Use [color] Tags in [code] Mod
Post by: Kays on February 18, 2007, 07:14:57 PM
Nice mod. :)

Quote from: Rasyr on November 11, 2006, 10:11:51 AM
I am running 1.1 RC3, and I just installed this Mod. Unfortunately, it doesn't seem to be working properly.

If I try the following:

This is a test of [color=maroon]Color [/color]within Code


I end up with


[/color]within Code


The Mod said that it installed properly, and gave me no errors. Any idea what may be causing this?

I had the same problem (SMF1.1.2) but finally fixed it by making the following change. It looks like $count isn't incrementing as it should which is what caused the problem.

In Sources/Subs.php

Code (find) Select

foreach ($color_parts as $id => $part)
{
// If it\'s not the last one, try to parse the tag and add it on to the data.
if ($id != $last)
{
$data .= preg_replace(\'~\[color=(#[\da-fA-F]{3}|#[\da-fA-F]{6}|[A-Za-z]{1,12})\]~i\', \'<span style="color: $1;">\', $part, 1, $count);


Code (replace with) Select

$count = 0;
foreach ($color_parts as $id => $part)
{
$count++;
// If it\'s not the last one, try to parse the tag and add it on to the data.
if ($id != $last)
{
$data .= preg_replace(\'~\[color=(#[\da-fA-F]{3}|#[\da-fA-F]{6}|[A-Za-z]{1,12})\]~i\', \'<span style="color: $1;">\', $part);


But the above did not work when I used code=. Where the mod is written in the second time I discovered that $data needs to be changed to $data[0] as well.

Code (find) Select

// Mini-parser to parse just [color] tags.
if (!isset($disabled[\'color\']))
{
// Explode the data on each end tag.
$color_parts = explode(\'[/color]\', $data);

$last = count($color_parts) - 1;
$data = \'\';

foreach ($color_parts as $id => $part)
{
// If it\'s not the last one, try to parse the tag and add it on to the data.
if ($id != $last)
{
$data .= preg_replace(\'~\[color=(#[\da-fA-F]{3}|#[\da-fA-F]{6}|[A-Za-z]{1,12})\]~i\', \'<span style="color: $1;">\', $part, 1, $count);

// If we parsed the start tag we should also parse the end tag.
if ($count)
$data .= \'</span>\';
else
$data .= \'[/color]\';
}
// Else just add on the data.
else
$data .= $part;
}
}

// Older browsers are annoying, aren\'t they?


Code (replace with) Select

// Mini-parser to parse just [color] tags.
if (!isset($disabled[\'color\']))
{
// Explode the data on each end tag.
$color_parts = explode(\'[/color]\', $data[0]);

$last = count($color_parts) - 1;
$data[0] = \'\';

$count = 0;
foreach ($color_parts as $id => $part)
{
$count++;
// If it\'s not the last one, try to parse the tag and add it on to the data.
if ($id != $last)
{
$data[0] .= preg_replace(\'~\[color=(#[\da-fA-F]{3}|#[\da-fA-F]{6}|[A-Za-z]{1,12})\]~i\', \'<span style="color: $1;">\', $part);

// If we parsed the start tag we should also parse the end tag.
if ($count)
$data[0] .= \'</span>\';
else
$data[0] .= \'[/color]\';
}
// Else just add on the data.
else
$data[0] .= $part;
}
}

// Older browsers are annoying, aren\'t they?


Hope this helps. :)
Title: Re: Use [color] Tags in [code] Mod
Post by: FragaCampos on June 24, 2009, 10:06:00 AM
Thanks, very useful mod and working on 1.1.9 8)
Title: Re: Use [color] Tags in [code] Mod
Post by: Rohan_ on August 29, 2009, 02:54:08 PM
hi .. i am using this mod and its working good .. but its not work if we use color tags in capital e.g COLOR

how can i make this work ?
Title: Re: Use [color] Tags in [code] Mod
Post by: Arantor on August 29, 2009, 03:31:33 PM
As I advised you in your other post, not without rewriting the mod from scratch.
Title: Re: Use [color] Tags in [code] Mod
Post by: Kays on August 30, 2009, 11:49:25 AM
Quote from: Rohan_ on August 29, 2009, 02:54:08 PM
hi .. i am using this mod and its working good .. but its not work if we use color tags in capital e.g COLOR

how can i make this work ?

Hi, it's been a while since i've looked at this but here's something to try.

Above // Explode the data on each end tag.

Add:


str_replace(array('[COLOR', 'COLOR]'), array('[color', 'color]'), $data);


If you're using the corrections I posted, for the second instance of the code array use $data[0].
Title: Re: Use [color] Tags in [code] Mod
Post by: Arantor on August 30, 2009, 11:55:40 AM
*nods* I was actually going to suggest that after I mentioned it elsewhere though I forgot about posting, thanks :)
Title: Re: Use [color] Tags in [code] Mod
Post by: Rohan_ on August 30, 2009, 01:38:28 PM
Quote from: Kays on August 30, 2009, 11:49:25 AM
Quote from: Rohan_ on August 29, 2009, 02:54:08 PM
hi .. i am using this mod and its working good .. but its not work if we use color tags in capital e.g COLOR

how can i make this work ?


Hi, it's been a while since i've looked at this but here's something to try.

Above // Explode the data on each end tag.

Add:


str_replace(array('[COLOR', 'COLOR]'), array('[color', 'color]'), $data);


If you're using the corrections I posted, for the second instance of the code array use $data[0].

please tell me exactly that where i need to add this
Title: Re: Use [color] Tags in [code] Mod
Post by: Kays on August 30, 2009, 01:51:54 PM
Since you have the mod installed, look in Sources/Subs.php for // Explode the data on each end tag in two places.
Title: Re: Use [color] Tags in [code] Mod
Post by: Arantor on August 30, 2009, 01:56:38 PM
Then add:
$data = str_replace(array('[COLOR', 'COLOR]'), array('[color', 'color]'), $data);

and

$data = str_replace(array('[COLOR', 'COLOR]'), array('[color', 'color]'), $data[0]);

Careful to ensure you add them the right way around.
Title: Re: Use [color] Tags in [code] Mod
Post by: Rohan_ on August 30, 2009, 02:00:46 PM
where i need to add this ? do u mean

// Explode the data on each end tag.
                     $data = str_replace(array('[COLOR', 'COLOR]'), array('[color', 'color]'), $data);
$color_parts = explode(\'[/color]\', $data);

This ??
Title: Re: Use [color] Tags in [code] Mod
Post by: Arantor on August 30, 2009, 02:05:50 PM
Yes.
Title: Re: Use [color] Tags in [code] Mod
Post by: Rohan_ on August 30, 2009, 02:06:28 PM
Parse error: syntax error, unexpected '[' in /home/vhosts/www.site.com/Sources/Subs.php on line 1154
Title: Re: Use [color] Tags in [code] Mod
Post by: Rohan_ on August 31, 2009, 03:24:05 AM
what happened ??? no reply ?
Title: Re: Use [color] Tags in [code] Mod
Post by: Kays on August 31, 2009, 04:30:02 AM
Sorry, I forgot that single quotes need to be escaped. Try this instead



str_replace(array(\'[COLOR\', \'COLOR]\'), array(\'[color\',\ 'color]\'), $data);
Title: Re: Use [color] Tags in [code] Mod
Post by: Rohan_ on August 31, 2009, 04:45:23 AM
cant you tell the exact code what i need to replace with in a easy way ?? you saying to write direct str_replace and arantor saying $data = srt_replace ..
but none of them working .. where i need to add the code tell me exactly and now you are giving just 1 code what i need to add in second ?anyways this one also not works
Title: Re: Use [color] Tags in [code] Mod
Post by: Kays on August 31, 2009, 05:05:42 AM
Arantor 's correct, it should be:



$data = str_replace(array(\'[COLOR\', \'COLOR]\'), array(\'[color\',\ 'color]\'), $data);


and



$data[0] = str_replace(array(\'[COLOR\', \'COLOR]\'), array(\'[color\',\ 'color]\'), $data[0]);


Sorry, I don't know how I missed that.
Title: Re: Use [color] Tags in [code] Mod
Post by: Arantor on August 31, 2009, 05:06:43 AM
And I don't know how I missed the fact it should have been escaped!
Title: Re: Use [color] Tags in [code] Mod
Post by: Rohan_ on August 31, 2009, 05:15:27 AM
Quote from: Arantor on August 31, 2009, 05:06:43 AM
And I don't know how I missed the fact it should have been escaped!

it happens Bro :) let me try it
Title: Re: Use [color] Tags in [code] Mod
Post by: Rohan_ on August 31, 2009, 06:05:14 AM
ok now i added the code . and it looks now like this
// Explode the data on each end tag.
                                          $data = str_replace(array(\'[COLOR\', \'COLOR]\'), array(\'[color\',\ 'color]\'), $data);
$color_parts = explode(\'[/color]\', $data);


and
// Explode the data on each end tag.
                                          $data[0] = str_replace(array(\'[COLOR\', \'COLOR]\'), array(\'[color\',\ 'color]\'), $data[0]);
$color_parts = explode(\'[/color]\', $data);


after uploading i got this
Parse error: syntax error, unexpected T_STRING in /home/vhosts/www.site.com/Sources/Subs.php on line 1156
Title: Re: Use [color] Tags in [code] Mod
Post by: Kays on August 31, 2009, 06:13:26 AM
Comment it out or remove it for now and attach Subs.php to a post.
Title: Re: Use [color] Tags in [code] Mod
Post by: Rohan_ on August 31, 2009, 06:37:47 AM
here is my unedited subs.php

Title: Re: Use [color] Tags in [code] Mod
Post by: Kays on August 31, 2009, 07:41:25 AM
Try this. I've also added the corrections for code=xx

Do make a backup of your Subs.php before overwriting it. The code does work on my install, but I couldn't get your Subs.php to load on my install. Possibly a mod conflict.
Title: Re: Use [color] Tags in [code] Mod
Post by: Rohan_ on August 31, 2009, 07:55:54 AM
THANKS A LOT . it worked . i was adding the code after    // Explode the data on each end tag.

i also confirmed it before doing it .. but the problem was that i needed to add the code before // Explode the data on each end tag.

Title: Re: Use [color] Tags in [code] Mod
Post by: devoetbalkantine on February 17, 2011, 12:07:07 PM
I've installed this and it is working even on 2.0 RC3 and 2.0 RC5 so no problems there. I have a small request... Is it possible to also do this for and tags?

My members are asking for it now that I enabled the color option haha
Title: Re: Use [color] Tags in [code] Mod
Post by: Arantor on February 17, 2011, 12:13:59 PM
And what tags? If you mean the html tag, it's admin only for a very, very good reason.

Seriously, though, what is it with people abusing the code tag? It's for posting computer code, rarely needs colour formatting for that. If you need colour formatting, use something like tt which supports colours inside it naturally.
Title: Re: Use [color] Tags in [code] Mod
Post by: devoetbalkantine on February 21, 2011, 08:24:52 AM
I know. I am not a big fan of it either, just wanted to know if it was possible for the people who ask for it