Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

bbcode.php

Zuletzt modifiziert: 02.04.2025, 15:01 - Dateigröße: 19.33 KiB


001  <?php
002  /**
003  *
004  * This file is part of the phpBB Forum Software package.
005  *
006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
007  * @license GNU General Public License, version 2 (GPL-2.0)
008  *
009  * For full copyright and license information, please see
010  * the docs/CREDITS.txt file.
011  *
012  */
013   
014  /**
015  * @ignore
016  */
017  if (!defined('IN_PHPBB'))
018  {
019      exit;
020  }
021   
022  /**
023  * BBCode class
024  */
025  class bbcode
026  {
027      var $bbcode_uid = '';
028      var $bbcode_bitfield = '';
029      var $bbcode_cache = array();
030      var $bbcode_template = array();
031   
032      var $bbcodes = array();
033   
034      var $template_bitfield;
035   
036      /**
037      * Constructor
038      */
039      function __construct($bitfield = '')
040      {
041          $this->bbcode_set_bitfield($bitfield);
042      }
043   
044      /**
045      * Init bbcode cache entries if bitfield is specified
046      *
047      * @param    string    $bitfield    The bbcode bitfield
048      */
049      function bbcode_set_bitfield($bitfield = '')
050      {
051          if ($bitfield)
052          {
053              $this->bbcode_bitfield = $bitfield;
054              $this->bbcode_cache_init();
055          }
056      }
057   
058      /**
059      * Second pass bbcodes
060      */
061      function bbcode_second_pass(&$message, $bbcode_uid = '', $bbcode_bitfield = false)
062      {
063          if ($bbcode_uid)
064          {
065              $this->bbcode_uid = $bbcode_uid;
066          }
067   
068          if ($bbcode_bitfield !== false)
069          {
070              $this->bbcode_bitfield = $bbcode_bitfield;
071   
072              // Init those added with a new bbcode_bitfield (already stored codes will not get parsed again)
073              $this->bbcode_cache_init();
074          }
075   
076          if (!$this->bbcode_bitfield)
077          {
078              // Remove the uid from tags that have not been transformed into HTML
079              if ($this->bbcode_uid)
080              {
081                  $message = str_replace(':' . $this->bbcode_uid, '', $message);
082              }
083   
084              return;
085          }
086   
087          $str = array('search' => array(), 'replace' => array());
088          $preg = array('search' => array(), 'replace' => array());
089   
090          $bitfield = new bitfield($this->bbcode_bitfield);
091          $bbcodes_set = $bitfield->get_all_set();
092   
093          $undid_bbcode_specialchars = false;
094          foreach ($bbcodes_set as $bbcode_id)
095          {
096              if (!empty($this->bbcode_cache[$bbcode_id]))
097              {
098                  foreach ($this->bbcode_cache[$bbcode_id] as $type => $array)
099                  {
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          foreach ($bbcode_ids as $bbcode_id)
225          {
226              switch ($bbcode_id)
227              {
228                  case BBCODE_ID_QUOTE:
229                      $this->bbcode_cache[$bbcode_id] = array(
230                          'str' => array(
231                              '[/quote:$uid]'    => $this->bbcode_tpl('quote_close', $bbcode_id)
232                          ),
233                          'preg' => array(
234                              '#\[quote(?:=&quot;(.*?)&quot;)?:$uid\]((?!\[quote(?:=&quot;.*?&quot;)?:$uid\]).)?#is'    => function ($match) {
235                                  if (!isset($match[2]))
236                                  {
237                                      $match[2] = '';
238                                  }
239   
240                                  return $this->bbcode_second_pass_quote($match[1], $match[2]);
241                              },
242                          )
243                      );
244                  break;
245   
246                  case BBCODE_ID_B:
247                      $this->bbcode_cache[$bbcode_id] = array(
248                          'str' => array(
249                              '[b:$uid]'    => $this->bbcode_tpl('b_open', $bbcode_id),
250                              '[/b:$uid]'    => $this->bbcode_tpl('b_close', $bbcode_id),
251                          )
252                      );
253                  break;
254   
255                  case BBCODE_ID_I:
256                      $this->bbcode_cache[$bbcode_id] = array(
257                          'str' => array(
258                              '[i:$uid]'    => $this->bbcode_tpl('i_open', $bbcode_id),
259                              '[/i:$uid]'    => $this->bbcode_tpl('i_close', $bbcode_id),
260                          )
261                      );
262                  break;
263   
264                  case BBCODE_ID_URL:
265                      $this->bbcode_cache[$bbcode_id] = array(
266                          'preg' => array(
267                              '#\[url:$uid\]((.*?))\[/url:$uid\]#s'            => $this->bbcode_tpl('url', $bbcode_id),
268                              '#\[url=([^\[]+?):$uid\](.*?)\[/url:$uid\]#s'    => $this->bbcode_tpl('url', $bbcode_id),
269                          )
270                      );
271                  break;
272   
273                  case BBCODE_ID_IMG:
274                      if ($user->optionget('viewimg'))
275                      {
276                          $this->bbcode_cache[$bbcode_id] = array(
277                              'preg' => array(
278                                  '#\[img:$uid\](.*?)\[/img:$uid\]#s'        => $this->bbcode_tpl('img', $bbcode_id),
279                              )
280                          );
281                      }
282                      else
283                      {
284                          $this->bbcode_cache[$bbcode_id] = array(
285                              'preg' => array(
286                                  '#\[img:$uid\](.*?)\[/img:$uid\]#s'        => str_replace('$2', '[ img ]', $this->bbcode_tpl('url', $bbcode_id, true)),
287                              )
288                          );
289                      }
290                  break;
291   
292                  case BBCODE_ID_SIZE:
293                      $this->bbcode_cache[$bbcode_id] = array(
294                          'preg' => array(
295                              '#\[size=([\-\+]?\d+):$uid\](.*?)\[/size:$uid\]#s'    => $this->bbcode_tpl('size', $bbcode_id),
296                          )
297                      );
298                  break;
299   
300                  case BBCODE_ID_COLOR:
301                      $this->bbcode_cache[$bbcode_id] = array(
302                          'preg' => array(
303                              '!\[color=(#[0-9a-f]{3}|#[0-9a-f]{6}|[a-z\-]+):$uid\](.*?)\[/color:$uid\]!is'    => $this->bbcode_tpl('color', $bbcode_id),
304                          )
305                      );
306                  break;
307   
308                  case BBCODE_ID_U:
309                      $this->bbcode_cache[$bbcode_id] = array(
310                          'str' => array(
311                              '[u:$uid]'    => $this->bbcode_tpl('u_open', $bbcode_id),
312                              '[/u:$uid]'    => $this->bbcode_tpl('u_close', $bbcode_id),
313                          )
314                      );
315                  break;
316   
317                  case BBCODE_ID_CODE:
318                      $this->bbcode_cache[$bbcode_id] = array(
319                          'preg' => array(
320                              '#\[code(?:=([a-z]+))?:$uid\](.*?)\[/code:$uid\]#is'    => function ($match) {
321                                  return $this->bbcode_second_pass_code($match[1], $match[2]);
322                              },
323                          )
324                      );
325                  break;
326   
327                  case BBCODE_ID_LIST:
328                      $this->bbcode_cache[$bbcode_id] = array(
329                          'preg' => array(
330                              '#(\[\/?(list|\*):[mou]?:?$uid\])[\n]{1}#'    => "\$1",
331                              '#(\[list=([^\[]+):$uid\])[\n]{1}#'            => "\$1",
332                              '#\[list=([^\[]+):$uid\]#'                    => function ($match) {
333                                  return $this->bbcode_list($match[1]);
334                              },
335                          ),
336                          'str' => array(
337                              '[list:$uid]'        => $this->bbcode_tpl('ulist_open_default', $bbcode_id),
338                              '[/list:u:$uid]'    => $this->bbcode_tpl('ulist_close', $bbcode_id),
339                              '[/list:o:$uid]'    => $this->bbcode_tpl('olist_close', $bbcode_id),
340                              '[*:$uid]'            => $this->bbcode_tpl('listitem', $bbcode_id),
341                              '[/*:$uid]'            => $this->bbcode_tpl('listitem_close', $bbcode_id),
342                              '[/*:m:$uid]'        => $this->bbcode_tpl('listitem_close', $bbcode_id)
343                          ),
344                      );
345                  break;
346   
347                  case BBCODE_ID_EMAIL:
348                      $this->bbcode_cache[$bbcode_id] = array(
349                          'preg' => array(
350                              '#\[email:$uid\]((.*?))\[/email:$uid\]#is'            => $this->bbcode_tpl('email', $bbcode_id),
351                              '#\[email=([^\[]+):$uid\](.*?)\[/email:$uid\]#is'    => $this->bbcode_tpl('email', $bbcode_id)
352                          )
353                      );
354                  break;
355   
356                  case BBCODE_ID_FLASH:
357                      if ($user->optionget('viewflash'))
358                      {
359                          $this->bbcode_cache[$bbcode_id] = array(
360                              'preg' => array(
361                                  '#\[flash=([0-9]+),([0-9]+):$uid\](.*?)\[/flash:$uid\]#'    => $this->bbcode_tpl('flash', $bbcode_id),
362                              )
363                          );
364                      }
365                      else
366                      {
367                          $this->bbcode_cache[$bbcode_id] = array(
368                              'preg' => array(
369                                  '#\[flash=([0-9]+),([0-9]+):$uid\](.*?)\[/flash:$uid\]#'    => str_replace('$1', '$3', str_replace('$2', '[ flash ]', $this->bbcode_tpl('url', $bbcode_id, true)))
370                              )
371                          );
372                      }
373                  break;
374   
375                  case BBCODE_ID_ATTACH:
376                      $this->bbcode_cache[$bbcode_id] = array(
377                          'str'    => array(
378                              '[/attachment:$uid]'    => $this->bbcode_tpl('inline_attachment_close', $bbcode_id)
379                          ),
380                          'preg'    => array(
381                              '#\[attachment=([0-9]+):$uid\]#'    => $this->bbcode_tpl('inline_attachment_open', $bbcode_id)
382                          )
383                      );
384                  break;
385   
386                  default:
387                      if (isset($rowset[$bbcode_id]))
388                      {
389                          if ($this->template_bitfield->get($bbcode_id))
390                          {
391                              // The bbcode requires a custom template to be loaded
392                              if (!$bbcode_tpl = $this->bbcode_tpl($rowset[$bbcode_id]['bbcode_tag'], $bbcode_id))
393                              {
394                                  // For some reason, the required template seems not to be available, use the default template
395                                  $bbcode_tpl = (!empty($rowset[$bbcode_id]['second_pass_replace'])) ? $rowset[$bbcode_id]['second_pass_replace'] : $rowset[$bbcode_id]['bbcode_tpl'];
396                              }
397                              else
398                              {
399                                  // In order to use templates with custom bbcodes we need
400                                  // to replace all {VARS} to corresponding backreferences
401                                  // Note that backreferences are numbered from bbcode_match
402                                  if (preg_match_all('/\{(URL|LOCAL_URL|EMAIL|TEXT|SIMPLETEXT|INTTEXT|IDENTIFIER|COLOR|NUMBER)[0-9]*\}/', $rowset[$bbcode_id]['bbcode_match'], $m))
403                                  {
404                                      foreach ($m[0] as $i => $tok)
405                                      {
406                                          $bbcode_tpl = str_replace($tok, '$' . ($i + 1), $bbcode_tpl);
407                                      }
408                                  }
409                              }
410                          }
411                          else
412                          {
413                              // Default template
414                              $bbcode_tpl = (!empty($rowset[$bbcode_id]['second_pass_replace'])) ? $rowset[$bbcode_id]['second_pass_replace'] : $rowset[$bbcode_id]['bbcode_tpl'];
415                          }
416   
417                          // Replace {L_*} lang strings
418                          $bbcode_tpl = preg_replace_callback('/{L_([A-Z0-9_]+)}/', function ($match) use ($user) {
419                              return (!empty($user->lang[$match[1]])) ? $user->lang($match[1]) : ucwords(strtolower(str_replace('_', ' ', $match[1])));
420                          }, $bbcode_tpl);
421   
422                          if (!empty($rowset[$bbcode_id]['second_pass_replace']))
423                          {
424                              // The custom BBCode requires second-pass pattern replacements
425                              $this->bbcode_cache[$bbcode_id] = array(
426                                  'preg' => array($rowset[$bbcode_id]['second_pass_match'] => $bbcode_tpl)
427                              );
428                          }
429                          else
430                          {
431                              $this->bbcode_cache[$bbcode_id] = array(
432                                  'str' => array($rowset[$bbcode_id]['second_pass_match'] => $bbcode_tpl)
433                              );
434                          }
435                      }
436                      else
437                      {
438                          $this->bbcode_cache[$bbcode_id] = false;
439                      }
440                  break;
441              }
442          }
443   
444          $bbcode_cache = $this->bbcode_cache;
445          $bbcode_bitfield = $this->bbcode_bitfield;
446          $bbcode_uid = $this->bbcode_uid;
447   
448          /**
449          * Use this event to modify the bbcode_cache
450          *
451          * @event core.bbcode_cache_init_end
452          * @var    array    bbcode_cache        The array of cached search and replace patterns of bbcodes
453          * @var    string    bbcode_bitfield        The bbcode bitfield
454          * @var    string    bbcode_uid            The bbcode uid
455          * @since 3.1.3-RC1
456          */
457          $vars = array('bbcode_cache', 'bbcode_bitfield', 'bbcode_uid');
458          extract($phpbb_dispatcher->trigger_event('core.bbcode_cache_init_end', compact($vars)));
459   
460          $this->bbcode_cache = $bbcode_cache;
461          $this->bbcode_bitfield = $bbcode_bitfield;
462          $this->bbcode_uid = $bbcode_uid;
463      }
464   
465      /**
466      * Return bbcode template
467      */
468      function bbcode_tpl($tpl_name, $bbcode_id = -1, $skip_bitfield_check = false)
469      {
470          static $bbcode_hardtpl = array();
471          if (empty($bbcode_hardtpl))
472          {
473              global $user;
474   
475              $bbcode_hardtpl = array(
476                  'b_open'    => '<span style="font-weight: bold">',
477                  'b_close'    => '</span>',
478                  'i_open'    => '<span style="font-style: italic">',
479                  'i_close'    => '</span>',
480                  'u_open'    => '<span style="text-decoration: underline">',
481                  'u_close'    => '</span>',
482                  'img'        => '<img src="$1" class="postimage" alt="' . $user->lang['IMAGE'] . '" />',
483                  'size'        => '<span style="font-size: $1%; line-height: normal">$2</span>',
484                  'color'        => '<span style="color: $1">$2</span>',
485                  'email'        => '<a href="mailto:$1">$2</a>'
486              );
487          }
488   
489          if ($bbcode_id != -1 && !$skip_bitfield_check && !$this->template_bitfield->get($bbcode_id))
490          {
491              return (isset($bbcode_hardtpl[$tpl_name])) ? $bbcode_hardtpl[$tpl_name] : false;
492          }
493   
494          if (empty($this->bbcode_template))
495          {
496              if (($tpl = file_get_contents($this->template_filename)) === false)
497              {
498                  trigger_error('Could not load bbcode template', E_USER_ERROR);
499              }
500   
501              // replace \ with \\ and then ' with \'.
502              $tpl = str_replace('\\', '\\\\', $tpl);
503              $tpl = str_replace("'", "\'", $tpl);
504   
505              // strip newlines and indent
506              $tpl = preg_replace("/\n[\n\r\s\t]*/", '', $tpl);
507   
508              // Turn template blocks into PHP assignment statements for the values of $bbcode_tpl..
509              $this->bbcode_template = array();
510   
511              // Capture the BBCode template matches
512              // Allow phpBB template or the Twig syntax
513              $matches = (preg_match_all('#<!-- BEGIN (.*?) -->(.*?)<!-- END (?:.*?) -->#', $tpl, $match)) ?:
514                              preg_match_all('#{% for (.*?) in .*? %}(.*?){% endfor %}#s', $tpl, $match);
515   
516              for ($i = 0; $i < $matches; $i++)
517              {
518                  if (empty($match[1][$i]))
519                  {
520                      continue;
521                  }
522   
523                  $this->bbcode_template[$match[1][$i]] = $this->bbcode_tpl_replace($match[1][$i], $match[2][$i]);
524              }
525          }
526   
527          return (isset($this->bbcode_template[$tpl_name])) ? $this->bbcode_template[$tpl_name] : ((isset($bbcode_hardtpl[$tpl_name])) ? $bbcode_hardtpl[$tpl_name] : false);
528      }
529   
530      /**
531      * Return bbcode template replacement
532      */
533      function bbcode_tpl_replace($tpl_name, $tpl)
534      {
535          global $user;
536   
537          static $replacements = array(
538              'quote_username_open'    => array('{USERNAME}'    => '$1'),
539              'color'                    => array('{COLOR}'        => '$1', '{TEXT}'            => '$2'),
540              'size'                    => array('{SIZE}'        => '$1', '{TEXT}'            => '$2'),
541              'img'                    => array('{URL}'        => '$1'),
542              'flash'                    => array('{WIDTH}'        => '$1', '{HEIGHT}'            => '$2', '{URL}'    => '$3'),
543              'url'                    => array('{URL}'        => '$1', '{DESCRIPTION}'    => '$2'),
544              'email'                    => array('{EMAIL}'        => '$1', '{DESCRIPTION}'    => '$2')
545          );
546   
547          $tpl = preg_replace_callback('/{L_([A-Z0-9_]+)}/', function ($match) use ($user) {
548              return (!empty($user->lang[$match[1]])) ? $user->lang($match[1]) : ucwords(strtolower(str_replace('_', ' ', $match[1])));
549          }, $tpl);
550   
551          if (!empty($replacements[$tpl_name]))
552          {
553              $tpl = strtr($tpl, $replacements[$tpl_name]);
554          }
555   
556          return trim($tpl);
557      }
558   
559      /**
560      * Second parse list bbcode
561      */
562      function bbcode_list($type)
563      {
564          if ($type == '')
565          {
566              $tpl = 'ulist_open_default';
567              $type = 'default';
568          }
569          else if ($type == 'i')
570          {
571              $tpl = 'olist_open';
572              $type = 'lower-roman';
573          }
574          else if ($type == 'I')
575          {
576              $tpl = 'olist_open';
577              $type = 'upper-roman';
578          }
579          else if (preg_match('#^(disc|circle|square)$#i', $type))
580          {
581              $tpl = 'ulist_open';
582              $type = strtolower($type);
583          }
584          else if (preg_match('#^[a-z]$#', $type))
585          {
586              $tpl = 'olist_open';
587              $type = 'lower-alpha';
588          }
589          else if (preg_match('#[A-Z]#', $type))
590          {
591              $tpl = 'olist_open';
592              $type = 'upper-alpha';
593          }
594          else if (is_numeric($type))
595          {
596              $tpl = 'olist_open';
597              $type = 'decimal';
598          }
599          else
600          {
601              $tpl = 'olist_open';
602              $type = 'decimal';
603          }
604   
605          return str_replace('{LIST_TYPE}', $type, $this->bbcode_tpl($tpl));
606      }
607   
608      /**
609      * Second parse quote tag
610      */
611      function bbcode_second_pass_quote($username, $quote)
612      {
613          // when using the /e modifier, preg_replace slashes double-quotes but does not
614          // seem to slash anything else
615          $quote = str_replace('\"', '"', $quote);
616          $username = str_replace('\"', '"', $username);
617   
618          // remove newline at the beginning
619          if ($quote == "\n")
620          {
621              $quote = '';
622          }
623   
624          $quote = (($username) ? str_replace('$1', $username, $this->bbcode_tpl('quote_username_open')) : $this->bbcode_tpl('quote_open')) . $quote;
625   
626          return $quote;
627      }
628   
629      /**
630      * Second parse code tag
631      */
632      function bbcode_second_pass_code($type, $code)
633      {
634          // when using the /e modifier, preg_replace slashes double-quotes but does not
635          // seem to slash anything else
636          $code = str_replace('\"', '"', $code);
637   
638          switch ($type)
639          {
640              case 'php':
641                  // Not the english way, but valid because of hardcoded syntax highlighting
642                  if (strpos($code, '<span class="syntaxdefault"><br /></span>') === 0)
643                  {
644                      $code = substr($code, 41);
645                  }
646   
647              // no break;
648   
649              default:
650                  $code = str_replace("\t", '&nbsp; &nbsp;', $code);
651                  $code = str_replace('  ', '&nbsp; ', $code);
652                  $code = str_replace('  ', ' &nbsp;', $code);
653                  $code = str_replace("\n ", "\n&nbsp;", $code);
654   
655                  // keep space at the beginning
656                  if (!empty($code) && $code[0] == ' ')
657                  {
658                      $code = '&nbsp;' . substr($code, 1);
659                  }
660   
661                  // remove newline at the beginning
662                  if (!empty($code) && $code[0] == "\n")
663                  {
664                      $code = substr($code, 1);
665                  }
666              break;
667          }
668   
669          $code = $this->bbcode_tpl('code_open') . $code . $this->bbcode_tpl('code_close');
670   
671          return $code;
672      }
673   
674      /**
675      * Function to perform custom bbcode second pass by extensions
676      * can be used to assign bbcode pattern replacement
677      * Example: '#\[list=([^\[]+):$uid\]#e'    => "\$this->bbcode_second_pass_by_extension('\$1')"
678      *
679      * Accepts variable number of parameters
680      *
681      * @return mixed Second pass result
682      *
683      * @deprecated 3.2.10 (To be removed 4.0.0)
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  }
708