Overview

Packages

  • Horde
    • Form
    • MIME
      • Viewer
    • Scheduler
  • None
  • Whups
    • UnitTests

Classes

  • Whups_Mime_Viewer_zip
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * The Whups_Mime_Viewer_Zip class renders out the contents of ZIP files
  4:  * in HTML format and allows downloading of extractable files.
  5:  *
  6:  * Copyright 2002-2012 Horde LLC (http://www.horde.org/)
  7:  *
  8:  * See the enclosed file COPYING for license information (GPL). If you
  9:  * did not receive this file, see http://www.horde.org/licenses/gpl.
 10:  *
 11:  * @author  Mike Cochrane <mike@graftonhall.co.nz>
 12:  * @author  Michael Slusarz <slusarz@horde.org>
 13:  * @author  Jan Schneider <jan@horde.org>
 14:  * @package Horde_MIME_Viewer
 15:  */
 16: class Whups_Mime_Viewer_zip extends Horde_Mime_Viewer_Zip
 17: {
 18:     /**
 19:      * Return the full rendered version of the Horde_Mime_Part object.
 20:      *
 21:      * URL parameters used by this function:
 22:      * <pre>
 23:      * 'zip_attachment' - (integer) The ZIP attachment to download.
 24:      * </pre>
 25:      *
 26:      * @return array  See parent::render().
 27:      */
 28:     protected function _render()
 29:     {
 30:         if (!($zip_atc = Horde_Util::getFormData('zip_attachment'))) {
 31:             $this->_callback = array($this, '_whupsCallback');
 32:             return parent::_render();
 33:         }
 34: 
 35:         /* Send the requested file. Its position in the zip archive is located
 36:          * in 'zip_attachment'. */
 37:         $data = $this->_mimepart->getContents();
 38: 
 39:         if (!($zip = $this->getConfigParam('zip'))) {
 40:             $zip = Horde_Compress::factory('zip');
 41:             $this->setConfigParam('zip', $zip);
 42:         }
 43: 
 44:         $fileKey = $zip_atc - 1;
 45:         $zipInfo = $zip->decompress($data, array(
 46:             'action' => Horde_Compress_Zip::ZIP_LIST
 47:         ));
 48: 
 49:         /* Verify that the requested file exists. */
 50:         if (isset($zipInfo[$fileKey])) {
 51:             $text = $zip->decompress($data, array(
 52:                 'action' => Horde_Compress_Zip::ZIP_DATA,
 53:                 'info' => &$zipInfo,
 54:                 'key' => $fileKey
 55:             ));
 56:             if (!empty($text)) {
 57:                 return array(
 58:                     $this->_mimepart->getMimeId() => array(
 59:                         'data' => $text,
 60:                         'name' => basename($zipInfo[$fileKey]['name']),
 61:                         'status' => array(),
 62:                         'type' => 'application/octet-stream'
 63:                     )
 64:                 );
 65:             }
 66:         }
 67: 
 68:         // TODO: Error reporting
 69:         return array();
 70:     }
 71: 
 72:     /**
 73:      * Return the rendered inline version of the Horde_Mime_Part object.
 74:      *
 75:      * @return array  See parent::render().
 76:      */
 77:     protected function _renderInfo()
 78:     {
 79:         $this->_callback = array($this, '_whupsCallback');
 80:         return parent::_renderInfo();
 81:     }
 82: 
 83:     /**
 84:      * The function to use as a callback to _toHTML().
 85:      *
 86:      * @param integer $key  The position of the file in the zip archive.
 87:      * @param array $val    The information array for the archived file.
 88:      *
 89:      * @return string  The content-type of the output.
 90:      */
 91:     protected function _whupsCallback($key, $val)
 92:     {
 93:         $name = preg_replace('/(&nbsp;)+$/', '', $val['name']);
 94: 
 95:         if (!empty($val['size']) && (strstr($val['attr'], 'D') === false) &&
 96:             ((($val['method'] == 0x8) && Horde_Util::extensionExists('zlib')) ||
 97:              ($val['method'] == 0x0))) {
 98:             $mime_part = $this->_mimepart;
 99:             $mime_part->setName(basename($name));
100:             $val['name'] = str_replace($name, Horde::url('view.php')->add(array('actionID' => 'view_file', 'type' => Horde_Util::getFormData('type'), 'file' => Horde_Util::getFormData('file'), 'ticket' => Horde_Util::getFormData('ticket'), 'zip_attachment' => $key + 1))->link() . $name . '</a>', $val['name']);
101:         }
102: 
103:         return $val;
104:     }
105: 
106: }
107: 
API documentation generated by ApiGen