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>";
Ejemplo n.º 2
0
 /**
  * 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;
 }