1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16:
17: class Horde_Mime_Viewer_Tgz extends Horde_Mime_Viewer_Base
18: {
19: 20: 21: 22: 23:
24: protected $_capability = array(
25: 'full' => false,
26: 'info' => true,
27: 'inline' => false,
28: 'raw' => false
29: );
30:
31: 32: 33: 34: 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: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 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: 63: 64: 65: 66:
67: protected function _renderInfo()
68: {
69:
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:
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:
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: