close #114
parent
f6a1e69f72
commit
6754e8b855
|
@ -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);
|
||||
|
||||
|
|
|
@ -1,135 +0,0 @@
|
|||
<?php
|
||||
|
||||
/* --------------------------------------------------------------------
|
||||
|
||||
Chevereto
|
||||
http://chevereto.com/
|
||||
|
||||
@author Rodolfo Berrios A. <http://rodolfoberrios.com/>
|
||||
<inbox@rodolfoberrios.com>
|
||||
|
||||
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]);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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 = [
|
||||
|
|
|
@ -1,68 +0,0 @@
|
|||
<?php
|
||||
|
||||
/* --------------------------------------------------------------------
|
||||
|
||||
Chevereto
|
||||
http://chevereto.com/
|
||||
|
||||
@author Rodolfo Berrios A. <http://rodolfoberrios.com/>
|
||||
<inbox@rodolfoberrios.com>
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
|
@ -120,14 +120,6 @@ if (is_maintenance() || is_show_consent_screen() || in_array($templateUsed, ['re
|
|||
</li>
|
||||
<?php
|
||||
} ?>
|
||||
<?php if (is_content_manager()) { ?>
|
||||
<li id="top-bar-moderate" data-nav="moderate" class="top-btn-el<?php if (in_array(G\get_route_name(), ['moderate'])) {
|
||||
?> current<?php
|
||||
} ?>"">
|
||||
<a href="<?php echo G\get_base_url('moderate'); ?>"><span class="top-btn-text"><span class="icon icon-download2"></span><span class="btn-text phone-hide phablet-hide"><?php _se('Moderate'); ?></span></span></a>
|
||||
</li>
|
||||
<?php } ?>
|
||||
|
||||
<?php if (is_search_enabled()) {
|
||||
?>
|
||||
<li data-action="top-bar-search" data-nav="search" class="phone-hide pop-btn">
|
||||
|
|
|
@ -190,17 +190,11 @@ if (CHV\Login::isLoggedUser()) {
|
|||
?>
|
||||
<div data-group="upload-result" data-result="success" class="c16 center-box soft-hidden">
|
||||
<div class="input-label margin-bottom-0 copy-hover-display">
|
||||
<?php
|
||||
if (is_moderate_uploads()) {
|
||||
?>
|
||||
<div class="growl font-size-small static text-align-center margin-bottom-30 clear-both"><b><?php _se('Note'); ?>:</b> <?php _se('We must approve the uploaded content before being able to share.'); ?></div>
|
||||
<?php
|
||||
} ?>
|
||||
<label for="uploaded-embed-toggle"><?php _se('Embed codes'); ?></label>
|
||||
<div class="c7 margin-bottom-10">
|
||||
<select name="uploaded-embed-toggle" id="uploaded-embed-toggle" class="text-input" data-combo="uploaded-embed-toggle-combo">
|
||||
<?php
|
||||
$tpl = is_moderate_uploads() ? 'embed_unapproved_tpl' : 'embed_tpl';
|
||||
$tpl = 'embed_tpl';
|
||||
foreach (G\get_global($tpl) as $key => $value) {
|
||||
echo '<optgroup label="'.$value['label'].'">'."\n";
|
||||
foreach ($value['options'] as $k => $v) {
|
||||
|
|
|
@ -73,7 +73,7 @@ if (is_captcha_show() && CHV\getSetting('recaptcha_version') == 3) {
|
|||
redirect_single_upload: <?php echo json_encode(CHV\getSetting('enable_redirect_single_upload')); ?>,
|
||||
threads: <?php echo json_encode(CHV\getSetting('upload_threads')); ?>,
|
||||
image_types: <?php echo json_encode(CHV\Image::getEnabledImageFormats()); ?>,
|
||||
moderation: <?php echo json_encode(is_moderate_uploads()); ?>,
|
||||
moderation: 0,
|
||||
},
|
||||
user: {
|
||||
avatar_max_filesize: "<?php echo CHV\getSetting('user_image_avatar_max_filesize_mb') . ' MB'; ?>",
|
||||
|
|
|
@ -52,11 +52,8 @@ foreach ($tabs as $tab) {
|
|||
<li><a data-action="flag-safe" class="hidden"><?php _se('Flag as safe'); ?></a></li>
|
||||
<li><a data-action="flag-unsafe" class="hidden"><?php _se('Flag as unsafe'); ?></a></li>
|
||||
<?php
|
||||
}
|
||||
if (G\Handler::getRouteName() == 'moderate') { ?>
|
||||
<li><a data-action="approve"><?php _se('Approve'); ?></a></li>
|
||||
} ?>
|
||||
<?php
|
||||
}
|
||||
} // images?>
|
||||
<?php
|
||||
if (is_allowed_to_delete_content() && (array_key_exists('tools_available', $tab) ? in_array('delete', $tab['tools_available']) : true)) {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
|
@ -13,14 +13,6 @@
|
|||
</li>
|
||||
<?php
|
||||
}
|
||||
if (G\Handler::getRouteName() == 'moderate') {
|
||||
?>
|
||||
<li class="tool-approve" data-action="approve">
|
||||
<span class="btn-icon icon-checkmark" title="<?php _se('Approve'); ?>"></span>
|
||||
<span class="label label-approve"><?php _se('Approve'); ?></span>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<li class="tool-delete" data-action="delete">
|
||||
<span class="btn-icon icon-remove" title="<?php _se('Delete'); ?>"></span>
|
||||
|
|
|
@ -1178,21 +1178,6 @@ function free_version_warning($wrap=true)
|
|||
<div class="input-below"><?php _se('Enable this if you want to allow non registered users to upload.'); ?></div>
|
||||
<?php personal_mode_warning(); ?>
|
||||
</div>
|
||||
<div class="input-label">
|
||||
<label for="moderate_uploads"><?php _se('Moderate uploads'); ?></label>
|
||||
<div class="c5 phablet-c1"><select type="text" name="moderate_uploads" id="moderate_uploads" class="text-input" <?php if (CHV\getSetting('website_mode') == 'personal') {
|
||||
echo ' disabled';
|
||||
} ?>>
|
||||
<?php
|
||||
echo CHV\Render\get_select_options_html([
|
||||
'' => _s('Disabled'),
|
||||
'guest' => _s('Guest'),
|
||||
'all' => _s('All')
|
||||
], CHV\Settings::get('moderate_uploads')); ?>
|
||||
</select></div>
|
||||
<div class="input-below"><?php _se('Enable this to moderate incoming uploads. Target content will require moderation for approval.'); ?></div>
|
||||
<?php personal_mode_warning(); ?>
|
||||
</div>
|
||||
|
||||
<hr class="line-separator">
|
||||
|
||||
|
@ -2677,45 +2662,6 @@ function free_version_warning($wrap=true)
|
|||
</div>
|
||||
</div>
|
||||
<hr class="line-separator"></hr>
|
||||
<div class="input-label">
|
||||
<label for="moderatecontent">ModerateContent</label>
|
||||
<div class="c5 phablet-c1"><select type="text" name="moderatecontent" id="moderatecontent" class="text-input" data-combo="moderatecontent-combo">
|
||||
<?php
|
||||
echo CHV\Render\get_select_options_html([1 => _s('Enabled'), 0 => _s('Disabled')], get_safe_post() ? get_safe_post()['moderatecontent'] : CHV\Settings::get('moderatecontent')); ?>
|
||||
</select></div>
|
||||
<div class="input-below"><?php _se('Automatically moderate the content using the %s service.', '<a href="https://www.moderatecontent.com/" target="_blank">ModerateContent</a>'); ?></div>
|
||||
</div>
|
||||
<div id="moderatecontent-combo" class="c12 phablet-c1">
|
||||
<div data-combo-value="1" class="switch-combo<?php if ((get_safe_post() ? get_safe_post()['moderatecontent'] : CHV\Settings::get('moderatecontent')) == 0) {
|
||||
echo ' soft-hidden';
|
||||
} ?>">
|
||||
<div class="input-label">
|
||||
<label for="moderatecontent_key">ModerateContent API Key</label>
|
||||
<input type="text" name="moderatecontent_key" id="moderatecontent_key" class="text-input" value="<?php echo get_safe_post() ? get_safe_post()['moderatecontent_key'] : CHV\Settings::get('moderatecontent_key'); ?>" placeholder="">
|
||||
<div class="input-below input-warning red-warning"><?php echo get_input_errors()['moderatecontent_key']; ?></div>
|
||||
</div>
|
||||
<div class="input-label">
|
||||
<label for="moderatecontent_auto_approve"><?php _se('Automatic approve'); ?></label>
|
||||
<div class="c5 phablet-c1"><select type="text" name="moderatecontent_auto_approve" id="moderatecontent_auto_approve" class="text-input">
|
||||
<?php echo CHV\Render\get_select_options_html([0 => _s('Disabled'), 1 => _s('Enabled')], get_safe_post() ? get_safe_post()['moderatecontent_auto_approve'] : CHV\Settings::get('moderatecontent_auto_approve')); ?>
|
||||
</select></div>
|
||||
<div class="input-below"><?php _se('Enable this to automatically approve content moderated by this service.'); ?></div>
|
||||
</div>
|
||||
<div class="input-label">
|
||||
<label for="moderatecontent_block_rating"><?php _se('Block content'); ?></label>
|
||||
<div class="c5 phablet-c1"><select type="text" name="moderatecontent_block_rating" id="moderatecontent_block_rating" class="text-input">
|
||||
<?php echo CHV\Render\get_select_options_html(['' => _s('Disabled'), 'a' => _s('Adult'), 't' => _s('Teen and adult')], get_safe_post() ? get_safe_post()['moderatecontent_block_rating'] : CHV\Settings::get('moderatecontent_block_rating')); ?>
|
||||
</select></div>
|
||||
</div>
|
||||
<div class="input-label">
|
||||
<label for="moderatecontent_flag_nsfw"><?php _se('Flag NSFW'); ?></label>
|
||||
<div class="c5 phablet-c1"><select type="text" name="moderatecontent_flag_nsfw" id="moderatecontent_flag_nsfw" class="text-input">
|
||||
<?php echo CHV\Render\get_select_options_html([0 => _s('Disabled'), 'a' => _s('Adult'), 't' => _s('Teen and adult')], get_safe_post() ? get_safe_post()['moderatecontent_flag_nsfw'] : CHV\Settings::get('moderatecontent_flag_nsfw')); ?>
|
||||
</select></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<hr class="line-separator">
|
||||
<div class="input-label">
|
||||
<label for="analytics_code"><?php _se('Analytics code'); ?></label>
|
||||
<div class="c12 phablet-c1"><textarea type="text" name="analytics_code" id="analytics_code" class="text-input r4" value="" placeholder="<?php _se('Google Analytics or anything you want. It will be added to the theme footer.'); ?>"><?php echo CHV\Settings::get('analytics_code', true); ?></textarea></div>
|
||||
|
|
11
app/web.php
11
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 {
|
||||
|
|
Loading…
Reference in New Issue