Added OnTagTermParse to rating extension
Updated an install step to be pgsql compatible
This commit is contained in:
parent
8f3c20134f
commit
8f73b35fbb
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user