From: Michael M Slusarz Date: Wed, 12 Nov 2008 18:51:27 +0000 (-0700) Subject: Update webcpp Viewer. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=8f68341df57419d7fe58b45eddc201f1cf035a87;p=horde.git Update webcpp Viewer. --- diff --git a/framework/Mime/lib/Horde/Mime/Viewer/webcpp.php b/framework/Mime/lib/Horde/Mime/Viewer/webcpp.php index 756479ec1..0dad46637 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/webcpp.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/webcpp.php @@ -16,66 +16,90 @@ class Horde_Mime_Viewer_webcpp extends Horde_Mime_Viewer_Driver { /** - * Render out the currently set contents using Web C Plus Plus. + * 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' => true + ); + + /** + * Return the full rendered version of the Horde_Mime_Part object. * - * @return string The rendered contents. + * @return array See Horde_Mime_Viewer_Driver::render(). */ - protected function render($params = array()) + protected function _render() { - /* Check to make sure the program actually exists. */ - if (!file_exists($GLOBALS['mime_drivers']['horde']['webcpp']['location'])) { - return '
' . sprintf(_("The program used to view this data type (%s) was not found on the system."), $GLOBALS['mime_drivers']['horde']['webcpp']['location']) . '
'; - } + $ret = $this->_toHTML(); - /* Create temporary files for Webcpp. */ - $tmpin = Horde::getTempFile('WebcppIn'); - $tmpout = Horde::getTempFile('WebcppOut'); - - /* Write the contents of our buffer to the temporary input file. */ - $contents = $this->mime_part->getContents(); - $fh = fopen($tmpin, 'wb'); - fwrite($fh, $contents, strlen($contents)); - fclose($fh); + /* The first 2 lines are the Content-Type line and a blank line so + * remove them before outputting. */ + $ret['data'] = preg_replace("/.*\n.*\n/", '', $ret['data'], 1); - /* Get the extension for the mime type. */ - include_once 'Horde/MIME/Magic.php'; - $ext = MIME_Magic::MIMEToExt($this->mime_part->getType()); - - /* Execute Web C Plus Plus. Specifying the in and out files didn't - work for me but pipes did. */ - exec($GLOBALS['mime_drivers']['horde']['webcpp']['location'] . " --pipe --pipe -x=$ext -l -a -t < $tmpin > $tmpout"); - $results = file_get_contents($tmpout); + return $ret; + } - /* If we are not displaying inline, all the formatting is already - * done for us. */ - if (!$this->viewInline()) { - /* The first 2 lines are the Content-Type line and a blank line - * so we should remove them before outputting. */ - return preg_replace("/.*\n.*\n/", '', $results, 1); - } + /** + * Return the rendered inline version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _renderInline() + { + $ret = $this->_toHTML(); + $data = $ret['data']; /* Extract the style sheet, removing any global body formatting * if we're displaying inline. */ - $res = preg_split(';()|()|(
' . $body . '
'; + $ret['data'] = '
' . $body . '
'; + + return $ret; } /** - * Return the MIME content type of the rendered content. + * Converts the code to HTML. * - * @return string The content type of the output. + * @return string The HTML-ified version of the MIME part contents. */ - protected function getType() + protected function _toHTML() { - return 'text/html; charset=' . NLS::getCharset(); + /* Check to make sure the viewer program exists. */ + if (!isset($this->_conf['location']) || + !file_exists($this->_conf['location'])) { + return array(); + } + + /* Create temporary files for Webcpp. */ + $tmpin = Horde::getTempFile('WebcppIn'); + $tmpout = Horde::getTempFile('WebcppOut'); + + /* Write the contents of our buffer to the temporary input file. */ + file_put_contents($tmpin, $this->_mimepart->getContents()); + + /* Get the extension for the mime type. */ + include_once dirname(__FILE__) . '/../Magic.php'; + $ext = Horde_Mime_Magic::MIMEToExt($this->_mimepart->getType()); + + /* Execute Web C Plus Plus. Specifying the in and out files didn't + * work for me but pipes did. */ + exec($this->_conf['location'] . " --pipe --pipe -x=$ext -l -a -t < $tmpin > $tmpout"); + $results = file_get_contents($tmpout); + + return array( + 'data' => $results, + 'type' => 'text/html; charset=' . NLS::getCharset() + ); } }