/** * Upload function will be called via the Flash uploader * * @class nggAdmin * @param integer $galleryID * @return string $result */ static function swfupload_image($galleryID = 0) { global $nggdb; if ($galleryID == 0) { return __('No gallery selected !', 'nggallery'); } // WPMU action if (nggWPMU::check_quota()) { return '0'; } // Check the upload if (!isset($_FILES['Filedata']) || !is_uploaded_file($_FILES['Filedata']['tmp_name']) || $_FILES['Filedata']['error'] != 0) { return __('Invalid upload. Error Code : ', 'nggallery') . $_FILES['Filedata']['error']; } // get the filename and extension $temp_file = $_FILES['Filedata']['tmp_name']; $filepart = nggGallery::fileinfo($_FILES['Filedata']['name']); $filename = $filepart['basename']; // check for allowed extension $ext = apply_filters('ngg_allowed_file_types', array('jpeg', 'jpg', 'png', 'gif')); if (!in_array(strtolower($filepart['extension']), $ext)) { return esc_html($_FILES[$key]['name']) . __('is no valid image file!', 'nggallery'); } // get the path to the gallery $gallery = $nggdb->find_gallery((int) $galleryID); if (empty($gallery->path)) { @unlink($temp_file); return __('Failure in database, no gallery path set !', 'nggallery'); } // read list of images $imageslist = nggAdmin::scandir(WINABSPATH . $gallery->path); // check if this filename already exist $i = 0; while (in_array($filename, $imageslist)) { $filename = $filepart['filename'] . '_' . $i++ . '.' . $filepart['extension']; } $dest_file = WINABSPATH . $gallery->path . '/' . $filename; // save temp file to gallery if (!@move_uploaded_file($_FILES["Filedata"]['tmp_name'], $dest_file)) { nggAdmin::check_safemode(WINABSPATH . $gallery->path); return __('Error, the file could not be moved to : ', 'nggallery') . esc_html($dest_file); } if (!nggAdmin::chmod($dest_file)) { return __('Error, the file permissions could not be set', 'nggallery'); } return '0'; }
/** * Upload function will be called via the Flash uploader * * @class nggAdmin * @param integer $galleryID * @return string $result */ function swfupload_image($galleryID = 0) { global $wpdb; if ($galleryID == 0) { return __('No gallery selected !', 'nggallery'); } // WPMU action if (nggWPMU::check_quota()) { return '0'; } // Check the upload if (!isset($_FILES['Filedata']) || !is_uploaded_file($_FILES['Filedata']['tmp_name']) || $_FILES['Filedata']['error'] != 0) { return __('Invalid upload. Error Code : ', 'nggallery') . $_FILES['Filedata']['error']; } // get the filename and extension $temp_file = $_FILES['Filedata']['tmp_name']; $filepart = nggGallery::fileinfo($_FILES['Filedata']['name']); $filename = $filepart['basename']; // check for allowed extension $ext = array('jpg', 'png', 'gif'); if (!in_array($filepart['extension'], $ext)) { return $_FILES[$key]['name'] . __('is no valid image file!', 'nggallery'); } // get the path to the gallery $gallerypath = $wpdb->get_var("SELECT path FROM {$wpdb->nggallery} WHERE gid = '{$galleryID}' "); if (!$gallerypath) { @unlink($temp_file); return __('Failure in database, no gallery path set !', 'nggallery'); } // read list of images $imageslist = nggAdmin::scandir(WINABSPATH . $gallerypath); // check if this filename already exist $i = 0; while (in_array($filename, $imageslist)) { $filename = $filepart['filename'] . '_' . $i++ . '.' . $filepart['extension']; } $dest_file = WINABSPATH . $gallerypath . '/' . $filename; // save temp file to gallery if (!@move_uploaded_file($_FILES["Filedata"]['tmp_name'], $dest_file)) { nggAdmin::check_safemode(WINABSPATH . $gallerypath); return __('Error, the file could not be moved to : ', 'nggallery') . $dest_file; } if (!nggAdmin::chmod($dest_file)) { return __('Error, the file permissions could not be set', 'nggallery'); } return '0'; }
/** * Method "ngg.uploadImage" * Uploads a image to a gallery * * @since 1.4 * * @copyright addapted from WP Core * @param array $args Method parameters. * - int blog_id * - string username * - string password * - struct data * o string name * o string type (optional) * o base64 bits * o bool overwrite (optional) * o int gallery * o int image_id (optional) * @return array with image meta data */ function uploadImage($args) { global $wpdb; require_once dirname(dirname(__FILE__)) . '/admin/functions.php'; // admin functions require_once 'meta.php'; // meta data import $blog_ID = (int) $args[0]; $username = $wpdb->escape($args[1]); $password = $wpdb->escape($args[2]); $data = $args[3]; $name = $data['name']; $type = $data['type']; $bits = $data['bits']; // gallery & image id $gid = (int) $data['gallery']; // required field $pid = (int) $data['image_id']; // optional but more foolproof of overwrite $image = false; // container for the image object logIO('O', '(NGG) Received ' . strlen($bits) . ' bytes'); if (!($user = $this->login($username, $password))) { return $this->error; } // Check if you have the correct capability for upload if (!current_user_can('NextGEN Upload images')) { logIO('O', '(NGG) User does not have upload_files capability'); $this->error = new IXR_Error(401, __('You are not allowed to upload files to this site.')); return $this->error; } // Look for the gallery , could we find it ? if (!($gallery = nggdb::find_gallery($gid))) { return new IXR_Error(404, __('Could not find gallery ' . $gid)); } // Now check if you have the correct capability for this gallery if (!nggAdmin::can_manage_this_gallery($gallery->author)) { logIO('O', '(NGG) User does not have upload_files capability'); $this->error = new IXR_Error(401, __('You are not allowed to upload files to this gallery.')); return $this->error; } //clean filename and extract extension $filepart = nggGallery::fileinfo($name); $name = $filepart['basename']; // check for allowed extension and if it's an image file $ext = array('jpg', 'png', 'gif'); if (!in_array($filepart['extension'], $ext)) { logIO('O', '(NGG) Not allowed file type'); $this->error = new IXR_Error(401, __('This is no valid image file.', 'nggallery')); return $this->error; } // in the case you would overwrite the image, let's delete the old one first if (!empty($data["overwrite"]) && $data["overwrite"] == true) { // search for the image based on the filename, if it's not already provided if ($pid == 0) { $pid = $wpdb->get_col(" SELECT pid FROM {$wpdb->nggpictures} WHERE filename = '{$name}' AND galleryid = '{$gid}' "); } if (!($image = nggdb::find_image($pid))) { return new IXR_Error(404, __('Could not find image id ' . $pid)); } // sync the gallery<->image parameter, otherwise we may copy it to the wrong gallery $gallery = $image; // delete now the image if (!@unlink($image->imagePath)) { $errorString = sprintf(__('Failed to delete image %1$s ', 'nggallery'), $image->imagePath); logIO('O', '(NGG) ' . $errorString); return new IXR_Error(500, $errorString); } } // upload routine from wp core, load first the image to the upload folder, $upload['file'] contain the path $upload = wp_upload_bits($name, $type, $bits); if (!empty($upload['error'])) { $errorString = sprintf(__('Could not write file %1$s (%2$s)'), $name, $upload['error']); logIO('O', '(NGG) ' . $errorString); return new IXR_Error(500, $errorString); } // this is the dir to the gallery $path = WINABSPATH . $gallery->path; // check if the filename already exist, if not add a counter index $filename = wp_unique_filename($path, $name); $destination = $path . '/' . $filename; // Move files to gallery folder if (!@rename($upload['file'], $destination)) { $errorString = sprintf(__('Failed to move image %1$s to %2$s', 'nggallery'), '<strong>' . $upload['file'] . '</strong>', $destination); logIO('O', '(NGG) ' . $errorString); return new IXR_Error(500, $errorString); } //add to database if it's a new image if (empty($data["overwrite"]) || $data["overwrite"] == false) { $pid_array = nggAdmin::add_Images($gallery->gid, array($filename)); // the first element is our new image id if (count($pid_array) == 1) { $pid = $pid_array[0]; } } //get all information about the image, in the case it's a new one if (!$image) { $image = nggdb::find_image($pid); } // create again the thumbnail, should return a '1' nggAdmin::create_thumbnail($image); return apply_filters('ngg_upload_image', $image); }