Changeset 702 for trunk/forum/includes/acp/acp_bbcodes.php
- Timestamp:
- Mar 31, 2010, 6:32:40 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/forum/includes/acp/acp_bbcodes.php
r400 r702 3 3 * 4 4 * @package acp 5 * @version $Id : acp_bbcodes.php 8743 2008-08-12 16:03:18Z Kellanved$5 * @version $Id$ 6 6 * @copyright (c) 2005 phpBB Group 7 7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License … … 125 125 case 'create': 126 126 127 $data = $this->build_regexp($bbcode_match, $bbcode_tpl); 128 129 // Make sure the user didn't pick a "bad" name for the BBCode tag. 130 $hard_coded = array('code', 'quote', 'quote=', 'attachment', 'attachment=', 'b', 'i', 'url', 'url=', 'img', 'size', 'size=', 'color', 'color=', 'u', 'list', 'list=', 'email', 'email=', 'flash', 'flash='); 131 132 if (($action == 'modify' && strtolower($data['bbcode_tag']) !== strtolower($row['bbcode_tag'])) || ($action == 'create')) 133 { 134 $sql = 'SELECT 1 as test 135 FROM ' . BBCODES_TABLE . " 136 WHERE LOWER(bbcode_tag) = '" . $db->sql_escape(strtolower($data['bbcode_tag'])) . "'"; 137 $result = $db->sql_query($sql); 138 $info = $db->sql_fetchrow($result); 139 $db->sql_freeresult($result); 140 141 // Grab the end, interrogate the last closing tag 142 if ($info['test'] === '1' || in_array(strtolower($data['bbcode_tag']), $hard_coded) || (preg_match('#\[/([^[]*)]$#', $bbcode_match, $regs) && in_array(strtolower($regs[1]), $hard_coded))) 143 { 144 trigger_error($user->lang['BBCODE_INVALID_TAG_NAME'] . adm_back_link($this->u_action), E_USER_WARNING); 145 } 146 } 147 148 if (substr($data['bbcode_tag'], -1) === '=') 149 { 150 $test = substr($data['bbcode_tag'], 0, -1); 151 } 152 else 153 { 154 $test = $data['bbcode_tag']; 155 } 156 157 if (!preg_match('%\\[' . $test . '[^]]*].*?\\[/' . $test . ']%s', $bbcode_match)) 158 { 159 trigger_error($user->lang['BBCODE_OPEN_ENDED_TAG'] . adm_back_link($this->u_action), E_USER_WARNING); 160 } 161 162 if (strlen($data['bbcode_tag']) > 16) 163 { 164 trigger_error($user->lang['BBCODE_TAG_TOO_LONG'] . adm_back_link($this->u_action), E_USER_WARNING); 165 } 166 167 if (strlen($bbcode_match) > 4000) 168 { 169 trigger_error($user->lang['BBCODE_TAG_DEF_TOO_LONG'] . adm_back_link($this->u_action), E_USER_WARNING); 170 } 171 172 173 if (strlen($bbcode_helpline) > 255) 174 { 175 trigger_error($user->lang['BBCODE_HELPLINE_TOO_LONG'] . adm_back_link($this->u_action), E_USER_WARNING); 176 } 177 178 $sql_ary = array( 179 'bbcode_tag' => $data['bbcode_tag'], 180 'bbcode_match' => $bbcode_match, 181 'bbcode_tpl' => $bbcode_tpl, 182 'display_on_posting' => $display_on_posting, 183 'bbcode_helpline' => $bbcode_helpline, 184 'first_pass_match' => $data['first_pass_match'], 185 'first_pass_replace' => $data['first_pass_replace'], 186 'second_pass_match' => $data['second_pass_match'], 187 'second_pass_replace' => $data['second_pass_replace'] 188 ); 189 190 if ($action == 'create') 191 { 192 $sql = 'SELECT MAX(bbcode_id) as max_bbcode_id 193 FROM ' . BBCODES_TABLE; 194 $result = $db->sql_query($sql); 195 $row = $db->sql_fetchrow($result); 196 $db->sql_freeresult($result); 197 198 if ($row) 199 { 200 $bbcode_id = $row['max_bbcode_id'] + 1; 201 202 // Make sure it is greater than the core bbcode ids... 203 if ($bbcode_id <= NUM_CORE_BBCODES) 127 $warn_text = preg_match('%<[^>]*\{text[\d]*\}[^>]*>%i', $bbcode_tpl); 128 if (!$warn_text || confirm_box(true)) 129 { 130 $data = $this->build_regexp($bbcode_match, $bbcode_tpl); 131 132 // Make sure the user didn't pick a "bad" name for the BBCode tag. 133 $hard_coded = array('code', 'quote', 'quote=', 'attachment', 'attachment=', 'b', 'i', 'url', 'url=', 'img', 'size', 'size=', 'color', 'color=', 'u', 'list', 'list=', 'email', 'email=', 'flash', 'flash='); 134 135 if (($action == 'modify' && strtolower($data['bbcode_tag']) !== strtolower($row['bbcode_tag'])) || ($action == 'create')) 136 { 137 $sql = 'SELECT 1 as test 138 FROM ' . BBCODES_TABLE . " 139 WHERE LOWER(bbcode_tag) = '" . $db->sql_escape(strtolower($data['bbcode_tag'])) . "'"; 140 $result = $db->sql_query($sql); 141 $info = $db->sql_fetchrow($result); 142 $db->sql_freeresult($result); 143 144 // Grab the end, interrogate the last closing tag 145 if ($info['test'] === '1' || in_array(strtolower($data['bbcode_tag']), $hard_coded) || (preg_match('#\[/([^[]*)]$#', $bbcode_match, $regs) && in_array(strtolower($regs[1]), $hard_coded))) 146 { 147 trigger_error($user->lang['BBCODE_INVALID_TAG_NAME'] . adm_back_link($this->u_action), E_USER_WARNING); 148 } 149 } 150 151 if (substr($data['bbcode_tag'], -1) === '=') 152 { 153 $test = substr($data['bbcode_tag'], 0, -1); 154 } 155 else 156 { 157 $test = $data['bbcode_tag']; 158 } 159 160 if (!preg_match('%\\[' . $test . '[^]]*].*?\\[/' . $test . ']%s', $bbcode_match)) 161 { 162 trigger_error($user->lang['BBCODE_OPEN_ENDED_TAG'] . adm_back_link($this->u_action), E_USER_WARNING); 163 } 164 165 if (strlen($data['bbcode_tag']) > 16) 166 { 167 trigger_error($user->lang['BBCODE_TAG_TOO_LONG'] . adm_back_link($this->u_action), E_USER_WARNING); 168 } 169 170 if (strlen($bbcode_match) > 4000) 171 { 172 trigger_error($user->lang['BBCODE_TAG_DEF_TOO_LONG'] . adm_back_link($this->u_action), E_USER_WARNING); 173 } 174 175 176 if (strlen($bbcode_helpline) > 255) 177 { 178 trigger_error($user->lang['BBCODE_HELPLINE_TOO_LONG'] . adm_back_link($this->u_action), E_USER_WARNING); 179 } 180 181 $sql_ary = array( 182 'bbcode_tag' => $data['bbcode_tag'], 183 'bbcode_match' => $bbcode_match, 184 'bbcode_tpl' => $bbcode_tpl, 185 'display_on_posting' => $display_on_posting, 186 'bbcode_helpline' => $bbcode_helpline, 187 'first_pass_match' => $data['first_pass_match'], 188 'first_pass_replace' => $data['first_pass_replace'], 189 'second_pass_match' => $data['second_pass_match'], 190 'second_pass_replace' => $data['second_pass_replace'] 191 ); 192 193 if ($action == 'create') 194 { 195 $sql = 'SELECT MAX(bbcode_id) as max_bbcode_id 196 FROM ' . BBCODES_TABLE; 197 $result = $db->sql_query($sql); 198 $row = $db->sql_fetchrow($result); 199 $db->sql_freeresult($result); 200 201 if ($row) 202 { 203 $bbcode_id = $row['max_bbcode_id'] + 1; 204 205 // Make sure it is greater than the core bbcode ids... 206 if ($bbcode_id <= NUM_CORE_BBCODES) 207 { 208 $bbcode_id = NUM_CORE_BBCODES + 1; 209 } 210 } 211 else 204 212 { 205 213 $bbcode_id = NUM_CORE_BBCODES + 1; 206 214 } 215 216 if ($bbcode_id > 1511) 217 { 218 trigger_error($user->lang['TOO_MANY_BBCODES'] . adm_back_link($this->u_action), E_USER_WARNING); 219 } 220 221 $sql_ary['bbcode_id'] = (int) $bbcode_id; 222 223 $db->sql_query('INSERT INTO ' . BBCODES_TABLE . $db->sql_build_array('INSERT', $sql_ary)); 224 $cache->destroy('sql', BBCODES_TABLE); 225 226 $lang = 'BBCODE_ADDED'; 227 $log_action = 'LOG_BBCODE_ADD'; 207 228 } 208 229 else 209 230 { 210 $bbcode_id = NUM_CORE_BBCODES + 1; 211 } 212 213 if ($bbcode_id > 1511) 214 { 215 trigger_error($user->lang['TOO_MANY_BBCODES'] . adm_back_link($this->u_action), E_USER_WARNING); 216 } 217 218 $sql_ary['bbcode_id'] = (int) $bbcode_id; 219 220 $db->sql_query('INSERT INTO ' . BBCODES_TABLE . $db->sql_build_array('INSERT', $sql_ary)); 221 $cache->destroy('sql', BBCODES_TABLE); 222 223 $lang = 'BBCODE_ADDED'; 224 $log_action = 'LOG_BBCODE_ADD'; 231 $sql = 'UPDATE ' . BBCODES_TABLE . ' 232 SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' 233 WHERE bbcode_id = ' . $bbcode_id; 234 $db->sql_query($sql); 235 $cache->destroy('sql', BBCODES_TABLE); 236 237 $lang = 'BBCODE_EDITED'; 238 $log_action = 'LOG_BBCODE_EDIT'; 239 } 240 241 add_log('admin', $log_action, $data['bbcode_tag']); 242 243 trigger_error($user->lang[$lang] . adm_back_link($this->u_action)); 225 244 } 226 245 else 227 246 { 228 $sql = 'UPDATE ' . BBCODES_TABLE . ' 229 SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' 230 WHERE bbcode_id = ' . $bbcode_id; 231 $db->sql_query($sql); 232 $cache->destroy('sql', BBCODES_TABLE); 233 234 $lang = 'BBCODE_EDITED'; 235 $log_action = 'LOG_BBCODE_EDIT'; 236 } 237 238 add_log('admin', $log_action, $data['bbcode_tag']); 239 240 trigger_error($user->lang[$lang] . adm_back_link($this->u_action)); 247 confirm_box(false, $user->lang['BBCODE_DANGER'], build_hidden_fields(array( 248 'action' => $action, 249 'bbcode' => $bbcode_id, 250 'bbcode_match' => $bbcode_match, 251 'bbcode_tpl' => htmlspecialchars($bbcode_tpl), 252 'bbcode_helpline' => $bbcode_helpline, 253 'display_on_posting' => $display_on_posting, 254 )) 255 , 'confirm_bbcode.html'); 256 } 241 257 242 258 break; … … 300 316 $bbcode_match = trim($bbcode_match); 301 317 $bbcode_tpl = trim($bbcode_tpl); 318 $utf8 = strpos($bbcode_match, 'INTTEXT') !== false; 319 320 // make sure we have utf8 support 321 $utf8_pcre_properties = false; 322 if (version_compare(PHP_VERSION, '5.1.0', '>=') || (version_compare(PHP_VERSION, '5.0.0-dev', '<=') && version_compare(PHP_VERSION, '4.4.0', '>='))) 323 { 324 // While this is the proper range of PHP versions, PHP may not be linked with the bundled PCRE lib and instead with an older version 325 if (@preg_match('/\p{L}/u', 'a') !== false) 326 { 327 $utf8_pcre_properties = true; 328 } 329 } 302 330 303 331 $fp_match = preg_quote($bbcode_match, '!'); … … 326 354 'SIMPLETEXT' => array( 327 355 '!([a-zA-Z0-9-+.,_ ]+)!' => "$1" 356 ), 357 'INTTEXT' => array( 358 ($utf8_pcre_properties) ? '!([\p{L}\p{N}\-+,_. ]+)!u' : '!([a-zA-Z0-9\-+,_. ]+)!u' => "$1" 328 359 ), 329 360 'IDENTIFIER' => array( … … 344 375 'TEXT' => '(.*?)', 345 376 'SIMPLETEXT' => '([a-zA-Z0-9-+.,_ ]+)', 377 'INTTEXT' => ($utf8_pcre_properties) ? '([\p{L}\p{N}\-+,_. ]+)' : '([a-zA-Z0-9\-+,_. ]+)', 346 378 'IDENTIFIER' => '([a-zA-Z0-9-_]+)', 347 379 'COLOR' => '([a-zA-Z]+|#[0-9abcdefABCDEF]+)', … … 351 383 $pad = 0; 352 384 $modifiers = 'i'; 385 $modifiers .= ($utf8 && $utf8_pcre_properties) ? 'u' : ''; 353 386 354 387 if (preg_match_all('/\{(' . implode('|', array_keys($tokens)) . ')[0-9]*\}/i', $bbcode_match, $m)) … … 399 432 400 433 $fp_match = '!' . $fp_match . '!' . $modifiers; 401 $sp_match = '!' . $sp_match . '!s' ;434 $sp_match = '!' . $sp_match . '!s' . (($utf8) ? 'u' : ''); 402 435 403 436 if (strpos($fp_match, 'e') !== false)
Note:
See TracChangeset
for help on using the changeset viewer.