From 43384fc6c3d3cb33dee96d452c5de548087d72c2 Mon Sep 17 00:00:00 2001 From: Giraffaman Date: Sat, 13 Apr 2024 02:09:35 +0200 Subject: [PATCH] add settings to disable post-specific tags and ratings (to prevent overriding tag-based ratings --- ext/rating/main.php | 14 ++++++++++++-- ext/upload/config.php | 2 ++ ext/upload/main.php | 6 ++++++ ext/upload/theme.php | 9 ++++++--- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/ext/rating/main.php b/ext/rating/main.php index ac3741346..b2d522365 100644 --- a/ext/rating/main.php +++ b/ext/rating/main.php @@ -226,9 +226,12 @@ public function onRatingSet(RatingSetEvent $event): void { if (empty($event->image['rating'])) { $old_rating = ""; + error_log("ratings: no old rating."); } else { $old_rating = $event->image['rating']; + error_log("ratings: old rating is ".$old_rating); } + error_log("ratings: calling set_rating for image ".$event->image->id.", new rating ".$event->rating.", old rating ".$old_rating); $this->set_rating($event->image->id, $event->rating, $old_rating); } @@ -323,6 +326,7 @@ public function onTagTermCheck(TagTermCheckEvent $event): void { if (preg_match($this->search_regexp, $event->term)) { $event->metatag = true; + error_log("ratings: ".$event->term." is a ratings tag!"); } } @@ -336,12 +340,14 @@ public function onTagTermParse(TagTermParseEvent $event): void if (count($matches) > 2 && in_array($matches[2], self::UNRATED_KEYWORDS)) { $ratings = "?"; + error_log("ratings: don't know what rating ".$event->term." is."); } $ratings = array_intersect(str_split($ratings), Ratings::get_user_class_privs($user)); $rating = $ratings[0]; $image = Image::by_id_ex($event->image_id); send_event(new RatingSetEvent($image, $rating)); + error_log("ratings: ".$event->term." is rating ".$rating); } } @@ -524,7 +530,10 @@ public function onUploadHeaderBuilding(UploadHeaderBuildingEvent $event): void public function onUploadSpecificBuilding(UploadSpecificBuildingEvent $event): void { - $event->add_part($this->theme->get_upload_specific_rater_html($event->suffix)); + global $config; + if($config->get_bool(UploadConfig::ALLOW_SPECIFIC_RATINGS)) { + $event->add_part($this->theme->get_upload_specific_rater_html($event->suffix)); + } } /** @@ -692,7 +701,8 @@ private function set_rating(int $image_id, string $rating, string $old_rating): global $database; if ($old_rating != $rating) { $database->execute("UPDATE images SET rating=:rating WHERE id=:id", ['rating' => $rating, 'id' => $image_id]); - log_info("rating", "Rating for >>{$image_id} set to: ".$this->rating_to_human($rating)); + #log_info("rating", "Rating for >>{$image_id} set to: ".$this->rating_to_human($rating)); + error_log("Rating for >>{$image_id} set to: ".$this->rating_to_human($rating)); } } } diff --git a/ext/upload/config.php b/ext/upload/config.php index 94cd6a601..d2f41dbe1 100644 --- a/ext/upload/config.php +++ b/ext/upload/config.php @@ -8,6 +8,8 @@ class UploadConfig { public const COUNT = "upload_count"; public const FORM_COUNT = "form_count"; + public const ALLOW_SPECIFIC_TAGS = "allow_specific_tags"; + public const ALLOW_SPECIFIC_RATINGS = "allow_specific_ratings"; public const SIZE = "upload_size"; public const MIN_FREE_SPACE = "upload_min_free_space"; public const TLSOURCE = "upload_tlsource"; diff --git a/ext/upload/main.php b/ext/upload/main.php index 8e0ef6c88..5dcdf2059 100644 --- a/ext/upload/main.php +++ b/ext/upload/main.php @@ -113,6 +113,10 @@ public function onInitExt(InitExtEvent $event): void global $config; $config->set_default_int(UploadConfig::COUNT, 3); $config->set_default_int(UploadConfig::FORM_COUNT, 5); + $config->set_default_bool(UploadConfig::ALLOW_SPECIFIC_TAGS, true); + # disabling post-specific ratings selector since we set ratings through tags and this would override it + # e.g. if tag "nsfw" (rating=e) present but this is left "unrated", image ends up with rating=? + $config->set_default_bool(UploadConfig::ALLOW_SPECIFIC_RATINGS, false); $config->set_default_int(UploadConfig::SIZE, parse_shorthand_int('1MB')); $config->set_default_int(UploadConfig::MIN_FREE_SPACE, parse_shorthand_int('100MB')); $config->set_default_bool(UploadConfig::TLSOURCE, true); @@ -158,6 +162,8 @@ public function onSetupBuilding(SetupBuildingEvent $event): void $sb->add_label("PHP Limit = " . ini_get('upload_max_filesize') . ""); $sb->add_choice_option(UploadConfig::TRANSLOAD_ENGINE, $tes, "
Transload: "); $sb->add_bool_option(UploadConfig::TLSOURCE, "
Use transloaded URL as source if none is provided: "); + $sb->add_bool_option(UploadConfig::ALLOW_SPECIFIC_TAGS, "
Support post-specific tags:"); + $sb->add_bool_option(UploadConfig::ALLOW_SPECIFIC_RATINGS, "
Support post-specific tags:"); $sb->start_table(); $sb->add_bool_option(UploadConfig::MIME_CHECK_ENABLED, "Enable upload MIME checks", true); diff --git a/ext/upload/theme.php b/ext/upload/theme.php index 08609ce29..4da61412b 100644 --- a/ext/upload/theme.php +++ b/ext/upload/theme.php @@ -127,9 +127,12 @@ protected function build_upload_list(): HTMLElement } for ($i = 0; $i < $form_count; $i++) { $specific_fields = emptyHTML(); - $usfbe = send_event(new UploadSpecificBuildingEvent((string)$i)); - foreach ($usfbe->get_parts() as $part) { - $specific_fields->appendChild($part); + if($config->get_bool(UploadConfig::ALLOW_SPECIFIC_TAGS)) { + $usfbe = send_event(new UploadSpecificBuildingEvent((string)$i)); + + foreach ($usfbe->get_parts() as $part) { + $specific_fields->appendChild($part); + } } $upload_list->appendChild(