126 lines
5.7 KiB
PHP
126 lines
5.7 KiB
PHP
|
|
<?php if ( !defined('PATHTOINCLUDES') ) define('PATHTOINCLUDES', $_SERVER["DOCUMENT_ROOT"] . '/include/analytics/');
|
||
|
|
include(PATHTOINCLUDES."base.php");
|
||
|
|
date_default_timezone_set('UTC');
|
||
|
|
// A list of permitted file extensions
|
||
|
|
if(isset($_POST["adlink"])){$theadlink=$_POST["adlink"];} else {$theadlink="";}
|
||
|
|
$allowed = array('png', 'jpg', 'jpeg', 'gif');
|
||
|
|
if(isset($_FILES['upl']) && $_FILES['upl']['error'] == 0){
|
||
|
|
$dbcon=dbconnect2();
|
||
|
|
//$sql="Delete FROM `community_user_ads`";
|
||
|
|
//$query=mysql_query($sql);
|
||
|
|
// check number of ads uploaded by customer
|
||
|
|
$em="";
|
||
|
|
$sql="SELECT count(`adid`) FROM `community_user_ads` WHERE `community_user_ads`.`trash` = 0 AND `userid` = ".$_SESSION["cp_userid"];
|
||
|
|
$query=mysql_query($sql) or $em=$em.mysql_error();
|
||
|
|
$row=mysql_fetch_row($query);
|
||
|
|
$countofads=$row[0];
|
||
|
|
if($countofads >= 3)
|
||
|
|
{
|
||
|
|
$tmpfile=$_FILES['upl']['tmp_name'];
|
||
|
|
@unlink($_FILES['upl']['tmp_name']);
|
||
|
|
$isgone=file_exists($tmpfile);
|
||
|
|
echo '{"status":"Error: You have exceeded the limit of 3 ads. Please delete an ad and try again.","imgurl":"","iwidth":"","iheight":"","thecount":"","badurl":""}';
|
||
|
|
exit;
|
||
|
|
}
|
||
|
|
//check image extention
|
||
|
|
$extension = pathinfo($_FILES['upl']['name'], PATHINFO_EXTENSION);
|
||
|
|
if(!in_array(strtolower($extension), $allowed)){
|
||
|
|
$tmpfile=$_FILES['upl']['tmp_name'];
|
||
|
|
@unlink($_FILES['upl']['tmp_name']);
|
||
|
|
$isgone=file_exists($tmpfile);
|
||
|
|
echo '{"status":"Error: Please upload a jpg, gif, or png file !","imgurl":"","iwidth":"","iheight":"","thecount":"","badurl":""}';
|
||
|
|
exit;
|
||
|
|
}
|
||
|
|
// check size of image
|
||
|
|
$thesize=$_FILES['upl']['size'];
|
||
|
|
if($thesize > 5000000)
|
||
|
|
{
|
||
|
|
$tmpfile=$_FILES['upl']['tmp_name'];
|
||
|
|
@unlink($_FILES['upl']['tmp_name']);
|
||
|
|
$isgone=file_exists($tmpfile);
|
||
|
|
echo '{"status":"Error: Image file size exceeds 5MB !","imgurl":"","iwidth":"","iheight":"","thecount":"","badurl":""}';
|
||
|
|
exit;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
$updir=dirname( __FILE__ );
|
||
|
|
$updir=$updir."/uploads/".$_SESSION["cp_userid"];
|
||
|
|
$imgurl="/mini-upload-form/uploads/".$_SESSION["cp_userid"]."/".$_FILES['upl']['name'];
|
||
|
|
$imgpath=$updir."/".$_FILES['upl']['name'];
|
||
|
|
$imgname=$_FILES['upl']['name'];
|
||
|
|
if(!is_dir($updir))
|
||
|
|
{
|
||
|
|
if(!mkdir($updir,0777)){echo '{"status":"System Error: Please try again. If error persists, please contact <a href=\"http://bateworld.com/help_contact.php\" target=\"_blank\">bateworld customer satisfaction</a> !","imgurl":"","iwidth":"","iheight":"","thecount":"","badurl":""}';exit;}
|
||
|
|
}
|
||
|
|
if(move_uploaded_file($_FILES['upl']['tmp_name'], $updir."/".$_FILES['upl']['name'])){
|
||
|
|
//strip image of Exif data - which can be corrupt
|
||
|
|
$image = new Imagick($imgpath);
|
||
|
|
$image->stripImage();
|
||
|
|
// Writes resultant image to output directory
|
||
|
|
$image->writeImage($imgpath);
|
||
|
|
$image->destroy();
|
||
|
|
//resize image
|
||
|
|
$size = getimagesize($imgpath);
|
||
|
|
$width=$size[0];
|
||
|
|
$height=$size[1];
|
||
|
|
include("resize-class.php");
|
||
|
|
if($width >= $height)
|
||
|
|
{
|
||
|
|
$resizeObj = new resize($imgpath);
|
||
|
|
$resizeObj -> resizeImage(435,'landscape'); //resize to landscape with fixed width of 435 px
|
||
|
|
$resizeObj -> saveImage($imgpath, 100);
|
||
|
|
$size = getimagesize($imgpath);
|
||
|
|
$width=$size[0];
|
||
|
|
$height=$size[1];
|
||
|
|
}
|
||
|
|
if($height > 116 || $height > $width)
|
||
|
|
{
|
||
|
|
$resizeObj = new resize($imgpath);
|
||
|
|
$resizeObj -> resizeImage(435,116,'crop'); //crop image to 435px width by 220 height
|
||
|
|
$resizeObj -> saveImage($imgpath, 100);
|
||
|
|
$width=435;
|
||
|
|
$height=116;
|
||
|
|
}
|
||
|
|
$urlissue=0;
|
||
|
|
$headers = @get_headers($theadlink);
|
||
|
|
|
||
|
|
if(strpos($headers[0],'404')==true) {$urlissue=1;}
|
||
|
|
// insert image details into database table
|
||
|
|
$sqlins="INSERT INTO `community_user_ads` (`userid`,`username`,`useremail`,`image_url`,`image_width`,`image_height`,`thelink`,`image_name`,`badurl`)
|
||
|
|
VALUES(
|
||
|
|
".$_SESSION["cp_userid"].",
|
||
|
|
'".$_SESSION["nickname"]."',
|
||
|
|
'".$_SESSION["cp_useremail"]."',
|
||
|
|
'".$imgurl."',
|
||
|
|
".$width.",
|
||
|
|
".$height.",
|
||
|
|
".GetSQLValueString($theadlink,"text").",
|
||
|
|
'".$imgname."',
|
||
|
|
".$urlissue.")";
|
||
|
|
$qins=mysql_query($sqlins) or $em=$em.mysql_error();
|
||
|
|
$adid= mysql_insert_id();
|
||
|
|
|
||
|
|
|
||
|
|
$status="Approval Pending";
|
||
|
|
$colorclass="yellow";
|
||
|
|
$userad="";
|
||
|
|
$userad.='<tr id=\"dad_'.$adid.'\" style=\"background:#333;\" onmouseover=\"this.style.background=\'#000\';\" onmouseout=\"this.style.background=\'#333\'\"><td style=\"width:90px;padding-left:2px;\"><img src=\"'.$imgurl.'\" width=\"'.$width.'\" height=\"'.$height.'\" style=\"width:100%;height:auto;\" /></td><td class=\"ua-status '.$colorclass.'\" style=\"padding-left:5px;\">'.$status.'</td>';
|
||
|
|
$userad.='<td>N/A</td><td>N/A</td><td>N/A</td>';
|
||
|
|
$userad.='<td class=\"tdright\" nowrap=\"nowrap\"><a onclick=\"ed_msad(\''.$adid.'\');\">edit</a> | <a class=\"adelad\" onclick=\"del_ad(\''.$adid.'\');\">del</a></td>';
|
||
|
|
$userad.='</tr>';
|
||
|
|
$userad.='<tr id=\"uef_'.$adid.'\" class=\"ms_uef\"><td colspan=\"6\"><div id=\"aeem_'.$adid.'\" class=\"aeem\"></div><div id=\"ed_'.$adid.'\" class=\"edit_ad\"> <label>URL: </label><input type=\"text\" name=\"url_'.$adid.'\" id=\"url_'.$adid.'\" value=\"'.$theadlink.'\" size=\"33\" maxlength=\"250\" /><button class=\"redbutton\" onclick=\"subuef(\''.$adid.'\')\">Update</button></div></td></tr>';
|
||
|
|
|
||
|
|
// do nothing on error ???
|
||
|
|
echo '{"status":"success","imgurl":"'.$imgurl.'","iwidth":"'.$width.'","iheight":"'.$height.'","thecount":"'.$row[0].'","badurl":"'.$urlissue.'","userad":"'.$userad.'", "adid":"'.$adid.'"}';
|
||
|
|
|
||
|
|
mail("phil@b8world.com", "New Members Section Add", "Waiting For Approval");
|
||
|
|
mail("bateworld@gmail.com", "New Members Section Add", "Waiting For Approval");
|
||
|
|
mail("bwecreative@gmail.com", "New Members Section Add", "Waiting For Approval");
|
||
|
|
mail("bateworldhelp@gmail.com", "New Members Section Add", "Waiting For Approval");
|
||
|
|
|
||
|
|
exit();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
echo '{"status":"error general","imgurl":"","iwidth":"","iheight":"","thecount":"","badurl":""}';
|
||
|
|
exit;
|