[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/includes/acp/ -> acp_words.php (source)

   1  <?php
   2  /**
   3  *
   4  * @package acp
   5  * @version $Id$
   6  * @copyright (c) 2005 phpBB Group
   7  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
   8  *
   9  */
  10  
  11  /**
  12  * @ignore
  13  */
  14  if (!defined('IN_PHPBB'))
  15  {
  16      exit;
  17  }
  18  
  19  /**
  20  * @todo [words] check regular expressions for special char replacements (stored specialchared in db)
  21  * @package acp
  22  */
  23  class acp_words
  24  {
  25      var $u_action;
  26  
  27  	function main($id, $mode)
  28      {
  29          global $db, $user, $auth, $template, $cache;
  30          global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
  31  
  32          $user->add_lang('acp/posting');
  33  
  34          // Set up general vars
  35          $action = request_var('action', '');
  36          $action = (isset($_POST['add'])) ? 'add' : ((isset($_POST['save'])) ? 'save' : $action);
  37  
  38          $s_hidden_fields = '';
  39          $word_info = array();
  40  
  41          $this->tpl_name = 'acp_words';
  42          $this->page_title = 'ACP_WORDS';
  43  
  44          $form_name = 'acp_words';
  45          add_form_key($form_name);
  46  
  47          switch ($action)
  48          {
  49              case 'edit':
  50  
  51                  $word_id = request_var('id', 0);
  52  
  53                  if (!$word_id)
  54                  {
  55                      trigger_error($user->lang['NO_WORD'] . adm_back_link($this->u_action), E_USER_WARNING);
  56                  }
  57  
  58                  $sql = 'SELECT *
  59                      FROM ' . WORDS_TABLE . "
  60                      WHERE word_id = $word_id";
  61                  $result = $db->sql_query($sql);
  62                  $word_info = $db->sql_fetchrow($result);
  63                  $db->sql_freeresult($result);
  64  
  65                  $s_hidden_fields .= '<input type="hidden" name="id" value="' . $word_id . '" />';
  66  
  67              case 'add':
  68  
  69                  $template->assign_vars(array(
  70                      'S_EDIT_WORD'        => true,
  71                      'U_ACTION'            => $this->u_action,
  72                      'U_BACK'            => $this->u_action,
  73                      'WORD'                => (isset($word_info['word'])) ? $word_info['word'] : '',
  74                      'REPLACEMENT'        => (isset($word_info['replacement'])) ? $word_info['replacement'] : '',
  75                      'S_HIDDEN_FIELDS'    => $s_hidden_fields)
  76                  );
  77  
  78                  return;
  79  
  80              break;
  81  
  82              case 'save':
  83  
  84                  if (!check_form_key($form_name))
  85                  {
  86                      trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
  87                  }
  88  
  89                  $word_id        = request_var('id', 0);
  90                  $word            = utf8_normalize_nfc(request_var('word', '', true));
  91                  $replacement    = utf8_normalize_nfc(request_var('replacement', '', true));
  92  
  93                  if ($word === '' || $replacement === '')
  94                  {
  95                      trigger_error($user->lang['ENTER_WORD'] . adm_back_link($this->u_action), E_USER_WARNING);
  96                  }
  97  
  98                  // Replace multiple consecutive asterisks with single one as those are not needed
  99                  $word = preg_replace('#\*{2,}#', '*', $word);
 100  
 101                  $sql_ary = array(
 102                      'word'            => $word,
 103                      'replacement'    => $replacement
 104                  );
 105                  
 106                  if ($word_id)
 107                  {
 108                      $db->sql_query('UPDATE ' . WORDS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE word_id = ' . $word_id);
 109                  }
 110                  else
 111                  {
 112                      $db->sql_query('INSERT INTO ' . WORDS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
 113                  }
 114  
 115                  $cache->destroy('_word_censors');
 116  
 117                  $log_action = ($word_id) ? 'LOG_WORD_EDIT' : 'LOG_WORD_ADD';
 118                  add_log('admin', $log_action, $word);
 119  
 120                  $message = ($word_id) ? $user->lang['WORD_UPDATED'] : $user->lang['WORD_ADDED'];
 121                  trigger_error($message . adm_back_link($this->u_action));
 122  
 123              break;
 124  
 125              case 'delete':
 126  
 127                  $word_id = request_var('id', 0);
 128  
 129                  if (!$word_id)
 130                  {
 131                      trigger_error($user->lang['NO_WORD'] . adm_back_link($this->u_action), E_USER_WARNING);
 132                  }
 133  
 134                  if (confirm_box(true))
 135                  {
 136                      $sql = 'SELECT word
 137                          FROM ' . WORDS_TABLE . "
 138                          WHERE word_id = $word_id";
 139                      $result = $db->sql_query($sql);
 140                      $deleted_word = $db->sql_fetchfield('word');
 141                      $db->sql_freeresult($result);
 142  
 143                      $sql = 'DELETE FROM ' . WORDS_TABLE . "
 144                          WHERE word_id = $word_id";
 145                      $db->sql_query($sql);
 146  
 147                      $cache->destroy('_word_censors');
 148  
 149                      add_log('admin', 'LOG_WORD_DELETE', $deleted_word);
 150  
 151                      trigger_error($user->lang['WORD_REMOVED'] . adm_back_link($this->u_action));
 152                  }
 153                  else
 154                  {
 155                      confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
 156                          'i'            => $id,
 157                          'mode'        => $mode,
 158                          'id'        => $word_id,
 159                          'action'    => 'delete',
 160                      )));
 161                  }
 162  
 163              break;
 164          }
 165  
 166  
 167          $template->assign_vars(array(
 168              'U_ACTION'            => $this->u_action,
 169              'S_HIDDEN_FIELDS'    => $s_hidden_fields)
 170          );
 171  
 172          $sql = 'SELECT *
 173              FROM ' . WORDS_TABLE . '
 174              ORDER BY word';
 175          $result = $db->sql_query($sql);
 176  
 177          while ($row = $db->sql_fetchrow($result))
 178          {
 179              $template->assign_block_vars('words', array(
 180                  'WORD'            => $row['word'],
 181                  'REPLACEMENT'    => $row['replacement'],
 182                  'U_EDIT'        => $this->u_action . '&amp;action=edit&amp;id=' . $row['word_id'],
 183                  'U_DELETE'        => $this->u_action . '&amp;action=delete&amp;id=' . $row['word_id'])
 184              );
 185          }
 186          $db->sql_freeresult($result);
 187      }
 188  }
 189  
 190  ?>


Generated: Wed Oct 2 15:03:47 2013 Cross-referenced by PHPXref 0.7.1