From 8f73b35fbb7b99cc407ab3cde04dbc3d4e4efbf8 Mon Sep 17 00:00:00 2001 From: Matthew Barbour Date: Tue, 11 Jun 2019 09:59:06 -0500 Subject: [PATCH] Added OnTagTermParse to rating extension Updated an install step to be pgsql compatible --- ext/rating/main.php | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/ext/rating/main.php b/ext/rating/main.php index 42663322..d99fa8d8 100644 --- a/ext/rating/main.php +++ b/ext/rating/main.php @@ -143,6 +143,28 @@ class Ratings extends Extension } } + public function onTagTermParse(TagTermParseEvent $event) + { + $matches = []; + + if (preg_match("/^rating[=|:](?:([sqeu]+)|(safe|questionable|explicit|unknown))$/D", strtolower($event->term), $matches) && $event->parse) { + $ratings = $matches[1] ? $matches[1] : $matches[2][0]; + $ratings = array_intersect(str_split($ratings), str_split(Ratings::get_user_privs($user))); + + $rating = $ratings[0]; + + $image = Image::by_id($event->id); + + $re = new RatingSetEvent($image, $rating); + + send_event($re); + } + + if (!empty($matches)) { + $event->metatag = true; + } + } + public function onBulkActionBlockBuilding(BulkActionBlockBuildingEvent $event) { global $user; @@ -301,8 +323,17 @@ class Ratings extends Extension } if ($config->get_int("ext_ratings2_version") < 3) { - $database->Execute("ALTER TABLE images CHANGE rating rating CHAR(1) NOT NULL DEFAULT 'u'"); - $config->set_int("ext_ratings2_version", 3); + $database->Execute("UPDATE images SET rating = 'u' WHERE rating is null"); + switch($database->get_driver_name()) { + case "mysql": + $database->Execute("ALTER TABLE images CHANGE rating rating CHAR(1) NOT NULL DEFAULT 'u'"); + break; + case "pgsql": + $database->Execute("ALTER TABLE images ALTER COLUMN rating SET DEFAULT 'u'"); + $database->Execute("ALTER TABLE images ALTER COLUMN rating SET NOT NULL"); + break; + } + $config->set_int("ext_ratings2_version", 3); } }