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