Advertisement:

Author Topic: Change username link colors  (Read 37048 times)

Offline roach6390

  • Newbie
  • *
  • Posts: 7
Change username link colors
« on: August 24, 2006, 07:04:17 PM »
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
« Last Edit: February 22, 2008, 10:56:41 AM by IchBin™ »

Offline junglecat

  • Full Member
  • ***
  • Posts: 439
  • Gender: Female
  • Geek Wannabe
Re: Change username link colors
« Reply #1 on: November 25, 2006, 01:44:54 PM »
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 
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~

Offline MinasC

  • Full Member
  • ***
  • Posts: 423
  • Gender: Male
    • The Copycat
Re: Change username link colors
« Reply #2 on: March 07, 2007, 07:03:48 AM »
yeah , where ?

Offline codenaught

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 14,653
  • Gender: Male
  • Formerly Known As akabugeyes
Re: Change username link colors
« Reply #3 on: June 30, 2007, 10:51:15 PM »
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

Offline MinasC

  • Full Member
  • ***
  • Posts: 423
  • Gender: Male
    • The Copycat
Re: Change username link colors
« Reply #4 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 .

Offline MinasC

  • Full Member
  • ***
  • Posts: 423
  • Gender: Male
    • The Copycat
Re: Change username link colors
« Reply #5 on: December 01, 2007, 06:44:15 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 ?

Offline IchBin™

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 11,115
  • Gender: Male
  • I don't speak German.
    • IchBin.us
Re: Change username link colors
« Reply #6 on: December 15, 2007, 12:11:50 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?
Brad "IchBin™" Grow        TinyPortal        Themes
Coding Guidelines       

Offline MinasC

  • Full Member
  • ***
  • Posts: 423
  • Gender: Male
    • The Copycat
Re: Change username link colors
« Reply #7 on: December 16, 2007, 03:27:26 AM »
yes but didn't change anything ...

Offline Sarge

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 6,209
  • Gender: Male
    • Zëri YT!
Re: Change username link colors
« Reply #8 on: December 23, 2007, 02:55:29 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

Offline MinasC

  • Full Member
  • ***
  • Posts: 423
  • Gender: Male
    • The Copycat
Re: Change username link colors
« Reply #9 on: December 23, 2007, 03:44:29 AM »
i am using the default theme , and yes i tried it .

Offline Oldiesmann

  • Developer
  • SMF Super Hero
  • *
  • Posts: 24,814
  • Gender: Male
  • Ask me about the function DB :)
    • oldiesmann on Facebook
    • Oldiesmann on GitHub
    • http://www.linkedin.com/in/michaeleshom on LinkedIn
    • @oldiesmann on Twitter
    • Archie Comics Fan Forum
Re: Change username link colors
« Reply #10 on: January 19, 2008, 09:20:52 PM »
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
Webmaster / SMF Lead Developer
oldiesmann@simplemachines.org

Offline MinasC

  • Full Member
  • ***
  • Posts: 423
  • Gender: Male
    • The Copycat
Re: Change username link colors
« Reply #11 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 !

Offline H

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 21,660
  • Gender: Male
Re: Change username link colors
« Reply #12 on: February 02, 2008, 05:51:42 PM »
Oldiesmann / MinasC, any update on this? :)
-H
Former Support Team Lead
                              I recommend:
Namecheap (domains)
Fastmail (e-mail)
Linode (VPS)
                             

Offline MinasC

  • Full Member
  • ***
  • Posts: 423
  • Gender: Male
    • The Copycat
Re: Change username link colors
« Reply #13 on: February 10, 2008, 06:08:26 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 !

Offline Rumbaar

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 15,805
  • Gender: Male
  • Inherent Omniscience
    • Rumbaar.net
Re: Change username link colors
« Reply #14 on: February 17, 2008, 05:22:54 AM »
This mods might offer additional/alternate options:
ColorizePost
"An important reward for a job well done is a personal sense of worthwhile achievement."

[ Themes ]

Offline MinasC

  • Full Member
  • ***
  • Posts: 423
  • Gender: Male
    • The Copycat
Re: Change username link colors
« Reply #15 on: February 20, 2008, 01:54:19 AM »
actually it does !

Offline Rumbaar

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 15,805
  • Gender: Male
  • Inherent Omniscience
    • Rumbaar.net
Re: Change username link colors
« Reply #16 on: February 20, 2008, 04:15:54 PM »
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 ]

Offline MinasC

  • Full Member
  • ***
  • Posts: 423
  • Gender: Male
    • The Copycat
Re: Change username link colors
« Reply #17 on: February 22, 2008, 04:54:30 AM »
i suppose it gave me some similar solution , so , yes , please consider this matter solved !
thnx !

Offline eliteghost

  • Semi-Newbie
  • *
  • Posts: 40
  • Gender: Male
    • Elite's Training
Re: Change username link colors
« Reply #18 on: August 31, 2008, 12:37:28 PM »
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?

Offline Rumbaar

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 15,805
  • Gender: Male
  • Inherent Omniscience
    • Rumbaar.net
Re: Change username link colors
« Reply #19 on: August 31, 2008, 06:05:51 PM »
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 ]