[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

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

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


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1