includes/acp/acp_words.php
changeset 0 ceef6d64c21d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/includes/acp/acp_words.php	Wed Mar 07 16:41:10 2012 +0400
     1.3 @@ -0,0 +1,190 @@
     1.4 +<?php
     1.5 +/**
     1.6 +*
     1.7 +* @package acp
     1.8 +* @version $Id$
     1.9 +* @copyright (c) 2005 phpBB Group
    1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
    1.11 +*
    1.12 +*/
    1.13 +
    1.14 +/**
    1.15 +* @ignore
    1.16 +*/
    1.17 +if (!defined('IN_PHPBB'))
    1.18 +{
    1.19 +	exit;
    1.20 +}
    1.21 +
    1.22 +/**
    1.23 +* @todo [words] check regular expressions for special char replacements (stored specialchared in db)
    1.24 +* @package acp
    1.25 +*/
    1.26 +class acp_words
    1.27 +{
    1.28 +	var $u_action;
    1.29 +
    1.30 +	function main($id, $mode)
    1.31 +	{
    1.32 +		global $db, $user, $auth, $template, $cache;
    1.33 +		global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
    1.34 +
    1.35 +		$user->add_lang('acp/posting');
    1.36 +
    1.37 +		// Set up general vars
    1.38 +		$action = request_var('action', '');
    1.39 +		$action = (isset($_POST['add'])) ? 'add' : ((isset($_POST['save'])) ? 'save' : $action);
    1.40 +
    1.41 +		$s_hidden_fields = '';
    1.42 +		$word_info = array();
    1.43 +
    1.44 +		$this->tpl_name = 'acp_words';
    1.45 +		$this->page_title = 'ACP_WORDS';
    1.46 +
    1.47 +		$form_name = 'acp_words';
    1.48 +		add_form_key($form_name);
    1.49 +
    1.50 +		switch ($action)
    1.51 +		{
    1.52 +			case 'edit':
    1.53 +
    1.54 +				$word_id = request_var('id', 0);
    1.55 +
    1.56 +				if (!$word_id)
    1.57 +				{
    1.58 +					trigger_error($user->lang['NO_WORD'] . adm_back_link($this->u_action), E_USER_WARNING);
    1.59 +				}
    1.60 +
    1.61 +				$sql = 'SELECT *
    1.62 +					FROM ' . WORDS_TABLE . "
    1.63 +					WHERE word_id = $word_id";
    1.64 +				$result = $db->sql_query($sql);
    1.65 +				$word_info = $db->sql_fetchrow($result);
    1.66 +				$db->sql_freeresult($result);
    1.67 +
    1.68 +				$s_hidden_fields .= '<input type="hidden" name="id" value="' . $word_id . '" />';
    1.69 +
    1.70 +			case 'add':
    1.71 +
    1.72 +				$template->assign_vars(array(
    1.73 +					'S_EDIT_WORD'		=> true,
    1.74 +					'U_ACTION'			=> $this->u_action,
    1.75 +					'U_BACK'			=> $this->u_action,
    1.76 +					'WORD'				=> (isset($word_info['word'])) ? $word_info['word'] : '',
    1.77 +					'REPLACEMENT'		=> (isset($word_info['replacement'])) ? $word_info['replacement'] : '',
    1.78 +					'S_HIDDEN_FIELDS'	=> $s_hidden_fields)
    1.79 +				);
    1.80 +
    1.81 +				return;
    1.82 +
    1.83 +			break;
    1.84 +
    1.85 +			case 'save':
    1.86 +
    1.87 +				if (!check_form_key($form_name))
    1.88 +				{
    1.89 +					trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
    1.90 +				}
    1.91 +
    1.92 +				$word_id		= request_var('id', 0);
    1.93 +				$word			= utf8_normalize_nfc(request_var('word', '', true));
    1.94 +				$replacement	= utf8_normalize_nfc(request_var('replacement', '', true));
    1.95 +
    1.96 +				if ($word === '' || $replacement === '')
    1.97 +				{
    1.98 +					trigger_error($user->lang['ENTER_WORD'] . adm_back_link($this->u_action), E_USER_WARNING);
    1.99 +				}
   1.100 +
   1.101 +				// Replace multiple consecutive asterisks with single one as those are not needed
   1.102 +				$word = preg_replace('#\*{2,}#', '*', $word);
   1.103 +
   1.104 +				$sql_ary = array(
   1.105 +					'word'			=> $word,
   1.106 +					'replacement'	=> $replacement
   1.107 +				);
   1.108 +				
   1.109 +				if ($word_id)
   1.110 +				{
   1.111 +					$db->sql_query('UPDATE ' . WORDS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE word_id = ' . $word_id);
   1.112 +				}
   1.113 +				else
   1.114 +				{
   1.115 +					$db->sql_query('INSERT INTO ' . WORDS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
   1.116 +				}
   1.117 +
   1.118 +				$cache->destroy('_word_censors');
   1.119 +
   1.120 +				$log_action = ($word_id) ? 'LOG_WORD_EDIT' : 'LOG_WORD_ADD';
   1.121 +				add_log('admin', $log_action, $word);
   1.122 +
   1.123 +				$message = ($word_id) ? $user->lang['WORD_UPDATED'] : $user->lang['WORD_ADDED'];
   1.124 +				trigger_error($message . adm_back_link($this->u_action));
   1.125 +
   1.126 +			break;
   1.127 +
   1.128 +			case 'delete':
   1.129 +
   1.130 +				$word_id = request_var('id', 0);
   1.131 +
   1.132 +				if (!$word_id)
   1.133 +				{
   1.134 +					trigger_error($user->lang['NO_WORD'] . adm_back_link($this->u_action), E_USER_WARNING);
   1.135 +				}
   1.136 +
   1.137 +				if (confirm_box(true))
   1.138 +				{
   1.139 +					$sql = 'SELECT word
   1.140 +						FROM ' . WORDS_TABLE . "
   1.141 +						WHERE word_id = $word_id";
   1.142 +					$result = $db->sql_query($sql);
   1.143 +					$deleted_word = $db->sql_fetchfield('word');
   1.144 +					$db->sql_freeresult($result);
   1.145 +
   1.146 +					$sql = 'DELETE FROM ' . WORDS_TABLE . "
   1.147 +						WHERE word_id = $word_id";
   1.148 +					$db->sql_query($sql);
   1.149 +
   1.150 +					$cache->destroy('_word_censors');
   1.151 +
   1.152 +					add_log('admin', 'LOG_WORD_DELETE', $deleted_word);
   1.153 +
   1.154 +					trigger_error($user->lang['WORD_REMOVED'] . adm_back_link($this->u_action));
   1.155 +				}
   1.156 +				else
   1.157 +				{
   1.158 +					confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
   1.159 +						'i'			=> $id,
   1.160 +						'mode'		=> $mode,
   1.161 +						'id'		=> $word_id,
   1.162 +						'action'	=> 'delete',
   1.163 +					)));
   1.164 +				}
   1.165 +
   1.166 +			break;
   1.167 +		}
   1.168 +
   1.169 +
   1.170 +		$template->assign_vars(array(
   1.171 +			'U_ACTION'			=> $this->u_action,
   1.172 +			'S_HIDDEN_FIELDS'	=> $s_hidden_fields)
   1.173 +		);
   1.174 +
   1.175 +		$sql = 'SELECT *
   1.176 +			FROM ' . WORDS_TABLE . '
   1.177 +			ORDER BY word';
   1.178 +		$result = $db->sql_query($sql);
   1.179 +
   1.180 +		while ($row = $db->sql_fetchrow($result))
   1.181 +		{
   1.182 +			$template->assign_block_vars('words', array(
   1.183 +				'WORD'			=> $row['word'],
   1.184 +				'REPLACEMENT'	=> $row['replacement'],
   1.185 +				'U_EDIT'		=> $this->u_action . '&amp;action=edit&amp;id=' . $row['word_id'],
   1.186 +				'U_DELETE'		=> $this->u_action . '&amp;action=delete&amp;id=' . $row['word_id'])
   1.187 +			);
   1.188 +		}
   1.189 +		$db->sql_freeresult($result);
   1.190 +	}
   1.191 +}
   1.192 +
   1.193 +?>
   1.194 \ No newline at end of file