Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Thema gestartet von: roach6390 in August 24, 2006, 07:04:17 NACHMITTAGS

Titel: Change username link colors
Beitrag von: roach6390 in August 24, 2006, 07:04:17 NACHMITTAGS
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:
Zitat<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.
Zitat<?

   $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
Titel: Re: Change username link colors
Beitrag von: junglecat in November 25, 2006, 01:44:54 NACHMITTAGS
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. :-[
Titel: Re: Change username link colors
Beitrag von: MinasC in März 07, 2007, 07:03:48 VORMITTAG
yeah , where ?
Titel: Re: Change username link colors
Beitrag von: codenaught in Juni 30, 2007, 10:51:15 NACHMITTAGS
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.
Titel: Re: Change username link colors
Beitrag von: MinasC in Juli 01, 2007, 04:18:13 VORMITTAG
you mean i should put both the script and the phpcode anywhere in the head section of the index.template.php ?

thnx a lot .
Titel: Re: Change username link colors
Beitrag von: MinasC in Dezember 01, 2007, 06:44:15 VORMITTAG
Zitat von: MinasC in Juli 01, 2007, 04:18:13 VORMITTAG
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 ?
Titel: Re: Change username link colors
Beitrag von: IchBin™ in Dezember 15, 2007, 12:11:50 VORMITTAG
Zitat von: MinasC in Dezember 01, 2007, 06:44:15 VORMITTAG
Zitat von: MinasC in Juli 01, 2007, 04:18:13 VORMITTAG
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?
Titel: Re: Change username link colors
Beitrag von: MinasC in Dezember 16, 2007, 03:27:26 VORMITTAG
yes but didn't change anything ...
Titel: Re: Change username link colors
Beitrag von: Sarge in Dezember 23, 2007, 02:55:29 VORMITTAG
Zitat von: MinasC in Dezember 16, 2007, 03:27:26 VORMITTAG
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?
Titel: Re: Change username link colors
Beitrag von: MinasC in Dezember 23, 2007, 03:44:29 VORMITTAG
i am using the default theme , and yes i tried it .
Titel: Re: Change username link colors
Beitrag von: Oldiesmann in Januar 19, 2008, 09:20:52 NACHMITTAGS
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.
Titel: Re: Change username link colors
Beitrag von: MinasC in Januar 22, 2008, 02:38:11 NACHMITTAGS
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 !
Titel: Re: Change username link colors
Beitrag von: H in Februar 02, 2008, 05:51:42 NACHMITTAGS
Oldiesmann / MinasC, any update on this? :)
Titel: Re: Change username link colors
Beitrag von: MinasC in Februar 10, 2008, 06:08:26 NACHMITTAGS
Zitat von: MinasC in Januar 22, 2008, 02:38:11 NACHMITTAGS
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 !
Titel: Re: Change username link colors
Beitrag von: Rumbaar in Februar 17, 2008, 05:22:54 VORMITTAG
This mods might offer additional/alternate options:
ColorizePost (http://custom.simplemachines.org/mods/index.php?mod=1061)
Titel: Re: Change username link colors
Beitrag von: MinasC in Februar 20, 2008, 01:54:19 VORMITTAG
actually it does !
Titel: Re: Change username link colors
Beitrag von: Rumbaar in Februar 20, 2008, 04:15:54 NACHMITTAGS
So what the mod a solution to your current issue?
Titel: Re: Change username link colors
Beitrag von: MinasC in Februar 22, 2008, 04:54:30 VORMITTAG
i suppose it gave me some similar solution , so , yes , please consider this matter solved !
thnx !
Titel: Re: Change username link colors
Beitrag von: eliteghost in August 31, 2008, 12:37:28 NACHMITTAGS
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?
Titel: Re: Change username link colors
Beitrag von: Rumbaar in August 31, 2008, 06:05:51 NACHMITTAGS
I would recommend the "Member Color Link" mod, it will change the color of each persons link based on membergroup in many places.
Titel: Re: Change username link colors
Beitrag von: eliteghost in August 31, 2008, 07:18:03 NACHMITTAGS
aww lame, thats not what i wanted lol Dam!

this only colors the members by group, its not user selectable. How can i mod this mod so that users select a color from thier profile, and it applies it thoughout the entire forum?
Titel: Re: Change username link colors
Beitrag von: H in September 01, 2008, 10:16:43 VORMITTAG
Do you know php? If not I suggest you post in Mod Requests (http://www.simplemachines.org/community/index.php?board=79.0).
Titel: Re: Change username link colors
Beitrag von: esttecb in November 16, 2009, 07:17:30 NACHMITTAGS
Ok, this is pretty old... but this topic is a friend of google...
So, here we go...

Open Source/Load.php
find:
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $profile['ID_MEMBER'] . '" title="' . $txt[92] . ' ' . $profile['realName'] . '">' . $profile['realName'] . '</a>',

replace with:
'link' => '<a style="color: ' . $profile['member_group_color'] . ';" href="' . $scripturl . '?action=profile;u=' . $profile['ID_MEMBER'] . '" title="' . $txt[92] . ' ' . $profile['realName'] . '">' . $profile['realName'] . '</a>',


all done. I know it's by member group, but it doesn't need any mod.
Titel: Re: Change username link colors
Beitrag von: Arantor in November 16, 2009, 08:45:30 NACHMITTAGS
That assumes everyone has a member_group_color; Regular Member does not, neither do the post count groups by default.