1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Title Control 1.7

Allows complete thread title control. Limit length, change case, remove certain characters and more.

  1. AndyB

    AndyB Well-Known Member

    AndyB submitted a new resource:

    Title Control - Allows complete thread title control.

    Read more about this resource...
     
  2. The Sandman

    The Sandman Well-Known Member

    Will this allow for "Title Case" (first letter of each word of the title in capitals) and retain additional capital letters? For example, if I type in "OMG I love XenForo" with Title case enabled it will show as "Omg I Love Xenforo" instead of "OMG I Love XenForo". I'd prefer the ability to keep the additional caps.
     
  3. AndyB

    AndyB Well-Known Member

    Yes you can easily do that by following these steps.

    1) Turn off the following Option:

    Admin CP -> Options -> Threads, Discussions and Conversations -> Automatically Adjust Case of Discussion Titles

    2) Create a file called TitleControl.php with the following content:

    PHP:
    <?php

    // get title
    $title $this->get('title');

    // uppercase the first character of each word in a string
    $title ucwords($title);

    // set title
    $this->set('title'$title);

    ?>
    3) Upload the TitleControl.php file to a folder on your server:

    4) In the Options page of the add-on, enter the relative path to the TitleControl.php file.

    Example: /home/southbay/www/misc/TitleControl.php
     
    Last edited: Aug 3, 2014
    The Sandman likes this.
  4. giorgino

    giorgino Well-Known Member

    wow another great must-have add-on Andy :)
    I've one request/suggestion

    I hate to read two types of titles: Those ones with the first letter lowercase (covered in your add-on) and those one with all uppercase.

    Is there the chance to add a control that count the lowercase chars in the title and force the user to write e better title?
    Example:

    bad --> I REALLY LOVE YOUR ADDONS (100% uppercase chars)
    bad --> I REALLY LOVE your add ons (more than 50% uppercase chars)
    good -> I really love your ADDONS (less than 25% of the title is uppercase)

    In this way is possible for the user to input in the title an acronym or something like that, avoiding the all-uppercase title standardizing the board typography.
     
  5. AndyB

    AndyB Well-Known Member

    Thank you, giogino.

    As described using the Path to PHP option, create a file and put the following code into it.

    PHP:
    <?php

    // get title
    $title $this->get('title');

    // prevent majority all caps
    if (strlen($title) > 40)
    {
        
    $pattern[0] = '/[^a-z]/';
        
    $replacement[0] = '';
        
    $parsed preg_replace($pattern$replacement$title);    
        
    $lower_count strlen($parsed);
        
        
    $pattern[0] = '/[^A-Z]/';
        
    $replacement[0] = '';
        
    $parsed preg_replace($pattern$replacement$title);
        
    $upper_count strlen($parsed);
        
        if (
    $upper_count $lower_count)
        {
            
    $title strtolower($title);
            
    $title ucfirst($title);
        }
    }

    // set title
    $this->set('title'$title);

    ?>
    This will act on thread titles longer than 40 characters and will convert the entire title (except the first character) to lower case if there are more uppercase characters than lowercase characters.
     
    Last edited: Aug 11, 2014
    giorgino likes this.
  6. giorgino

    giorgino Well-Known Member

    SuperGreat Andy!
    I'll test it ASAP!
     
  7. yavuz

    yavuz Well-Known Member

    Hi andy, thank you for this addon. Would it be possible to uppercase all words but have some words not to be changed?
     
  8. AndyB

    AndyB Well-Known Member

    Here is the code needed to make the thread title all uppercase except the word yavuz.

    PHP:
    <?php

    // get title
    $title $this->get('title');

    // make title uppercase
    $title $str strtoupper($title);

    // make YAVUZ lowercase
    if (substr_count($title'YAVUZ') > 0){
        
    $patterns[0] = '/YAVUZ/';
        
    $replacements[0] = 'yavuz';
        
    $title preg_replace($patterns$replacements$title);
    }

    // set title
    $this->set('title'$title);

    ?>
    Be careful not to convert those words which are very common, because the code will convert parts of a word too. So if I wanted to make the word "for" always lowercase this problem would occur:

    for EXAMPLE WORDS THAT ARE PART OF OTHER WORDS ARE AN UNforESEEN PROBLEM
     
    yavuz likes this.
  9. AndyB

    AndyB Well-Known Member

    Add this code:

    PHP:
    // see if there's any lowercase characters
    $pattern[0] = '/[^a-z]/';
    $replacement[0] = '';
    $parsed preg_replace($pattern$replacement$title);    
    $lower_count strlen($parsed);

    // convert title to all lowercase if currently all uppercase
    if ($lower_count == 0) {
        
    $title strtolower($title);
    }
    Just add that code preceding the other code. Of course make sure the first line is:

    PHP:
    // get title
    $title $this->get('title');
     
  10. AndyB

    AndyB Well-Known Member

    Yes I'll send that to you via Private Conversation.
     
  11. AndyB

    AndyB Well-Known Member

    Currently the preview will not show the converted title. It might be best not show any changes until the thread is posted, that way it won't confuse the user.
     
    Last edited: Oct 25, 2013
    The Sandman likes this.
  12. AndyB

    AndyB Well-Known Member

    I haven't tested, but adding code to the External PHP file to exclude by group might very well be possible.
     
  13. AndyB

    AndyB Well-Known Member

    There would be an infinite number of check boxes if I were to go that route. That's why I chose to use an External PHP file which can be custom coded for any forums needs.

    So for example you could exclude the admin using this code:

    PHP:
    <?php

    // get userId
    $visitor XenForo_Visitor::getInstance();
    $userId $visitor['user_id'];

    if (
    $userId != 1)
    {
        
    // get title
        
    $title $this->get('title');
           
        
    // uppercase the first character of each word in a string
        
    $title ucwords($title);
       
        
    // set title
        
    $this->set('title'$title);
    }

    ?>
    It's also possible to exclude by group.
     
    Last edited: Oct 25, 2013
  14. AndyB

    AndyB Well-Known Member

    That would be very difficult to code. I think it's easier to read as "Side-by-side" anyway.
     
  15. AndyB

    AndyB Well-Known Member

    Sorry I don't have a solution for this. Thankfully the use of quotes in a thread title occurs very infrequently.
     
  16. AndyB

    AndyB Well-Known Member

    I suggest keeping things simple. You can quickly create a coding mess if you try to get too fancy.
     
  17. AndyB

    AndyB Well-Known Member

    The Sandman likes this.
  18. Veer

    Veer Well-Known Member

    Hello AndyB

    I'm using XenForo's built-in Title case option but there is one thing that I want to control, when we use ) ( - " . or , the first letter of next word becomes lower case. Example: My "Thread" Title becomes My "thread" Title.
    It would be great if you could provide a solution for this?

    title case.png
     
  19. AndyB

    AndyB Well-Known Member

    Hi Veer,

    Here is the solution to the problem with special characters preventing words from being converted to first character uppercase.

    1) Turn off the Automatically Adjust Case of Discussion Titles (XenForo option)
    2) Create a file called TitleControl.php
    3) Add the following code to TitleControl.php

    PHP:
    <?php

    // get title
    $title $this->get('title');

    // convert words to first character uppercase
    $temp '';
    $temp preg_split('/(\W)/'$title, -1PREG_SPLIT_DELIM_CAPTURE );
    foreach (
    $temp as $key=>$word) {
        
    $temp[$key] = ucfirst(strtolower($word));
    }
    $title implode(''$temp);

    // set title
    $this->set('title'$title);

    ?>
    4) In this add-on option, provide the relative path to your External File TitleControl.php
     
    Last edited: Oct 27, 2013
    Veer likes this.
  20. Veer

    Veer Well-Known Member

    Great, Thank you @AndyB for helping me with this, it worked (y)
     

Share This Page