Set unrated and unknown as reserved ratings
This commit is contained in:
parent
0506adbf30
commit
1e60c8720c
@ -77,6 +77,11 @@ function add_rating(ImageRating $rating) {
|
|||||||
if($rating->code=="?"&&array_key_exists("?",$_shm_ratings)) {
|
if($rating->code=="?"&&array_key_exists("?",$_shm_ratings)) {
|
||||||
throw new Exception("? is a reserved rating code that cannot be overridden");
|
throw new Exception("? is a reserved rating code that cannot be overridden");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($rating->code!="?"&&in_array(strtolower($rating->search_term), Ratings::UNRATED_KEYWORDS)) {
|
||||||
|
throw new Exception("$rating->search_term is a reserved search term");
|
||||||
|
}
|
||||||
|
|
||||||
$_shm_ratings[$rating->code] = $rating;
|
$_shm_ratings[$rating->code] = $rating;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,6 +119,8 @@ class Ratings extends Extension
|
|||||||
{
|
{
|
||||||
protected $db_support = [DatabaseDriver::MYSQL, DatabaseDriver::PGSQL];
|
protected $db_support = [DatabaseDriver::MYSQL, DatabaseDriver::PGSQL];
|
||||||
|
|
||||||
|
public const UNRATED_KEYWORDS = ["unknown","unrated"];
|
||||||
|
|
||||||
private $search_regexp;
|
private $search_regexp;
|
||||||
|
|
||||||
|
|
||||||
@ -129,7 +136,7 @@ class Ratings extends Extension
|
|||||||
array_push($search_terms, $rating->search_term);
|
array_push($search_terms, $rating->search_term);
|
||||||
}
|
}
|
||||||
$this->search_regexp = "/^rating[=|:](?:(\*|[" . $codes . "]+)|(" .
|
$this->search_regexp = "/^rating[=|:](?:(\*|[" . $codes . "]+)|(" .
|
||||||
implode("|", $search_terms) . "|unknown))$/D";
|
implode("|", $search_terms) . "|".implode("|",self::UNRATED_KEYWORDS)."))$/D";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_priority(): int
|
public function get_priority(): int
|
||||||
@ -260,7 +267,7 @@ class Ratings extends Extension
|
|||||||
|
|
||||||
public function onSearchTermParse(SearchTermParseEvent $event)
|
public function onSearchTermParse(SearchTermParseEvent $event)
|
||||||
{
|
{
|
||||||
global $user, $_shm_ratings;
|
global $user;
|
||||||
|
|
||||||
$matches = [];
|
$matches = [];
|
||||||
if (is_null($event->term) && $this->no_rating_query($event->context)) {
|
if (is_null($event->term) && $this->no_rating_query($event->context)) {
|
||||||
@ -272,6 +279,10 @@ class Ratings extends Extension
|
|||||||
if (preg_match($this->search_regexp, strtolower($event->term), $matches)) {
|
if (preg_match($this->search_regexp, strtolower($event->term), $matches)) {
|
||||||
$ratings = $matches[1] ? $matches[1] : $matches[2][0];
|
$ratings = $matches[1] ? $matches[1] : $matches[2][0];
|
||||||
|
|
||||||
|
if(count($matches)>2&&in_array($matches[2], self::UNRATED_KEYWORDS)) {
|
||||||
|
$ratings = "?";
|
||||||
|
}
|
||||||
|
|
||||||
if ($ratings == '*') {
|
if ($ratings == '*') {
|
||||||
$ratings = Ratings::get_user_class_privs($user);
|
$ratings = Ratings::get_user_class_privs($user);
|
||||||
} else {
|
} else {
|
||||||
@ -291,6 +302,10 @@ class Ratings extends Extension
|
|||||||
if (preg_match($this->search_regexp, strtolower($event->term), $matches) && $event->parse) {
|
if (preg_match($this->search_regexp, strtolower($event->term), $matches) && $event->parse) {
|
||||||
$ratings = $matches[1] ? $matches[1] : $matches[2][0];
|
$ratings = $matches[1] ? $matches[1] : $matches[2][0];
|
||||||
|
|
||||||
|
if(count($matches)>2&&in_array($matches[2], self::UNRATED_KEYWORDS)) {
|
||||||
|
$ratings = "?";
|
||||||
|
}
|
||||||
|
|
||||||
$ratings = array_intersect(str_split($ratings), Ratings::get_user_class_privs($user));
|
$ratings = array_intersect(str_split($ratings), Ratings::get_user_class_privs($user));
|
||||||
|
|
||||||
$rating = $ratings[0];
|
$rating = $ratings[0];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user