From 6754e8b855c66c9ff4c67bb1b61bc76b86534567 Mon Sep 17 00:00:00 2001 From: Rodolfo Berrios <20590102+rodber@users.noreply.github.com> Date: Tue, 19 Oct 2021 11:16:55 -0300 Subject: [PATCH] close #114 --- app/lib/classes/class.image.php | 27 - app/lib/classes/class.moderatecontent.php | 135 - app/lib/classes/class.upload.php | 10 - app/routes/route.dashboard.php | 16 - app/routes/route.moderate.php | 68 - app/themes/Peafowl/header.php | 8 - .../Peafowl/snippets/anywhere_upload.php | 8 +- app/themes/Peafowl/snippets/footer.js.php | 2 +- .../Peafowl/snippets/listing_tools_editor.php | 5 +- app/themes/Peafowl/style.css | 2212 +++++++++-------- app/themes/Peafowl/style.min.css | 2 +- .../tpl_list_item/item_image_admin_tools.php | 8 - app/themes/Peafowl/views/dashboard.php | 54 - app/web.php | 11 - 14 files changed, 1111 insertions(+), 1455 deletions(-) delete mode 100644 app/lib/classes/class.moderatecontent.php delete mode 100644 app/routes/route.moderate.php diff --git a/app/lib/classes/class.image.php b/app/lib/classes/class.image.php index 798b286..e4af4c9 100644 --- a/app/lib/classes/class.image.php +++ b/app/lib/classes/class.image.php @@ -585,9 +585,6 @@ class Image 'uploaded' => $upload->uploaded, 'source' => $upload->source, ]; - if (isset($upload->moderation)) { - $return['moderation'] = $upload->moderation; - } return $return; } catch (Exception $e) { @@ -1027,18 +1024,6 @@ class Image $original_exifdata = $image_upload['source']['image_exif'] ? json_encode(G\array_utf8encode($image_upload['source']['image_exif'])) : null; $values['nsfw'] = in_array(strval($values['nsfw']), ['0', '1']) ? $values['nsfw'] : 0; - if (Settings::get('moderatecontent') && $values['nsfw'] == 0 && Settings::get('moderatecontent_flag_nsfw')) { - switch ($image_upload['moderation']->rating_letter) { - case 'a': - $values['nsfw'] = '1'; - break; - case 't': - if (Settings::get('moderatecontent_flag_nsfw') == 't') { - $values['nsfw'] = 1; - } - break; - } - } $populate_values = [ 'uploader_ip' => $values['uploader_ip'], @@ -1070,18 +1055,6 @@ class Image } $values['is_approved'] = 1; - switch (Settings::get('moderate_uploads')) { - case 'all': - $values['is_approved'] = 0; - break; - case 'guest': - $values['is_approved'] = (int) isset($values['user_id']); - break; - } - - if (Settings::get('moderatecontent_auto_approve') && isset($image_upload['moderation'])) { - $values['is_approved'] = 1; - } $insert = DB::insert('images', $values); diff --git a/app/lib/classes/class.moderatecontent.php b/app/lib/classes/class.moderatecontent.php deleted file mode 100644 index 8f73f50..0000000 --- a/app/lib/classes/class.moderatecontent.php +++ /dev/null @@ -1,135 +0,0 @@ - - - - Copyright (C) Rodolfo Berrios A. All rights reserved. - - BY USING THIS SOFTWARE YOU DECLARE TO ACCEPT THE CHEVERETO EULA - http://chevereto.com/license - - --------------------------------------------------------------------- */ - -namespace CHV; - -use G; - -class ModerateContent -{ - private $imageFilename; - private $imageInfo; - private $moderation; - private $error_message = ''; - private $error_code = 0; - private $imageOptimized; - - public function __construct($imageFilename, $info=[]) - { - $this->imageFilename = $imageFilename; - $this->imageInfo = $info; - if ($this->imageInfo === []) { - $this->imageInfo = G\get_image_fileinfo($this->imageFilename); - } - $this->optimizeImage(); - $url = "http://api.moderatecontent.com/moderate/?key=".Settings::get('moderatecontent_key'); - $this->error_message = ''; - $this->error_code = 0; - $curl = curl_init(); - curl_setopt_array($curl, array( - CURLOPT_URL => $url, - CURLOPT_FAILONERROR => true, - CURLOPT_RETURNTRANSFER => true, - CURLOPT_ENCODING => "", - CURLOPT_MAXREDIRS => 10, - CURLOPT_TIMEOUT => 10, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, - CURLOPT_CUSTOMREQUEST => 'POST', - CURLOPT_POSTFIELDS => array('file'=> new \CURLFile($this->imageOptimized)), - )); - $curl_response = curl_exec($curl); - if (curl_errno($curl)) { - $error_msg = curl_error($curl); - } - if ($curl_response === false) { - $this->error_message = $error_msg; - $this->error_code = 1402; - } else { - $json = json_decode($curl_response); - if ($json === null && json_last_error() !== JSON_ERROR_NONE) { - $this->error_message = 'Malformed content moderation response'; - $this->error_code = 1403; - } else { - $this->moderation = $json; - $this->assertIsAllowed(); - } - } - curl_close($curl); - } - - public function moderation() - { - return $this->moderation; - } - - public function isSuccess() - { - return $this->error_code === 0; - } - - public function isError() - { - return $this->error_code !== 0; - } - - public function errorCode() - { - return $this->error_code; - } - - public function errorMessage() - { - return $this->error_message; - } - - private function assertIsAllowed() - { - $block = []; - $blockRating = Settings::get('moderatecontent_block_rating'); - switch ($blockRating) { - case 'a': - $block[] = 'a'; - break; - case 't': - $block[] = 'a'; - $block[] = 't'; - break; - } - $ratings = [ - 'a' => _s('adult'), - 't' => _s('teen'), - ]; - foreach ($block as $rating) { - if ($this->moderation->rating_letter == $rating) { - throw new UploadException(_s('Content of type %s is forbidden', $ratings[$rating]), 1404); - } - } - } - - private function optimizeImage() - { - $this->imageOptimized = $this->imageFilename; - // if ($this->imageInfo['size'] > G\get_bytes('1 MB') && !G\is_animated_image($this->imageFilename)) { - // $this->imageOptimized = Upload::getTempNam(sys_get_temp_dir()); - // if (copy($this->imageFilename, $this->imageOptimized)) { - // $option = $this->imageInfo['ratio'] >= 1 ? 'width' : 'height'; - // Image::resize($this->imageOptimized, null, null, [$option => 300]); - // } - // } - } -} diff --git a/app/lib/classes/class.upload.php b/app/lib/classes/class.upload.php index 760ed65..47da89a 100644 --- a/app/lib/classes/class.upload.php +++ b/app/lib/classes/class.upload.php @@ -489,16 +489,6 @@ class Upload if ($this->source_image_fileinfo['extension'] == 'webp' && G\is_animated_webp($this->downstream)) { throw new UploadException('Animated WebP is not supported', 314); } - - if (Settings::get('moderatecontent') && (Settings::get('moderatecontent_block_rating') != '' || Settings::get('moderatecontent_flag_nsfw'))) { - $moderateContent = new ModerateContent($this->downstream, $this->source_image_fileinfo); - if ($moderateContent->isSuccess()) { - $this->moderation = $moderateContent->moderation(); - } else { - throw new UploadException('Error processing content moderation: ' . $moderateContent->errorMessage()); - error_log($moderateContent->errorMessage()); - } - } } // Handle flood uploads diff --git a/app/routes/route.dashboard.php b/app/routes/route.dashboard.php index cbc871d..5abb7e3 100644 --- a/app/routes/route.dashboard.php +++ b/app/routes/route.dashboard.php @@ -812,22 +812,6 @@ $route = function ($handler) { } } - if ($_POST['moderatecontent'] == 1) { - $moderateContentKey = CHV\getSetting('moderatecontent_key'); - if ($_POST['moderatecontent_key']) { - $moderateContentKey = $_POST['moderatecontent_key']; - } - $sample = 'http://www.moderatecontent.com/img/sample_face_2.jpg'; - $json = G\fetch_url('https://api.moderatecontent.com/moderate/?key='.$moderateContentKey.'&url=' . $sample); - $data = json_decode($json); - if (isset($data->error)) { - $validations['moderatecontent_key'] = [ - 'validate' => false, - 'error_msg' => $data->error - ]; - } - } - // Validate SMTP credentials if ($_POST['email_mode'] == 'smtp') { $email_smtp_validate = [ diff --git a/app/routes/route.moderate.php b/app/routes/route.moderate.php deleted file mode 100644 index f67e3e3..0000000 --- a/app/routes/route.moderate.php +++ /dev/null @@ -1,68 +0,0 @@ - - - - Copyright (C) Rodolfo Berrios A. All rights reserved. - - BY USING THIS SOFTWARE YOU DECLARE TO ACCEPT THE CHEVERETO EULA - http://chevereto.com/license - - --------------------------------------------------------------------- */ - -$route = function ($handler) { - try { - $logged_user = CHV\Login::getUser(); - - if (!$logged_user['is_content_manager']) { - return $handler->issue404(); - } - $listing = ['label' => _s('Moderate'), 'icon' => 'icon-download2']; - $listing['list'] = G\get_route_name(); - $listingParams = [ - 'listing' => $listing['list'], - 'basename' => G\get_route_name(), - 'params_hidden' => [ - 'approved' => 0, - 'hide_empty' => 0, - 'hide_banned' => 0, - 'album_min_image_count' => 0, - ], - 'exclude_criterias' => ['most-viewed', 'most-liked'] - ]; - $tabs = CHV\Listing::getTabs($listingParams, true); - $currentKey = $tabs['currentKey']; - $type = $tabs['tabs'][$currentKey]['type']; - $tabs = $tabs['tabs']; - parse_str($tabs[$currentKey]['params'], $tabs_params); - $list_params = CHV\Listing::getParams(); // Use CHV magic params - $list_params['sort'] = explode('_', $tabs_params['sort']); // Hack this stuff - $handler::setVar('list_params', $list_params); - // List - $list = new CHV\Listing; - $list->setApproved(0); - $list->setType($type); - $list->setReverse($list_params['reverse']); - $list->setSeek($list_params['seek']); - $list->setOffset($list_params['offset']); - $list->setLimit($list_params['limit']); // how many results? - $list->setItemsPerPage($list_params['items_per_page']); // must - $list->setSortType($list_params['sort'][0]); // date | size | views | likes - $list->setSortOrder($list_params['sort'][1]); // asc | desc - $list->setRequester(CHV\Login::getUser()); - $list->setParamsHidden($listingParams['params_hidden']); - $list->exec(); - $handler::setVar('listing', $listing); - $handler::setVar('pre_doctitle', _s('Moderate')); - $handler::setVar('category', null); - $handler::setVar('tabs', $tabs); - $handler::setVar('list', $list); - } catch (Exception $e) { - G\exception_to_error($e); - } -}; diff --git a/app/themes/Peafowl/header.php b/app/themes/Peafowl/header.php index 2e5c701..b01fb2c 100644 --- a/app/themes/Peafowl/header.php +++ b/app/themes/Peafowl/header.php @@ -120,14 +120,6 @@ if (is_maintenance() || is_show_consent_screen() || in_array($templateUsed, ['re - -
  • - -
  • - -
  • diff --git a/app/themes/Peafowl/snippets/anywhere_upload.php b/app/themes/Peafowl/snippets/anywhere_upload.php index afa4d4c..9f653c6 100644 --- a/app/themes/Peafowl/snippets/anywhere_upload.php +++ b/app/themes/Peafowl/snippets/anywhere_upload.php @@ -190,17 +190,11 @@ if (CHV\Login::isLoggedUser()) { ?>
    - -
    :
    -
    > - _s('Disabled'), - 'guest' => _s('Guest'), - 'all' => _s('All') - ], CHV\Settings::get('moderate_uploads')); ?> -
    -
    - -

    @@ -2677,45 +2662,6 @@ function free_version_warning($wrap=true)

    -
    - -
    -
    ModerateContent'); ?>
    -
    -
    -
    -
    - - -
    -
    -
    - -
    -
    -
    -
    - -
    -
    -
    - -
    -
    -
    -
    -
    diff --git a/app/web.php b/app/web.php index a6775a6..91ca24c 100644 --- a/app/web.php +++ b/app/web.php @@ -325,17 +325,6 @@ try { $handler::setCond('search_enabled', $handler::getCond('content_manager') ?: getSetting('website_search')); - $moderate_uploads = false; - switch (getSetting('moderate_uploads')) { - case 'all': - $moderate_uploads = true; - break; - case 'guest': - $moderate_uploads = !Login::isLoggedUser(); - break; - } - $handler::setCond('moderate_uploads', $moderate_uploads); - $categories = []; if ($handler::getCond('explore_enabled') || $base == 'dashboard') { try {