more pdo compat
This commit is contained in:
parent
9e00675900
commit
8d978aa06a
4 changed files with 39 additions and 42 deletions
|
@ -148,7 +148,7 @@ class Image {
|
|||
else {
|
||||
$querylet = Image::build_search_querylet($tags);
|
||||
$result = $database->execute($querylet->sql, $querylet->variables);
|
||||
return $result->RecordCount();
|
||||
return $result->rowCount();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -365,7 +365,7 @@ class Image {
|
|||
public function set_source($source) {
|
||||
global $database;
|
||||
if(empty($source)) $source = null;
|
||||
$database->execute("UPDATE images SET source=? WHERE id=?", array($source, $this->id));
|
||||
$database->execute("UPDATE images SET source=:source WHERE id=:id", array("source"=>$source, "id"=>$this->id));
|
||||
}
|
||||
|
||||
|
||||
|
@ -378,7 +378,7 @@ class Image {
|
|||
$sln = $database->engine->scoreql_to_sql("SCORE_BOOL_$ln");
|
||||
$sln = str_replace("'", "", $sln);
|
||||
$sln = str_replace('"', "", $sln);
|
||||
$database->execute("UPDATE images SET locked=? WHERE id=?", array($sln, $this->id));
|
||||
$database->execute("UPDATE images SET locked=:yn WHERE id=:id", array("yn"=>$sln, "id"=>$this->id));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -390,8 +390,8 @@ class Image {
|
|||
global $database;
|
||||
$database->execute(
|
||||
"UPDATE tags SET count = count - 1 WHERE id IN ".
|
||||
"(SELECT tag_id FROM image_tags WHERE image_id = ?)", array($this->id));
|
||||
$database->execute("DELETE FROM image_tags WHERE image_id=?", array($this->id));
|
||||
"(SELECT tag_id FROM image_tags WHERE image_id = :id)", array("id"=>$this->id));
|
||||
$database->execute("DELETE FROM image_tags WHERE image_id=:id", array("id"=>$this->id));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -411,30 +411,30 @@ class Image {
|
|||
foreach($tags as $tag) {
|
||||
$id = $database->db->GetOne(
|
||||
$database->engine->scoreql_to_sql(
|
||||
"SELECT id FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(?)"
|
||||
"SELECT id FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag)"
|
||||
),
|
||||
array($tag));
|
||||
array("tag"=>$tag));
|
||||
if(empty($id)) {
|
||||
// a new tag
|
||||
$database->execute(
|
||||
"INSERT INTO tags(tag) VALUES (?)",
|
||||
array($tag));
|
||||
"INSERT INTO tags(tag) VALUES (:tag)",
|
||||
array("tag"=>$tag));
|
||||
$database->execute(
|
||||
"INSERT INTO image_tags(image_id, tag_id)
|
||||
VALUES(?, (SELECT id FROM tags WHERE tag = ?))",
|
||||
array($this->id, $tag));
|
||||
VALUES(:id, (SELECT id FROM tags WHERE tag = :tag))",
|
||||
array("id"=>$this->id, "tag"=>$tag));
|
||||
}
|
||||
else {
|
||||
// user of an existing tag
|
||||
$database->execute(
|
||||
"INSERT INTO image_tags(image_id, tag_id) VALUES(?, ?)",
|
||||
array($this->id, $id));
|
||||
"INSERT INTO image_tags(image_id, tag_id) VALUES(:iid, :tid)",
|
||||
array("iid"=>$this->id, "tid"=>$id));
|
||||
}
|
||||
$database->execute(
|
||||
$database->engine->scoreql_to_sql(
|
||||
"UPDATE tags SET count = count + 1 WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(?)"
|
||||
"UPDATE tags SET count = count + 1 WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag)"
|
||||
),
|
||||
array($tag));
|
||||
array("tag"=>$tag));
|
||||
}
|
||||
|
||||
log_info("core-image", "Tags for Image #{$this->id} set to: ".implode(" ", $tags));
|
||||
|
@ -447,7 +447,7 @@ class Image {
|
|||
public function delete() {
|
||||
global $database;
|
||||
$this->delete_tags_from_image();
|
||||
$database->execute("DELETE FROM images WHERE id=?", array($this->id));
|
||||
$database->execute("DELETE FROM images WHERE id=:id", array("id"=>$this->id));
|
||||
log_info("core-image", "Deleted Image #{$this->id} ({$this->hash})");
|
||||
|
||||
unlink($this->get_image_filename());
|
||||
|
@ -595,8 +595,8 @@ class Image {
|
|||
$query = new Querylet($database->engine->scoreql_to_sql("
|
||||
SELECT images.* FROM images
|
||||
JOIN image_tags ON images.id = image_tags.image_id
|
||||
WHERE tag_id = (SELECT tags.id FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(?))
|
||||
"), array($tag_querylets[0]->tag));
|
||||
WHERE tag_id = (SELECT tags.id FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag))
|
||||
"), array("tag"=>$tag_querylets[0]->tag));
|
||||
|
||||
if(strlen($img_search->sql) > 0) {
|
||||
$query->append_sql(" AND ");
|
||||
|
@ -613,9 +613,9 @@ class Image {
|
|||
foreach($tag_querylets as $tq) {
|
||||
$tag_ids = $database->db->GetCol(
|
||||
$database->engine->scoreql_to_sql(
|
||||
"SELECT id FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(?)"
|
||||
"SELECT id FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag)"
|
||||
),
|
||||
array($tq->tag));
|
||||
array("tag"=>$tq->tag));
|
||||
if($tq->positive) {
|
||||
$positive_tag_id_array = array_merge($positive_tag_id_array, $tag_ids);
|
||||
$tags_ok = count($tag_ids) > 0;
|
||||
|
@ -728,8 +728,8 @@ class Image {
|
|||
$terms = array();
|
||||
foreach($tag_querylets as $tq) {
|
||||
$sign = $tq->positive ? "+" : "-";
|
||||
$sql .= " $sign (tag LIKE ?)";
|
||||
$terms[] = $tq->tag;
|
||||
$sql .= " $sign (tag LIKE :tag)";
|
||||
$terms["tag"] = $tq->tag;
|
||||
|
||||
if($sign == "+") $positive_tag_count++;
|
||||
else $negative_tag_count++;
|
||||
|
@ -768,7 +768,7 @@ class Image {
|
|||
SELECT images.*, UNIX_TIMESTAMP(posted) AS posted_timestamp
|
||||
FROM tags, image_tags, images
|
||||
WHERE
|
||||
tag LIKE ?
|
||||
tag LIKE :tag
|
||||
AND tags.id = image_tags.tag_id
|
||||
AND image_tags.image_id = images.id
|
||||
",
|
||||
|
@ -788,7 +788,7 @@ class Image {
|
|||
$tag_id_array = array();
|
||||
$tags_ok = true;
|
||||
foreach($tag_search->variables as $tag) {
|
||||
$tag_ids = $database->db->GetCol("SELECT id FROM tags WHERE tag LIKE ?", array($tag));
|
||||
$tag_ids = $database->get_col("SELECT id FROM tags WHERE tag LIKE :tag", array("tag"=>$tag));
|
||||
$tag_id_array = array_merge($tag_id_array, $tag_ids);
|
||||
$tags_ok = count($tag_ids) > 0;
|
||||
if(!$tags_ok) break;
|
||||
|
@ -803,10 +803,10 @@ class Image {
|
|||
JOIN tags ON image_tags.tag_id = tags.id
|
||||
WHERE tags.id IN ({$tag_id_list})
|
||||
GROUP BY images.id
|
||||
HAVING score = ?",
|
||||
HAVING score = :score",
|
||||
array_merge(
|
||||
$tag_search->variables,
|
||||
array($positive_tag_count)
|
||||
array("score"=>$positive_tag_count)
|
||||
)
|
||||
);
|
||||
$query = new Querylet("
|
||||
|
@ -895,7 +895,7 @@ class Tag {
|
|||
assert(is_string($tag));
|
||||
|
||||
global $database;
|
||||
$newtag = $database->db->GetOne("SELECT newtag FROM aliases WHERE oldtag=?", array($tag));
|
||||
$newtag = $database->get_one("SELECT newtag FROM aliases WHERE oldtag=:tag", array("tag"=>$tag));
|
||||
if(!empty($newtag)) {
|
||||
return $newtag;
|
||||
} else {
|
||||
|
|
|
@ -53,14 +53,14 @@ class User {
|
|||
public static function by_id($id) {
|
||||
assert(is_numeric($id));
|
||||
global $database;
|
||||
$row = $database->get_row("SELECT * FROM users WHERE id = ?", array($id));
|
||||
$row = $database->get_row("SELECT * FROM users WHERE id = :id", array("id"=>$id));
|
||||
return is_null($row) ? null : new User($row);
|
||||
}
|
||||
|
||||
public static function by_name($name) {
|
||||
assert(is_string($name));
|
||||
global $database;
|
||||
$row = $database->get_row("SELECT * FROM users WHERE name = ?", array($name));
|
||||
$row = $database->get_row("SELECT * FROM users WHERE name = :name", array("name"=>$name));
|
||||
return is_null($row) ? null : new User($row);
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ class User {
|
|||
assert(is_string($hash));
|
||||
assert(strlen($hash) == 32);
|
||||
global $database;
|
||||
$row = $database->get_row("SELECT * FROM users WHERE name = ? AND pass = ?", array($name, $hash));
|
||||
$row = $database->get_row("SELECT * FROM users WHERE name = :name AND pass = :hash", array("name"=>$name, "hash"=>$hash));
|
||||
return is_null($row) ? null : new User($row);
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ class User {
|
|||
assert(is_numeric($offset));
|
||||
assert(is_numeric($limit));
|
||||
global $database;
|
||||
$rows = $database->get_all("SELECT * FROM users WHERE id >= ? AND id < ?", array($offset, $offset+$limit));
|
||||
$rows = $database->get_all("SELECT * FROM users WHERE id >= :start AND id < :end", array("start"=>$offset, "end"=>$offset+$limit));
|
||||
return array_map("_new_user", $rows);
|
||||
}
|
||||
|
||||
|
@ -119,20 +119,20 @@ class User {
|
|||
assert(is_bool($admin));
|
||||
global $database;
|
||||
$yn = $admin ? 'Y' : 'N';
|
||||
$database->Execute("UPDATE users SET admin=? WHERE id=?", array($yn, $this->id));
|
||||
$database->Execute("UPDATE users SET admin=:yn WHERE id=:id", array("yn"=>$yn, "id"=>$this->id));
|
||||
log_info("core-user", "Made {$this->name} admin=$yn");
|
||||
}
|
||||
|
||||
public function set_password($password) {
|
||||
global $database;
|
||||
$hash = md5(strtolower($this->name) . $password);
|
||||
$database->Execute("UPDATE users SET pass=? WHERE id=?", array($hash, $this->id));
|
||||
$database->Execute("UPDATE users SET pass=:hash WHERE id=:id", array("hash"=>$hash, "id"=>$this->id));
|
||||
log_info("core-user", "Set password for {$this->name}");
|
||||
}
|
||||
|
||||
public function set_email($address) {
|
||||
global $database;
|
||||
$database->Execute("UPDATE users SET email=? WHERE id=?", array($address, $this->id));
|
||||
$database->Execute("UPDATE users SET email=:email WHERE id=:id", array("email"=>$address, "id"=>$this->id));
|
||||
log_info("core-user", "Set email for {$this->name}");
|
||||
}
|
||||
|
||||
|
@ -181,6 +181,5 @@ class User {
|
|||
public function check_auth_token() {
|
||||
return ($_POST["auth_token"] == $this->get_auth_token());
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -51,7 +51,7 @@ class Comment {
|
|||
|
||||
public static function count_comments_by_user($user) {
|
||||
global $database;
|
||||
return $database->db->GetOne("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));
|
||||
}
|
||||
|
||||
public function get_owner() {
|
||||
|
@ -265,12 +265,12 @@ class CommentList extends SimpleExtension {
|
|||
";
|
||||
$result = $database->Execute($get_threads, array("limit"=>$threads_per_page, "offset"=>$start));
|
||||
|
||||
$total_pages = (int)($database->db->GetOne("SELECT COUNT(c1) FROM (SELECT COUNT(image_id) AS c1 FROM comments GROUP BY image_id) AS s1") / 10);
|
||||
$total_pages = (int)($database->get_one("SELECT COUNT(c1) FROM (SELECT COUNT(image_id) AS c1 FROM comments GROUP BY image_id) AS s1") / 10);
|
||||
|
||||
|
||||
$images = array();
|
||||
while(!$result->EOF) {
|
||||
$image = Image::by_id($result->fields["image_id"]);
|
||||
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) {
|
||||
|
@ -278,7 +278,6 @@ class CommentList extends SimpleExtension {
|
|||
}
|
||||
}
|
||||
if(!is_null($image)) $images[] = array($image, $comments);
|
||||
$result->MoveNext();
|
||||
}
|
||||
|
||||
$this->theme->display_comment_list($images, $current_page, $total_pages, $this->can_comment());
|
||||
|
|
|
@ -310,7 +310,7 @@ class TagList implements Extension {
|
|||
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 :tag", array("tag"=>$tag));
|
||||
$tag_ids = $database->get_col("SELECT id FROM tags WHERE tag LIKE :tag", array("tag"=>$tag));
|
||||
// $search_tags = array_merge($search_tags,
|
||||
// $database->db->GetCol("SELECT tag FROM tags WHERE tag LIKE :tag", array("tag"=>$tag)));
|
||||
$tag_id_array = array_merge($tag_id_array, $tag_ids);
|
||||
|
@ -339,7 +339,6 @@ class TagList implements Extension {
|
|||
$args = array("limit"=>$config->get_int('tag_list_length'));
|
||||
|
||||
$related_tags = $database->get_all($query, $args);
|
||||
print $database->db->ErrorMsg();
|
||||
if(count($related_tags) > 0) {
|
||||
$this->theme->display_refine_block($page, $related_tags, $wild_tags);
|
||||
}
|
||||
|
|
Reference in a new issue