From 1c8d07983e58a06539c0fca66c8410965211f991 Mon Sep 17 00:00:00 2001 From: jgen Date: Thu, 5 Dec 2013 19:50:21 -0500 Subject: [PATCH] Fix for PHP Notice being generated. "PHP Notice: Trying to get property of non-object in /comment/main.php on line 325" Details: We don't need to try and get comments for images that don't exist. This might also help speed things up a bit as it should eliminate an unnecessary database query. --- ext/comment/main.php | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/ext/comment/main.php b/ext/comment/main.php index 22bf4551..398c43c0 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -320,13 +320,15 @@ class CommentList extends Extension { $images = array(); while($row = $result->fetch()) { $image = Image::by_id($row["image_id"]); - $comments = $this->get_comments($image->id); - if(class_exists("Ratings")) { - if(strpos($user_ratings, $image->rating) === FALSE) { - $image = null; // this is "clever", I may live to regret it + if (!is_null($image)) { + $comments = $this->get_comments($image->id); + if(class_exists("Ratings")) { + if(strpos($user_ratings, $image->rating) === FALSE) { + $image = null; // this is "clever", I may live to regret it + } } + if(!is_null($image)) $images[] = array($image, $comments); } - if(!is_null($image)) $images[] = array($image, $comments); } $this->theme->display_comment_list($images, $current_page, $total_pages, $user->can("create_comment")); @@ -335,8 +337,7 @@ class CommentList extends Extension { // get comments {{{ private function get_recent_comments($count) { - global $config; - global $database; + global $config, $database; $rows = $database->get_all(" SELECT users.id as user_id, users.name as user_name, users.email as user_email, users.class as user_class, @@ -356,8 +357,7 @@ class CommentList extends Extension { } private function get_user_comments(/*int*/ $user_id, /*int*/ $count, /*int*/ $offset=0) { - global $config; - global $database; + global $config, $database; $rows = $database->get_all(" SELECT users.id as user_id, users.name as user_name, users.email as user_email, users.class as user_class, @@ -378,8 +378,7 @@ class CommentList extends Extension { } private function get_comments(/*int*/ $image_id) { - global $config; - global $database; + global $config, $database; $i_image_id = int_escape($image_id); $rows = $database->get_all(" SELECT @@ -402,9 +401,7 @@ class CommentList extends Extension { // add / remove / edit comments {{{ private function is_comment_limit_hit() { - global $user; - global $config; - global $database; + global $user, $config, $database; // sqlite fails at intervals if($database->get_driver_name() === "sqlite") return false; @@ -493,9 +490,9 @@ class CommentList extends Extension { } return $pagenum; } + private function add_comment_wrapper(/*int*/ $image_id, User $user, /*string*/ $comment) { - global $database; - global $config; + global $database, $config; // basic sanity checks if(!$user->can("create_comment")) {