/** * Return the rendered information about the Horde_Mime_Part object. * * @return array See parent::render(). * @throws Horde_Exception */ protected function _renderInfo() { /* Currently, can't do anything without tar file. */ $subtype = $this->_mimepart->getSubType(); if (in_array($subtype, array('gzip', 'x-gzip', 'x-gzip-compressed'))) { return array(); } $charset = $this->getConfigParam('charset'); $contents = $this->_mimepart->getContents(); /* Decompress gzipped files. */ if (in_array($subtype, $this->_gzipSubtypes)) { if (!$this->getConfigParam('gzip')) { $this->setConfigParam('gzip', Horde_Compress::factory('Gzip')); } $contents = $this->getConfigParam('gzip')->decompress($contents); } /* Obtain the list of files/data in the tar file. */ if (!$this->getConfigParam('tar')) { $this->setConfigParam('tar', Horde_Compress::factory('Tar')); } $tarData = $this->getConfigParam('tar')->decompress($contents); $fileCount = count($tarData); $name = $this->_mimepart->getName(true); if (empty($name)) { $name = Horde_Mime_Viewer_Translation::t("unnamed"); } $monospace = $this->getConfigParam('monospace'); $text = '<table><tr><td align="left"><span ' . ($monospace ? 'class="' . $monospace . '">' : 'style="font-family:monospace">') . $this->_textFilter(Horde_Mime_Viewer_Translation::t("Archive Name") . ': ' . $name, 'Space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n" . $this->_textFilter(Horde_Mime_Viewer_Translation::t("Archive File Size") . ': ' . strlen($contents) . ' bytes', 'Space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n" . $this->_textFilter(sprintf(Horde_Mime_Viewer_Translation::ngettext("File Count: %d file", "File Count: %d files", $fileCount), $fileCount), 'Space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n\n" . $this->_textFilter(str_pad(Horde_Mime_Viewer_Translation::t("File Name"), 62, ' ', STR_PAD_RIGHT) . str_pad(Horde_Mime_Viewer_Translation::t("Attributes"), 15, ' ', STR_PAD_LEFT) . str_pad(Horde_Mime_Viewer_Translation::t("Size"), 10, ' ', STR_PAD_LEFT) . str_pad(Horde_Mime_Viewer_Translation::t("Modified Date"), 19, ' ', STR_PAD_LEFT), 'Space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n" . str_repeat('-', 106) . "\n"; foreach ($tarData as $val) { $text .= $this->_textFilter(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), 'Space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n"; } return $this->_renderReturn(nl2br($text . str_repeat('-', 106) . "\n</span></td></tr></table>"), 'text/html; charset=' . $charset); }
/** * Return the rendered information about the Horde_Mime_Part object. * * @return array See parent::render(). * @throws Horde_Exception */ protected function _renderInfo() { $charset = $this->getConfigParam('charset'); $contents = $this->_mimepart->getContents(); if (!$this->getConfigParam('zip')) { $this->setConfigParam('zip', Horde_Compress::factory('Zip')); } $zipInfo = $this->getConfigParam('zip')->decompress($contents, array('action' => Horde_Compress_Zip::ZIP_LIST)); $fileCount = count($zipInfo); $name = $this->_mimepart->getName(true); if (empty($name)) { $name = Horde_Mime_Viewer_Translation::t("unnamed"); } $monospace = $this->getConfigParam('monospace'); $text = '<table><tr><td align="left"><span ' . ($monospace ? 'class="' . $monospace . '">' : 'style="font-family:monospace">') . $this->_textFilter(Horde_Mime_Viewer_Translation::t("Archive Name") . ': ' . $name . "\n" . Horde_Mime_Viewer_Translation::t("Archive File Size") . ': ' . strlen($contents) . " bytes\n" . sprintf(Horde_Mime_Viewer_Translation::ngettext("File Count: %d file", "File Count: %d files", $fileCount), $fileCount) . "\n\n" . str_repeat(' ', 15) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Attributes"), 10, ' ', STR_PAD_LEFT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Size"), 10, ' ', STR_PAD_LEFT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Modified Date"), 19, ' ', STR_PAD_LEFT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Method"), 10, ' ', STR_PAD_LEFT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Ratio"), 10, ' ', STR_PAD_LEFT) . "\n", 'Space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . str_repeat('-', 74) . "\n"; foreach ($zipInfo as $key => $val) { $ratio = empty($val['size']) ? 0 : 100 * ($val['csize'] / $val['size']); $val['name'] = Horde_String::pad(Horde_String::truncate($val['name'], 15), 15, ' ', STR_PAD_RIGHT); $val['attr'] = Horde_String::pad($val['attr'], 10, ' ', STR_PAD_LEFT); $val['size'] = Horde_String::pad($val['size'], 10, ' ', STR_PAD_LEFT); $val['date'] = Horde_String::pad(strftime("%d-%b-%Y %H:%M", $val['date']), 19, ' ', STR_PAD_LEFT); $val['method'] = Horde_String::pad($val['method'], 10, ' ', STR_PAD_LEFT); $val['ratio'] = Horde_String::pad(sprintf("%1.1f%%", $ratio), 10, ' ', STR_PAD_LEFT); reset($val); while (list($k, $v) = each($val)) { $val[$k] = $this->_textFilter($v, 'Space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)); } if (!is_null($this->_callback)) { $val = call_user_func($this->_callback, $key, $val); } $text .= $val['name'] . $val['attr'] . $val['size'] . $val['date'] . $val['method'] . $val['ratio'] . "\n"; } return $this->_renderReturn(nl2br($text . str_repeat('-', 74) . "\n</span></td></tr></table>"), 'text/html; charset=' . $charset); }
/** * Return the full rendered version of the Horde_Mime_Part object. * * @return array See parent::render(). */ protected function _render() { /* Check to make sure the viewer program exists. */ if (!($location = $this->getConfigParam('location')) || !file_exists($location)) { return array(); } $tmp_rtf = $this->_getTempFile(); $tmp_output = $this->_getTempFile(); file_put_contents($tmp_rtf, $this->_mimepart->getContents()); exec($location . ' ' . $tmp_rtf . ' > ' . $tmp_output); $data = file_exists($tmp_output) ? file_get_contents($tmp_output) : Horde_Mime_Viewer_Translation::t("Unable to translate this RTF document"); return $this->_renderReturn($data, 'text/html; charset=UTF-8'); }
/** * Return the converted msword document. * * @param string $type The document type (abiword 'to' argument). * @param string $mime The MIME type of the output. * * @return array See render(). */ protected function _convert($type, $mime) { /* Check to make sure the viewer program exists. */ if (!($location = $this->getConfigParam('location')) || !file_exists($location)) { return array(); } $tmp_in = $this->_getTempFile(); $tmp_out = $this->_getTempFile(); file_put_contents($tmp_in, $this->_mimepart->getContents()); exec($location . ' --to=' . escapeshellcmd($type) . ' --to-name=' . escapeshellcmd($tmp_out) . ' ' . escapeshellcmd($tmp_in)); if (file_exists($tmp_out)) { $data = file_get_contents($tmp_out); } else { $data = Horde_Mime_Viewer_Translation::t("Unable to translate this Word document"); $mime = 'text/plain; charset=UTF-8'; } return $this->_renderReturn($data, $mime); }
/** * Return the rendered information about the Horde_Mime_Part object. * * @return array See parent::render(). * @throws Horde_Exception */ protected function _renderInfo() { $charset = $this->getConfigParam('charset'); $contents = $this->_mimepart->getContents(); if (!$this->getConfigParam('rar')) { $this->setConfigParam('rar', Horde_Compress::factory('rar')); } $rarData = $this->getConfigParam('rar')->decompress($contents); $fileCount = count($rarData); $name = $this->_mimepart->getName(true); if (empty($name)) { $name = Horde_Mime_Viewer_Translation::t("unnamed"); } $monospace = $this->getConfigParam('monospace'); $text = '<table><tr><td align="left"><span ' . ($monospace ? 'class="' . $monospace . '">' : 'style="font-family:monospace">') . $this->_textFilter(Horde_Mime_Viewer_Translation::t("Archive Name") . ': ' . $name, 'space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n" . $this->_textFilter(Horde_Mime_Viewer_Translation::t("Archive File Size") . ': ' . strlen($contents) . ' bytes', 'space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n" . $this->_textFilter(sprintf(Horde_Mime_Viewer_Translation::ngettext("File Count: %d file", "File Count: %d files", $fileCount), $fileCount), 'space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n\n" . $this->_textFilter(Horde_String::pad(Horde_Mime_Viewer_Translation::t("File Name"), 50, ' ', STR_PAD_RIGHT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Attributes"), 10, ' ', STR_PAD_LEFT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Size"), 10, ' ', STR_PAD_LEFT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Modified Date"), 19, ' ', STR_PAD_LEFT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Method"), 10, ' ', STR_PAD_LEFT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Ratio"), 10, ' ', STR_PAD_LEFT), 'space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n" . str_repeat('-', 109) . "\n"; foreach ($rarData as $val) { $ratio = empty($val['size']) ? 0 : 100 * ($val['csize'] / $val['size']); $text .= $this->_textFilter(Horde_String::pad($val['name'], 50, ' ', STR_PAD_RIGHT) . Horde_String::pad($val['attr'], 10, ' ', STR_PAD_LEFT) . Horde_String::pad($val['size'], 10, ' ', STR_PAD_LEFT) . Horde_String::pad(strftime("%d-%b-%Y %H:%M", $val['date']), 19, ' ', STR_PAD_LEFT) . Horde_String::pad($val['method'], 10, ' ', STR_PAD_LEFT) . Horde_String::pad(sprintf("%1.1f%%", $ratio), 10, ' ', STR_PAD_LEFT), 'space2html', array('encode' => true, 'encode_all' => true)) . "\n"; } return $this->_renderReturn(nl2br($text . str_repeat('-', 106) . "\n</span></td></tr></table>"), 'text/html; charset=' . $charset); }
/** * Return the rendered information about the Horde_Mime_Part object. * * @return array See parent::render(). */ protected function _renderInfo() { /* Get the text of the part. Since we need to look for the end of * the headers by searching for the CRLFCRLF sequence, use * getCanonicalContents() to make sure we are getting the text with * CRLF's. */ $text = $this->_mimepart->getContents(array('canonical' => true)); if (empty($text)) { return array(); } /* Search for the end of the header text (CRLFCRLF). */ $text = substr($text, 0, strpos($text, "\r\n\r\n")); /* Get the list of headers now. */ $headers = Horde_Mime_Headers::parseHeaders($text); $header_array = array('date' => Horde_Mime_Viewer_Translation::t("Date"), 'from' => Horde_Mime_Viewer_Translation::t("From"), 'to' => Horde_Mime_Viewer_Translation::t("To"), 'cc' => Horde_Mime_Viewer_Translation::t("Cc"), 'bcc' => Horde_Mime_Viewer_Translation::t("Bcc"), 'reply-to' => Horde_Mime_Viewer_Translation::t("Reply-To"), 'subject' => Horde_Mime_Viewer_Translation::t("Subject")); $header_output = array(); foreach ($header_array as $key => $val) { $hdr = $this->_getHeaderValue($headers, $key); if (!empty($hdr)) { $header_output[] = '<strong>' . $val . ':</strong> ' . htmlspecialchars($hdr); } } return $this->_renderReturn(empty($header_output) ? '' : '<div class="fixed mimeHeaders">' . $this->_textFilter(implode("<br />\n", $header_output), 'emails') . '</div>', 'text/html; charset=UTF-8'); }
/** * Return the rendered information about the Horde_Mime_Part object. * * @return array See parent::render(). * @throws Horde_Exception */ protected function _renderInfo() { $charset = $this->getConfigParam('charset'); $contents = $this->_mimepart->getContents(); /* Decompress gzipped files. */ if (!($gzip = $this->getConfigParam('gzip'))) { $gzip = Horde_Compress::factory('Gzip'); } try { $contents = $gzip->decompress($contents); $this->_metadata['compressed'] = true; } catch (Horde_Compress_Exception $e) { $this->_metadata['compressed'] = false; } /* Obtain the list of files/data in the tar file. */ if (!($tar = $this->getConfigParam('tar'))) { $tar = Horde_Compress::factory('Tar'); } $tarData = null; try { $tarData = $tar->decompress($contents); } catch (Horde_Compress_Exception $e) { if ($this->_metadata['compressed']) { /* Doubly gzip'd files are somewhat common. Try a second * decompression before giving up. */ try { $tarData = $tar->decompress($gzip->decompress($contents)); } catch (Horde_Compress_Exception $e) { } } } if (is_null($tarData)) { return array(); } $fileCount = count($tarData); $name = $this->_mimepart->getName(true); if (empty($name)) { $name = Horde_Mime_Viewer_Translation::t("unnamed"); } $monospace = $this->getConfigParam('monospace'); $text = '<table><tr><td align="left"><span ' . ($monospace ? 'class="' . $monospace . '">' : 'style="font-family:monospace">') . $this->_textFilter(Horde_Mime_Viewer_Translation::t("Archive Name") . ': ' . $name, 'Space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n" . $this->_textFilter(Horde_Mime_Viewer_Translation::t("Archive File Size") . ': ' . strlen($contents) . ' bytes', 'Space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n" . $this->_textFilter(sprintf(Horde_Mime_Viewer_Translation::ngettext("File Count: %d file", "File Count: %d files", $fileCount), $fileCount), 'Space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n\n" . $this->_textFilter(str_pad(Horde_Mime_Viewer_Translation::t("File Name"), 62, ' ', STR_PAD_RIGHT) . str_pad(Horde_Mime_Viewer_Translation::t("Attributes"), 15, ' ', STR_PAD_LEFT) . str_pad(Horde_Mime_Viewer_Translation::t("Size"), 10, ' ', STR_PAD_LEFT) . str_pad(Horde_Mime_Viewer_Translation::t("Modified Date"), 19, ' ', STR_PAD_LEFT), 'Space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n" . str_repeat('-', 106) . "\n"; foreach ($tarData as $val) { $text .= $this->_textFilter(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), 'Space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n"; } return $this->_renderReturn(nl2br($text . str_repeat('-', 106) . "\n</span></td></tr></table>"), 'text/html; charset=' . $charset); }
/** * Returns the plural translation of a message. * * @param string $singular The singular version to translate. * @param string $plural The plural version to translate. * @param integer $number The number that determines singular vs. plural. * * @return string The string translation, or the original string if no * translation exists. */ public static function ngettext($singular, $plural, $number) { self::$_domain = 'Horde_Mime_Viewer'; self::$_directory = '@data_dir@' == '@' . 'data_dir' . '@' ? __DIR__ . '/../../../../locale' : '@data_dir@/Horde_Mime_Viewer/locale'; return parent::ngettext($singular, $plural, $number); }