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) {
|
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) {
|
if($event instanceof ParseLinkTemplateEvent) {
|
||||||
@ -79,8 +79,8 @@ class NumericScore implements Extension {
|
|||||||
"Can't find the user named ".html_escape($matches[1]));
|
"Can't find the user named ".html_escape($matches[1]));
|
||||||
}
|
}
|
||||||
$event->add_querylet(new Querylet(
|
$event->add_querylet(new Querylet(
|
||||||
"images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=? AND score=1)",
|
"images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=:userid AND score=1)",
|
||||||
array($duser->id)));
|
array("userid" => $duser->id)));
|
||||||
}
|
}
|
||||||
if(preg_match("/^downvoted_by=(.*)$/", $event->term, $matches)) {
|
if(preg_match("/^downvoted_by=(.*)$/", $event->term, $matches)) {
|
||||||
$duser = User::by_name($matches[1]);
|
$duser = User::by_name($matches[1]);
|
||||||
@ -89,20 +89,20 @@ class NumericScore implements Extension {
|
|||||||
"Can't find the user named ".html_escape($matches[1]));
|
"Can't find the user named ".html_escape($matches[1]));
|
||||||
}
|
}
|
||||||
$event->add_querylet(new Querylet(
|
$event->add_querylet(new Querylet(
|
||||||
"images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=? AND score=-1)",
|
"images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=:userid AND score=-1)",
|
||||||
array($duser->id)));
|
array("userid" => $duser->id)));
|
||||||
}
|
}
|
||||||
if(preg_match("/^upvoted_by_id=(\d+)$/", $event->term, $matches)) {
|
if(preg_match("/^upvoted_by_id=(\d+)$/", $event->term, $matches)) {
|
||||||
$iid = int_escape($matches[1]);
|
$iid = int_escape($matches[1]);
|
||||||
$event->add_querylet(new Querylet(
|
$event->add_querylet(new Querylet(
|
||||||
"images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=? AND score=1)",
|
"images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=:userid AND score=1)",
|
||||||
array($iid)));
|
array("userid" => $iid)));
|
||||||
}
|
}
|
||||||
if(preg_match("/^downvoted_by_id=(\d+)$/", $event->term, $matches)) {
|
if(preg_match("/^downvoted_by_id=(\d+)$/", $event->term, $matches)) {
|
||||||
$iid = int_escape($matches[1]);
|
$iid = int_escape($matches[1]);
|
||||||
$event->add_querylet(new Querylet(
|
$event->add_querylet(new Querylet(
|
||||||
"images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=? AND score=-1)",
|
"images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=:userid AND score=-1)",
|
||||||
array($iid)));
|
array("userid" => $iid)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,8 +112,8 @@ class NumericScore implements Extension {
|
|||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
if($config->get_int("ext_numeric_score_version") < 1) {
|
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("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("CREATE INDEX images__numeric_score ON images(numeric_score)");
|
||||||
$database->create_table("numeric_score_votes", "
|
$database->create_table("numeric_score_votes", "
|
||||||
image_id INTEGER NOT NULL,
|
image_id INTEGER NOT NULL,
|
||||||
user_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);
|
$config->set_int("ext_numeric_score_version", 1);
|
||||||
}
|
}
|
||||||
if($config->get_int("ext_numeric_score_version") < 2) {
|
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);
|
$config->set_int("ext_numeric_score_version", 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function add_vote($image_id, $user_id, $score) {
|
private function add_vote($image_id, $user_id, $score) {
|
||||||
global $database;
|
global $database;
|
||||||
$database->Execute(
|
$database->execute(
|
||||||
"DELETE FROM numeric_score_votes WHERE image_id=? AND user_id=?",
|
"DELETE FROM numeric_score_votes WHERE image_id=:imageid AND user_id=:userid",
|
||||||
array($image_id, $user_id));
|
array("imageid" => $image_id, "userid" => $user_id));
|
||||||
if($score != 0) {
|
if($score != 0) {
|
||||||
$database->Execute(
|
$database->execute(
|
||||||
"INSERT INTO numeric_score_votes(image_id, user_id, score) VALUES(?, ?, ?)",
|
"INSERT INTO numeric_score_votes(image_id, user_id, score) VALUES(:imageid, :userid, :score)",
|
||||||
array($image_id, $user_id, $score));
|
array("imageid" => $image_id, "userid" => $user_id, "score" => $score));
|
||||||
}
|
}
|
||||||
$database->Execute(
|
$database->Execute(
|
||||||
"UPDATE images SET numeric_score=(SELECT SUM(score) FROM numeric_score_votes WHERE image_id=?) WHERE id=?",
|
"UPDATE images SET numeric_score=(SELECT SUM(score) FROM numeric_score_votes WHERE image_id=:imageid) WHERE id=:id",
|
||||||
array($image_id, $image_id));
|
array("imageid" => $image_id, "id" => $image_id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
add_event_listener(new NumericScore());
|
add_event_listener(new NumericScore());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user