Since I use Google ads, every image had to be moderated before I could show ads. With Moderatecontent API, we could automate this task. However, the free version is pretty slow and support only 1000 images. Hence, it is impossible to send 10K images uploaded on my site every day.
Based on Auto detect Adult Content and hide thread, I have modified the script to add a few more features to best suite for my requirements. I am only sending those images with a view more than 20 for moderation before I place ads. So I get revenue for all the views generated on the site.
Features
Phase 1: Mark all images uploaded as NSFW by default
After line 89 (before $uploaded_id = CHV\Image::uploadToWebsite($source, $logged_user, $_REQUEST)๐
// Upload to website
$_REQUEST['nsfw'] = 1; //Set all images as NSFW by default on upload
of /app/routes/route.json.php and upload the new file to to /app/routes/overrides
Phase 2: Remove NSFW option from anywhere uploader and replace it with a warning.
Replace line 169 of /var/www/html/app/themes/Peafowl/snippets/anywhere_upload.php with below code. Upload the new file to /var/www/html/app/themes/Peafowl/overrides/snippets.
<div class="margin-10"><span rel="tooltip" data-tiptip="top" title="<?php _se('Adult contents uploaded will be deleted'); ?>"><name="upload-nsfw" id="upload-nsfw" class="margin-right-5" value="1"><label for="upload-nsfw"><?php _se('Note: Adult contents not allowed'); ?></label></span></div>
Phase 3: Add crontab job to run every hour
Moderate.php
dbconnectfile.php
After implementing this, my revenue jumped by 150% as ads get placed on images with good view within 1 hour of being uploaded.
Based on Auto detect Adult Content and hide thread, I have modified the script to add a few more features to best suite for my requirements. I am only sending those images with a view more than 20 for moderation before I place ads. So I get revenue for all the views generated on the site.
Features
- Mark all images as NSWF on upload.
- The hourly script will approve only images with more than 20 views. So that Google Ads can be shown on those images.
- The script will output results to an HTML file which can be viewed on the browser.
- Only sent 10 images for moderation per run to reduce failure.
- For an image with size larger than 10MB, the thumbnail is sent.
- Adult images detected will be added to the log.
- Click the image on the log will initiate a search for the image on the site with the image name.
- Image rating, size, upload date and uploader IP info added to log.
- IP is hyperlinked and clicking it will show all images uploaded from that IP.
Phase 1: Mark all images uploaded as NSFW by default
After line 89 (before $uploaded_id = CHV\Image::uploadToWebsite($source, $logged_user, $_REQUEST)๐
// Upload to website
$_REQUEST['nsfw'] = 1; //Set all images as NSFW by default on upload
of /app/routes/route.json.php and upload the new file to to /app/routes/overrides
Phase 2: Remove NSFW option from anywhere uploader and replace it with a warning.
Replace line 169 of /var/www/html/app/themes/Peafowl/snippets/anywhere_upload.php with below code. Upload the new file to /var/www/html/app/themes/Peafowl/overrides/snippets.
<div class="margin-10"><span rel="tooltip" data-tiptip="top" title="<?php _se('Adult contents uploaded will be deleted'); ?>"><name="upload-nsfw" id="upload-nsfw" class="margin-right-5" value="1"><label for="upload-nsfw"><?php _se('Note: Adult contents not allowed'); ?></label></span></div>
Phase 3: Add crontab job to run every hour
0 * * * * /usr/bin/php /var/www/html/moderate.php >> /var/www/html/log.html //Run moderation hourly
0 0 * * * mv /var/www/html/log.html /var/www/html/log/log_`date +\%d\%m\%y`.html //Archive log every day
Moderate.php
Code:
<html>
<?php
include('dbconnectfile.php'); //Your database config file
date_default_timezone_set('Asia/Kolkata'); // Your time zone
$time=date('Y-m-d H:i:s'); //Current date and time
$result = mysqli_query($link,"SELECT * FROM images where image_views > 20 and image_nsfw=1 and image_date > '2020-01-01 12:58:01' ORDER BY image_id DESC LIMIT 10"); //SQL query to pull images with more than 20 views and uploaded after 01-01-2020
$find=0;
echo '<h2>Mod time '.$time.'</h2>'; //Print cureent date and time to HTML
if (mysqli_num_rows($result)>0){
while($r=mysqli_fetch_array($result))
{
$find++;
$imageid=$r["image_id"];
$imagename=$r["image_name"];
$imageview=$r["image_views"];
$imagex=$r["image_extension"];
$ip=$r["image_uploader_ip"];
$imagedate=$r["image_date"];
$size=$r["image_size"];
$storid=$r["image_storage_id"];
$times=date("Y-m-d", strtotime($imagedate));
$timesp=explode('-',$times);
$search='https://gifyu.com/search/images/?as_q=&as_epq=%22'.$imagename.'%22&as_eq=&as_stor='.$storid.''; //Search link to find image by anme
$storid--;
$imgurl='https://s'.$storid.'.gifyu.com/images/'.$imagename.'.'.$imagex.''; //Generate image URL for external storage server
$imgmd='https://s'.$storid.'.gifyu.com/images/'.$imagename.'.md.'.$imagex.''; //Image URL for thimbnail
$ipurl='https://gifyu.com/search/images/?as_ip='.$ip.''; //Search link to find all images uploaded by this IP
$asize= number_format($size / 1048576, 2) . ' MB'; //Convert image size to MB
if($size < '10485760') // If image size is less than 10MB sent directly for moderation
{
$links='https://www.moderatecontent.com/api/v2?key=yourAPI&url='.$imgurl.'';
}
else //If image size is greater than 10MB sent the thimbnail for moderation
{
$links='https://www.moderatecontent.com/api/v2?key=yourAPI&url='.$imgmd.'';
}
$file_get_contents=file_get_contents($links);
$parse=json_decode($file_get_contents);
$rating=$parse->rating_label;
if ($rating === "everyone"){ //If the image is safe, remove NSFW tag
mysqli_query($link,"UPDATE images SET image_nsfw='0' WHERE image_id='$imageid'") or die(mysql_error());
}
echo '<p><a href='.$search.'><img src='.$imgmd.'></a></p>'; //Display image thimbnail with hyper link to search image by name
echo '<p>'.$rating.' Size: '.$asize.' '.$imagedate.' IP:<a href='.$ipurl.'>'.$ip.'</a> Views:'.$imageview.'<p>'; //Image rating, size, upload date and uploader IP info
}
}
?>
</html>
dbconnectfile.php
Code:
<?php
$link = mysqli_connect("localhost", "DBuser", "DBuserpass", "DBname");
if (!$link) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
mysqli_select_db($link, 'DBname') or die("Could not open the db 'DBname'");
?>
After implementing this, my revenue jumped by 150% as ads get placed on images with good view within 1 hour of being uploaded.
Attachments
Last edited: