safety wrapper for db->GetAll
git-svn-id: file:///home/shish/svn/shimmie2/trunk@690 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
parent
0c639c1861
commit
3e25a08db2
@ -48,7 +48,7 @@ class EventLog extends Extension {
|
|||||||
$filter_sql = "WHERE $filter = $where";
|
$filter_sql = "WHERE $filter = $where";
|
||||||
}
|
}
|
||||||
|
|
||||||
$events = $database->db->GetAll("
|
$events = $database->get_all("
|
||||||
SELECT event_log.*,users.name FROM event_log
|
SELECT event_log.*,users.name FROM event_log
|
||||||
JOIN users ON event_log.owner_id = users.id
|
JOIN users ON event_log.owner_id = users.id
|
||||||
$filter_sql
|
$filter_sql
|
||||||
|
@ -127,7 +127,7 @@ class Image_Hash_Ban extends Extension {
|
|||||||
public function get_image_hash_bans() {
|
public function get_image_hash_bans() {
|
||||||
// FIXME: many
|
// FIXME: many
|
||||||
global $database;
|
global $database;
|
||||||
$bans = $database->db->GetAll("SELECT * FROM image_bans");
|
$bans = $database->get_all("SELECT * FROM image_bans");
|
||||||
if($bans) {return $bans;}
|
if($bans) {return $bans;}
|
||||||
else {return array();}
|
else {return array();}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ class Notes extends Extension {
|
|||||||
|
|
||||||
if(is_a($event, 'DisplayingImageEvent')) {
|
if(is_a($event, 'DisplayingImageEvent')) {
|
||||||
global $database;
|
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);
|
$this->theme->display_notes($event->page, $notes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ class report_image extends Extension {
|
|||||||
public function get_reported_images() {
|
public function get_reported_images() {
|
||||||
// FIXME: many
|
// FIXME: many
|
||||||
global $database;
|
global $database;
|
||||||
$reportedimages = $database->db->GetAll("SELECT * FROM ReportImage");
|
$reportedimages = $database->get_all("SELECT * FROM ReportImage");
|
||||||
if($reportedimages) {return $reportedimages;}
|
if($reportedimages) {return $reportedimages;}
|
||||||
else {return array();}
|
else {return array();}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ class RSS_Comments extends Extension {
|
|||||||
$page->set_mode("data");
|
$page->set_mode("data");
|
||||||
$page->set_type("application/xml");
|
$page->set_type("application/xml");
|
||||||
|
|
||||||
$comments = $database->db->GetAll("
|
$comments = $database->get_all("
|
||||||
SELECT
|
SELECT
|
||||||
users.id as user_id, users.name as user_name,
|
users.id as user_id, users.name as user_name,
|
||||||
comments.comment as comment, comments.id as comment_id,
|
comments.comment as comment, comments.id as comment_id,
|
||||||
|
@ -141,7 +141,7 @@ class Tag_History extends Extension {
|
|||||||
public function get_tag_history_from_id($image_id)
|
public function get_tag_history_from_id($image_id)
|
||||||
{
|
{
|
||||||
global $database;
|
global $database;
|
||||||
$row = $database->db->GetAll("
|
$row = $database->get_all("
|
||||||
SELECT tag_histories.*, users.name
|
SELECT tag_histories.*, users.name
|
||||||
FROM tag_histories
|
FROM tag_histories
|
||||||
JOIN users ON tag_histories.user_id = users.id
|
JOIN users ON tag_histories.user_id = users.id
|
||||||
@ -154,7 +154,7 @@ class Tag_History extends Extension {
|
|||||||
public function get_global_tag_history()
|
public function get_global_tag_history()
|
||||||
{
|
{
|
||||||
global $database;
|
global $database;
|
||||||
$row = $database->db->GetAll("
|
$row = $database->get_all("
|
||||||
SELECT tag_histories.*, users.name
|
SELECT tag_histories.*, users.name
|
||||||
FROM tag_histories
|
FROM tag_histories
|
||||||
JOIN users ON tag_histories.user_id = users.id
|
JOIN users ON tag_histories.user_id = users.id
|
||||||
|
@ -94,6 +94,17 @@ class Database {
|
|||||||
return $result;
|
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 "<br>Query: $query";
|
||||||
|
print "<br>Args: "; print_r($args);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
public function cache_execute($time, $query, $args=array()) {
|
public function cache_execute($time, $query, $args=array()) {
|
||||||
global $config;
|
global $config;
|
||||||
if($config->get_bool('db_cache')) {
|
if($config->get_bool('db_cache')) {
|
||||||
|
@ -205,7 +205,7 @@ class CommentList extends Extension {
|
|||||||
private function get_recent_comments() {
|
private function get_recent_comments() {
|
||||||
global $config;
|
global $config;
|
||||||
global $database;
|
global $database;
|
||||||
$rows = $database->db->GetAll("
|
$rows = $database->get_all("
|
||||||
SELECT
|
SELECT
|
||||||
users.id as user_id, users.name as user_name,
|
users.id as user_id, users.name as user_name,
|
||||||
comments.comment as comment, comments.id as comment_id,
|
comments.comment as comment, comments.id as comment_id,
|
||||||
@ -227,7 +227,7 @@ class CommentList extends Extension {
|
|||||||
global $config;
|
global $config;
|
||||||
global $database;
|
global $database;
|
||||||
$i_image_id = int_escape($image_id);
|
$i_image_id = int_escape($image_id);
|
||||||
$rows = $database->db->GetAll("
|
$rows = $database->get_all("
|
||||||
SELECT
|
SELECT
|
||||||
users.id as user_id, users.name as user_name,
|
users.id as user_id, users.name as user_name,
|
||||||
comments.comment as comment, comments.id as comment_id,
|
comments.comment as comment, comments.id as comment_id,
|
||||||
|
@ -54,7 +54,7 @@ class ET extends Extension {
|
|||||||
$info['sys_extensions'] = join(', ', $els);
|
$info['sys_extensions'] = join(', ', $els);
|
||||||
|
|
||||||
//$cfs = array();
|
//$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'];
|
// $cfs[] = $pair['name']."=".$pair['value'];
|
||||||
//}
|
//}
|
||||||
//$info[''] = "Config: ".join(", ", $cfs);
|
//$info[''] = "Config: ".join(", ", $cfs);
|
||||||
|
@ -122,7 +122,7 @@ class IPBan extends Extension {
|
|||||||
// database {{{
|
// database {{{
|
||||||
private function get_bans() {
|
private function get_bans() {
|
||||||
global $database;
|
global $database;
|
||||||
$bans = $database->db->GetAll("SELECT * FROM bans");
|
$bans = $database->get_all("SELECT * FROM bans");
|
||||||
if($bans) {return $bans;}
|
if($bans) {return $bans;}
|
||||||
else {return array();}
|
else {return array();}
|
||||||
}
|
}
|
||||||
|
@ -188,7 +188,7 @@ class TagList extends Extension {
|
|||||||
";
|
";
|
||||||
$args = array($image->id, $config->get_int('tag_list_length'));
|
$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) {
|
if(count($tags) > 0) {
|
||||||
$this->theme->display_related_block($page, $tags);
|
$this->theme->display_related_block($page, $tags);
|
||||||
}
|
}
|
||||||
@ -206,7 +206,7 @@ class TagList extends Extension {
|
|||||||
";
|
";
|
||||||
$args = array($config->get_int('tag_list_length'));
|
$args = array($config->get_int('tag_list_length'));
|
||||||
|
|
||||||
$tags = $database->db->GetAll($query, $args);
|
$tags = $database->get_all($query, $args);
|
||||||
if(count($tags) > 0) {
|
if(count($tags) > 0) {
|
||||||
$this->theme->display_popular_block($page, $tags);
|
$this->theme->display_popular_block($page, $tags);
|
||||||
}
|
}
|
||||||
@ -216,12 +216,17 @@ class TagList extends Extension {
|
|||||||
global $database;
|
global $database;
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
$tags = tag_explode($search);
|
$wild_tags = tag_explode($search);
|
||||||
|
// $search_tags = array();
|
||||||
|
|
||||||
$tag_id_array = array();
|
$tag_id_array = array();
|
||||||
$tags_ok = true;
|
$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));
|
$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);
|
$tag_id_array = array_merge($tag_id_array, $tag_ids);
|
||||||
$tags_ok = count($tag_ids) > 0;
|
$tags_ok = count($tag_ids) > 0;
|
||||||
if(!$tags_ok) break;
|
if(!$tags_ok) break;
|
||||||
@ -247,10 +252,10 @@ class TagList extends Extension {
|
|||||||
";
|
";
|
||||||
$args = array($config->get_int('tag_list_length'));
|
$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();
|
print $database->db->ErrorMsg();
|
||||||
if(count($tags) > 0) {
|
if(count($related_tags) > 0) {
|
||||||
$this->theme->display_refine_block($page, $tags, $search);
|
$this->theme->display_refine_block($page, $related_tags, $wild_tags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user