punbb/admin/censoring.php
changeset 6 5e1f1e916419
equal deleted inserted replaced
5:e3d7322305bf 6:5e1f1e916419
       
     1 <?php
       
     2 /***********************************************************************
       
     3 
       
     4   Copyright (C) 2002-2008  PunBB.org
       
     5 
       
     6   This file is part of PunBB.
       
     7 
       
     8   PunBB is free software; you can redistribute it and/or modify it
       
     9   under the terms of the GNU General Public License as published
       
    10   by the Free Software Foundation; either version 2 of the License,
       
    11   or (at your option) any later version.
       
    12 
       
    13   PunBB is distributed in the hope that it will be useful, but
       
    14   WITHOUT ANY WARRANTY; without even the implied warranty of
       
    15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    16   GNU General Public License for more details.
       
    17 
       
    18   You should have received a copy of the GNU General Public License
       
    19   along with this program; if not, write to the Free Software
       
    20   Foundation, Inc., 59 Temple Place, Suite 330, Boston,
       
    21   MA  02111-1307  USA
       
    22 
       
    23 ************************************************************************/
       
    24 
       
    25 
       
    26 // if (!defined('PUN_ROOT'))
       
    27 // 	define('PUN_ROOT', '../');
       
    28 // require PUN_ROOT.'include/common.php';
       
    29 require PUN_ROOT.'include/common_admin.php';
       
    30 
       
    31 // import globals (I really hope this isn't dangerous)
       
    32 foreach ( $GLOBALS as $key => $_ )
       
    33 {
       
    34   $$key =& $GLOBALS[$key];
       
    35 }
       
    36 
       
    37 ($hook = get_hook('acs_start')) ? eval($hook) : null;
       
    38 
       
    39 if (!$pun_user['is_admmod'])
       
    40 	message($lang_common['No permission']);
       
    41 
       
    42 // Load the admin.php language file
       
    43 require PUN_ROOT.'lang/'.$pun_user['language'].'/admin.php';
       
    44 $GLOBALS['lang_admin'] = $lang_admin;
       
    45 
       
    46 
       
    47 // Add a censor word
       
    48 if (isset($_POST['add_word']))
       
    49 {
       
    50 	$search_for = trim($_POST['new_search_for']);
       
    51 	$replace_with = trim($_POST['new_replace_with']);
       
    52 
       
    53 	if ($search_for == '' || $replace_with == '')
       
    54 		message($lang_admin['Must enter text message']);
       
    55 
       
    56 	($hook = get_hook('acs_add_word_form_submitted')) ? eval($hook) : null;
       
    57 
       
    58 	$query = array(
       
    59 		'INSERT'	=> 'search_for, replace_with',
       
    60 		'INTO'		=> 'censoring',
       
    61 		'VALUES'	=> '\''.$pun_db->escape($search_for).'\', \''.$pun_db->escape($replace_with).'\''
       
    62 	);
       
    63 
       
    64 	($hook = get_hook('acs_qr_add_censor')) ? eval($hook) : null;
       
    65 	$pun_db->query_build($query) or error(__FILE__, __LINE__);
       
    66 
       
    67 	// Regenerate the censor cache
       
    68 	require_once PUN_ROOT.'include/cache.php';
       
    69 	generate_censors_cache();
       
    70 
       
    71 	pun_redirect(pun_link($pun_url['admin_censoring']), $lang_admin['Censor word added'].' '.$lang_admin['Redirect']);
       
    72 }
       
    73 
       
    74 
       
    75 // Update a censor word
       
    76 else if (isset($_POST['update']))
       
    77 {
       
    78 	$id = intval(key($_POST['update']));
       
    79 
       
    80 	$search_for = trim($_POST['search_for'][$id]);
       
    81 	$replace_with = trim($_POST['replace_with'][$id]);
       
    82 
       
    83 	if ($search_for == '' || $replace_with == '')
       
    84 		message($lang_admin['Must enter text message']);
       
    85 
       
    86 	($hook = get_hook('acs_update_form_submitted')) ? eval($hook) : null;
       
    87 
       
    88 	$query = array(
       
    89 		'UPDATE'	=> 'censoring',
       
    90 		'SET'		=> 'search_for=\''.$pun_db->escape($search_for).'\', replace_with=\''.$pun_db->escape($replace_with).'\'',
       
    91 		'WHERE'		=> 'id='.$id
       
    92 	);
       
    93 
       
    94 	($hook = get_hook('acs_qr_update_censor')) ? eval($hook) : null;
       
    95 	$pun_db->query_build($query) or error(__FILE__, __LINE__);
       
    96 
       
    97 	// Regenerate the censor cache
       
    98 	require_once PUN_ROOT.'include/cache.php';
       
    99 	generate_censors_cache();
       
   100 
       
   101 	pun_redirect(pun_link($pun_url['admin_censoring']), $lang_admin['Censor word updated'].' '.$lang_admin['Redirect']);
       
   102 }
       
   103 
       
   104 
       
   105 // Remove a censor word
       
   106 else if (isset($_POST['remove']))
       
   107 {
       
   108 	$id = intval(key($_POST['remove']));
       
   109 
       
   110 	($hook = get_hook('acs_remove_form_submitted')) ? eval($hook) : null;
       
   111 
       
   112 	$query = array(
       
   113 		'DELETE'	=> 'censoring',
       
   114 		'WHERE'		=> 'id='.$id
       
   115 	);
       
   116 
       
   117 	($hook = get_hook('acs_qr_delete_censor')) ? eval($hook) : null;
       
   118 	$pun_db->query_build($query) or error(__FILE__, __LINE__);
       
   119 
       
   120 	// Regenerate the censor cache
       
   121 	require_once PUN_ROOT.'include/cache.php';
       
   122 	generate_censors_cache();
       
   123 
       
   124 	pun_redirect(pun_link($pun_url['admin_censoring']), $lang_admin['Censor word removed'].' '.$lang_admin['Redirect']);
       
   125 }
       
   126 
       
   127 
       
   128 // Load the cached censors
       
   129 if (file_exists(PUN_CACHE_DIR.'cache_censors.php'))
       
   130 	include PUN_CACHE_DIR.'cache_censors.php';
       
   131 
       
   132 if (!defined('PUN_CENSORS_LOADED'))
       
   133 {
       
   134 	require_once PUN_ROOT.'include/cache.php';
       
   135 	generate_censors_cache();
       
   136 	require PUN_CACHE_DIR.'cache_censors.php';
       
   137 }
       
   138 
       
   139 
       
   140 // Setup the form
       
   141 $pun_page['part_count'] = $pun_page['fld_count'] = $pun_page['set_count'] = 0;
       
   142 
       
   143 // Setup breadcrumbs
       
   144 $pun_page['crumbs'] = array(
       
   145 	array($pun_config['o_board_title'], pun_link($pun_url['index'])),
       
   146 	array($lang_admin['Forum administration'], pun_link($pun_url['admin_index'])),
       
   147 	$lang_admin['Censoring']
       
   148 );
       
   149 
       
   150 ($hook = get_hook('acs_pre_header_load')) ? eval($hook) : null;
       
   151 
       
   152 define('PUN_PAGE_SECTION', 'options');
       
   153 define('PUN_PAGE', 'admin-censoring');
       
   154 require PUN_ROOT.'header.php';
       
   155 
       
   156 ?>
       
   157 <div id="pun-main" class="main sectioned admin">
       
   158 
       
   159 <?php echo generate_admin_menu(); ?>
       
   160 
       
   161 	<div class="main-head">
       
   162 		<h1><span>{ <?php echo end($pun_page['crumbs']) ?> }</span></h1>
       
   163 	</div>
       
   164 
       
   165 	<div class="main-content frm">
       
   166 		<div class="frm-head">
       
   167 			<h2><span><?php echo $lang_admin['Add censored word head'] ?></span></h2>
       
   168 		</div>
       
   169 		<form class="frm-form" method="post" accept-charset="utf-8" action="<?php echo pun_link($pun_url['admin_censoring']) ?>&amp;action=foo">
       
   170 			<div class="hidden">
       
   171 				<input type="hidden" name="csrf_token" value="<?php echo generate_form_token(pun_link($pun_url['admin_censoring']).'&action=foo') ?>" />
       
   172 			</div>
       
   173 			<div class="frm-info">
       
   174 				<p><?php printf($lang_admin['Add censored word intro'], '<strong><a href="'.pun_link($pun_url['admin_options_features']).'#fs4">'.$lang_admin['Options'].' - '.$lang_admin['Features'].'</a></strong>') ?></p>
       
   175 			</div>
       
   176 			<fieldset class="frm-set set<?php echo ++$pun_page['set_count'] ?>">
       
   177 				<legend class="frm-legend"><span><?php echo $lang_admin['Add censored word legend'] ?></span></legend>
       
   178 <?php ($hook = get_hook('acs_add_word_pre_search_for')) ? eval($hook) : null; ?>
       
   179 				<div class="frm-fld text">
       
   180 					<label for="fld<?php echo ++$pun_page['fld_count'] ?>">
       
   181 						<span class="fld-label"><?php echo $lang_admin['Censored word'] ?></span><br />
       
   182 						<span class="fld-input"><input type="text" id="fld<?php echo $pun_page['fld_count'] ?>" name="new_search_for" size="24" maxlength="60" /></span>
       
   183 					</label>
       
   184 				</div>
       
   185 <?php ($hook = get_hook('acs_add_word_pre_replace_with')) ? eval($hook) : null; ?>
       
   186 				<div class="frm-fld text">
       
   187 					<label for="fld<?php echo ++$pun_page['fld_count'] ?>">
       
   188 						<span class="fld-label"><?php echo $lang_admin['Censored replacement text'] ?></span><br />
       
   189 						<span class="fld-input"><input type="text" id="fld<?php echo $pun_page['fld_count'] ?>" name="new_replace_with" size="24" maxlength="60" /></span>
       
   190 					</label>
       
   191 				</div>
       
   192 <?php ($hook = get_hook('acs_add_word_end')) ? eval($hook) : null; ?>
       
   193 			</fieldset>
       
   194 			<div class="frm-buttons">
       
   195 				<span class="submit"><input type="submit" class="button" name="add_word" value=" <?php echo $lang_admin['Add'] ?> " /></span>
       
   196 			</div>
       
   197 		</form>
       
   198 	</div>
       
   199 <?php
       
   200 
       
   201 if (!empty($pun_censors))
       
   202 {
       
   203 	// Reset fieldset counter
       
   204 	$pun_page['set_count'] = 0;
       
   205 
       
   206 ?>
       
   207 	<div class="main-content frm">
       
   208 		<div class="frm-head">
       
   209 			<h2><span><?php echo $lang_admin['Edit censored word legend'] ?></span></h2>
       
   210 		</div>
       
   211 		<form class="frm-form" method="post" accept-charset="utf-8" action="<?php echo pun_link($pun_url['admin_censoring']) ?>&amp;action=foo">
       
   212 			<div class="hidden">
       
   213 				<input type="hidden" name="csrf_token" value="<?php echo generate_form_token(pun_link($pun_url['admin_censoring']).'&action=foo') ?>" />
       
   214 			</div>
       
   215 <?php
       
   216 
       
   217 	foreach ($pun_censors as $censor_key => $cur_word)
       
   218 	{
       
   219 
       
   220 	?>
       
   221 			<fieldset class="frm-set set<?php echo ++$pun_page['set_count'] ?>">
       
   222 				<legend class="frm-legend"><span><?php echo $lang_admin['Edit censored word legend'] ?></span></legend>
       
   223 <?php ($hook = get_hook('acs_edit_word_pre_search_for')) ? eval($hook) : null; ?>
       
   224 				<div class="frm-fld text">
       
   225 					<label for="fld<?php echo ++$pun_page['fld_count'] ?>">
       
   226 						<span class="fld-label"><?php echo $lang_admin['Censored word'] ?></span><br />
       
   227 						<span class="fld-input"><input type="text" id="fld<?php echo $pun_page['fld_count'] ?>" name="search_for[<?php echo $cur_word['id'] ?>]" value="<?php echo htmlspecialchars($cur_word['search_for']) ?>" size="24" maxlength="60" /></span>
       
   228 					</label>
       
   229 				</div>
       
   230 <?php ($hook = get_hook('acs_edit_word_pre_replace_with')) ? eval($hook) : null; ?>
       
   231 				<div class="frm-fld text">
       
   232 					<label for="fld<?php echo ++$pun_page['fld_count'] ?>">
       
   233 						<span class="fld-label"><?php echo $lang_admin['Censored replacement text'] ?></span><br />
       
   234 						<span class="fld-input"><input type="text" id="fld<?php echo $pun_page['fld_count'] ?>" name="replace_with[<?php echo $cur_word['id'] ?>]" value="<?php echo htmlspecialchars($cur_word['replace_with']) ?>" size="24" maxlength="60" /></span>
       
   235 					</label>
       
   236 					<span class="submit"><input type="submit" name="update[<?php echo $cur_word['id'] ?>]" value="<?php echo $lang_admin['Update'] ?>" /> <input type="submit" name="remove[<?php echo $cur_word['id'] ?>]" value="<?php echo $lang_admin['Remove'] ?>" /></span>
       
   237 				</div>
       
   238 <?php ($hook = get_hook('acs_edit_word_end')) ? eval($hook) : null; ?>
       
   239 			</fieldset>
       
   240 	<?php
       
   241 
       
   242 	}
       
   243 
       
   244 ?>
       
   245 		</form>
       
   246 	</div>
       
   247 <?php
       
   248 
       
   249 }
       
   250 else
       
   251 {
       
   252 
       
   253 ?>
       
   254 	<div class="main-content frm">
       
   255 		<div class="frm-head">
       
   256 			<h2><span><?php echo $lang_admin['Edit censored word legend'] ?></span></h2>
       
   257 		</div>
       
   258 		<div class="frm-form">
       
   259 			<div class="frm-info">
       
   260 				<p><?php echo $lang_admin['No censored words'] ?></p>
       
   261 			</div>
       
   262 		</div>
       
   263 	</div>
       
   264 <?php
       
   265 
       
   266 }
       
   267 
       
   268 ?>
       
   269 </div>
       
   270 <?php
       
   271 
       
   272 require PUN_ROOT.'footer.php';