From afa1f4a5830eeb17184af95862cc980d2b90cf09 Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 13 Aug 2009 20:10:48 +0100 Subject: [PATCH] don't force the user to set a rating --- contrib/rating/main.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/contrib/rating/main.php b/contrib/rating/main.php index c34e32cb..114d6b79 100644 --- a/contrib/rating/main.php +++ b/contrib/rating/main.php @@ -10,6 +10,7 @@ class RatingSetEvent extends Event { var $image, $user, $rating; public function RatingSetEvent(Image $image, User $user, $rating) { + assert(in_array($rating, array("s", "q", "e", "u"))); $this->image = $image; $this->user = $user; $this->rating = $rating; @@ -58,7 +59,7 @@ class Ratings implements Extension { } $config->set_default_string("ext_rating_anon_privs", 'squ'); - $config->set_default_string("ext_rating_user_privs", 'squ'); + $config->set_default_string("ext_rating_user_privs", 'sqeu'); $config->set_default_string("ext_rating_admin_privs", 'sqeu'); } @@ -67,13 +68,13 @@ class Ratings implements Extension { } if($event instanceof ImageInfoBoxBuildingEvent) { - if($user->is_admin()) { + if($this->can_rate()) { $event->add_part($this->theme->get_rater_html($event->image->id, $event->image->rating), 80); } } if($event instanceof ImageInfoSetEvent) { - if($user->is_admin()) { + if($this->can_rate() && isset($_POST["rating"])) { send_event(new RatingSetEvent($event->image, $user, $_POST['rating'])); } } @@ -133,6 +134,15 @@ class Ratings implements Extension { } } + // FIXME: this is a bit ugly and guessey, should have proper options + private function can_rate() { + global $config, $user; + if($user->is_anonymous() && $config->get_string("ext_rating_anon_privs") == "sqeu") return false; + if($user->is_admin()) return true; + if(!$user->is_anonymous() && $config->get_string("ext_rating_user_privs") == "sqeu") return true; + return false; + } + private function no_rating_query($context) { foreach($context as $term) { if(preg_match("/^rating=/", $term)) {