[ Index ]

PHP Cross Reference of phpBB-3.2.8-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, $template, $cache, $request, $phpbb_dispatcher, $phpbb_container;
  29          global $phpbb_log;
  30  
  31          $user->add_lang('acp/posting');
  32  
  33          // Set up general vars
  34          $action    = $request->variable('action', '');
  35          $bbcode_id = $request->variable('bbcode', 0);
  36  
  37          $this->tpl_name = 'acp_bbcodes';
  38          $this->page_title = 'ACP_BBCODES';
  39          $form_key = 'acp_bbcodes';
  40  
  41          add_form_key($form_key);
  42  
  43          // Set up mode-specific vars
  44          switch ($action)
  45          {
  46              case 'add':
  47                  $bbcode_match = $bbcode_tpl = $bbcode_helpline = '';
  48                  $display_on_posting = 0;
  49              break;
  50  
  51              case 'edit':
  52                  $sql = 'SELECT bbcode_match, bbcode_tpl, display_on_posting, bbcode_helpline
  53                      FROM ' . BBCODES_TABLE . '
  54                      WHERE bbcode_id = ' . $bbcode_id;
  55                  $result = $db->sql_query($sql);
  56                  $row = $db->sql_fetchrow($result);
  57                  $db->sql_freeresult($result);
  58  
  59                  if (!$row)
  60                  {
  61                      trigger_error($user->lang['BBCODE_NOT_EXIST'] . adm_back_link($this->u_action), E_USER_WARNING);
  62                  }
  63  
  64                  $bbcode_match = $row['bbcode_match'];
  65                  $bbcode_tpl = htmlspecialchars($row['bbcode_tpl']);
  66                  $display_on_posting = $row['display_on_posting'];
  67                  $bbcode_helpline = $row['bbcode_helpline'];
  68              break;
  69  
  70              case 'modify':
  71                  $sql = 'SELECT bbcode_id, bbcode_tag
  72                      FROM ' . BBCODES_TABLE . '
  73                      WHERE bbcode_id = ' . $bbcode_id;
  74                  $result = $db->sql_query($sql);
  75                  $row = $db->sql_fetchrow($result);
  76                  $db->sql_freeresult($result);
  77  
  78                  if (!$row)
  79                  {
  80                      trigger_error($user->lang['BBCODE_NOT_EXIST'] . adm_back_link($this->u_action), E_USER_WARNING);
  81                  }
  82  
  83              // No break here
  84  
  85              case 'create':
  86                  $display_on_posting = $request->variable('display_on_posting', 0);
  87  
  88                  $bbcode_match = $request->variable('bbcode_match', '');
  89                  $bbcode_tpl = htmlspecialchars_decode($request->variable('bbcode_tpl', '', true));
  90                  $bbcode_helpline = $request->variable('bbcode_helpline', '', true);
  91              break;
  92          }
  93  
  94          // Do major work
  95          switch ($action)
  96          {
  97              case 'edit':
  98              case 'add':
  99  
 100                  $tpl_ary = array(
 101                      'S_EDIT_BBCODE'        => true,
 102                      'U_BACK'            => $this->u_action,
 103                      'U_ACTION'            => $this->u_action . '&amp;action=' . (($action == 'add') ? 'create' : 'modify') . (($bbcode_id) ? "&amp;bbcode=$bbcode_id" : ''),
 104  
 105                      'L_BBCODE_USAGE_EXPLAIN'=> sprintf($user->lang['BBCODE_USAGE_EXPLAIN'], '<a href="#down">', '</a>'),
 106                      'BBCODE_MATCH'            => $bbcode_match,
 107                      'BBCODE_TPL'            => $bbcode_tpl,
 108                      'BBCODE_HELPLINE'        => $bbcode_helpline,
 109                      'DISPLAY_ON_POSTING'    => $display_on_posting,
 110                  );
 111  
 112                  $bbcode_tokens = array('TEXT', 'SIMPLETEXT', 'INTTEXT', 'IDENTIFIER', 'NUMBER', 'EMAIL', 'URL', 'LOCAL_URL', 'RELATIVE_URL', 'COLOR');
 113  
 114                  /**
 115                  * Modify custom bbcode template data before we display the add/edit form
 116                  *
 117                  * @event core.acp_bbcodes_edit_add
 118                  * @var    string    action            Type of the action: add|edit
 119                  * @var    array    tpl_ary            Array with custom bbcode add/edit data
 120                  * @var    int        bbcode_id        When editing: the bbcode id,
 121                  *                                when creating: 0
 122                  * @var    array    bbcode_tokens    Array of bbcode tokens
 123                  * @since 3.1.0-a3
 124                  */
 125                  $vars = array('action', 'tpl_ary', 'bbcode_id', 'bbcode_tokens');
 126                  extract($phpbb_dispatcher->trigger_event('core.acp_bbcodes_edit_add', compact($vars)));
 127  
 128                  $template->assign_vars($tpl_ary);
 129  
 130                  foreach ($bbcode_tokens as $token)
 131                  {
 132                      $template->assign_block_vars('token', array(
 133                          'TOKEN'        => '{' . $token . '}',
 134                          'EXPLAIN'    => ($token === 'LOCAL_URL') ? $user->lang(array('tokens', $token), generate_board_url() . '/') : $user->lang(array('tokens', $token)),
 135                      ));
 136                  }
 137  
 138                  return;
 139  
 140              break;
 141  
 142              case 'modify':
 143              case 'create':
 144  
 145                  $sql_ary = $hidden_fields = array();
 146  
 147                  /**
 148                  * Modify custom bbcode data before the modify/create action
 149                  *
 150                  * @event core.acp_bbcodes_modify_create
 151                  * @var    string    action                Type of the action: modify|create
 152                  * @var    array    sql_ary                Array with new bbcode data
 153                  * @var    int        bbcode_id            When editing: the bbcode id,
 154                  *                                    when creating: 0
 155                  * @var    bool    display_on_posting    Display bbcode on posting form
 156                  * @var    string    bbcode_match        The bbcode usage string to match
 157                  * @var    string    bbcode_tpl            The bbcode HTML replacement string
 158                  * @var    string    bbcode_helpline        The bbcode help line string
 159                  * @var    array    hidden_fields        Array of hidden fields for use when
 160                  *                                    submitting form when $warn_text is true
 161                  * @since 3.1.0-a3
 162                  */
 163                  $vars = array(
 164                      'action',
 165                      'sql_ary',
 166                      'bbcode_id',
 167                      'display_on_posting',
 168                      'bbcode_match',
 169                      'bbcode_tpl',
 170                      'bbcode_helpline',
 171                      'hidden_fields',
 172                  );
 173                  extract($phpbb_dispatcher->trigger_event('core.acp_bbcodes_modify_create', compact($vars)));
 174  
 175                  $warn_text = preg_match('%<[^>]*\{text[\d]*\}[^>]*>%i', $bbcode_tpl);
 176  
 177                  if (!$warn_text && !check_form_key($form_key))
 178                  {
 179                      trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
 180                  }
 181  
 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 = (int) $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                          $phpbb_container->get('text_formatter.cache')->invalidate();
 279  
 280                          $lang = 'BBCODE_ADDED';
 281                          $log_action = 'LOG_BBCODE_ADD';
 282                      }
 283                      else
 284                      {
 285                          $sql = 'UPDATE ' . BBCODES_TABLE . '
 286                              SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
 287                              WHERE bbcode_id = ' . $bbcode_id;
 288                          $db->sql_query($sql);
 289                          $cache->destroy('sql', BBCODES_TABLE);
 290                          $phpbb_container->get('text_formatter.cache')->invalidate();
 291  
 292                          $lang = 'BBCODE_EDITED';
 293                          $log_action = 'LOG_BBCODE_EDIT';
 294                      }
 295  
 296                      $phpbb_log->add('admin', $user->data['user_id'], $user->ip, $log_action, false, array($data['bbcode_tag']));
 297  
 298                      /**
 299                      * Event after a BBCode has been added or updated
 300                      *
 301                      * @event core.acp_bbcodes_modify_create_after
 302                      * @var    string    action        Type of the action: modify|create
 303                      * @var    int        bbcode_id    The id of the added or updated bbcode
 304                      * @var    array    sql_ary        Array with bbcode data (read only)
 305                      * @since 3.2.4-RC1
 306                      */
 307                      $vars = array(
 308                          'action',
 309                          'bbcode_id',
 310                          'sql_ary',
 311                      );
 312                      extract($phpbb_dispatcher->trigger_event('core.acp_bbcodes_modify_create_after', compact($vars)));
 313  
 314                      trigger_error($user->lang[$lang] . adm_back_link($this->u_action));
 315                  }
 316                  else
 317                  {
 318                      confirm_box(false, $user->lang['BBCODE_DANGER'], build_hidden_fields(array_merge($hidden_fields, array(
 319                          'action'                => $action,
 320                          'bbcode'                => $bbcode_id,
 321                          'bbcode_match'            => $bbcode_match,
 322                          'bbcode_tpl'            => htmlspecialchars($bbcode_tpl),
 323                          'bbcode_helpline'        => $bbcode_helpline,
 324                          'display_on_posting'    => $display_on_posting,
 325                          )))
 326                      , 'confirm_bbcode.html');
 327                  }
 328  
 329              break;
 330  
 331              case 'delete':
 332  
 333                  $sql = 'SELECT bbcode_tag
 334                      FROM ' . BBCODES_TABLE . "
 335                      WHERE bbcode_id = $bbcode_id";
 336                  $result = $db->sql_query($sql);
 337                  $row = $db->sql_fetchrow($result);
 338                  $db->sql_freeresult($result);
 339  
 340                  if ($row)
 341                  {
 342                      if (confirm_box(true))
 343                      {
 344                          $bbcode_tag = $row['bbcode_tag'];
 345  
 346                          $db->sql_query('DELETE FROM ' . BBCODES_TABLE . " WHERE bbcode_id = $bbcode_id");
 347                          $cache->destroy('sql', BBCODES_TABLE);
 348                          $phpbb_container->get('text_formatter.cache')->invalidate();
 349                          $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_BBCODE_DELETE', false, array($bbcode_tag));
 350  
 351                          /**
 352                          * Event after a BBCode has been deleted
 353                          *
 354                          * @event core.acp_bbcodes_delete_after
 355                          * @var    string    action        Type of the action: delete
 356                          * @var    int        bbcode_id    The id of the deleted bbcode
 357                          * @var    string    bbcode_tag    The tag of the deleted bbcode
 358                          * @since 3.2.4-RC1
 359                          */
 360                          $vars = array(
 361                              'action',
 362                              'bbcode_id',
 363                              'bbcode_tag',
 364                          );
 365                          extract($phpbb_dispatcher->trigger_event('core.acp_bbcodes_delete_after', compact($vars)));
 366  
 367                          if ($request->is_ajax())
 368                          {
 369                              $json_response = new \phpbb\json_response;
 370                              $json_response->send(array(
 371                                  'MESSAGE_TITLE'    => $user->lang['INFORMATION'],
 372                                  'MESSAGE_TEXT'    => $user->lang['BBCODE_DELETED'],
 373                                  'REFRESH_DATA'    => array(
 374                                      'time'    => 3
 375                                  )
 376                              ));
 377                          }
 378                      }
 379                      else
 380                      {
 381                          confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
 382                              'bbcode'    => $bbcode_id,
 383                              'i'            => $id,
 384                              'mode'        => $mode,
 385                              'action'    => $action))
 386                          );
 387                      }
 388                  }
 389  
 390              break;
 391          }
 392  
 393          $u_action = $this->u_action;
 394  
 395          $template_data = array(
 396              'U_ACTION'        => $this->u_action . '&amp;action=add',
 397          );
 398  
 399          $sql_ary = array(
 400              'SELECT'    => 'b.*',
 401              'FROM'        => array(BBCODES_TABLE => 'b'),
 402              'ORDER_BY'    => 'b.bbcode_tag',
 403          );
 404  
 405          /**
 406          *  Modify custom bbcode template data before we display the form
 407          *
 408          * @event core.acp_bbcodes_display_form
 409          * @var    string    action            Type of the action: modify|create
 410          * @var    array    sql_ary            The SQL array to get custom bbcode data
 411          * @var    array    template_data    Array with form template data
 412          * @var    string    u_action        The u_action link
 413          * @since 3.1.0-a3
 414          */
 415          $vars = array('action', 'sql_ary', 'template_data', 'u_action');
 416          extract($phpbb_dispatcher->trigger_event('core.acp_bbcodes_display_form', compact($vars)));
 417  
 418          $result = $db->sql_query($db->sql_build_query('SELECT', $sql_ary));
 419  
 420          $template->assign_vars($template_data);
 421  
 422          while ($row = $db->sql_fetchrow($result))
 423          {
 424              $bbcodes_array = array(
 425                  'BBCODE_TAG'        => $row['bbcode_tag'],
 426                  'U_EDIT'            => $u_action . '&amp;action=edit&amp;bbcode=' . $row['bbcode_id'],
 427                  'U_DELETE'            => $u_action . '&amp;action=delete&amp;bbcode=' . $row['bbcode_id'],
 428              );
 429  
 430              /**
 431              *  Modify display of custom bbcodes in the form
 432              *
 433              * @event core.acp_bbcodes_display_bbcodes
 434              * @var    array    row                Array with current bbcode data
 435              * @var    array    bbcodes_array    Array of bbcodes template data
 436              * @var    string    u_action        The u_action link
 437              * @since 3.1.0-a3
 438              */
 439              $vars = array('bbcodes_array', 'row', 'u_action');
 440              extract($phpbb_dispatcher->trigger_event('core.acp_bbcodes_display_bbcodes', compact($vars)));
 441  
 442              $template->assign_block_vars('bbcodes', $bbcodes_array);
 443  
 444          }
 445          $db->sql_freeresult($result);
 446      }
 447  
 448      /*
 449      * Build regular expression for custom bbcode
 450      */
 451  	function build_regexp(&$bbcode_match, &$bbcode_tpl)
 452      {
 453          $bbcode_match = trim($bbcode_match);
 454          $bbcode_tpl = trim($bbcode_tpl);
 455  
 456          // Allow unicode characters for URL|LOCAL_URL|RELATIVE_URL|INTTEXT tokens
 457          $utf8 = preg_match('/(URL|LOCAL_URL|RELATIVE_URL|INTTEXT)/', $bbcode_match);
 458  
 459          $fp_match = preg_quote($bbcode_match, '!');
 460          $fp_replace = preg_replace('#^\[(.*?)\]#', '[$1:$uid]', $bbcode_match);
 461          $fp_replace = preg_replace('#\[/(.*?)\]$#', '[/$1:$uid]', $fp_replace);
 462  
 463          $sp_match = preg_quote($bbcode_match, '!');
 464          $sp_match = preg_replace('#^\\\\\[(.*?)\\\\\]#', '\[$1:$uid\]', $sp_match);
 465          $sp_match = preg_replace('#\\\\\[/(.*?)\\\\\]$#', '\[/$1:$uid\]', $sp_match);
 466          $sp_replace = $bbcode_tpl;
 467  
 468          // @todo Make sure to change this too if something changed in message parsing
 469          $tokens = array(
 470              'URL'     => array(
 471                  '!(?:(' . 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')"
 472              ),
 473              'LOCAL_URL'     => array(
 474                  '!(' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('relative_url')) . ')!e'    =>    "\$this->bbcode_specialchars('$1')"
 475              ),
 476              'RELATIVE_URL'    => array(
 477                  '!(' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('relative_url')) . ')!e'    =>    "\$this->bbcode_specialchars('$1')"
 478              ),
 479              'EMAIL' => array(
 480                  '!(' . get_preg_expression('email') . ')!ie'    =>    "\$this->bbcode_specialchars('$1')"
 481              ),
 482              'TEXT' => array(
 483                  '!(.*?)!es'     =>    "str_replace(array(\"\\r\\n\", '\\\"', '\\'', '(', ')'), array(\"\\n\", '\"', '&#39;', '&#40;', '&#41;'), trim('\$1'))"
 484              ),
 485              'SIMPLETEXT' => array(
 486                  '!([a-zA-Z0-9-+.,_ ]+)!'     =>    "$1"
 487              ),
 488              'INTTEXT' => array(
 489                  '!([\p{L}\p{N}\-+,_. ]+)!u'     =>    "$1"
 490              ),
 491              'IDENTIFIER' => array(
 492                  '!([a-zA-Z0-9-_]+)!'     =>    "$1"
 493              ),
 494              'COLOR' => array(
 495                  '!([a-z]+|#[0-9abcdef]+)!i'    =>    '$1'
 496              ),
 497              'NUMBER' => array(
 498                  '!([0-9]+)!'    =>    '$1'
 499              )
 500          );
 501  
 502          $sp_tokens = array(
 503              'URL'     => '(?i)((?:' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('url')) . ')|(?:' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('www_url')) . '))(?-i)',
 504              'LOCAL_URL'     => '(?i)(' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('relative_url')) . ')(?-i)',
 505              'RELATIVE_URL'     => '(?i)(' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('relative_url')) . ')(?-i)',
 506              'EMAIL' => '(' . get_preg_expression('email') . ')',
 507              'TEXT' => '(.*?)',
 508              'SIMPLETEXT' => '([a-zA-Z0-9-+.,_ ]+)',
 509              'INTTEXT' => '([\p{L}\p{N}\-+,_. ]+)',
 510              'IDENTIFIER' => '([a-zA-Z0-9-_]+)',
 511              'COLOR' => '([a-zA-Z]+|#[0-9abcdefABCDEF]+)',
 512              'NUMBER' => '([0-9]+)',
 513          );
 514  
 515          $pad = 0;
 516          $modifiers = 'i';
 517          $modifiers .= ($utf8) ? 'u' : '';
 518  
 519          if (preg_match_all('/\{(' . implode('|', array_keys($tokens)) . ')[0-9]*\}/i', $bbcode_match, $m))
 520          {
 521              foreach ($m[0] as $n => $token)
 522              {
 523                  $token_type = $m[1][$n];
 524  
 525                  reset($tokens[strtoupper($token_type)]);
 526                  list($match, $replace) = each($tokens[strtoupper($token_type)]);
 527  
 528                  // Pad backreference numbers from tokens
 529                  if (preg_match_all('/(?<!\\\\)\$([0-9]+)/', $replace, $repad))
 530                  {
 531                      $repad = $pad + count(array_unique($repad[0]));
 532                      $replace = preg_replace_callback('/(?<!\\\\)\$([0-9]+)/', function ($match) use ($pad) {
 533                          return '${' . ($match[1] + $pad) . '}';
 534                      }, $replace);
 535                      $pad = $repad;
 536                  }
 537  
 538                  // Obtain pattern modifiers to use and alter the regex accordingly
 539                  $regex = preg_replace('/!(.*)!([a-z]*)/', '$1', $match);
 540                  $regex_modifiers = preg_replace('/!(.*)!([a-z]*)/', '$2', $match);
 541  
 542                  for ($i = 0, $size = strlen($regex_modifiers); $i < $size; ++$i)
 543                  {
 544                      if (strpos($modifiers, $regex_modifiers[$i]) === false)
 545                      {
 546                          $modifiers .= $regex_modifiers[$i];
 547  
 548                          if ($regex_modifiers[$i] == 'e')
 549                          {
 550                              $fp_replace = "'" . str_replace("'", "\\'", $fp_replace) . "'";
 551                          }
 552                      }
 553  
 554                      if ($regex_modifiers[$i] == 'e')
 555                      {
 556                          $replace = "'.$replace.'";
 557                      }
 558                  }
 559  
 560                  $fp_match = str_replace(preg_quote($token, '!'), $regex, $fp_match);
 561                  $fp_replace = str_replace($token, $replace, $fp_replace);
 562  
 563                  $sp_match = str_replace(preg_quote($token, '!'), $sp_tokens[$token_type], $sp_match);
 564  
 565                  // Prepend the board url to local relative links
 566                  $replace_prepend = ($token_type === 'LOCAL_URL') ? generate_board_url() . '/' : '';
 567  
 568                  $sp_replace = str_replace($token, $replace_prepend . '${' . ($n + 1) . '}', $sp_replace);
 569              }
 570  
 571              $fp_match = '!' . $fp_match . '!' . $modifiers;
 572              $sp_match = '!' . $sp_match . '!s' . (($utf8) ? 'u' : '');
 573  
 574              if (strpos($fp_match, 'e') !== false)
 575              {
 576                  $fp_replace = str_replace("'.'", '', $fp_replace);
 577                  $fp_replace = str_replace(".''.", '.', $fp_replace);
 578              }
 579          }
 580          else
 581          {
 582              // No replacement is present, no need for a second-pass pattern replacement
 583              // A simple str_replace will suffice
 584              $fp_match = '!' . $fp_match . '!' . $modifiers;
 585              $sp_match = $fp_replace;
 586              $sp_replace = '';
 587          }
 588  
 589          // Lowercase tags
 590          $bbcode_tag = preg_replace('/.*?\[([a-z0-9_-]+).*/i', '$1', $bbcode_match);
 591          $bbcode_search = preg_replace('/.*?\[([a-z0-9_-]+).*/i', '$1', $bbcode_match);
 592  
 593          if (!preg_match('/^[a-zA-Z0-9_-]+$/', $bbcode_tag))
 594          {
 595              global $user;
 596              trigger_error($user->lang['BBCODE_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
 597          }
 598  
 599          $fp_match = preg_replace_callback('#\[/?' . $bbcode_search . '#i', function ($match) {
 600              return strtolower($match[0]);
 601          }, $fp_match);
 602          $fp_replace = preg_replace_callback('#\[/?' . $bbcode_search . '#i', function ($match) {
 603              return strtolower($match[0]);
 604          }, $fp_replace);
 605          $sp_match = preg_replace_callback('#\[/?' . $bbcode_search . '#i', function ($match) {
 606              return strtolower($match[0]);
 607          }, $sp_match);
 608          $sp_replace = preg_replace_callback('#\[/?' . $bbcode_search . '#i', function ($match) {
 609              return strtolower($match[0]);
 610          }, $sp_replace);
 611  
 612          return array(
 613              'bbcode_tag'                => $bbcode_tag,
 614              'first_pass_match'            => $fp_match,
 615              'first_pass_replace'        => $fp_replace,
 616              'second_pass_match'            => $sp_match,
 617              'second_pass_replace'        => $sp_replace
 618          );
 619      }
 620  }


Generated: Tue Apr 7 19:42:26 2020 Cross-referenced by PHPXref 0.7.1