only check event type once
This commit is contained in:
parent
cd86859f08
commit
bc49df35c1
@ -35,21 +35,44 @@ class NumericScore implements Extension {
|
|||||||
if($event instanceof DisplayingImageEvent) {
|
if($event instanceof DisplayingImageEvent) {
|
||||||
if(!$user->is_anonymous()) {
|
if(!$user->is_anonymous()) {
|
||||||
$html = $this->theme->get_voter_html($event->image);
|
$html = $this->theme->get_voter_html($event->image);
|
||||||
|
if($user->is_admin()) {
|
||||||
|
$html .= "<p><a href='/numeric_score_votes/{$event->image->id}'>See All Votes</a>";
|
||||||
|
}
|
||||||
$page->add_block(new Block("Image Score", $html, "left", 20));
|
$page->add_block(new Block("Image Score", $html, "left", 20));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(($event instanceof PageRequestEvent) && $event->page_matches("numeric_score_vote") && $user->check_auth_token()) {
|
if($event instanceof PageRequestEvent) {
|
||||||
if(!$user->is_anonymous()) {
|
if($event->page_matches("numeric_score_votes")) {
|
||||||
$image_id = int_escape($_POST['image_id']);
|
$image_id = int_escape($event->get_arg(0));
|
||||||
$char = $_POST['vote'];
|
$x = $database->get_all(
|
||||||
$score = null;
|
"SELECT users.name as username, user_id, score
|
||||||
if($char == "up") $score = 1;
|
FROM numeric_score_votes
|
||||||
else if($char == "null") $score = 0;
|
JOIN users ON numeric_score_votes.user_id=users.id
|
||||||
else if($char == "down") $score = -1;
|
WHERE image_id=?",
|
||||||
if(!is_null($score) && $image_id>0) send_event(new NumericScoreSetEvent($image_id, $user, $score));
|
array($image_id));
|
||||||
$page->set_mode("redirect");
|
$html = "<table>";
|
||||||
$page->set_redirect(make_link("post/view/$image_id"));
|
foreach($x as $vote) {
|
||||||
|
$html .= "<tr><td>";
|
||||||
|
$html .= "<a href='/user/{$vote['username']}'>{$vote['username']}</a>";
|
||||||
|
$html .= "</td><td>";
|
||||||
|
$html .= $vote['score'];
|
||||||
|
$html .= "</td></tr>";
|
||||||
|
}
|
||||||
|
die($html);
|
||||||
|
}
|
||||||
|
if($event->page_matches("numeric_score_vote") && $user->check_auth_token()) {
|
||||||
|
if(!$user->is_anonymous()) {
|
||||||
|
$image_id = int_escape($_POST['image_id']);
|
||||||
|
$char = $_POST['vote'];
|
||||||
|
$score = null;
|
||||||
|
if($char == "up") $score = 1;
|
||||||
|
else if($char == "null") $score = 0;
|
||||||
|
else if($char == "down") $score = -1;
|
||||||
|
if(!is_null($score) && $image_id>0) send_event(new NumericScoreSetEvent($image_id, $user, $score));
|
||||||
|
$page->set_mode("redirect");
|
||||||
|
$page->set_redirect(make_link("post/view/$image_id"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user