Overview

Packages

  • Mime
    • Viewer

Classes

  • Horde_Mime_Viewer
  • Horde_Mime_Viewer_Audio
  • Horde_Mime_Viewer_Base
  • Horde_Mime_Viewer_Deb
  • Horde_Mime_Viewer_Default
  • Horde_Mime_Viewer_Enriched
  • Horde_Mime_Viewer_Exception
  • Horde_Mime_Viewer_Html
  • Horde_Mime_Viewer_Images
  • Horde_Mime_Viewer_Msexcel
  • Horde_Mime_Viewer_Mspowerpoint
  • Horde_Mime_Viewer_Msword
  • Horde_Mime_Viewer_Ooo
  • Horde_Mime_Viewer_Pdf
  • Horde_Mime_Viewer_Plain
  • Horde_Mime_Viewer_Rar
  • Horde_Mime_Viewer_Report
  • Horde_Mime_Viewer_Rfc822
  • Horde_Mime_Viewer_Richtext
  • Horde_Mime_Viewer_Rpm
  • Horde_Mime_Viewer_Rtf
  • Horde_Mime_Viewer_Security
  • Horde_Mime_Viewer_Simple
  • Horde_Mime_Viewer_Smil
  • Horde_Mime_Viewer_Syntaxhighlighter
  • Horde_Mime_Viewer_Tgz
  • Horde_Mime_Viewer_Tnef
  • Horde_Mime_Viewer_Translation
  • Horde_Mime_Viewer_Wordperfect
  • Horde_Mime_Viewer_Zip
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * The Horde_Mime_Viewer_Tgz class renders out plain or gzipped tarballs in
  4:  * HTML.
  5:  *
  6:  * Copyright 1999-2012 Horde LLC (http://www.horde.org/)
  7:  *
  8:  * See the enclosed file COPYING for license information (LGPL). If you
  9:  * did not receive this file, see http://www.horde.org/licenses/lgpl21.
 10:  *
 11:  * @author   Anil Madhavapeddy <anil@recoil.org>
 12:  * @author   Michael Cochrane <mike@graftonhall.co.nz>
 13:  * @category Horde
 14:  * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
 15:  * @package  Mime_Viewer
 16:  */
 17: class Horde_Mime_Viewer_Tgz extends Horde_Mime_Viewer_Base
 18: {
 19:     /**
 20:      * This driver's display capabilities.
 21:      *
 22:      * @var array
 23:      */
 24:     protected $_capability = array(
 25:         'full' => false,
 26:         'info' => true,
 27:         'inline' => false,
 28:         'raw' => false
 29:     );
 30: 
 31:     /**
 32:      * The list of compressed subtypes.
 33:      *
 34:      * @var array
 35:      */
 36:     protected $_gzipSubtypes = array(
 37:         'x-compressed-tar', 'tgz', 'x-tgz', 'gzip', 'x-gzip',
 38:         'x-gzip-compressed', 'x-gtar'
 39:     );
 40: 
 41:     /**
 42:      * Constructor.
 43:      *
 44:      * @param Horde_Mime_Part $mime_part  The object with the data to be
 45:      *                                    rendered.
 46:      * @param array $conf                 Configuration:
 47:      * <pre>
 48:      * 'gzip' - (Horde_Compress_Gzip) A gzip object.
 49:      * 'monospace' - (string) A class to use to display monospace text inline.
 50:      *               DEFAULT: Uses style="font-family:monospace"
 51:      * 'tar' - (Horde_Compress_Tar) A tar object.
 52:      * </pre>
 53:      */
 54:     public function __construct(Horde_Mime_Part $part, array $conf = array())
 55:     {
 56:         parent::__construct($part, $conf);
 57: 
 58:         $this->_metadata['compressed'] = in_array($part->getSubType(), $this->_gzipSubtypes);
 59:     }
 60: 
 61:     /**
 62:      * Return the rendered information about the Horde_Mime_Part object.
 63:      *
 64:      * @return array  See parent::render().
 65:      * @throws Horde_Exception
 66:      */
 67:     protected function _renderInfo()
 68:     {
 69:         /* Currently, can't do anything without tar file. */
 70:         $subtype = $this->_mimepart->getSubType();
 71:         if (in_array($subtype, array('gzip', 'x-gzip', 'x-gzip-compressed'))) {
 72:             return array();
 73:         }
 74: 
 75:         $charset = $this->getConfigParam('charset');
 76:         $contents = $this->_mimepart->getContents();
 77: 
 78:         /* Decompress gzipped files. */
 79:         if (in_array($subtype, $this->_gzipSubtypes)) {
 80:             if (!$this->getConfigParam('gzip')) {
 81:                 $this->setConfigParam('gzip', Horde_Compress::factory('Gzip'));
 82:             }
 83:             $contents = $this->getConfigParam('gzip')->decompress($contents);
 84:         }
 85: 
 86:         /* Obtain the list of files/data in the tar file. */
 87:         if (!$this->getConfigParam('tar')) {
 88:             $this->setConfigParam('tar', Horde_Compress::factory('Tar'));
 89:         }
 90:         $tarData = $this->getConfigParam('tar')->decompress($contents);
 91: 
 92:         $fileCount = count($tarData);
 93: 
 94:         $name = $this->_mimepart->getName(true);
 95:         if (empty($name)) {
 96:             $name = Horde_Mime_Viewer_Translation::t("unnamed");
 97:         }
 98: 
 99:         $monospace = $this->getConfigParam('monospace');
100: 
101:         $text = '<table><tr><td align="left"><span ' .
102:             ($monospace ? 'class="' . $monospace . '">' : 'style="font-family:monospace">') .
103:             $this->_textFilter(Horde_Mime_Viewer_Translation::t("Archive Name") . ':  ' . $name, 'Space2html', array(
104:                 'charset' => $charset,
105:                 'encode' => true,
106:                 'encode_all' => true
107:             )) . "\n" .
108:             $this->_textFilter(Horde_Mime_Viewer_Translation::t("Archive File Size") . ': ' . strlen($contents) . ' bytes', 'Space2html', array(
109:                 'charset' => $charset,
110:                 'encode' => true,
111:                 'encode_all' => true
112:             )) . "\n" .
113:             $this->_textFilter(sprintf(Horde_Mime_Viewer_Translation::ngettext("File Count: %d file", "File Count: %d files", $fileCount), $fileCount), 'Space2html', array(
114:                 'charset' => $charset,
115:                 'encode' => true,
116:                 'encode_all' => true
117:             )) .
118:             "\n\n" .
119:             $this->_textFilter(
120:                 str_pad(Horde_Mime_Viewer_Translation::t("File Name"), 62, ' ', STR_PAD_RIGHT) .
121:                 str_pad(Horde_Mime_Viewer_Translation::t("Attributes"), 15, ' ', STR_PAD_LEFT) .
122:                 str_pad(Horde_Mime_Viewer_Translation::t("Size"), 10, ' ', STR_PAD_LEFT) .
123:                 str_pad(Horde_Mime_Viewer_Translation::t("Modified Date"), 19, ' ', STR_PAD_LEFT),
124:                 'Space2html',
125:                 array(
126:                     'charset' => $charset,
127:                     'encode' => true,
128:                     'encode_all' => true
129:                 )
130:             ) . "\n" .
131:             str_repeat('-', 106) . "\n";
132: 
133:         foreach ($tarData as $val) {
134:             $text .= $this->_textFilter(
135:                 str_pad($val['name'], 62, ' ', STR_PAD_RIGHT) .
136:                 str_pad($val['attr'], 15, ' ', STR_PAD_LEFT) .
137:                 str_pad($val['size'], 10, ' ', STR_PAD_LEFT) .
138:                 str_pad(strftime("%d-%b-%Y %H:%M", $val['date']), 19, ' ', STR_PAD_LEFT),
139:                 'Space2html',
140:                 array(
141:                     'charset' => $charset,
142:                     'encode' => true,
143:                     'encode_all' => true
144:                 )
145:             ) . "\n";
146:         }
147: 
148:         return $this->_renderReturn(
149:             nl2br($text . str_repeat('-', 106) . "\n</span></td></tr></table>"),
150:             'text/html; charset=' . $charset
151:         );
152:     }
153: 
154: }
155: 
API documentation generated by ApiGen