$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) {
global $path_prefix;
$two_level_tlds = array_flip(explode("\n", file_get_contents("$path_prefix/api/Comment/two-level-tlds.txt")));
$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 '/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 '/akismet_verify_key':
if (!$is_admin) $msg = "Sorry, only administrators can access Akismet at the moment.";
else {
global $akismet_key, $base_url;
$msg .= "
";
}
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 .= "
checking comment for spam
";
$cmt = new Comment();
$cmt->load((int)$_REQUEST['comment']);
$cmt->akismet_check();
$msg .= "
result: ".var_export($cmt->akismet_spam, TRUE)."
";
}
break;
default:
if (preg_match("~^/delete/(\d+)$~", $path_info, $m)) {
list(, $cid) = $m;
if (!$is_admin) $msg = "Sorry, only administrators can delete comments at the moment :(";
else {
try {
$c = new Comment();
$c->load((int)$cid);
$c->delete();
$msg = "Comment deleted.";
} catch (PAException $e) {
if ($e->code == COMMENT_NOT_EXIST) {
$msg = "Comment already deleted.";
} else throw $e;
}
}
}
}
$per_page = 20; // how many comments to show on a page
// paging
if ($limit_set !== NULL) {
$total_comments = count($limit_set);
} else {
$total_comments = Comment::count_all_comments($is_admin ? 0 : $user->user_id);
}
$pager = new pager($total_comments, $per_page, $paging_url);
$paging = $pager->getButList(8) . " (total $total_comments comments)";
// main comment list
if ($limit_set !== NULL) {
$show_start = max(0, min(($pager->page - 1) * $per_page, $total_comments));
$show_count = min($per_page, $total_comments - $show_start);
$limit_set_ids = array_map(create_function('$item', 'return $item["comment_id"];'),
array_slice($limit_set, $show_start, $show_count));
$cmts = Comment::get_selected($limit_set_ids);
} else {
$cmts = Comment::get_all_comments($is_admin ? 0 : $user->user_id, $per_page, $pager->page);
}
$comments = "";
foreach ($cmts as $cmt) {
// $comments .= "