punbb/admin_censoring.php
changeset 6 5e1f1e916419
parent 5 e3d7322305bf
child 7 98bbc533541c
equal deleted inserted replaced
5:e3d7322305bf 6:5e1f1e916419
     1 <?php
       
     2 /***********************************************************************
       
     3 
       
     4   Copyright (C) 2002-2005  Rickard Andersson (rickard@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 // Tell header.php to use the admin template
       
    27 define('PUN_ADMIN_CONSOLE', 1);
       
    28 
       
    29 //define('PUN_ROOT', './');
       
    30 //require PUN_ROOT.'include/common.php';
       
    31 
       
    32 global $pun_db, $pun_user, $pun_config, $lang_common;
       
    33 
       
    34 require PUN_ROOT.'include/common_admin.php';
       
    35 
       
    36 
       
    37 if ($pun_user['g_id'] < PUN_MOD)
       
    38 	message($lang_common['No permission']);
       
    39 
       
    40 
       
    41 // Add a censor word
       
    42 if (isset($_POST['add_word']))
       
    43 {
       
    44 	confirm_referrer('admin_censoring.php');
       
    45 
       
    46 	$search_for = trim($_POST['new_search_for']);
       
    47 	$replace_with = trim($_POST['new_replace_with']);
       
    48 
       
    49 	if ($search_for == '' || $replace_with == '')
       
    50 		message('You must enter both a word to censor and text to replace it with.');
       
    51 
       
    52 	$pun_db->query('INSERT INTO '.$pun_db->prefix.'censoring (search_for, replace_with) VALUES (\''.$pun_db->escape($search_for).'\', \''.$pun_db->escape($replace_with).'\')') or error('Unable to add censor word', __FILE__, __LINE__, $pun_db->error());
       
    53 
       
    54 	pun_redirect('admin_censoring.php', 'Censor word added. Redirecting &hellip;');
       
    55 }
       
    56 
       
    57 
       
    58 // Update a censor word
       
    59 else if (isset($_POST['update']))
       
    60 {
       
    61 	confirm_referrer('admin_censoring.php');
       
    62 
       
    63 	$id = intval(key($_POST['update']));
       
    64 
       
    65 	$search_for = trim($_POST['search_for'][$id]);
       
    66 	$replace_with = trim($_POST['replace_with'][$id]);
       
    67 
       
    68 	if ($search_for == '' || $replace_with == '')
       
    69 		message('You must enter both text to search for and text to replace with.');
       
    70 
       
    71 	$pun_db->query('UPDATE '.$pun_db->prefix.'censoring SET search_for=\''.$pun_db->escape($search_for).'\', replace_with=\''.$pun_db->escape($replace_with).'\' WHERE id='.$id) or error('Unable to update censor word', __FILE__, __LINE__, $pun_db->error());
       
    72 
       
    73 	pun_redirect('admin_censoring.php', 'Censor word updated. Redirecting &hellip;');
       
    74 }
       
    75 
       
    76 
       
    77 // Remove a censor word
       
    78 else if (isset($_POST['remove']))
       
    79 {
       
    80 	confirm_referrer('admin_censoring.php');
       
    81 
       
    82 	$id = intval(key($_POST['remove']));
       
    83 
       
    84 	$pun_db->query('DELETE FROM '.$pun_db->prefix.'censoring WHERE id='.$id) or error('Unable to delete censor word', __FILE__, __LINE__, $pun_db->error());
       
    85 
       
    86 	pun_redirect('admin_censoring.php', 'Censor word removed. Redirecting &hellip;');
       
    87 }
       
    88 
       
    89 
       
    90 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Censoring';
       
    91 $focus_element = array('censoring', 'new_search_for');
       
    92 require PUN_ROOT.'header.php';
       
    93 
       
    94 generate_admin_menu('censoring');
       
    95 
       
    96 ?>
       
    97 	<div class="blockform">
       
    98 		<h2><span>Censoring</span></h2>
       
    99 		<div class="box">
       
   100 			<form id="censoring" method="post" action="<?php echo makeUrlNS('Special', 'Forum/Admin_censoring', 'action=foo', true); ?>">
       
   101 				<div class="inform">
       
   102 					<fieldset>
       
   103 						<legend>Add word</legend>
       
   104 						<div class="infldset">
       
   105 							<p>Enter a word that you want to censor and the replacement text for this word. Wildcards are accepted (i.e. *some* would match somewhere and lonesome). Censor words also affect usernames. New users will not be able to register with usernames containing any censored words. The search is case insensitive. <strong>Censor words must be enabled in <a href="admin_options.php#censoring">Options</a> for this to have any effect.</strong></p>
       
   106 							<table  cellspacing="0">
       
   107 							<thead>
       
   108 								<tr>
       
   109 									<th class="tcl" scope="col">Censored&nbsp;word</th>
       
   110 									<th class="tc2" scope="col">Replacement&nbsp;text</th>
       
   111 									<th class="hidehead" scope="col">Action</th>
       
   112 								</tr>
       
   113 							</thead>
       
   114 							<tbody>
       
   115 								<tr>
       
   116 									<td><input type="text" name="new_search_for" size="24" maxlength="60" tabindex="1" /></td>
       
   117 									<td><input type="text" name="new_replace_with" size="24" maxlength="60" tabindex="2" /></td>
       
   118 									<td><input type="submit" name="add_word" value=" Add " tabindex="3" /></td>
       
   119 								</tr>
       
   120 							</tbody>
       
   121 							</table>
       
   122 						</div>
       
   123 					</fieldset>
       
   124 				</div>
       
   125 				<div class="inform">
       
   126 					<fieldset>
       
   127 						<legend>Edit/remove words</legend>
       
   128 						<div class="infldset">
       
   129 <?php
       
   130 
       
   131 $result = $pun_db->query('SELECT id, search_for, replace_with FROM '.$pun_db->prefix.'censoring ORDER BY id') or error('Unable to fetch censor word list', __FILE__, __LINE__, $pun_db->error());
       
   132 if ($pun_db->num_rows($result))
       
   133 {
       
   134 
       
   135 ?>
       
   136 							<table cellspacing="0" >
       
   137 							<thead>
       
   138 								<tr>
       
   139 									<th class="tcl" scope="col">Censored&nbsp;word</th>
       
   140 									<th class="tc2" scope="col">Replacement&nbsp;text</th>
       
   141 									<th class="hidehead" scope="col">Actions</th>
       
   142 								</tr>
       
   143 							</thead>
       
   144 							<tbody>
       
   145 <?php
       
   146 
       
   147 	while ($cur_word = $pun_db->fetch_assoc($result))
       
   148 		echo "\t\t\t\t\t\t\t\t".'<tr><td><input type="text" name="search_for['.$cur_word['id'].']" value="'.pun_htmlspecialchars($cur_word['search_for']).'" size="24" maxlength="60" /></td><td><input type="text" name="replace_with['.$cur_word['id'].']" value="'.pun_htmlspecialchars($cur_word['replace_with']).'" size="24" maxlength="60" /></td><td><input type="submit" name="update['.$cur_word['id'].']" value="Update" />&nbsp;<input type="submit" name="remove['.$cur_word['id'].']" value="Remove" /></td></tr>'."\n";
       
   149 
       
   150 ?>
       
   151 							</tbody>
       
   152 							</table>
       
   153 <?php
       
   154 
       
   155 }
       
   156 else
       
   157 	echo "\t\t\t\t\t\t\t".'<p>No censor words in list.</p>'."\n";
       
   158 
       
   159 ?>
       
   160 						</div>
       
   161 					</fieldset>
       
   162 				</div>
       
   163 			</form>
       
   164 		</div>
       
   165 	</div>
       
   166 	<div class="clearer"></div>
       
   167 </div>
       
   168 <?php
       
   169 
       
   170 require PUN_ROOT.'footer.php';