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...')

2»

Answers

  • Options

    you have to pull it out of Discussion object and set it first.

    $DiscussionId = $Discussion->DiscussionID;

    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 ✭✭
    edited July 2012

    ahh ok! thanks for the hint - it works now, but all my conditioned styling does not work anymore

    i have
    $ShortDiscussionNameAnchor = '<a href="'.htmlspecialchars(Url('/discussion'. $DiscussionID . '/' .rawurlencode($Discussion->DiscussionID))).'/'.Gdn_Format::Url($Discussion->Name).'"'.$CssClass.'>'.htmlspecialchars($DiscussionNameShort).'</a>';

    and later

    <?php  if ($Discussion->Announce == '1' && ($Session->IsValid() && $Discussion->CountUnreadComments < 1)) {
         echo Anchor($ShortDiscussionNameAnchor, $DiscussionUrl, 'TitleRedRead');
         }
    elseif ...and many more
    

    that basically gives announcements that a user has already read the link color 'red' and font-weight:normal via the class TitleRedRead. the next few elseif's give the discussiontitles either font-weight:bold or not depending on whether there are new posts or not

    so since i replaced $DiscussionName with $ShortDiscussionNameAnchor it is not assigning the classes (e.g. TitleRedRead) to the link ..

    i'm clueless mybe i have been staring at the screen for too long to get it .. have been on the computer for .. way too long without a break for my mind :-P

  • Options
    since the function is this.
    
     function Anchor($Text, $Destination = '', $CssClass = '', $Attributes = '', $ForceAnchor = FALSE) {
    
    this appears to be strange - are you sure?
    echo Anchor($ShortDiscussionNameAnchor, $DiscussionUrl, 'TitleRedRead')
    
    
    I would think the first parameter is text (e.g. Title).
    
    $DiscussionNameShort = $Discussion->Name;
    if (strlen($DiscussionNameShort) > 56 )
    $DiscussionNameShort = substr($DiscussionNameShort,0,56) . '...';
    
    echo Anchor($DiscussionNameShort, $DiscussionUrl, 'TitleRedRead');
    

    I'm not quite sure what you are doing.

    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 ✭✭

    ah ok this makes much more sense to me now. thanks for explaining! i just assumed i had to redefine the link similar to

    $newanchor = '<a href="'.htmlspecialchars(Url('/profile/'.$UserID . '/' .rawurlencode($Last->Name))).'"'.$CssClass.'>'.htmlspecialchars($short).'</a>';

    for the shortened usernames. i actually ended up adding a title to the shortened username links that outputs the complete username and i was hoping i could do the same with the discussion title, but it doesn't seem to work

    now the titles are shortened and the styling is working too, which is great. thanks

  • Options
    fh111fh111 Vanilla Padawan ✭✭

    @peregrine

    i just noticed, that when there is a long discussion title that ends with a special character (in todays case ", then it abbreviates wrong and ends up showing &qu... (from &quot;)

    is there a way to fix this?

  • Options
    peregrineperegrine MVP
    edited July 2012

    you could strip the special characters period that would be the easiest.

    can you show an image example?

    or you would need to keep track of opening and closing quotes.

    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 ✭✭

    not sure what you mean by 'strip the special characters period'

    here is an example image. notice the &q... instead of " at the end of the abbreviated discussion title

  • Options
    peregrineperegrine MVP
    edited July 2012

    shorten it up if it finds an ampersand towards the last 5 characters of string.

       $pos = (strrpos($DiscussionNameShort, '&', -5));                                    
        if ($pos > 50) {
        $DiscussionNameShort = substr($$DiscussionNameShort,0,$pos) . '...';
        } else {
        $DiscussionNameShort = substr($$DiscussionNameShort,0,56) . '...';
        }
    

    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 ✭✭

    good idea, will implement that! thanks : )

    you're spreading quite a bit of knowledge, thanks for that

Sign In or Register to comment.