/wordpress/wp-content/plugins/nextgen-public-uploader/inc/class.npu_uploader.php
PHP | 187 lines | 159 code | 4 blank | 24 comment | 34 complexity | 7f68ddd5ef18681d6d9d57983f2ff47e MD5 | raw file
Possible License(s): Apache-2.0, AGPL-1.0, GPL-2.0, GPL-3.0, LGPL-2.1
- <?php
- // Get NextGEN Gallery Functions
- require_once (NGGALLERY_ABSPATH."/admin/functions.php");
- class UploaderNggAdmin extends nggAdmin
- {
- // Public Variables
- public $arrImageIds = false;
- public $strGalleryPath = false;
- public $arrImageNames = false;
- public $strFileName = false;
- public $blnRedirectPage = false;
- public $arrThumbReturn = false;
- public $arrEXIF = false;
- public $arrErrorMsg = array();
- public $arrErrorMsg_widg = array();
- function upload_images() {
- global $wpdb;
- // Image Array
- $imageslist = array();
- // Get Gallery ID
- $galleryID = (int) $_POST['galleryselect'];
- if ($galleryID == 0) {
- if(get_option('npu_default_gallery')) {
- $galleryID = get_option('npu_default_gallery');
- } else {
- nggGallery::show_error(__('No gallery selected.','nggallery'));
- return;
- }
- }
- // Get Gallery Path
- $gallerypath = $wpdb->get_var("SELECT path FROM $wpdb->nggallery WHERE gid = '$galleryID' ");
- if (!$gallerypath){
- nggGallery::show_error(__('Failure in database, no gallery path set.','nggallery'));
- return;
- }
- // Read Image List
- $dirlist = $this->scandir(WINABSPATH.$gallerypath);
- foreach ($_FILES as $key => $value) {
- if ($_FILES[$key]['error'] == 0) {
- $temp_file = $_FILES[$key]['tmp_name'];
- $filepart = pathinfo ( strtolower($_FILES[$key]['name']) );
- // Required Until PHP 5.2.0
- $filepart['filename'] = substr($filepart["basename"],0 ,strlen($filepart["basename"]) - (strlen($filepart["extension"]) + 1) );
- $filename = sanitize_title($filepart['filename']) . '.' . $filepart['extension'];
- // Allowed Extensions
- $ext = array('jpeg', 'jpg', 'png', 'gif');
- if ( !in_array($filepart['extension'], $ext) || !@getimagesize($temp_file) ){
- nggGallery::show_error('<strong>'.$_FILES[$key]['name'].' </strong>'.__('is not a valid file.','nggallery'));
- continue;
- }
- // Check If File Exists
- $i = 0;
- while (in_array($filename,$dirlist)) {
- $filename = sanitize_title($filepart['filename']) . '_' . $i++ . '.' .$filepart['extension'];
- }
- $dest_file = WINABSPATH . $gallerypath . '/' . $filename;
- // Check Folder Permissions
- if (!is_writeable(WINABSPATH.$gallerypath)) {
- $message = sprintf(__('Unable to write to directory %s. Is this directory writable by the server?', 'nggallery'), WINABSPATH.$gallerypath);
- nggGallery::show_error($message);
- return;
- }
- // Save Temporary File
- if (!@move_uploaded_file($_FILES[$key]['tmp_name'], $dest_file)){
- nggGallery::show_error(__('Error, the file could not moved to : ','nggallery').$dest_file);
- $this->check_safemode(WINABSPATH.$gallerypath);
- continue;
- }
- if (!$this->chmod ($dest_file)) {
- nggGallery::show_error(__('Error, the file permissions could not set.','nggallery'));
- continue;
- }
- // Add to Image and Dir List
- $imageslist[] = $filename;
- $dirlist[] = $filename;
- }
- }
- if (count($imageslist) > 0) {
- if (get_option('npu_exclude_select') == "Disabled") {
- $npu_exclude_id = 0;
- } else {
- $npu_exclude_id = 1;
- }
- // Add Images to Database
- $image_ids = $this->add_Images($galleryID, $imageslist);
- $this->arrThumbReturn = array();
- foreach ($image_ids as $pid) {
- $wpdb->query("UPDATE $wpdb->nggpictures SET exclude = '$npu_exclude_id' WHERE pid = '$pid'");
- $this->arrThumbReturn[] = $this->create_thumbnail($pid);
- }
- $this->arrImageIds = array();
- $this->arrImageIds = $image_ids;
- $this->arrImageNames =array();
- $this->arrImageNames = $imageslist;
- $this->strGalleryPath = $gallerypath;
- }
- return;
- } // End Function
-
- function upload_images_widget() {
- global $wpdb;
- // Image Array
- $imageslist = array();
- // Get Gallery ID
- $galleryID = (int) $_POST['galleryselect'];
- if ($galleryID == 0) {
- if(get_option('npu_default_gallery')) {
- $galleryID = get_option('npu_default_gallery');
- } else {
- nggGallery::show_error(__('No gallery selected.','nggallery'));
- return;
- }
- }
- // Get Gallery Path
- $gallerypath = $wpdb->get_var("SELECT path FROM $wpdb->nggallery WHERE gid = '$galleryID' ");
- if (!$gallerypath){
- nggGallery::show_error(__('Failure in database, no gallery path set.','nggallery'));
- return;
- }
- // Read Image List
- $dirlist = $this->scandir(WINABSPATH.$gallerypath);
- foreach ($_FILES as $key => $value) {
- if ($_FILES[$key]['error'] == 0) {
- $temp_file = $_FILES[$key]['tmp_name'];
- $filepart = pathinfo ( strtolower($_FILES[$key]['name']) );
- // Required Until PHP 5.2.0
- $filepart['filename'] = substr($filepart["basename"],0 ,strlen($filepart["basename"]) - (strlen($filepart["extension"]) + 1) );
- $filename = sanitize_title($filepart['filename']) . '.' . $filepart['extension'];
- // Allowed Extensions
- $ext = array('jpeg', 'jpg', 'png', 'gif');
- if ( !in_array($filepart['extension'], $ext) || !@getimagesize($temp_file) ){
- nggGallery::show_error('<strong>'.$_FILES[$key]['name'].' </strong>'.__('is not a valid file.','nggallery'));
- continue;
- }
- // Check If File Exists
- $i = 0;
- while (in_array($filename,$dirlist)) {
- $filename = sanitize_title($filepart['filename']) . '_' . $i++ . '.' .$filepart['extension'];
- }
- $dest_file = WINABSPATH . $gallerypath . '/' . $filename;
- // Check Folder Permissions
- if (!is_writeable(WINABSPATH.$gallerypath)) {
- $message = sprintf(__('Unable to write to directory %s. Is this directory writable by the server?', 'nggallery'), WINABSPATH.$gallerypath);
- nggGallery::show_error($message);
- return;
- }
- // Save Temporary File
- if (!@move_uploaded_file($_FILES[$key]['tmp_name'], $dest_file)){
- nggGallery::show_error(__('Error, the file could not moved to : ','nggallery').$dest_file);
- $this->check_safemode(WINABSPATH.$gallerypath);
- continue;
- }
- if (!$this->chmod ($dest_file)) {
- nggGallery::show_error(__('Error, the file permissions could not set.','nggallery'));
- continue;
- }
- // Add to Image and Dir List
- $imageslist[] = $filename;
- $dirlist[] = $filename;
- }
- }
- if (count($imageslist) > 0) {
- if (get_option('npu_exclude_select') == "Disabled") {
- $npu_exclude_id = 0;
- } else {
- $npu_exclude_id = 1;
- }
- // Add Images to Database
- $image_ids = $this->add_Images($galleryID, $imageslist);
- $this->arrThumbReturn = array();
- foreach ($image_ids as $pid) {
- $wpdb->query("UPDATE $wpdb->nggpictures SET exclude = '$npu_exclude_id' WHERE pid = '$pid'");
- $this->arrThumbReturn[] = $this->create_thumbnail($pid);
- }
- $this->arrImageIds = array();
- $this->arrImageIds = $image_ids;
- $this->arrImageNames =array();
- $this->arrImageNames = $imageslist;
- $this->strGalleryPath = $gallerypath;
- }
- return;
- } // End Function
- }
- ?>