Файл: sources/admin/manage_bad_words.php
Строк: 300
<?php
if (!defined('VAPHP')) {
die("Этот файл недоступен.");
}
class manage_bad_words extends base
{
function manage_bad_words()
{
global $FORM, $LNG, $TMPL;
$TMPL['header'] = $LNG['a_man_bad_words_header'];
if ((!isset($FORM['word']) && !isset($FORM['replacement']) && !isset($FORM['matching'])) || !$FORM['word'])
{
$this->main();
}
else
{
$this->ban_word();
}
}
function main() {
global $CONF, $DB, $FORM, $LNG, $TMPL;
$TMPL['admin_content'] = <<<EndHTML
{$LNG['a_man_bad_words_instructions']}<br><br>
{$LNG['a_man_bad_words_instructions_matching']}<br><br>
<form action="index.php" method="get">
<input type="hidden" name="a" value="admin" />
<input type="hidden" name="b" value="manage_bad_words" />
<table cellspacing="0" cellpadding="0" width="100%" border=0>
<tr>
<td width="25%">
{$LNG['a_man_bad_words_word']}
</td>
<td width="25%">
{$LNG['a_man_bad_words_replacement']}
</td>
<td width="25%">
{$LNG['a_man_bad_words_matching']}
</td>
</tr>
<tr>
<td>
<input type="text" name="word" class="SmallInput" />
</td>
<td>
<input type="text" name="replacement" class="SmallInput" />
</td>
<td>
<select name="matching" class="SmallInput">
<option value="1">{$LNG['a_man_bad_words_exact']}</option>
<option value="0">{$LNG['a_man_bad_words_global']}</option>
</select>
</td>
<td rowspan="2" width="20%">
<input type="submit" class="ButtonNormal" value="{$LNG['a_man_bad_words_filter']}" />
</td>
</tr>
</table>
</form><br>
EndHTML;
list($num_words) = $DB->fetch("SELECT COUNT(*) FROM {$CONF['sql_prefix']}_bad_words", __FILE__, __LINE__);
//адрес этой страницы
$template_href="{$CONF['site_url']}?a=admin&b=manage_bad_words";
if ($FORM['pp'])
{
$pp = intval($FORM['pp']);
if ($pp < $CONF['sites_per_page'][0]) {$pp = $CONF['sites_per_page'][0];}
}
else {$pp = $CONF['sites_per_page'][0];}
foreach($CONF['sites_per_page'] as $value)
{
if ($pp == $value) {$per_page_menu.= "<b>$value</b> ";}
else{
$per_page_menu.=<<<EndHTML
<a href="{$template_href}&pp=$value">{$value}</a>
EndHTML;
}
}
if (isset($FORM['p']))
{
$p = intval ($FORM['p']);
if ($p > ceil($num_words/$pp) || $p < 1) {$p=1;} //если номер страницы больше максимально возможного - присваиваем ему значение 1
$start = intval($p - 1);
if ($start < 0) $start=0;
$start = $start * $pp;
}
else
{
$p = 1;
$start = 0;
}
if($num_words > $pp) //проверка необходимости в постраничном выводе
{
$TMPL['page_menu'] = '';
$num_page = ceil($num_words/$pp); //количество страниц
$PrevPage = $p-1;
$NextPage = $p+1;
//определение переменных для счетчика цикла
if($num_page > $CONF['lenght_pp_block']){
$left_pages = floor(($CONF['lenght_pp_block']-1)/2);
$number_start_page = $p-$left_pages;
if($number_start_page <= 0) {$number_start_page = 1;}
$number_end_page = $number_start_page + $CONF['lenght_pp_block']-1;
if($number_end_page > $num_page) {$number_end_page = $num_page; $number_start_page = $number_end_page-$CONF['lenght_pp_block']+1;}
}else
{
$number_start_page = 1;
$number_end_page = $num_page;
}
//само построение кода постраничного вывода
if($number_start_page > 1) {
$prev_page = $number_start_page-1;
$TMPL['page_menu'] .= "<a href="{$template_href}&p=1&pp=$pp">1</a> "; //ссылка на самую первую страницу
$TMPL['page_menu'] .= "<a href="{$template_href}&p={$prev_page}&pp=$pp">...</a> "; //
}
for($i=$number_start_page; $i<=$number_end_page; $i++)
{
if($i == $p)
$TMPL['page_menu'] .= "<b>$i</b> ";
else
$TMPL['page_menu'] .= "<a href="{$template_href}&p=$i&pp=$pp">$i</a> ";
}
if($number_end_page < $num_page) {
$next_page = $number_end_page+1;
$TMPL['page_menu'] .= "<a href="{$template_href}&p={$next_page}&pp=$pp">...</a> ";
$TMPL['page_menu'] .= "<a href="{$template_href}&p={$num_page}&pp=$pp">$num_page</a> ";
}
if($p <= 1) {$TMPL['AtStart'] = "<span class=AtStart><IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" src="{$CONF['skins_image']}/button_prev.gif"></span>";}
else {$TMPL['AtStart'] = "<a href="{$template_href}&p={$PrevPage}&pp={$pp}" class=AtStart><IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" src="{$CONF['skins_image']}/button_prev_act.gif"></a>";}
if($p >= $num_page) {$TMPL['AtEnd']="<a class=AtEnd><IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" src="{$CONF['skins_image']}/button_next.gif"></a>";}
else {$TMPL['AtEnd']="<a href="{$template_href}&p={$NextPage}&pp={$pp}" class=AtEnd><IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" src="{$CONF['skins_image']}/button_next_act.gif"></a>";}
$TMPL['page_menu'] = $TMPL['AtStart'].$TMPL['page_menu'].$TMPL['AtEnd'];
$TMPL['page_menu']="<div class="PagingStrip">".$TMPL['page_menu']."</div>";
//конец построения кода постраничного вывода
}
$num_first_site = $start + 1;
$num_final_site = $num_first_site + $pp - 1;
if ($num_final_site > $num_words) {$num_final_site = $num_words;}
$LNG['g_number_of_all'] = sprintf($LNG['g_number_of_all'], $num_first_site, $num_final_site, $num_words);
if ($num_words != 0) $TMPL['admin_content'] .= <<<EndHTML
<table width="100%">
<tr><td colspan="2">
<table width="100%" border=0>
<tr>
<td width="33%"></td>
<td width="33%" align="center"><span class="GreyTextNormal">{$LNG['g_number_of_all']}</span></td>
<td width="33%" align="right"><span class="GreyTextSmall">{$LNG['g_string_per_page']} <img src="{$CONF['skins_image']}/arrow_right.gif"> $per_page_menu</span></td>
</tr>
</table>
</td></tr>
<tr><td colspan="2"><hr width=100% size="1" class="SeparatorHr2"></td></tr>
<tr><td colspan="2" align=center>{$TMPL['page_menu']}</td></tr>
<tr><td colspan="2"><hr width=100% size="1" class="SeparatorHr"></td></tr>
</table>
EndHTML;
$TMPL['admin_content'] .= <<<EndHTML
<script language="javascript">
function check(form_name, field_name, value)
{
var check_boxes = document.forms[form_name].elements[field_name];
var num_check_boxes = check_boxes.length;
if (!num_check_boxes)
{
check_boxes.checked = value;
}
else {
for(var i = 0; i < num_check_boxes; i++)
{
check_boxes[i].checked = value;
}
}
}
</script>
<form action="{$TMPL['site_url']}/index.php?a=admin&b=delete_bad_word" method="post" name="manage">
<table cellpadding="1" cellspacing="1" width="100%">
<tr class="TableHeader">
<td width="18px"></td>
<td width="30%">{$LNG['a_man_bad_words_word']}</td>
<td>{$LNG['a_man_bad_words_replacement']}</td>
<td>{$LNG['a_man_bad_words_matching']}</td>
<td align="center" colspan="2">{$LNG['a_man_bad_words_actions']}</td>
</tr>
EndHTML;
$alt = '';
$num = 0;
$result = $DB->select_limit("SELECT id, word, replacement, matching FROM {$CONF['sql_prefix']}_bad_words ORDER BY id ASC", $pp, $start, __FILE__, __LINE__);
while (list($id, $word, $replacement, $matching) = $DB->fetch_array($result))
{
if ($matching) {
$matching = $LNG['a_man_bad_words_exact'];
}
else {
$matching = $LNG['a_man_bad_words_global'];
}
$TMPL['admin_content'] .= <<<EndHTML
<tr class="lightbg{$alt}">
<td><input type="checkbox" name="id[]" value="{$id}" id="checkbox_{$num}" /></td>
<td>{$word}</td>
<td>{$replacement}</td>
<td>{$matching}</td>
<td align="center"><a href="{$TMPL['site_url']}/index.php?a=admin&b=edit_bad_word&id={$id}">{$LNG['a_man_edit']}</a></td>
<td align="center"><a href="{$TMPL['site_url']}/index.php?a=admin&b=delete_bad_word&id={$id}">{$LNG['a_man_delete']}</a></td>
</tr>
EndHTML;
if ($alt) { $alt = ''; }
else { $alt = 'alt'; }
$num++;
}
$TMPL['admin_content'] .= <<<EndHTML
</table><br>
<a href="javascript:void;" onclick="check('manage', 'id[]', true)">{$LNG['a_man_all']}</a> |
<a href="javascript:void;" onclick="check('manage', 'id[]', false)">{$LNG['a_man_none']}</a><br><br>
<input type="submit" class="ButtonNormal" value="{$LNG['a_man_del_sel']}" />
</form>
EndHTML;
}
function ban_word()
{
global $CONF, $DB, $FORM, $LNG, $TMPL;
$TMPL['word'] = $DB->escape($FORM['word']);
$TMPL['replacement'] = $DB->escape($FORM['replacement']);
$TMPL['matching'] = intval($FORM['matching']);
$DB->query("INSERT INTO {$CONF['sql_prefix']}_bad_words (word, replacement, matching) VALUES ('{$TMPL['word']}', '{$TMPL['replacement']}', {$TMPL['matching']})", __FILE__, __LINE__);
$TMPL['admin_content'] = sprintf($LNG['a_man_bad_words_filtered'], $TMPL['word']);
}
}
?>