Exemplo n.º 1
0
 /**
  *  Compress file as zip using pclzip library (thanhnv - use other lib now :D)
  *
  * @param $zipFile  string path to store zip file
  * @param $path {string | array()} path to file or directory to zip
  * @param $rmPath  boolean do not add full path to archive
  *
  * @return  boolean true if success, false if failure
  */
 function zip($zipFile, $path, $rmPath = false)
 {
     $oZip = new CreateZipFile();
     if (!is_array($path)) {
         $paths[] = $path;
     } else {
         $paths = $path;
     }
     foreach ($paths as $path) {
         if (JFile::exists($path)) {
             $oZip->addDirectory($outputDir);
             $fileContents = file_get_contents($path);
             $oZip->addFile($fileContents, basename($path));
         } elseif (JFolder::exists($path)) {
             $outputDir = str_replace(array(dirname($path), DS, '/'), '', $path) . DS;
             $oZip->zipDirectory($path, $outputDir);
         }
     }
     $out = JFile::write($zipFile, $oZip->getZippedfile());
     return $out;
 }
Exemplo n.º 2
0
 /**
  *  Compress file as zip using pclzip library (thanhnv - use other lib now :D)
  *
  * @param $zipFile  string path to store zip file
  * @param $path {string | array()} path to file or directory to zip
  * @param $rmPath  boolean do not add full path to archive
  *
  * @return  boolean true if success, false if failure
  */
 public static function zip($zipFile, $path, $rmPath = false)
 {
     $oZip = new CreateZipFile();
     if (!is_array($path)) {
         $paths[] = $path;
     } else {
         $paths = $path;
     }
     foreach ($paths as $path) {
         if (is_file($path)) {
             $oZip->addDirectory($outputDir);
             $fileContents = file_get_contents($path);
             $oZip->addFile($fileContents, basename($path));
         } elseif (is_dir($path)) {
             $outputDir = str_replace(array(dirname($path), DS, '/'), '', $path) . DS;
             $oZip->zipDirectory($path, $outputDir);
         }
     }
     $fp = fopen($zipFile, "wb");
     $out = fwrite($fp, $oZip->getZippedfile());
     fclose($fp);
     return $out;
 }
 function export_xliff()
 {
     global $wpdb, $current_user;
     get_currentuserinfo();
     $data = $_GET['xliff_export_data'];
     $data = unserialize(base64_decode($data));
     //by default set xliff version to 1.2
     $xliff_version = '1.2';
     //check for required xliff version from action name
     if (isset($data['action2'])) {
         $xliff_action = $data['action2'];
         //we are looking for action in format: export_xliff_VERSION
         if (strpos($xliff_action, 'export_xliff_') === 0) {
             switch (ltrim($xliff_action, 'export_xliff_')) {
                 case '10':
                     $xliff_version = '1.0';
                     break;
                 case '11':
                     $xliff_version = '1.1';
                     break;
                 case '12':
                     $xliff_version = '1.2';
                     break;
             }
         }
     }
     require_once WPML_XLIFF_PATH . '/inc/CreateZipFile.inc.php';
     $archive = new CreateZipFile();
     $job_ids = array();
     foreach ($data['job'] as $job_id => $dummy) {
         $xliff_file = $this->get_xliff_file($job_id, $xliff_version);
         // assign the job to this translator
         $rid = $wpdb->get_var("SELECT rid FROM {$wpdb->prefix}icl_translate_job WHERE job_id={$job_id}");
         $wpdb->update($wpdb->prefix . 'icl_translate_job', array('translator_id' => $current_user->ID), array('job_id' => $job_id));
         $wpdb->update($wpdb->prefix . 'icl_translation_status', array('translator_id' => $current_user->ID), array('rid' => $rid));
         $archive->addFile($xliff_file, get_bloginfo('name') . '-translation-job-' . $job_id . '.xliff');
         $job_ids[] = $job_id;
     }
     $archive_data = $archive->getZippedfile();
     header("Content-Type: application/force-download");
     header("Content-Type: application/octet-stream");
     header("Content-Type: application/download");
     header("Content-Disposition: attachment; filename=" . $this->_get_zip_name_from_jobs($job_ids));
     //header("Content-Encoding: gzip");
     header("Content-Length: " . strlen($archive_data));
     echo $archive_data;
     exit;
 }
 function download_zip()
 {
     require "create_zip_file.php";
     $files_to_zip = array();
     // create files array
     //run a query
     $post_id = $_POST["Id"];
     $args = array('post_type' => $this->post_types_attachments, 'post_parent' => $post_id);
     $attachments = get_posts($args);
     if ($attachments) {
         //print_r($attachments);
         foreach ($attachments as $attachment) {
             $files_to_zip[] = get_attached_file($attachment->ID);
             // populate files array
         }
         //print_r($files_to_zip);
         //exit;
         $zip = new CreateZipFile();
         $uploads = wp_upload_dir();
         $tmp_location = $uploads['path'];
         $tmp_location_url = $uploads['url'];
         $FileName = sanitize_title(get_the_title($post_id)) . ".zip";
         $zipFileName = $tmp_location . '/' . $FileName;
         //$zipFileName_url = $tmp_location_url.'/'.sanitize_title(get_the_title($post_id)).".zip";
         //$zip->addDirectory('/');
         foreach ($files_to_zip as $file) {
             //$filecontent =
             $zip->addFile(file_get_contents($file), basename($file));
         }
         $handle = fopen($zipFileName, 'wb');
         $out = fwrite($handle, $zip->getZippedFile());
         fclose($handle);
         //$zip->forceDownload($zipFileName);
         //@unlink($zipFileName);
         echo plugins_url($file_path, __FILE__) . "/download.php?File=" . $FileName;
     } else {
         echo 'false';
     }
     exit;
 }