[ Index ]

PHP Cross Reference of MyBB 1.8.29

title

Body

[close]

/admin/modules/config/ -> badwords.php (source)

   1  <?php
   2  /**
   3   * MyBB 1.8
   4   * Copyright 2014 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://www.mybb.com
   7   * License: http://www.mybb.com/about/license
   8   *
   9   */
  10  
  11  // Disallow direct access to this file for security reasons
  12  if(!defined("IN_MYBB"))
  13  {
  14      die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
  15  }
  16  
  17  $page->add_breadcrumb_item($lang->bad_words, "index.php?module=config-badwords");
  18  
  19  $plugins->run_hooks("admin_config_badwords_begin");
  20  
  21  if($mybb->input['action'] == "add")
  22  {
  23      $plugins->run_hooks("admin_config_badwords_add");
  24  
  25      if($mybb->request_method == "post")
  26      {
  27          if(!trim($mybb->input['badword']))
  28          {
  29              $errors[] = $lang->error_missing_bad_word;
  30          }
  31  
  32          if(strlen(trim($mybb->input['badword'])) > 100)
  33          {
  34              $errors[] = $lang->bad_word_max;
  35          }
  36  
  37          if(strlen($mybb->input['replacement']) > 100)
  38          {
  39              $errors[] = $lang->replacement_word_max;
  40          }
  41  
  42          if(!$errors)
  43          {
  44              $query = $db->simple_select("badwords", "bid", "badword = '".$db->escape_string($mybb->input['badword'])."'");
  45  
  46              if($db->num_rows($query))
  47              {
  48                  $errors[] = $lang->error_bad_word_filtered;
  49              }
  50          }
  51  
  52          $badword = trim($mybb->input['badword']);
  53  
  54          if($mybb->get_input('regex', MyBB::INPUT_INT))
  55          {
  56              // Check validity of defined regular expression
  57              if((@preg_match('#'.$badword.'#is', null) === false))
  58              {
  59                  $errors[] = $lang->error_invalid_regex;
  60              }
  61          }
  62          else
  63          {
  64              if(!isset($parser) || !is_object($parser))
  65              {
  66                  require_once  MYBB_ROOT."inc/class_parser.php";
  67                  $parser = new postParser;
  68              }
  69  
  70              $badword = $parser->generate_regex($badword);
  71          }
  72  
  73          // Don't allow certain badword replacements to be added if it would cause an infinite recursive loop.
  74          if(@preg_match('#'.$badword.'#is', $mybb->input['replacement']))
  75          {
  76              $errors[] = $lang->error_replacement_word_invalid;
  77          }
  78  
  79          if(!$errors)
  80          {
  81              $new_badword = array(
  82                  "badword" => $db->escape_string($mybb->input['badword']),
  83                  "regex" => $mybb->get_input('regex', MyBB::INPUT_INT),
  84                  "replacement" => $db->escape_string($mybb->input['replacement'])
  85              );
  86  
  87              $bid = $db->insert_query("badwords", $new_badword);
  88  
  89              $plugins->run_hooks("admin_config_badwords_add_commit");
  90  
  91              // Log admin action
  92              log_admin_action($bid, $mybb->input['badword']);
  93  
  94              $cache->update_badwords();
  95              flash_message($lang->success_added_bad_word, 'success');
  96              admin_redirect("index.php?module=config-badwords");
  97          }
  98      }
  99  
 100      $page->add_breadcrumb_item($lang->add_bad_word);
 101      $page->output_header($lang->bad_words." - ".$lang->add_bad_word);
 102  
 103      $sub_tabs['badwords'] = array(
 104          'title' => $lang->bad_word_filters,
 105          'description' => $lang->bad_word_filters_desc,
 106          'link' => "index.php?module=config-badwords"
 107      );
 108  
 109      $sub_tabs['add_badword'] = array(
 110          'title' => $lang->add_bad_word,
 111          'description' => $lang->add_bad_word_desc,
 112          'link' => "index.php?module=config-badwords&amp;action=add"
 113      );
 114  
 115      $page->output_nav_tabs($sub_tabs, "add_badword");
 116  
 117      $form = new Form("index.php?module=config-badwords&amp;action=add", "post", "add");
 118  
 119      if($errors)
 120      {
 121          $page->output_inline_error($errors);
 122      }
 123  
 124      $form_container = new FormContainer($lang->add_bad_word);
 125      $form_container->output_row($lang->bad_word." <em>*</em>", $lang->bad_word_desc, $form->generate_text_box('badword', $mybb->get_input('badword'), array('id' => 'badword')), 'badword');
 126      $form_container->output_row($lang->replacement, $lang->replacement_desc, $form->generate_text_box('replacement', $mybb->get_input('replacement'), array('id' => 'replacement')), 'replacement');
 127      $form_container->output_row($lang->regex, $lang->regex_desc, $form->generate_yes_no_radio('regex', $mybb->get_input('regex', MyBB::INPUT_INT), array('id' => 'regex')), 'regex');
 128      $form_container->end();
 129      $buttons[] = $form->generate_submit_button($lang->save_bad_word);
 130      $form->output_submit_wrapper($buttons);
 131      $form->end();
 132  
 133      $page->output_footer();
 134  }
 135  
 136  if($mybb->input['action'] == "delete")
 137  {
 138      $query = $db->simple_select("badwords", "*", "bid='".$mybb->get_input('bid', MyBB::INPUT_INT)."'");
 139      $badword = $db->fetch_array($query);
 140  
 141      // Does the bad word not exist?
 142      if(!$badword['bid'])
 143      {
 144          flash_message($lang->error_invalid_bid, 'error');
 145          admin_redirect("index.php?module=config-badwords");
 146      }
 147  
 148      // User clicked no
 149      if($mybb->get_input('no'))
 150      {
 151          admin_redirect("index.php?module=config-badwords");
 152      }
 153  
 154      $plugins->run_hooks("admin_config_badwords_delete");
 155  
 156      if($mybb->request_method == "post")
 157      {
 158          // Delete the bad word
 159          $db->delete_query("badwords", "bid='{$badword['bid']}'");
 160  
 161          $plugins->run_hooks("admin_config_badwords_delete_commit");
 162  
 163          // Log admin action
 164          log_admin_action($badword['bid'], $badword['badword']);
 165  
 166          $cache->update_badwords();
 167  
 168          flash_message($lang->success_deleted_bad_word, 'success');
 169          admin_redirect("index.php?module=config-badwords");
 170      }
 171      else
 172      {
 173          $page->output_confirm_action("index.php?module=config-badwords&action=delete&bid={$badword['bid']}", $lang->confirm_bad_word_deletion);
 174      }
 175  }
 176  
 177  if($mybb->input['action'] == "edit")
 178  {
 179      $query = $db->simple_select("badwords", "*", "bid='".$mybb->get_input('bid', MyBB::INPUT_INT)."'");
 180      $badword = $db->fetch_array($query);
 181  
 182      // Does the bad word not exist?
 183      if(!$badword['bid'])
 184      {
 185          flash_message($lang->error_invalid_bid, 'error');
 186          admin_redirect("index.php?module=config-badwords");
 187      }
 188  
 189      $plugins->run_hooks("admin_config_badwords_edit");
 190  
 191      if($mybb->request_method == "post")
 192      {
 193          if(!trim($mybb->input['badword']))
 194          {
 195              $errors[] = $lang->error_missing_bad_word;
 196          }
 197  
 198          if(strlen(trim($mybb->input['badword'])) > 100)
 199          {
 200              $errors[] = $lang->bad_word_max;
 201          }
 202  
 203          if(strlen($mybb->input['replacement']) > 100)
 204          {
 205              $errors[] = $lang->replacement_word_max;
 206          }
 207  
 208          if(!$errors)
 209          {
 210              $updated_badword = array(
 211                  "badword" => $db->escape_string($mybb->input['badword']),
 212                  "regex" => $mybb->get_input('regex', MyBB::INPUT_INT),
 213                  "replacement" => $db->escape_string($mybb->input['replacement'])
 214              );
 215  
 216              $plugins->run_hooks("admin_config_badwords_edit_commit");
 217  
 218              $db->update_query("badwords", $updated_badword, "bid='{$badword['bid']}'");
 219  
 220              // Log admin action
 221              log_admin_action($badword['bid'], $mybb->input['badword']);
 222  
 223              $cache->update_badwords();
 224  
 225              flash_message($lang->success_updated_bad_word, 'success');
 226              admin_redirect("index.php?module=config-badwords");
 227          }
 228      }
 229  
 230      $page->add_breadcrumb_item($lang->edit_bad_word);
 231      $page->output_header($lang->bad_words." - ".$lang->edit_bad_word);
 232  
 233      $sub_tabs['editbadword'] = array(
 234          'title' => $lang->edit_bad_word,
 235          'description' => $lang->edit_bad_word_desc,
 236          'link' => "index.php?module=config-badwords"
 237      );
 238  
 239      $page->output_nav_tabs($sub_tabs, "editbadword");
 240  
 241      $form = new Form("index.php?module=config-badwords&amp;action=edit&amp;bid={$badword['bid']}", "post");
 242  
 243      if($errors)
 244      {
 245          $page->output_inline_error($errors);
 246          $badword_data = $mybb->input;
 247      }
 248      else
 249      {
 250          $badword_data = $badword;
 251      }
 252  
 253      $form_container = new FormContainer($lang->edit_bad_word);
 254      $form_container->output_row($lang->bad_word." <em>*</em>", $lang->bad_word_desc, $form->generate_text_box('badword', $badword_data['badword'], array('id' => 'badword')), 'badword');
 255      $form_container->output_row($lang->replacement, $lang->replacement_desc, $form->generate_text_box('replacement', $badword_data['replacement'], array('id' => 'replacement')), 'replacement');
 256      $form_container->output_row($lang->regex, $lang->regex_desc, $form->generate_yes_no_radio('regex', (int)$badword_data['regex'], array('id' => 'regex')), 'regex');
 257      $form_container->end();
 258      $buttons[] = $form->generate_submit_button($lang->save_bad_word);
 259      $form->output_submit_wrapper($buttons);
 260      $form->end();
 261  
 262      $page->output_footer();
 263  }
 264  
 265  if(!$mybb->input['action'])
 266  {
 267      $page->output_header($lang->bad_words);
 268  
 269      $sub_tabs['badwords'] = array(
 270          'title' => $lang->bad_word_filters,
 271          'description' => $lang->bad_word_filters_desc,
 272          'link' => "index.php?module=config-badwords"
 273      );
 274  
 275      $sub_tabs['add_badword'] = array(
 276          'title' => $lang->add_bad_word,
 277          'description' => $lang->add_bad_word_desc,
 278          'link' => "index.php?module=config-badwords&amp;action=add"
 279      );
 280  
 281      $plugins->run_hooks("admin_config_badwords_start");
 282  
 283      $page->output_nav_tabs($sub_tabs, "badwords");
 284  
 285      $query = $db->simple_select("badwords", "COUNT(bid) AS badwords");
 286      $total_rows = $db->fetch_field($query, "badwords");
 287  
 288      $pagenum = $mybb->get_input('page', MyBB::INPUT_INT);
 289      if($pagenum)
 290      {
 291          $start = ($pagenum - 1) * 20;
 292          $pages = ceil($total_rows / 20);
 293          if($pagenum > $pages)
 294          {
 295              $start = 0;
 296              $pagenum = 1;
 297          }
 298      }
 299      else
 300      {
 301          $start = 0;
 302          $pagenum = 1;
 303      }
 304  
 305      $table = new Table;
 306      $table->construct_header($lang->bad_word);
 307      $table->construct_header($lang->replacement, array("width" => "50%"));
 308      $table->construct_header($lang->regex, array("class" => "align_center", "width" => "20%"));
 309      $table->construct_header($lang->controls, array("class" => "align_center", "width" => 150, "colspan" => 2));
 310  
 311      $query = $db->simple_select("badwords", "*", "", array('limit_start' => $start, 'limit' => 20, "order_by" => "badword", "order_dir" => "asc"));
 312      while($badword = $db->fetch_array($query))
 313      {
 314          $badword['badword'] = htmlspecialchars_uni($badword['badword']);
 315          $badword['replacement'] = htmlspecialchars_uni($badword['replacement']);
 316          if(!$badword['replacement'])
 317          {
 318              $badword['replacement'] = '*****';
 319          }
 320  
 321          $regex = $lang->no;
 322          if($badword['regex'])
 323          {
 324              $regex = $lang->yes;
 325          }
 326  
 327          $table->construct_cell($badword['badword']);
 328          $table->construct_cell($badword['replacement']);
 329          $table->construct_cell($regex, array("class" => "align_center"));
 330          $table->construct_cell("<a href=\"index.php?module=config-badwords&amp;action=edit&amp;bid={$badword['bid']}\">{$lang->edit}</a>", array("class" => "align_center"));
 331          $table->construct_cell("<a href=\"index.php?module=config-badwords&amp;action=delete&amp;bid={$badword['bid']}&amp;my_post_key={$mybb->post_code}\" onclick=\"return AdminCP.deleteConfirmation(this, '{$lang->confirm_bad_word_deletion}');\">{$lang->delete}</a>", array("class" => "align_center"));
 332          $table->construct_row();
 333      }
 334  
 335      if($table->num_rows() == 0)
 336      {
 337          $table->construct_cell($lang->no_bad_words, array("colspan" => 4));
 338          $table->construct_row();
 339      }
 340  
 341      $table->output($lang->bad_word_filters);
 342  
 343      echo "<br />".draw_admin_pagination($pagenum, "20", $total_rows, "index.php?module=config-badwords&amp;page={page}");
 344  
 345      $page->output_footer();
 346  }
 347  


2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup Cross-referenced by PHPXref