"; $message.=__("AWPCP requires the graphics processing library GD and it is not installed. Contact your web host to fix this.","AWPCP"); $message.=""; echo $message; die; } /** * @param $file A $_FILES item */ function awpcp_upload_image_file($directory, $filename, $tmpname, $min_size, $max_size, $min_width, $min_height, $uploaded=true) { $filename = sanitize_file_name($filename); $newname = wp_unique_filename($directory, $filename); $newpath = trailingslashit($directory) . $newname; $ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); $imginfo = getimagesize($tmpname); $size = filesize($tmpname); $allowed_extensions = array('gif', 'jpg', 'jpeg', 'png'); if (empty($filename)) { return __('No file was selected.', 'AWPCP'); } if ($uploaded && !is_uploaded_file($tmpname)) { return __('Unknown error encountered while uploading the image.', 'AWPCP'); } if (empty($size) || $size <= 0) { $message = "There was an error trying to find out the file size of the image %s."; return __(sprintf($message, $filename), 'AWPCP'); } if (!(in_array($ext, $allowed_extensions))) { return __('The file has an invalid extension and was rejected.', 'AWPCP'); } elseif ($size < $min_size) { $message = __('The size of %1$s was too small. The file was not uploaded. File size must be greater than %2$d bytes.', 'AWPCP'); return sprintf($message, $filename, $min_size); } elseif ($size > $max_size) { $message = __('The file %s was larger than the maximum allowed file size of %s bytes. The file was not uploaded.', 'AWPCP'); return sprintf($message, $filename, $max_size); } elseif (!isset($imginfo[0]) && !isset($imginfo[1])) { return __('The file does not appear to be a valid image file.', 'AWPCP'); } elseif ($imginfo[0] < $min_height) { $message = __('The image did not meet the minimum width of %s pixels. The file was not uploaded.', 'AWPCP'); return sprintf($message, $min_width); } elseif ($imginfo[1] < $min_height) { $message = __('The image did not meet the minimum height of %s pixels. The file was not uploaded.', 'AWPCP'); return sprintf($message, $min_width); } if ($uploaded && !@move_uploaded_file($tmpname, $newpath)) { $message = __('The file % could not be moved to the destination directory.', 'AWPCP'); return sprintf($message, $filename); } else if (!$uploaded && !@copy($tmpname, $newpath)) { $message = __('The file %s could not be moved to the destination directory.', 'AWPCP'); return sprintf($message, $filename); } if (!awpcp_create_image_versions($newname, $directory)) { $message = __('Could not create resized versions of image %s.', 'AWPCP'); # TODO: unlink resized version, thumbnail and primary image @unlink($newpath); return sprintf($message, $filename); } @chmod($newpath, 0644); return array('original' => $filename, 'filename' => $newname); } /** * Used in the admin panels to add images to existing ads */ function admin_handleimagesupload($adid) { global $wpdb, $wpcontentdir, $awpcp_plugin_path; list($images_dir, $thumbs_dir) = awpcp_setup_uploads_dir(); list($min_width, $min_height, $min_size, $max_size) = awpcp_get_image_constraints(); $ad = AWPCP_Ad::find_by_id($adid); if (!is_null($ad)) { list($images_allowed, $images_uploaded, $images_left) = awpcp_get_ad_images_information($adid); if ($images_left > 0) { $filename = awpcp_array_data('name', '', $_FILES['awpcp_add_file']); $tmpname = awpcp_array_data('tmp_name', '', $_FILES['awpcp_add_file']); $result = awpcp_upload_image_file($images_dir, $filename, $tmpname, $min_size, $max_size, $min_width, $min_height); } else { $message = __('No more images can be added to this Ad. The Ad already have %d of %d images allowed.', 'AWPCP'); $result = sprintf($message, $images_uploaded, $images_allowed); } } else { $result = __("The Ad doesn't exists. All uploaded files were rejected.", 'AWPCP'); } if (is_array($result) && isset($result['filename'])) { // TODO: consider images approve settings $sql = 'insert into ' . AWPCP_TABLE_ADPHOTOS . " set image_name = '%s', ad_id = '$adid', disabled = 0"; $sql = $wpdb->prepare($sql, $result['filename']); $result = $wpdb->query($sql) ; } else { return '
' . $result . '
"; // $awpcpuerror[].=__("No file was selected","AWPCP"); // $awpcpuerror[].="
"; // $awpcpuploadformshow=display_awpcp_image_upload_form($adid,$adtermid,$adkey,$adaction,$nextstep,$adpaymethod,$awpcpuerror); // $output .= $awpcpuploadformshow; // } // else // { // $output .= awpcpuploadimages($adid,$adtermid,$adkey,$imgmaxsize,$imgminsize,$twidth,$nextstep,$adpaymethod,$adaction,$awpcp_main_folder,'AWPCPfileToUpload'); // } // return $output; } // function awpcpuploadimages($adid,$adtermid,$adkey,$imgmaxsize,$imgminsize,$twidth,$nextstep,$adpaymethod,$adaction,$destdir,$actual_field_name,$required=false) // { // $output = ''; // global $wpdb; // $tbl_ad_photos = $wpdb->prefix . "awpcp_adphotos"; // $awpcpupdatinserted=false; // $awpcpuploaderror=false; // $awpcpfilesuploaded=true; // $awpcpuerror=array(); // if(adidexists($adid)) { // $totalimagesuploaded=get_total_imagesuploaded($adid); // } // $numimgsallowed = awpcp_get_ad_number_allowed_images($adid, $adtermid); // $numimgsleft = ($numimgsallowed - $totalimagesuploaded); // //debug("num imgs left: $numimgsleft"); // for ($i = 0; $i < $numimgsleft; $i++) { // //debug("num imgs left: $numimgsleft, i: $i"); // $filename = addslashes($_FILES[$actual_field_name.$i]['name']); // $ext = strtolower(substr(strrchr($_FILES[$actual_field_name.$i]['name'],"."),1)); // $ext_array = array('gif','jpg','jpeg','png'); // if (isset($_FILES[$actual_field_name.$i]['tmp_name']) && // is_uploaded_file($_FILES[$actual_field_name.$i]['tmp_name'])) { // $imginfo = getimagesize($_FILES[$actual_field_name.$i]['tmp_name']); // $imgfilesizeval=filesize($_FILES[$actual_field_name.$i]['tmp_name']); // $desired_filename = mktime(); // $desired_filename .= "_$i"; // if(isset($filename) && !empty($filename)) { // if (!(in_array($ext, $ext_array))) { // $awpcpuploaderror=true; // $awpcpuerror[].="[$filename]"; // $awpcpuerror[].=__(" had an invalid file extension and was not uploaded","AWPCP"); // $awpcpuerror[].="
"; // } // elseif(filesize($_FILES[$actual_field_name.$i]['tmp_name']) <= $imgminsize) // { // $awpcpuploaderror=true; // $awpcpuerror[].=""; // $awpcpuerror[].=sprintf(__("The size of %1$s was too small. The file was not uploaded. File size must be greater than %2$d bytes", "AWPCP"), $filename, $imgminsize); // $awpcpuerror[].="
"; // } // elseif($imginfo[0]< $twidth) // { // // width is too short // $awpcpuploaderror=true; // $awpcpuerror[].="[$filename]"; // $awpcpuerror[].=sprintf(__(" did not meet the minimum width of [%s] pixels. The file was not uploaded", "AWPCP"), $twidth); // $awpcpuerror[].="
"; // } // elseif ($imginfo[1]< $twidth) // { // // height is too short // $awpcpuploaderror=true; // $awpcpuerror[].="[$filename]"; // $awpcpuerror[].=sprintf(__(" did not meet the minimum height of [%s] pixels. The file was not uploaded", "AWPCP"), $twidth); // $awpcpuerror[].="
"; // } // elseif(!isset($imginfo[0]) && !isset($imginfo[1])) // { // $awpcpuploaderror=true; // $awpcpuerror[].="[$filename]"; // $awpcpuerror[].=__(" does not appear to be a valid image file","AWPCP"); // $awpcpuerror[].="
"; // } // elseif( $imgfilesizeval > $imgmaxsize ) // { // $awpcpuploaderror=true; // $awpcpuerror[].="[$filename]"; // $awpcpuerror[].=sprintf(__(" was larger than the maximum allowed file size of [%s] bytes. The file was not uploaded", "AWPCP"), $imgmaxsize); // $awpcpuerror[].="
"; // } elseif(!empty($desired_filename)) { // //debug('uploading...'); // $filename="$desired_filename.$ext"; // if (!move_uploaded_file($_FILES[$actual_field_name.$i]['tmp_name'],$destdir.'/'.$filename)) { // $orfilename=$filename; // $filename=''; // $awpcpuploaderror=true; // $awpcpuerror[].="[$orfilename]"; // $awpcpuerror[].=__(" could not be moved to the destination directory","AWPCP"); // $awpcpuerror[].="
"; // } else { // awpcp_resizer($filename, $destdir); // if(!awpcpcreatethumb($filename,$destdir,$twidth)) { // $awpcpuploaderror=true; // $awpcpuerror[].=""; // $awpcpuerror[].=sprintf(__("Could not create thumbnail image of [ %s ]", "AWPCP"), $filename); // $awpcpuerror[].="
"; // } // @chmod($destdir.'/'.$filename,0644); // $ctiu = get_total_imagesuploaded($adid); // if(get_awpcp_option('imagesapprove') == 1) { // $disabled=1; // } else { // $disabled=0; // } // if($ctiu < $numimgsallowed) { // $query="INSERT INTO ".$tbl_ad_photos." SET image_name='$filename',ad_id='$adid',disabled='$disabled'"; // if (!($res=@mysql_query($query))) { // sqlerrorhandler("(".mysql_errno().") ".mysql_error(), $query, $_SERVER['PHP_SELF'], __LINE__); // } // } // $awpcpupdatinserted=true; // if(!($awpcpupdatinserted)) { // $awpcpuploaderror=true; // $awpcpuerror[].=""; // $awpcpuerror[].=sprintf(__("Could not save the information to the database for [ %s ]", "AWPCP"), $filename); // $awpcpuerror[].="
"; // } // } // } // } else { // $awpcpuploaderror=true; // $awpcpuerror[].=""; // $awpcpuerror[].=__("Unknown error encountered uploading image","AWPCP"); // $awpcpuerror[].="
"; // } // } // //debug($awpcpuerror); // } // Close for $i... // if ($awpcpuploaderror) // { // $awpcpuploadformshow=display_awpcp_image_upload_form($adid,$adtermid,$adkey,$adaction,$nextstep,$adpaymethod,$awpcpuerror); // $output .= $awpcpuploadformshow; // } // elseif(!($awpcpfilesuploaded)) // { // $awpcpuerror[]=""; // $awpcpuerror[].=__("One or more images failed to be uploaded","AWPCP"); // $awpcpuerror[].="
"; // $awpcpuploadformshow=display_awpcp_image_upload_form($adid,$adtermid,$adkey,$adaction,$nextstep,$adpaymethod,$awpcpuerror); // $output .= $awpcpuploadformshow; // } // else // { // if(($nextstep == 'finish') && ($adaction == 'editad')) { // $awpcpadpostedmsg=__("Your ad has been submitted","AWPCP"); // if(get_awpcp_option('adapprove') == 1) // { // $awaitingapprovalmsg=get_awpcp_option('notice_awaiting_approval_ad'); // $awpcpadpostedmsg.=""; // $awpcpadpostedmsg.=$awaitingapprovalmsg; // $awpcpadpostedmsg.="
"; // } // if(get_awpcp_option('imagesapprove') == 1) // { // $imagesawaitingapprovalmsg=__("If you have uploaded images your images will not show up until an admin has approved them.","AWPCP"); // $awpcpadpostedmsg.=""; // $awpcpadpostedmsg.=$imagesawaitingapprovalmsg; // $awpcpadpostedmsg.="
"; // } // $awpcpshowadsample=1; // $awpcpsubmissionresultmessage =''; // $message=''; // $awpcpsubmissionresultmessage =ad_success_email($adid,$txn_id='',$adkey,$awpcpadpostedmsg,$gateway=''); // $output .= "'; // $output .= $awpcpsubmissionresultmessage; // $output .= "
"; // $output .= awpcp_menu_items(); // if($awpcpshowadsample == 1) // { // $output .= '"; // $awpcpadpostedmsg.=$awaitingapprovalmsg; // $awpcpadpostedmsg.="
"; // } // if(get_awpcp_option('imagesapprove') == 1) // { // $imagesawaitingapprovalmsg=__("If you have uploaded images your images will not show up until an admin has approved them.","AWPCP"); // $awpcpadpostedmsg.=""; // $awpcpadpostedmsg.=$imagesawaitingapprovalmsg; // $awpcpadpostedmsg.="
"; // } // $awpcpshowadsample=1; // $awpcpsubmissionresultmessage =''; // $message=''; // $awpcpsubmissionresultmessage = ad_success_email($adid,$txn_id='',$adkey,$awpcpadpostedmsg,$gateway=''); // $output .= "'; // $output .= $awpcpsubmissionresultmessage; // $output .= "
"; // if($awpcpshowadsample == 1) // { // $output .= "