News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Use [color] Tags in [code] Mod

Started by winrules, October 24, 2006, 04:58:21 PM

Previous topic - Next topic

winrules

Link to Mod
Rate this Mod

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.


winrules
SMF Developer
               
My Mods
Please do not PM me for support.


nitins60

Can you make a mod such that, certain groups can only use color codes n topic titles?

winrules

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.


winrules
SMF Developer
               
My Mods
Please do not PM me for support.


wibo

Quote from: winrules on October 24, 2006, 04:58:21 PM
Link to Mod
Rate this Mod

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?)

Rasyr

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?


winrules

Could I have a link to your site and a test account?


winrules
SMF Developer
               
My Mods
Please do not PM me for support.


Rasyr


winrules

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?


winrules
SMF Developer
               
My Mods
Please do not PM me for support.


Mark Thomas

Great mod! Really makes it easy to describe certain things in code.

thanks

Kays

#9
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. :)

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

FragaCampos

Thanks, very useful mod and working on 1.1.9 8)

Rohan_

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 ?
Proud To Be An Indian

Arantor

As I advised you in your other post, not without rewriting the mod from scratch.
Holder of controversial views, all of which my own.


Kays

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].

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Arantor

*nods* I was actually going to suggest that after I mentioned it elsewhere though I forgot about posting, thanks :)
Holder of controversial views, all of which my own.


Rohan_

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
Proud To Be An Indian

Kays

Since you have the mod installed, look in Sources/Subs.php for // Explode the data on each end tag in two places.

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Arantor

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.
Holder of controversial views, all of which my own.


Rohan_

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 ??
Proud To Be An Indian

Arantor

Holder of controversial views, all of which my own.


Advertisement: