[ Index ] |
PHP Cross Reference of MyBB |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * MyBB 1.6 4 * Copyright 2010 MyBB Group, All Rights Reserved 5 * 6 * Website: http://mybb.com 7 * License: http://mybb.com/about/license 8 * 9 * $Id$ 10 */ 11 12 // Disallow direct access to this file for security reasons 13 if(!defined("IN_MYBB")) 14 { 15 die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined."); 16 } 17 18 $page->add_breadcrumb_item($lang->mycode, "index.php?module=config-mycode"); 19 20 $plugins->run_hooks("admin_config_mycode_begin"); 21 22 if($mybb->input['action'] == "toggle_status") 23 { 24 if(!verify_post_check($mybb->input['my_post_key'])) 25 { 26 flash_message($lang->invalid_post_verify_key2, 'error'); 27 admin_redirect("index.php?module=config-mycode"); 28 } 29 30 $plugins->run_hooks("admin_config_mycode_toggle_status"); 31 32 $query = $db->simple_select("mycode", "*", "cid='".intval($mybb->input['cid'])."'"); 33 $mycode = $db->fetch_array($query); 34 35 if(!$mycode['cid']) 36 { 37 flash_message($lang->error_invalid_mycode, 'error'); 38 admin_redirect("index.php?module=config-mycode"); 39 } 40 41 if($mycode['active'] == 1) 42 { 43 $new_status = 0; 44 $phrase = $lang->success_deactivated_mycode; 45 } 46 else 47 { 48 $new_status = 1; 49 $phrase = $lang->success_activated_mycode; 50 } 51 $mycode_update = array( 52 'active' => $new_status, 53 ); 54 55 $db->update_query("mycode", $mycode_update, "cid='".intval($mybb->input['cid'])."'"); 56 57 $cache->update_mycode(); 58 59 $plugins->run_hooks("admin_config_mycode_toggle_status_commit"); 60 61 // Log admin action 62 log_admin_action($mycode['cid'], $mycode['title'], $new_status); 63 64 flash_message($phrase, 'success'); 65 admin_redirect('index.php?module=config-mycode'); 66 } 67 68 if($mybb->input['action'] == "xmlhttp_test_mycode" && $mybb->request_method == "post") 69 { 70 $plugins->run_hooks("admin_config_mycode_xmlhttp_test_mycode_start"); 71 72 // Send no cache headers 73 header("Expires: Sat, 1 Jan 2000 01:00:00 GMT"); 74 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 75 header("Cache-Control: no-cache, must-revalidate"); 76 header("Pragma: no-cache"); 77 header("Content-type: text/html"); 78 79 $sandbox = test_regex($mybb->input['regex'], $mybb->input['replacement'], $mybb->input['test_value']); 80 81 $plugins->run_hooks("admin_config_mycode_xmlhttp_test_mycode_end"); 82 83 echo $sandbox['actual']; 84 exit; 85 } 86 87 if($mybb->input['action'] == "add") 88 { 89 $plugins->run_hooks("admin_config_mycode_add"); 90 91 if($mybb->request_method == "post") 92 { 93 if(!trim($mybb->input['title'])) 94 { 95 $errors[] = $lang->error_missing_title; 96 } 97 98 if(!trim($mybb->input['regex'])) 99 { 100 $errors[] = $lang->error_missing_regex; 101 } 102 103 if(!trim($mybb->input['replacement'])) 104 { 105 $errors[] = $lang->error_missing_replacement; 106 } 107 108 if($mybb->input['test']) 109 { 110 $errors[] = $lang->changes_not_saved; 111 $sandbox = test_regex($mybb->input['regex'], $mybb->input['replacement'], $mybb->input['test_value']); 112 } 113 114 if(!$errors) 115 { 116 $new_mycode = array( 117 'title' => $db->escape_string($mybb->input['title']), 118 'description' => $db->escape_string($mybb->input['description']), 119 'regex' => $db->escape_string(str_replace("\x0", "", $mybb->input['regex'])), 120 'replacement' => $db->escape_string($mybb->input['replacement']), 121 'active' => $db->escape_string($mybb->input['active']), 122 'parseorder' => intval($mybb->input['parseorder']) 123 ); 124 125 $cid = $db->insert_query("mycode", $new_mycode); 126 127 $cache->update_mycode(); 128 129 $plugins->run_hooks("admin_config_mycode_add_commit"); 130 131 // Log admin action 132 log_admin_action($cid, $mybb->input['title']); 133 134 flash_message($lang->success_added_mycode, 'success'); 135 admin_redirect('index.php?module=config-mycode'); 136 } 137 } 138 139 $sub_tabs['mycode'] = array( 140 'title' => $lang->mycode, 141 'link' => "index.php?module=config-mycode", 142 'description' => $lang->mycode_desc 143 ); 144 145 $sub_tabs['add_new_mycode'] = array( 146 'title' => $lang->add_new_mycode, 147 'link' => "index.php?module=config-mycode&action=add", 148 'description' => $lang->add_new_mycode_desc 149 ); 150 151 $page->extra_header .= " 152 <script type=\"text/javascript\"> 153 var my_post_key = '".$mybb->post_code."'; 154 </script>"; 155 156 $page->add_breadcrumb_item($lang->add_new_mycode); 157 $page->output_header($lang->custom_mycode." - ".$lang->add_new_mycode); 158 $page->output_nav_tabs($sub_tabs, 'add_new_mycode'); 159 160 if($errors) 161 { 162 $page->output_inline_error($errors); 163 } 164 else 165 { 166 $mybb->input['active'] = 1; 167 } 168 169 $form = new Form("index.php?module=config-mycode&action=add", "post", "add"); 170 $form_container = new FormContainer($lang->add_mycode); 171 $form_container->output_row($lang->title." <em>*</em>", '', $form->generate_text_box('title', $mybb->input['title'], array('id' => 'title')), 'title'); 172 $form_container->output_row($lang->short_description, '', $form->generate_text_box('description', $mybb->input['description'], array('id' => 'description')), 'description'); 173 $form_container->output_row($lang->regular_expression." <em>*</em>", $lang->regular_expression_desc.'<br /><strong>'.$lang->example.'</strong> \[b\](.*?)\[/b\]', $form->generate_text_area('regex', $mybb->input['regex'], array('id' => 'regex')), 'regex'); 174 $form_container->output_row($lang->replacement." <em>*</em>", $lang->replacement_desc.'<br /><strong>'.$lang->example.'</strong> <strong>$1</strong>', $form->generate_text_area('replacement', $mybb->input['replacement'], array('id' => 'replacement')), 'replacement'); 175 $form_container->output_row($lang->enabled." <em>*</em>", '', $form->generate_yes_no_radio('active', $mybb->input['active'])); 176 $form_container->output_row($lang->parse_order, $lang->parse_order_desc, $form->generate_text_box('parseorder', $mybb->input['parseorder'], array('id' => 'parseorder')), 'parseorder'); 177 $form_container->end(); 178 179 $buttons[] = $form->generate_submit_button($lang->save_mycode); 180 $form->output_submit_wrapper($buttons); 181 182 // Sandbox 183 echo "<br />\n"; 184 $form_container = new FormContainer($lang->sandbox); 185 $form_container->output_row($lang->sandbox_desc); 186 $form_container->output_row($lang->test_value, $lang->test_value_desc, $form->generate_text_area('test_value', $mybb->input['test_value'], array('id' => 'test_value'))."<br />".$form->generate_submit_button($lang->test, array('id' => 'test', 'name' => 'test')), 'test_value'); 187 $form_container->output_row($lang->result_html, $lang->result_html_desc, $form->generate_text_area('result_html', $sandbox['html'], array('id' => 'result_html', 'disabled' => 1)), 'result_html'); 188 $form_container->output_row($lang->result_actual, $lang->result_actual_desc, "<div id=\"result_actual\">{$sandbox['actual']}</div>"); 189 $form_container->end(); 190 echo '<script type="text/javascript" src="./jscripts/mycode_sandbox.js"></script>'; 191 echo '<script type="text/javascript"> 192 //<![CDATA[ 193 Event.observe(window, "load", function() { 194 new MyCodeSandbox("./index.php?module=config-mycode&action=xmlhttp_test_mycode", $("test"), $("regex"), $("replacement"), $("test_value"), $("result_html"), $("result_actual")); 195 }); 196 //]]> 197 </script>'; 198 199 $form->end(); 200 201 $page->output_footer(); 202 } 203 204 if($mybb->input['action'] == "edit") 205 { 206 $plugins->run_hooks("admin_config_mycode_edit"); 207 208 $query = $db->simple_select("mycode", "*", "cid='".intval($mybb->input['cid'])."'"); 209 $mycode = $db->fetch_array($query); 210 211 if(!$mycode['cid']) 212 { 213 flash_message($lang->error_invalid_mycode, 'error'); 214 admin_redirect("index.php?module=config-mycode"); 215 } 216 217 if($mybb->request_method == "post") 218 { 219 if(!trim($mybb->input['title'])) 220 { 221 $errors[] = $lang->error_missing_title; 222 } 223 224 if(!trim($mybb->input['regex'])) 225 { 226 $errors[] = $lang->error_missing_regex; 227 } 228 229 if(!trim($mybb->input['replacement'])) 230 { 231 $errors[] = $lang->error_missing_replacement; 232 } 233 234 if($mybb->input['test']) 235 { 236 $errors[] = $lang->changes_not_saved; 237 $sandbox = test_regex($mybb->input['regex'], $mybb->input['replacement'], $mybb->input['test_value']); 238 } 239 240 if(!$errors) 241 { 242 $updated_mycode = array( 243 'title' => $db->escape_string($mybb->input['title']), 244 'description' => $db->escape_string($mybb->input['description']), 245 'regex' => $db->escape_string(str_replace("\x0", "", $mybb->input['regex'])), 246 'replacement' => $db->escape_string($mybb->input['replacement']), 247 'active' => $db->escape_string($mybb->input['active']), 248 'parseorder' => intval($mybb->input['parseorder']) 249 ); 250 251 $db->update_query("mycode", $updated_mycode, "cid='".intval($mybb->input['cid'])."'"); 252 253 $cache->update_mycode(); 254 255 $plugins->run_hooks("admin_config_mycode_edit_commit"); 256 257 // Log admin action 258 log_admin_action($mycode['cid'], $mybb->input['title']); 259 260 flash_message($lang->success_updated_mycode, 'success'); 261 admin_redirect('index.php?module=config-mycode'); 262 } 263 } 264 265 $sub_tabs['edit_mycode'] = array( 266 'title' => $lang->edit_mycode, 267 'link' => "index.php?module=config-mycode&action=edit", 268 'description' => $lang->edit_mycode_desc 269 ); 270 271 $page->extra_header .= " 272 <script type=\"text/javascript\"> 273 var my_post_key = '".$mybb->post_code."'; 274 </script>"; 275 276 $page->add_breadcrumb_item($lang->edit_mycode); 277 $page->output_header($lang->custom_mycode." - ".$lang->edit_mycode); 278 $page->output_nav_tabs($sub_tabs, 'edit_mycode'); 279 280 $form = new Form("index.php?module=config-mycode&action=edit", "post", "edit"); 281 echo $form->generate_hidden_field('cid', $mycode['cid']); 282 283 if($errors) 284 { 285 $page->output_inline_error($errors); 286 } 287 else 288 { 289 $mybb->input = $mycode; 290 } 291 292 $form_container = new FormContainer($lang->edit_mycode); 293 $form_container->output_row($lang->title." <em>*</em>", '', $form->generate_text_box('title', $mybb->input['title'], array('id' => 'title')), 'title'); 294 $form_container->output_row($lang->short_description, '', $form->generate_text_box('description', $mybb->input['description'], array('id' => 'description')), 'description'); 295 $form_container->output_row($lang->regular_expression." <em>*</em>", $lang->regular_expression_desc.'<br /><strong>'.$lang->example.'</strong> \[b\](.*?)\[/b\]', $form->generate_text_area('regex', $mybb->input['regex'], array('id' => 'regex')), 'regex'); 296 $form_container->output_row($lang->replacement." <em>*</em>", $lang->replacement_desc.'<br /><strong>'.$lang->example.'</strong> <strong>$1</strong>', $form->generate_text_area('replacement', $mybb->input['replacement'], array('id' => 'replacement')), 'replacement'); 297 $form_container->output_row($lang->enabled." <em>*</em>", '', $form->generate_yes_no_radio('active', $mybb->input['active'])); 298 $form_container->output_row($lang->parse_order, $lang->parse_order_desc, $form->generate_text_box('parseorder', $mybb->input['parseorder'], array('id' => 'parseorder')), 'parseorder'); 299 $form_container->end(); 300 301 $buttons[] = $form->generate_submit_button($lang->save_mycode); 302 303 $form->output_submit_wrapper($buttons); 304 305 // Sandbox 306 echo "<br />\n"; 307 $form_container = new FormContainer($lang->sandbox); 308 $form_container->output_row($lang->sandbox_desc); 309 $form_container->output_row($lang->test_value, $lang->test_value_desc, $form->generate_text_area('test_value', $mybb->input['test_value'], array('id' => 'test_value'))."<br />".$form->generate_submit_button($lang->test, array('id' => 'test', 'name' => 'test')), 'test_value'); 310 $form_container->output_row($lang->result_html, $lang->result_html_desc, $form->generate_text_area('result_html', $sandbox['html'], array('id' => 'result_html', 'disabled' => 1)), 'result_html'); 311 $form_container->output_row($lang->result_actual, $lang->result_actual_desc, "<div id=\"result_actual\">{$sandbox['actual']}</div>"); 312 $form_container->end(); 313 echo '<script type="text/javascript" src="./jscripts/mycode_sandbox.js"></script>'; 314 echo '<script type="text/javascript"> 315 316 Event.observe(window, "load", function() { 317 //<![CDATA[ 318 new MyCodeSandbox("./index.php?module=config-mycode&action=xmlhttp_test_mycode", $("test"), $("regex"), $("replacement"), $("test_value"), $("result_html"), $("result_actual")); 319 }); 320 //]]> 321 </script>'; 322 323 $form->end(); 324 325 $page->output_footer(); 326 } 327 328 if($mybb->input['action'] == "delete") 329 { 330 $plugins->run_hooks("admin_config_mycode_delete"); 331 332 $query = $db->simple_select("mycode", "*", "cid='".intval($mybb->input['cid'])."'"); 333 $mycode = $db->fetch_array($query); 334 335 if(!$mycode['cid']) 336 { 337 flash_message($lang->error_invalid_mycode, 'error'); 338 admin_redirect("index.php?module=config-mycode"); 339 } 340 341 // User clicked no 342 if($mybb->input['no']) 343 { 344 admin_redirect("index.php?module=config-mycode"); 345 } 346 347 if($mybb->request_method == "post") 348 { 349 $db->delete_query("mycode", "cid='{$mycode['cid']}'"); 350 351 $cache->update_mycode(); 352 353 $plugins->run_hooks("admin_config_mycode_delete_commit"); 354 355 // Log admin action 356 log_admin_action($mycode['cid'], $mycode['title']); 357 358 flash_message($lang->success_deleted_mycode, 'success'); 359 admin_redirect("index.php?module=config-mycode"); 360 } 361 else 362 { 363 $page->output_confirm_action("index.php?module=config-mycode&action=delete&cid={$mycode['cid']}", $lang->confirm_mycode_deletion); 364 } 365 } 366 367 if(!$mybb->input['action']) 368 { 369 $plugins->run_hooks("admin_config_mycode_start"); 370 371 $page->output_header($lang->custom_mycode); 372 373 $sub_tabs['mycode'] = array( 374 'title' => $lang->mycode, 375 'link' => "index.php?module=config-mycode", 376 'description' => $lang->mycode_desc 377 ); 378 379 $sub_tabs['add_new_mycode'] = array( 380 'title' => $lang->add_new_mycode, 381 'link' => "index.php?module=config-mycode&action=add" 382 ); 383 384 $page->output_nav_tabs($sub_tabs, 'mycode'); 385 386 $table = new Table; 387 $table->construct_header($lang->title); 388 $table->construct_header($lang->controls, array('class' => 'align_center', 'width' => 150)); 389 390 $query = $db->simple_select("mycode", "*", "", array('order_by' => 'parseorder')); 391 while($mycode = $db->fetch_array($query)) 392 { 393 if($mycode['active'] == 1) 394 { 395 $phrase = $lang->deactivate_mycode; 396 $indicator = ''; 397 } 398 else 399 { 400 $phrase = $lang->activate_mycode; 401 $indicator = "<div class=\"float_right\"><small>{$lang->deactivated}</small></div>"; 402 } 403 404 if($mycode['description']) 405 { 406 $mycode['description'] = "<small>{$mycode['description']}</small>"; 407 } 408 409 $table->construct_cell("{$indicator}<strong><a href=\"index.php?module=config-mycode&action=edit&cid={$mycode['cid']}\">{$mycode['title']}</a></strong><br />{$mycode['description']}"); 410 411 $popup = new PopupMenu("mycode_{$mycode['cid']}", $lang->options); 412 $popup->add_item($lang->edit_mycode, "index.php?module=config-mycode&action=edit&cid={$mycode['cid']}"); 413 $popup->add_item($phrase, "index.php?module=config-mycode&action=toggle_status&cid={$mycode['cid']}&my_post_key={$mybb->post_code}"); 414 $popup->add_item($lang->delete_mycode, "index.php?module=config-mycode&action=delete&cid={$mycode['cid']}&my_post_key={$mybb->post_code}", "return AdminCP.deleteConfirmation(this, '{$lang->confirm_mycode_deletion}')"); 415 $table->construct_cell($popup->fetch(), array('class' => 'align_center')); 416 $table->construct_row(); 417 } 418 419 if($table->num_rows() == 0) 420 { 421 $table->construct_cell($lang->no_mycode, array('colspan' => 2)); 422 $table->construct_row(); 423 } 424 425 $table->output($lang->custom_mycode); 426 427 $page->output_footer(); 428 } 429 430 function test_regex($regex, $replacement, $test) 431 { 432 $array = array(); 433 $array['actual'] = @preg_replace("#".str_replace("\x0", "", $regex)."#si", $replacement, $test); 434 $array['html'] = htmlspecialchars_uni($array['actual']); 435 return $array; 436 } 437 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Oct 8 19:19:50 2013 | Cross-referenced by PHPXref 0.7.1 |