This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/contrib/rating/main.php
shish 0466bdd66d most of the rating-setting code done
git-svn-id: file:///home/shish/svn/shimmie2/trunk@510 7f39781d-f577-437e-ae19-be835c7a54ca
2007-10-02 21:59:20 +00:00

54 lines
1.5 KiB
PHP

<?php
/**
* Name: Image Ratings
* Author: Shish <webmaster@shishnet.org>
* Link: http://trac.shishnet.org/shimmie2/
* License: GPLv2
* Description: Allow users to rate images
*/
class Ratings extends Extension {
var $theme;
public function receive_event($event) {
if(is_null($this->theme)) $this->theme = get_theme_object("rating", "RatingsTheme");
if(is_a($event, 'InitExtEvent')) {
global $config;
if($config->get_int("ext_ratings_version") < 1) {
$this->install();
}
}
if(is_a($event, 'PageRequestEvent') && $event->page_name == "rating" &&
$event->get_arg(0) == "set" && $event->user->is_admin() &&
isset($_POST['rating']) && isset($_POST['image_id'])) {
$this->set_rating($_POST['image_id'], $_POST['rating']);
$event->page->set_mode("redirect");
$event->page->set_redirect(make_link("post/view/".int_escape($_POST['image_id'])));
}
if(is_a($event, 'DisplayingImageEvent')) {
global $user;
if($user->is_admin()) {
$this->theme->display_rater($event->page, $event->image->id);
}
}
}
private function install() {
global $database;
global $config;
$database->Execute("ALTER TABLE images
ADD COLUMN rating ENUM('s', 'q', 'e') NOT NULL DEFAULT 'q'
)");
$config->set_int("ext_ratings_version", 1);
}
private function set_rating($image_id, $rating) {
global $database;
$database->Execute("UPDATE images SET rating=? WHERE id=?", array($rating, $image_id));
}
}
add_event_listener(new Ratings());
?>