Blame Extras/phpBB/3.0.4/includes/acp/acp_words.php

4c79b5
4c79b5
/**
4c79b5
*
4c79b5
* @package acp
4c79b5
* @version $Id: acp_words.php 8479 2008-03-29 00:22:48Z naderman $
4c79b5
* @copyright (c) 2005 phpBB Group
4c79b5
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
4c79b5
*
4c79b5
*/
4c79b5
4c79b5
/**
4c79b5
* @ignore
4c79b5
*/
4c79b5
if (!defined('IN_PHPBB'))
4c79b5
{
4c79b5
	exit;
4c79b5
}
4c79b5
4c79b5
/**
4c79b5
* @todo [words] check regular expressions for special char replacements (stored specialchared in db)
4c79b5
* @package acp
4c79b5
*/
4c79b5
class acp_words
4c79b5
{
4c79b5
	var $u_action;
4c79b5
	
4c79b5
	function main($id, $mode)
4c79b5
	{
4c79b5
		global $db, $user, $auth, $template, $cache;
4c79b5
		global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
4c79b5
4c79b5
		$user->add_lang('acp/posting');
4c79b5
4c79b5
		// Set up general vars
4c79b5
		$action = request_var('action', '');
4c79b5
		$action = (isset($_POST['add'])) ? 'add' : ((isset($_POST['save'])) ? 'save' : $action);
4c79b5
4c79b5
		$s_hidden_fields = '';
4c79b5
		$word_info = array();
4c79b5
4c79b5
		$this->tpl_name = 'acp_words';
4c79b5
		$this->page_title = 'ACP_WORDS';
4c79b5
4c79b5
		$form_name = 'acp_words';
4c79b5
		add_form_key($form_name);
4c79b5
4c79b5
		switch ($action)
4c79b5
		{
4c79b5
			case 'edit':
4c79b5
				$word_id = request_var('id', 0);
4c79b5
				
4c79b5
				if (!$word_id)
4c79b5
				{
4c79b5
					trigger_error($user->lang['NO_WORD'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
				}
4c79b5
4c79b5
				$sql = 'SELECT *
4c79b5
					FROM ' . WORDS_TABLE . "
4c79b5
					WHERE word_id = $word_id";
4c79b5
				$result = $db->sql_query($sql);
4c79b5
				$word_info = $db->sql_fetchrow($result);
4c79b5
				$db->sql_freeresult($result);
4c79b5
4c79b5
				$s_hidden_fields .= '<input type="hidden" name="id" value="' . $word_id . '" />';
4c79b5
4c79b5
			case 'add':
4c79b5
4c79b5
				$template->assign_vars(array(
4c79b5
					'S_EDIT_WORD'		=> true,
4c79b5
					'U_ACTION'			=> $this->u_action,
4c79b5
					'U_BACK'			=> $this->u_action,
4c79b5
					'WORD'				=> (isset($word_info['word'])) ? $word_info['word'] : '',
4c79b5
					'REPLACEMENT'		=> (isset($word_info['replacement'])) ? $word_info['replacement'] : '',
4c79b5
					'S_HIDDEN_FIELDS'	=> $s_hidden_fields)
4c79b5
				);
4c79b5
				
4c79b5
				return;
4c79b5
4c79b5
			break;
4c79b5
4c79b5
			case 'save':
4c79b5
4c79b5
				if (!check_form_key($form_name))
4c79b5
				{
4c79b5
					trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
				}
4c79b5
				$word_id		= request_var('id', 0);
4c79b5
				$word			= utf8_normalize_nfc(request_var('word', '', true));
4c79b5
				$replacement	= utf8_normalize_nfc(request_var('replacement', '', true));
4c79b5
				
4c79b5
				if (!$word || !$replacement)
4c79b5
				{
4c79b5
					trigger_error($user->lang['ENTER_WORD'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
				}
4c79b5
4c79b5
				$sql_ary = array(
4c79b5
					'word'			=> $word,
4c79b5
					'replacement'	=> $replacement
4c79b5
				);
4c79b5
				
4c79b5
				if ($word_id)
4c79b5
				{
4c79b5
					$db->sql_query('UPDATE ' . WORDS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE word_id = ' . $word_id);
4c79b5
				}
4c79b5
				else
4c79b5
				{
4c79b5
					$db->sql_query('INSERT INTO ' . WORDS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
4c79b5
				}
4c79b5
4c79b5
				$cache->destroy('_word_censors');
4c79b5
4c79b5
				$log_action = ($word_id) ? 'LOG_WORD_EDIT' : 'LOG_WORD_ADD';
4c79b5
				add_log('admin', $log_action, $word);
4c79b5
4c79b5
				$message = ($word_id) ? $user->lang['WORD_UPDATED'] : $user->lang['WORD_ADDED'];
4c79b5
				trigger_error($message . adm_back_link($this->u_action));
4c79b5
4c79b5
			break;
4c79b5
4c79b5
			case 'delete':
4c79b5
4c79b5
				$word_id = request_var('id', 0);
4c79b5
4c79b5
				if (!$word_id)
4c79b5
				{
4c79b5
					trigger_error($user->lang['NO_WORD'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
				}
4c79b5
4c79b5
				if (confirm_box(true))
4c79b5
				{
4c79b5
					$sql = 'SELECT word
4c79b5
						FROM ' . WORDS_TABLE . "
4c79b5
						WHERE word_id = $word_id";
4c79b5
					$result = $db->sql_query($sql);
4c79b5
					$deleted_word = $db->sql_fetchfield('word');
4c79b5
					$db->sql_freeresult($result);
4c79b5
4c79b5
					$sql = 'DELETE FROM ' . WORDS_TABLE . "
4c79b5
						WHERE word_id = $word_id";
4c79b5
					$db->sql_query($sql);
4c79b5
4c79b5
					$cache->destroy('_word_censors');
4c79b5
4c79b5
					add_log('admin', 'LOG_WORD_DELETE', $deleted_word);
4c79b5
4c79b5
					trigger_error($user->lang['WORD_REMOVED'] . adm_back_link($this->u_action));
4c79b5
				}
4c79b5
				else
4c79b5
				{
4c79b5
					confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
4c79b5
						'i'			=> $id,
4c79b5
						'mode'		=> $mode,
4c79b5
						'id'		=> $word_id,
4c79b5
						'action'	=> 'delete',
4c79b5
					)));
4c79b5
				}
4c79b5
4c79b5
			break;
4c79b5
		}
4c79b5
4c79b5
4c79b5
		$template->assign_vars(array(
4c79b5
			'U_ACTION'			=> $this->u_action,
4c79b5
			'S_HIDDEN_FIELDS'	=> $s_hidden_fields)
4c79b5
		);
4c79b5
4c79b5
		$sql = 'SELECT *
4c79b5
			FROM ' . WORDS_TABLE . '
4c79b5
			ORDER BY word';
4c79b5
		$result = $db->sql_query($sql);
4c79b5
4c79b5
		while ($row = $db->sql_fetchrow($result))
4c79b5
		{
4c79b5
			$template->assign_block_vars('words', array(
4c79b5
				'WORD'			=> $row['word'],
4c79b5
				'REPLACEMENT'	=> $row['replacement'],
4c79b5
				'U_EDIT'		=> $this->u_action . '&action=edit&id=' . $row['word_id'],
4c79b5
				'U_DELETE'		=> $this->u_action . '&action=delete&id=' . $row['word_id'])
4c79b5
			);
4c79b5
		}
4c79b5
		$db->sql_freeresult($result);
4c79b5
	}
4c79b5
}
4c79b5
4c79b5
?>