Location: PHPKode > projects > XennoBB > xennobb/admin/censoring.php
<?php
/*

  Copyright (C) 2005-2011 UserDot
  Visit XennoBB at www.userdot.net/projects/xennobb
  Originally based on PunBB www.punbb.org

  XennoBB is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published
  by the Free Software Foundation; either version 2 of the License,
  or (at your option) any later version.

  XennoBB is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  MA 02110-1301 USA

 */
define('IN_FORUM_ADMIN', 1);
require dirname(__FILE__) . '/../include/init.php';
if ($forum_user['g_id'] > USER_MOD && !$forum_user['g_global_moderation'])
    BB_Functions::Message($lang['No permission'], true, 1);
$page = isset($_GET['Page']) ? BB_Input::Htmlspecialchars($_GET['Page']) : null;
$submenu = array($lang['Configure'] => 'censoring.php?Page=Configure', $lang['Add'] => 'censoring.php?Page=Add', $lang['Edit'] => 'censoring.php?Page=Edit');
if (isset($_POST['form_sent']))
{
    if (!isset($_SERVER['HTTP_REFERER']) || !preg_match('#/censoring\.php#i', $_SERVER['HTTP_REFERER']))
        BB_Functions::Message($lang['Bad referrer']);
    $form = array_map('trim', $_POST['form']);
    $cms_settings->Set_Namespace('xennobb');
    $res = true;
    while (list($key, $input) = @each($form))
    {
        $key = 'bb_' . $key;
        if ($input != '' || is_int($input))
            $value = $input;
        else
            $value = 'NULL';
        $res &= $cms_settings->Save($key, $value);
        if ($res)
            BB_Admin_Functions::Log_Action('Change censoring configuration', 2);
    }
    $cms_settings->Set_Namespace('');
    BB_Functions::Redirect('censoring.php?Page=Configure', $lang['censor_activated']);
}
if (isset($_POST['add_word']))
{
    BB_Input::Confirm_Referrer('censoring.php');
    $search_for = trim($_POST['new_search_for']);
    $replace_with = trim($_POST['new_replace_with']);
    if ($search_for == '' || $replace_with == '')
        BB_Functions::Message($lang['err_censor_replace']);
    $db->query('INSERT INTO ' . $db->prefix . 'censoring (search_for, replace_with) VALUES (\'' . $db->escape($search_for) . '\', \'' . $db->escape($replace_with) . '\')') or BB_Functions::Error($lang['error_14'], __FILE__, __LINE__, $db->error());
    BB_Admin_Functions::Log_Action('Censor word added ' . search_for, 1);
    BB_Functions::Redirect('censoring.php?Page=Add', $lang['censor_word_added']);
}
else if (isset($_POST['update']))
{
    BB_Input::Confirm_Referrer('censoring.php');
    $id = intval(key($_POST['update']));
    $search_for = trim($_POST['search_for'][$id]);
    $replace_with = trim($_POST['replace_with'][$id]);
    if ($search_for == '' || $replace_with == '')
        BB_Functions::Message($lang['err_replace_and_search']);
    $db->query('UPDATE ' . $db->prefix . 'censoring SET search_for=\'' . $db->escape($search_for) . '\', replace_with=\'' . $db->escape($replace_with) . '\' WHERE id=' . $db->escape($id)) or BB_Functions::Error($lang['error_16'], __FILE__, __LINE__, $db->error());
    BB_Functions::Redirect('censoring.php?Page=Edit', $lang['censor_word_updated']);
}
else if (isset($_POST['remove']))
{
    BB_Input::Confirm_Referrer('censoring.php');
    $id = intval(key($_POST['remove']));
    $db->query('DELETE FROM ' . $db->prefix . 'censoring WHERE id=' . $db->escape($id)) or BB_Functions::Error($lang['error_15'], __FILE__, __LINE__, $db->error());
    BB_Admin_Functions::Log_Action('Censor word removed', 1);
    BB_Functions::Redirect('censoring.php?Page=Edit', $lang['censor_word_removed']);
}
$page_title = BB_Input::Htmlspecialchars($lang['Admin'] . $lang['Censoring']);
require FORUM_ROOT . 'admin/header.php';
if ($page == 'Configure')
{
    echo BB_Template::Generate_Menu($submenu);
    ?>
    <div class="blockform">
        <form id="bans" method="post" action="censoring.php">
            <input type="hidden" name="form_sent" value="1" />
            <div class="inform">
                <div class="infldset file" style="padding:10px">
                    <table class="aligntop" cellspacing="0">
                        <tr>
                            <th class="header"><?php echo $lang['Activate word censor'] ?></th>
                            <td class="tips"><?php BB_Template::Print_Tooltip($lang['tip_25']) ?></td>
                            <td><input type="radio" class="radio_yes" name="form[censoring]" value="1"<?php if (bb_censoring == '1')
        echo ' checked="checked"' ?> />&nbsp;<?php echo $lang['Yes'] ?>&nbsp;&nbsp;&nbsp;<input type="radio" class="radio_no" name="form[censoring]" value="0"<?php if (bb_censoring == '0')
        echo ' checked="checked"' ?> />&nbsp;<?php echo $lang['No'] ?></td>
                        </tr>
                    </table>
                </div>
            </div>
            <div><input type="submit" class="b1" name="save" value="<?php echo $lang['Save'] ?>" tabindex="2" /></div>
        </form>
    </div>
    <?php
}
else if ($page == 'Add')
{
    echo BB_Template::Generate_Menu($submenu);
    $focus_element = array('censoring', 'new_search_for');
    ?>
    <div class="blockform">
        <form id="censoring" method="post" action="censoring.php">
            <div class="inform">
                <div class="infldset file" style="padding:0px">
                    <table>
                        <thead>
                            <tr>
                                <th class="tcl"><?php echo $lang['Censored word']; ?></th>
                                <th class="tc2" style="width:250px"><?php echo $lang['Replacement text']; ?></th>
                                <th class="hidehead">&nbsp;</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td><input type="text" class="textbox" name="new_search_for" size="24" maxlength="60" tabindex="1" /></td>
                                <td><input type="text" class="textbox" name="new_replace_with" size="20" maxlength="60" tabindex="2" /><?php BB_Template::Print_Tooltip($lang['tip_26']) ?></td>
                                <td><input type="submit" class="b1" name="add_word" value="<?php echo $lang['Add'] ?>" tabindex="3" /></td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </form>
    </div>
                    <?php
                }
                else if ($page == 'Edit')
                {
                    echo BB_Template::Generate_Menu($submenu);
                    ?>
    <div class="blockform">
        <form id="censoring" method="post" action="censoring.php">
            <div class="inform">
                <div class="infldset file" style="padding:0px">
    <?php
    $result = $db->query('SELECT id, search_for, replace_with FROM ' . $db->prefix . 'censoring ORDER BY id') or BB_Functions::Error($lang['error_17'], __FILE__, __LINE__, $db->error());
    if ($db->num_rows($result))
    {
        ?>
                        <table>
                            <thead>
                                <tr>
                                    <th class="tcl"><strong><?php echo $lang['Censored word']; ?></strong></th>
                                    <th class="tc2" style="width:150px"><strong><?php echo $lang['Replacement text']; ?></strong></th>
                                    <th class="hidehead">&nbsp;</th>
                                </tr>
                            </thead>
                            <tbody>
        <?php
        while ($cur_word = $db->fetch_assoc($result))
            echo "\t\t\t\t\t\t\t\t" . '<tr><td><input type="text" class="textbox" name="search_for[' . $cur_word['id'] . ']" value="' . BB_Input::Htmlspecialchars($cur_word['search_for']) . '" size="24" maxlength="60" /></td><td><input type="text" class="textbox" name="replace_with[' . $cur_word['id'] . ']" value="' . BB_Input::Htmlspecialchars($cur_word['replace_with']) . '" size="24" maxlength="60" /></td><td><input type="submit" class="b1" name="update[' . $cur_word['id'] . ']" value="' . $lang['Update'] . '" />&nbsp;<input type="submit" class="b1" name="remove[' . $cur_word['id'] . ']" value="' . $lang['Remove'] . '" /></td></tr>' . "\n";
        ?>
                            </tbody>
                        </table>
        <?php
    }
    else
        echo "\t\t\t\t\t\t\t" . '<p>' . $lang['no_cens_words'] . '</p>' . "\n";
    ?>
                </div>
            </div>
        </form>
    </div>
    <?php
}
else
{
    BB_Functions::Message($lang['Bad request']);
}
require FORUM_ROOT . 'admin/footer.php';
?>
Return current item: XennoBB