2009-10-04 18:14:59 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
*
|
2014-05-27 20:18:06 +02:00
|
|
|
* This file is part of the phpBB Forum Software package.
|
|
|
|
*
|
|
|
|
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0)
|
|
|
|
*
|
|
|
|
* For full copyright and license information, please see
|
|
|
|
* the docs/CREDITS.txt file.
|
2009-10-04 18:14:59 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
if (!defined('IN_PHPBB'))
|
|
|
|
{
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @todo [words] check regular expressions for special char replacements (stored specialchared in db)
|
|
|
|
*/
|
|
|
|
class acp_words
|
|
|
|
{
|
|
|
|
var $u_action;
|
|
|
|
|
|
|
|
function main($id, $mode)
|
|
|
|
{
|
2015-02-08 13:35:07 +01:00
|
|
|
global $db, $user, $auth, $template, $cache, $phpbb_log, $request, $phpbb_container;
|
2009-10-04 18:14:59 +00:00
|
|
|
global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
|
|
|
|
|
|
|
|
$user->add_lang('acp/posting');
|
|
|
|
|
|
|
|
// Set up general vars
|
2015-01-04 20:41:04 +01:00
|
|
|
$action = $request->variable('action', '');
|
2009-10-04 18:14:59 +00:00
|
|
|
$action = (isset($_POST['add'])) ? 'add' : ((isset($_POST['save'])) ? 'save' : $action);
|
|
|
|
|
|
|
|
$s_hidden_fields = '';
|
|
|
|
$word_info = array();
|
|
|
|
|
|
|
|
$this->tpl_name = 'acp_words';
|
|
|
|
$this->page_title = 'ACP_WORDS';
|
|
|
|
|
|
|
|
$form_name = 'acp_words';
|
|
|
|
add_form_key($form_name);
|
|
|
|
|
|
|
|
switch ($action)
|
|
|
|
{
|
|
|
|
case 'edit':
|
|
|
|
|
2015-01-04 20:41:04 +01:00
|
|
|
$word_id = $request->variable('id', 0);
|
2009-10-04 18:14:59 +00:00
|
|
|
|
|
|
|
if (!$word_id)
|
|
|
|
{
|
|
|
|
trigger_error($user->lang['NO_WORD'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql = 'SELECT *
|
|
|
|
FROM ' . WORDS_TABLE . "
|
|
|
|
WHERE word_id = $word_id";
|
|
|
|
$result = $db->sql_query($sql);
|
|
|
|
$word_info = $db->sql_fetchrow($result);
|
|
|
|
$db->sql_freeresult($result);
|
|
|
|
|
|
|
|
$s_hidden_fields .= '<input type="hidden" name="id" value="' . $word_id . '" />';
|
|
|
|
|
|
|
|
case 'add':
|
|
|
|
|
|
|
|
$template->assign_vars(array(
|
|
|
|
'S_EDIT_WORD' => true,
|
|
|
|
'U_ACTION' => $this->u_action,
|
|
|
|
'U_BACK' => $this->u_action,
|
|
|
|
'WORD' => (isset($word_info['word'])) ? $word_info['word'] : '',
|
|
|
|
'REPLACEMENT' => (isset($word_info['replacement'])) ? $word_info['replacement'] : '',
|
|
|
|
'S_HIDDEN_FIELDS' => $s_hidden_fields)
|
|
|
|
);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'save':
|
|
|
|
|
|
|
|
if (!check_form_key($form_name))
|
|
|
|
{
|
|
|
|
trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
|
}
|
|
|
|
|
2015-01-04 20:41:04 +01:00
|
|
|
$word_id = $request->variable('id', 0);
|
2015-02-02 21:35:46 +01:00
|
|
|
$word = $request->variable('word', '', true);
|
|
|
|
$replacement = $request->variable('replacement', '', true);
|
2009-10-04 18:14:59 +00:00
|
|
|
|
|
|
|
if ($word === '' || $replacement === '')
|
|
|
|
{
|
|
|
|
trigger_error($user->lang['ENTER_WORD'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
|
}
|
|
|
|
|
2011-01-04 11:54:10 +07:00
|
|
|
// Replace multiple consecutive asterisks with single one as those are not needed
|
|
|
|
$word = preg_replace('#\*{2,}#', '*', $word);
|
|
|
|
|
2009-10-04 18:14:59 +00:00
|
|
|
$sql_ary = array(
|
|
|
|
'word' => $word,
|
|
|
|
'replacement' => $replacement
|
|
|
|
);
|
2014-04-29 17:51:21 +02:00
|
|
|
|
2009-10-04 18:14:59 +00:00
|
|
|
if ($word_id)
|
|
|
|
{
|
|
|
|
$db->sql_query('UPDATE ' . WORDS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE word_id = ' . $word_id);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$db->sql_query('INSERT INTO ' . WORDS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
|
|
|
|
}
|
|
|
|
|
|
|
|
$cache->destroy('_word_censors');
|
2014-11-22 20:00:58 +01:00
|
|
|
$phpbb_container->get('text_formatter.cache')->invalidate();
|
2009-10-04 18:14:59 +00:00
|
|
|
|
|
|
|
$log_action = ($word_id) ? 'LOG_WORD_EDIT' : 'LOG_WORD_ADD';
|
2015-01-05 22:21:31 +01:00
|
|
|
|
|
|
|
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, $log_action, false, array($word));
|
2009-10-04 18:14:59 +00:00
|
|
|
|
|
|
|
$message = ($word_id) ? $user->lang['WORD_UPDATED'] : $user->lang['WORD_ADDED'];
|
|
|
|
trigger_error($message . adm_back_link($this->u_action));
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'delete':
|
|
|
|
|
2015-01-04 20:41:04 +01:00
|
|
|
$word_id = $request->variable('id', 0);
|
2009-10-04 18:14:59 +00:00
|
|
|
|
|
|
|
if (!$word_id)
|
|
|
|
{
|
|
|
|
trigger_error($user->lang['NO_WORD'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (confirm_box(true))
|
|
|
|
{
|
|
|
|
$sql = 'SELECT word
|
|
|
|
FROM ' . WORDS_TABLE . "
|
|
|
|
WHERE word_id = $word_id";
|
|
|
|
$result = $db->sql_query($sql);
|
|
|
|
$deleted_word = $db->sql_fetchfield('word');
|
|
|
|
$db->sql_freeresult($result);
|
|
|
|
|
|
|
|
$sql = 'DELETE FROM ' . WORDS_TABLE . "
|
|
|
|
WHERE word_id = $word_id";
|
|
|
|
$db->sql_query($sql);
|
|
|
|
|
|
|
|
$cache->destroy('_word_censors');
|
2014-11-22 20:00:58 +01:00
|
|
|
$phpbb_container->get('text_formatter.cache')->invalidate();
|
2009-10-04 18:14:59 +00:00
|
|
|
|
2015-01-05 22:21:31 +01:00
|
|
|
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_WORD_DELETE', false, array($deleted_word));
|
2009-10-04 18:14:59 +00:00
|
|
|
|
|
|
|
trigger_error($user->lang['WORD_REMOVED'] . adm_back_link($this->u_action));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
|
|
|
|
'i' => $id,
|
|
|
|
'mode' => $mode,
|
|
|
|
'id' => $word_id,
|
|
|
|
'action' => 'delete',
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$template->assign_vars(array(
|
|
|
|
'U_ACTION' => $this->u_action,
|
|
|
|
'S_HIDDEN_FIELDS' => $s_hidden_fields)
|
|
|
|
);
|
|
|
|
|
|
|
|
$sql = 'SELECT *
|
|
|
|
FROM ' . WORDS_TABLE . '
|
|
|
|
ORDER BY word';
|
|
|
|
$result = $db->sql_query($sql);
|
|
|
|
|
|
|
|
while ($row = $db->sql_fetchrow($result))
|
|
|
|
{
|
|
|
|
$template->assign_block_vars('words', array(
|
|
|
|
'WORD' => $row['word'],
|
|
|
|
'REPLACEMENT' => $row['replacement'],
|
|
|
|
'U_EDIT' => $this->u_action . '&action=edit&id=' . $row['word_id'],
|
|
|
|
'U_DELETE' => $this->u_action . '&action=delete&id=' . $row['word_id'])
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$db->sql_freeresult($result);
|
|
|
|
}
|
|
|
|
}
|