From b3e19d34569e113d331dfe90637eb1e86cd1fa9c Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 12 Nov 2008 11:50:05 -0700 Subject: [PATCH] Update RTF Viewer. --- framework/Mime/lib/Horde/Mime/Viewer/rtf.php | 53 +++++++++++++++------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/framework/Mime/lib/Horde/Mime/Viewer/rtf.php b/framework/Mime/lib/Horde/Mime/Viewer/rtf.php index b7e9001b6..e6b7baa7b 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/rtf.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/rtf.php @@ -15,43 +15,46 @@ class Horde_Mime_Viewer_rtf extends Horde_Mime_Viewer_Driver { /** - * Render out the current data using UnRTF. + * Can this driver render various views? * - * @param array $params Any parameters the viewer may need. + * @var boolean + */ + protected $_capability = array( + 'embedded' => false, + 'full' => true, + 'info' => false, + 'inline' => false + ); + + /** + * Return the full rendered version of the Horde_Mime_Part object. * - * @return string The rendered contents. + * @return array See Horde_Mime_Viewer_Driver::render(). */ - public function render($params = array()) + protected function _render() { - /* Check to make sure the program actually exists. */ - if (!file_exists($GLOBALS['mime_drivers']['horde']['rtf']['location'])) { - return '
' . sprintf(_("The program used to view this data type (%s) was not found on the system."), $GLOBALS['mime_drivers']['horde']['rtf']['location']) . '
'; + /* Check to make sure the viewer program exists. */ + if (!isset($this->_conf['location']) || + !file_exists($this->_conf['location'])) { + return array(); } $tmp_rtf = Horde::getTempFile('rtf'); $tmp_output = Horde::getTempFile('rtf'); - $args = " $tmp_rtf > $tmp_output"; - $fh = fopen($tmp_rtf, 'w'); - fwrite($fh, $this->mime_part->getContents()); - fclose($fh); + file_put_contents($tmp_rtf, $this->_mimepart->getContents()); - exec($GLOBALS['mime_drivers']['horde']['rtf']['location'] . $args); + exec($GLOBALS['mime_drivers']['horde']['rtf']['location'] . " $tmp_rtf > $tmp_output"); - if (!file_exists($tmp_output)) { - return _("Unable to translate this RTF document"); + if (file_exists($tmp_output)) { + $data = file_get_contents($tmp_output); + } else { + $data = _("Unable to translate this RTF document"); } - return file_get_contents($tmp_output); - } - - /** - * Return the MIME content type of the rendered content. - * - * @return string The content type of the output. - */ - public function getType() - { - return 'text/html; charset=' . NLS::getCharset(); + return array( + 'data' => $data, + 'type' => 'text/html; charset=' . NLS::getCharset() + ); } } -- 2.11.0