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.

Auto truncate titles of discussions created by embedded comments in WordPress

Hi,
I'm trying to set up Vanilla 2.1a33 to replace WordPress' commenting system. Basically it works just fine, but I have a problem with very long titles of discussions created automatically in Vanilla. In my case titles of WordPress posts are scrapped in following format:
Post title | Full site name . Since blog's name is some good 50 characters, titles are getting ridiculously long.

I was wondering if anybody got around this problem. As a lousy workaround, I have added the following to the class.postcontroller.php (thanks, stackoverflow):

        function nsubstr($needle, $haystack, $n_occurrence)
        {
            $arr = explode($needle,$haystack,$n_occurrence);
            $last = count($arr) - 1;
            $pos_in_last = strpos($arr[$last],$needle);

            if ($pos_in_last !== false)
            $arr[$last] = substr($arr[$last],0,$pos_in_last);

            return implode($needle,$arr);
        }

         $Title = nsubstr('|',$Title,1);

As long as I'm not refetching, I'm fine (or at least I think I am). It would be nice if there was a proper solution.

Cheers,

Best Answer

Answers

  • you could write a plugin to replace the title either via php or js, if you don't want to modify core.

    or you might possibly do something in a themehooks file.

    another alternative, equally messy
    http://vanillaforums.org/discussion/comment/164019/#Comment_164019

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

  • you could put something like in your themehooks file

    public function DiscussionsController_BeforeDiscussionContent_Handler($Sender, $Args) {
    
        $DiscussionNameShort = $Sender->EventArguments['DiscussionName'];
        if (strlen($DiscussionNameShort) > 50) {
        $Sender->EventArguments['DiscussionName'] = substr($DiscussionNameShort,0,50) . '...';
        }
    
    }
    
    
    public function CategoriesController_BeforeDiscussionContent_Handler($Sender, $Args) {
    
     $DiscussionNameShort = $Sender->EventArguments['DiscussionName'];
        if (strlen($DiscussionNameShort) > 50) {
        $Sender->EventArguments['DiscussionName'] = substr($DiscussionNameShort,0,50) . '...';
        }
    
    
    
    }
    

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

  • @peregrine said:
    you could put something like in your themehooks file

    Thanks for the suggestion, but your function only truncates titles in discussions list, not in the discussion itself. Plus, I really want to keep all text before first pipe, so I need something like the function I have posted.

  • I've the same problem but the workaround of PolishKaragionis doesn't work! How I can remove all "Full site name" and "|"?

Sign In or Register to comment.