$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 = "

Analysis of comment $comment_id:


".nl2br(htmlspecialchars($cmt->comment))."



"; } 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).":

    "; } 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:

    "; } 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.

    '; } else { global $base_url; $msg .= "

    verifying akismet key: $akismet_key

    "; $ak = new Akismet($akismet_key); $msg .= "

    result: ".var_export($ak->verify_key("$base_url/user.php?uid=".$user->user_id), TRUE)."

    "; } 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(); try { $cmt->load((int)$_REQUEST['comment']); } catch (PAException $e) { if ($e->getCode() != COMMENT_NOT_EXIST) throw $e; $msg .= "

    Comment already deleted.

    "; break; } $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 .= "
  • ".htmlspecialchars(var_export($cmt, TRUE))."
  • "; $akismet_result = $cmt['akismet_spam'] ? "spam" : "?"; $comments .= "".$cmt['comment_id']."" .$cmt['content_id']."" .esc_wbr($cmt['name'])."" .esc_wbr($cmt['email'])."" .esc_wbr($cmt['homepage'])."" .esc_wbr($cmt['subject'])."" .esc_wbr($cmt['comment'])." $akismet_result analyze" .esc_wbr($cmt['ip_addr'])."" .'
    ak'; } if ($is_admin) { if ($current_search_terms) { $current_search = '

    Currently displaying results for: '.htmlspecialchars($current_search_terms).'. Show all comments.

    '; } else $current_search = ""; $your_permissions = <<

    You are an administrator, so all comments in the site will be displayed.

    Verify Akismet key | Show most common domains | Spam statistics

    Search comment content:

    $current_search EOS; } else { $your_permissions = <<Showing comments on your blog and groups for which you are moderator.

    Or enter the admin password here to adminster the whole site:

    EOS; } $page_title = "Manage comments"; global $akismet_key; if ($akismet_key) $page_title .= " (Akismet active)"; else $page_title .= " (Akismet not configured)"; $page_html = <<

    $page_title

    $msg
    $your_permissions

    $paging

    $comments
    ID Post Name Email Website Subject Comment IP X
    EOS; return $page_html; } // --- $user = new User(); $user->load($login_uid); $page = new PageRenderer(NULL, PAGE_COMMENT_MANAGEMENT, "Manage comments", "container_one_column.tpl", "header.tpl"); $page->add_header_js("fat.js"); $page->add_header_css("$current_theme_path/comment_management.css"); $page->add_module("middle", "top", render_main_page_area($user)); uihelper_set_user_heading($page); echo $page->render(); ?>