News:

Wondering if this will always be free?  See why free is better.

Main Menu

Change username link colors

Started by roach6390, August 24, 2006, 07:04:17 PM

Previous topic - Next topic

roach6390

A while ago I found this code to change the color of links on a page. It uses JavaScript.

I'll try to explain better: Each member of your forum can have their personal color. Every time a link is posted with their name, (or how you set the code), the link will be their custom color.

Here is the code, with an example on the bottom:
Quote<script type="text/javascript">
function ColourName(username,colour,method) {
   var iLink = document.getElementsByTagName("a");
      for (a=0; a<iLink.length; a++) {
         switch (method) {
            case "num":
               if (iLink[a].href.match(new RegExp('showuser=' + username,'i'))) {
               iLink[a].style.color = colour;
               }break;
            case "name":
               if (iLink[a].href.match(new RegExp('index.php?')))  {
               if (iLink[a].innerHTML.toString().match(new RegExp(username,'i'))) {
               iLink[a].style.color = colour;
               }break;
                         }
      }
   }
}

ColourName("roach6390","#3399CC","name");
</script>

You can change what is in bold to furthur refine which links are highlighted in the color.

You can either do it by "name" or "num" (number).
If you do it by number, it uses the first bold.
If you do it by name, it uses the 2nd bold.

Here is a PHP script to get your started integrating this into your forum. It will take the submission and edit the file above. Edit the values on the top.
Quote<?

   $USER = $_POST['user'];
   $COLOR = '#'.$_POST['color'];
   $output = 'ColourName("'.$USER.'","'.$COLOR.'","name");';
   $fname = 'unc_change.txt';
   $found = false;
    
     // Read the file and count the lines
     $filetxt = file($fname);               // $filetext = a new array
     $line_count = count($filetxt);         // Line count in $filetext
    
     // Check each line to see if the user's name is in it.
     for ($i = 1; $i <= $line_count; $i += 1) {
       if (substr_count($filetxt[$i],'ColourName("'.$USER) == 1) {
         if ($found == false) {
           $newfile = str_replace($filetxt[$i],$output.'
         ',implode('',$filetxt));
           $found = true;
         }
       }
     }
    
     // The user's name is NOT in any of the files, so add a new one, and a blank "buffer" zone.
     if ($found == false) {
       $filetxt[($line_count-2)] = $output.'
      

';
     } 
    
   
   // Write the new file
   if ($newfile == '') {
     $newfile = implode('',$filetxt);
   }
   $handle = fopen($fname,"w");
   fwrite($handle,$newfile);
   fclose($handle);
   
?>
Settings changed!<BR>
Your color is now: <? echo $COLOR ?><BR>
Preview: <FONT COLOR="<? echo $COLOR ?>"><? echo $USER ?>

Any bugs, please tell me!

Please move to Tips and Tricks!

Enjoy,
roach

junglecat

I would like to do this, but where do I put the php script that writes the code and the first file?

I guess I need idiot instructions. :-[
PM me for affordable hosting. I will install your SMF forum with your choice of a theme for FREE.
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
Join us at Christian Discussions 
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~

MinasC


codenaught

junglecat, MinasC, do either of you still need help with this? First place you should probably try is somewhere between the <head> </head> tags in Themes/<theme_name>/index.template.php.
Dev Consultant
Former SMF Doc Coordinator

MinasC

you mean i should put both the script and the phpcode anywhere in the head section of the index.template.php ?

thnx a lot .

MinasC

Quote from: MinasC on July 01, 2007, 04:18:13 AM
you mean i should put both the script and the phpcode anywhere in the head section of the index.template.php ?

thnx a lot .

well ?

IchBin™

Quote from: MinasC on December 01, 2007, 06:44:15 AM
Quote from: MinasC on July 01, 2007, 04:18:13 AM
you mean i should put both the script and the phpcode anywhere in the head section of the index.template.php ?

thnx a lot .

well ?
That is what he said. Did you try it?
IchBin™        TinyPortal

MinasC

yes but didn't change anything ...

Sarge

Quote from: MinasC on December 16, 2007, 03:27:26 AM
yes but didn't change anything ...

If you use a custom theme in your forum, you need to make the change there.

Have you tried akabugeyes' suggestion and placed the code in index.template.php of the theme you're using?

    Please do not PM me with support requests unless I invite you to.

http://www.zeriyt.com/   ~   http://www.galeriashqiptare.net/


Quote
<H> I had zero posts when I started posting

MinasC

i am using the default theme , and yes i tried it .

Oldiesmann

The javascript won't work at all because it's looking for things in the url that SMF doesn't use. I'm not sure what the php script is supposed to do. The best way to do this is to add a custom profile field to handle the color, then modify the link that's generated in the loadusercontext function in Load.php to change the link color if a color is set. Unfortunately I can't post examples right now because I'm on my cell phone, but that should get you started.
Michael Eshom
Christian Metal Fans

MinasC

i'd be a liar if i say that i can do any of that by myself ! so i guess i'll have to wait till you get to a pc !  :P

thnx a lot !

H

Oldiesmann / MinasC, any update on this? :)
-H
Former Support Team Lead
                              I recommend:
Namecheap (domains)
Fastmail (e-mail)
Linode (VPS)
                             

MinasC

Quote from: MinasC on January 22, 2008, 02:38:11 PM
i'd be a liar if i say that i can do any of that by myself ! so i guess i'll have to wait till you get to a pc !  :P

thnx a lot !

still waiting myself !

Rumbaar

This mods might offer additional/alternate options:
ColorizePost
"An important reward for a job well done is a personal sense of worthwhile achievement."

[ Themes ]

MinasC


Rumbaar

So what the mod a solution to your current issue?
"An important reward for a job well done is a personal sense of worthwhile achievement."

[ Themes ]

MinasC

i suppose it gave me some similar solution , so , yes , please consider this matter solved !
thnx !

eliteghost

Does this old thing still work? ive been looking for this, now that ive found it i  cant get it to work,  maybe i need better dummy instructions..

After all this argument up top here about where to put it, you would think they could just specify.
I pasted it all into my index.template.php after <head> and it wouldnt load my page, gave me a parse error.

now, i know with coding my own page that it should go in the <head> of the page. of index template.   I would place it somwhere in the profile.php  so that in the users profile they can change thier color and appearance on the entire forum.

Anyone have this working?  Help me out?

Rumbaar

I would recommend the "Member Color Link" mod, it will change the color of each persons link based on membergroup in many places.
"An important reward for a job well done is a personal sense of worthwhile achievement."

[ Themes ]

Advertisement: