CZUser-Info Block - Need To Truncate Long Usernames

  Post new topicReply to topicPrintable Version
<< View previous topic View next topic >>
Share: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
#1   CZUser-Info Block - Need To Truncate Long Usernames
mjhufford
CZ Active Member
 Codezwiz Site Donator
mjhufford has been a member for over 19 year's 19 Year Member
usa.gif arkansas.gif
Occupation: IT Industry
Age: 46
Gender: Male
Fav. Sports Team: Da Bears.
Website:
Status: Offline
Joined: Jul 01, 2004
0.04 posts per day
Posts: 288
Points: 15,094
  MSN Messenger 
Hey there,

I need to find a way to truncate long usernames in the CZUser-Info block. I have some users that have LONG names (like 18-20 charachters). Is there a way this can be done...where if it exceeds so many charachters that it truncates it with "..." ?

Thanks,

MJ




_________________
"The pursuit of easy things makes men weak."
-David O. McKay
Back to top Reply with quote
#2   re: CZUser-Info Block - Need To Truncate Long Usernames
mjhufford
CZ Active Member
 Codezwiz Site Donator
mjhufford has been a member for over 19 year's 19 Year Member
usa.gif arkansas.gif
Occupation: IT Industry
Age: 46
Gender: Male
Fav. Sports Team: Da Bears.
Website:
Status: Offline
Joined: Jul 01, 2004
0.04 posts per day
Posts: 288
Points: 15,094
  MSN Messenger 
Alrighty, I found my answer after surfing a bit. I'm not sure how it works, but I know it does. I wanted to share my findings in case anyone else needs this.

I opened the CZUser-Info block file and added this around line 26:

$truncate = 13; // number of chars before truncated.

function trun($s, $l) {
   if (strlen($s) > $l) {
      $return = substr($s,0,$l-3).'...';
   } else { $return = $s; }
   return $return;
}



Then, around what is now line 109, I changed this:

     $uname = $session['uname'];


To this:

     $uname = trun($session['uname'], $truncate);


You can change the $truncate variable to whatever is necessary for you site. Any username longer than 13 characters will be truncated in the block with "...".

Hope you find it useful!



_________________
"The pursuit of easy things makes men weak."
-David O. McKay
Back to top Reply with quote
#3   re: CZUser-Info Block - Need To Truncate Long Usernames
Dauthus
CZ Addict
 Codezwiz Site Donator
Dauthus has been a member for over 20 year's 20 Year Member
usa.gif illinois.gif
Age: 60
Gender: Male
Website:
Status: Offline
Joined: Mar 17, 2004
0.06 posts per day
Posts: 426
Points: 15,917
   
If you don't mind me adding a little bit.... icon_biggrin.gif

With a little more modification you can also change the Latest User and have it truncated too.

---------- FIND ---------

// Info for users who are logged in AND Guests
      $last = new_users();
      $lastuser = last_user();


---------- REPLACE WITH ----------

// Info for users who are logged in AND Guests
      $last = new_users();
      $lastuser1 = last_user();
      $lastuser = trun(last_user(), $truncate);


---------- FIND ----------

$content .= "<a title=\""._CZ_VIEW." $lastuser's "._CZ_VIEWPP."\" href=\"modules.php?name=Your_Account&amp;op=userinfo&amp;username=$lastuser\"><b>$lastuser</b></a><br />\n";


---------- REPLACE WITH ----------

$content .= "<a title=\""._CZ_VIEW." $lastuser1's "._CZ_VIEWPP."\" href=\"modules.php?name=Your_Account&amp;op=userinfo&amp;username=$lastuser1\"><b>$lastuser</b></a><br />\n";


This allows the Latest User to be truncated and the hover window still shows their full name, and allows for the full username to be used for the link to their profile.



_________________
[ Register or login to view links on this board.]
Vivere disce, cogita mori
Back to top Reply with quote
#4   
Telli
Site Admin
Telli has been a member for over 20 year's 20 Year Member
Occupation: Self Employed
Age: 46
Gender: Male
Fav. Sports Team: Detroit Red Wings
Website:
Status: Offline
Joined: May 26, 2003
1.06 posts per day
Posts: 8089
Points: 494,430
   
You could also add a new function into your mainfile.php:


//$val - What your truncating
//$cut_len - How many letters before you truncate it

function cut_word($val, $cut_len) {
    $tot_len = strlen($val);
    $cut_str = substr($val, 0, $cut_len);
    $len = strlen($cut_str);
    for($i=0;$i < $len;$i++) {
    for($i=0;$i < $len;$i++) {
        if(ord($val[$i]) > 127) $hanlen++;
            else $englen++;
        }
    $cut_gap = $hanlen % 2;
        if($cut_gap == 1){
      $hanlen--;
     }
    $length=$hanlen + $englen;

     if($tot_len > $length){
      return substr($val, 0, $length)."...";
     } else {
         return substr($val, 0, $length);
     }
    }
}


Then to use it:


$uname = cut_word($session['uname'], 13);


That way you don't have to add that code to every file if you want to use it more then once in your site.



_________________
The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men. Blessed is he, who in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy my brothers. And you will know my name is the Lord when I lay my vengeance upon thee. Ezekiel 25:17
Back to top Reply with quote
#5   
mjhufford
CZ Active Member
 Codezwiz Site Donator
mjhufford has been a member for over 19 year's 19 Year Member
usa.gif arkansas.gif
Occupation: IT Industry
Age: 46
Gender: Male
Fav. Sports Team: Da Bears.
Website:
Status: Offline
Joined: Jul 01, 2004
0.04 posts per day
Posts: 288
Points: 15,094
  MSN Messenger 
Sweet, thanks guys!




_________________
"The pursuit of easy things makes men weak."
-David O. McKay
Back to top Reply with quote
Display posts from previous:      
Add To: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
<< View previous topic View next topic >>
Post new topicReply to topic

Jump to 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum