Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

abbreviate usernames in discussions overview so they don't exceed 6 characters (e.g. 'Userna...')

fh111fh111 Vanilla Padawan ✭✭
edited December 2011 in Vanilla 2.0 - 2.8

how can i abbreviate usernames in discussions overview so they are not longer than 6 characters (e.g. 'Username' --> 'Userna...')

?

i am in applications/vanilla/views/discussions/helper_funtions.php

i tried to add

$short = substr_replace($Last, '...', 6);

and changed

           echo '<span class="LastCommentBy">'.sprintf(T('Most recent by %1$s'), UserAnchor($Last)).'</span>';

to

           echo '<span class="LastCommentBy">'.sprintf(T('Most recent by %1$s'), UserAnchor($short)).'</span>';

but it's giving me a 'bonk' :(

anyone know how to?
thanks

«1

Answers

  • Options
    sahotataransahotataran Developer, Bay Area - CA ✭✭✭

    UserAnchor takes in FULL USER OBJECT detail rather than just passing the USERNAME.
    for reference you can check the function UserAnchor in /library/core/functions.render.php around line 146.
    since you are passing only username thats y you are getting bonk

    There was an error rendering this rich post.

  • Options
    422422 Developer MVP
    edited December 2011

    Woudnt you use strlen, string trim

    There was an error rendering this rich post.

  • Options
    sahotataransahotataran Developer, Bay Area - CA ✭✭✭
    edited December 2011

    ok heres is the solution:

    Your user is $Last

    do: $Last->Name = substr_replace($Last->Name, '...', 6);

    and then you can use your line:
    echo '< span class="LastCommentBy">'.sprintf(T('Most recent by %1$s'), UserAnchor($short)).'< /span>';

    There was an error rendering this rich post.

  • Options
    sahotataransahotataran Developer, Bay Area - CA ✭✭✭
    edited December 2011

    ok heres is the solution:
    Your user is $Last
    do: $Last->Name = substr_replace($Last->Name, '...', 6);

    and then you can use your line:
    echo '< span class="LastCommentBy">'.sprintf(T('Most recent by %1$s'), UserAnchor($Last)).'< /span>';

    There was an error rendering this rich post.

  • Options
    fh111fh111 Vanilla Padawan ✭✭

    thanks for your suggestions. i quickly tried your code sahotaran but it does not work. what's shown in the end is "..." as username and it links to the profile of "..." instead of the real user (which obviously does not exist) .. a problem i did not think of until now

  • Options
    sahotataransahotataran Developer, Bay Area - CA ✭✭✭

    Did you make sure what is the user you are passing? $Last is ur user variable or some other variable?

    There was an error rendering this rich post.

  • Options
    fh111fh111 Vanilla Padawan ✭✭
    edited December 2011

    $First and $Last are user variables, yes

  • Options
    sahotataransahotataran Developer, Bay Area - CA ✭✭✭

    I had given it a try on my local host and it seemed to work. I will give it a shot again

    There was an error rendering this rich post.

  • Options
    fh111fh111 Vanilla Padawan ✭✭

    sahotataran said:
    ok heres is the solution:
    Your user is $Last
    do: $Last->Name = substr_replace($Last->Name, '...', 6);

    and then you can use your line:
    echo '< span class="LastCommentBy">'.sprintf(T('Most recent by %1$s'), UserAnchor($Last)).'< /span>';

    i gave this another try but i can't get it work. still just showing '...' instead of the abbreviated usernames ..

    any suggestions/ideas on how to get this done?

  • Options
    peregrineperegrine MVP
    edited June 2012

    @fh111 said:

    i am in applications/vanilla/views/discussions/helper_funtions.php >

    this is for last - (do the same thing for first replacing Last with First).

     $short = $Last->Name;
      if (strlen($short) > 6 ) 
                  $short = substr($short,0,6) . '...';
     $newanchor = '<a href="'.htmlspecialchars(Url('/profile/'.($NameUnique ? '' : "$UserID/").rawurlencode($Last->Name))).'"'.$CssClass.'>'.htmlspecialchars($short).'</a>';
    
     echo '<span class="LastCommentBy">'.sprintf(T('Most recent by %1$s'), $newanchor) .'</span>';
    

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options
    peregrineperegrine MVP
    edited June 2012

    left out $Userid - the above will work because it doesn't matter if id is blank but below with userid corrected.

     $UserID = $Last->UserID;
     $short = $Last->Name;
        if (strlen($short) > 6 )
        $short = substr($short,0,6) . '...';
        $newanchor = '<a href="'.htmlspecialchars(Url('/profile/'.$UserID . '/' .rawurlencode($Last->Name))).'"'.$CssClass.'>'.htmlspecialchars($short).'</a>';
        echo '<span class="LastCommentBy">'.sprintf(T('Most recent by %1$s'), $newanchor) .'</span>';
    

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options
    fh111fh111 Vanilla Padawan ✭✭

    @peregrine i wish i could press like 100 more times thanks so much!!!! this is going to make such a big difference for our community, i believe

    big thanks

  • Options
    peregrineperegrine MVP
    edited June 2012

    fh111 said:
    @peregrine i wish i could press like 100 more times thanks so much!!!! this is going to make such a big difference for our community, i believe

    big thanks

    my pleasure.
    I wish you could too(that is press like 100 times)! then I would surpass the supreme leader 422. :).

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options
    fh111fh111 Vanilla Padawan ✭✭

    let me prophecy this - you will for sure soon take over the lead with all the good help and support you give. you deserve it ..

    :D

  • Options
    422422 Developer MVP

    Lol at supreme leader. Clicked like to both of you guys ;)

    There was an error rendering this rich post.

  • Options
    peregrineperegrine MVP
    edited June 2012

    @supreme-leader I see your 1 and raise you 2

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options
    422422 Developer MVP

    You should start a thread, the "like lottery"

    There was an error rendering this rich post.

  • Options
    peregrineperegrine MVP
    edited June 2012

    Well, I've seen what you've won from from having the highest points. :). Is it really worth it.

    I don't know if I could bear the load of all that fame and fortune. Mostly fortune - BTW did you get a big monetary increase from the developers :). 1000 X 0 = 0!

    I figured you should be able to ask one question of the developers for them to spend a bit of time to answer. - seems like that should have been the 1000 pt badge.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options
    422422 Developer MVP

    Uh huh, seemingly the only badges remaining are anniversary badges now.

    There was an error rendering this rich post.

  • Options
    fh111fh111 Vanilla Padawan ✭✭
    edited July 2012

    lol, raining likes here : )

    @peregrine

    i am trying to do the same with the discussion title, i want to abbreviate it to something like 56 characters or so, this is what i have now, following your example with the usernames. what i am struggeling with is the last part, where the url is put together in the 'a href' part. i can-t figure it out. it gives me

    /discussion//the discussion title/

    instead of

    /discussion/DiscussionID/discussion-slug

    $DiscussionName = $Discussion->Name;
       if ($DiscussionName == '')
          $DiscussionName = T('Blank Discussion Topic');
    $DiscussionNameShort = $Discussion->Name;
        if (strlen($DiscussionNameShort) > 56 ) 
    $DiscussionNameShort = substr($DiscussionNameShort,0,56) . '...';
    $ShortDiscussionNameAnchor = '<a href="'.htmlspecialchars(Url('/discussion/'. $DiscussionID . '/' .rawurlencode($Discussion->Name))).'"'.$CssClass.'>'.htmlspecialchars($DiscussionName).'</a>';
    
Sign In or Register to comment.