Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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