/**
  * Download all key files for the head revision of an item.
  */
 public function itemAction()
 {
     $itemId = $this->getParam('itemId');
     if (!isset($itemId)) {
         throw new Exception('Must pass an itemId parameter');
     }
     $item = $this->Item->load($itemId);
     if (!$item) {
         throw new Zend_Exception('Invalid itemId', 404);
     }
     if (!$this->Item->policyCheck($item, $this->userSession->Dao)) {
         throw new Zend_Exception('Read permission required', 403);
     }
     $revision = $this->Item->getLastRevision($item);
     if (!$revision) {
         throw new Zend_Exception('Item must have at least one revision', 404);
     }
     $this->disableView();
     $this->disableLayout();
     if (headers_sent()) {
         return;
     }
     $this->_emptyOutputBuffer();
     ob_start();
     //must start a new buffer for ZipStream to work
     $zip = new \ZipStream\ZipStream($item->getName() . '.zip');
     $bitstreams = $revision->getBitstreams();
     foreach ($bitstreams as $bitstream) {
         $zip->addFile($bitstream->getName() . '.md5', $bitstream->getChecksum());
     }
     $zip->finish();
     exit;
 }
Exemple #2
0
/**
 * send_zip
 *
 * takes array of full paths to medias
 * zips them and sends them
 *
 * @param    string    $name    name of the zip file to be created
 * @param    array    $media_files    array of full paths to medias to zip create w/ call to get_media_files
 */
function send_zip($name, $media_files)
{
    /* Require needed library */
    require_once AmpConfig::get('prefix') . '/modules/ZipStream/ZipStream.php';
    $arc = new ZipStream\ZipStream($name . ".zip");
    $options = array('comment' => AmpConfig::get('file_zip_comment'));
    foreach ($media_files as $dir => $files) {
        foreach ($files as $file) {
            $arc->addFileFromPath($dir . "/" . basename($file), $file, $options);
        }
    }
    $arc->finish();
}
 /** Download remote script action. */
 public function downloadAction()
 {
     while (ob_get_level() > 0) {
         ob_end_clean();
     }
     $this->requireAdminPrivileges();
     $this->disableLayout();
     $this->disableView();
     ob_start();
     $zip = new \ZipStream\ZipStream('RemoteScript.zip');
     $file = BASE_PATH . '/modules/remoteprocessing/remotescript/main.py';
     $zip->addFileFromPath(basename($file), $file);
     $file = BASE_PATH . '/modules/remoteprocessing/remotescript/config.cfg';
     $zip->addFileFromPath(basename($file), $file);
     $dirname = BASE_PATH . '/modules/remoteprocessing/remotescript/pydas/';
     $dir = opendir($dirname);
     while ($file = readdir($dir)) {
         if ($file != '.' && $file != '..' && !is_dir($dirname . $file)) {
             $zip->addFileFromPath('pydas/' . basename($dirname . $file), $dirname . $file);
         }
     }
     $zip->finish();
     exit;
 }
 /**
  * will download a zip file with the same name as the item name,
  * if the item exists, then will exit.
  *
  * @param type $item
  */
 private function _downloadEmptyItem($item)
 {
     ob_start();
     $this->disableView();
     if (isset($item) && $item instanceof ItemDao) {
         $name = $item->getName();
     } else {
         $name = 'No_item_selected';
     }
     $name = substr($name, 0, 50);
     if (headers_sent()) {
         echo $name;
         // this is used in testing mode since we cannot send headers from ZipStream
         return;
     }
     $zip = new \ZipStream\ZipStream($name . '.zip');
     $zip->finish();
     exit;
 }
        if (preg_match("/^https?:\\/\\/(img[0-9]+\\.)?imageshack\\.us\\/([a-z]\\/)?img([0-9]+)/", $image->getAttribute("src"))) {
            // Only the images using the old Imageshack URLs are retrieved
            // Creation of a new zipstream object if it hasnt been created yet
            if (!isset($zip)) {
                $zip = new ZipStream\ZipStream("imageShackRetriever_" . time() . ".zip");
            }
            // Modification of the image URL from the olf format to the new one
            $imgUrl = preg_replace("/^https?:\\/\\/(img[0-9]+\\.)?imageshack\\.us\\/([a-z]\\/)?img([0-9]+)\\/[0-9]+\\/(.+)\$/", 'http://imageshack.com/download/\\3/\\4', $image->getAttribute("src"));
            // Replacement of all special characters on the filename by an underscore
            $fileName = preg_replace("/[^a-z0-9\\._-]/", "_", strtolower(basename($imgUrl)));
            // If $prefixImageIndex is True, the image filename will have its position in the source page as a prefix
            if ($prefixImageIndex) {
                $fileName = $i . "-" . $fileName;
            }
            // Retrieval of the image
            $img = file_get_contents($imgUrl);
            // Adding the image to the Zip file
            $zip->addFile($fileName, $img);
            unset($img);
            $i++;
        }
    }
    if ($i == 1) {
        //
        echo "<span style='color: red;'>No Imageshack images have been found on the page.</span>";
    } elseif (isset($zip)) {
        // At least one image was found and zipped, once $zip-finish() is executed the script ends
        $zip->finish();
    }
}
echo "\n</body>\n</html>";
Exemple #6
0
/**
 * send_zip
 *
 * takes array of full paths to medias
 * zips them and sends them
 *
 * @param    string    $name    name of the zip file to be created
 * @param    array    $media_files    array of full paths to medias to zip create w/ call to get_media_files
 */
function send_zip($name, $media_files)
{
    /* Require needed library */
    if (!@(include_once AmpConfig::get('prefix') . '/lib/vendor/maennchen/zipstream-php/src/ZipStream.php')) {
        throw new Exception('Missing ZipStream dependency.');
    }
    $arc = new ZipStream\ZipStream($name . ".zip");
    $options = array('comment' => AmpConfig::get('file_zip_comment'));
    foreach ($media_files as $dir => $files) {
        foreach ($files as $file) {
            $arc->addFileFromPath($dir . "/" . basename($file), $file, $options);
        }
    }
    $arc->finish();
}