[ Index ]

PHP Cross Reference of MyBB 1.8.38

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', '') === 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)
 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)
 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              $query = $db->simple_select("badwords", "bid", "badword = '".$db->escape_string($mybb->input['badword'])."' AND bid != '".$badword['bid']."'");
 211  
 212              if($db->num_rows($query))
 213              {
 214                  $errors[] = $lang->error_bad_word_filtered;
 215              }
 216          }
 217  
 218          $badword_check = trim($mybb->input['badword']);
 219  
 220          if($mybb->get_input('regex', MyBB::INPUT_INT))
 221          {
 222              // Check validity of defined regular expression
 223              if((@preg_match('#'.$badword_check.'#is', '') === false))
 224              {
 225                  $errors[] = $lang->error_invalid_regex;
 226              }
 227          }
 228          else
 229          {
 230              if(!isset($parser) || !is_object($parser))
 231              {
 232                  require_once  MYBB_ROOT."inc/class_parser.php";
 233                  $parser = new postParser;
 234              }
 235  
 236              $badword_check = $parser->generate_regex($badword_check);
 237          }
 238  
 239          // Don't allow certain badword replacements to be added if it would cause an infinite recursive loop.
 240          if(@preg_match('#'.$badword_check.'#is', $mybb->input['replacement']))
 241          {
 242              $errors[] = $lang->error_replacement_word_invalid;
 243          }
 244  
 245          if(!$errors)
 246          {
 247              $updated_badword = array(
 248                  "badword" => $db->escape_string($mybb->input['badword']),
 249                  "regex" => $mybb->get_input('regex', MyBB::INPUT_INT),
 250                  "replacement" => $db->escape_string($mybb->input['replacement'])
 251              );
 252  
 253              $plugins->run_hooks("admin_config_badwords_edit_commit");
 254  
 255              $db->update_query("badwords", $updated_badword, "bid='{$badword['bid']}'");
 256  
 257              // Log admin action
 258              log_admin_action($badword['bid'], $mybb->input['badword']);
 259  
 260              $cache->update_badwords();
 261  
 262              flash_message($lang->success_updated_bad_word, 'success');
 263              admin_redirect("index.php?module=config-badwords");
 264          }
 265      }
 266  
 267      $page->add_breadcrumb_item($lang->edit_bad_word);
 268      $page->output_header($lang->bad_words." - ".$lang->edit_bad_word);
 269  
 270      $sub_tabs['editbadword'] = array(
 271          'title' => $lang->edit_bad_word,
 272          'description' => $lang->edit_bad_word_desc,
 273          'link' => "index.php?module=config-badwords"
 274      );
 275  
 276      $page->output_nav_tabs($sub_tabs, "editbadword");
 277  
 278      $form = new Form("index.php?module=config-badwords&amp;action=edit&amp;bid={$badword['bid']}", "post");
 279  
 280      if($errors)
 281      {
 282          $page->output_inline_error($errors);
 283          $badword_data = $mybb->input;
 284      }
 285      else
 286      {
 287          $badword_data = $badword;
 288      }
 289  
 290      $form_container = new FormContainer($lang->edit_bad_word);
 291      $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');
 292      $form_container->output_row($lang->replacement, $lang->replacement_desc, $form->generate_text_box('replacement', $badword_data['replacement'], array('id' => 'replacement')), 'replacement');
 293      $form_container->output_row($lang->regex, $lang->regex_desc, $form->generate_yes_no_radio('regex', (int)$badword_data['regex'], array('id' => 'regex')), 'regex');
 294      $form_container->end();
 295      $buttons[] = $form->generate_submit_button($lang->save_bad_word);
 296      $form->output_submit_wrapper($buttons);
 297      $form->end();
 298  
 299      $page->output_footer();
 300  }
 301  
 302  if(!$mybb->input['action'])
 303  {
 304      $page->output_header($lang->bad_words);
 305  
 306      $sub_tabs['badwords'] = array(
 307          'title' => $lang->bad_word_filters,
 308          'description' => $lang->bad_word_filters_desc,
 309          'link' => "index.php?module=config-badwords"
 310      );
 311  
 312      $sub_tabs['add_badword'] = array(
 313          'title' => $lang->add_bad_word,
 314          'description' => $lang->add_bad_word_desc,
 315          'link' => "index.php?module=config-badwords&amp;action=add"
 316      );
 317  
 318      $plugins->run_hooks("admin_config_badwords_start");
 319  
 320      $page->output_nav_tabs($sub_tabs, "badwords");
 321  
 322      $query = $db->simple_select("badwords", "COUNT(bid) AS badwords");
 323      $total_rows = $db->fetch_field($query, "badwords");
 324  
 325      $pagenum = $mybb->get_input('page', MyBB::INPUT_INT);
 326      if($pagenum)
 327      {
 328          $start = ($pagenum - 1) * 20;
 329          $pages = ceil($total_rows / 20);
 330          if($pagenum > $pages)
 331          {
 332              $start = 0;
 333              $pagenum = 1;
 334          }
 335      }
 336      else
 337      {
 338          $start = 0;
 339          $pagenum = 1;
 340      }
 341  
 342      $table = new Table;
 343      $table->construct_header($lang->bad_word);
 344      $table->construct_header($lang->replacement, array("width" => "50%"));
 345      $table->construct_header($lang->regex, array("class" => "align_center", "width" => "20%"));
 346      $table->construct_header($lang->controls, array("class" => "align_center", "width" => 150, "colspan" => 2));
 347  
 348      $query = $db->simple_select("badwords", "*", "", array('limit_start' => $start, 'limit' => 20, "order_by" => "badword", "order_dir" => "asc"));
 349      while($badword = $db->fetch_array($query))
 350      {
 351          $badword['badword'] = htmlspecialchars_uni($badword['badword']);
 352          $badword['replacement'] = htmlspecialchars_uni($badword['replacement']);
 353          if(!$badword['replacement'])
 354          {
 355              $badword['replacement'] = '*****';
 356          }
 357  
 358          $regex = $lang->no;
 359          if($badword['regex'])
 360          {
 361              $regex = $lang->yes;
 362          }
 363  
 364          $table->construct_cell($badword['badword']);
 365          $table->construct_cell($badword['replacement']);
 366          $table->construct_cell($regex, array("class" => "align_center"));
 367          $table->construct_cell("<a href=\"index.php?module=config-badwords&amp;action=edit&amp;bid={$badword['bid']}\">{$lang->edit}</a>", array("class" => "align_center"));
 368          $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"));
 369          $table->construct_row();
 370      }
 371  
 372      if($table->num_rows() == 0)
 373      {
 374          $table->construct_cell($lang->no_bad_words, array("colspan" => 4));
 375          $table->construct_row();
 376      }
 377  
 378      $table->output($lang->bad_word_filters);
 379  
 380      echo "<br />".draw_admin_pagination($pagenum, "20", $total_rows, "index.php?module=config-badwords&amp;page={page}");
 381  
 382      $page->output_footer();
 383  }
 384  


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