more misc work
git-svn-id: file:///home/shish/svn/shimmie2/trunk@514 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
parent
c30fee9f0b
commit
5b6ca92d4f
2 changed files with 21 additions and 11 deletions
|
@ -15,11 +15,12 @@ class Ratings extends Extension {
|
|||
|
||||
if(is_a($event, 'InitExtEvent')) {
|
||||
global $config;
|
||||
if($config->get_int("ext_ratings_version") < 1) {
|
||||
if($config->get_int("ext_ratings_version") < 2) {
|
||||
$this->install();
|
||||
}
|
||||
}
|
||||
|
||||
# TODO: ImageEditorBuildingEvent
|
||||
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'])) {
|
||||
|
@ -31,7 +32,7 @@ class Ratings extends Extension {
|
|||
if(is_a($event, 'DisplayingImageEvent')) {
|
||||
global $user;
|
||||
if($user->is_admin()) {
|
||||
$this->theme->display_rater($event->page, $event->image->id);
|
||||
$this->theme->display_rater($event->page, $event->image->id, $event->image->rating);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,10 +40,16 @@ class Ratings extends Extension {
|
|||
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);
|
||||
|
||||
if($config->get_int("ext_ratings_version") < 1) {
|
||||
$database->Execute("ALTER TABLE images ADD COLUMN rating ENUM('s', 'q', 'e') NOT NULL DEFAULT 'q'");
|
||||
$config->set_int("ext_ratings_version", 1);
|
||||
}
|
||||
|
||||
if($config->get_int("ext_ratings_version") < 2) {
|
||||
$database->Execute("CREATE INDEX images__rating ON images(rating)");
|
||||
$config->set_int("ext_ratings_version", 2);
|
||||
}
|
||||
}
|
||||
|
||||
private function set_rating($image_id, $rating) {
|
||||
|
|
|
@ -1,18 +1,21 @@
|
|||
<?php
|
||||
|
||||
class RatingsTheme extends Themelet {
|
||||
public function display_rater($page, $image_id) {
|
||||
public function display_rater($page, $image_id, $rating) {
|
||||
$i_image_id = int_escape($image_id);
|
||||
$s_checked = $rating == 's' ? " checked" : "";
|
||||
$q_checked = $rating == 'q' ? " checked" : "";
|
||||
$e_checked = $rating == 'e' ? " checked" : "";
|
||||
$html = "
|
||||
<form action='".make_link("rating/set")."' method='POST'>
|
||||
<input type='hidden' name='image_id' value='$i_image_id' />
|
||||
<input type='radio' name='rating' value='s' id='s'><label for='s'>Safe</label>
|
||||
<input type='radio' name='rating' value='q' id='q'><label for='q'>Questionable</label>
|
||||
<input type='radio' name='rating' value='e' id='e'><label for='e'>Explicit</label>
|
||||
<input type='radio' name='rating' value='s' id='s'$s_checked><label for='s'>Safe</label>
|
||||
<input type='radio' name='rating' value='q' id='q'$q_checked><label for='q'>Questionable</label>
|
||||
<input type='radio' name='rating' value='e' id='e'$e_checked><label for='e'>Explicit</label>
|
||||
<input type='submit' value='Set' />
|
||||
</form>
|
||||
";
|
||||
$page->add_block(new Block(null, $html, "main", 45));
|
||||
$page->add_block(new Block(null, $html, "main", 7));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue