|
|
ef5584 |
|
|
|
ef5584 |
/**
|
|
|
ef5584 |
*
|
|
|
ef5584 |
* @package phpBB3
|
|
|
ef5584 |
* @version $Id: bbcode.php 8953 2008-09-28 17:08:09Z acydburn $
|
|
|
ef5584 |
* @copyright (c) 2005 phpBB Group
|
|
|
ef5584 |
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
|
ef5584 |
*
|
|
|
ef5584 |
*/
|
|
|
ef5584 |
|
|
|
ef5584 |
/**
|
|
|
ef5584 |
* @ignore
|
|
|
ef5584 |
*/
|
|
|
ef5584 |
if (!defined('IN_PHPBB'))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
exit;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
/**
|
|
|
ef5584 |
* BBCode class
|
|
|
ef5584 |
* @package phpBB3
|
|
|
ef5584 |
*/
|
|
|
ef5584 |
class bbcode
|
|
|
ef5584 |
{
|
|
|
ef5584 |
var $bbcode_uid = '';
|
|
|
ef5584 |
var $bbcode_bitfield = '';
|
|
|
ef5584 |
var $bbcode_cache = array();
|
|
|
ef5584 |
var $bbcode_template = array();
|
|
|
ef5584 |
|
|
|
ef5584 |
var $bbcodes = array();
|
|
|
ef5584 |
|
|
|
ef5584 |
var $template_bitfield;
|
|
|
ef5584 |
var $template_filename = '';
|
|
|
ef5584 |
|
|
|
ef5584 |
/**
|
|
|
ef5584 |
* Constructor
|
|
|
ef5584 |
* Init bbcode cache entries if bitfield is specified
|
|
|
ef5584 |
*/
|
|
|
ef5584 |
function bbcode($bitfield = '')
|
|
|
ef5584 |
{
|
|
|
ef5584 |
if ($bitfield)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$this->bbcode_bitfield = $bitfield;
|
|
|
ef5584 |
$this->bbcode_cache_init();
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
/**
|
|
|
ef5584 |
* Second pass bbcodes
|
|
|
ef5584 |
*/
|
|
|
ef5584 |
function bbcode_second_pass(&$message, $bbcode_uid = '', $bbcode_bitfield = false)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
if ($bbcode_uid)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$this->bbcode_uid = $bbcode_uid;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
if ($bbcode_bitfield !== false)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$this->bbcode_bitfield = $bbcode_bitfield;
|
|
|
ef5584 |
|
|
|
ef5584 |
// Init those added with a new bbcode_bitfield (already stored codes will not get parsed again)
|
|
|
ef5584 |
$this->bbcode_cache_init();
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
if (!$this->bbcode_bitfield)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
// Remove the uid from tags that have not been transformed into HTML
|
|
|
ef5584 |
if ($this->bbcode_uid)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$message = str_replace(':' . $this->bbcode_uid, '', $message);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
return;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
$str = array('search' => array(), 'replace' => array());
|
|
|
ef5584 |
$preg = array('search' => array(), 'replace' => array());
|
|
|
ef5584 |
|
|
|
ef5584 |
$bitfield = new bitfield($this->bbcode_bitfield);
|
|
|
ef5584 |
$bbcodes_set = $bitfield->get_all_set();
|
|
|
ef5584 |
|
|
|
ef5584 |
$undid_bbcode_specialchars = false;
|
|
|
ef5584 |
foreach ($bbcodes_set as $bbcode_id)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
if (!empty($this->bbcode_cache[$bbcode_id]))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
foreach ($this->bbcode_cache[$bbcode_id] as $type => $array)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
foreach ($array as $search => $replace)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
${$type}['search'][] = str_replace('$uid', $this->bbcode_uid, $search);
|
|
|
ef5584 |
${$type}['replace'][] = $replace;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
if (sizeof($str['search']))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$message = str_replace($str['search'], $str['replace'], $message);
|
|
|
ef5584 |
$str = array('search' => array(), 'replace' => array());
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
if (sizeof($preg['search']))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
// we need to turn the entities back into their original form to allow the
|
|
|
ef5584 |
// search patterns to work properly
|
|
|
ef5584 |
if (!$undid_bbcode_specialchars)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$message = str_replace(array(':', '.'), array(':', '.'), $message);
|
|
|
ef5584 |
$undid_bbcode_specialchars = true;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
$message = preg_replace($preg['search'], $preg['replace'], $message);
|
|
|
ef5584 |
$preg = array('search' => array(), 'replace' => array());
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
// Remove the uid from tags that have not been transformed into HTML
|
|
|
ef5584 |
$message = str_replace(':' . $this->bbcode_uid, '', $message);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
/**
|
|
|
ef5584 |
* Init bbcode cache
|
|
|
ef5584 |
*
|
|
|
ef5584 |
* requires: $this->bbcode_bitfield
|
|
|
ef5584 |
* sets: $this->bbcode_cache with bbcode templates needed for bbcode_bitfield
|
|
|
ef5584 |
*/
|
|
|
ef5584 |
function bbcode_cache_init()
|
|
|
ef5584 |
{
|
|
|
ef5584 |
global $user, $phpbb_root_path;
|
|
|
ef5584 |
|
|
|
ef5584 |
if (empty($this->template_filename))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$this->template_bitfield = new bitfield($user->theme['bbcode_bitfield']);
|
|
|
ef5584 |
$this->template_filename = $phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template/bbcode.html';
|
|
|
ef5584 |
|
|
|
ef5584 |
if (!@file_exists($this->template_filename))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'])
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$this->template_filename = $phpbb_root_path . 'styles/' . $user->theme['template_inherit_path'] . '/template/bbcode.html';
|
|
|
ef5584 |
if (!@file_exists($this->template_filename))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
trigger_error('The file ' . $this->template_filename . ' is missing.', E_USER_ERROR);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else
|
|
|
ef5584 |
{
|
|
|
ef5584 |
trigger_error('The file ' . $this->template_filename . ' is missing.', E_USER_ERROR);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
$bbcode_ids = $rowset = $sql = array();
|
|
|
ef5584 |
|
|
|
ef5584 |
$bitfield = new bitfield($this->bbcode_bitfield);
|
|
|
ef5584 |
$bbcodes_set = $bitfield->get_all_set();
|
|
|
ef5584 |
|
|
|
ef5584 |
foreach ($bbcodes_set as $bbcode_id)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
if (isset($this->bbcode_cache[$bbcode_id]))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
// do not try to re-cache it if it's already in
|
|
|
ef5584 |
continue;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
$bbcode_ids[] = $bbcode_id;
|
|
|
ef5584 |
|
|
|
ef5584 |
if ($bbcode_id > NUM_CORE_BBCODES)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$sql[] = $bbcode_id;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
if (sizeof($sql))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
global $db;
|
|
|
ef5584 |
|
|
|
ef5584 |
$sql = 'SELECT *
|
|
|
ef5584 |
FROM ' . BBCODES_TABLE . '
|
|
|
ef5584 |
WHERE ' . $db->sql_in_set('bbcode_id', $sql);
|
|
|
ef5584 |
$result = $db->sql_query($sql, 3600);
|
|
|
ef5584 |
|
|
|
ef5584 |
while ($row = $db->sql_fetchrow($result))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
// To circumvent replacing newlines with for the generated html,
|
|
|
ef5584 |
// we use carriage returns here. They are later changed back to newlines
|
|
|
ef5584 |
$row['bbcode_tpl'] = str_replace("\n", "\r", $row['bbcode_tpl']);
|
|
|
ef5584 |
$row['second_pass_replace'] = str_replace("\n", "\r", $row['second_pass_replace']);
|
|
|
ef5584 |
|
|
|
ef5584 |
$rowset[$row['bbcode_id']] = $row;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
$db->sql_freeresult($result);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
foreach ($bbcode_ids as $bbcode_id)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
switch ($bbcode_id)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
case 0:
|
|
|
ef5584 |
$this->bbcode_cache[$bbcode_id] = array(
|
|
|
ef5584 |
'str' => array(
|
|
|
ef5584 |
'[/quote:$uid]' => $this->bbcode_tpl('quote_close', $bbcode_id)
|
|
|
ef5584 |
),
|
|
|
ef5584 |
'preg' => array(
|
|
|
ef5584 |
'#\[quote(?:="(.*?)")?:$uid\]((?!\[quote(?:=".*?")?:$uid\]).)?#ise' => "\$this->bbcode_second_pass_quote('\$1', '\$2')"
|
|
|
ef5584 |
)
|
|
|
ef5584 |
);
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case 1:
|
|
|
ef5584 |
$this->bbcode_cache[$bbcode_id] = array(
|
|
|
ef5584 |
'str' => array(
|
|
|
ef5584 |
'[b:$uid]' => $this->bbcode_tpl('b_open', $bbcode_id),
|
|
|
ef5584 |
'[/b:$uid]' => $this->bbcode_tpl('b_close', $bbcode_id),
|
|
|
ef5584 |
)
|
|
|
ef5584 |
);
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case 2:
|
|
|
ef5584 |
$this->bbcode_cache[$bbcode_id] = array(
|
|
|
ef5584 |
'str' => array(
|
|
|
ef5584 |
'[i:$uid]' => $this->bbcode_tpl('i_open', $bbcode_id),
|
|
|
ef5584 |
'[/i:$uid]' => $this->bbcode_tpl('i_close', $bbcode_id),
|
|
|
ef5584 |
)
|
|
|
ef5584 |
);
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case 3:
|
|
|
ef5584 |
$this->bbcode_cache[$bbcode_id] = array(
|
|
|
ef5584 |
'preg' => array(
|
|
|
ef5584 |
'#\[url:$uid\]((.*?))\[/url:$uid\]#s' => $this->bbcode_tpl('url', $bbcode_id),
|
|
|
ef5584 |
'#\[url=([^\[]+?):$uid\](.*?)\[/url:$uid\]#s' => $this->bbcode_tpl('url', $bbcode_id),
|
|
|
ef5584 |
)
|
|
|
ef5584 |
);
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case 4:
|
|
|
ef5584 |
if ($user->optionget('viewimg'))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$this->bbcode_cache[$bbcode_id] = array(
|
|
|
ef5584 |
'preg' => array(
|
|
|
ef5584 |
'#\[img:$uid\](.*?)\[/img:$uid\]#s' => $this->bbcode_tpl('img', $bbcode_id),
|
|
|
ef5584 |
)
|
|
|
ef5584 |
);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$this->bbcode_cache[$bbcode_id] = array(
|
|
|
ef5584 |
'preg' => array(
|
|
|
ef5584 |
'#\[img:$uid\](.*?)\[/img:$uid\]#s' => str_replace('$2', '[ img ]', $this->bbcode_tpl('url', $bbcode_id, true)),
|
|
|
ef5584 |
)
|
|
|
ef5584 |
);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case 5:
|
|
|
ef5584 |
$this->bbcode_cache[$bbcode_id] = array(
|
|
|
ef5584 |
'preg' => array(
|
|
|
ef5584 |
'#\[size=([\-\+]?\d+):$uid\](.*?)\[/size:$uid\]#s' => $this->bbcode_tpl('size', $bbcode_id),
|
|
|
ef5584 |
)
|
|
|
ef5584 |
);
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case 6:
|
|
|
ef5584 |
$this->bbcode_cache[$bbcode_id] = array(
|
|
|
ef5584 |
'preg' => array(
|
|
|
ef5584 |
'!\[color=(#[0-9a-f]{6}|[a-z\-]+):$uid\](.*?)\[/color:$uid\]!is' => $this->bbcode_tpl('color', $bbcode_id),
|
|
|
ef5584 |
)
|
|
|
ef5584 |
);
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case 7:
|
|
|
ef5584 |
$this->bbcode_cache[$bbcode_id] = array(
|
|
|
ef5584 |
'str' => array(
|
|
|
ef5584 |
'[u:$uid]' => $this->bbcode_tpl('u_open', $bbcode_id),
|
|
|
ef5584 |
'[/u:$uid]' => $this->bbcode_tpl('u_close', $bbcode_id),
|
|
|
ef5584 |
)
|
|
|
ef5584 |
);
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case 8:
|
|
|
ef5584 |
$this->bbcode_cache[$bbcode_id] = array(
|
|
|
ef5584 |
'preg' => array(
|
|
|
ef5584 |
'#\[code(?:=([a-z]+))?:$uid\](.*?)\[/code:$uid\]#ise' => "\$this->bbcode_second_pass_code('\$1', '\$2')",
|
|
|
ef5584 |
)
|
|
|
ef5584 |
);
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case 9:
|
|
|
ef5584 |
$this->bbcode_cache[$bbcode_id] = array(
|
|
|
ef5584 |
'preg' => array(
|
|
|
ef5584 |
'#(\[\/?(list|\*):[mou]?:?$uid\])[\n]{1}#' => "\$1",
|
|
|
ef5584 |
'#(\[list=([^\[]+):$uid\])[\n]{1}#' => "\$1",
|
|
|
ef5584 |
'#\[list=([^\[]+):$uid\]#e' => "\$this->bbcode_list('\$1')",
|
|
|
ef5584 |
),
|
|
|
ef5584 |
'str' => array(
|
|
|
ef5584 |
'[list:$uid]' => $this->bbcode_tpl('ulist_open_default', $bbcode_id),
|
|
|
ef5584 |
'[/list:u:$uid]' => $this->bbcode_tpl('ulist_close', $bbcode_id),
|
|
|
ef5584 |
'[/list:o:$uid]' => $this->bbcode_tpl('olist_close', $bbcode_id),
|
|
|
ef5584 |
'[*:$uid]' => $this->bbcode_tpl('listitem', $bbcode_id),
|
|
|
ef5584 |
'[/*:$uid]' => $this->bbcode_tpl('listitem_close', $bbcode_id),
|
|
|
ef5584 |
'[/*:m:$uid]' => $this->bbcode_tpl('listitem_close', $bbcode_id)
|
|
|
ef5584 |
),
|
|
|
ef5584 |
);
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case 10:
|
|
|
ef5584 |
$this->bbcode_cache[$bbcode_id] = array(
|
|
|
ef5584 |
'preg' => array(
|
|
|
ef5584 |
'#\[email:$uid\]((.*?))\[/email:$uid\]#is' => $this->bbcode_tpl('email', $bbcode_id),
|
|
|
ef5584 |
'#\[email=([^\[]+):$uid\](.*?)\[/email:$uid\]#is' => $this->bbcode_tpl('email', $bbcode_id)
|
|
|
ef5584 |
)
|
|
|
ef5584 |
);
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case 11:
|
|
|
ef5584 |
if ($user->optionget('viewflash'))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$this->bbcode_cache[$bbcode_id] = array(
|
|
|
ef5584 |
'preg' => array(
|
|
|
ef5584 |
'#\[flash=([0-9]+),([0-9]+):$uid\](.*?)\[/flash:$uid\]#' => $this->bbcode_tpl('flash', $bbcode_id),
|
|
|
ef5584 |
)
|
|
|
ef5584 |
);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$this->bbcode_cache[$bbcode_id] = array(
|
|
|
ef5584 |
'preg' => array(
|
|
|
ef5584 |
'#\[flash=([0-9]+),([0-9]+):$uid\](.*?)\[/flash:$uid\]#' => str_replace('$1', '$3', str_replace('$2', '[ flash ]', $this->bbcode_tpl('url', $bbcode_id, true)))
|
|
|
ef5584 |
)
|
|
|
ef5584 |
);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case 12:
|
|
|
ef5584 |
$this->bbcode_cache[$bbcode_id] = array(
|
|
|
ef5584 |
'str' => array(
|
|
|
ef5584 |
'[/attachment:$uid]' => $this->bbcode_tpl('inline_attachment_close', $bbcode_id)
|
|
|
ef5584 |
),
|
|
|
ef5584 |
'preg' => array(
|
|
|
ef5584 |
'#\[attachment=([0-9]+):$uid\]#' => $this->bbcode_tpl('inline_attachment_open', $bbcode_id)
|
|
|
ef5584 |
)
|
|
|
ef5584 |
);
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
default:
|
|
|
ef5584 |
if (isset($rowset[$bbcode_id]))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
if ($this->template_bitfield->get($bbcode_id))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
// The bbcode requires a custom template to be loaded
|
|
|
ef5584 |
if (!$bbcode_tpl = $this->bbcode_tpl($rowset[$bbcode_id]['bbcode_tag'], $bbcode_id))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
// For some reason, the required template seems not to be available, use the default template
|
|
|
ef5584 |
$bbcode_tpl = (!empty($rowset[$bbcode_id]['second_pass_replace'])) ? $rowset[$bbcode_id]['second_pass_replace'] : $rowset[$bbcode_id]['bbcode_tpl'];
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else
|
|
|
ef5584 |
{
|
|
|
ef5584 |
// In order to use templates with custom bbcodes we need
|
|
|
ef5584 |
// to replace all {VARS} to corresponding backreferences
|
|
|
ef5584 |
// Note that backreferences are numbered from bbcode_match
|
|
|
ef5584 |
if (preg_match_all('/\{(URL|LOCAL_URL|EMAIL|TEXT|SIMPLETEXT|IDENTIFIER|COLOR|NUMBER)[0-9]*\}/', $rowset[$bbcode_id]['bbcode_match'], $m))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
foreach ($m[0] as $i => $tok)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$bbcode_tpl = str_replace($tok, '$' . ($i + 1), $bbcode_tpl);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else
|
|
|
ef5584 |
{
|
|
|
ef5584 |
// Default template
|
|
|
ef5584 |
$bbcode_tpl = (!empty($rowset[$bbcode_id]['second_pass_replace'])) ? $rowset[$bbcode_id]['second_pass_replace'] : $rowset[$bbcode_id]['bbcode_tpl'];
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
// Replace {L_*} lang strings
|
|
|
ef5584 |
$bbcode_tpl = preg_replace('/{L_([A-Z_]+)}/e', "(!empty(\$user->lang['\$1'])) ? \$user->lang['\$1'] : ucwords(strtolower(str_replace('_', ' ', '\$1')))", $bbcode_tpl);
|
|
|
ef5584 |
|
|
|
ef5584 |
if (!empty($rowset[$bbcode_id]['second_pass_replace']))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
// The custom BBCode requires second-pass pattern replacements
|
|
|
ef5584 |
$this->bbcode_cache[$bbcode_id] = array(
|
|
|
ef5584 |
'preg' => array($rowset[$bbcode_id]['second_pass_match'] => $bbcode_tpl)
|
|
|
ef5584 |
);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$this->bbcode_cache[$bbcode_id] = array(
|
|
|
ef5584 |
'str' => array($rowset[$bbcode_id]['second_pass_match'] => $bbcode_tpl)
|
|
|
ef5584 |
);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$this->bbcode_cache[$bbcode_id] = false;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
/**
|
|
|
ef5584 |
* Return bbcode template
|
|
|
ef5584 |
*/
|
|
|
ef5584 |
function bbcode_tpl($tpl_name, $bbcode_id = -1, $skip_bitfield_check = false)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
static $bbcode_hardtpl = array();
|
|
|
ef5584 |
if (empty($bbcode_hardtpl))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
global $user;
|
|
|
ef5584 |
|
|
|
ef5584 |
$bbcode_hardtpl = array(
|
|
|
ef5584 |
'b_open' => '',
|
|
|
ef5584 |
'b_close' => '',
|
|
|
ef5584 |
'i_open' => '',
|
|
|
ef5584 |
'i_close' => '',
|
|
|
ef5584 |
'u_open' => '',
|
|
|
ef5584 |
'u_close' => '',
|
|
|
ef5584 |
'img' => '',
|
|
|
ef5584 |
'size' => '$2',
|
|
|
ef5584 |
'color' => '$2',
|
|
|
ef5584 |
'email' => '$2'
|
|
|
ef5584 |
);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
if ($bbcode_id != -1 && !$skip_bitfield_check && !$this->template_bitfield->get($bbcode_id))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
return (isset($bbcode_hardtpl[$tpl_name])) ? $bbcode_hardtpl[$tpl_name] : false;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
if (empty($this->bbcode_template))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
if (($tpl = file_get_contents($this->template_filename)) === false)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
trigger_error('Could not load bbcode template', E_USER_ERROR);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
// replace \ with \\ and then ' with \'.
|
|
|
ef5584 |
$tpl = str_replace('\\', '\\\\', $tpl);
|
|
|
ef5584 |
$tpl = str_replace("'", "\'", $tpl);
|
|
|
ef5584 |
|
|
|
ef5584 |
// strip newlines and indent
|
|
|
ef5584 |
$tpl = preg_replace("/\n[\n\r\s\t]*/", '', $tpl);
|
|
|
ef5584 |
|
|
|
ef5584 |
// Turn template blocks into PHP assignment statements for the values of $bbcode_tpl..
|
|
|
ef5584 |
$this->bbcode_template = array();
|
|
|
ef5584 |
|
|
|
ef5584 |
$matches = preg_match_all('#(.*?)#', $tpl, $match);
|
|
|
ef5584 |
|
|
|
ef5584 |
for ($i = 0; $i < $matches; $i++)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
if (empty($match[1][$i]))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
continue;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
$this->bbcode_template[$match[1][$i]] = $this->bbcode_tpl_replace($match[1][$i], $match[2][$i]);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
return (isset($this->bbcode_template[$tpl_name])) ? $this->bbcode_template[$tpl_name] : ((isset($bbcode_hardtpl[$tpl_name])) ? $bbcode_hardtpl[$tpl_name] : false);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
/**
|
|
|
ef5584 |
* Return bbcode template replacement
|
|
|
ef5584 |
*/
|
|
|
ef5584 |
function bbcode_tpl_replace($tpl_name, $tpl)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
global $user;
|
|
|
ef5584 |
|
|
|
ef5584 |
static $replacements = array(
|
|
|
ef5584 |
'quote_username_open' => array('{USERNAME}' => '$1'),
|
|
|
ef5584 |
'color' => array('{COLOR}' => '$1', '{TEXT}' => '$2'),
|
|
|
ef5584 |
'size' => array('{SIZE}' => '$1', '{TEXT}' => '$2'),
|
|
|
ef5584 |
'img' => array('{URL}' => '$1'),
|
|
|
ef5584 |
'flash' => array('{WIDTH}' => '$1', '{HEIGHT}' => '$2', '{URL}' => '$3'),
|
|
|
ef5584 |
'url' => array('{URL}' => '$1', '{DESCRIPTION}' => '$2'),
|
|
|
ef5584 |
'email' => array('{EMAIL}' => '$1', '{DESCRIPTION}' => '$2')
|
|
|
ef5584 |
);
|
|
|
ef5584 |
|
|
|
ef5584 |
$tpl = preg_replace('/{L_([A-Z_]+)}/e', "(!empty(\$user->lang['\$1'])) ? \$user->lang['\$1'] : ucwords(strtolower(str_replace('_', ' ', '\$1')))", $tpl);
|
|
|
ef5584 |
|
|
|
ef5584 |
if (!empty($replacements[$tpl_name]))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$tpl = strtr($tpl, $replacements[$tpl_name]);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
return trim($tpl);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
/**
|
|
|
ef5584 |
* Second parse list bbcode
|
|
|
ef5584 |
*/
|
|
|
ef5584 |
function bbcode_list($type)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
if ($type == '')
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$tpl = 'ulist_open_default';
|
|
|
ef5584 |
$type = 'default';
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else if ($type == 'i')
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$tpl = 'olist_open';
|
|
|
ef5584 |
$type = 'lower-roman';
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else if ($type == 'I')
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$tpl = 'olist_open';
|
|
|
ef5584 |
$type = 'upper-roman';
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else if (preg_match('#^(disc|circle|square)$#i', $type))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$tpl = 'ulist_open';
|
|
|
ef5584 |
$type = strtolower($type);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else if (preg_match('#^[a-z]$#', $type))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$tpl = 'olist_open';
|
|
|
ef5584 |
$type = 'lower-alpha';
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else if (preg_match('#[A-Z]#', $type))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$tpl = 'olist_open';
|
|
|
ef5584 |
$type = 'upper-alpha';
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else if (is_numeric($type))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$tpl = 'olist_open';
|
|
|
ef5584 |
$type = 'arabic-numbers';
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$tpl = 'olist_open';
|
|
|
ef5584 |
$type = 'arabic-numbers';
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
return str_replace('{LIST_TYPE}', $type, $this->bbcode_tpl($tpl));
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
/**
|
|
|
ef5584 |
* Second parse quote tag
|
|
|
ef5584 |
*/
|
|
|
ef5584 |
function bbcode_second_pass_quote($username, $quote)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
// when using the /e modifier, preg_replace slashes double-quotes but does not
|
|
|
ef5584 |
// seem to slash anything else
|
|
|
ef5584 |
$quote = str_replace('\"', '"', $quote);
|
|
|
ef5584 |
$username = str_replace('\"', '"', $username);
|
|
|
ef5584 |
|
|
|
ef5584 |
// remove newline at the beginning
|
|
|
ef5584 |
if ($quote == "\n")
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$quote = '';
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
$quote = (($username) ? str_replace('$1', $username, $this->bbcode_tpl('quote_username_open')) : $this->bbcode_tpl('quote_open')) . $quote;
|
|
|
ef5584 |
|
|
|
ef5584 |
return $quote;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
/**
|
|
|
ef5584 |
* Second parse code tag
|
|
|
ef5584 |
*/
|
|
|
ef5584 |
function bbcode_second_pass_code($type, $code)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
// when using the /e modifier, preg_replace slashes double-quotes but does not
|
|
|
ef5584 |
// seem to slash anything else
|
|
|
ef5584 |
$code = str_replace('\"', '"', $code);
|
|
|
ef5584 |
|
|
|
ef5584 |
switch ($type)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
case 'php':
|
|
|
ef5584 |
// Not the english way, but valid because of hardcoded syntax highlighting
|
|
|
ef5584 |
if (strpos($code, ' ') === 0)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$code = substr($code, 41);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
// no break;
|
|
|
ef5584 |
|
|
|
ef5584 |
default:
|
|
|
ef5584 |
$code = str_replace("\t", ' ', $code);
|
|
|
ef5584 |
$code = str_replace(' ', ' ', $code);
|
|
|
ef5584 |
$code = str_replace(' ', ' ', $code);
|
|
|
ef5584 |
|
|
|
ef5584 |
// remove newline at the beginning
|
|
|
ef5584 |
if (!empty($code) && $code[0] == "\n")
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$code = substr($code, 1);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
$code = $this->bbcode_tpl('code_open') . $code . $this->bbcode_tpl('code_close');
|
|
|
ef5584 |
|
|
|
ef5584 |
return $code;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
?>
|