1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/includes/bbcode.php Wed Mar 07 16:41:10 2012 +0400
1.3 @@ -0,0 +1,609 @@
1.4 +<?php
1.5 +/**
1.6 +*
1.7 +* @package phpBB3
1.8 +* @version $Id$
1.9 +* @copyright (c) 2005 phpBB Group
1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
1.11 +*
1.12 +*/
1.13 +
1.14 +/**
1.15 +* @ignore
1.16 +*/
1.17 +if (!defined('IN_PHPBB'))
1.18 +{
1.19 + exit;
1.20 +}
1.21 +
1.22 +/**
1.23 +* BBCode class
1.24 +* @package phpBB3
1.25 +*/
1.26 +class bbcode
1.27 +{
1.28 + var $bbcode_uid = '';
1.29 + var $bbcode_bitfield = '';
1.30 + var $bbcode_cache = array();
1.31 + var $bbcode_template = array();
1.32 +
1.33 + var $bbcodes = array();
1.34 +
1.35 + var $template_bitfield;
1.36 + var $template_filename = '';
1.37 +
1.38 + /**
1.39 + * Constructor
1.40 + * Init bbcode cache entries if bitfield is specified
1.41 + */
1.42 + function bbcode($bitfield = '')
1.43 + {
1.44 + if ($bitfield)
1.45 + {
1.46 + $this->bbcode_bitfield = $bitfield;
1.47 + $this->bbcode_cache_init();
1.48 + }
1.49 + }
1.50 +
1.51 + /**
1.52 + * Second pass bbcodes
1.53 + */
1.54 + function bbcode_second_pass(&$message, $bbcode_uid = '', $bbcode_bitfield = false)
1.55 + {
1.56 + if ($bbcode_uid)
1.57 + {
1.58 + $this->bbcode_uid = $bbcode_uid;
1.59 + }
1.60 +
1.61 + if ($bbcode_bitfield !== false)
1.62 + {
1.63 + $this->bbcode_bitfield = $bbcode_bitfield;
1.64 +
1.65 + // Init those added with a new bbcode_bitfield (already stored codes will not get parsed again)
1.66 + $this->bbcode_cache_init();
1.67 + }
1.68 +
1.69 + if (!$this->bbcode_bitfield)
1.70 + {
1.71 + // Remove the uid from tags that have not been transformed into HTML
1.72 + if ($this->bbcode_uid)
1.73 + {
1.74 + $message = str_replace(':' . $this->bbcode_uid, '', $message);
1.75 + }
1.76 +
1.77 + return;
1.78 + }
1.79 +
1.80 + $str = array('search' => array(), 'replace' => array());
1.81 + $preg = array('search' => array(), 'replace' => array());
1.82 +
1.83 + $bitfield = new bitfield($this->bbcode_bitfield);
1.84 + $bbcodes_set = $bitfield->get_all_set();
1.85 +
1.86 + $undid_bbcode_specialchars = false;
1.87 + foreach ($bbcodes_set as $bbcode_id)
1.88 + {
1.89 + if (!empty($this->bbcode_cache[$bbcode_id]))
1.90 + {
1.91 + foreach ($this->bbcode_cache[$bbcode_id] as $type => $array)
1.92 + {
1.93 + foreach ($array as $search => $replace)
1.94 + {
1.95 + ${$type}['search'][] = str_replace('$uid', $this->bbcode_uid, $search);
1.96 + ${$type}['replace'][] = $replace;
1.97 + }
1.98 +
1.99 + if (sizeof($str['search']))
1.100 + {
1.101 + $message = str_replace($str['search'], $str['replace'], $message);
1.102 + $str = array('search' => array(), 'replace' => array());
1.103 + }
1.104 +
1.105 + if (sizeof($preg['search']))
1.106 + {
1.107 + // we need to turn the entities back into their original form to allow the
1.108 + // search patterns to work properly
1.109 + if (!$undid_bbcode_specialchars)
1.110 + {
1.111 + $message = str_replace(array(':', '.'), array(':', '.'), $message);
1.112 + $undid_bbcode_specialchars = true;
1.113 + }
1.114 +
1.115 + $message = preg_replace($preg['search'], $preg['replace'], $message);
1.116 + $preg = array('search' => array(), 'replace' => array());
1.117 + }
1.118 + }
1.119 + }
1.120 + }
1.121 +
1.122 + // Remove the uid from tags that have not been transformed into HTML
1.123 + $message = str_replace(':' . $this->bbcode_uid, '', $message);
1.124 + }
1.125 +
1.126 + /**
1.127 + * Init bbcode cache
1.128 + *
1.129 + * requires: $this->bbcode_bitfield
1.130 + * sets: $this->bbcode_cache with bbcode templates needed for bbcode_bitfield
1.131 + */
1.132 + function bbcode_cache_init()
1.133 + {
1.134 + global $phpbb_root_path, $template, $user;
1.135 +
1.136 + if (empty($this->template_filename))
1.137 + {
1.138 + $this->template_bitfield = new bitfield($user->theme['bbcode_bitfield']);
1.139 + $this->template_filename = $phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template/bbcode.html';
1.140 +
1.141 + if (!@file_exists($this->template_filename))
1.142 + {
1.143 + if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'])
1.144 + {
1.145 + $this->template_filename = $phpbb_root_path . 'styles/' . $user->theme['template_inherit_path'] . '/template/bbcode.html';
1.146 + if (!@file_exists($this->template_filename))
1.147 + {
1.148 + trigger_error('The file ' . $this->template_filename . ' is missing.', E_USER_ERROR);
1.149 + }
1.150 + }
1.151 + else
1.152 + {
1.153 + trigger_error('The file ' . $this->template_filename . ' is missing.', E_USER_ERROR);
1.154 + }
1.155 + }
1.156 + }
1.157 +
1.158 + $bbcode_ids = $rowset = $sql = array();
1.159 +
1.160 + $bitfield = new bitfield($this->bbcode_bitfield);
1.161 + $bbcodes_set = $bitfield->get_all_set();
1.162 +
1.163 + foreach ($bbcodes_set as $bbcode_id)
1.164 + {
1.165 + if (isset($this->bbcode_cache[$bbcode_id]))
1.166 + {
1.167 + // do not try to re-cache it if it's already in
1.168 + continue;
1.169 + }
1.170 + $bbcode_ids[] = $bbcode_id;
1.171 +
1.172 + if ($bbcode_id > NUM_CORE_BBCODES)
1.173 + {
1.174 + $sql[] = $bbcode_id;
1.175 + }
1.176 + }
1.177 +
1.178 + if (sizeof($sql))
1.179 + {
1.180 + global $db;
1.181 +
1.182 + $sql = 'SELECT *
1.183 + FROM ' . BBCODES_TABLE . '
1.184 + WHERE ' . $db->sql_in_set('bbcode_id', $sql);
1.185 + $result = $db->sql_query($sql, 3600);
1.186 +
1.187 + while ($row = $db->sql_fetchrow($result))
1.188 + {
1.189 + // To circumvent replacing newlines with <br /> for the generated html,
1.190 + // we use carriage returns here. They are later changed back to newlines
1.191 + $row['bbcode_tpl'] = str_replace("\n", "\r", $row['bbcode_tpl']);
1.192 + $row['second_pass_replace'] = str_replace("\n", "\r", $row['second_pass_replace']);
1.193 +
1.194 + $rowset[$row['bbcode_id']] = $row;
1.195 + }
1.196 + $db->sql_freeresult($result);
1.197 + }
1.198 +
1.199 + foreach ($bbcode_ids as $bbcode_id)
1.200 + {
1.201 + switch ($bbcode_id)
1.202 + {
1.203 + case 0:
1.204 + $this->bbcode_cache[$bbcode_id] = array(
1.205 + 'str' => array(
1.206 + '[/quote:$uid]' => $this->bbcode_tpl('quote_close', $bbcode_id)
1.207 + ),
1.208 + 'preg' => array(
1.209 + '#\[quote(?:="(.*?)")?:$uid\]((?!\[quote(?:=".*?")?:$uid\]).)?#ise' => "\$this->bbcode_second_pass_quote('\$1', '\$2')"
1.210 + )
1.211 + );
1.212 + break;
1.213 +
1.214 + case 1:
1.215 + $this->bbcode_cache[$bbcode_id] = array(
1.216 + 'str' => array(
1.217 + '[b:$uid]' => $this->bbcode_tpl('b_open', $bbcode_id),
1.218 + '[/b:$uid]' => $this->bbcode_tpl('b_close', $bbcode_id),
1.219 + )
1.220 + );
1.221 + break;
1.222 +
1.223 + case 2:
1.224 + $this->bbcode_cache[$bbcode_id] = array(
1.225 + 'str' => array(
1.226 + '[i:$uid]' => $this->bbcode_tpl('i_open', $bbcode_id),
1.227 + '[/i:$uid]' => $this->bbcode_tpl('i_close', $bbcode_id),
1.228 + )
1.229 + );
1.230 + break;
1.231 +
1.232 + case 3:
1.233 + $this->bbcode_cache[$bbcode_id] = array(
1.234 + 'preg' => array(
1.235 + '#\[url:$uid\]((.*?))\[/url:$uid\]#s' => $this->bbcode_tpl('url', $bbcode_id),
1.236 + '#\[url=([^\[]+?):$uid\](.*?)\[/url:$uid\]#s' => $this->bbcode_tpl('url', $bbcode_id),
1.237 + )
1.238 + );
1.239 + break;
1.240 +
1.241 + case 4:
1.242 + if ($user->optionget('viewimg'))
1.243 + {
1.244 + $this->bbcode_cache[$bbcode_id] = array(
1.245 + 'preg' => array(
1.246 + '#\[img:$uid\](.*?)\[/img:$uid\]#s' => $this->bbcode_tpl('img', $bbcode_id),
1.247 + )
1.248 + );
1.249 + }
1.250 + else
1.251 + {
1.252 + $this->bbcode_cache[$bbcode_id] = array(
1.253 + 'preg' => array(
1.254 + '#\[img:$uid\](.*?)\[/img:$uid\]#s' => str_replace('$2', '[ img ]', $this->bbcode_tpl('url', $bbcode_id, true)),
1.255 + )
1.256 + );
1.257 + }
1.258 + break;
1.259 +
1.260 + case 5:
1.261 + $this->bbcode_cache[$bbcode_id] = array(
1.262 + 'preg' => array(
1.263 + '#\[size=([\-\+]?\d+):$uid\](.*?)\[/size:$uid\]#s' => $this->bbcode_tpl('size', $bbcode_id),
1.264 + )
1.265 + );
1.266 + break;
1.267 +
1.268 + case 6:
1.269 + $this->bbcode_cache[$bbcode_id] = array(
1.270 + 'preg' => array(
1.271 + '!\[color=(#[0-9a-f]{3}|#[0-9a-f]{6}|[a-z\-]+):$uid\](.*?)\[/color:$uid\]!is' => $this->bbcode_tpl('color', $bbcode_id),
1.272 + )
1.273 + );
1.274 + break;
1.275 +
1.276 + case 7:
1.277 + $this->bbcode_cache[$bbcode_id] = array(
1.278 + 'str' => array(
1.279 + '[u:$uid]' => $this->bbcode_tpl('u_open', $bbcode_id),
1.280 + '[/u:$uid]' => $this->bbcode_tpl('u_close', $bbcode_id),
1.281 + )
1.282 + );
1.283 + break;
1.284 +
1.285 + case 8:
1.286 + $this->bbcode_cache[$bbcode_id] = array(
1.287 + 'preg' => array(
1.288 + '#\[code(?:=([a-z]+))?:$uid\](.*?)\[/code:$uid\]#ise' => "\$this->bbcode_second_pass_code('\$1', '\$2')",
1.289 + )
1.290 + );
1.291 + break;
1.292 +
1.293 + case 9:
1.294 + $this->bbcode_cache[$bbcode_id] = array(
1.295 + 'preg' => array(
1.296 + '#(\[\/?(list|\*):[mou]?:?$uid\])[\n]{1}#' => "\$1",
1.297 + '#(\[list=([^\[]+):$uid\])[\n]{1}#' => "\$1",
1.298 + '#\[list=([^\[]+):$uid\]#e' => "\$this->bbcode_list('\$1')",
1.299 + ),
1.300 + 'str' => array(
1.301 + '[list:$uid]' => $this->bbcode_tpl('ulist_open_default', $bbcode_id),
1.302 + '[/list:u:$uid]' => $this->bbcode_tpl('ulist_close', $bbcode_id),
1.303 + '[/list:o:$uid]' => $this->bbcode_tpl('olist_close', $bbcode_id),
1.304 + '[*:$uid]' => $this->bbcode_tpl('listitem', $bbcode_id),
1.305 + '[/*:$uid]' => $this->bbcode_tpl('listitem_close', $bbcode_id),
1.306 + '[/*:m:$uid]' => $this->bbcode_tpl('listitem_close', $bbcode_id)
1.307 + ),
1.308 + );
1.309 + break;
1.310 +
1.311 + case 10:
1.312 + $this->bbcode_cache[$bbcode_id] = array(
1.313 + 'preg' => array(
1.314 + '#\[email:$uid\]((.*?))\[/email:$uid\]#is' => $this->bbcode_tpl('email', $bbcode_id),
1.315 + '#\[email=([^\[]+):$uid\](.*?)\[/email:$uid\]#is' => $this->bbcode_tpl('email', $bbcode_id)
1.316 + )
1.317 + );
1.318 + break;
1.319 +
1.320 + case 11:
1.321 + if ($user->optionget('viewflash'))
1.322 + {
1.323 + $this->bbcode_cache[$bbcode_id] = array(
1.324 + 'preg' => array(
1.325 + '#\[flash=([0-9]+),([0-9]+):$uid\](.*?)\[/flash:$uid\]#' => $this->bbcode_tpl('flash', $bbcode_id),
1.326 + )
1.327 + );
1.328 + }
1.329 + else
1.330 + {
1.331 + $this->bbcode_cache[$bbcode_id] = array(
1.332 + 'preg' => array(
1.333 + '#\[flash=([0-9]+),([0-9]+):$uid\](.*?)\[/flash:$uid\]#' => str_replace('$1', '$3', str_replace('$2', '[ flash ]', $this->bbcode_tpl('url', $bbcode_id, true)))
1.334 + )
1.335 + );
1.336 + }
1.337 + break;
1.338 +
1.339 + case 12:
1.340 + $this->bbcode_cache[$bbcode_id] = array(
1.341 + 'str' => array(
1.342 + '[/attachment:$uid]' => $this->bbcode_tpl('inline_attachment_close', $bbcode_id)
1.343 + ),
1.344 + 'preg' => array(
1.345 + '#\[attachment=([0-9]+):$uid\]#' => $this->bbcode_tpl('inline_attachment_open', $bbcode_id)
1.346 + )
1.347 + );
1.348 + break;
1.349 +
1.350 + default:
1.351 + if (isset($rowset[$bbcode_id]))
1.352 + {
1.353 + if ($this->template_bitfield->get($bbcode_id))
1.354 + {
1.355 + // The bbcode requires a custom template to be loaded
1.356 + if (!$bbcode_tpl = $this->bbcode_tpl($rowset[$bbcode_id]['bbcode_tag'], $bbcode_id))
1.357 + {
1.358 + // For some reason, the required template seems not to be available, use the default template
1.359 + $bbcode_tpl = (!empty($rowset[$bbcode_id]['second_pass_replace'])) ? $rowset[$bbcode_id]['second_pass_replace'] : $rowset[$bbcode_id]['bbcode_tpl'];
1.360 + }
1.361 + else
1.362 + {
1.363 + // In order to use templates with custom bbcodes we need
1.364 + // to replace all {VARS} to corresponding backreferences
1.365 + // Note that backreferences are numbered from bbcode_match
1.366 + if (preg_match_all('/\{(URL|LOCAL_URL|EMAIL|TEXT|SIMPLETEXT|INTTEXT|IDENTIFIER|COLOR|NUMBER)[0-9]*\}/', $rowset[$bbcode_id]['bbcode_match'], $m))
1.367 + {
1.368 + foreach ($m[0] as $i => $tok)
1.369 + {
1.370 + $bbcode_tpl = str_replace($tok, '$' . ($i + 1), $bbcode_tpl);
1.371 + }
1.372 + }
1.373 + }
1.374 + }
1.375 + else
1.376 + {
1.377 + // Default template
1.378 + $bbcode_tpl = (!empty($rowset[$bbcode_id]['second_pass_replace'])) ? $rowset[$bbcode_id]['second_pass_replace'] : $rowset[$bbcode_id]['bbcode_tpl'];
1.379 + }
1.380 +
1.381 + // Replace {L_*} lang strings
1.382 + $bbcode_tpl = preg_replace('/{L_([A-Z_]+)}/e', "(!empty(\$user->lang['\$1'])) ? \$user->lang['\$1'] : ucwords(strtolower(str_replace('_', ' ', '\$1')))", $bbcode_tpl);
1.383 +
1.384 + if (!empty($rowset[$bbcode_id]['second_pass_replace']))
1.385 + {
1.386 + // The custom BBCode requires second-pass pattern replacements
1.387 + $this->bbcode_cache[$bbcode_id] = array(
1.388 + 'preg' => array($rowset[$bbcode_id]['second_pass_match'] => $bbcode_tpl)
1.389 + );
1.390 + }
1.391 + else
1.392 + {
1.393 + $this->bbcode_cache[$bbcode_id] = array(
1.394 + 'str' => array($rowset[$bbcode_id]['second_pass_match'] => $bbcode_tpl)
1.395 + );
1.396 + }
1.397 + }
1.398 + else
1.399 + {
1.400 + $this->bbcode_cache[$bbcode_id] = false;
1.401 + }
1.402 + break;
1.403 + }
1.404 + }
1.405 + }
1.406 +
1.407 + /**
1.408 + * Return bbcode template
1.409 + */
1.410 + function bbcode_tpl($tpl_name, $bbcode_id = -1, $skip_bitfield_check = false)
1.411 + {
1.412 + static $bbcode_hardtpl = array();
1.413 + if (empty($bbcode_hardtpl))
1.414 + {
1.415 + global $user;
1.416 +
1.417 + $bbcode_hardtpl = array(
1.418 + 'b_open' => '<span style="font-weight: bold">',
1.419 + 'b_close' => '</span>',
1.420 + 'i_open' => '<span style="font-style: italic">',
1.421 + 'i_close' => '</span>',
1.422 + 'u_open' => '<span style="text-decoration: underline">',
1.423 + 'u_close' => '</span>',
1.424 + 'img' => '<img src="$1" alt="' . $user->lang['IMAGE'] . '" />',
1.425 + 'size' => '<span style="font-size: $1%; line-height: normal">$2</span>',
1.426 + 'color' => '<span style="color: $1">$2</span>',
1.427 + 'email' => '<a href="mailto:$1">$2</a>'
1.428 + );
1.429 + }
1.430 +
1.431 + if ($bbcode_id != -1 && !$skip_bitfield_check && !$this->template_bitfield->get($bbcode_id))
1.432 + {
1.433 + return (isset($bbcode_hardtpl[$tpl_name])) ? $bbcode_hardtpl[$tpl_name] : false;
1.434 + }
1.435 +
1.436 + if (empty($this->bbcode_template))
1.437 + {
1.438 + if (($tpl = file_get_contents($this->template_filename)) === false)
1.439 + {
1.440 + trigger_error('Could not load bbcode template', E_USER_ERROR);
1.441 + }
1.442 +
1.443 + // replace \ with \\ and then ' with \'.
1.444 + $tpl = str_replace('\\', '\\\\', $tpl);
1.445 + $tpl = str_replace("'", "\'", $tpl);
1.446 +
1.447 + // strip newlines and indent
1.448 + $tpl = preg_replace("/\n[\n\r\s\t]*/", '', $tpl);
1.449 +
1.450 + // Turn template blocks into PHP assignment statements for the values of $bbcode_tpl..
1.451 + $this->bbcode_template = array();
1.452 +
1.453 + $matches = preg_match_all('#<!-- BEGIN (.*?) -->(.*?)<!-- END (?:.*?) -->#', $tpl, $match);
1.454 +
1.455 + for ($i = 0; $i < $matches; $i++)
1.456 + {
1.457 + if (empty($match[1][$i]))
1.458 + {
1.459 + continue;
1.460 + }
1.461 +
1.462 + $this->bbcode_template[$match[1][$i]] = $this->bbcode_tpl_replace($match[1][$i], $match[2][$i]);
1.463 + }
1.464 + }
1.465 +
1.466 + return (isset($this->bbcode_template[$tpl_name])) ? $this->bbcode_template[$tpl_name] : ((isset($bbcode_hardtpl[$tpl_name])) ? $bbcode_hardtpl[$tpl_name] : false);
1.467 + }
1.468 +
1.469 + /**
1.470 + * Return bbcode template replacement
1.471 + */
1.472 + function bbcode_tpl_replace($tpl_name, $tpl)
1.473 + {
1.474 + global $user;
1.475 +
1.476 + static $replacements = array(
1.477 + 'quote_username_open' => array('{USERNAME}' => '$1'),
1.478 + 'color' => array('{COLOR}' => '$1', '{TEXT}' => '$2'),
1.479 + 'size' => array('{SIZE}' => '$1', '{TEXT}' => '$2'),
1.480 + 'img' => array('{URL}' => '$1'),
1.481 + 'flash' => array('{WIDTH}' => '$1', '{HEIGHT}' => '$2', '{URL}' => '$3'),
1.482 + 'url' => array('{URL}' => '$1', '{DESCRIPTION}' => '$2'),
1.483 + 'email' => array('{EMAIL}' => '$1', '{DESCRIPTION}' => '$2')
1.484 + );
1.485 +
1.486 + $tpl = preg_replace('/{L_([A-Z_]+)}/e', "(!empty(\$user->lang['\$1'])) ? \$user->lang['\$1'] : ucwords(strtolower(str_replace('_', ' ', '\$1')))", $tpl);
1.487 +
1.488 + if (!empty($replacements[$tpl_name]))
1.489 + {
1.490 + $tpl = strtr($tpl, $replacements[$tpl_name]);
1.491 + }
1.492 +
1.493 + return trim($tpl);
1.494 + }
1.495 +
1.496 + /**
1.497 + * Second parse list bbcode
1.498 + */
1.499 + function bbcode_list($type)
1.500 + {
1.501 + if ($type == '')
1.502 + {
1.503 + $tpl = 'ulist_open_default';
1.504 + $type = 'default';
1.505 + }
1.506 + else if ($type == 'i')
1.507 + {
1.508 + $tpl = 'olist_open';
1.509 + $type = 'lower-roman';
1.510 + }
1.511 + else if ($type == 'I')
1.512 + {
1.513 + $tpl = 'olist_open';
1.514 + $type = 'upper-roman';
1.515 + }
1.516 + else if (preg_match('#^(disc|circle|square)$#i', $type))
1.517 + {
1.518 + $tpl = 'ulist_open';
1.519 + $type = strtolower($type);
1.520 + }
1.521 + else if (preg_match('#^[a-z]$#', $type))
1.522 + {
1.523 + $tpl = 'olist_open';
1.524 + $type = 'lower-alpha';
1.525 + }
1.526 + else if (preg_match('#[A-Z]#', $type))
1.527 + {
1.528 + $tpl = 'olist_open';
1.529 + $type = 'upper-alpha';
1.530 + }
1.531 + else if (is_numeric($type))
1.532 + {
1.533 + $tpl = 'olist_open';
1.534 + $type = 'decimal';
1.535 + }
1.536 + else
1.537 + {
1.538 + $tpl = 'olist_open';
1.539 + $type = 'decimal';
1.540 + }
1.541 +
1.542 + return str_replace('{LIST_TYPE}', $type, $this->bbcode_tpl($tpl));
1.543 + }
1.544 +
1.545 + /**
1.546 + * Second parse quote tag
1.547 + */
1.548 + function bbcode_second_pass_quote($username, $quote)
1.549 + {
1.550 + // when using the /e modifier, preg_replace slashes double-quotes but does not
1.551 + // seem to slash anything else
1.552 + $quote = str_replace('\"', '"', $quote);
1.553 + $username = str_replace('\"', '"', $username);
1.554 +
1.555 + // remove newline at the beginning
1.556 + if ($quote == "\n")
1.557 + {
1.558 + $quote = '';
1.559 + }
1.560 +
1.561 + $quote = (($username) ? str_replace('$1', $username, $this->bbcode_tpl('quote_username_open')) : $this->bbcode_tpl('quote_open')) . $quote;
1.562 +
1.563 + return $quote;
1.564 + }
1.565 +
1.566 + /**
1.567 + * Second parse code tag
1.568 + */
1.569 + function bbcode_second_pass_code($type, $code)
1.570 + {
1.571 + // when using the /e modifier, preg_replace slashes double-quotes but does not
1.572 + // seem to slash anything else
1.573 + $code = str_replace('\"', '"', $code);
1.574 +
1.575 + switch ($type)
1.576 + {
1.577 + case 'php':
1.578 + // Not the english way, but valid because of hardcoded syntax highlighting
1.579 + if (strpos($code, '<span class="syntaxdefault"><br /></span>') === 0)
1.580 + {
1.581 + $code = substr($code, 41);
1.582 + }
1.583 +
1.584 + // no break;
1.585 +
1.586 + default:
1.587 + $code = str_replace("\t", ' ', $code);
1.588 + $code = str_replace(' ', ' ', $code);
1.589 + $code = str_replace(' ', ' ', $code);
1.590 + $code = str_replace("\n ", "\n ", $code);
1.591 +
1.592 + // keep space at the beginning
1.593 + if (!empty($code) && $code[0] == ' ')
1.594 + {
1.595 + $code = ' ' . substr($code, 1);
1.596 + }
1.597 +
1.598 + // remove newline at the beginning
1.599 + if (!empty($code) && $code[0] == "\n")
1.600 + {
1.601 + $code = substr($code, 1);
1.602 + }
1.603 + break;
1.604 + }
1.605 +
1.606 + $code = $this->bbcode_tpl('code_open') . $code . $this->bbcode_tpl('code_close');
1.607 +
1.608 + return $code;
1.609 + }
1.610 +}
1.611 +
1.612 +?>
1.613 \ No newline at end of file