[ Index ]

PHP Cross Reference of MyBB 1.8.21

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" && $mybb->request_method == "post")
  22  {
  23      $plugins->run_hooks("admin_config_badwords_add");
  24  
  25      if(!trim($mybb->input['badword']))
  26      {
  27          $errors[] = $lang->error_missing_bad_word;
  28      }
  29  
  30      if(strlen(trim($mybb->input['badword'])) > 100)
  31      {
  32          $errors[] = $lang->bad_word_max;
  33      }
  34  
  35      if(strlen($mybb->input['replacement']) > 100)
  36      {
  37          $errors[] = $lang->replacement_word_max;
  38      }
  39  
  40      if(!$errors)
  41      {
  42          $query = $db->simple_select("badwords", "bid", "badword = '".$db->escape_string($mybb->input['badword'])."'");
  43  
  44          if($db->num_rows($query))
  45          {
  46              $errors[] = $lang->error_bad_word_filtered;
  47          }
  48      }
  49  
  50      $badword = trim($mybb->input['badword']);
  51  
  52      if($mybb->get_input('regex', MyBB::INPUT_INT))
  53      {
  54          // Check validity of defined regular expression
  55          if((@preg_match('#'.$badword.'#is', null) === false))
  56          {
  57              $errors[] = $lang->error_invalid_regex;
  58          }
  59      }
  60      else
  61      {
  62          if(!is_object($parser))
  63          {
  64              require_once  MYBB_ROOT."inc/class_parser.php";
  65              $parser = new postParser;
  66          }
  67      
  68          $badword = $parser->generate_regex($badword);
  69      }
  70  
  71      // Don't allow certain badword replacements to be added if it would cause an infinite recursive loop.
  72      if(@preg_match('#'.$badword.'#is', $mybb->input['replacement']))
  73      {
  74          $errors[] = $lang->error_replacement_word_invalid;
  75      }
  76  
  77      if(!$errors)
  78      {
  79          $new_badword = array(
  80              "badword" => $db->escape_string($mybb->input['badword']),
  81              "regex" => $mybb->get_input('regex', MyBB::INPUT_INT),
  82              "replacement" => $db->escape_string($mybb->input['replacement'])
  83          );
  84  
  85          $bid = $db->insert_query("badwords", $new_badword);
  86  
  87          $plugins->run_hooks("admin_config_badwords_add_commit");
  88  
  89          // Log admin action
  90          log_admin_action($bid, $mybb->input['badword']);
  91  
  92          $cache->update_badwords();
  93          flash_message($lang->success_added_bad_word, 'success');
  94          admin_redirect("index.php?module=config-badwords");
  95      }
  96      else
  97      {
  98          $mybb->input['action'] = '';
  99      }
 100  }
 101  
 102  if($mybb->input['action'] == "delete")
 103  {
 104      $query = $db->simple_select("badwords", "*", "bid='".$mybb->get_input('bid', MyBB::INPUT_INT)."'");
 105      $badword = $db->fetch_array($query);
 106  
 107      // Does the bad word not exist?
 108      if(!$badword['bid'])
 109      {
 110          flash_message($lang->error_invalid_bid, 'error');
 111          admin_redirect("index.php?module=config-badwords");
 112      }
 113  
 114      // User clicked no
 115      if($mybb->input['no'])
 116      {
 117          admin_redirect("index.php?module=config-badwords");
 118      }
 119  
 120      $plugins->run_hooks("admin_config_badwords_delete");
 121  
 122      if($mybb->request_method == "post")
 123      {
 124          // Delete the bad word
 125          $db->delete_query("badwords", "bid='{$badword['bid']}'");
 126  
 127          $plugins->run_hooks("admin_config_badwords_delete_commit");
 128  
 129          // Log admin action
 130          log_admin_action($badword['bid'], $badword['badword']);
 131  
 132          $cache->update_badwords();
 133  
 134          flash_message($lang->success_deleted_bad_word, 'success');
 135          admin_redirect("index.php?module=config-badwords");
 136      }
 137      else
 138      {
 139          $page->output_confirm_action("index.php?module=config-badwords&action=delete&bid={$badword['bid']}", $lang->confirm_bad_word_deletion);
 140      }
 141  }
 142  
 143  if($mybb->input['action'] == "edit")
 144  {
 145      $query = $db->simple_select("badwords", "*", "bid='".$mybb->get_input('bid', MyBB::INPUT_INT)."'");
 146      $badword = $db->fetch_array($query);
 147  
 148      // Does the bad word not exist?
 149      if(!$badword['bid'])
 150      {
 151          flash_message($lang->error_invalid_bid, 'error');
 152          admin_redirect("index.php?module=config-badwords");
 153      }
 154  
 155      $plugins->run_hooks("admin_config_badwords_edit");
 156  
 157      if($mybb->request_method == "post")
 158      {
 159          if(!trim($mybb->input['badword']))
 160          {
 161              $errors[] = $lang->error_missing_bad_word;
 162          }
 163  
 164          if(strlen(trim($mybb->input['badword'])) > 100)
 165          {
 166              $errors[] = $lang->bad_word_max;
 167          }
 168  
 169          if(strlen($mybb->input['replacement']) > 100)
 170          {
 171              $errors[] = $lang->replacement_word_max;
 172          }
 173  
 174          if(!$errors)
 175          {
 176              $updated_badword = array(
 177                  "badword" => $db->escape_string($mybb->input['badword']),
 178                  "regex" => $mybb->get_input('regex', MyBB::INPUT_INT),
 179                  "replacement" => $db->escape_string($mybb->input['replacement'])
 180              );
 181  
 182              $plugins->run_hooks("admin_config_badwords_edit_commit");
 183  
 184              $db->update_query("badwords", $updated_badword, "bid='{$badword['bid']}'");
 185  
 186              // Log admin action
 187              log_admin_action($badword['bid'], $mybb->input['badword']);
 188  
 189              $cache->update_badwords();
 190  
 191              flash_message($lang->success_updated_bad_word, 'success');
 192              admin_redirect("index.php?module=config-badwords");
 193          }
 194      }
 195  
 196      $page->add_breadcrumb_item($lang->edit_bad_word);
 197      $page->output_header($lang->bad_words." - ".$lang->edit_bad_word);
 198  
 199      $sub_tabs['editbadword'] = array(
 200          'title' => $lang->edit_bad_word,
 201          'description' => $lang->edit_bad_word_desc,
 202          'link' => "index.php?module=config-badwords"
 203      );
 204  
 205      $page->output_nav_tabs($sub_tabs, "editbadword");
 206  
 207      $form = new Form("index.php?module=config-badwords&amp;action=edit&amp;bid={$badword['bid']}", "post");
 208  
 209      if($errors)
 210      {
 211          $page->output_inline_error($errors);
 212          $badword_data = $mybb->input;
 213      }
 214      else
 215      {
 216          $badword_data = $badword;
 217      }
 218  
 219      $form_container = new FormContainer($lang->edit_bad_word);
 220      $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');
 221      $form_container->output_row($lang->replacement, $lang->replacement_desc, $form->generate_text_box('replacement', $badword_data['replacement'], array('id' => 'replacement')), 'replacement');
 222      $form_container->output_row($lang->regex, $lang->regex_desc, $form->generate_yes_no_radio('regex', (int)$badword_data['regex'], array('id' => 'regex')), 'regex');
 223      $form_container->end();
 224      $buttons[] = $form->generate_submit_button($lang->save_bad_word);
 225      $form->output_submit_wrapper($buttons);
 226      $form->end();
 227  
 228      $page->output_footer();
 229  }
 230  
 231  if(!$mybb->input['action'])
 232  {
 233      $page->output_header($lang->bad_words);
 234  
 235      $sub_tabs['badwords'] = array(
 236          'title' => $lang->bad_word_filters,
 237          'description' => $lang->bad_word_filters_desc,
 238          'link' => "index.php?module=config-badwords"
 239      );
 240  
 241      $plugins->run_hooks("admin_config_badwords_start");
 242  
 243      $page->output_nav_tabs($sub_tabs, "badwords");
 244  
 245      if($errors)
 246      {
 247          $page->output_inline_error($errors);
 248      }
 249  
 250      $table = new Table;
 251      $table->construct_header($lang->bad_word);
 252      $table->construct_header($lang->replacement, array("width" => "50%"));
 253      $table->construct_header($lang->regex, array("class" => "align_center", "width" => "20%"));
 254      $table->construct_header($lang->controls, array("class" => "align_center", "width" => 150, "colspan" => 2));
 255  
 256      $query = $db->simple_select("badwords", "*", "", array("order_by" => "badword", "order_dir" => "asc"));
 257      while($badword = $db->fetch_array($query))
 258      {
 259          $badword['badword'] = htmlspecialchars_uni($badword['badword']);
 260          $badword['replacement'] = htmlspecialchars_uni($badword['replacement']);
 261          if(!$badword['replacement'])
 262          {
 263              $badword['replacement'] = '*****';
 264          }
 265  
 266          $regex = $lang->no;
 267          if($badword['regex'])
 268          {
 269              $regex = $lang->yes;
 270          }
 271  
 272          $table->construct_cell($badword['badword']);
 273          $table->construct_cell($badword['replacement']);
 274          $table->construct_cell($regex, array("class" => "align_center"));
 275          $table->construct_cell("<a href=\"index.php?module=config-badwords&amp;action=edit&amp;bid={$badword['bid']}\">{$lang->edit}</a>", array("class" => "align_center"));
 276          $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"));
 277          $table->construct_row();
 278      }
 279  
 280      if($table->num_rows() == 0)
 281      {
 282          $table->construct_cell($lang->no_bad_words, array("colspan" => 4));
 283          $table->construct_row();
 284      }
 285  
 286      $table->output($lang->bad_word_filters);
 287  
 288      $form = new Form("index.php?module=config-badwords&amp;action=add", "post", "add");
 289  
 290      $form_container = new FormContainer($lang->add_bad_word);
 291      $form_container->output_row($lang->bad_word." <em>*</em>", $lang->bad_word_desc, $form->generate_text_box('badword', $mybb->input['badword'], array('id' => 'badword')), 'badword');
 292      $form_container->output_row($lang->replacement, $lang->replacement_desc, $form->generate_text_box('replacement', $mybb->input['replacement'], array('id' => 'replacement')), 'replacement');
 293      $form_container->output_row($lang->regex, $lang->regex_desc, $form->generate_yes_no_radio('regex', !$mybb->get_input('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  


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