1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16:
17: class Horde_Mime_Viewer_Zip 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 $_metadata = array(
37: 'compressed' => true,
38: 'embedded' => false,
39: 'forceinline' => false
40: );
41:
42: 43: 44: 45: 46:
47: protected $_callback = null;
48:
49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62:
63: public function __construct(Horde_Mime_Part $part, array $conf = array())
64: {
65: parent::__construct($part, $conf);
66: }
67:
68: 69: 70: 71: 72: 73:
74: protected function _renderInfo()
75: {
76: $charset = $this->getConfigParam('charset');
77: $contents = $this->_mimepart->getContents();
78:
79: if (!$this->getConfigParam('zip')) {
80: $this->setConfigParam('zip', Horde_Compress::factory('Zip'));
81: }
82: $zipInfo = $this->getConfigParam('zip')->decompress($contents, array(
83: 'action' => Horde_Compress_Zip::ZIP_LIST
84: ));
85:
86: $fileCount = count($zipInfo);
87:
88: $name = $this->_mimepart->getName(true);
89: if (empty($name)) {
90: $name = Horde_Mime_Viewer_Translation::t("unnamed");
91: }
92:
93: $monospace = $this->getConfigParam('monospace');
94:
95: $text = '<table><tr><td align="left"><span ' .
96: ($monospace ? 'class="' . $monospace . '">' : 'style="font-family:monospace">') .
97: $this->_textFilter(
98: Horde_Mime_Viewer_Translation::t("Archive Name") . ': ' . $name . "\n" .
99: Horde_Mime_Viewer_Translation::t("Archive File Size") . ': ' . strlen($contents) .
100: " bytes\n" .
101: sprintf(Horde_Mime_Viewer_Translation::ngettext("File Count: %d file", "File Count: %d files", $fileCount), $fileCount) .
102: "\n\n" .
103: str_repeat(' ', 15) .
104: Horde_String::pad(Horde_Mime_Viewer_Translation::t("Attributes"), 10, ' ', STR_PAD_LEFT) .
105: Horde_String::pad(Horde_Mime_Viewer_Translation::t("Size"), 10, ' ', STR_PAD_LEFT) .
106: Horde_String::pad(Horde_Mime_Viewer_Translation::t("Modified Date"), 19, ' ', STR_PAD_LEFT) .
107: Horde_String::pad(Horde_Mime_Viewer_Translation::t("Method"), 10, ' ', STR_PAD_LEFT) .
108: Horde_String::pad(Horde_Mime_Viewer_Translation::t("Ratio"), 10, ' ', STR_PAD_LEFT) .
109: "\n",
110: 'Space2html',
111: array(
112: 'charset' => $charset,
113: 'encode' => true,
114: 'encode_all' => true
115: )
116: ) . str_repeat('-', 74) . "\n";
117:
118: foreach ($zipInfo as $key => $val) {
119: $ratio = (empty($val['size']))
120: ? 0
121: : 100 * ($val['csize'] / $val['size']);
122:
123: $val['name'] = Horde_String::pad(Horde_String::truncate($val['name'], 15), 15, ' ', STR_PAD_RIGHT);
124: $val['attr'] = Horde_String::pad($val['attr'], 10, ' ', STR_PAD_LEFT);
125: $val['size'] = Horde_String::pad($val['size'], 10, ' ', STR_PAD_LEFT);
126: $val['date'] = Horde_String::pad(strftime("%d-%b-%Y %H:%M", $val['date']), 19, ' ', STR_PAD_LEFT);
127: $val['method'] = Horde_String::pad($val['method'], 10, ' ', STR_PAD_LEFT);
128: $val['ratio'] = Horde_String::pad(sprintf("%1.1f%%", $ratio), 10, ' ', STR_PAD_LEFT);
129:
130: reset($val);
131: while (list($k, $v) = each($val)) {
132: $val[$k] = $this->_textFilter($v, 'Space2html', array(
133: 'charset' => $charset,
134: 'encode' => true,
135: 'encode_all' => true
136: ));
137: }
138:
139: if (!is_null($this->_callback)) {
140: $val = call_user_func($this->_callback, $key, $val);
141: }
142:
143: $text .= $val['name'] . $val['attr'] . $val['size'] .
144: $val['date'] . $val['method'] . $val['ratio'] .
145: "\n";
146: }
147:
148: return $this->_renderReturn(
149: nl2br($text . str_repeat('-', 74) . "\n</span></td></tr></table>"),
150: 'text/html; charset=' . $charset
151: );
152: }
153:
154: }
155: