PageRenderTime 53ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/wwwroot/phpbb/includes/acp/acp_bbcodes.php

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