Exemple #1
0
 /**
  * Import a ZIP file via a upload form or a URL
  * 
  * @class nggAdmin
  * @param int (optional) $galleryID
  * @return bool $result
  */
 function import_zipfile($galleryID)
 {
     global $ngg, $wpdb;
     if (nggWPMU::check_quota()) {
         return false;
     }
     $defaultpath = $ngg->options['gallerypath'];
     $zipurl = $_POST['zipurl'];
     // if someone entered a URL try to upload it
     if (!empty($zipurl) && function_exists('curl_init')) {
         if (!preg_match('/^http(s)?:\\/\\//i', $zipurl)) {
             nggGallery::show_error(__('No valid URL path ', 'nggallery'));
             return false;
         }
         $temp_zipfile = tempnam('/tmp', 'zipimport_');
         $filename = basename($zipurl);
         //Grab the zip via cURL
         $save = fopen($temp_zipfile, "w");
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_FILE, $save);
         curl_setopt($ch, CURLOPT_HEADER, 0);
         curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
         curl_setopt($ch, CURLOPT_URL, $zipurl);
         $success = curl_exec($ch);
         if (!$success) {
             nggGallery::show_error(__('Import via cURL failed.', 'nggallery') . ' Error code ' . curl_errno($ch) . ' : ' . curl_error($ch));
         }
         curl_close($ch);
         fclose($save);
         if (!$success) {
             return false;
         }
     } else {
         $temp_zipfile = $_FILES['zipfile']['tmp_name'];
         $filename = $_FILES['zipfile']['name'];
         // Chrome return a empty content-type : http://code.google.com/p/chromium/issues/detail?id=6800
         if (!preg_match('/chrome/i', $_SERVER['HTTP_USER_AGENT'])) {
             // check if file is a zip file
             if (!preg_match('/(zip|download|octet-stream)/i', $_FILES['zipfile']['type'])) {
                 @unlink($temp_zipfile);
                 // del temp file
                 nggGallery::show_error(__('Uploaded file was no or a faulty zip file ! The server recognized : ', 'nggallery') . $_FILES['zipfile']['type']);
                 return false;
             }
         }
     }
     // should this unpacked into a new folder ?
     if ($galleryID == '0') {
         //cleanup and take the zipfile name as folder name
         $foldername = sanitize_title(strtok($filename, '.'));
         $foldername = $defaultpath . $foldername;
     } else {
         // get foldername if selected
         $foldername = $wpdb->get_var("SELECT path FROM {$wpdb->nggallery} WHERE gid = '{$galleryID}' ");
     }
     if (empty($foldername)) {
         nggGallery::show_error(__('Could not get a valid foldername', 'nggallery'));
         return false;
     }
     // set complete folder path
     $newfolder = WINABSPATH . $foldername;
     // check first if the traget folder exist
     if (!is_dir($newfolder)) {
         // create new directories
         if (!wp_mkdir_p($newfolder)) {
             $message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?', 'nggallery'), $newfolder);
             nggGallery::show_error($message);
             return false;
         }
         if (!wp_mkdir_p($newfolder . '/thumbs')) {
             nggGallery::show_error(__('Unable to create directory ', 'nggallery') . $newfolder . '/thumbs !');
             return false;
         }
     }
     // unzip and del temp file
     $result = nggAdmin::unzip($newfolder, $temp_zipfile);
     @unlink($temp_zipfile);
     if ($result) {
         $message = __('Zip-File successfully unpacked', 'nggallery') . '<br />';
         // parse now the folder and add to database
         $message .= nggAdmin::import_gallery($foldername);
         nggGallery::show_message($message);
     }
     return true;
 }
Exemple #2
0
 function import_zipfile($galleryID)
 {
     global $ngg, $wpdb;
     if (nggAdmin::check_quota()) {
         return false;
     }
     $defaultpath = $ngg->options['gallerypath'];
     $temp_zipfile = $_FILES['zipfile']['tmp_name'];
     $filename = $_FILES['zipfile']['name'];
     // check if file is a zip file
     if (!eregi('zip|download|octet-stream', $_FILES['zipfile']['type'])) {
         @unlink($temp_zipfile);
         // del temp file
         nggGallery::show_error(__('Uploaded file was no or a faulty zip file ! The server recognize : ', 'nggallery') . $_FILES['zipfile']['type']);
         return false;
     }
     // should this unpacked into a new folder ?
     if ($galleryID == '0') {
         //cleanup and take the zipfile name as folder name
         $foldername = sanitize_title(strtok($filename, '.'));
         $foldername = $defaultpath . $foldername;
     } else {
         // get foldername if selected
         $foldername = $wpdb->get_var("SELECT path FROM {$wpdb->nggallery} WHERE gid = '{$galleryID}' ");
     }
     if (empty($foldername)) {
         nggGallery::show_error(__('Could not get a valid foldername', 'nggallery'));
         return false;
     }
     // set complete folder path
     $newfolder = WINABSPATH . $foldername;
     // check first if the traget folder exist
     if (!is_dir($newfolder)) {
         // create new directories
         if (!wp_mkdir_p($newfolder)) {
             $message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?', 'nggallery'), $newfolder);
             nggGallery::show_error($message);
             return false;
         }
         if (!wp_mkdir_p($newfolder . '/thumbs')) {
             nggGallery::show_error(__('Unable to create directory ', 'nggallery') . $newfolder . '/thumbs !');
             return false;
         }
     }
     // unzip and del temp file
     $result = nggAdmin::unzip($newfolder, $temp_zipfile);
     @unlink($temp_zipfile);
     if ($result) {
         $message = __('Zip-File successfully unpacked', 'nggallery') . '<br />';
         // parse now the folder and add to database
         $message .= nggAdmin::import_gallery($foldername);
         nggGallery::show_message($message);
     }
     return true;
 }