[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

/includes/acp/ -> acp_bbcodes.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  class acp_bbcodes
  23  {
  24      var $u_action;
  25  
  26  	function main($id, $mode)
  27      {
  28          global $db, $user, $auth, $template, $cache, $request, $phpbb_dispatcher;
  29          global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
  30  
  31          $user->add_lang('acp/posting');
  32  
  33          // Set up general vars
  34          $action    = request_var('action', '');
  35          $bbcode_id = request_var('bbcode', 0);
  36          $submit = $request->is_set_post('submit');
  37  
  38          $this->tpl_name = 'acp_bbcodes';
  39          $this->page_title = 'ACP_BBCODES';
  40          $form_key = 'acp_bbcodes';
  41  
  42          add_form_key($form_key);
  43  
  44          if ($submit && !check_form_key($form_key))
  45          {
  46              trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
  47          }
  48  
  49          // Set up mode-specific vars
  50          switch ($action)
  51          {
  52              case 'add':
  53                  $bbcode_match = $bbcode_tpl = $bbcode_helpline = '';
  54                  $display_on_posting = 0;
  55              break;
  56  
  57              case 'edit':
  58                  $sql = 'SELECT bbcode_match, bbcode_tpl, display_on_posting, bbcode_helpline
  59                      FROM ' . BBCODES_TABLE . '
  60                      WHERE bbcode_id = ' . $bbcode_id;
  61                  $result = $db->sql_query($sql);
  62                  $row = $db->sql_fetchrow($result);
  63                  $db->sql_freeresult($result);
  64  
  65                  if (!$row)
  66                  {
  67                      trigger_error($user->lang['BBCODE_NOT_EXIST'] . adm_back_link($this->u_action), E_USER_WARNING);
  68                  }
  69  
  70                  $bbcode_match = $row['bbcode_match'];
  71                  $bbcode_tpl = htmlspecialchars($row['bbcode_tpl']);
  72                  $display_on_posting = $row['display_on_posting'];
  73                  $bbcode_helpline = $row['bbcode_helpline'];
  74              break;
  75  
  76              case 'modify':
  77                  $sql = 'SELECT bbcode_id, bbcode_tag
  78                      FROM ' . BBCODES_TABLE . '
  79                      WHERE bbcode_id = ' . $bbcode_id;
  80                  $result = $db->sql_query($sql);
  81                  $row = $db->sql_fetchrow($result);
  82                  $db->sql_freeresult($result);
  83  
  84                  if (!$row)
  85                  {
  86                      trigger_error($user->lang['BBCODE_NOT_EXIST'] . adm_back_link($this->u_action), E_USER_WARNING);
  87                  }
  88  
  89              // No break here
  90  
  91              case 'create':
  92                  $display_on_posting = request_var('display_on_posting', 0);
  93  
  94                  $bbcode_match = request_var('bbcode_match', '');
  95                  $bbcode_tpl = htmlspecialchars_decode(utf8_normalize_nfc(request_var('bbcode_tpl', '', true)));
  96                  $bbcode_helpline = utf8_normalize_nfc(request_var('bbcode_helpline', '', true));
  97              break;
  98          }
  99  
 100          // Do major work
 101          switch ($action)
 102          {
 103              case 'edit':
 104              case 'add':
 105  
 106                  $tpl_ary = array(
 107                      'S_EDIT_BBCODE'        => true,
 108                      'U_BACK'            => $this->u_action,
 109                      'U_ACTION'            => $this->u_action . '&amp;action=' . (($action == 'add') ? 'create' : 'modify') . (($bbcode_id) ? "&amp;bbcode=$bbcode_id" : ''),
 110  
 111                      'L_BBCODE_USAGE_EXPLAIN'=> sprintf($user->lang['BBCODE_USAGE_EXPLAIN'], '<a href="#down">', '</a>'),
 112                      'BBCODE_MATCH'            => $bbcode_match,
 113                      'BBCODE_TPL'            => $bbcode_tpl,
 114                      'BBCODE_HELPLINE'        => $bbcode_helpline,
 115                      'DISPLAY_ON_POSTING'    => $display_on_posting,
 116                  );
 117  
 118                  $bbcode_tokens = array('TEXT', 'SIMPLETEXT', 'INTTEXT', 'IDENTIFIER', 'NUMBER', 'EMAIL', 'URL', 'LOCAL_URL', 'RELATIVE_URL', 'COLOR');
 119  
 120                  /**
 121                  * Modify custom bbcode template data before we display the add/edit form
 122                  *
 123                  * @event core.acp_bbcodes_edit_add
 124                  * @var    string    action            Type of the action: add|edit
 125                  * @var    array    tpl_ary            Array with custom bbcode add/edit data
 126                  * @var    int        bbcode_id        When editing: the bbcode id,
 127                  *                                when creating: 0
 128                  * @var    array    bbcode_tokens    Array of bbcode tokens
 129                  * @since 3.1.0-a3
 130                  */
 131                  $vars = array('action', 'tpl_ary', 'bbcode_id', 'bbcode_tokens');
 132                  extract($phpbb_dispatcher->trigger_event('core.acp_bbcodes_edit_add', compact($vars)));
 133  
 134                  $template->assign_vars($tpl_ary);
 135  
 136                  foreach ($bbcode_tokens as $token)
 137                  {
 138                      $template->assign_block_vars('token', array(
 139                          'TOKEN'        => '{' . $token . '}',
 140                          'EXPLAIN'    => ($token === 'LOCAL_URL') ? $user->lang(array('tokens', $token), generate_board_url() . '/') : $user->lang(array('tokens', $token)),
 141                      ));
 142                  }
 143  
 144                  return;
 145  
 146              break;
 147  
 148              case 'modify':
 149              case 'create':
 150  
 151                  $sql_ary = $hidden_fields = array();
 152  
 153                  /**
 154                  * Modify custom bbcode data before the modify/create action
 155                  *
 156                  * @event core.acp_bbcodes_modify_create
 157                  * @var    string    action                Type of the action: modify|create
 158                  * @var    array    sql_ary                Array with new bbcode data
 159                  * @var    int        bbcode_id            When editing: the bbcode id,
 160                  *                                    when creating: 0
 161                  * @var    bool    display_on_posting    Display bbcode on posting form
 162                  * @var    string    bbcode_match        The bbcode usage string to match
 163                  * @var    string    bbcode_tpl            The bbcode HTML replacement string
 164                  * @var    string    bbcode_helpline        The bbcode help line string
 165                  * @var    array    hidden_fields        Array of hidden fields for use when
 166                  *                                    submitting form when $warn_text is true
 167                  * @since 3.1.0-a3
 168                  */
 169                  $vars = array(
 170                      'action',
 171                      'sql_ary',
 172                      'bbcode_id',
 173                      'display_on_posting',
 174                      'bbcode_match',
 175                      'bbcode_tpl',
 176                      'bbcode_helpline',
 177                      'hidden_fields',
 178                  );
 179                  extract($phpbb_dispatcher->trigger_event('core.acp_bbcodes_modify_create', compact($vars)));
 180  
 181                  $warn_text = preg_match('%<[^>]*\{text[\d]*\}[^>]*>%i', $bbcode_tpl);
 182                  if (!$warn_text || confirm_box(true))
 183                  {
 184                      $data = $this->build_regexp($bbcode_match, $bbcode_tpl);
 185  
 186                      // Make sure the user didn't pick a "bad" name for the BBCode tag.
 187                      $hard_coded = array('code', 'quote', 'quote=', 'attachment', 'attachment=', 'b', 'i', 'url', 'url=', 'img', 'size', 'size=', 'color', 'color=', 'u', 'list', 'list=', 'email', 'email=', 'flash', 'flash=');
 188  
 189                      if (($action == 'modify' && strtolower($data['bbcode_tag']) !== strtolower($row['bbcode_tag'])) || ($action == 'create'))
 190                      {
 191                          $sql = 'SELECT 1 as test
 192                              FROM ' . BBCODES_TABLE . "
 193                              WHERE LOWER(bbcode_tag) = '" . $db->sql_escape(strtolower($data['bbcode_tag'])) . "'";
 194                          $result = $db->sql_query($sql);
 195                          $info = $db->sql_fetchrow($result);
 196                          $db->sql_freeresult($result);
 197  
 198                          // Grab the end, interrogate the last closing tag
 199                          if ($info['test'] === '1' || in_array(strtolower($data['bbcode_tag']), $hard_coded) || (preg_match('#\[/([^[]*)]$#', $bbcode_match, $regs) && in_array(strtolower($regs[1]), $hard_coded)))
 200                          {
 201                              trigger_error($user->lang['BBCODE_INVALID_TAG_NAME'] . adm_back_link($this->u_action), E_USER_WARNING);
 202                          }
 203                      }
 204  
 205                      if (substr($data['bbcode_tag'], -1) === '=')
 206                      {
 207                          $test = substr($data['bbcode_tag'], 0, -1);
 208                      }
 209                      else
 210                      {
 211                          $test = $data['bbcode_tag'];
 212                      }
 213  
 214                      if (!preg_match('%\\[' . $test . '[^]]*].*?\\[/' . $test . ']%s', $bbcode_match))
 215                      {
 216                          trigger_error($user->lang['BBCODE_OPEN_ENDED_TAG'] . adm_back_link($this->u_action), E_USER_WARNING);
 217                      }
 218  
 219                      if (strlen($data['bbcode_tag']) > 16)
 220                      {
 221                          trigger_error($user->lang['BBCODE_TAG_TOO_LONG'] . adm_back_link($this->u_action), E_USER_WARNING);
 222                      }
 223  
 224                      if (strlen($bbcode_match) > 4000)
 225                      {
 226                          trigger_error($user->lang['BBCODE_TAG_DEF_TOO_LONG'] . adm_back_link($this->u_action), E_USER_WARNING);
 227                      }
 228  
 229                      if (strlen($bbcode_helpline) > 255)
 230                      {
 231                          trigger_error($user->lang['BBCODE_HELPLINE_TOO_LONG'] . adm_back_link($this->u_action), E_USER_WARNING);
 232                      }
 233  
 234                      $sql_ary = array_merge($sql_ary, array(
 235                          'bbcode_tag'                => $data['bbcode_tag'],
 236                          'bbcode_match'                => $bbcode_match,
 237                          'bbcode_tpl'                => $bbcode_tpl,
 238                          'display_on_posting'        => $display_on_posting,
 239                          'bbcode_helpline'            => $bbcode_helpline,
 240                          'first_pass_match'            => $data['first_pass_match'],
 241                          'first_pass_replace'        => $data['first_pass_replace'],
 242                          'second_pass_match'            => $data['second_pass_match'],
 243                          'second_pass_replace'        => $data['second_pass_replace']
 244                      ));
 245  
 246                      if ($action == 'create')
 247                      {
 248                          $sql = 'SELECT MAX(bbcode_id) as max_bbcode_id
 249                              FROM ' . BBCODES_TABLE;
 250                          $result = $db->sql_query($sql);
 251                          $row = $db->sql_fetchrow($result);
 252                          $db->sql_freeresult($result);
 253  
 254                          if ($row)
 255                          {
 256                              $bbcode_id = $row['max_bbcode_id'] + 1;
 257  
 258                              // Make sure it is greater than the core bbcode ids...
 259                              if ($bbcode_id <= NUM_CORE_BBCODES)
 260                              {
 261                                  $bbcode_id = NUM_CORE_BBCODES + 1;
 262                              }
 263                          }
 264                          else
 265                          {
 266                              $bbcode_id = NUM_CORE_BBCODES + 1;
 267                          }
 268  
 269                          if ($bbcode_id > BBCODE_LIMIT)
 270                          {
 271                              trigger_error($user->lang['TOO_MANY_BBCODES'] . adm_back_link($this->u_action), E_USER_WARNING);
 272                          }
 273  
 274                          $sql_ary['bbcode_id'] = (int) $bbcode_id;
 275  
 276                          $db->sql_query('INSERT INTO ' . BBCODES_TABLE . $db->sql_build_array('INSERT', $sql_ary));
 277                          $cache->destroy('sql', BBCODES_TABLE);
 278  
 279                          $lang = 'BBCODE_ADDED';
 280                          $log_action = 'LOG_BBCODE_ADD';
 281                      }
 282                      else
 283                      {
 284                          $sql = 'UPDATE ' . BBCODES_TABLE . '
 285                              SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
 286                              WHERE bbcode_id = ' . $bbcode_id;
 287                          $db->sql_query($sql);
 288                          $cache->destroy('sql', BBCODES_TABLE);
 289  
 290                          $lang = 'BBCODE_EDITED';
 291                          $log_action = 'LOG_BBCODE_EDIT';
 292                      }
 293  
 294                      add_log('admin', $log_action, $data['bbcode_tag']);
 295  
 296                      trigger_error($user->lang[$lang] . adm_back_link($this->u_action));
 297                  }
 298                  else
 299                  {
 300                      confirm_box(false, $user->lang['BBCODE_DANGER'], build_hidden_fields(array_merge($hidden_fields, array(
 301                          'action'                => $action,
 302                          'bbcode'                => $bbcode_id,
 303                          'bbcode_match'            => $bbcode_match,
 304                          'bbcode_tpl'            => htmlspecialchars($bbcode_tpl),
 305                          'bbcode_helpline'        => $bbcode_helpline,
 306                          'display_on_posting'    => $display_on_posting,
 307                          )))
 308                      , 'confirm_bbcode.html');
 309                  }
 310  
 311              break;
 312  
 313              case 'delete':
 314  
 315                  $sql = 'SELECT bbcode_tag
 316                      FROM ' . BBCODES_TABLE . "
 317                      WHERE bbcode_id = $bbcode_id";
 318                  $result = $db->sql_query($sql);
 319                  $row = $db->sql_fetchrow($result);
 320                  $db->sql_freeresult($result);
 321  
 322                  if ($row)
 323                  {
 324                      if (confirm_box(true))
 325                      {
 326                          $db->sql_query('DELETE FROM ' . BBCODES_TABLE . " WHERE bbcode_id = $bbcode_id");
 327                          $cache->destroy('sql', BBCODES_TABLE);
 328                          add_log('admin', 'LOG_BBCODE_DELETE', $row['bbcode_tag']);
 329  
 330                          if ($request->is_ajax())
 331                          {
 332                              $json_response = new \phpbb\json_response;
 333                              $json_response->send(array(
 334                                  'MESSAGE_TITLE'    => $user->lang['INFORMATION'],
 335                                  'MESSAGE_TEXT'    => $user->lang['BBCODE_DELETED'],
 336                                  'REFRESH_DATA'    => array(
 337                                      'time'    => 3
 338                                  )
 339                              ));
 340                          }
 341                      }
 342                      else
 343                      {
 344                          confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
 345                              'bbcode'    => $bbcode_id,
 346                              'i'            => $id,
 347                              'mode'        => $mode,
 348                              'action'    => $action))
 349                          );
 350                      }
 351                  }
 352  
 353              break;
 354          }
 355  
 356          $u_action = $this->u_action;
 357  
 358          $template_data = array(
 359              'U_ACTION'        => $this->u_action . '&amp;action=add',
 360          );
 361  
 362          $sql_ary = array(
 363              'SELECT'    => 'b.*',
 364              'FROM'        => array(BBCODES_TABLE => 'b'),
 365              'ORDER_BY'    => 'b.bbcode_tag',
 366          );
 367  
 368          /**
 369          *  Modify custom bbcode template data before we display the form
 370          *
 371          * @event core.acp_bbcodes_display_form
 372          * @var    string    action            Type of the action: modify|create
 373          * @var    array    sql_ary            The SQL array to get custom bbcode data
 374          * @var    array    template_data    Array with form template data
 375          * @var    string    u_action        The u_action link
 376          * @since 3.1.0-a3
 377          */
 378          $vars = array('action', 'sql_ary', 'template_data', 'u_action');
 379          extract($phpbb_dispatcher->trigger_event('core.acp_bbcodes_display_form', compact($vars)));
 380  
 381          $result = $db->sql_query($db->sql_build_query('SELECT', $sql_ary));
 382  
 383          $template->assign_vars($template_data);
 384  
 385          while ($row = $db->sql_fetchrow($result))
 386          {
 387              $bbcodes_array = array(
 388                  'BBCODE_TAG'        => $row['bbcode_tag'],
 389                  'U_EDIT'            => $u_action . '&amp;action=edit&amp;bbcode=' . $row['bbcode_id'],
 390                  'U_DELETE'            => $u_action . '&amp;action=delete&amp;bbcode=' . $row['bbcode_id'],
 391              );
 392  
 393              /**
 394              *  Modify display of custom bbcodes in the form
 395              *
 396              * @event core.acp_bbcodes_display_bbcodes
 397              * @var    array    row                Array with current bbcode data
 398              * @var    array    bbcodes_array    Array of bbcodes template data
 399              * @var    string    u_action        The u_action link
 400              * @since 3.1.0-a3
 401              */
 402              $vars = array('bbcodes_array', 'row', 'u_action');
 403              extract($phpbb_dispatcher->trigger_event('core.acp_bbcodes_display_bbcodes', compact($vars)));
 404  
 405              $template->assign_block_vars('bbcodes', $bbcodes_array);
 406  
 407          }
 408          $db->sql_freeresult($result);
 409      }
 410  
 411      /*
 412      * Build regular expression for custom bbcode
 413      */
 414  	function build_regexp(&$bbcode_match, &$bbcode_tpl)
 415      {
 416          $bbcode_match = trim($bbcode_match);
 417          $bbcode_tpl = trim($bbcode_tpl);
 418  
 419          // Allow unicode characters for URL|LOCAL_URL|RELATIVE_URL|INTTEXT tokens
 420          $utf8 = preg_match('/(URL|LOCAL_URL|RELATIVE_URL|INTTEXT)/', $bbcode_match);
 421  
 422          $utf8_pcre_properties = phpbb_pcre_utf8_support();
 423  
 424          $fp_match = preg_quote($bbcode_match, '!');
 425          $fp_replace = preg_replace('#^\[(.*?)\]#', '[$1:$uid]', $bbcode_match);
 426          $fp_replace = preg_replace('#\[/(.*?)\]$#', '[/$1:$uid]', $fp_replace);
 427  
 428          $sp_match = preg_quote($bbcode_match, '!');
 429          $sp_match = preg_replace('#^\\\\\[(.*?)\\\\\]#', '\[$1:$uid\]', $sp_match);
 430          $sp_match = preg_replace('#\\\\\[/(.*?)\\\\\]$#', '\[/$1:$uid\]', $sp_match);
 431          $sp_replace = $bbcode_tpl;
 432  
 433          // @todo Make sure to change this too if something changed in message parsing
 434          $tokens = array(
 435              'URL'     => array(
 436                  '!(?:(' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('url')) . ')|(' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('www_url')) . '))!ie'    =>    "\$this->bbcode_specialchars(('\$1') ? '\$1' : 'http://\$2')"
 437              ),
 438              'LOCAL_URL'     => array(
 439                  '!(' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('relative_url')) . ')!e'    =>    "\$this->bbcode_specialchars('$1')"
 440              ),
 441              'RELATIVE_URL'    => array(
 442                  '!(' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('relative_url')) . ')!e'    =>    "\$this->bbcode_specialchars('$1')"
 443              ),
 444              'EMAIL' => array(
 445                  '!(' . get_preg_expression('email') . ')!ie'    =>    "\$this->bbcode_specialchars('$1')"
 446              ),
 447              'TEXT' => array(
 448                  '!(.*?)!es'     =>    "str_replace(array(\"\\r\\n\", '\\\"', '\\'', '(', ')'), array(\"\\n\", '\"', '&#39;', '&#40;', '&#41;'), trim('\$1'))"
 449              ),
 450              'SIMPLETEXT' => array(
 451                  '!([a-zA-Z0-9-+.,_ ]+)!'     =>    "$1"
 452              ),
 453              'INTTEXT' => array(
 454                  ($utf8_pcre_properties) ? '!([\p{L}\p{N}\-+,_. ]+)!u' : '!([a-zA-Z0-9\-+,_. ]+)!u'     =>    "$1"
 455              ),
 456              'IDENTIFIER' => array(
 457                  '!([a-zA-Z0-9-_]+)!'     =>    "$1"
 458              ),
 459              'COLOR' => array(
 460                  '!([a-z]+|#[0-9abcdef]+)!i'    =>    '$1'
 461              ),
 462              'NUMBER' => array(
 463                  '!([0-9]+)!'    =>    '$1'
 464              )
 465          );
 466  
 467          $sp_tokens = array(
 468              'URL'     => '(?i)((?:' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('url')) . ')|(?:' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('www_url')) . '))(?-i)',
 469              'LOCAL_URL'     => '(?i)(' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('relative_url')) . ')(?-i)',
 470              'RELATIVE_URL'     => '(?i)(' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('relative_url')) . ')(?-i)',
 471              'EMAIL' => '(' . get_preg_expression('email') . ')',
 472              'TEXT' => '(.*?)',
 473              'SIMPLETEXT' => '([a-zA-Z0-9-+.,_ ]+)',
 474              'INTTEXT' => ($utf8_pcre_properties) ? '([\p{L}\p{N}\-+,_. ]+)' : '([a-zA-Z0-9\-+,_. ]+)',
 475              'IDENTIFIER' => '([a-zA-Z0-9-_]+)',
 476              'COLOR' => '([a-zA-Z]+|#[0-9abcdefABCDEF]+)',
 477              'NUMBER' => '([0-9]+)',
 478          );
 479  
 480          $pad = 0;
 481          $modifiers = 'i';
 482          $modifiers .= ($utf8 && $utf8_pcre_properties) ? 'u' : '';
 483  
 484          if (preg_match_all('/\{(' . implode('|', array_keys($tokens)) . ')[0-9]*\}/i', $bbcode_match, $m))
 485          {
 486              foreach ($m[0] as $n => $token)
 487              {
 488                  $token_type = $m[1][$n];
 489  
 490                  reset($tokens[strtoupper($token_type)]);
 491                  list($match, $replace) = each($tokens[strtoupper($token_type)]);
 492  
 493                  // Pad backreference numbers from tokens
 494                  if (preg_match_all('/(?<!\\\\)\$([0-9]+)/', $replace, $repad))
 495                  {
 496                      $repad = $pad + sizeof(array_unique($repad[0]));
 497                      $replace = preg_replace('/(?<!\\\\)\$([0-9]+)/e', "'\${' . (\$1 + \$pad) . '}'", $replace);
 498                      $pad = $repad;
 499                  }
 500  
 501                  // Obtain pattern modifiers to use and alter the regex accordingly
 502                  $regex = preg_replace('/!(.*)!([a-z]*)/', '$1', $match);
 503                  $regex_modifiers = preg_replace('/!(.*)!([a-z]*)/', '$2', $match);
 504  
 505                  for ($i = 0, $size = strlen($regex_modifiers); $i < $size; ++$i)
 506                  {
 507                      if (strpos($modifiers, $regex_modifiers[$i]) === false)
 508                      {
 509                          $modifiers .= $regex_modifiers[$i];
 510  
 511                          if ($regex_modifiers[$i] == 'e')
 512                          {
 513                              $fp_replace = "'" . str_replace("'", "\\'", $fp_replace) . "'";
 514                          }
 515                      }
 516  
 517                      if ($regex_modifiers[$i] == 'e')
 518                      {
 519                          $replace = "'.$replace.'";
 520                      }
 521                  }
 522  
 523                  $fp_match = str_replace(preg_quote($token, '!'), $regex, $fp_match);
 524                  $fp_replace = str_replace($token, $replace, $fp_replace);
 525  
 526                  $sp_match = str_replace(preg_quote($token, '!'), $sp_tokens[$token_type], $sp_match);
 527  
 528                  // Prepend the board url to local relative links
 529                  $replace_prepend = ($token_type === 'LOCAL_URL') ? generate_board_url() . '/' : '';
 530  
 531                  $sp_replace = str_replace($token, $replace_prepend . '${' . ($n + 1) . '}', $sp_replace);
 532              }
 533  
 534              $fp_match = '!' . $fp_match . '!' . $modifiers;
 535              $sp_match = '!' . $sp_match . '!s' . (($utf8) ? 'u' : '');
 536  
 537              if (strpos($fp_match, 'e') !== false)
 538              {
 539                  $fp_replace = str_replace("'.'", '', $fp_replace);
 540                  $fp_replace = str_replace(".''.", '.', $fp_replace);
 541              }
 542          }
 543          else
 544          {
 545              // No replacement is present, no need for a second-pass pattern replacement
 546              // A simple str_replace will suffice
 547              $fp_match = '!' . $fp_match . '!' . $modifiers;
 548              $sp_match = $fp_replace;
 549              $sp_replace = '';
 550          }
 551  
 552          // Lowercase tags
 553          $bbcode_tag = preg_replace('/.*?\[([a-z0-9_-]+=?).*/i', '$1', $bbcode_match);
 554          $bbcode_search = preg_replace('/.*?\[([a-z0-9_-]+)=?.*/i', '$1', $bbcode_match);
 555  
 556          if (!preg_match('/^[a-zA-Z0-9_-]+=?$/', $bbcode_tag))
 557          {
 558              global $user;
 559              trigger_error($user->lang['BBCODE_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
 560          }
 561  
 562          $fp_match = preg_replace('#\[/?' . $bbcode_search . '#ie', "strtolower('\$0')", $fp_match);
 563          $fp_replace = preg_replace('#\[/?' . $bbcode_search . '#ie', "strtolower('\$0')", $fp_replace);
 564          $sp_match = preg_replace('#\[/?' . $bbcode_search . '#ie', "strtolower('\$0')", $sp_match);
 565          $sp_replace = preg_replace('#\[/?' . $bbcode_search . '#ie', "strtolower('\$0')", $sp_replace);
 566  
 567          return array(
 568              'bbcode_tag'                => $bbcode_tag,
 569              'first_pass_match'            => $fp_match,
 570              'first_pass_replace'        => $fp_replace,
 571              'second_pass_match'            => $sp_match,
 572              'second_pass_replace'        => $sp_replace
 573          );
 574      }
 575  }


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1