How can I create a censor add-on?

And be sure what you want to search/replace is enough specific to avoid to modify any important code source.

The variable $outout is the entire HTML page and now I can change any word contained in the HTML output as needed. This will mostly be used to prevent showing the "f" word and it's variations.

Again the idea is to allow members to use the "f" word but censor it for guests.
 
The variable $outout is the entire HTML page and now I can change any word contained in the HTML output as needed. This will mostly be used to prevent showing the "f" word and it's variations.

Again the idea is to allow members to use the "f" word but censor it for guests.

Use a regex then:
PHP:
$output = preg_replace('#\b****\b#i', 'bloody', $output);

Read more about the regex \b feature. This would prevent to make the replacement too much greedy.
 
This currently works very well.

PHP:
<?php

class Andy_Censor_Listener
{
	protected static $_responseType = NULL;
	
	public static function frontControllerPreDispatch(XenForo_FrontController $fc, XenForo_RouteMatch &$routeMatch)
	{		
 		self::$_responseType = $routeMatch->getResponseType(); 
	}
	
	public static function frontControllerPostView($fc, &$output) 
	{		
		if (self::$_responseType == 'html')
		{
			$userId = XenForo_Visitor::getUserId();  
			
			if ($userId == 0)
			{
				$output = preg_replace('/test1234/', "********", $output);
			}
		}
	}	
}
 
Thank you for all your help cclaerhout, you're amazing.

Also thank you for the Word Boundaries tip.
 
Top Bottom