( ′∀`)σ≡σ☆))Д′)レ(゚∀゚;)ヘ=З=З=Зε≡(ノ´_ゝ`)ノ
<?php
$mag = $_GET["mag"];
$VideoPath = "uploads/live/";
$live_img = 'uploads/images/';
$msg_id = $db->base64url_decode($msg_id);
$result = $db->getnewsbyidr2($msg_id);
$catalogid = $result[0]["catalogid"];
$yanani= $result[0]["yanani"];
$original= $result[0]["original"];
$title = $result[0]["title"];
$content = $result[0]["content"];
$viewnum = $result[0]["viewnum"];
$rating = $result[0]["rating"];
$picture = $result[0]["picture"];
$ratenum = $result[0]["ratenum"];
$episodeid = $result[0]["episodeid"];
$slug = $result[0]["slug"];
$keywords = $result[0]["keywords"];
$isdisplay = $result[0]["isdisplay"];
$description = $result[0]["description"];
$vcat = $result[0]["vcat"];
$summary = $result[0]["summary"];
$video = $result[0]["video"];
$thumb= $result[0]["thumb"];
$post_id= $_GET["msg_id3"];
$pic ="v/uploads/raw/$original";
list($w, $h) = getimagesize($pic);
if ($w < 400)
{
header("Location: ./index.php?mode=magazines&msg=Your Image is too small. Width should be at least 814px and height of not less than 666px");
}
/*START PROCESS*/
define('MEMORY_TO_ALLOCATE', '100M');
define('DEFAULT_QUALITY', 100);
define('CURRENT_DIR', dirname(__FILE__));
define('CACHE_DIR_NAME', '/v/uploads/raw/');
define('CACHE_DIR', CURRENT_DIR . CACHE_DIR_NAME);
define('DOCUMENT_ROOT', $_SERVER['DOCUMENT_ROOT']);
if(!empty($mag))
{
$width1=500;
}
else
{
$width1=814;
}
/*$height1=100;*/
/*$cropratio="1.666666666666667:1";*/
$photo="/v/uploads/raw/$original";
$resizedPhoto="v/uploads/raw/$original";
function findSharp($orig, $final) // function from Ryan Rud (http://adryrun.com)
{
$final = $final * (750.0 / $orig);
$a = 52;
$b = -0.27810650887573124;
$c = .00047337278106508946;
$result = $a + $b * $final + $c * $final * $final;
return max(round($result), 0);
} // findSharp()
function doConditionalGet($etag, $lastModified)
{
$if_none_match = isset($_SERVER['HTTP_IF_NONE_MATCH']) ?
stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) :
false;
$if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ?
stripslashes($_SERVER['HTTP_IF_MODIFIED_SINCE']) :
false;
if (!$if_modified_since && !$if_none_match)
return;
if ($if_none_match && $if_none_match != $etag && $if_none_match != '"' . $etag . '"')
return; // etag is there but doesn't match
if ($if_modified_since && $if_modified_since != $lastModified)
return; // if-modified-since is there but doesn't match
exit();
} // doConditionalGet()
if (!isset($photo))
{
header("Location: ./index.php?msg=no image was specified");
exit();
}
// Images must be local files, so for convenience we strip the domain if it's there
$image = preg_replace('/^(s?f|ht)tps?:\/\/[^\/]+/i', '', $folder.(string) $photo);
// For security, directories cannot contain ':', images cannot contain '..' or '<', and
// images must start with '/'
if ($image{0} != '/' || strpos(dirname($image), ':') || preg_match('/(\.\.|<|>)/', $image))
{
header("Location: ./index.php?msg=malformed image path. Image paths must begin with");
exit();
}
// If the image doesn't exist, or we haven't been told what it is, there's nothing
// that we can do
if (!$image)
{
header("Location: ./index.php?mode=photos&msg=no image was specified");
exit();
}
// Strip the possible trailing slash off the document root
$docRoot = preg_replace('/\/$/', '', DOCUMENT_ROOT);
if (!file_exists($docRoot . $image))
{
header("Location: ./index.php?mode=photos&msg=image does not exist");
exit();
}
// Get the size and MIME type of the requested image
$size = GetImageSize($docRoot . $image);
$mime = $size['mime'];
// Make sure that the requested file is actually an image
if (substr($mime, 0, 6) != 'image/')
{
header("Location: ./index.php?mode=photos&msg=requested file is not an accepted type");
exit();
}
$width = $size[0];
$height = $size[1];
$maxWidth = (isset($width1)) ? (int) $width1 : 0;
$maxHeight = (isset($height1)) ? (int) $height1 : 0;
if (isset($_GET['color']))
$color = preg_replace('/[^0-9a-fA-F]/', '', (string) $_GET['color']);
else
$color = FALSE;
// If either a max width or max height are not specified, we default to something
// large so the unspecified dimension isn't a constraint on our resized image.
// If neither are specified but the color is, we aren't going to be resizing at
// all, just coloring.
if (!$maxWidth && $maxHeight)
{
$maxWidth = 840;
}
elseif ($maxWidth && !$maxHeight)
{
$maxHeight = 2000;
}
elseif ($color && !$maxWidth && !$maxHeight)
{
$maxWidth = $width;
$maxHeight = $height;
}
// If we don't have a max width or max height, OR the image is smaller than both
// we do not want to resize it, so we simply output the original image and exit
if ((!$maxWidth && !$maxHeight) || (!$color && $maxWidth >= $width && $maxHeight >= $height))
{
$data = file_get_contents($docRoot . '/' . $image);
$lastModifiedString = gmdate('D, d M Y H:i:s', filemtime($docRoot . '/' . $image)) . ' GMT';
$etag = $data;
doConditionalGet($etag, $lastModifiedString);
}
else
{
// Ratio cropping
$offsetX = 0;
$offsetY = 0;
if (isset($_GET['cropratio']))
{
$cropRatio = explode(':', (string) $_GET['cropratio']);
if (count($cropRatio) == 2)
{
$ratioComputed = $width / $height;
$cropRatioComputed = (float) $cropRatio[0] / (float) $cropRatio[1];
if ($ratioComputed < $cropRatioComputed)
{ // Image is too tall so we will crop the top and bottom
$origHeight = $height;
$height = $width / $cropRatioComputed;
$offsetY = ($origHeight - $height) / 2;
}
else if ($ratioComputed > $cropRatioComputed)
{ // Image is too wide so we will crop off the left and right sides
$origWidth = $width;
$width = $height * $cropRatioComputed;
$offsetX = ($origWidth - $width) / 2;
}
}
}
// Setting up the ratios needed for resizing. We will compare these below to determine how to
// resize the image (based on height or based on width)
$xRatio = $maxWidth / $width;
$yRatio = $maxHeight / $height;
if ($xRatio * $height < $maxHeight)
{ // Resize the image based on width
$tnHeight = ceil($xRatio * $height);
$tnWidth = $maxWidth;
}
else // Resize the image based on height
{
$tnWidth = ceil($yRatio * $width);
$tnHeight = $maxHeight;
}
// Determine the quality of the output image
$quality = (isset($_GET['quality'])) ? (int) $_GET['quality'] : DEFAULT_QUALITY;
// Before we actually do any crazy resizing of the image, we want to make sure that we
// haven't already done this one at these dimensions. To the cache!
// Note, cache must be world-readable
// We store our cached image filenames as a hash of the dimensions and the original filename
$extfile = explode('/',$image);
$extfile = $extfile[5];
$extfile = explode('.',$extfile);
$imageName = $extfile[0];
switch ($size['mime'])
{
case 'image/gif':
$resizedImage = "$imageName.gif";
break;
case 'image/x-png':
case 'image/png':
$resizedImage = "$imageName.png";
break;
default:
$resizedImage = "$imageName.jpg";
break;
}
$resized = CACHE_DIR . $resizedImage;
$nocache = "yes";
// Check the modified times of the cached file and the original file.
// If the original file is older than the cached file, then we simply serve up the cached file
// We don't want to run out of memory
ini_set('memory_limit', MEMORY_TO_ALLOCATE);
// Set up a blank canvas for our resized image (destination)
$dst = imagecreatetruecolor($tnWidth, $tnHeight);
// Set up the appropriate image handling functions based on the original image's mime type
switch ($size['mime'])
{
case 'image/gif':
// We will be converting GIFs to PNGs to avoid transparency issues when resizing GIFs
// This is maybe not the ideal solution, but IE6 can suck it
$creationFunction = 'ImageCreateFromGif';
$outputFunction = 'ImagePng';
$mime = 'image/png'; // We need to convert GIFs to PNGs
$doSharpen = FALSE;
$quality = round(10 - ($quality / 10)); // We are converting the GIF to a PNG and PNG needs a compression level of 0 (no compression) through 9
break;
case 'image/x-png':
case 'image/png':
$creationFunction = 'ImageCreateFromPng';
$outputFunction = 'ImagePng';
$doSharpen = FALSE;
$quality = round(10 - ($quality / 10)); // PNG needs a compression level of 0 (no compression) through 9
break;
default:
$creationFunction = 'ImageCreateFromJpeg';
$outputFunction = 'ImageJpeg';
$doSharpen = FALSE;
break;
}
// Read in the original image
$src = $creationFunction($docRoot . $image);
if (in_array($size['mime'], array('image/gif', 'image/png')))
{
if (!$color)
{
// If this is a GIF or a PNG, we need to set up transparency
imagealphablending($dst, false);
imagesavealpha($dst, true);
}
else
{
// Fill the background with the specified color for matting purposes
if ($color[0] == '#')
$color = substr($color, 1);
$background = FALSE;
if (strlen($color) == 6)
$background = imagecolorallocate($dst, hexdec($color[0].$color[1]), hexdec($color[2].$color[3]), hexdec($color[4].$color[5]));
else if (strlen($color) == 3)
$background = imagecolorallocate($dst, hexdec($color[0].$color[0]), hexdec($color[1].$color[1]), hexdec($color[2].$color[2]));
if ($background)
imagefill($dst, 0, 0, $background);
}
}
// Resample the original image into the resized canvas we set up earlier
imagecopyresampled($dst, $src, 0, 0, $offsetX, $offsetY, $tnWidth, $tnHeight, $width, $height);
if ($doSharpen)
{
// Sharpen the image based on two things:
// (1) the difference between the original size and the final size
// (2) the final size
$sharpness = findSharp($width, $tnWidth);
$sharpenMatrix = array(
array(-1, -2, -1),
array(-2, $sharpness + 12, -2),
array(-1, -2, -1)
);
$divisor = $sharpness;
$offset = 0;
imageconvolution($dst, $sharpenMatrix, $divisor, $offset);
}
// Make sure the cache exists. If it doesn't, then create it
if (!file_exists(CACHE_DIR))
mkdir(CACHE_DIR, 0755);
// Make sure we can read and write the cache directory
if (!is_readable(CACHE_DIR))
{
header("Location: ./index.php?mode=photos&msg=the cache directory is not readable");
exit();
}
else if (!is_writable(CACHE_DIR))
{
header("Location: ./index.php?mode=photos&msg=the cache directory is not writable");
exit();
}
// Write the resized image to the cache
$outputFunction($dst, $resized, 100);
// Put the data of the resized image into a variable
ob_start();
$outputFunction($dst, null, 100);
$data = ob_get_contents();
ob_end_clean();
// Clean up the memory
ImageDestroy($src);
ImageDestroy($dst);
// See if the browser already has the image
$lastModifiedString = gmdate('D, d M Y H:i:s', filemtime($resized)) . ' GMT';
$etag = $data;
doConditionalGet($etag, $lastModifiedString);
}
list($upana, $urefu) = getimagesize($resizedPhoto);
if ($upana <300)
{
header("Location: ./index.php?mode=photos&msg=Your photo is too small to edit! ");
exit();}
/*END PROCESS IMAGE*/
?>
<style type="text/css">
.thumbnails{
width:100px;
float:left;
border:#363636 dashed 1px;
margin:2px;
margin-left:10px;
margin-bottom:10px;
}
</style>
<table id="Table_01" width="100%" height="537" border="0" cellpadding="0" cellspacing="0" >
<tr>
<td align="center" valign="top"><table width="100%" border="0">
<tr>
<td width="348" height="54"><img src="images/pimp.png" width="348" height="54" /></td>
<td align="right">
<?php $msg_idx = $db->base64url_encode($msg_id); ?>
<?php if($step < 7 )
{?>
<?php
if(!empty($mag))
{?>
<span id="done3"> <a class="large ezbutton green" href="index.php?mode=magazines&msg_id=<?php echo $msg_idx ?>&mag=yes&step=7" style=" margin-top:2px;border:0px;background-color:#333; margin-right:5px">Skip</a></span> <?php }
else
{?>
<span id="done3"> <a class="large ezbutton green" href="index.php?mode=pimpme&msg_id=<?php echo $msg_idx ?>&step=7" style=" margin-top:2px;border:0px;background-color:#333; margin-right:5px">Skip</a></span>
<?php }
?>
<?php }?>
<span id="process"><a id="submit" class="large ezbutton green" style=" margin-top:2px;border:0px; margin-right:5px">Pimp My Photo!</a></span>
</td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
<form id="jsonform5" action="index.php?mag=mag&mode=share&msg_id=<?php echo $msg_idx ?>&step=2" method="POST">
</form>
<form id="s" action="index.php" method="POST"> <?php
$mag = $_GET["mag"];
if(!empty($mag))
{?>
<input type="hidden" id="mag" name="mag" value="yes" />
<?php }
else
{?>
<input type="hidden" id="mag" name="mag" value="no" />
<?php }
?>
<input id="effecto" name="effecto" type="text" value="contrast" autocomplete="off"></input>
<input id="photo" name="photo" type="hidden" value="<?php echo $original;?>"></input>
<input type="hidden" id="msg_id" name="msg_id" value="<?php echo $msg_idx ?>" />
<input type="hidden" id="step" name="step" value="<?php echo $step;?>" />
<input type="hidden" id="brand" name="brand" value="watermark.png" />
</form>
<script type="text/javascript">
$(function() {
$("#submit").click(function() {
var effect= encodeURI(document.getElementById('effecto').value);
var image= encodeURI(document.getElementById('photo').value);
var mag= encodeURI(document.getElementById('mag').value);
var msg_id= encodeURI(document.getElementById('msg_id').value);
var step= encodeURI(document.getElementById('step').value);
document.getElementById('process').innerHTML = 'Processing your Photo...';
if (mag == "yes")
{
$('#preview img').load(function() {
$('p').remove();
}).attr('src', 'processSaveMag.php?step=' + step + '&image=' + image + '&msg_id=' + msg_id + '&mag=' + mag + '&filter=' + effect);
}
if (mag == "no")
{
$('#preview img').load(function() {
$('p').remove();
}).attr('src', 'processSave.php?image=' + image + '&msg_id=' + msg_id + '&filter=' + effect);
}
document.getElementById('done').innerHTML = " ";
document.getElementById('done2').innerHTML = " ";
document.getElementById('done3').innerHTML = " ";
if (mag == "yes")
{
document.getElementById('process').innerHTML = '<a class="large ezbutton green" style=" margin-top:2px;border:0px; margin-right:5px" href="?mode=share&msg_id=' + msg_id + '&step=7">Share!</a>';
}
if (mag == "no")
{
document.getElementById('process').innerHTML = '<a class="large ezbutton green" style=" margin-top:2px;border:0px; margin-right:5px" href="index.php?mode=share&msg_id=' + msg_id + '&step=7">Share!</a>';
}
/* $('#jsonform5').submit();*/
});
$('.followme').click(function() {
var effect = $(this).attr("id");
var image = $(this).attr("title");
$('#effecto').val(effect);
var mag= encodeURI(document.getElementById('mag').value);
if (mag == "yes")
{
if ($('p').length == 0) $('.read').after('<p>Processing...</p>');
$('#preview img').load(function() {
$('p').remove();
}).attr('src', 'processMag.php?mag=yes&image=' + image + '&filter=' + effect);
}
if (mag == "no")
{
if ($('p').length == 0) $('.read').after('<p>Processing...</p>');
$('#preview img').load(function() {
$('p').remove();
}).attr('src', 'process.php?image=' + image + '&filter=' + effect);
}
});
});
</script>
<span id="done2">
<?php
if($step==1 || empty($step))
{
include("pages/filters.php");
}
/* if($step==2)
{
include("pages/covers.php");
}*/
if($step==3)
{
include("pages/captions.php");
}
?>
</span>
</td>
</tr>
<tr>
<td align="center">
<table width="100%" border="0" >
<tr>
<?php if($step==2)
{?>
<td width="100" valign="top">
<?php include("pages/covers.php");?>
</td>
<?php }
?>
<td valign="top" ><span id="proceed"></span>
<div id="done"></div>
<div id="preview">
<img class="<?php echo $original ?>" src="v/uploads/raw/<?php echo $original ?>" style=" margin-left:2px;-moz-border-radius : 3px 3px 3px 3px:-webkit-border-radius : 3px 3px 3px 3px;border-radius : 3px 3px 3px 3px; " width="<?php echo $upana;?>" height="<?php echo $urefu;?>" >
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<script>
$(document).ready(function(id) {
var count_dropped_hits = 0;
var data = {
"images": [
{"id" : "obj_0" ,"src" : "v/uploads/raw/<?php echo $original ?>" ,"width" : "<?php echo $upana;?>", "height" : "<?php echo $urefu;?>"}
]
};
// Array Remove - By John Resig (MIT Licensed)
Array.prototype.remove = function(from, to) {
var rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest);
};
/* remove an object from data */
$('.remove',$('#tools')).live('click',function(){
var $this = $(this);
/* the element next to this is the input that stores the obj id */
var objid = $this.next().val();
/* remove the object from the sidebar */
$this.parent().remove();
/* ,from the picture */
var divwrapper = $('#'+objid).parent().parent();
$('#'+objid).remove();
/* add again to the objects list */
var image_elem = $this.parent().find('img');
var thumb_width = image_elem.attr('width');
var thumb_height = image_elem.attr('height');
var thumb_src = image_elem.attr('src');
$('<img/>',{
id : objid,
src : thumb_src,
width : thumb_width,
//height : thumb_height,
className : 'ui-widget-content'
}).appendTo(divwrapper).resizable({
handles : 'se',
stop : resizestop
}).parent('.ui-wrapper').draggable({
revert: 'invalid'
});
/* and unregister it - delete from object data */
var index = exist_object(objid);
data.images.remove(index);
});
/* checks if an object was already registered */
function exist_object(id){
for(var i = 0;i<data.images.length;++i){
if(data.images[i].id == id)
return i;
}
return -1;
}
/* triggered when stop resizing an object */
function resizestop(event, ui) {
//calculate and change values to obj (width and height)
var $this = $(this);
var objid = $this.find('.ui-widget-content').attr('id');
var objwidth = ui.size.width;
var objheight = ui.size.height;
var index = exist_object(objid);
if(index!=-1) { //if exists (it should!) update width and height
data.images[index].width = objwidth;
data.images[index].height = objheight;
}
}
/* objects are resizable and draggable */
$('#objects img').resizable({
/* only diagonal (south east)*/
handles : 'se',
stop : resizestop
}).parent('.ui-wrapper').draggable({
revert : 'invalid'
});
$('#background').droppable({
accept : '#objects div', /* accept only draggables from #objects */
drop : function(event, ui) {
var $this = $(this);
++count_dropped_hits;
var draggable_elem = ui.draggable;
draggable_elem.css('z-index',count_dropped_hits);
/* object was dropped : register it */
var objsrc = draggable_elem.find('.ui-widget-content').attr('src');
var objwidth = parseFloat(draggable_elem.css('width'),10);
var objheight = parseFloat(draggable_elem.css('height'),10);
/* for top and left we decrease the top and left of the droppable element */
var objtop = ui.offset.top - $this.offset().top;
var objleft = ui.offset.left - $this.offset().left;
var objid = draggable_elem.find('.ui-widget-content').attr('id');
var index = exist_object(objid);
if(index!=-1) { //if exists update top and left
data.images[index].top = objtop;
data.images[index].left = objleft;
}
else{
/* register new one */
var newObject = {
'id' : objid,
'src' : objsrc,
'width' : objwidth,
'height' : objheight,
'top' : objtop,
'left' : objleft,
'rotation' : '0'
};
data.images.push(newObject);
/* add object to sidebar*/
$('<div/>',{
className : 'item'
}).append(
$('<div/>',{
className : 'thumb',
html : '<img width="50" class="ui-widget-content" src="'+objsrc+'"></img>'
})
).append(
$('<div/>',{
className : 'slider',
html : '<span>Rotate</span><span class="degrees">0</span>'
})
).append(
$('<a/>',{
className : 'remove'
})
).append(
$('<input/>',{
type : 'hidden',
value : objid // keeps track of which object is associated
})
).appendTo($('#tools'));
$('.slider').slider({
orientation : 'horizontal',
max : 180,
min : -180,
value : 0,
slide : function(event, ui) {
var $this = $(this);
/* Change the rotation and register that value in data object when it stops */
draggable_elem.css({'-moz-transform':'rotate('+ui.value+'deg)','-webkit-transform':'rotate('+ui.value+'deg)'});
$('.degrees',$this).html(ui.value);
},
stop : function(event, ui) {
newObject.rotation = ui.value;
}
});
}
}
});
/* User presses the download button */
$('#submit').bind('click',function(){
var dataString = JSON.stringify(data);
$('#jsondata').val(dataString);
$('#jsonform').submit();
});
});
</script>