[ Index ]

PHP Cross Reference of MyBB 1.6.7

title

Body

[close]

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

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


Generated: Sat Mar 31 17:55:03 2012 Cross-referenced by PHPXref 0.7.1