<?php
/* <Edit> */
// Todo - each imported line from the new blacklist should be displayed
require_once('../wp-config.php');
function add_magic_quotes($array) {
foreach ($array as $k => $v) {
if (is_array($v)) {
$array[$k] = add_magic_quotes($v);
} else {
$array[$k] = addslashes($v);
}
}
return $array;
}
if (!get_magic_quotes_gpc()) {
$_GET = add_magic_quotes($_GET);
$_POST = add_magic_quotes($_POST);
$_COOKIE = add_magic_quotes($_COOKIE);
}
$blfilename = 'http://www.jayallen.org/comment_spam/blacklist.txt';
$wpvarstoreset = array('action', 'blfilename', 'regextype', 'domain', 'search', 'delete_regexs', 'options');
for ($i=0; $i<count($wpvarstoreset); $i += 1) {
$wpvar = $wpvarstoreset[$i];
if (empty($_POST["$wpvar"])) {
if (empty($_GET["$wpvar"])) {
if (!isset($$wpvar)) {
$$wpvar = '';
}
} else {
$$wpvar = $_GET["$wpvar"];
}
} else {
$$wpvar = $_POST["$wpvar"];
}
}
// if this is the first time, the options array will not be created
if (!is_array($options)) {
$options = array();
}
$standalone = 0;
switch($action) {
case 'options':
// delete all options from DB first
$sql = "DELETE FROM blacklist WHERE regex_type = 'option'";
$wpdb->query($sql);
// save options to DB
foreach ($options as $option) {
$sql = "INSERT INTO blacklist (regex, regex_type) VALUES ('$option','option')";
$wpdb->query($sql);
}
break;
case 'export':
require_once('../wp-config.php');
$postquery ="SELECT * FROM blacklist WHERE regex_type='url'";
$exportfile = '';
$results = $wpdb->get_results($postquery);
foreach ($results as $result) {
$exportfile .=$result->regex."\n";
}
//Send the headers to control the download
header('Content-Type: text/comma-separated-values');
header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Content-Disposition: inline; filename="blacklist.txt"');
echo $exportfile;
exit();
case 'import':
$title = 'Manage WPBlacklist - Import';
break;
case 'add':
$title = 'Manage WPBlacklist - Add';
break;
case 'delete':
case 'search':
$title = 'Manage WPBlacklist - Delete';
break;
default:
$title = 'Manage WPBlacklist';
// load options from DB
$sql = "SELECT * FROM blacklist WHERE regex_type = 'option'";
$results = $wpdb->get_results($sql);
if ($results) {
foreach ($results as $result) {
$options[] = $result->regex;
}
}
break;
}
require_once ('./admin-header.php');
if ($user_level <= 0) {
?>
<div class="wrap">
<p>
Since you’re a newcomer, you’ll have to wait for an admin to raise your level to 1, in order to be authorized to modify the Blacklist.<br />
You can also <a href="mailto:<?php echo $admin_email ?>?subject=Plugin permission">e-mail the admin</a> to ask for a promotion.<br />
When you’re promoted, just reload this page to play with the Blacklist. :)
</p>
</div>
<?php
exit();
} // $user_level <= 0
?>
<ul id="adminmenu2">
<li><a href="wpblacklist.php" class="current">設定</a></li>
<li><a href="wpblsearch.php">検索</a></li>
<li class="last"><a href="wpblmoderate.php">Moderate</a></li>
</ul>
<script type="text/javascript">
<!--
function checkAll(form)
{
for (i = 0, n = form.elements.length; i < n; i++) {
if(form.elements[i].type == "checkbox") {
if(form.elements[i].checked == true)
form.elements[i].checked = false;
else
form.elements[i].checked = true;
}
}
}
//-->
</script>
<div class="wrap">
<form name="options" action="wpblacklist.php?action=options" method="post" id="post">
<div id="poststuff">
<fieldset id="postdiv">
<legend><strong>Blacklist Options</strong></legend>
コメントを削除して欲しいかどうか、削除に関するメール通知が欲しいかどうか指定することができます。<br />
<label>
<input type="checkbox" name="options[]" value="sendmail" <?php echo (in_array('sendmail', $options) ? 'checked' : ''); ?> />
コメント削除に関するメールを送る <br />
</label>
<label>
<input type="checkbox" name="options[]" value="deleteip" <?php echo (in_array('deleteip', $options) ? 'checked' : ''); ?> />
ブラックリストに載っているサイトのコメントを削除する <br />
</label>
<label>
<input type="checkbox" name="options[]" value="deleterbl" <?php echo (in_array('deleterbl', $options) ? 'checked' : ''); ?> />
投稿者のIPがブラックリストと一致した場合コメントを削除する(RBL) <br />
</label>
<label>
<input type="checkbox" name="options[]" value="deletemail" <?php echo (in_array('deletemail', $options) ? 'checked' : ''); ?> />
投稿者のe-mailがブラックリストと一致した場合コメントを削除する <br />
</label>
<label>
<input type="checkbox" name="options[]" value="deleteurl" <?php echo (in_array('deleteurl', $options) ? 'checked' : ''); ?> />
投稿者のURLがブラックリストと一致した場合コメントを削除する <br />
</label>
<label>
<input type="checkbox" name="options[]" value="delcommurl" <?php echo (in_array('delcommurl', $options) ? 'checked' : ''); ?> />
コメントの内容がブラックリストと一致するURLを含む場合コメントを削除する <br />
</label>
<input name="saveoptions" type="submit" id="saveoptions" tabindex="9" value="設定を保存" />
</fieldset>
</form>
<br/>
<form name="export" action="wpblacklist.php?action=export" method="post" id="post">
<fieldset id="postdiv">
<legend><strong>Export Blacklist</strong></legend>
<input name="exportblacklist" type="submit" id="exportblacklist" tabindex="9" value="Export Blacklist" />
</fieldset>
</form>
<br/>
<form name="import" action="wpblacklist.php?action=import" method="post" id="post">
<fieldset id="postdiv">
<legend><strong>Import Blacklist</strong></legend>
あなたがインポートしたいブラックリスト・ファイルの名前をタイプインするか貼って、「Import Blacklist」をクリックしてください。<br />
<div>
<input type="text" name="blfilename" size="60" tabindex="1" value="<?php echo $blfilename ?>" id="blfilename" />
</div>
<input name="importblacklist" type="submit" id="importblacklist" tabindex="9" value="Import Blacklist" />
<?php
if ($action == 'import') {
?>
<p>
<b>Import Blacklist Results</b>
<br/><br/>
<?php
$blfile = @file($blfilename);
if (!$blfile) {
echo 'File not found. Please check the path or copy the file to the wp-admin directory.';
} else {
for ($i=0; $i<count($blfile); $i++) {
$data = $blfile[$i];
$temp = "";
for ($j=0; $j<strlen($data); $j++) {
if ($data[$j]==" " || $data[$j] == "#")
break;
else
$temp.=$data[$j];
continue;
}
// modify Jay Allen stuff to work with PHP
if (strpos($temp, '[\w\-_.]')) {
$temp = str_replace('[\w\-_.]','[-\w\_.]',$temp);
}
// get rid of all unescaped forwardslashes
$ps = strpos($temp, '/');
while ($ps !== False) {
if ($ps == 0) {
// slash at beginning, escape
$temp = '\\' + $temp;
} else if (substr($temp, $ps-1, 1) != '\\') {
$temp = substr_replace($temp, '\/', $ps, 1);
}
$ps = strpos($temp, '/', $ps+2);
}
$buf = mysql_escape_string(trim($temp));
// echo "Regex: $temp<br />";
if ($buf != '') {
$request = $wpdb->get_row("SELECT id FROM blacklist WHERE regex='$buf'");
if (!$request) {
$request1 = $wpdb->query("INSERT INTO blacklist (regex,regex_type) VALUES ('$buf','url')");
if ($request1)
echo "<font color='green'>Added : $temp</font><BR />";
else
echo "<font color='red'>Error adding: $temp</font><BR />";
}
}
}
echo 'Done! <br/>';
}
echo '</p>';
} // $action == 'import'
?>
</fieldset>
</form>
<br />
<form name="add" action="wpblacklist.php?action=add" method="post" id="post">
<fieldset id="postdiv">
<legend><strong>Add values to Blacklist</strong></legend>
ドメイン、IPまたはリアルタイムでブラックリストサーバ(RBL)をブラックリストに追加しているかどうかを選択してください、そして、あなたがBlacklistに追加したい表現、IPアドレスまたはRBLサーバをタイプするか、または貼ってください、そして、「追加」をクリックしてください。<br />
<table>
<tr>
<td>Type of Expression</td>
<td>
<select name="regextype">
<option <?php echo ($regextype=='url'? 'selected' : '') ?> value="url">URL</option>
<option <?php echo ($regextype=='ip'? 'selected' : '') ?> value="ip">IP</option>
<option <?php echo ($regextype=='rbl'? 'selected' : '') ?> value="rbl">RBL</option>
</select>
</td>
</tr>
<tr>
<td>Domain URL/IP</td>
<td>
<input type="text" name="domain" size="60" tabindex="1" value="<?php echo $domain ?>" id="domain" />
</td>
</tr>
<tr align="left">
<td> </td>
<td>
<input name="add" type="submit" id="add" tabindex="9" value="追加" />
</td>
</tr>
</table>
<?php
if ($action == 'add') {
?>
<p>
<b>Add to Blacklist Result</b>
<br/><br/>
<?php
if ($regextype == 'url') {
$answer = "Expression : $domain";
} else if ($regextype == 'rbl') {
$answer = "RBL : $domain";
} else {
$answer = "IP : $domain";
}
$request = $wpdb->get_row("SELECT id FROM blacklist WHERE regex='$domain'");
if (!$request) {
$request = $wpdb->query("INSERT INTO blacklist (regex,regex_type) VALUES ('$domain','$regextype')");
if (!$request) {
$answer = $answer . " could not be added!";
} else {
$answer = $answer . " successfully added!";
}
} else {
$answer = $answer . " already exists in blacklist!";
}
echo $answer."<br/></p>";
} // $action == 'add'
?>
</fieldset>
</form>
<br/>
<fieldset id="postdiv">
<legend><strong>Delete from Blacklist</strong></legend>
<form name="search" id="search" action="wpblacklist.php?action=search" method="post">
削除するブラックリスト・アイテムを検索してください。結果は任意の--表現、IPあるいはRBLサーバーのようになるでしょう。<br />
<br /><br />
<input type="text" name="search" value="<?php echo $search; ?>" size="17" />
<input type="submit" name="submit" value="Search" />
</form>
<?php
if ($action == 'delete') {
if (!empty($delete_regexs)) {
$sql = 'DELETE FROM blacklist WHERE ID IN (';
$i = 0;
foreach ($delete_regexs as $id) {
$id = strval($id);
if ($i <> 0) {
$sql = $sql . ',';
}
$sql = $sql . $id;
++$i;
}
$sql = $sql . ')';
$i = $wpdb->query($sql);
echo "<p><b>" . sprintf(__('%s blacklist item(s) deleted.'), $i) . "</b></p>";
} else {
echo "<p><b>" . _e('no blacklist items selected') . "</b></p>";
}
}
?>
<?php
if (($action == 'search') || ($action == 'delete')) {
$search = $wpdb->escape($search);
$regexs = $wpdb->get_results("SELECT * FROM blacklist WHERE regex LIKE '%$search%' ORDER BY id DESC");
if ($regexs) {
?>
<form name="deleteregex" id="deleteregex" action="wpblacklist.php?action=delete" method="post">
<input name="search" type="hidden" value="<?php echo $search; ?>">
<table width="100%" cellpadding="3" cellspacing="3">
<tr>
<th scope="col">*</th>
<th scope="col">Blacklist Item</th>
<th scope="col">Type</th>
</tr>
<?php
foreach ($regexs as $regex) {
$bgcolor = ('#eee' == $bgcolor) ? 'none' : '#eee';
?>
<tr style='background-color: <?php echo $bgcolor; ?>'>
<td>
<input type="checkbox" name="delete_regexs[]" value="<?php echo $regex->id ?>" />
</td>
<td><?php echo $regex->regex ?></td>
<td><?php echo $regex->regex_type ?></td>
</tr>
<?php
} // foreach
?>
</table>
<p>
<a href="javascript:;" onclick="checkAll(document.getElementById('deleteregex')); return false; ">Invert Checkbox Selection</a>
</p>
<p style="text-align: right;">
<input type="submit" name="Submit" value="Delete Checked Items" onclick="return confirm('You are about to delete these blacklist items permanently \\n \'Cancel\' to stop, \'OK\' to delete.) " />
</p>
</form>
<?php
} else {
?>
<p>
<strong>No results found.</strong>
</p>
<?php
} // if ($regexs)
}
?>
</fieldset>
</div>
<?php
/* </Edit> */
include('admin-footer.php');
?>