1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16:
17: class Horde_Mime_Viewer_Rar 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: 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:
59: 60: 61: 62: 63: 64:
65: protected function _renderInfo()
66: {
67: $charset = $this->getConfigParam('charset');
68: $contents = $this->_mimepart->getContents();
69:
70: if (!$this->getConfigParam('rar')) {
71: $this->setConfigParam('rar', Horde_Compress::factory('rar'));
72: }
73: $rarData = $this->getConfigParam('rar')->decompress($contents);
74: $fileCount = count($rarData);
75:
76: $name = $this->_mimepart->getName(true);
77: if (empty($name)) {
78: $name = Horde_Mime_Viewer_Translation::t("unnamed");
79: }
80:
81: $monospace = $this->getConfigParam('monospace');
82:
83: $text = '<table><tr><td align="left"><span ' .
84: ($monospace ? 'class="' . $monospace . '">' : 'style="font-family:monospace">') .
85: $this->_textFilter(Horde_Mime_Viewer_Translation::t("Archive Name") . ': ' . $name, 'space2html', array(
86: 'charset' => $charset,
87: 'encode' => true,
88: 'encode_all' => true
89: )) . "\n" .
90: $this->_textFilter(Horde_Mime_Viewer_Translation::t("Archive File Size") . ': ' . strlen($contents) . ' bytes', 'space2html', array(
91: 'charset' => $charset,
92: 'encode' => true,
93: 'encode_all' => true
94: )) . "\n" .
95: $this->_textFilter(sprintf(Horde_Mime_Viewer_Translation::ngettext("File Count: %d file", "File Count: %d files", $fileCount), $fileCount), 'space2html', array(
96: 'charset' => $charset,
97: 'encode' => true,
98: 'encode_all' => true
99: )) .
100: "\n\n" .
101: $this->_textFilter(
102: Horde_String::pad(Horde_Mime_Viewer_Translation::t("File Name"), 50, ' ', STR_PAD_RIGHT) .
103: Horde_String::pad(Horde_Mime_Viewer_Translation::t("Attributes"), 10, ' ', STR_PAD_LEFT) .
104: Horde_String::pad(Horde_Mime_Viewer_Translation::t("Size"), 10, ' ', STR_PAD_LEFT) .
105: Horde_String::pad(Horde_Mime_Viewer_Translation::t("Modified Date"), 19, ' ', STR_PAD_LEFT) .
106: Horde_String::pad(Horde_Mime_Viewer_Translation::t("Method"), 10, ' ', STR_PAD_LEFT) .
107: Horde_String::pad(Horde_Mime_Viewer_Translation::t("Ratio"), 10, ' ', STR_PAD_LEFT),
108: 'space2html',
109: array(
110: 'charset' => $charset,
111: 'encode' => true,
112: 'encode_all' => true
113: )
114: ) . "\n" . str_repeat('-', 109) . "\n";
115:
116: foreach ($rarData as $val) {
117: $ratio = empty($val['size'])
118: ? 0
119: : 100 * ($val['csize'] / $val['size']);
120:
121: $text .= $this->_textFilter(
122: Horde_String::pad($val['name'], 50, ' ', STR_PAD_RIGHT) .
123: Horde_String::pad($val['attr'], 10, ' ', STR_PAD_LEFT) .
124: Horde_String::pad($val['size'], 10, ' ', STR_PAD_LEFT) .
125: Horde_String::pad(strftime("%d-%b-%Y %H:%M", $val['date']), 19, ' ', STR_PAD_LEFT) .
126: Horde_String::pad($val['method'], 10, ' ', STR_PAD_LEFT) .
127: Horde_String::pad(sprintf("%1.1f%%", $ratio), 10, ' ', STR_PAD_LEFT),
128: 'space2html',
129: array(
130: 'encode' => true,
131: 'encode_all' => true
132: )
133: ) . "\n";
134: }
135:
136: return $this->_renderReturn(
137: nl2br($text . str_repeat('-', 106) . "\n</span></td></tr></table>"),
138: 'text/html; charset=' . $charset
139: );
140: }
141:
142: }
143: