Файл: adultscript-2.0.3-pro/files/admin/modules/spam/spam.php
Строк: 82
<?php
defined('_VALID') or die('Restricted Access!');
class VModule_Admin_spam
{
public function __construct()
{
}
public function render()
{
$db = VF::factory('database');
$errors = array();
$messages = array();
if (isset($_POST['action']) && isset($_POST['spam_id'])) {
$action = trim($_POST['action']);
$id = (int) trim($_POST['spam_id']);
$cid = (int) trim($_POST['comment_id']);
$type = trim($_POST['type']);
$types = array('video' => 1, 'photo' => 1, 'model' => 1, 'user' => 1);
if ($action == 'delete') {
if ($type != '' && isset($types[$type])) {
$db->query("DELETE FROM #__".$type."_comments WHERE comment_id = ".$cid." LIMIT 1");
$db->query("DELETE FROM #__spam WHERE spam_id = ".$id." LIMIT 1");
$messages[] = 'Comment deleted (spam removed)!';
} else {
$errors[] = 'Invalid type!';
}
} elseif ($action == 'spam') {
$db->query("DELETE FROM #__spam WHERE spam_id = ".$id." LIMIT 1");
$db->query("UPDATE #__".$type."_comments SET spam = '0' WHERE comment_id = ".$cid." LIMIT 1");
$messages[] = 'Removed spam mark!';
} else {
$errors[] = 'Invalid action! What exactly did you click!?';
}
}
if (isset($_POST['submit_actions'])) {
$action = trim($_POST['action']);
$ids = $this->get_checkbox_ids();
if ($ids) {
if ($action == 'delete') {
foreach ($ids as $id) {
$id = (int) $id;
$db->query("SELECT comment_id, type FROM #__spam WHERE spam_id = ".$id." LIMIT 1");
if ($db->affected_rows()) {
$row = $db->fetch_assoc();
$db->query("UPDATE #__".$row['type']."_comments
SET spam = '0'
WHERE comment_id = ".(int) $row['comment_id']."
LIMIT 1");
$db->query("DELETE FROM #__spam WHERE spam_id = ".$id." LIMIT 1");
}
}
$messages[] = 'Removed spam from selected items!';
} else {
$errors[] = 'Invalid action! What exactly did you select!?';
}
} else {
$errors[] = 'Please check at least one item!';
}
}
$page = (isset($_GET['page'])) ? (int) trim($_GET['page']) : 1;
$sql_count = 'SELECT COUNT(*) AS total_comments FROM #__spam';
$total_comments = $db->get_field($sql_count, 'total_comments');
$pagination = VPagination::get($page, $total_comments, 10);
$sql = 'SELECT s.spam_id, s.type, s.spam_date, s.user_id, s.comment_id, u.username
FROM #__spam AS s
LEFT JOIN #__user AS u ON (s.user_id = u.user_id)
ORDER BY s.spam_id DESC
LIMIT '.$pagination['limit'];
$comments = $db->get_rows($sql);
foreach ($comments as $key => $comment) {
$comments[$key]['comment'] = '';
$db->query("SELECT comment
FROM #__".$comment['type']."_comments
WHERE comment_id = ".(int) $comment['comment_id']."
LIMIT 1");
if ($db->affected_rows()) {
$row = $db->fetch_assoc();
$comments[$key]['comment'] = $row['comment'];
unset($row);
}
}
$tpl = VF::factory('template');
$tpl->menu = 'home';
$tpl->submenu = '';
$tpl->meta_title = 'Admin::Spam';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->comments = $comments;
$tpl->pagination = $pagination;
$tpl->load(array('header', 'spam', 'footer'));
$tpl->display();
}
private function get_checkbox_ids()
{
$ids = array();
foreach ($_POST as $key => $value) {
if (strpos($key, 'checkbox_spam_') !== FALSE) {
$ids[] = (int) str_replace('checkbox_spam_', '', $key);
}
}
return $ids;
}
}