More comments, removing dead code, fixing small bugs.

This commit is contained in:
jgen 2014-04-28 17:36:52 -04:00
parent 86612bb1ff
commit 2a9f76d2f0
2 changed files with 86 additions and 19 deletions

View File

@ -12,8 +12,18 @@
require_once "lib/akismet.class.php"; require_once "lib/akismet.class.php";
class CommentPostingEvent extends Event { class CommentPostingEvent extends Event {
var $image_id, $user, $comment; /** @var int */
public $image_id;
/** @var \User */
public $user;
/** @var string */
public $comment;
/**
* @param int $image_id
* @param \User $user
* @param string $comment
*/
public function __construct($image_id, $user, $comment) { public function __construct($image_id, $user, $comment) {
$this->image_id = $image_id; $this->image_id = $image_id;
$this->user = $user; $this->user = $user;
@ -27,8 +37,12 @@ class CommentPostingEvent extends Event {
* and what should be kept? * and what should be kept?
*/ */
class CommentDeletionEvent extends Event { class CommentDeletionEvent extends Event {
var $comment_id; /** @var int */
public $comment_id;
/**
* @param int $comment_id
*/
public function __construct($comment_id) { public function __construct($comment_id) {
$this->comment_id = $comment_id; $this->comment_id = $comment_id;
} }
@ -54,11 +68,18 @@ class Comment {
$this->posted = $row['posted']; $this->posted = $row['posted'];
} }
/**
* @param \User $user
* @return mixed
*/
public static function count_comments_by_user($user) { public static function count_comments_by_user($user) {
global $database; global $database;
return $database->get_one("SELECT COUNT(*) AS count FROM comments WHERE owner_id=:owner_id", array("owner_id"=>$user->id)); return $database->get_one("SELECT COUNT(*) AS count FROM comments WHERE owner_id=:owner_id", array("owner_id"=>$user->id));
} }
/**
* @return null|User
*/
public function get_owner() { public function get_owner() {
if(empty($this->owner)) $this->owner = User::by_id($this->owner_id); if(empty($this->owner)) $this->owner = User::by_id($this->owner_id);
return $this->owner; return $this->owner;
@ -265,19 +286,20 @@ class CommentList extends Extension {
} }
public function onSearchTermParse(SearchTermParseEvent $event) { public function onSearchTermParse(SearchTermParseEvent $event) {
global $database;
$matches = array(); $matches = array();
if(preg_match("/^comments([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])(\d+)$/i", $event->term, $matches)) { if(preg_match("/^comments([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])(\d+)$/i", $event->term, $matches)) {
$cmp = ltrim($matches[1], ":") ?: "="; $cmp = ltrim($matches[1], ":") ?: "=";
$comments = $matches[2]; $comments = $matches[2];
$event->add_querylet(new Querylet("images.id IN (SELECT DISTINCT image_id FROM comments GROUP BY image_id HAVING count(image_id) $cmp $comments)")); $event->add_querylet(new Querylet("images.id IN (SELECT DISTINCT image_id FROM comments GROUP BY image_id HAVING count(image_id) $cmp $comments)"));
} }
else if(preg_match("/^commented_by[=|:](.*)$/i", $event->term, $matches)) { else if(preg_match("/^commented_by[=|:](.*)$/i", $event->term, $matches)) {
global $database;
$user = User::by_name($matches[1]); $user = User::by_name($matches[1]);
if(!is_null($user)) { if(!is_null($user)) {
$user_id = $user->id; $user_id = $user->id;
} } else {
else {
$user_id = -1; $user_id = -1;
} }
@ -290,13 +312,18 @@ class CommentList extends Extension {
} }
// page building {{{ // page building {{{
/**
* @param int $current_page
*/
private function build_page(/*int*/ $current_page) { private function build_page(/*int*/ $current_page) {
global $page, $config, $database, $user; global $database, $user;
if(class_exists("Ratings")) { if(class_exists("Ratings")) {
$user_ratings = Ratings::get_user_privs($user); $user_ratings = Ratings::get_user_privs($user);
} else {
$user_ratings = "";
} }
$where = SPEED_HAX ? "WHERE posted > now() - interval '24 hours'" : ""; $where = SPEED_HAX ? "WHERE posted > now() - interval '24 hours'" : "";
$total_pages = $database->cache->get("comment_pages"); $total_pages = $database->cache->get("comment_pages");
@ -341,8 +368,12 @@ class CommentList extends Extension {
// }}} // }}}
// get comments {{{ // get comments {{{
/**
* @param int $count
* @return array
*/
private function get_recent_comments($count) { private function get_recent_comments($count) {
global $config, $database; global $database;
$rows = $database->get_all(" $rows = $database->get_all("
SELECT SELECT
users.id as user_id, users.name as user_name, users.email as user_email, users.class as user_class, users.id as user_id, users.name as user_name, users.email as user_email, users.class as user_class,
@ -361,8 +392,14 @@ class CommentList extends Extension {
return $comments; return $comments;
} }
/**
* @param int $user_id
* @param int $count
* @param int $offset
* @return array
*/
private function get_user_comments(/*int*/ $user_id, /*int*/ $count, /*int*/ $offset=0) { private function get_user_comments(/*int*/ $user_id, /*int*/ $count, /*int*/ $offset=0) {
global $config, $database; global $database;
$rows = $database->get_all(" $rows = $database->get_all("
SELECT SELECT
users.id as user_id, users.name as user_name, users.email as user_email, users.class as user_class, users.id as user_id, users.name as user_name, users.email as user_email, users.class as user_class,
@ -382,8 +419,12 @@ class CommentList extends Extension {
return $comments; return $comments;
} }
/**
* @param int $image_id
* @return array
*/
private function get_comments(/*int*/ $image_id) { private function get_comments(/*int*/ $image_id) {
global $config, $database; global $database;
$i_image_id = int_escape($image_id); $i_image_id = int_escape($image_id);
$rows = $database->get_all(" $rows = $database->get_all("
SELECT SELECT

View File

@ -18,8 +18,12 @@ class CommentListTheme extends Themelet {
} }
/** /**
* Display a page with a list of images, and for each image, * Display a page with a list of images, and for each image, the image's comments.
* the image's comments *
* @param array $images
* @param int $page_number
* @param int $total_pages
* @param bool $can_post
*/ */
public function display_comment_list($images, $page_number, $total_pages, $can_post) { public function display_comment_list($images, $page_number, $total_pages, $can_post) {
global $config, $page, $user; global $config, $page, $user;
@ -119,9 +123,9 @@ class CommentListTheme extends Themelet {
/** /**
* Add some comments to the page, probably in a sidebar * Add some comments to the page, probably in a sidebar.
* *
* $comments = an array of Comment objects to be shown * @param \Comment[] $comments An array of Comment objects to be shown
*/ */
public function display_recent_comments($comments) { public function display_recent_comments($comments) {
global $page; global $page;
@ -136,7 +140,11 @@ class CommentListTheme extends Themelet {
/** /**
* Show comments for an image * Show comments for an image.
*
* @param Image $image
* @param \Comment[] $comments
* @param bool $postbox
*/ */
public function display_image_comments(Image $image, $comments, $postbox) { public function display_image_comments(Image $image, $comments, $postbox) {
global $page; global $page;
@ -153,9 +161,12 @@ class CommentListTheme extends Themelet {
/** /**
* Show comments made by a user * Show comments made by a user.
*
* @param \Comment[] $comments
* @param \User $user
*/ */
public function display_recent_user_comments($comments, $user) { public function display_recent_user_comments($comments, User $user) {
global $page; global $page;
$html = ""; $html = "";
foreach($comments as $comment) { foreach($comments as $comment) {
@ -170,7 +181,13 @@ class CommentListTheme extends Themelet {
$page->add_block(new Block("Comments", $html, "left", 70, "comment-list-user")); $page->add_block(new Block("Comments", $html, "left", 70, "comment-list-user"));
} }
public function display_all_user_comments($comments, $page_number, $total_pages, $user) { /**
* @param \Comment[] $comments
* @param int $page_number
* @param int $total_pages
* @param \User $user
*/
public function display_all_user_comments($comments, $page_number, $total_pages, User $user) {
global $page; global $page;
assert(is_numeric($page_number)); assert(is_numeric($page_number));
@ -203,7 +220,12 @@ class CommentListTheme extends Themelet {
$this->display_paginator($page, "comment/beta-search/{$user->name}", null, $page_number, $total_pages); $this->display_paginator($page, "comment/beta-search/{$user->name}", null, $page_number, $total_pages);
} }
protected function comment_to_html($comment, $trim=false) { /**
* @param \Comment $comment
* @param bool $trim
* @return string
*/
protected function comment_to_html(Comment $comment, $trim=false) {
global $config, $user; global $config, $user;
$tfe = new TextFormattingEvent($comment->comment); $tfe = new TextFormattingEvent($comment->comment);
@ -276,6 +298,10 @@ class CommentListTheme extends Themelet {
return $html; return $html;
} }
/**
* @param int $image_id
* @return string
*/
protected function build_postbox(/*int*/ $image_id) { protected function build_postbox(/*int*/ $image_id) {
global $config; global $config;