| 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 | $sql_ary = array(
|
|---|
| 99 | 'word' => $word,
|
|---|
| 100 | 'replacement' => $replacement
|
|---|
| 101 | );
|
|---|
| 102 |
|
|---|
| 103 | if ($word_id)
|
|---|
| 104 | {
|
|---|
| 105 | $db->sql_query('UPDATE ' . WORDS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE word_id = ' . $word_id);
|
|---|
| 106 | }
|
|---|
| 107 | else
|
|---|
| 108 | {
|
|---|
| 109 | $db->sql_query('INSERT INTO ' . WORDS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | $cache->destroy('_word_censors');
|
|---|
| 113 |
|
|---|
| 114 | $log_action = ($word_id) ? 'LOG_WORD_EDIT' : 'LOG_WORD_ADD';
|
|---|
| 115 | add_log('admin', $log_action, $word);
|
|---|
| 116 |
|
|---|
| 117 | $message = ($word_id) ? $user->lang['WORD_UPDATED'] : $user->lang['WORD_ADDED'];
|
|---|
| 118 | trigger_error($message . adm_back_link($this->u_action));
|
|---|
| 119 |
|
|---|
| 120 | break;
|
|---|
| 121 |
|
|---|
| 122 | case 'delete':
|
|---|
| 123 |
|
|---|
| 124 | $word_id = request_var('id', 0);
|
|---|
| 125 |
|
|---|
| 126 | if (!$word_id)
|
|---|
| 127 | {
|
|---|
| 128 | trigger_error($user->lang['NO_WORD'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | if (confirm_box(true))
|
|---|
| 132 | {
|
|---|
| 133 | $sql = 'SELECT word
|
|---|
| 134 | FROM ' . WORDS_TABLE . "
|
|---|
| 135 | WHERE word_id = $word_id";
|
|---|
| 136 | $result = $db->sql_query($sql);
|
|---|
| 137 | $deleted_word = $db->sql_fetchfield('word');
|
|---|
| 138 | $db->sql_freeresult($result);
|
|---|
| 139 |
|
|---|
| 140 | $sql = 'DELETE FROM ' . WORDS_TABLE . "
|
|---|
| 141 | WHERE word_id = $word_id";
|
|---|
| 142 | $db->sql_query($sql);
|
|---|
| 143 |
|
|---|
| 144 | $cache->destroy('_word_censors');
|
|---|
| 145 |
|
|---|
| 146 | add_log('admin', 'LOG_WORD_DELETE', $deleted_word);
|
|---|
| 147 |
|
|---|
| 148 | trigger_error($user->lang['WORD_REMOVED'] . adm_back_link($this->u_action));
|
|---|
| 149 | }
|
|---|
| 150 | else
|
|---|
| 151 | {
|
|---|
| 152 | confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
|
|---|
| 153 | 'i' => $id,
|
|---|
| 154 | 'mode' => $mode,
|
|---|
| 155 | 'id' => $word_id,
|
|---|
| 156 | 'action' => 'delete',
|
|---|
| 157 | )));
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | break;
|
|---|
| 161 | }
|
|---|
| 162 |
|
|---|
| 163 |
|
|---|
| 164 | $template->assign_vars(array(
|
|---|
| 165 | 'U_ACTION' => $this->u_action,
|
|---|
| 166 | 'S_HIDDEN_FIELDS' => $s_hidden_fields)
|
|---|
| 167 | );
|
|---|
| 168 |
|
|---|
| 169 | $sql = 'SELECT *
|
|---|
| 170 | FROM ' . WORDS_TABLE . '
|
|---|
| 171 | ORDER BY word';
|
|---|
| 172 | $result = $db->sql_query($sql);
|
|---|
| 173 |
|
|---|
| 174 | while ($row = $db->sql_fetchrow($result))
|
|---|
| 175 | {
|
|---|
| 176 | $template->assign_block_vars('words', array(
|
|---|
| 177 | 'WORD' => $row['word'],
|
|---|
| 178 | 'REPLACEMENT' => $row['replacement'],
|
|---|
| 179 | 'U_EDIT' => $this->u_action . '&action=edit&id=' . $row['word_id'],
|
|---|
| 180 | 'U_DELETE' => $this->u_action . '&action=delete&id=' . $row['word_id'])
|
|---|
| 181 | );
|
|---|
| 182 | }
|
|---|
| 183 | $db->sql_freeresult($result);
|
|---|
| 184 | }
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | ?>
|
|---|