From: Michael M Slusarz Date: Wed, 12 Nov 2008 04:36:02 +0000 (-0700) Subject: Update php Viewer. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=3f8dba04c83a25fe92897866f04e01998f4fa05f;p=horde.git Update php Viewer. --- diff --git a/framework/Mime/lib/Horde/Mime/Viewer/php.php b/framework/Mime/lib/Horde/Mime/Viewer/php.php index 3113cce3f..090050c6e 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/php.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/php.php @@ -1,7 +1,4 @@ * @package Horde_Mime_Viewer */ -class Horde_Mime_Viewer_php extends Horde_Mime_Viewer_source +class Horde_Mime_Viewer_php extends Horde_Mime_Viewer_Driver { /** - * Renders out the contents. + * 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(). */ - public function render($params = array()) + protected function _render() + { + $ret = $this->_renderInline(); + $ret['data'] = Util::bufferOutput('require', $GLOBALS['registry']->get('templates', 'horde') . '/common-header.inc') . + $ret['data'] . + Util::bufferOutput('require', $GLOBALS['registry']->get('templates', 'horde') . '/common-footer.inc'); + + return $ret; + } + + /** + * Return the rendered inline version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _renderInline() { ini_set('highlight.comment', 'comment'); ini_set('highlight.default', 'default'); @@ -31,63 +53,52 @@ class Horde_Mime_Viewer_php extends Horde_Mime_Viewer_source ini_set('highlight.string', 'string'); ini_set('highlight.html', 'html'); - $code = $this->mime_part->getContents(); - if (strpos($code, 'lineNumber(str_replace('<?php ', '', highlight_string('lineNumber(highlight_string($code, true)); - } + $code = $this->_mimepart->getContents(); + $text = (strpos($code, '_lineNumber(str_replace('<?php ', '', highlight_string('_lineNumber(highlight_string($code, true)); - // Educated guess at whether we are inline or not. - if (headers_sent() || ob_get_length()) { - return $results; - } else { - return Util::bufferOutput('require', $GLOBALS['registry']->get('templates', 'horde') . '/common-header.inc') - . $results - . Util::bufferOutput('require', $GLOBALS['registry']->get('templates', 'horde') . '/common-footer.inc'); - } + return array( + 'data' => $text, + 'type' => 'text/html; charset=' . NLS::getCharset() + ); } /** * Add line numbers to a block of code. * * @param string $code The code to number. + * + * @return string The code with line numbers added. */ - public function lineNumber($code, $linebreak = "\n") + protected function _lineNumber($code, $linebreak = "\n") { // Clean up. - $code = preg_replace(array('/\s*/', - '/\s*/', - '/\s*<\/span>\s*<\/span>\s*<\/code>/', - '/\s*<\/font>\s*<\/font>\s*<\/code>/'), - '', - $code); - $code = str_replace(array(' ', - '&', - '
', - '', - ), - array(' ', - '&', - "\n", - '', - ), - $code); + $code = preg_replace( + array( + '/\s*/', + '/\s*/', + '/\s*<\/span>\s*<\/span>\s*<\/code>/', + '/\s*<\/font>\s*<\/font>\s*<\/code>/' + ), '', $code); + + $code = str_replace( + array(' ', '&', '
', '',), + array(' ', '&', "\n", '',), + $code); + $code = trim($code); // Normalize newlines. $code = str_replace("\r", '', $code); $code = preg_replace('/\n\n\n+/', "\n\n", $code); - $lines = explode("\n", $code); - $results = array('
    '); $previous = false; - foreach ($lines as $lineno => $line) { + + $lines = explode("\n", $code); + reset($lines); + while (list($lineno, $line) = each($lines)) { if (substr($line, 0, 7) == '') { $previous = false; $line = substr($line, 7); @@ -133,6 +144,7 @@ class Horde_Mime_Viewer_php extends Horde_Mime_Viewer_source } $results[] = '
'; + return implode("\n", $results); } }