diff --git a/contrib/event_log/main.php b/contrib/event_log/main.php index 67380e20..cb03873d 100644 --- a/contrib/event_log/main.php +++ b/contrib/event_log/main.php @@ -48,7 +48,7 @@ class EventLog extends Extension { $filter_sql = "WHERE $filter = $where"; } - $events = $database->db->GetAll(" + $events = $database->get_all(" SELECT event_log.*,users.name FROM event_log JOIN users ON event_log.owner_id = users.id $filter_sql diff --git a/contrib/image_hash_ban/main.php b/contrib/image_hash_ban/main.php index ee6a775d..dab6d57a 100644 --- a/contrib/image_hash_ban/main.php +++ b/contrib/image_hash_ban/main.php @@ -127,7 +127,7 @@ class Image_Hash_Ban extends Extension { public function get_image_hash_bans() { // FIXME: many global $database; - $bans = $database->db->GetAll("SELECT * FROM image_bans"); + $bans = $database->get_all("SELECT * FROM image_bans"); if($bans) {return $bans;} else {return array();} } diff --git a/contrib/notes/main.php b/contrib/notes/main.php index 36129386..0f30c126 100644 --- a/contrib/notes/main.php +++ b/contrib/notes/main.php @@ -22,7 +22,7 @@ class Notes extends Extension { if(is_a($event, 'DisplayingImageEvent')) { global $database; - $notes = $database->db->GetAll("SELECT * FROM image_notes WHERE image_id = ?", array($event->image->id)); + $notes = $database->get_all("SELECT * FROM image_notes WHERE image_id = ?", array($event->image->id)); $this->theme->display_notes($event->page, $notes); } } diff --git a/contrib/report_image/main.php b/contrib/report_image/main.php index 34f61618..1621eb37 100755 --- a/contrib/report_image/main.php +++ b/contrib/report_image/main.php @@ -137,7 +137,7 @@ class report_image extends Extension { public function get_reported_images() { // FIXME: many global $database; - $reportedimages = $database->db->GetAll("SELECT * FROM ReportImage"); + $reportedimages = $database->get_all("SELECT * FROM ReportImage"); if($reportedimages) {return $reportedimages;} else {return array();} } diff --git a/contrib/rss_comments/main.php b/contrib/rss_comments/main.php index 5d1fd050..edf8c196 100644 --- a/contrib/rss_comments/main.php +++ b/contrib/rss_comments/main.php @@ -33,7 +33,7 @@ class RSS_Comments extends Extension { $page->set_mode("data"); $page->set_type("application/xml"); - $comments = $database->db->GetAll(" + $comments = $database->get_all(" SELECT users.id as user_id, users.name as user_name, comments.comment as comment, comments.id as comment_id, diff --git a/contrib/tag_history/main.php b/contrib/tag_history/main.php index 71b599f3..4fc90807 100644 --- a/contrib/tag_history/main.php +++ b/contrib/tag_history/main.php @@ -141,7 +141,7 @@ class Tag_History extends Extension { public function get_tag_history_from_id($image_id) { global $database; - $row = $database->db->GetAll(" + $row = $database->get_all(" SELECT tag_histories.*, users.name FROM tag_histories JOIN users ON tag_histories.user_id = users.id @@ -154,7 +154,7 @@ class Tag_History extends Extension { public function get_global_tag_history() { global $database; - $row = $database->db->GetAll(" + $row = $database->get_all(" SELECT tag_histories.*, users.name FROM tag_histories JOIN users ON tag_histories.user_id = users.id diff --git a/core/database.class.php b/core/database.class.php index df2fddc3..e8d15cf3 100644 --- a/core/database.class.php +++ b/core/database.class.php @@ -94,6 +94,17 @@ class Database { return $result; } + public function get_all($query, $args=array()) { + $result = $this->db->GetAll($query, $args); + if($result === False) { + print "SQL Error: " . $this->db->ErrorMsg(); + print "
Query: $query"; + print "
Args: "; print_r($args); + exit; + } + return $result; + } + public function cache_execute($time, $query, $args=array()) { global $config; if($config->get_bool('db_cache')) { diff --git a/ext/comment/main.php b/ext/comment/main.php index 4f100a3f..154b205d 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -205,7 +205,7 @@ class CommentList extends Extension { private function get_recent_comments() { global $config; global $database; - $rows = $database->db->GetAll(" + $rows = $database->get_all(" SELECT users.id as user_id, users.name as user_name, comments.comment as comment, comments.id as comment_id, @@ -227,7 +227,7 @@ class CommentList extends Extension { global $config; global $database; $i_image_id = int_escape($image_id); - $rows = $database->db->GetAll(" + $rows = $database->get_all(" SELECT users.id as user_id, users.name as user_name, comments.comment as comment, comments.id as comment_id, diff --git a/ext/et/main.php b/ext/et/main.php index 7fcf3a30..acf46dc7 100644 --- a/ext/et/main.php +++ b/ext/et/main.php @@ -54,7 +54,7 @@ class ET extends Extension { $info['sys_extensions'] = join(', ', $els); //$cfs = array(); - //foreach($database->db->GetAll("SELECT name, value FROM config") as $pair) { + //foreach($database->get_all("SELECT name, value FROM config") as $pair) { // $cfs[] = $pair['name']."=".$pair['value']; //} //$info[''] = "Config: ".join(", ", $cfs); diff --git a/ext/ipban/main.php b/ext/ipban/main.php index fe51deaf..f6668171 100644 --- a/ext/ipban/main.php +++ b/ext/ipban/main.php @@ -122,7 +122,7 @@ class IPBan extends Extension { // database {{{ private function get_bans() { global $database; - $bans = $database->db->GetAll("SELECT * FROM bans"); + $bans = $database->get_all("SELECT * FROM bans"); if($bans) {return $bans;} else {return array();} } diff --git a/ext/tag_list/main.php b/ext/tag_list/main.php index b348aa7d..84dd80e9 100644 --- a/ext/tag_list/main.php +++ b/ext/tag_list/main.php @@ -188,7 +188,7 @@ class TagList extends Extension { "; $args = array($image->id, $config->get_int('tag_list_length')); - $tags = $database->db->GetAll($query, $args); + $tags = $database->get_all($query, $args); if(count($tags) > 0) { $this->theme->display_related_block($page, $tags); } @@ -206,7 +206,7 @@ class TagList extends Extension { "; $args = array($config->get_int('tag_list_length')); - $tags = $database->db->GetAll($query, $args); + $tags = $database->get_all($query, $args); if(count($tags) > 0) { $this->theme->display_popular_block($page, $tags); } @@ -216,12 +216,17 @@ class TagList extends Extension { global $database; global $config; - $tags = tag_explode($search); + $wild_tags = tag_explode($search); + // $search_tags = array(); $tag_id_array = array(); $tags_ok = true; - foreach($tags as $tag) { + foreach($wild_tags as $tag) { + $tag = str_replace("*", "%", $tag); + $tag = str_replace("?", "_", $tag); $tag_ids = $database->db->GetCol("SELECT id FROM tags WHERE tag LIKE ?", array($tag)); + // $search_tags = array_merge($search_tags, + // $database->db->GetCol("SELECT tag FROM tags WHERE tag LIKE ?", array($tag))); $tag_id_array = array_merge($tag_id_array, $tag_ids); $tags_ok = count($tag_ids) > 0; if(!$tags_ok) break; @@ -247,10 +252,10 @@ class TagList extends Extension { "; $args = array($config->get_int('tag_list_length')); - $tags = $database->db->GetAll($query, $args); + $related_tags = $database->get_all($query, $args); print $database->db->ErrorMsg(); - if(count($tags) > 0) { - $this->theme->display_refine_block($page, $tags, $search); + if(count($related_tags) > 0) { + $this->theme->display_refine_block($page, $related_tags, $wild_tags); } } }