aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/bbcode.php
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/includes/bbcode.php')
-rw-r--r--phpBB/includes/bbcode.php87
1 files changed, 66 insertions, 21 deletions
diff --git a/phpBB/includes/bbcode.php b/phpBB/includes/bbcode.php
index 86390c0901..e8492a82a3 100644
--- a/phpBB/includes/bbcode.php
+++ b/phpBB/includes/bbcode.php
@@ -110,7 +110,18 @@ class bbcode
$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());
}
}
@@ -129,13 +140,32 @@ class bbcode
*/
function bbcode_cache_init()
{
- global $phpbb_root_path, $phpEx, $config, $user, $phpbb_dispatcher, $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']);
- $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');
@@ -188,18 +218,25 @@ class bbcode
{
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(
- '#\[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;
- case 1:
+ case BBCODE_ID_B:
$this->bbcode_cache[$bbcode_id] = array(
'str' => array(
'[b:$uid]' => $this->bbcode_tpl('b_open', $bbcode_id),
@@ -208,7 +245,7 @@ class bbcode
);
break;
- case 2:
+ case BBCODE_ID_I:
$this->bbcode_cache[$bbcode_id] = array(
'str' => array(
'[i:$uid]' => $this->bbcode_tpl('i_open', $bbcode_id),
@@ -217,7 +254,7 @@ class bbcode
);
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),
@@ -226,7 +263,7 @@ class bbcode
);
break;
- case 4:
+ case BBCODE_ID_IMG:
if ($user->optionget('viewimg'))
{
$this->bbcode_cache[$bbcode_id] = array(
@@ -245,7 +282,7 @@ class bbcode
}
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),
@@ -253,7 +290,7 @@ class bbcode
);
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),
@@ -261,7 +298,7 @@ class bbcode
);
break;
- case 7:
+ case BBCODE_ID_U:
$this->bbcode_cache[$bbcode_id] = array(
'str' => array(
'[u:$uid]' => $this->bbcode_tpl('u_open', $bbcode_id),
@@ -270,20 +307,24 @@ class bbcode
);
break;
- case 8:
+ case BBCODE_ID_CODE:
$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;
- 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",
- '#\[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),
@@ -296,7 +337,7 @@ class bbcode
);
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),
@@ -305,7 +346,7 @@ class bbcode
);
break;
- case 11:
+ case BBCODE_ID_FLASH:
if ($user->optionget('viewflash'))
{
$this->bbcode_cache[$bbcode_id] = array(
@@ -324,7 +365,7 @@ class bbcode
}
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)
@@ -367,7 +408,9 @@ class bbcode
}
// 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']))
{
@@ -491,7 +534,9 @@ class bbcode
'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]))
{