+++ /dev/null
-<?php
-/**
- * The Horde_Mime_Viewer_Css class renders CSS source as HTML with an effort
- * to remove potentially malicious code.
- *
- * Copyright 2004-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @author Chuck Hagenbuch <chuck@horde.org>
- * @category Horde
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @package Mime_Viewer
- */
-class Horde_Mime_Viewer_Css extends Horde_Mime_Viewer_Source
-{
- /**
- * This driver's display capabilities.
- *
- * @var array
- */
- protected $_capability = array(
- 'full' => true,
- 'info' => false,
- 'inline' => true,
- 'raw' => false
- );
-
- /**
- * Attribute preg patterns.
- *
- * @var array
- */
- protected $_attrPatterns = array(
- // Attributes
- '!([-\w]+\s*):!s' => '<span class="attr"">\\1</span>:',
- // Values
- '!:(\s*)(.+?)(\s*;)!s' => ':\\1<span class="value">\\2</span><span class="eol">\\3</span>',
- // URLs
- '!(url\([\'"]?)(.*?)([\'"]?\))!s' => '<span class="url">\\1<span class="file">\\2</span>\\3</span>',
- // Colors
- '!(#[[:xdigit:]]{3,6})!s' => '<span class="color">\\1</span>',
- // Parentheses
- '!({|})!s' => '<span class="parentheses">\\1</span>',
- // Unity
- '!(em|px|%)\b!s' => '<em>\\1</em>'
- );
-
- /**
- * Handles preg patterns.
- *
- * @var array
- */
- protected $_handlesPatterns = array(
- // HTML Tags
- '!\b(body|h\d|a|span|div|acronym|small|strong|em|pre|ul|ol|li|p)\b!s' => '<span class="htag">\\1</span>\\2',
- // IDs
- '!(#[-\w]+)!s' => '<span class="id">\\1</span>',
- // Class
- '!(\.[-\w]+)\b!s' => '<span class="class">\\1</span>',
- // METAs
- '!(:link|:visited|:hover|:active|:first-letter)!s' => '<span class="metac">\\1</span>'
- );
-
- /**
- * Return the full rendered version of the Horde_Mime_Part object.
- *
- * @return array See parent::render().
- */
- protected function _render()
- {
- return $this->_renderFullReturn($this->_renderInline());
- }
-
- /**
- * Return the rendered inline version of the Horde_Mime_Part object.
- *
- * @return array See parent::render().
- */
- protected function _renderInline()
- {
- $css = preg_replace_callback('!(}|\*/).*?({|/\*)!s', array($this, '_handles'), htmlspecialchars($this->_mimepart->getContents(), ENT_NOQUOTES));
- $css = preg_replace_callback('!{[^}]*}!s', array($this, '_attributes'), $css);
- $css = preg_replace_callback('!/\*.*?\*/!s', array($this, '_comments'), $css);
-
- return $this->_renderReturn(
- $this->_lineNumber(trim($css)),
- 'text/html; charset=' . $GLOBALS['registry']->getCharset()
- );
- }
-
- /**
- * TODO
- */
- protected function _comments($matches)
- {
- return '<span class="comment">' .
- preg_replace('!(http://[/\w-.]+)!s', '<a href="\\1">\\1</a>', $matches[0]) .
- '</span>';
- }
-
- /**
- * TODO
- */
- protected function _attributes($matches)
- {
- return preg_replace(array_keys($this->_attrPatterns), array_values($this->_attrPatterns), $matches[0]);
- }
-
- /**
- * TODO
- */
- protected function _handles($matches)
- {
- return preg_replace(array_keys($this->_handlesPatterns), array_values($this->_handlesPatterns), $matches[0]);
- }
-
-}
+++ /dev/null
-<?php
-/**
- * The Horde_Mime_Viewer_Php class renders out syntax-highlighted PHP code in
- * HTML format.
- *
- * Copyright 1999-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @author Chuck Hagenbuch <chuck@horde.org>
- * @category Horde
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @package Mime_Viewer
- */
-class Horde_Mime_Viewer_Php extends Horde_Mime_Viewer_Source
-{
- /**
- * This driver's display capabilities.
- *
- * @var array
- */
- protected $_capability = array(
- 'full' => true,
- 'info' => false,
- 'inline' => true,
- 'raw' => false
- );
-
- /**
- * Return the full rendered version of the Horde_Mime_Part object.
- *
- * @return array See parent::render().
- */
- protected function _render()
- {
- return $this->_renderFullReturn($this->_renderInline());
- }
-
- /**
- * Return the rendered inline version of the Horde_Mime_Part object.
- *
- * @return array See parent::render().
- */
- protected function _renderInline()
- {
- $code = $this->_mimepart->getContents();
-
- $text = (strpos($code, '<?php') === false)
- ? str_replace('<?php ', '', highlight_string('<?php ' . $code, true))
- : highlight_string($code, true);
-
- return $this->_renderReturn(
- $this->_lineNumber(trim(str_replace(array("\n", '<br />'), array('', "\n"), $text))),
- 'text/html; charset=' . $this->getConfigParam('charset')
- );
- }
-
-}
+++ /dev/null
-<?php
-/**
- * The Horde_Mime_Viewer_Source class is a class for any viewer that wants
- * to provide line numbers to extend.
- *
- * Copyright 1999-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @author Chuck Hagenbuch <chuck@horde.org>
- * @category Horde
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @package Mime_Viewer
- */
-class Horde_Mime_Viewer_Source extends Horde_Mime_Viewer_Base
-{
- /**
- * Add line numbers to a block of code.
- *
- * @param string $code The code to number.
- *
- * @return string The code with line numbers added.
- */
- protected function _lineNumber($code, $linebreak = "\n")
- {
- $html = array('<table class="lineNumbered" cellspacing="0"><tr><th>');
- for ($l = 1, $lines = substr_count($code, $linebreak) + 1; $l <= $lines; ++$l) {
- $html[] = sprintf('<a id="l%s" href="#l%s">%s</a><br />', $l, $l, $l);
- }
- return implode("\n", $html) . '</th><td><div>' . $code . '</div></td></tr></table>';
- }
-
-}
+++ /dev/null
-<?php
-/**
- * The Horde_Mime_Viewer_Srchighlite class renders out various content in HTML
- * format by using the GNU source-highlight package.
- *
- * Source-highlight: http://www.gnu.org/software/src-highlite/
- * Tested with v3.1.3
- *
- * Copyright 2003-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @author Mike Cochrane <mike@graftonhall.co.nz>
- * @author Michael Slusarz <slusarz@horde.org>
- * @category Horde
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @package Mime_Viewer
- */
-class Horde_Mime_Viewer_Srchighlite extends Horde_Mime_Viewer_Base
-{
- /**
- * This driver's display capabilities.
- *
- * @var array
- */
- protected $_capability = array(
- 'full' => true,
- 'info' => false,
- 'inline' => true,
- 'raw' => false
- );
-
- /**
- * Constructor.
- *
- * @param Horde_Mime_Part $mime_part The object with the data to be
- * rendered.
- * @param array $conf Configuration:
- * <pre>
- * 'location' - (string) Location of the source-highlight binary.
- * </pre>
- *
- * @throws InvalidArgumentException
- */
- public function __construct(Horde_Mime_Part $part, array $conf = array())
- {
- $this->_required = array_merge($this->_required, array(
- 'location'
- ));
-
- parent::__construct($part, $conf);
- }
-
- /**
- * Return the full rendered version of the Horde_Mime_Part object.
- *
- * @return array See parent::render().
- */
- protected function _render()
- {
- return $this->_renderFullReturn($this->_renderInline());
- }
-
- /**
- * Return the rendered inline version of the Horde_Mime_Part object.
- *
- * @return array See parent::render().
- */
- protected function _renderInline()
- {
- /* Check to make sure the viewer program exists. */
- if (!($location = $this->getConfigParam('location')) ||
- !file_exists($location)) {
- return array();
- }
-
- $tmpin = $this->_getTempFile();
- $tmpout = $this->_getTempFile();
-
- /* Write the contents of our buffer to the temporary input file. */
- file_put_contents($tmpin, $this->_mimepart->getContents());
-
- /* Determine the language from the mime type. */
- $lang = $this->_typeToLang($this->_mimepart->getType());
-
- /* Execute Source-Highlite. */
- exec($location . ' --src-lang ' . escapeshellarg($lang) . ' --out-format html --input ' . $tmpin . ' --output ' . $tmpout);
- $results = file_get_contents($tmpout);
- unlink($tmpout);
-
- return $this->_renderReturn(
- $results,
- 'text/html; charset=' . $this->getConfigParam('charset')
- );
- }
-
- /**
- * Attempts to determine what mode to use for the source-highlight
- * program from a MIME type.
- *
- * @param string $type The MIME type.
- *
- * @return string The mode to use.
- */
- protected function _typeToLang($type)
- {
- switch ($type) {
- case 'application/x-javascript':
- return 'js';
-
- case 'application/x-perl':
- return 'perl';
-
- case 'application/x-php':
- case 'x-extension/phps':
- case 'x-extension/php3s':
- case 'application/x-httpd-php':
- case 'application/x-httpd-php3':
- case 'application/x-httpd-phps':
- return 'php';
-
- case 'application/x-python':
- return 'python';
-
- case 'application/x-ruby':
- return 'ruby';
-
- case 'application/x-sh':
- case 'application/x-shellscript':
- return 'sh';
-
- case 'application/x-tcl':
- return 'tcl';
-
- case 'application/xml':
- case 'text/xml':
- return 'xml';
-
- case 'text/cpp':
- case 'text/x-c++':
- case 'text/x-c++src':
- case 'text/x-c++hdr':
- return 'cpp';
-
- case 'text/css':
- case 'x-extension/css':
- return 'css';
-
- case 'text/diff':
- case 'text/x-diff':
- case 'text/x-patch':
- return 'diff';
-
- case 'text/x-c':
- case 'text/x-chdr':
- case 'text/x-csrc':
- return 'c';
-
- case 'text/x-emacs-lisp':
- return 'lisp';
-
- case 'text/x-fortran':
- case 'x-extension/f77':
- case 'x-extension/f90':
- case 'x-extension/for':
- case 'x-extension/ftn':
- return 'fortran';
-
- case 'text/x-java':
- return 'java';
-
- case 'text/x-pascal':
- return 'pascal';
-
- case 'text/x-sql':
- return 'sql';
-
- case 'text/x-tex':
- return 'tex';
-
- case 'x-extension/asm':
- return 'asm';
-
- case 'x-extension/bat':
- return 'batch';
-
- case 'x-extension/cs':
- return 'csharp';
-
- case 'x-extension/vb':
- case 'x-extension/vba':
- return 'vbs';
- }
- }
-
-}
<email>slusarz@horde.org</email>
<active>yes</active>
</lead>
- <date>2010-07-25</date>
+ <date>2010-10-02</date>
<version>
- <release>0.1.0</release>
+ <release>0.2.0</release>
<api>0.1.0</api>
</version>
<stability>
<api>beta</api>
</stability>
<license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>* Initial package.
+ <notes>Replaced external or PHP-based syntax highlighters with javascript SyntaxHighlighter
</notes>
<contents>
<dir name="/">
</dir> <!-- /lib/Horde/Mime/Viewer/Ooo -->
<file name="Audio.php" role="php" />
<file name="Base.php" role="php" />
- <file name="Css.php" role="php" />
<file name="Deb.php" role="php" />
<file name="Default.php" role="php" />
<file name="Enriched.php" role="php" />
<file name="Msword.php" role="php" />
<file name="Ooo.php" role="php" />
<file name="Pdf.php" role="php" />
- <file name="Php.php" role="php" />
<file name="Plain.php" role="php" />
<file name="Rar.php" role="php" />
<file name="Report.php" role="php" />
<file name="Security.php" role="php" />
<file name="Simple.php" role="php" />
<file name="Smil.php" role="php" />
- <file name="Source.php" role="php" />
- <file name="Srchighlite.php" role="php" />
+ <file name="SyntaxHighlighter.php" role="php" />
<file name="Tgz.php" role="php" />
<file name="Tnef.php" role="php" />
<file name="Wordperfect.php" role="php" />
<dir name="Mime">
<dir name="Viewer">
<file name="url.phpt" role="test" />
- <file name="viewer_php.phpt" role="test" />
</dir> <!-- /test/Horde/Mime/Viewer -->
</dir> <!-- /test/Horde/Mime -->
</dir> <!-- /test/Horde -->
<install name="lib/Horde/Mime/Viewer/Ooo/table_rows.xsl" as="Horde/Mime/Viewer/Ooo/table_rows.xsl" />
<install name="lib/Horde/Mime/Viewer/Audio.php" as="Horde/Mime/Viewer/Audio.php" />
<install name="lib/Horde/Mime/Viewer/Base.php" as="Horde/Mime/Viewer/Base.php" />
- <install name="lib/Horde/Mime/Viewer/Css.php" as="Horde/Mime/Viewer/Css.php" />
<install name="lib/Horde/Mime/Viewer/Deb.php" as="Horde/Mime/Viewer/Deb.php" />
<install name="lib/Horde/Mime/Viewer/Default.php" as="Horde/Mime/Viewer/Default.php" />
<install name="lib/Horde/Mime/Viewer/Enriched.php" as="Horde/Mime/Viewer/Enriched.php" />
<install name="lib/Horde/Mime/Viewer/Msword.php" as="Horde/Mime/Viewer/Msword.php" />
<install name="lib/Horde/Mime/Viewer/Ooo.php" as="Horde/Mime/Viewer/Ooo.php" />
<install name="lib/Horde/Mime/Viewer/Pdf.php" as="Horde/Mime/Viewer/Pdf.php" />
- <install name="lib/Horde/Mime/Viewer/Php.php" as="Horde/Mime/Viewer/Php.php" />
<install name="lib/Horde/Mime/Viewer/Plain.php" as="Horde/Mime/Viewer/Plain.php" />
<install name="lib/Horde/Mime/Viewer/Rar.php" as="Horde/Mime/Viewer/Rar.php" />
<install name="lib/Horde/Mime/Viewer/Report.php" as="Horde/Mime/Viewer/Report.php" />
<install name="lib/Horde/Mime/Viewer/Security.php" as="Horde/Mime/Viewer/Security.php" />
<install name="lib/Horde/Mime/Viewer/Simple.php" as="Horde/Mime/Viewer/Simple.php" />
<install name="lib/Horde/Mime/Viewer/Smil.php" as="Horde/Mime/Viewer/Smil.php" />
- <install name="lib/Horde/Mime/Viewer/Source.php" as="Horde/Mime/Viewer/Source.php" />
- <install name="lib/Horde/Mime/Viewer/Srchighlite.php" as="Horde/Mime/Viewer/Srchighlite.php" />
+ <install name="lib/Horde/Mime/Viewer/SyntaxHighlighter.php" as="Horde/Mime/Viewer/SyntaxHighlighter.php" />
<install name="lib/Horde/Mime/Viewer/Tgz.php" as="Horde/Mime/Viewer/Tgz.php" />
<install name="lib/Horde/Mime/Viewer/Tnef.php" as="Horde/Mime/Viewer/Tnef.php" />
<install name="lib/Horde/Mime/Viewer/Wordperfect.php" as="Horde/Mime/Viewer/Wordperfect.php" />
+++ /dev/null
---TEST--
-PHP source viewer
---SKIPIF--
-skip: Horde_Mime_Viewer has too many dependencies.
---FILE--
-<?php
-
-require_once dirname(__FILE__) . '/../../../lib/Horde/Mime/Part.php';
-require_once dirname(__FILE__) . '/../../../lib/Horde/Mime/Viewer.php';
-
-ini_set('highlight.comment', 'comment');
-ini_set('highlight.default', 'default');
-ini_set('highlight.keyword', 'keyword');
-ini_set('highlight.string', 'string');
-ini_set('highlight.html', 'html');
-
-$part = new Horde_Mime_Part();
-$part->setType('application/x-php');
-$part->setContents(str_replace('<?php ', '', highlight_string('<?php highlight_file(__FILE__);', true)));
-
-$viewer = Horde_Mime_Viewer::factory($part);
-echo $viewer->render();
-?>
---EXPECT--
-<ol class="code-listing striped">
-<li id="l1"><span class="default">highlight_file</span><span class="keyword">(</span><span class="default">__FILE__</span><span class="keyword">);</span></li>
-</ol>
)
),
- /* PHP pretty-print code display. */
- 'php' => array(
- 'inline' => true,
- 'handles' => array(
- 'application/x-php',
- 'x-extension/phps',
- 'x-extension/php3s',
- 'application/x-httpd-php',
- 'application/x-httpd-php3',
- 'application/x-httpd-phps'
- ),
- 'icons' => array(
- 'default' => 'php.png'
- )
- ),
-
- /* CSS pretty-print display. */
- 'css' => array(
- 'inline' => true,
- 'handles' => array(
- 'text/css',
- 'x-extension/css'
- ),
- 'icons' => array(
- 'default' => 'html.png'
- )
- ),
-
/* HTML display. */
'html' => array(
// NOTE: Inline HTML viewing is DISABLED by default.
)
),
- /* Source-highlight driver.
- * http://www.gnu.org/software/src-highlite/ */
- 'srchighlite' => array(
- // Disabled by default
- 'disable' => true,
+ /* SyntaxHighlighter driver.
+ * http://alexgorbatchev.com/SyntaxHighlighter/ */
+ 'syntaxhighlighter' => array(
'inline' => true,
'handles' => array(
'application/x-httpd-php',
'text/x-chdr',
'text/x-csrc',
'text/x-diff',
- 'text/x-emacs-lisp',
- 'text/x-fortran',
'text/x-java',
- 'text/x-pascal',
'text/x-patch',
'text/x-sql',
'text/x-tex',
'text/xml',
- 'x-extension/asm',
'x-extension/bat',
+ 'x-extension/c',
+ 'x-extension/cpp',
'x-extension/cs',
'x-extension/css',
- 'x-extension/f77',
- 'x-extension/f90',
- 'x-extension/for',
- 'x-extension/ftn',
+ 'x-extension/html',
+ 'x-extension/js',
+ 'x-extension/perl',
+ 'x-extension/php',
'x-extension/php3s',
'x-extension/phps',
- 'x-extension/rc',
+ 'x-extension/pl',
+ 'x-extension/py',
+ 'x-extension/python',
+ 'x-extension/rb',
+ 'x-extension/ruby',
'x-extension/vb',
- 'x-extension/vba'
+ 'x-extension/vba',
+ 'x-extension/xml',
),
'icons' => array(
'default' => 'text.png',
'text/x-java' => 'source-java.png',
'text/x-sql' => 'sql.png',
'text/xml' => 'xml.png',
+ 'x-extension/bash' => 'shell.png',
+ 'x-extension/c' => 'source-c.png',
+ 'x-extension/cpp' => 'source-c.png',
+ 'x-extension/cs' => 'source-c.png',
'x-extension/css' => 'html.png',
+ 'x-extension/html' => 'html.png',
+ 'x-extension/js' => 'script-js.png',
+ 'x-extension/php' => 'php.png',
'x-extension/php3s' => 'php.png',
'x-extension/phps' => 'php.png',
- 'x-extension/rc' => 'xml.png'
+ 'x-extension/py' => 'source-python.png',
+ 'x-extension/python' => 'source-python.png',
+ 'x-extension/sh' => 'shell.png',
+ 'x-extension/xml' => 'xml.png'
),
-
- // REQUIRED: Location of the source-highlight binary
- 'location' => '/usr/bin/source-highlight'
),
/* Tar file display.