From: Michael M Slusarz Date: Wed, 12 Nov 2008 05:38:35 +0000 (-0700) Subject: Update tgz Viewer. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=00df8d7a64347f4cf50e8d7abb11a1dd7c04ec6f;p=horde.git Update tgz Viewer. --- diff --git a/framework/Mime/lib/Horde/Mime/Viewer/tgz.php b/framework/Mime/lib/Horde/Mime/Viewer/tgz.php index a49595b3c..3fc6c9480 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/tgz.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/tgz.php @@ -1,8 +1,4 @@ false, + 'full' => true, + 'info' => false, + 'inline' => true + ); + + /** + * The list of compressed subtypes. + * + * @var array + */ + protected $_gzipSubtypes = array( + 'x-compressed-tar', 'tgz', 'x-tgz', 'gzip', 'x-gzip', + 'x-gzip-compressed', 'x-gtar' + ); + + /** + * Return the full rendered version of the Horde_Mime_Part object. * - * @param array $params Any parameters the Viewer may need. + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _render() + { + $ret = $this->_renderInline(); + if (!empty($ret)) { + $ret['data'] = '' . $ret['data'] . ''; + } + return $ret; + } + + /** + * Return the rendered inline version of the Horde_Mime_Part object. * - * @return string The rendered contents. + * @return array See Horde_Mime_Viewer_Driver::render(). */ - public function render($params = array()) + protected function _renderInline() { - $contents = $this->mime_part->getContents(); + $contents = $this->_mimepart->getContents(); /* Only decompress gzipped files. */ - $subtype = $this->mime_part->getSubType(); - if (($subtype == 'x-compressed-tar') || - ($subtype == 'tgz') || - ($subtype == 'x-tgz') || - ($subtype == 'gzip') || - ($subtype == 'x-gzip') || - ($subtype == 'x-gzip-compressed') || - ($subtype == 'x-gtar')) { + $subtype = $this->_mimepart->getSubType(); + if (in_array($subtype, $this->_gzipSubtypes)) { $gzip = &Horde_Compress::singleton('gzip'); $contents = $gzip->decompress($contents); - if (empty($contents)) { - return _("Unable to open compressed archive."); - } elseif (is_a($contents, 'PEAR_Error')) { - return $contents->getMessage(); + if (is_a($contents, 'PEAR_Error') || + empty($contents)) { + return array(); } } - if ($subtype == 'gzip' || - $subtype == 'x-gzip' || - $subtype == 'x-gzip-compressed') { - global $conf; - require_once 'Horde/MIME/Magic.php'; - $mime_type = MIME_Magic::analyzeData($contents, isset($conf['mime']['magic_db']) ? $conf['mime']['magic_db'] : null); - if (!$mime_type) { - $mime_type = _("Unknown"); - } - return sprintf(_("Content type of compressed file: %s"), $mime_type); - } - /* Obtain the list of files/data in the tar file. */ - $tar = Horde_Compress::factory('tar'); + $tar = &Horde_Compress::singleton('tar'); $tarData = $tar->decompress($contents); if (is_a($tarData, 'PEAR_Error')) { - return $tarData->getMessage(); + return array(); } - $fileCount = count($tarData); - $text = '' . htmlspecialchars(sprintf(_("Contents of \"%s\""), $this->mime_part->getName())) . ':' . "\n" . + + require_once 'Horde/Text.php'; + + $text = '' . htmlspecialchars(sprintf(_("Contents of \"%s\""), $this->_mimepart->getName(true))) . ':' . "\n" . '
' . - Text::htmlAllSpaces(_("Archive Name") . ': ' . $this->mime_part->getName()) . "\n" . + Text::htmlAllSpaces(_("Archive Name") . ': ' . $this->_mimepart->getName(true)) . "\n" . Text::htmlAllSpaces(_("Archive File Size") . ': ' . strlen($contents) . ' bytes') . "\n" . Text::htmlAllSpaces(sprintf(ngettext("File Count: %d file", "File Count: %d files", $fileCount), $fileCount)) . "\n\n" . Text::htmlAllSpaces( - str_pad(_("File Name"), 62, ' ', STR_PAD_RIGHT) . - str_pad(_("Attributes"), 15, ' ', STR_PAD_LEFT) . - str_pad(_("Size"), 10, ' ', STR_PAD_LEFT) . + str_pad(_("File Name"), 62, ' ', STR_PAD_RIGHT) . + str_pad(_("Attributes"), 15, ' ', STR_PAD_LEFT) . + str_pad(_("Size"), 10, ' ', STR_PAD_LEFT) . str_pad(_("Modified Date"), 19, ' ', STR_PAD_LEFT) ) . "\n" . str_repeat('-', 106) . "\n"; foreach ($tarData as $val) { $text .= Text::htmlAllSpaces( - str_pad($val['name'], 62, ' ', STR_PAD_RIGHT) . - str_pad($val['attr'], 15, ' ', STR_PAD_LEFT) . - str_pad($val['size'], 10, ' ', STR_PAD_LEFT) . - str_pad(strftime("%d-%b-%Y %H:%M", $val['date']), 19, ' ', STR_PAD_LEFT) - ) . "\n"; + str_pad($val['name'], 62, ' ', STR_PAD_RIGHT) . + str_pad($val['attr'], 15, ' ', STR_PAD_LEFT) . + str_pad($val['size'], 10, ' ', STR_PAD_LEFT) . + str_pad(strftime("%d-%b-%Y %H:%M", $val['date']), 19, ' ', STR_PAD_LEFT) + ) . "\n"; } - return nl2br($text . str_repeat('-', 106) . "\n" . - '
'); - } - - /** - * Return the content-type - * - * @return string The content-type of the output. - */ - public function getType() - { - return 'text/html; charset=' . NLS::getCharset(); + return array( + 'data' => nl2br($text . str_repeat('-', 106) . "\n" . ''), + 'type' => 'text/html; charset=' . NLS::getCharset() + ); } }