Title Control

Title Control 1.7

No permission to download

AndyB

Well-known member
AndyB submitted a new resource:

Title Control - Allows complete thread title control.

Description:

The Title Control add-on will do the following:
  • Control maximum length of thread titles (Option)
  • Force the first character of the thread title to uppercase (Option)
  • Allow title control using external PHP file (Option)

Admin Options:

View attachment 59766

Requirements:

This add-on works on all versions of XenForo v1.2x and above.

Installation:
  1. Download titlecontrol_v1.0.zip and unzip it.
  2. Upload the Andy...

Read more about this resource...
 
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.
 
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.

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:
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.
 
wow another great must-have add-on Andy :)

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:
Thank you, giogino.

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

This will act on thread titles longer than 20 characters and will convert the entire title (except the first character) to lower case if there are more uppercase characters than lowercase characters.
SuperGreat Andy!
I'll test it ASAP!
 
Hi andy, thank you for this addon. Would it be possible to uppercase all words but have some words not to be changed?
 
Hi andy, thank you for this addon. Would it be possible to uppercase all words but have some words not to be changed?

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
 
...if the title has all capital letters can we first change it to all small letters, then run it through the rules you gave me above...

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');
 
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:
Not sure how useful it would really be, but it would be kinda cool if there was a usergroup option to override the preset thread title rules and post the title exactly as entered. :cool:

I haven't tested, but adding code to the External PHP file to exclude by group might very well be possible.
 
I was thinking more like a check box...

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:
@Andy - my current script handles words joined together by special characters instead of spaces (e.g. side-by-side) as single words. So if I enter "side-by-side" as a title it comes out "Side-by-side". I'm not sure that "Side-By-Side" would be better, but how would I add this as a rule to what I already have?

That would be very difficult to code. I think it's easier to read as "Side-by-side" anyway.
 
The current rules also fail to capitalize the first letter of a word after an open quotation symbol, so "test" comes out as "test" and "test test test" comes out as "test Test Test".

Sorry I don't have a solution for this. Thankfully the use of quotes in a thread title occurs very infrequently.
 
Hmm, what if the script added a space after each special character, did it's thing, and then removed the space after each special character in the last step?

I suggest keeping things simple. You can quickly create a coding mess if you try to get too fancy.
 
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.webp
 
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, -1, PREG_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:
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, -1, PREG_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
Great, Thank you @AndyB for helping me with this, it worked (y)
 
Back
Top Bottom