[ Index ]

PHP Cross Reference of phpBB-3.3.0-deutsch

title

Body

[close]

/includes/ -> bbcode.php (source)

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @license GNU General Public License, version 2 (GPL-2.0)
   8  *
   9  * For full copyright and license information, please see
  10  * the docs/CREDITS.txt file.
  11  *
  12  */
  13  
  14  /**
  15  * @ignore
  16  */
  17  if (!defined('IN_PHPBB'))
  18  {
  19      exit;
  20  }
  21  
  22  /**
  23  * BBCode class
  24  */
  25  class bbcode
  26  {
  27      var $bbcode_uid = '';
  28      var $bbcode_bitfield = '';
  29      var $bbcode_cache = array();
  30      var $bbcode_template = array();
  31  
  32      var $bbcodes = array();
  33  
  34      var $template_bitfield;
  35  
  36      /**
  37      * Constructor
  38      */
  39  	function __construct($bitfield = '')
  40      {
  41          $this->bbcode_set_bitfield($bitfield);
  42      }
  43  
  44      /**
  45      * Init bbcode cache entries if bitfield is specified
  46      *
  47      * @param    string    $bitfield    The bbcode bitfield
  48      */
  49  	function bbcode_set_bitfield($bitfield = '')
  50      {
  51          if ($bitfield)
  52          {
  53              $this->bbcode_bitfield = $bitfield;
  54              $this->bbcode_cache_init();
  55          }
  56      }
  57  
  58      /**
  59      * Second pass bbcodes
  60      */
  61  	function bbcode_second_pass(&$message, $bbcode_uid = '', $bbcode_bitfield = false)
  62      {
  63          if ($bbcode_uid)
  64          {
  65              $this->bbcode_uid = $bbcode_uid;
  66          }
  67  
  68          if ($bbcode_bitfield !== false)
  69          {
  70              $this->bbcode_bitfield = $bbcode_bitfield;
  71  
  72              // Init those added with a new bbcode_bitfield (already stored codes will not get parsed again)
  73              $this->bbcode_cache_init();
  74          }
  75  
  76          if (!$this->bbcode_bitfield)
  77          {
  78              // Remove the uid from tags that have not been transformed into HTML
  79              if ($this->bbcode_uid)
  80              {
  81                  $message = str_replace(':' . $this->bbcode_uid, '', $message);
  82              }
  83  
  84              return;
  85          }
  86  
  87          $str = array('search' => array(), 'replace' => array());
  88          $preg = array('search' => array(), 'replace' => array());
  89  
  90          $bitfield = new bitfield($this->bbcode_bitfield);
  91          $bbcodes_set = $bitfield->get_all_set();
  92  
  93          $undid_bbcode_specialchars = false;
  94          foreach ($bbcodes_set as $bbcode_id)
  95          {
  96              if (!empty($this->bbcode_cache[$bbcode_id]))
  97              {
  98                  foreach ($this->bbcode_cache[$bbcode_id] as $type => $array)
  99                  {
 100                      foreach ($array as $search => $replace)
 101                      {
 102                          ${$type}['search'][] = str_replace('$uid', $this->bbcode_uid, $search);
 103                          ${$type}['replace'][] = $replace;
 104                      }
 105  
 106                      if (count($str['search']))
 107                      {
 108                          $message = str_replace($str['search'], $str['replace'], $message);
 109                          $str = array('search' => array(), 'replace' => array());
 110                      }
 111  
 112                      if (count($preg['search']))
 113                      {
 114                          // we need to turn the entities back into their original form to allow the
 115                          // search patterns to work properly
 116                          if (!$undid_bbcode_specialchars)
 117                          {
 118                              $message = str_replace(array('&#58;', '&#46;'), array(':', '.'), $message);
 119                              $undid_bbcode_specialchars = true;
 120                          }
 121  
 122                          foreach ($preg['search'] as $key => $search)
 123                          {
 124                              if (is_callable($preg['replace'][$key]))
 125                              {
 126                                  $message = preg_replace_callback($search, $preg['replace'][$key], $message);
 127                              }
 128                              else
 129                              {
 130                                  $message = preg_replace($search, $preg['replace'][$key], $message);
 131                              }
 132                          }
 133  
 134                          $preg = array('search' => array(), 'replace' => array());
 135                      }
 136                  }
 137              }
 138          }
 139  
 140          // Remove the uid from tags that have not been transformed into HTML
 141          $message = str_replace(':' . $this->bbcode_uid, '', $message);
 142      }
 143  
 144      /**
 145      * Init bbcode cache
 146      *
 147      * requires: $this->bbcode_bitfield
 148      * sets: $this->bbcode_cache with bbcode templates needed for bbcode_bitfield
 149      */
 150  	function bbcode_cache_init()
 151      {
 152          global $user, $phpbb_dispatcher, $phpbb_extension_manager, $phpbb_container, $phpbb_filesystem;
 153  
 154          if (empty($this->template_filename))
 155          {
 156              $this->template_bitfield = new bitfield($user->style['bbcode_bitfield']);
 157  
 158              $template = new \phpbb\template\twig\twig(
 159                  $phpbb_container->get('path_helper'),
 160                  $phpbb_container->get('config'),
 161                  new \phpbb\template\context(),
 162                  new \phpbb\template\twig\environment(
 163                      $phpbb_container->get('config'),
 164                      $phpbb_container->get('filesystem'),
 165                      $phpbb_container->get('path_helper'),
 166                      $phpbb_container->getParameter('core.cache_dir'),
 167                      $phpbb_container->get('ext.manager'),
 168                      new \phpbb\template\twig\loader(
 169                          $phpbb_filesystem
 170                      )
 171                  ),
 172                  $phpbb_container->getParameter('core.cache_dir'),
 173                  $phpbb_container->get('user'),
 174                  $phpbb_container->get('template.twig.extensions.collection'),
 175                  $phpbb_extension_manager
 176              );
 177  
 178              $template->set_style();
 179              $template->set_filenames(array('bbcode.html' => 'bbcode.html'));
 180              $this->template_filename = $template->get_source_file_for_handle('bbcode.html');
 181          }
 182  
 183          $bbcode_ids = $rowset = $sql = array();
 184  
 185          $bitfield = new bitfield($this->bbcode_bitfield);
 186          $bbcodes_set = $bitfield->get_all_set();
 187  
 188          foreach ($bbcodes_set as $bbcode_id)
 189          {
 190              if (isset($this->bbcode_cache[$bbcode_id]))
 191              {
 192                  // do not try to re-cache it if it's already in
 193                  continue;
 194              }
 195              $bbcode_ids[] = $bbcode_id;
 196  
 197              if ($bbcode_id > NUM_CORE_BBCODES)
 198              {
 199                  $sql[] = $bbcode_id;
 200              }
 201          }
 202  
 203          if (count($sql))
 204          {
 205              global $db;
 206  
 207              $sql = 'SELECT *
 208                  FROM ' . BBCODES_TABLE . '
 209                  WHERE ' . $db->sql_in_set('bbcode_id', $sql);
 210              $result = $db->sql_query($sql, 3600);
 211  
 212              while ($row = $db->sql_fetchrow($result))
 213              {
 214                  // To circumvent replacing newlines with <br /> for the generated html,
 215                  // we use carriage returns here. They are later changed back to newlines
 216                  $row['bbcode_tpl'] = str_replace("\n", "\r", $row['bbcode_tpl']);
 217                  $row['second_pass_replace'] = str_replace("\n", "\r", $row['second_pass_replace']);
 218  
 219                  $rowset[$row['bbcode_id']] = $row;
 220              }
 221              $db->sql_freeresult($result);
 222          }
 223  
 224          // To perform custom second pass in extension, use $this->bbcode_second_pass_by_extension()
 225          // method which accepts variable number of parameters
 226          foreach ($bbcode_ids as $bbcode_id)
 227          {
 228              switch ($bbcode_id)
 229              {
 230                  case BBCODE_ID_QUOTE:
 231                      $this->bbcode_cache[$bbcode_id] = array(
 232                          'str' => array(
 233                              '[/quote:$uid]'    => $this->bbcode_tpl('quote_close', $bbcode_id)
 234                          ),
 235                          'preg' => array(
 236                              '#\[quote(?:=&quot;(.*?)&quot;)?:$uid\]((?!\[quote(?:=&quot;.*?&quot;)?:$uid\]).)?#is'    => function ($match) {
 237                                  if (!isset($match[2]))
 238                                  {
 239                                      $match[2] = '';
 240                                  }
 241  
 242                                  return $this->bbcode_second_pass_quote($match[1], $match[2]);
 243                              },
 244                          )
 245                      );
 246                  break;
 247  
 248                  case BBCODE_ID_B:
 249                      $this->bbcode_cache[$bbcode_id] = array(
 250                          'str' => array(
 251                              '[b:$uid]'    => $this->bbcode_tpl('b_open', $bbcode_id),
 252                              '[/b:$uid]'    => $this->bbcode_tpl('b_close', $bbcode_id),
 253                          )
 254                      );
 255                  break;
 256  
 257                  case BBCODE_ID_I:
 258                      $this->bbcode_cache[$bbcode_id] = array(
 259                          'str' => array(
 260                              '[i:$uid]'    => $this->bbcode_tpl('i_open', $bbcode_id),
 261                              '[/i:$uid]'    => $this->bbcode_tpl('i_close', $bbcode_id),
 262                          )
 263                      );
 264                  break;
 265  
 266                  case BBCODE_ID_URL:
 267                      $this->bbcode_cache[$bbcode_id] = array(
 268                          'preg' => array(
 269                              '#\[url:$uid\]((.*?))\[/url:$uid\]#s'            => $this->bbcode_tpl('url', $bbcode_id),
 270                              '#\[url=([^\[]+?):$uid\](.*?)\[/url:$uid\]#s'    => $this->bbcode_tpl('url', $bbcode_id),
 271                          )
 272                      );
 273                  break;
 274  
 275                  case BBCODE_ID_IMG:
 276                      if ($user->optionget('viewimg'))
 277                      {
 278                          $this->bbcode_cache[$bbcode_id] = array(
 279                              'preg' => array(
 280                                  '#\[img:$uid\](.*?)\[/img:$uid\]#s'        => $this->bbcode_tpl('img', $bbcode_id),
 281                              )
 282                          );
 283                      }
 284                      else
 285                      {
 286                          $this->bbcode_cache[$bbcode_id] = array(
 287                              'preg' => array(
 288                                  '#\[img:$uid\](.*?)\[/img:$uid\]#s'        => str_replace('$2', '[ img ]', $this->bbcode_tpl('url', $bbcode_id, true)),
 289                              )
 290                          );
 291                      }
 292                  break;
 293  
 294                  case BBCODE_ID_SIZE:
 295                      $this->bbcode_cache[$bbcode_id] = array(
 296                          'preg' => array(
 297                              '#\[size=([\-\+]?\d+):$uid\](.*?)\[/size:$uid\]#s'    => $this->bbcode_tpl('size', $bbcode_id),
 298                          )
 299                      );
 300                  break;
 301  
 302                  case BBCODE_ID_COLOR:
 303                      $this->bbcode_cache[$bbcode_id] = array(
 304                          'preg' => array(
 305                              '!\[color=(#[0-9a-f]{3}|#[0-9a-f]{6}|[a-z\-]+):$uid\](.*?)\[/color:$uid\]!is'    => $this->bbcode_tpl('color', $bbcode_id),
 306                          )
 307                      );
 308                  break;
 309  
 310                  case BBCODE_ID_U:
 311                      $this->bbcode_cache[$bbcode_id] = array(
 312                          'str' => array(
 313                              '[u:$uid]'    => $this->bbcode_tpl('u_open', $bbcode_id),
 314                              '[/u:$uid]'    => $this->bbcode_tpl('u_close', $bbcode_id),
 315                          )
 316                      );
 317                  break;
 318  
 319                  case BBCODE_ID_CODE:
 320                      $this->bbcode_cache[$bbcode_id] = array(
 321                          'preg' => array(
 322                              '#\[code(?:=([a-z]+))?:$uid\](.*?)\[/code:$uid\]#is'    => function ($match) {
 323                                  return $this->bbcode_second_pass_code($match[1], $match[2]);
 324                              },
 325                          )
 326                      );
 327                  break;
 328  
 329                  case BBCODE_ID_LIST:
 330                      $this->bbcode_cache[$bbcode_id] = array(
 331                          'preg' => array(
 332                              '#(\[\/?(list|\*):[mou]?:?$uid\])[\n]{1}#'    => "\$1",
 333                              '#(\[list=([^\[]+):$uid\])[\n]{1}#'            => "\$1",
 334                              '#\[list=([^\[]+):$uid\]#'                    => function ($match) {
 335                                  return $this->bbcode_list($match[1]);
 336                              },
 337                          ),
 338                          'str' => array(
 339                              '[list:$uid]'        => $this->bbcode_tpl('ulist_open_default', $bbcode_id),
 340                              '[/list:u:$uid]'    => $this->bbcode_tpl('ulist_close', $bbcode_id),
 341                              '[/list:o:$uid]'    => $this->bbcode_tpl('olist_close', $bbcode_id),
 342                              '[*:$uid]'            => $this->bbcode_tpl('listitem', $bbcode_id),
 343                              '[/*:$uid]'            => $this->bbcode_tpl('listitem_close', $bbcode_id),
 344                              '[/*:m:$uid]'        => $this->bbcode_tpl('listitem_close', $bbcode_id)
 345                          ),
 346                      );
 347                  break;
 348  
 349                  case BBCODE_ID_EMAIL:
 350                      $this->bbcode_cache[$bbcode_id] = array(
 351                          'preg' => array(
 352                              '#\[email:$uid\]((.*?))\[/email:$uid\]#is'            => $this->bbcode_tpl('email', $bbcode_id),
 353                              '#\[email=([^\[]+):$uid\](.*?)\[/email:$uid\]#is'    => $this->bbcode_tpl('email', $bbcode_id)
 354                          )
 355                      );
 356                  break;
 357  
 358                  case BBCODE_ID_FLASH:
 359                      if ($user->optionget('viewflash'))
 360                      {
 361                          $this->bbcode_cache[$bbcode_id] = array(
 362                              'preg' => array(
 363                                  '#\[flash=([0-9]+),([0-9]+):$uid\](.*?)\[/flash:$uid\]#'    => $this->bbcode_tpl('flash', $bbcode_id),
 364                              )
 365                          );
 366                      }
 367                      else
 368                      {
 369                          $this->bbcode_cache[$bbcode_id] = array(
 370                              'preg' => array(
 371                                  '#\[flash=([0-9]+),([0-9]+):$uid\](.*?)\[/flash:$uid\]#'    => str_replace('$1', '$3', str_replace('$2', '[ flash ]', $this->bbcode_tpl('url', $bbcode_id, true)))
 372                              )
 373                          );
 374                      }
 375                  break;
 376  
 377                  case BBCODE_ID_ATTACH:
 378                      $this->bbcode_cache[$bbcode_id] = array(
 379                          'str'    => array(
 380                              '[/attachment:$uid]'    => $this->bbcode_tpl('inline_attachment_close', $bbcode_id)
 381                          ),
 382                          'preg'    => array(
 383                              '#\[attachment=([0-9]+):$uid\]#'    => $this->bbcode_tpl('inline_attachment_open', $bbcode_id)
 384                          )
 385                      );
 386                  break;
 387  
 388                  default:
 389                      if (isset($rowset[$bbcode_id]))
 390                      {
 391                          if ($this->template_bitfield->get($bbcode_id))
 392                          {
 393                              // The bbcode requires a custom template to be loaded
 394                              if (!$bbcode_tpl = $this->bbcode_tpl($rowset[$bbcode_id]['bbcode_tag'], $bbcode_id))
 395                              {
 396                                  // For some reason, the required template seems not to be available, use the default template
 397                                  $bbcode_tpl = (!empty($rowset[$bbcode_id]['second_pass_replace'])) ? $rowset[$bbcode_id]['second_pass_replace'] : $rowset[$bbcode_id]['bbcode_tpl'];
 398                              }
 399                              else
 400                              {
 401                                  // In order to use templates with custom bbcodes we need
 402                                  // to replace all {VARS} to corresponding backreferences
 403                                  // Note that backreferences are numbered from bbcode_match
 404                                  if (preg_match_all('/\{(URL|LOCAL_URL|EMAIL|TEXT|SIMPLETEXT|INTTEXT|IDENTIFIER|COLOR|NUMBER)[0-9]*\}/', $rowset[$bbcode_id]['bbcode_match'], $m))
 405                                  {
 406                                      foreach ($m[0] as $i => $tok)
 407                                      {
 408                                          $bbcode_tpl = str_replace($tok, '$' . ($i + 1), $bbcode_tpl);
 409                                      }
 410                                  }
 411                              }
 412                          }
 413                          else
 414                          {
 415                              // Default template
 416                              $bbcode_tpl = (!empty($rowset[$bbcode_id]['second_pass_replace'])) ? $rowset[$bbcode_id]['second_pass_replace'] : $rowset[$bbcode_id]['bbcode_tpl'];
 417                          }
 418  
 419                          // Replace {L_*} lang strings
 420                          $bbcode_tpl = preg_replace_callback('/{L_([A-Z0-9_]+)}/', function ($match) use ($user) {
 421                              return (!empty($user->lang[$match[1]])) ? $user->lang($match[1]) : ucwords(strtolower(str_replace('_', ' ', $match[1])));
 422                          }, $bbcode_tpl);
 423  
 424                          if (!empty($rowset[$bbcode_id]['second_pass_replace']))
 425                          {
 426                              // The custom BBCode requires second-pass pattern replacements
 427                              $this->bbcode_cache[$bbcode_id] = array(
 428                                  'preg' => array($rowset[$bbcode_id]['second_pass_match'] => $bbcode_tpl)
 429                              );
 430                          }
 431                          else
 432                          {
 433                              $this->bbcode_cache[$bbcode_id] = array(
 434                                  'str' => array($rowset[$bbcode_id]['second_pass_match'] => $bbcode_tpl)
 435                              );
 436                          }
 437                      }
 438                      else
 439                      {
 440                          $this->bbcode_cache[$bbcode_id] = false;
 441                      }
 442                  break;
 443              }
 444          }
 445  
 446          $bbcode_cache = $this->bbcode_cache;
 447          $bbcode_bitfield = $this->bbcode_bitfield;
 448          $bbcode_uid = $this->bbcode_uid;
 449  
 450          /**
 451          * Use this event to modify the bbcode_cache
 452          *
 453          * @event core.bbcode_cache_init_end
 454          * @var    array    bbcode_cache        The array of cached search and replace patterns of bbcodes
 455          * @var    string    bbcode_bitfield        The bbcode bitfield
 456          * @var    string    bbcode_uid            The bbcode uid
 457          * @since 3.1.3-RC1
 458          */
 459          $vars = array('bbcode_cache', 'bbcode_bitfield', 'bbcode_uid');
 460          extract($phpbb_dispatcher->trigger_event('core.bbcode_cache_init_end', compact($vars)));
 461  
 462          $this->bbcode_cache = $bbcode_cache;
 463          $this->bbcode_bitfield = $bbcode_bitfield;
 464          $this->bbcode_uid = $bbcode_uid;
 465      }
 466  
 467      /**
 468      * Return bbcode template
 469      */
 470  	function bbcode_tpl($tpl_name, $bbcode_id = -1, $skip_bitfield_check = false)
 471      {
 472          static $bbcode_hardtpl = array();
 473          if (empty($bbcode_hardtpl))
 474          {
 475              global $user;
 476  
 477              $bbcode_hardtpl = array(
 478                  'b_open'    => '<span style="font-weight: bold">',
 479                  'b_close'    => '</span>',
 480                  'i_open'    => '<span style="font-style: italic">',
 481                  'i_close'    => '</span>',
 482                  'u_open'    => '<span style="text-decoration: underline">',
 483                  'u_close'    => '</span>',
 484                  'img'        => '<img src="$1" class="postimage" alt="' . $user->lang['IMAGE'] . '" />',
 485                  'size'        => '<span style="font-size: $1%; line-height: normal">$2</span>',
 486                  'color'        => '<span style="color: $1">$2</span>',
 487                  'email'        => '<a href="mailto:$1">$2</a>'
 488              );
 489          }
 490  
 491          if ($bbcode_id != -1 && !$skip_bitfield_check && !$this->template_bitfield->get($bbcode_id))
 492          {
 493              return (isset($bbcode_hardtpl[$tpl_name])) ? $bbcode_hardtpl[$tpl_name] : false;
 494          }
 495  
 496          if (empty($this->bbcode_template))
 497          {
 498              if (($tpl = file_get_contents($this->template_filename)) === false)
 499              {
 500                  trigger_error('Could not load bbcode template', E_USER_ERROR);
 501              }
 502  
 503              // replace \ with \\ and then ' with \'.
 504              $tpl = str_replace('\\', '\\\\', $tpl);
 505              $tpl = str_replace("'", "\'", $tpl);
 506  
 507              // strip newlines and indent
 508              $tpl = preg_replace("/\n[\n\r\s\t]*/", '', $tpl);
 509  
 510              // Turn template blocks into PHP assignment statements for the values of $bbcode_tpl..
 511              $this->bbcode_template = array();
 512  
 513              // Capture the BBCode template matches
 514              // Allow phpBB template or the Twig syntax
 515              $matches = (preg_match_all('#<!-- BEGIN (.*?) -->(.*?)<!-- END (?:.*?) -->#', $tpl, $match)) ?:
 516                              preg_match_all('#{% for (.*?) in .*? %}(.*?){% endfor %}#s', $tpl, $match);
 517  
 518              for ($i = 0; $i < $matches; $i++)
 519              {
 520                  if (empty($match[1][$i]))
 521                  {
 522                      continue;
 523                  }
 524  
 525                  $this->bbcode_template[$match[1][$i]] = $this->bbcode_tpl_replace($match[1][$i], $match[2][$i]);
 526              }
 527          }
 528  
 529          return (isset($this->bbcode_template[$tpl_name])) ? $this->bbcode_template[$tpl_name] : ((isset($bbcode_hardtpl[$tpl_name])) ? $bbcode_hardtpl[$tpl_name] : false);
 530      }
 531  
 532      /**
 533      * Return bbcode template replacement
 534      */
 535  	function bbcode_tpl_replace($tpl_name, $tpl)
 536      {
 537          global $user;
 538  
 539          static $replacements = array(
 540              'quote_username_open'    => array('{USERNAME}'    => '$1'),
 541              'color'                    => array('{COLOR}'        => '$1', '{TEXT}'            => '$2'),
 542              'size'                    => array('{SIZE}'        => '$1', '{TEXT}'            => '$2'),
 543              'img'                    => array('{URL}'        => '$1'),
 544              'flash'                    => array('{WIDTH}'        => '$1', '{HEIGHT}'            => '$2', '{URL}'    => '$3'),
 545              'url'                    => array('{URL}'        => '$1', '{DESCRIPTION}'    => '$2'),
 546              'email'                    => array('{EMAIL}'        => '$1', '{DESCRIPTION}'    => '$2')
 547          );
 548  
 549          $tpl = preg_replace_callback('/{L_([A-Z0-9_]+)}/', function ($match) use ($user) {
 550              return (!empty($user->lang[$match[1]])) ? $user->lang($match[1]) : ucwords(strtolower(str_replace('_', ' ', $match[1])));
 551          }, $tpl);
 552  
 553          if (!empty($replacements[$tpl_name]))
 554          {
 555              $tpl = strtr($tpl, $replacements[$tpl_name]);
 556          }
 557  
 558          return trim($tpl);
 559      }
 560  
 561      /**
 562      * Second parse list bbcode
 563      */
 564  	function bbcode_list($type)
 565      {
 566          if ($type == '')
 567          {
 568              $tpl = 'ulist_open_default';
 569              $type = 'default';
 570          }
 571          else if ($type == 'i')
 572          {
 573              $tpl = 'olist_open';
 574              $type = 'lower-roman';
 575          }
 576          else if ($type == 'I')
 577          {
 578              $tpl = 'olist_open';
 579              $type = 'upper-roman';
 580          }
 581          else if (preg_match('#^(disc|circle|square)$#i', $type))
 582          {
 583              $tpl = 'ulist_open';
 584              $type = strtolower($type);
 585          }
 586          else if (preg_match('#^[a-z]$#', $type))
 587          {
 588              $tpl = 'olist_open';
 589              $type = 'lower-alpha';
 590          }
 591          else if (preg_match('#[A-Z]#', $type))
 592          {
 593              $tpl = 'olist_open';
 594              $type = 'upper-alpha';
 595          }
 596          else if (is_numeric($type))
 597          {
 598              $tpl = 'olist_open';
 599              $type = 'decimal';
 600          }
 601          else
 602          {
 603              $tpl = 'olist_open';
 604              $type = 'decimal';
 605          }
 606  
 607          return str_replace('{LIST_TYPE}', $type, $this->bbcode_tpl($tpl));
 608      }
 609  
 610      /**
 611      * Second parse quote tag
 612      */
 613  	function bbcode_second_pass_quote($username, $quote)
 614      {
 615          // when using the /e modifier, preg_replace slashes double-quotes but does not
 616          // seem to slash anything else
 617          $quote = str_replace('\"', '"', $quote);
 618          $username = str_replace('\"', '"', $username);
 619  
 620          // remove newline at the beginning
 621          if ($quote == "\n")
 622          {
 623              $quote = '';
 624          }
 625  
 626          $quote = (($username) ? str_replace('$1', $username, $this->bbcode_tpl('quote_username_open')) : $this->bbcode_tpl('quote_open')) . $quote;
 627  
 628          return $quote;
 629      }
 630  
 631      /**
 632      * Second parse code tag
 633      */
 634  	function bbcode_second_pass_code($type, $code)
 635      {
 636          // when using the /e modifier, preg_replace slashes double-quotes but does not
 637          // seem to slash anything else
 638          $code = str_replace('\"', '"', $code);
 639  
 640          switch ($type)
 641          {
 642              case 'php':
 643                  // Not the english way, but valid because of hardcoded syntax highlighting
 644                  if (strpos($code, '<span class="syntaxdefault"><br /></span>') === 0)
 645                  {
 646                      $code = substr($code, 41);
 647                  }
 648  
 649              // no break;
 650  
 651              default:
 652                  $code = str_replace("\t", '&nbsp; &nbsp;', $code);
 653                  $code = str_replace('  ', '&nbsp; ', $code);
 654                  $code = str_replace('  ', ' &nbsp;', $code);
 655                  $code = str_replace("\n ", "\n&nbsp;", $code);
 656  
 657                  // keep space at the beginning
 658                  if (!empty($code) && $code[0] == ' ')
 659                  {
 660                      $code = '&nbsp;' . substr($code, 1);
 661                  }
 662  
 663                  // remove newline at the beginning
 664                  if (!empty($code) && $code[0] == "\n")
 665                  {
 666                      $code = substr($code, 1);
 667                  }
 668              break;
 669          }
 670  
 671          $code = $this->bbcode_tpl('code_open') . $code . $this->bbcode_tpl('code_close');
 672  
 673          return $code;
 674      }
 675  
 676      /**
 677      * Function to perform custom bbcode second pass by extensions
 678      * can be used to assign bbcode pattern replacement
 679      * Example: '#\[list=([^\[]+):$uid\]#e'    => "\$this->bbcode_second_pass_by_extension('\$1')"
 680      *
 681      * Accepts variable number of parameters
 682      *
 683      * @return mixed Second pass result
 684      */
 685  	function bbcode_second_pass_by_extension()
 686      {
 687          global $phpbb_dispatcher;
 688  
 689          $return = false;
 690          $params_array = func_get_args();
 691  
 692          /**
 693          * Event to perform bbcode second pass with
 694          * the custom validating methods provided by extensions
 695          *
 696          * @event core.bbcode_second_pass_by_extension
 697          * @var array    params_array    Array with the function parameters
 698          * @var mixed    return            Second pass result to return
 699          *
 700          * @since 3.1.5-RC1
 701          */
 702          $vars = array('params_array', 'return');
 703          extract($phpbb_dispatcher->trigger_event('core.bbcode_second_pass_by_extension', compact($vars)));
 704  
 705          return $return;
 706      }
 707  }


Generated: Tue Apr 7 19:44:41 2020 Cross-referenced by PHPXref 0.7.1