working ratings

git-svn-id: file:///home/shish/svn/shimmie2/trunk@1079 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
shish 2008-10-17 20:18:38 +00:00
parent 13fb0356c2
commit dba8e76830
3 changed files with 37 additions and 9 deletions

View File

@ -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; $i<strlen($sqes); $i++) {
$arr[] = "'" . $sqes[$i] . "'";
}
$set = join(', ', $arr);
$event->add_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;

View File

@ -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;
}
}
?>

View File

@ -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);