numeric_score: PDO compatibility
This commit is contained in:
parent
57972632e4
commit
0661f95fbb
40
contrib/numeric_score/main.php
Normal file → Executable file
40
contrib/numeric_score/main.php
Normal file → Executable file
@ -58,7 +58,7 @@ class NumericScore implements Extension {
|
||||
}
|
||||
|
||||
if($event instanceof ImageDeletionEvent) {
|
||||
$database->execute("DELETE FROM numeric_score_votes WHERE image_id=?", array($event->image->id));
|
||||
$database->execute("DELETE FROM numeric_score_votes WHERE image_id=:id", array("id" => $event->image->id));
|
||||
}
|
||||
|
||||
if($event instanceof ParseLinkTemplateEvent) {
|
||||
@ -79,8 +79,8 @@ class NumericScore implements Extension {
|
||||
"Can't find the user named ".html_escape($matches[1]));
|
||||
}
|
||||
$event->add_querylet(new Querylet(
|
||||
"images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=? AND score=1)",
|
||||
array($duser->id)));
|
||||
"images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=:userid AND score=1)",
|
||||
array("userid" => $duser->id)));
|
||||
}
|
||||
if(preg_match("/^downvoted_by=(.*)$/", $event->term, $matches)) {
|
||||
$duser = User::by_name($matches[1]);
|
||||
@ -89,20 +89,20 @@ class NumericScore implements Extension {
|
||||
"Can't find the user named ".html_escape($matches[1]));
|
||||
}
|
||||
$event->add_querylet(new Querylet(
|
||||
"images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=? AND score=-1)",
|
||||
array($duser->id)));
|
||||
"images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=:userid AND score=-1)",
|
||||
array("userid" => $duser->id)));
|
||||
}
|
||||
if(preg_match("/^upvoted_by_id=(\d+)$/", $event->term, $matches)) {
|
||||
$iid = int_escape($matches[1]);
|
||||
$event->add_querylet(new Querylet(
|
||||
"images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=? AND score=1)",
|
||||
array($iid)));
|
||||
"images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=:userid AND score=1)",
|
||||
array("userid" => $iid)));
|
||||
}
|
||||
if(preg_match("/^downvoted_by_id=(\d+)$/", $event->term, $matches)) {
|
||||
$iid = int_escape($matches[1]);
|
||||
$event->add_querylet(new Querylet(
|
||||
"images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=? AND score=-1)",
|
||||
array($iid)));
|
||||
"images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=:userid AND score=-1)",
|
||||
array("userid" => $iid)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -112,8 +112,8 @@ class NumericScore implements Extension {
|
||||
global $config;
|
||||
|
||||
if($config->get_int("ext_numeric_score_version") < 1) {
|
||||
$database->Execute("ALTER TABLE images ADD COLUMN numeric_score INTEGER NOT NULL DEFAULT 0");
|
||||
$database->Execute("CREATE INDEX images__numeric_score ON images(numeric_score)");
|
||||
$database->execute("ALTER TABLE images ADD COLUMN numeric_score INTEGER NOT NULL DEFAULT 0");
|
||||
$database->execute("CREATE INDEX images__numeric_score ON images(numeric_score)");
|
||||
$database->create_table("numeric_score_votes", "
|
||||
image_id INTEGER NOT NULL,
|
||||
user_id INTEGER NOT NULL,
|
||||
@ -126,24 +126,24 @@ class NumericScore implements Extension {
|
||||
$config->set_int("ext_numeric_score_version", 1);
|
||||
}
|
||||
if($config->get_int("ext_numeric_score_version") < 2) {
|
||||
$database->Execute("CREATE INDEX numeric_score_votes__user_votes ON numeric_score_votes(user_id, score)");
|
||||
$database->execute("CREATE INDEX numeric_score_votes__user_votes ON numeric_score_votes(user_id, score)");
|
||||
$config->set_int("ext_numeric_score_version", 2);
|
||||
}
|
||||
}
|
||||
|
||||
private function add_vote($image_id, $user_id, $score) {
|
||||
global $database;
|
||||
$database->Execute(
|
||||
"DELETE FROM numeric_score_votes WHERE image_id=? AND user_id=?",
|
||||
array($image_id, $user_id));
|
||||
$database->execute(
|
||||
"DELETE FROM numeric_score_votes WHERE image_id=:imageid AND user_id=:userid",
|
||||
array("imageid" => $image_id, "userid" => $user_id));
|
||||
if($score != 0) {
|
||||
$database->Execute(
|
||||
"INSERT INTO numeric_score_votes(image_id, user_id, score) VALUES(?, ?, ?)",
|
||||
array($image_id, $user_id, $score));
|
||||
$database->execute(
|
||||
"INSERT INTO numeric_score_votes(image_id, user_id, score) VALUES(:imageid, :userid, :score)",
|
||||
array("imageid" => $image_id, "userid" => $user_id, "score" => $score));
|
||||
}
|
||||
$database->Execute(
|
||||
"UPDATE images SET numeric_score=(SELECT SUM(score) FROM numeric_score_votes WHERE image_id=?) WHERE id=?",
|
||||
array($image_id, $image_id));
|
||||
"UPDATE images SET numeric_score=(SELECT SUM(score) FROM numeric_score_votes WHERE image_id=:imageid) WHERE id=:id",
|
||||
array("imageid" => $image_id, "id" => $image_id));
|
||||
}
|
||||
}
|
||||
add_event_listener(new NumericScore());
|
||||
|
Loading…
x
Reference in New Issue
Block a user