1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
<?php
/**
* The MIME_Viewer_tgz class renders out plain or gzipped tarballs in HTML.
*
* $Horde: framework/MIME/MIME/Viewer/tgz.php,v 1.37.10.13 2006/01/26 10:22:46 jan Exp $
*
* Copyright 1999-2006 Anil Madhavapeddy <anil@recoil.org>
* Copyright 2002-2006 Michael Cochrane <mike@graftonhall.co.nz>
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
* @author Anil Madhavapeddy <anil@recoil.org>
* @author Michael Cochrane <mike@graftonhall.co.nz>
* @since Horde 1.3
* @package Horde_MIME_Viewer
*/
class MIME_Viewer_tgz extends MIME_Viewer {
/**
* Render out the currently set tar file contents.
*
* @param array $params Any parameters the Viewer may need.
*
* @return string The rendered contents.
*/
function render($params = array())
{
require_once 'Horde/Compress.php';
$contents = $this->mime_part->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')) {
$gzip = &Horde_Compress::singleton('gzip');
$contents = $gzip->decompress($contents);
if (empty($contents)) {
return '<pre>' . _("Unable to open compressed archive.") . '</pre>';
} elseif (is_a($contents, 'PEAR_Error')) {
return '<pre>' . $contents->getMessage() . '</pre>';
}
}
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 '<pre>' . _("Content type of compressed file: ") . $mime_type . '</pre>';
}
/* Obtain the list of files/data in the tar file. */
$tar = &Horde_Compress::singleton('tar');
$tarData = $tar->decompress($contents);
if (is_a($tarData, 'PEAR_Error')) {
return '<pre>' . $tarData->getMessage() . '</pre>';
}
$fileCount = count($tarData);
include_once 'Horde/Text.php';
$text = '<strong>' . htmlspecialchars(sprintf(_("Contents of \"%s\""), $this->mime_part->getName())) . ':</strong>' . "\n";
$text .= '<table><tr><td align="left"><tt><span class="fixed">';
$text .= Text::htmlAllSpaces(_("Archive Name") . ': ' . $this->mime_part->getName()) . "\n";
$text .= Text::htmlAllSpaces(_("Archive File Size") . ': ' . strlen($contents) . ' bytes') . "\n";
$text .= Text::htmlAllSpaces(($fileCount != 1) ? sprintf(_("File Count: %s files"), $fileCount) : sprintf(_("File Count: %s file"), $fileCount));
$text .= "\n\n";
$text .= 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(_("Modified Date"), 19, ' ', STR_PAD_LEFT)
) . "\n";
$text .= 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";
}
$text .= str_repeat('-', 106) . "\n";
$text .= '</span></tt></td></tr></table>';
return nl2br($text);
}
/**
* Return the content-type
*
* @return string The content-type of the output.
*/
function getType()
{
return 'text/html; charset=' . NLS::getCharset();
}
}
|