Make word censor work with code bbcode.

Looking for a MOD? Have a MOD request? Post here for help. (Note: This forum is community supported; phpBB does not have official MOD authors)
Get Involved
Locked
yais
Registered User
Posts: 306
Joined: Sun Jun 17, 2007 12:45 pm

Make word censor work with code bbcode.

Post by yais » Sun Nov 02, 2008 10:03 pm

I already posted this on the phpBB bug tracker. It was marked as "not a bug" but I was wondering if there is someway I could still make the word censor work with the code bbcode.

http://www.phpbb.com/bugs/phpbb3/35845

Basically, I have added some websites to my word censor and it normally works fine. However if I put the url in a

Code: Select all

 bbcode, it stops working and shows the url, despite the fact it is supposed to be censored.

For Example:

I add "*test.com*" to the work censor to replace with "~censored~"

when i type "test.com" normally, it works but if i put "test.com" in a code bbcode, it doesnt work.

This defeats the purpose of a censor as people use the code bbcode to bypass it.

User avatar
3Di
Former Team Member
Posts: 14482
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Make word censor work with code bbcode.

Post by 3Di » Mon Nov 03, 2008 8:05 am

It makes a non-sence IMO to censor a URL where a URL it is needed in that snippet, in case.
yais wrote:as people use the code bbcode to bypass it.
In this case, you could BAN them.
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
✒️ Black Friday 2019 @ The Studio ▪️◾️

User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 17087
Joined: Thu Jan 06, 2005 1:30 pm
Location: Fishkill, NY
Name: David Colón
Contact:

Re: Make word censor work with code bbcode.

Post by DavidIQ » Mon Nov 03, 2008 8:20 am

Plus you can't click on it anyways.
Apply to become a Jr. Extension Validator
My extensions | In need of phpBB services? | Was I helpful today?
No unsolicited PMs unless you're planning on asking for paid help.

Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 25490
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: Make word censor work with code bbcode.

Post by Paul » Mon Nov 03, 2008 8:28 am

Moved to MOD requests.
Knock knock
Race condition
Who's there?

My BlogMy Photosmy phpBB Extensionscustom phpBB work & Development

User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 17087
Joined: Thu Jan 06, 2005 1:30 pm
Location: Fishkill, NY
Name: David Colón
Contact:

Re: Make word censor work with code bbcode.

Post by DavidIQ » Mon Nov 03, 2008 1:49 pm

Ok...so I played around with this a bit last night and found that words within the code tag do get censored. For some reason the period (.) in test.com messes with the regular expression and causes it not to detect it. If I used just "test" the word does indeed get changed in the code tag.

Looking at the regular expression that gets generated for this particular word censor:

Code: Select all

#(?<!\w)(\w*?test\.com)(?!\w)#i
My guess would be that it's looking for word characters before and after "test.com" but the code tag gets rendered something like:

Code: Select all

[code:2o7ehetv]test.com[/code:2o7ehetv]
Something about the period is also coming into play here. Maybe if someone else stares at the regex long enough they'll figure it out...I'm still trying to figure it out.

EDIT: Could also have to do with the fact that bbcodes go through their own preg_replace as well...
Apply to become a Jr. Extension Validator
My extensions | In need of phpBB services? | Was I helpful today?
No unsolicited PMs unless you're planning on asking for paid help.

User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 17087
Joined: Thu Jan 06, 2005 1:30 pm
Location: Fishkill, NY
Name: David Colón
Contact:

Re: Make word censor work with code bbcode.

Post by DavidIQ » Mon Nov 03, 2008 2:04 pm

Alright...got a fix for you.

Open up includes/bbcode.php

Find:

Code: Select all

		// Remove the uid from tags that have not been transformed into HTML
		$message = str_replace(':' . $this->bbcode_uid, '', $message);
Add after:

Code: Select all

		$message = censor_text($message);
I tried it with the example you provided and the censoring filter was applied correctly. I have put this information in the bug report.
Apply to become a Jr. Extension Validator
My extensions | In need of phpBB services? | Was I helpful today?
No unsolicited PMs unless you're planning on asking for paid help.

yais
Registered User
Posts: 306
Joined: Sun Jun 17, 2007 12:45 pm

Re: Make word censor work with code bbcode.

Post by yais » Mon Nov 03, 2008 5:09 pm

that fix works well. thanks.

User avatar
Diet Ebola Cola
Registered User
Posts: 132
Joined: Fri Oct 03, 2008 3:57 am
Location: USA

Re: Make word censor work with code bbcode.

Post by Diet Ebola Cola » Mon Nov 03, 2008 9:34 pm

There are also two Mods that may be able to help, too:

NV Advanced Word Censor - allows bbcode and smilies to be used

There's also another Mod for the Word Censor with advanced wildcard filters, but the search engine isn't being very helpful today, and I was unable to find it. :?
Diet Ebola Cola

User avatar
Diet Ebola Cola
Registered User
Posts: 132
Joined: Fri Oct 03, 2008 3:57 am
Location: USA

Re: Make word censor work with code bbcode.

Post by Diet Ebola Cola » Tue Nov 04, 2008 1:31 am

Found the 2nd Mod i was looking for:
Censor Partial Word Replacement Mod

Edit: Oops. Now I realize I misread the original request. The OP couldn't get the word censor replacement to work within the CODE bbcode. The fix is above, and the mods i posted are still useful for working with bbcodes and the word censor. Hopefully someone else will find them useful.
Diet Ebola Cola

ibelphegor
Registered User
Posts: 453
Joined: Wed Oct 24, 2007 8:37 am

Re: Make word censor work with code bbcode.

Post by ibelphegor » Thu Nov 06, 2008 5:19 pm

DavidIQ wrote:Alright...got a fix for you.

Open up includes/bbcode.php

Find:

Code: Select all

		// Remove the uid from tags that have not been transformed into HTML
		$message = str_replace(':' . $this->bbcode_uid, '', $message);
Add after:

Code: Select all

		$message = censor_text($message);
I tried it with the example you provided and the censoring filter was applied correctly. I have put this information in the bug report.
It's not working for me.
Now link with bbcode are censored but when you click you still get to the link behind.

User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 17087
Joined: Thu Jan 06, 2005 1:30 pm
Location: Fishkill, NY
Name: David Colón
Contact:

Re: Make word censor work with code bbcode.

Post by DavidIQ » Thu Nov 06, 2008 5:45 pm

ibelphegor wrote:It's not working for me.
Now link with bbcode are censored but when you click you still get to the link behind.
:?:
Based on this:
yais wrote:that fix works well. thanks.
and my own testing I'd say that you either don't have a standard bbcode.php file or you didn't do the edit correctly or are missunderstanding what the issue really is especially because the code tag won't render clickable links. That's what this whole thing was about.
Apply to become a Jr. Extension Validator
My extensions | In need of phpBB services? | Was I helpful today?
No unsolicited PMs unless you're planning on asking for paid help.

ibelphegor
Registered User
Posts: 453
Joined: Wed Oct 24, 2007 8:37 am

Re: Make word censor work with code bbcode.

Post by ibelphegor » Thu Nov 06, 2008 5:54 pm

Based on my results on localhost test.
ibelphegor wrote: It's not working for me.
Now link with bbcode are censored but when you click you still get to the link behind.

DavidIQ wrote: and my own testing I'd say that you either don't have a standard bbcode.php file or you didn't do the edit correctly or are missunderstanding what the issue really is especially because the code tag won't render clickable links. That's what this whole thing was about.
Maybe Hoteditor problem? can you look into my code please?

Code: Select all

<?php
/**
*
* @package phpBB3
* @version $Id: bbcode.php,v 1.114 2007/10/07 10:34:45 naderman Exp $
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
	exit;
}

/**
* BBCode class
* @package phpBB3
*/
class bbcode
{
	var $bbcode_uid = '';
	var $bbcode_bitfield = '';
	var $bbcode_cache = array();
	var $bbcode_template = array();

	var $bbcodes = array();

	var $template_bitfield;
	var $template_filename = '';

	/**
	* Constructor
	* Init bbcode cache entries if bitfield is specified
	*/
	function bbcode($bitfield = '')
	{
		if ($bitfield)
		{
			$this->bbcode_bitfield = $bitfield;
			$this->bbcode_cache_init();
		}
	}

	/**
	* Second pass bbcodes
	*/
	function bbcode_second_pass(&$message, $bbcode_uid = '', $bbcode_bitfield = false)
	{
	//HotEditor MOD
    $message=BBCodeToHTML($message);
		if ($bbcode_uid)
		{
			$this->bbcode_uid = $bbcode_uid;
		}

		if ($bbcode_bitfield !== false)
		{
			$this->bbcode_bitfield = $bbcode_bitfield;

			// Init those added with a new bbcode_bitfield (already stored codes will not get parsed again)
			$this->bbcode_cache_init();
		}

		if (!$this->bbcode_bitfield)
		{
			// Remove the uid from tags that have not been transformed into HTML
			if ($this->bbcode_uid)
			{
				$message = str_replace(':' . $this->bbcode_uid, '', $message);
			}

			return;
		}

		$str = array('search' => array(), 'replace' => array());
		$preg = array('search' => array(), 'replace' => array());

		$bitfield = new bitfield($this->bbcode_bitfield);
		$bbcodes_set = $bitfield->get_all_set();

		$undid_bbcode_specialchars = false;
		foreach ($bbcodes_set as $bbcode_id)
		{
			if (!empty($this->bbcode_cache[$bbcode_id]))
			{
				foreach ($this->bbcode_cache[$bbcode_id] as $type => $array)
				{
					foreach ($array as $search => $replace)
					{
						${$type}['search'][] = str_replace('$uid', $this->bbcode_uid, $search);
						${$type}['replace'][] = $replace;
					}

					if (sizeof($str['search']))
					{
						$message = str_replace($str['search'], $str['replace'], $message);
						$str = array('search' => array(), 'replace' => array());
					}

					if (sizeof($preg['search']))
					{
						// we need to turn the entities back into their original form to allow the
						// search patterns to work properly
						if (!$undid_bbcode_specialchars)
						{
							$message = str_replace(array('&#58;', '&#46;'), array(':', '.'), $message);
							$undid_bbcode_specialchars = true;
						}

						$message = preg_replace($preg['search'], $preg['replace'], $message);
						$preg = array('search' => array(), 'replace' => array());
					}
				}
			}
		}

		// Remove the uid from tags that have not been transformed into HTML
		$message = str_replace(':' . $this->bbcode_uid, '', $message);
	}

	/**
	* Init bbcode cache
	*
	* requires: $this->bbcode_bitfield
	* sets: $this->bbcode_cache with bbcode templates needed for bbcode_bitfield
	*/
	function bbcode_cache_init()
	{
		global $user, $phpbb_root_path;

		if (empty($this->template_filename))
		{
			$this->template_bitfield = new bitfield($user->theme['bbcode_bitfield']);
			$this->template_filename = $phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template/bbcode.html';

			if (!@file_exists($this->template_filename))
			{
				trigger_error('The file ' . $this->template_filename . ' is missing.', E_USER_ERROR);
			}
		}

		$bbcode_ids = $rowset = $sql = array();

		$bitfield = new bitfield($this->bbcode_bitfield);
		$bbcodes_set = $bitfield->get_all_set();

		foreach ($bbcodes_set as $bbcode_id)
		{
			if (isset($this->bbcode_cache[$bbcode_id]))
			{
				// do not try to re-cache it if it's already in
				continue;
			}
			$bbcode_ids[] = $bbcode_id;

			if ($bbcode_id > NUM_CORE_BBCODES)
			{
				$sql[] = $bbcode_id;
			}
		}

		if (sizeof($sql))
		{
			global $db;

			$sql = 'SELECT *
				FROM ' . BBCODES_TABLE . '
				WHERE ' . $db->sql_in_set('bbcode_id', $sql);
			$result = $db->sql_query($sql, 3600);

			while ($row = $db->sql_fetchrow($result))
			{
				// To circumvent replacing newlines with <br /> for the generated html,
				// we use carriage returns here. They are later changed back to newlines
				$row['bbcode_tpl'] = str_replace("\n", "\r", $row['bbcode_tpl']);
				$row['second_pass_replace'] = str_replace("\n", "\r", $row['second_pass_replace']);

				$rowset[$row['bbcode_id']] = $row;
			}
			$db->sql_freeresult($result);
		}

		foreach ($bbcode_ids as $bbcode_id)
		{
			switch ($bbcode_id)
			{
				case 0:
					$this->bbcode_cache[$bbcode_id] = array(
						'str' => array(
							'[/quote:$uid]'	=> $this->bbcode_tpl('quote_close', $bbcode_id)
						),
						'preg' => array(
							'#\[quote(?:="(.*?)")?:$uid\]((?!\[quote(?:=".*?")?:$uid\]).)?#ise'	=> "\$this->bbcode_second_pass_quote('\$1', '\$2')"
						)
					);
				break;

				case 1:
					$this->bbcode_cache[$bbcode_id] = array(
						'str' => array(
							'[b:$uid]'	=> $this->bbcode_tpl('b_open', $bbcode_id),
							'[/b:$uid]'	=> $this->bbcode_tpl('b_close', $bbcode_id),
						)
					);
				break;

				case 2:
					$this->bbcode_cache[$bbcode_id] = array(
						'str' => array(
							'[i:$uid]'	=> $this->bbcode_tpl('i_open', $bbcode_id),
							'[/i:$uid]'	=> $this->bbcode_tpl('i_close', $bbcode_id),
						)
					);
				break;

				case 3:
					$this->bbcode_cache[$bbcode_id] = array(
						'preg' => array(
							'#\[url:$uid\]((.*?))\[/url:$uid\]#s'			=> $this->bbcode_tpl('url', $bbcode_id),
							'#\[url=([^\[]+?):$uid\](.*?)\[/url:$uid\]#s'	=> $this->bbcode_tpl('url', $bbcode_id),
						)
					);
				break;

				case 4:
					if ($user->optionget('viewimg'))
					{
						$this->bbcode_cache[$bbcode_id] = array(
							'preg' => array(
								'#\[img:$uid\](.*?)\[/img:$uid\]#s'		=> $this->bbcode_tpl('img', $bbcode_id),
							)
						);
					}
					else
					{
						$this->bbcode_cache[$bbcode_id] = array(
							'preg' => array(
								'#\[img:$uid\](.*?)\[/img:$uid\]#s'		=> str_replace('$2', '[ img ]', $this->bbcode_tpl('url', $bbcode_id, true)),
							)
						);
					}
				break;

				case 5:
					$this->bbcode_cache[$bbcode_id] = array(
						'preg' => array(
							'#\[size=([\-\+]?\d+):$uid\](.*?)\[/size:$uid\]#s'	=> $this->bbcode_tpl('size', $bbcode_id),
						)
					);
				break;

				case 6:
					$this->bbcode_cache[$bbcode_id] = array(
						'preg' => array(
							'!\[color=(#[0-9a-f]{6}|[a-z\-]+):$uid\](.*?)\[/color:$uid\]!is'	=> $this->bbcode_tpl('color', $bbcode_id),
						)
					);
				break;

				case 7:
					$this->bbcode_cache[$bbcode_id] = array(
						'str' => array(
							'[u:$uid]'	=> $this->bbcode_tpl('u_open', $bbcode_id),
							'[/u:$uid]'	=> $this->bbcode_tpl('u_close', $bbcode_id),
						)
					);
				break;

				case 8:
					$this->bbcode_cache[$bbcode_id] = array(
						'preg' => array(
							'#\[code(?:=([a-z]+))?:$uid\](.*?)\[/code:$uid\]#ise'	=> "\$this->bbcode_second_pass_code('\$1', '\$2')",
						)
					);
				break;

				case 9:
					$this->bbcode_cache[$bbcode_id] = array(
						'preg' => array(
							'#(\[\/?(list|\*):[mou]?:?$uid\])[\n]{1}#'	=> "\$1",
							'#(\[list=([^\[]+):$uid\])[\n]{1}#'			=> "\$1",
							'#\[list=([^\[]+):$uid\]#e'					=> "\$this->bbcode_list('\$1')",
						),
						'str' => array(
							'[list:$uid]'		=> $this->bbcode_tpl('ulist_open_default', $bbcode_id),
							'[/list:u:$uid]'	=> $this->bbcode_tpl('ulist_close', $bbcode_id),
							'[/list:o:$uid]'	=> $this->bbcode_tpl('olist_close', $bbcode_id),
							'[*:$uid]'			=> $this->bbcode_tpl('listitem', $bbcode_id),
							'[/*:$uid]'			=> $this->bbcode_tpl('listitem_close', $bbcode_id),
							'[/*:m:$uid]'		=> $this->bbcode_tpl('listitem_close', $bbcode_id)
						),
					);
				break;

				case 10:
					$this->bbcode_cache[$bbcode_id] = array(
						'preg' => array(
							'#\[email:$uid\]((.*?))\[/email:$uid\]#is'			=> $this->bbcode_tpl('email', $bbcode_id),
							'#\[email=([^\[]+):$uid\](.*?)\[/email:$uid\]#is'	=> $this->bbcode_tpl('email', $bbcode_id)
						)
					);
				break;

				case 11:
					if ($user->optionget('viewflash'))
					{
						$this->bbcode_cache[$bbcode_id] = array(
							'preg' => array(
								'#\[flash=([0-9]+),([0-9]+):$uid\](.*?)\[/flash:$uid\]#'	=> $this->bbcode_tpl('flash', $bbcode_id),
							)
						);
					}
					else
					{
						$this->bbcode_cache[$bbcode_id] = array(
							'preg' => array(
								'#\[flash=([0-9]+),([0-9]+):$uid\](.*?)\[/flash:$uid\]#'	=> str_replace('$1', '$3', str_replace('$2', '[ flash ]', $this->bbcode_tpl('url', $bbcode_id, true)))
							)
						);
					}
				break;

				case 12:
					$this->bbcode_cache[$bbcode_id] = array(
						'str'	=> array(
							'[/attachment:$uid]'	=> $this->bbcode_tpl('inline_attachment_close', $bbcode_id)
						),
						'preg'	=> array(
							'#\[attachment=([0-9]+):$uid\]#'	=> $this->bbcode_tpl('inline_attachment_open', $bbcode_id)
						)
					);
				break;

				default:
					if (isset($rowset[$bbcode_id]))
					{
						if ($this->template_bitfield->get($bbcode_id))
						{
							// The bbcode requires a custom template to be loaded
							if (!$bbcode_tpl = $this->bbcode_tpl($rowset[$bbcode_id]['bbcode_tag'], $bbcode_id))
							{
								// For some reason, the required template seems not to be available, use the default template
								$bbcode_tpl = (!empty($rowset[$bbcode_id]['second_pass_replace'])) ? $rowset[$bbcode_id]['second_pass_replace'] : $rowset[$bbcode_id]['bbcode_tpl'];
							}
							else
							{
								// In order to use templates with custom bbcodes we need
								// to replace all {VARS} to corresponding backreferences
								// Note that backreferences are numbered from bbcode_match
								if (preg_match_all('/\{(URL|LOCAL_URL|EMAIL|TEXT|SIMPLETEXT|IDENTIFIER|COLOR|NUMBER)[0-9]*\}/', $rowset[$bbcode_id]['bbcode_match'], $m))
								{
									foreach ($m[0] as $i => $tok)
									{
										$bbcode_tpl = str_replace($tok, '$' . ($i + 1), $bbcode_tpl);
									}
								}
							}
						}
						else
						{
							// Default template
							$bbcode_tpl = (!empty($rowset[$bbcode_id]['second_pass_replace'])) ? $rowset[$bbcode_id]['second_pass_replace'] : $rowset[$bbcode_id]['bbcode_tpl'];
						}

						// Replace {L_*} lang strings
						$bbcode_tpl = preg_replace('/{L_([A-Z_]+)}/e', "(!empty(\$user->lang['\$1'])) ? \$user->lang['\$1'] : ucwords(strtolower(str_replace('_', ' ', '\$1')))", $bbcode_tpl);

						if (!empty($rowset[$bbcode_id]['second_pass_replace']))
						{
							// The custom BBCode requires second-pass pattern replacements
							$this->bbcode_cache[$bbcode_id] = array(
								'preg' => array($rowset[$bbcode_id]['second_pass_match'] => $bbcode_tpl)
							);
						}
						else
						{
							$this->bbcode_cache[$bbcode_id] = array(
								'str' => array($rowset[$bbcode_id]['second_pass_match'] => $bbcode_tpl)
							);
						}
					}
					else
					{
						$this->bbcode_cache[$bbcode_id] = false;
					}
				break;
			}
		}
	}

	/**
	* Return bbcode template
	*/
	function bbcode_tpl($tpl_name, $bbcode_id = -1, $skip_bitfield_check = false)
	{
		static $bbcode_hardtpl = array();
		if (empty($bbcode_hardtpl))
		{
			global $user;
			
			$bbcode_hardtpl = array(
				'b_open'	=> '<span style="font-weight: bold">',
				'b_close'	=> '</span>',
				'i_open'	=> '<span style="font-style: italic">',
				'i_close'	=> '</span>',
				'u_open'	=> '<span style="text-decoration: underline">',
				'u_close'	=> '</span>',
				'img'		=> '<img src="$1" alt="' . $user->lang['IMAGE'] . '" />',
				'size'		=> '<span style="font-size: $1%; line-height: normal">$2</span>',
				'color'		=> '<span style="color: $1">$2</span>',
				'email'		=> '<a href="mailto:$1">$2</a>'
			);
		}

		if ($bbcode_id != -1 && !$skip_bitfield_check && !$this->template_bitfield->get($bbcode_id))
		{
			return (isset($bbcode_hardtpl[$tpl_name])) ? $bbcode_hardtpl[$tpl_name] : false;
		}

		if (empty($this->bbcode_template))
		{
			if (($tpl = file_get_contents($this->template_filename)) === false)
			{
				trigger_error('Could not load bbcode template', E_USER_ERROR);
			}

			// replace \ with \\ and then ' with \'.
			$tpl = str_replace('\\', '\\\\', $tpl);
			$tpl = str_replace("'", "\'", $tpl);

			// strip newlines and indent
			$tpl = preg_replace("/\n[\n\r\s\t]*/", '', $tpl);

			// Turn template blocks into PHP assignment statements for the values of $bbcode_tpl..
			$this->bbcode_template = array();

			$matches = preg_match_all('#<!-- BEGIN (.*?) -->(.*?)<!-- END (?:.*?) -->#', $tpl, $match);

			for ($i = 0; $i < $matches; $i++)
			{
				if (empty($match[1][$i]))
				{
					continue;
				}

				$this->bbcode_template[$match[1][$i]] = $this->bbcode_tpl_replace($match[1][$i], $match[2][$i]);
			}
		}

		return (isset($this->bbcode_template[$tpl_name])) ? $this->bbcode_template[$tpl_name] : ((isset($bbcode_hardtpl[$tpl_name])) ? $bbcode_hardtpl[$tpl_name] : false);
	}

	/**
	* Return bbcode template replacement
	*/
	function bbcode_tpl_replace($tpl_name, $tpl)
	{
		global $user;

		static $replacements = array(
			'quote_username_open'	=> array('{USERNAME}'	=> '$1'),
			'color'					=> array('{COLOR}'		=> '$1', '{TEXT}'			=> '$2'),
			'size'					=> array('{SIZE}'		=> '$1', '{TEXT}'			=> '$2'),
			'img'					=> array('{URL}'		=> '$1'),
			'flash'					=> array('{WIDTH}'		=> '$1', '{HEIGHT}'			=> '$2', '{URL}'	=> '$3'),
			'url'					=> array('{URL}'		=> '$1', '{DESCRIPTION}'	=> '$2'),
			'email'					=> array('{EMAIL}'		=> '$1', '{DESCRIPTION}'	=> '$2')
		);

		$tpl = preg_replace('/{L_([A-Z_]+)}/e', "(!empty(\$user->lang['\$1'])) ? \$user->lang['\$1'] : ucwords(strtolower(str_replace('_', ' ', '\$1')))", $tpl);

		if (!empty($replacements[$tpl_name]))
		{
			$tpl = strtr($tpl, $replacements[$tpl_name]);
		}

		return trim($tpl);
	}

	/**
	* Second parse list bbcode
	*/
	function bbcode_list($type)
	{
		if ($type == '')
		{
			$tpl = 'ulist_open_default';
			$type = 'default';
		}
		else if ($type == 'i')
		{
			$tpl = 'olist_open';
			$type = 'lower-roman';
		}
		else if ($type == 'I')
		{
			$tpl = 'olist_open';
			$type = 'upper-roman';
		}
		else if (preg_match('#^(disc|circle|square)$#i', $type))
		{
			$tpl = 'ulist_open';
			$type = strtolower($type);
		}
		else if (preg_match('#^[a-z]$#', $type))
		{
			$tpl = 'olist_open';
			$type = 'lower-alpha';
		}
		else if (preg_match('#[A-Z]#', $type))
		{
			$tpl = 'olist_open';
			$type = 'upper-alpha';
		}
		else if (is_numeric($type))
		{
			$tpl = 'olist_open';
			$type = 'arabic-numbers';
		}
		else
		{
			$tpl = 'olist_open';
			$type = 'arabic-numbers';
		}

		return str_replace('{LIST_TYPE}', $type, $this->bbcode_tpl($tpl));
	}

	/**
	* Second parse quote tag
	*/
	function bbcode_second_pass_quote($quote_data, $quote)
	{
		// when using the /e modifier, preg_replace slashes double-quotes but does not
		// seem to slash anything else
		$quote = str_replace('\"', '"', $quote);
		//-- Advanced quoting
		//-- Delete
		/*
		$username = str_replace('\"', '"', $username);

		// remove newline at the beginning
		if ($quote == "\n")
		{
			$quote = '';
		}

		$quote = (($username) ? str_replace('$1', $username, $this->bbcode_tpl('quote_username_open')) : $this->bbcode_tpl('quote_open')) . $quote;
		*/
		//-- Add
		global $db, $user;

		$quote_data = str_replace('\"', '"', $quote_data);
		
		/*
		 * Handeling the new version
		 */
		if (strpos ($quote_data,";p="))
		{
			$quote_temp_data =  str_replace(""", "", explode(';p=', $quote_data));
			$user_id = $quote_temp_data[0];
			$post_id = $quote_temp_data[1];
		}
		else
		{
			$user_id = $quote_data;
		}
		
		$data = array();
		if (!is_numeric ($user_id))
		{
			$data['username'] = $user_id;
		}
		$sql = "
			SELECT username, user_id, user_colour
				FROM " . USERS_TABLE . "
					WHERE user_id = " . (int) $user_id . "
		";
		$result = $db->sql_query_limit ($sql, 1);
		$row = $db->sql_fetchrow ($result);
		if (is_array ($row))
		{
			$data = array_merge ($data, $row);
		}
		else
		{
			$data['user_id'] = 1;
		}
		$db->sql_freeresult ($result);
		
		if (isset ($post_id) AND !empty ($post_id))
		{
			$sql = "
				SELECT post_id, forum_id, topic_id, post_time, post_subject
					FROM " . POSTS_TABLE . "
						WHERE post_id = '{$post_id}'
			";
			$result = $db->sql_query_limit ($sql, 1);
			$row = $db->sql_fetchrow ($result);
			if (is_array ($row))
			{
				$data = array_merge ($data, $row);
			}
			$db->sql_freeresult ($result);
		}

		$username = $this->advanced_quoting_quote_head ($data);
		$quote = (($username) ? str_replace('$1', $username, $this->bbcode_tpl('quote_username_open')) : $this->bbcode_tpl('quote_open')) . $quote;
		//-- End Advanced quoting

		return $quote;
	}

	/**
	* Second parse code tag
	*/
	function bbcode_second_pass_code($type, $code)
	{
		// when using the /e modifier, preg_replace slashes double-quotes but does not
		// seem to slash anything else
		$code = str_replace('\"', '"', $code);

		switch ($type)
		{
			case 'php':
				// Not the english way, but valid because of hardcoded syntax highlighting
				if (strpos($code, '<span class="syntaxdefault"><br /></span>') === 0)
				{
					$code = substr($code, 41);
				}

			// no break;

			default:
				$code = str_replace("\t", '&nbsp; &nbsp;', $code);
				$code = str_replace('  ', '&nbsp; ', $code);
				$code = str_replace('  ', ' &nbsp;', $code);

				// remove newline at the beginning
				if (!empty($code) && $code[0] == "\n")
				{
					$code = substr($code, 1);
				}
			break;
		}

		$code = $this->bbcode_tpl('code_open') . $code . $this->bbcode_tpl('code_close');

		return $code;
	}
	//-- Advanced quoting
	//-- Add
	/**
	* Prepare the quote head
	*
	* @param string[] $param 
	* @return string quote head
	*/
	function advanced_quoting_quote_head($param)
	{
		global $config, $user;

		$username	= "";
		$post_link	= "";
		
		// Create the username
		if ($config['aq_user_link'] === "1" AND $param['user_id'] != 1)
		{
			if ($param['user_id'] != 1)
			{
				$username .= "<a href=\"./memberlist.php?mode=viewprofile&un=" . $param['username'] . "\" title=\"" . $param['username'] . "\"%s>" . $param['username'] . "</a>";
			}
			else
			{
				$username .= $param['username'];
			}
			if ($config['aq_user_color'] === "1")
			{
				$username = sprintf ($username, " style=\"color: #".$param['user_colour']."; font-weight: bold;\" class=\"username-coloured\"");
			}
			else
			{
				$username = sprintf ($username, "");
			}
		}
		elseif ($config['aq_user_link'] === "0" AND $config['aq_user_color'] === "1")
		{
			$username = "<span style=\"color: #".$param['user_colour']."; font-weight: bold;\">" . $param['username'] . "</span>";
		}
		else
		{
			$username = $param['username'];
		}

		// Create the post link
		if ($config['aq_post_link'] === "1" AND isset ($param['post_id']))
		{
			$post_link .= "<a href=\"./viewtopic.php?f=".$param['forum_id']."&t=".$param['topic_id']."#p".$param['post_id']."\">";
			if ($config['aq_post_link_format'] === "1")
			{
				$post_link .= date ($user->data['user_dateformat'], $param['post_time']);
			}
			else
			{
				$post_link .= $param['post_subject'];
			}
			$post_link .= "</a>";
		}
		
		return $username . (($post_link != "") ? '&nbsp;-&nbsp;' . $post_link : '');
	}
	//-- End Advanced quoting
}

?>

User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 17087
Joined: Thu Jan 06, 2005 1:30 pm
Location: Fishkill, NY
Name: David Colón
Contact:

Re: Make word censor work with code bbcode.

Post by DavidIQ » Thu Nov 06, 2008 6:07 pm

I don't even see where you put the code in... I see nothing after:

Code: Select all

      // Remove the uid from tags that have not been transformed into HTML
      $message = str_replace(':' . $this->bbcode_uid, '', $message);
Apply to become a Jr. Extension Validator
My extensions | In need of phpBB services? | Was I helpful today?
No unsolicited PMs unless you're planning on asking for paid help.

ibelphegor
Registered User
Posts: 453
Joined: Wed Oct 24, 2007 8:37 am

Re: Make word censor work with code bbcode.

Post by ibelphegor » Thu Nov 06, 2008 6:18 pm

I add the code in line 73 (the first - hot editor)
and now i see that i have the same line in 122 (normal).

So now it's work perfect, sorry for the noob mistake :?

Locked

Return to “[3.0.x] MOD Requests”