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.
This commit is contained in:
jgen 2013-12-05 19:50:21 -05:00
parent a7ab12abdd
commit 1c8d07983e

View File

@ -320,13 +320,15 @@ class CommentList extends Extension {
$images = array(); $images = array();
while($row = $result->fetch()) { while($row = $result->fetch()) {
$image = Image::by_id($row["image_id"]); $image = Image::by_id($row["image_id"]);
$comments = $this->get_comments($image->id); if (!is_null($image)) {
if(class_exists("Ratings")) { $comments = $this->get_comments($image->id);
if(strpos($user_ratings, $image->rating) === FALSE) { if(class_exists("Ratings")) {
$image = null; // this is "clever", I may live to regret it 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")); $this->theme->display_comment_list($images, $current_page, $total_pages, $user->can("create_comment"));
@ -335,8 +337,7 @@ class CommentList extends Extension {
// get comments {{{ // get comments {{{
private function get_recent_comments($count) { private function get_recent_comments($count) {
global $config; 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,
@ -356,8 +357,7 @@ class CommentList extends Extension {
} }
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; 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,
@ -378,8 +378,7 @@ class CommentList extends Extension {
} }
private function get_comments(/*int*/ $image_id) { private function get_comments(/*int*/ $image_id) {
global $config; 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
@ -402,9 +401,7 @@ class CommentList extends Extension {
// add / remove / edit comments {{{ // add / remove / edit comments {{{
private function is_comment_limit_hit() { private function is_comment_limit_hit() {
global $user; global $user, $config, $database;
global $config;
global $database;
// sqlite fails at intervals // sqlite fails at intervals
if($database->get_driver_name() === "sqlite") return false; if($database->get_driver_name() === "sqlite") return false;
@ -493,9 +490,9 @@ class CommentList extends Extension {
} }
return $pagenum; return $pagenum;
} }
private function add_comment_wrapper(/*int*/ $image_id, User $user, /*string*/ $comment) { private function add_comment_wrapper(/*int*/ $image_id, User $user, /*string*/ $comment) {
global $database; global $database, $config;
global $config;
// basic sanity checks // basic sanity checks
if(!$user->can("create_comment")) { if(!$user->can("create_comment")) {