phpBB

Code Changes

File: includes/bbcode.php

  Unmodified   Added   Modified   Removed
Line 110Line 110
							$undid_bbcode_specialchars = true;
}


							$undid_bbcode_specialchars = true;
}


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












						foreach ($preg['search'] as $key => $search)
{
if (is_callable($preg['replace'][$key]))
{
$message = preg_replace_callback($search, $preg['replace'][$key], $message);
}
else
{
$message = preg_replace($search, $preg['replace'][$key], $message);
}
}


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

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

Line 129Line 140
	*/
function bbcode_cache_init()
{

	*/
function bbcode_cache_init()
{

		global $phpbb_root_path, $phpEx, $config, $user, $phpbb_extension_manager, $phpbb_path_helper;

		global $user, $phpbb_dispatcher, $phpbb_extension_manager, $phpbb_container, $phpbb_filesystem;


if (empty($this->template_filename))
{
$this->template_bitfield = new bitfield($user->style['bbcode_bitfield']);



if (empty($this->template_filename))
{
$this->template_bitfield = new bitfield($user->style['bbcode_bitfield']);


			$template = new phpbb\template\twig\twig($phpbb_path_helper, $config, $user, new phpbb\template\context(), $phpbb_extension_manager);




















			$template = new \phpbb\template\twig\twig(
$phpbb_container->get('path_helper'),
$phpbb_container->get('config'),
new \phpbb\template\context(),
new \phpbb\template\twig\environment(
$phpbb_container->get('config'),
$phpbb_container->get('filesystem'),
$phpbb_container->get('path_helper'),
$phpbb_container->getParameter('core.cache_dir'),
$phpbb_container->get('ext.manager'),
new \phpbb\template\twig\loader(
$phpbb_filesystem
)
),
$phpbb_container->getParameter('core.cache_dir'),
$phpbb_container->get('user'),
$phpbb_container->get('template.twig.extensions.collection'),
$phpbb_extension_manager
);


			$template->set_style();
$template->set_filenames(array('bbcode.html' => 'bbcode.html'));
$this->template_filename = $template->get_source_file_for_handle('bbcode.html');

			$template->set_style();
$template->set_filenames(array('bbcode.html' => 'bbcode.html'));
$this->template_filename = $template->get_source_file_for_handle('bbcode.html');

Line 182Line 212
			$db->sql_freeresult($result);
}


			$db->sql_freeresult($result);
}


 
		// To perform custom second pass in extension, use $this->bbcode_second_pass_by_extension()
// method which accepts variable number of parameters

		foreach ($bbcode_ids as $bbcode_id)
{
switch ($bbcode_id)
{

		foreach ($bbcode_ids as $bbcode_id)
{
switch ($bbcode_id)
{

				case 0:

				case BBCODE_ID_QUOTE:

					$this->bbcode_cache[$bbcode_id] = array(
'str' => array(
'[/quote:$uid]' => $this->bbcode_tpl('quote_close', $bbcode_id)
),
'preg' => array(

					$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')"








							'#\[quote(?:="(.*?)")?:$uid\]((?!\[quote(?:=".*?")?:$uid\]).)?#is'	=> function ($match) {
if (!isset($match[2]))
{
$match[2] = '';
}

return $this->bbcode_second_pass_quote($match[1], $match[2]);
},

						)
);
break;


						)
);
break;


				case 1:

				case BBCODE_ID_B:

					$this->bbcode_cache[$bbcode_id] = array(
'str' => array(
'[b:$uid]' => $this->bbcode_tpl('b_open', $bbcode_id),

					$this->bbcode_cache[$bbcode_id] = array(
'str' => array(
'[b:$uid]' => $this->bbcode_tpl('b_open', $bbcode_id),

Line 206Line 245
					);
break;


					);
break;


				case 2:

				case BBCODE_ID_I:

					$this->bbcode_cache[$bbcode_id] = array(
'str' => array(
'[i:$uid]' => $this->bbcode_tpl('i_open', $bbcode_id),

					$this->bbcode_cache[$bbcode_id] = array(
'str' => array(
'[i:$uid]' => $this->bbcode_tpl('i_open', $bbcode_id),

Line 215Line 254
					);
break;


					);
break;


				case 3:

				case BBCODE_ID_URL:

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

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

Line 224Line 263
					);
break;


					);
break;


				case 4:

				case BBCODE_ID_IMG:

					if ($user->optionget('viewimg'))
{
$this->bbcode_cache[$bbcode_id] = array(

					if ($user->optionget('viewimg'))
{
$this->bbcode_cache[$bbcode_id] = array(

Line 243Line 282
					}
break;


					}
break;


				case 5:

				case BBCODE_ID_SIZE:

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

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

Line 251Line 290
					);
break;


					);
break;


				case 6:

				case BBCODE_ID_COLOR:

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

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

Line 259Line 298
					);
break;


					);
break;


				case 7:

				case BBCODE_ID_U:

					$this->bbcode_cache[$bbcode_id] = array(
'str' => array(
'[u:$uid]' => $this->bbcode_tpl('u_open', $bbcode_id),

					$this->bbcode_cache[$bbcode_id] = array(
'str' => array(
'[u:$uid]' => $this->bbcode_tpl('u_open', $bbcode_id),

Line 268Line 307
					);
break;


					);
break;


				case 8:

				case BBCODE_ID_CODE:

					$this->bbcode_cache[$bbcode_id] = array(
'preg' => array(

					$this->bbcode_cache[$bbcode_id] = array(
'preg' => array(

							'#\[code(?:=([a-z]+))?:$uid\](.*?)\[/code:$uid\]#ise'	=> "\$this->bbcode_second_pass_code('\$1', '\$2')",



							'#\[code(?:=([a-z]+))?:$uid\](.*?)\[/code:$uid\]#is'	=> function ($match) {
return $this->bbcode_second_pass_code($match[1], $match[2]);
},

						)
);
break;


						)
);
break;


				case 9:

				case BBCODE_ID_LIST:

					$this->bbcode_cache[$bbcode_id] = array(
'preg' => array(
'#(\[\/?(list|\*):[mou]?:?$uid\])[\n]{1}#' => "\$1",
'#(\[list=([^\[]+):$uid\])[\n]{1}#' => "\$1",

					$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')",



							'#\[list=([^\[]+):$uid\]#'					=> function ($match) {
return $this->bbcode_list($match[1]);
},

						),
'str' => array(
'[list:$uid]' => $this->bbcode_tpl('ulist_open_default', $bbcode_id),

						),
'str' => array(
'[list:$uid]' => $this->bbcode_tpl('ulist_open_default', $bbcode_id),

Line 294Line 337
					);
break;


					);
break;


				case 10:

				case BBCODE_ID_EMAIL:

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

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

Line 303Line 346
					);
break;


					);
break;


				case 11:

				case BBCODE_ID_FLASH:

					if ($user->optionget('viewflash'))
{
$this->bbcode_cache[$bbcode_id] = array(

					if ($user->optionget('viewflash'))
{
$this->bbcode_cache[$bbcode_id] = array(

Line 322Line 365
					}
break;


					}
break;


				case 12:

				case BBCODE_ID_ATTACH:

					$this->bbcode_cache[$bbcode_id] = array(
'str' => array(
'[/attachment:$uid]' => $this->bbcode_tpl('inline_attachment_close', $bbcode_id)

					$this->bbcode_cache[$bbcode_id] = array(
'str' => array(
'[/attachment:$uid]' => $this->bbcode_tpl('inline_attachment_close', $bbcode_id)

Line 365Line 408
						}

// Replace {L_*} lang strings

						}

// Replace {L_*} lang strings

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



						$bbcode_tpl = preg_replace_callback('/{L_([A-Z0-9_]+)}/', function ($match) use ($user) {
return (!empty($user->lang[$match[1]])) ? $user->lang($match[1]) : ucwords(strtolower(str_replace('_', ' ', $match[1])));
}, $bbcode_tpl);


if (!empty($rowset[$bbcode_id]['second_pass_replace']))
{


if (!empty($rowset[$bbcode_id]['second_pass_replace']))
{

Line 388Line 433
				break;
}
}

				break;
}
}

 

$bbcode_cache = $this->bbcode_cache;
$bbcode_bitfield = $this->bbcode_bitfield;
$bbcode_uid = $this->bbcode_uid;

/**
* Use this event to modify the bbcode_cache
*
* @event core.bbcode_cache_init_end
* @var array bbcode_cache The array of cached search and replace patterns of bbcodes
* @var string bbcode_bitfield The bbcode bitfield
* @var string bbcode_uid The bbcode uid
* @since 3.1.3-RC1
*/
$vars = array('bbcode_cache', 'bbcode_bitfield', 'bbcode_uid');
extract($phpbb_dispatcher->trigger_event('core.bbcode_cache_init_end', compact($vars)));

$this->bbcode_cache = $bbcode_cache;
$this->bbcode_bitfield = $bbcode_bitfield;
$this->bbcode_uid = $bbcode_uid;

	}

/**

	}

/**

Line 469Line 534
			'email'					=> array('{EMAIL}'		=> '$1', '{DESCRIPTION}'	=> '$2')
);


			'email'					=> array('{EMAIL}'		=> '$1', '{DESCRIPTION}'	=> '$2')
);


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



		$tpl = preg_replace_callback('/{L_([A-Z0-9_]+)}/', function ($match) use ($user) {
return (!empty($user->lang[$match[1]])) ? $user->lang($match[1]) : ucwords(strtolower(str_replace('_', ' ', $match[1])));
}, $tpl);


if (!empty($replacements[$tpl_name]))
{


if (!empty($replacements[$tpl_name]))
{

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

return $code;

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

return $code;

 
	}

/**
* Function to perform custom bbcode second pass by extensions
* can be used to assign bbcode pattern replacement
* Example: '#\[list=([^\[]+):$uid\]#e' => "\$this->bbcode_second_pass_by_extension('\$1')"
*
* Accepts variable number of parameters
*
* @return mixed Second pass result
*/
function bbcode_second_pass_by_extension()
{
global $phpbb_dispatcher;

$return = false;
$params_array = func_get_args();

/**
* Event to perform bbcode second pass with
* the custom validating methods provided by extensions
*
* @event core.bbcode_second_pass_by_extension
* @var array params_array Array with the function parameters
* @var mixed return Second pass result to return
*
* @since 3.1.5-RC1
*/
$vars = array('params_array', 'return');
extract($phpbb_dispatcher->trigger_event('core.bbcode_second_pass_by_extension', compact($vars)));

return $return;

	}
}


	}
}