shakauy
Forum Replies Created
-
Forum: Plugins
In reply to: [ByREV WP-PICShield] Can't work under nginxHere is my byrev-wp-picshield2.php file:
<?php
define(‘_GTFO_KEY’,’cm78-A3xv’);if (!array_key_exists(‘key’, $_GET) OR ($_GET[‘key’] != _GTFO_KEY) ){
header(‘HTTP/1.0 401 Unauthorized’);
echo ‘Unauthorized!’;
die(401);
}define(‘_WATERMARK_ENABLED’, true);
define(‘_REDIRECT_DIRECT_LINK_IMAGES_FROM_GOOGLE’, true);
define(‘_HOTLINK_CACHE_FOLDER’, ‘img/~hotlink-cache’);
define(‘_IMAGE_SOURCE_TRANSPARENCY’, 65);
define(‘_BLEND_BAR_WATERMARK’, true);
define(‘_BLEND_BAR_OPACITY’, 25);
define(‘_WRITE_HOST_SOURCE’, false);
define(‘_WATERMARK_POSITION’, 0);
define(‘_WRITE_CREDIT_PLUGIN’, false);
define(‘_MAXIMUM_MEGAPIXELS_SIZE’, 3);
define(‘_WATERMARK_PNG_FILE’, ‘watermark.png’);
define(‘_SEND_HOTLINK_GTFO_HEADER_SIGNATURE’, false);
define(‘_WRITE_TIME_CACHED_OVER_IMAGE’, false);
define(‘_PRINT_QR_HOST’, false);
define(‘_LOG_REFERER_AND_TARGET_IMG’, false);
define(‘_LOG_REFERER_TABLE’, ‘** disabled **’);
define(‘_WATER_MARK_PASS_THROUGH’, true);
define(‘_WATER_MARK_REDIRECT_302_MODE’, false);
define(‘_WP_PICSHIELD_VERSION’, ‘1.8.9 K2’);
define(‘_WP_PICSHIELD_FORCE_WATERMARK’, isset($_GET[‘fw’]));
define(‘_WP_PICSHIELD_FORCE_DEBUG’, isset($_GET[‘fd’]));$image = ltrim(strip_tags( $_GET[‘src’] ), ‘/’);
if (_SEND_HOTLINK_GTFO_HEADER_SIGNATURE) {
header(‘X-Protect: ByREV WP-PICShield , HOTLINK Defence’);
}#~~~~ headers = watermarked file NOT cache
header(“Cache-Control: no-cache, must-revalidate”);
header(“Pragma: no-cache”);
header(“Expires: Sat, 26 Jul 1997 05:00:00 GMT”);#~~~~ REDIRECT DIRECT LINK IMAGES with GOOGLE IMAGES REFERRER
if (_REDIRECT_DIRECT_LINK_IMAGES_FROM_GOOGLE) :
if (array_key_exists(‘HTTP_REFERER’, $_SERVER)) {
$url = $_SERVER[‘HTTP_REFERER’];
$query = parse_url ($url, PHP_URL_QUERY);
$host = parse_url ($url, PHP_URL_HOST);if (strstr ($query, ‘q=’) && strstr ($host, ‘google.’)) {
require_once(‘byrev-wp-image2url.php’);
}}
endif;#~~~~ if watermak is disabled
function img_get_mime_type($file)
{
$mime_types = array(
“gif”=>”image/gif”,
“png”=>”image/png”,
“jpeg”=>”image/jpg”,
“jpg”=>”image/jpg”,
);
$file_exp = explode(‘.’,$file);
$extension = strtolower(end($file_exp));if (array_key_exists($extension, $mime_types)) {
return $mime_types[$extension];
}
return “application/force-download”;
}if (!_WATERMARK_ENABLED) {
$mime = img_get_mime_type($image);
header(‘Content-type: ‘.$mime);
fpassthru(fopen($image, ‘rb’));
exit();
}#~~~~
$dir = dirname(__FILE__);
$watermarked = $dir.’/’._HOTLINK_CACHE_FOLDER.$image;#~~ create WATERMARK cache folders if not exists;
$watermark_folder = dirname($watermarked);
if(!is_dir($watermark_folder)) {
mkdir($watermark_folder, 0777, true);
}function byrev_image_type_to_extension($imagetype) {
if(empty($imagetype)) return false;
switch($imagetype) {
case IMAGETYPE_GIF : return ‘gif’;
case IMAGETYPE_JPEG : return ‘jpeg’;
case IMAGETYPE_PNG : return ‘png’;
case IMAGETYPE_SWF : return ‘swf’;
case IMAGETYPE_PSD : return ‘psd’;
case IMAGETYPE_BMP : return ‘bmp’;
case IMAGETYPE_TIFF_II : return ‘tiff’;
case IMAGETYPE_TIFF_MM : return ‘tiff’;
case IMAGETYPE_JPC : return ‘jpc’;
case IMAGETYPE_JP2 : return ‘jp2’;
case IMAGETYPE_JPX : return ‘jpf’;
case IMAGETYPE_JB2 : return ‘jb2’;
case IMAGETYPE_SWC : return ‘swc’;
case IMAGETYPE_IFF : return ‘aiff’;
case IMAGETYPE_WBMP : return ‘wbmp’;
case IMAGETYPE_XBM : return ‘xbm’;
default : return false;
}
}#~~ if file exist, is serverd from disk, else is generated only once;
if(file_exists($image)&& !file_exists($watermarked)){
#~~~ image type
$image_size = getimagesize($image);$image_mime = $image_size[‘mime’];
$image_type = $image_size[2];
$image_extension = byrev_image_type_to_extension($image_type);
$imagecreatefrom = ‘imagecreatefrom’.$image_extension;
if (!function_exists($imagecreatefrom)) {
header(“Content-type: {$image_mime}”);
fpassthru(fopen($image, ‘rb’));
exit;
}$sizex = $image_size[0];
$sizey = $image_size[1];#~~ file si to big, may not be enough memory … / exit
$max_size = _MAXIMUM_MEGAPIXELS_SIZE * 1048576;
if (($sizex*$sizey) > $max_size) {
header(“Content-type: {$image_mime}”);
fpassthru(fopen($image, ‘rb’));
exit;
}//~~~ create images;
$photo = $imagecreatefrom($image);
$watermark = imagecreatefrompng(_WATERMARK_PNG_FILE);
//imagealphablending($photo, true);$w = imagesx($watermark);
$h = imagesy($watermark);//$sizex = imagesx($photo);
//$sizey = imagesy($photo);$percent = $sizex / (($w>$h)?$w:$h);
$nw = intval($w*$percent);
$nh = intval($h*$percent);switch (_WATERMARK_POSITION) {
case 0: $_watermark_ypos = 10; break;
case 1: $_watermark_ypos = round( ($sizey/2) – ($nh/2) ) ; break;
case 2: $_watermark_ypos = $sizey – $nh – 40; break;
}#~~~ set original image source opacity
$opacity_img = imagecreatetruecolor($sizex, $sizey);
imagecopymerge($photo, $opacity_img, 0, 0, 0, 0, $sizex, $sizey, _IMAGE_SOURCE_TRANSPARENCY);#~~~ set higher opacity band
if (_BLEND_BAR_WATERMARK) :
$opacity_img = imagecreatetruecolor($nw, $nh);
imagecopymerge($photo, $opacity_img, 0, $_watermark_ypos, 0, 0, $nw, $nh, _BLEND_BAR_OPACITY);
endif;
imagedestroy($opacity_img);#~~~ resize watermak with great deal of clarity
$image_p = imagecreatetruecolor($nw, $nh);
ImageAlphaBlending($image_p,false);
ImageSaveAlpha($image_p,true);
imagecopyresampled($image_p, $watermark, 0, 0, 0, 0, $nw, $nh, $w, $h);
imagedestroy($watermark);#~~~ put watermak over image source
imagecopy($photo, $image_p, 0, $_watermark_ypos, 0, 0, $nw, $nh);
imagedestroy($image_p);#~~~ write credit over hotlinked image
if (_WRITE_CREDIT_PLUGIN):
$textcolor = imagecolorallocate($photo, 128, 128, 128);
imagestring($photo, 5, 5, $sizey-17, ‘Protected by: ByREV WP-PICShield – HOTLINK Defence’, $textcolor);
$pos_x_host_source = 35;
else:
$pos_x_host_source = 20;
endif;#~~~ write image source
if (_WRITE_HOST_SOURCE):
$textcolor = imagecolorallocate($photo, 192, 192, 192);
imagestring($photo, 5, 5, $sizey – $pos_x_host_source, ‘( ‘. $_SERVER[‘SERVER_NAME’] .’ )’, $textcolor);
endif;// Output to the browser
imagejpeg($photo, $watermarked, 75);
imagedestroy($photo);
}header(‘Content-type: image/jpeg’);
fpassthru(fopen($watermarked, ‘rb’));
?>Hope that helps
Forum: Plugins
In reply to: [ByREV WP-PICShield] Can't work under nginxThis is the code we used in our site, placed inside the “server” block configuration. Hope it helps to make a new release of this great plugin with Nginx configuration supported by default.
location ~* \.(gif|jpg|jpeg|png)$ {
valid_referers none blocked mysite.org *.mysite.org pinterest.com tumblr.com facebook.com plus.google twitter.com;if ($http_user_agent ~* !(googlebot|msnbot|baiduspider|slurp|webcrawler|teoma|photon|facebookexternalhit|pinterest|feedfetcher|photon|smush\.it|akamai|cloudfront|netdna|bitgravity|maxcdn|edgecast|limelight)) {
return 418;
}if ($invalid_referer) {
return 418;
}
}
}error_page 418 = @hotlink;
location @hotlink {
try_files /img/~hotlink-cache$uri /byrev-wp-picshield2.php?key=cm78-A3xv&src=$uri;
}Forum: Plugins
In reply to: [ByREV WP-PICShield] Can't work under nginxI’ve made it work with Nginx + PHP-FPM daemon. In some days I will release the code for free. Stay tuned.