$msg (mem used ".memory_get_usage()."; delta $mem_delta)
";
$last_mem_used = $current_mem_used;
flush();
}
// --- main page area
function esc_wbr($s) {
$len = strlen($s);
$out = "";
$blklen = 5;
for ($i = 0; $i < $len; $i += $blklen) {
$out .= htmlspecialchars(substr($s, $i, $blklen)) . "";
}
return $out;
}
// This could be moved into a BlockModule at some point - if we ever
// want to run it outside of comment_management.php.
function render_main_page_area($user) {
global $base_url, $admin_password;
$page_url = "$base_url/comment_management.php";
$paging_url = "$page_url?"; // url to pass to the pager object
$msg = "";
$path_info = @$_SERVER['PATH_INFO'];
// see if the user is logged in as an admin
if ($path_info == "/login") {
if (@$_REQUEST['admin_password'] == $admin_password) {
$_SESSION['comment_management_is_admin'] = TRUE;
} else $msg = "Incorrect password! Try again...";
} else if ($path_info == "/logout") {
$_SESSION['comment_management_is_admin'] = FALSE;
$msg = "You are now logged out (of admin mode).";
}
$is_admin = @$_SESSION['comment_management_is_admin'];
$limit_set = NULL; // set this to an array with keys 'comment_id' to limit display to those keys
$current_search_terms = NULL; // current search terms
switch ($path_info) {
case '/analyze_comment':
$comment_id = (int)@$_REQUEST['comment'];
if (!$is_admin) $msg = "Sorry, only administrators can analyze comments at the moment :(";
elseif ($comment_id) {
$cmt = new Comment();
$cmt->load($comment_id);
$cmt->index_spam_domains();
$msg = "
";
}
break;
case '/search':
$current_search_terms = @$_REQUEST['q'];
if (!$is_admin) $msg = "Sorry, only administrators can search comments at the moment :(";
elseif ($current_search_terms) {
$paging_url = "$page_url/search?q=".urlencode($current_search_terms)."&";
$limit_set = Comment::search($current_search_terms);
}
break;
case '/stats':
$msg = "
Stats:
";
list($n) = Dal::query_one("SELECT COUNT(*) FROM {comments}");
list($n_deleted) = Dal::query_one("SELECT COUNT(*) FROM {comments} WHERE is_active=0");
$n_active = $n - $n_deleted;
$msg .= "
$n comments ($n_active active / $n_deleted deleted)
";
list($n_ham) = Dal::query_one("SELECT COUNT(*) FROM {comments} WHERE is_active=1 AND spam_state=0");
$n_spam = $n_active - $n_ham;
$msg .= "
$n_spam active+spam / $n_ham active+not spam
";
list($n_no_class) = Dal::query_one("SELECT COUNT(*) FROM {comments} WHERE is_active=1 AND akismet_spam IS NULL");
$msg .= "
$n_no_class active comments not (yet?) classified by Akismet
";
list($n_akismet_del) = Dal::query_one("SELECT COUNT(*) FROM {comments} WHERE is_active=0 AND akismet_spam=1");
$msg .= "
$n_akismet_del comments flagged as spam by akismet and deleted
";
break;
case '/add_spam_term':
$spam_term = @$_REQUEST['term'];
if (!$is_admin) $msg = "Sorry, only administrators can add spam terms at the moment.";
elseif ($spam_term) {
// find the comments
$matches = Comment::search($spam_term);
$n_deleted = count($matches);
// add the term
Comment::add_spam_term($spam_term);
// and delete the comments
$blk_size = 1000;
$F_fetch_ids = create_function('$item', 'return $item["comment_id"];');
for ($i = 0; $i < count($matches); $i += $blk_size) {
Comment::set_spam_state(array_map($F_fetch_ids, array_slice($matches, $i, $blk_size)), SPAM_STATE_SPAM_WORDS);
}
$msg = "Added ".htmlspecialchars($spam_term).' to the spam term database, and deleted '.$n_deleted.' comments containing it.';
}
break;
case '/analyze_domain':
$domain = @$_REQUEST['domain'];
if (!$is_admin) $msg = "Sorry, only administrators can analyze domains.";
else {
$msg .= "
analysis of domain ".htmlspecialchars($domain).":
";
$domain = new SpamDomain($domain);
foreach ($domain->find_associated_domains() as $r) {
$msg .= "
";
}
break;
case '/blacklist_domain':
$domain = @$_REQUEST['domain'];
if (!$is_admin) $msg = "Sorry, only administrators can blacklist domains.";
elseif (!trim($domain)) $msg = "Invalid domain";
else {
$dom = new SpamDomain($domain);
$dom->set_blacklisted(DOMAIN_BLACKLISTED_MANUALLY);
foreach ($dom->find_associated_domains() as $assoc_domain) {
SpamDomain::recalculate_link_counts_for_domain_id($assoc_domain['domain_id']);
}
}
// FALL THROUGH TO /common_domains
case '/common_domains':
if (!$is_admin) $msg = "Sorry, only administrators can do this.";
else {
list($total_domains, $total_blacklisted_domains) = SpamDomain::count_domains();
$msg .= "
Most common domains (out of total $total_domains, $total_blacklisted_domains blacklisted) in comments:
";
foreach (SpamDomain::get_most_common_domains() as $dom) {
$msg .= "
";
}
break;
case '/akismet_verify_key':
global $akismet_key;
if (!$is_admin) $msg = "Sorry, only administrators can access Akismet at the moment.";
elseif (!$akismet_key) {
$msg .= '
No Akismet key has been configured - Akismet is not active.
";
}
break;
case '/akismet_check_spam':
if (!$is_admin) $msg = "Sorry, only administrators can access Akismet at the moment.";
else {
global $akismet_key, $base_url;
$msg .= "
$current_search
EOS;
} else {
$your_permissions = <<Showing comments on your blog and groups for which you are moderator.
EOS;
}
$page_title = "Manage comments";
global $akismet_key;
if ($akismet_key) $page_title .= " (Akismet active)"; else $page_title .= " (Akismet not configured)";
$page_html = <<