/** * 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(); }
/** * 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(); }
/** 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; }
// domDocument is used to easily parse the HTML code to retrieve only <img> tags and extract their "src" value $dom = new domDocument(); // The @ is used to avoid warnings due to non standard HTML code @$dom->loadHTML($html); $dom->preserveWhiteSpace = false; // Retrieval of the <img> tags $images = $dom->getElementsByTagName('img'); unset($dom); $i = 1; foreach ($images as $image) { // Loop on each <img> tags of the page 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++;
/** * Download key files for a selected group of folders and/or items. * @param items List of item id's separated by - * @param folders List of folder id's separated by - */ public function batchAction() { UtilityComponent::disableMemoryLimit(); $itemIds = $this->getParam('items'); $folderIds = $this->getParam('folders'); if (!isset($itemIds) && !isset($folderIds)) { throw new Zend_Exception('No parameters'); } $this->disableLayout(); $this->disableView(); $folderIds = explode('-', $folderIds); $folders = $this->Folder->load($folderIds); $itemIds = explode('-', $itemIds); $items = $this->Item->load($itemIds); if (headers_sent()) { return; // can't do anything if headers sent already } $this->_emptyOutputBuffer(); ob_start(); //must start a new output buffer for ZipStream to work $zip = new \ZipStream\ZipStream('Keyfiles.zip'); // Iterate over top level items foreach ($items as $item) { if (!$this->Item->policyCheck($item, $this->userSession->Dao)) { $this->getLogger()->warn('Keyfiles: Permission failure, skipping item ' . $item->getKey()); continue; } $revision = $this->Item->getLastRevision($item); if (!$revision) { continue; } $bitstreams = $revision->getBitstreams(); $count = count($bitstreams); foreach ($bitstreams as $bitstream) { if ($count > 1 || $bitstream->getName() != $item->getName()) { $path = $item->getName() . '/'; } else { $path = ''; } $filename = $path . $bitstream->getName() . '.md5'; Zend_Registry::get('dbAdapter')->closeConnection(); $zip->addFile($filename, $bitstream->getChecksum()); } $this->Item->incrementDownloadCount($item); unset($item); unset($revision); unset($bitstreams); } // Iterate over top level folders, stream them out recursively using FolderModel::zipStream() foreach ($folders as $folder) { if (!$this->Folder->policyCheck($folder, $this->userSession->Dao)) { $this->getLogger()->warn('Keyfiles: Permission failure, skipping folder ' . $folder->getKey()); continue; } $callable = array($this, 'outputCallback'); $this->Folder->zipStream($zip, $folder->getName(), $folder, $this->userSession->Dao, $callable); } $zip->finish(); exit; }