From dba8e76830bb285f970ad9ac5128313588aa14f7 Mon Sep 17 00:00:00 2001 From: shish Date: Fri, 17 Oct 2008 20:18:38 +0000 Subject: [PATCH] working ratings git-svn-id: file:///home/shish/svn/shimmie2/trunk@1079 7f39781d-f577-437e-ae19-be835c7a54ca --- contrib/rating/main.php | 26 +++++++++++++++++++++++++- core/event.class.php | 12 ++++++------ core/image.class.php | 8 ++++++-- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/contrib/rating/main.php b/contrib/rating/main.php index 9324b6ee..a5b1e161 100644 --- a/contrib/rating/main.php +++ b/contrib/rating/main.php @@ -69,6 +69,21 @@ class Ratings implements Extension { if($event instanceof SearchTermParseEvent) { $matches = array(); + if(is_null($event->term) && $this->no_rating_query($event->context)) { + global $user, $config; + if($user->is_anonymous()) { + $sqes = $config->get_string("ext_rating_anon_privs"); + } + else { + $sqes = $config->get_string("ext_rating_user_privs"); + } + $arr = array(); + for($i=0; $iadd_querylet(new Querylet("rating IN ($set)")); + } if(preg_match("/rating=([sqe]+)/", $event->term, $matches)) { $sqes = $matches[1]; $arr = array(); @@ -76,11 +91,20 @@ class Ratings implements Extension { $arr[] = "'" . $sqes[$i] . "'"; } $set = join(', ', $arr); - $event->set_querylet(new Querylet("rating IN ($set)")); + $event->add_querylet(new Querylet("rating IN ($set)")); } } } + private function no_rating_query($context) { + foreach($context as $term) { + if(preg_match("/rating=([sqe]+)/", $term)) { + return false; + } + } + return true; + } + private function install() { global $database; global $config; diff --git a/core/event.class.php b/core/event.class.php index d6c1f274..abc0f189 100644 --- a/core/event.class.php +++ b/core/event.class.php @@ -269,7 +269,7 @@ class ThumbnailGenerationEvent extends Event { class SearchTermParseEvent extends Event { var $term = null; var $context = null; - var $querylet = null; + var $querylets = array(); public function SearchTermParseEvent($term, $context) { $this->term = $term; @@ -277,15 +277,15 @@ class SearchTermParseEvent extends Event { } public function is_querylet_set() { - return !is_null($this->querylet); + return (count($this->querylets) > 0); } - public function get_querylet() { - return $this->querylet; + public function get_querylets() { + return $this->querylets; } - public function set_querylet($q) { - $this->querylet = $q; + public function add_querylet($q) { + $this->querylets[] = $q; } } ?> diff --git a/core/image.class.php b/core/image.class.php index 93150876..4706f4ff 100644 --- a/core/image.class.php +++ b/core/image.class.php @@ -231,7 +231,9 @@ class Image { $stpe = new SearchTermParseEvent(null, $terms); send_event($stpe); if($stpe->is_querylet_set()) { - $img_querylets[] = new ImgQuerylet($stpe->get_querylet(), $positive); + foreach($stpe->get_querylets() as $querylet) { + $img_querylets[] = new ImgQuerylet($querylet, true); + } } // parse the words that are searched for into @@ -248,7 +250,9 @@ class Image { $stpe = new SearchTermParseEvent($term, $terms); send_event($stpe); if($stpe->is_querylet_set()) { - $img_querylets[] = new ImgQuerylet($stpe->get_querylet(), $positive); + foreach($stpe->get_querylets() as $querylet) { + $img_querylets[] = new ImgQuerylet($querylet, $positive); + } } else { $term = str_replace("*", "%", $term);