+++ /dev/null
-<?php
-/**
- * The Horde_Mime_Viewer_Enscript class renders out various content in HTML
- * format by using GNU Enscript.
- *
- * 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 Anil Madhavapeddy <anil@recoil.org>
- * @category Horde
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @package Mime
- */
-class Horde_Mime_Viewer_Enscript 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 Horde_Mime_Viewer_Driver::render().
- */
- protected function _render()
- {
- return array(
- $this->_mimepart->getMimeId() => array(
- 'data' => $this->_toHTML(),
- 'status' => array(),
- 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset()
- )
- );
- }
-
- /**
- * Return the rendered inline version of the Horde_Mime_Part object.
- *
- * @return array See Horde_Mime_Viewer_Driver::render().
- */
- protected function _renderInline()
- {
- return array(
- $this->_mimepart->getMimeId() => array(
- 'data' => $this->_toHTML(),
- 'status' => array(),
- 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset()
- )
- );
- }
-
- /**
- * Converts the code to HTML.
- *
- * @return string The HTML-ified version of the MIME part contents.
- */
- protected function _toHTML()
- {
- /* Check to make sure the viewer program exists. */
- if (!isset($this->_conf['location']) ||
- !file_exists($this->_conf['location'])) {
- return array();
- }
-
- /* Create temporary files for input to Enscript. Note that we can't
- * use a pipe, since enscript must have access to the whole file to
- * determine its type for coloured syntax highlighting. */
- $tmpin = Horde::getTempFile('enscriptin');
-
- /* Write the contents of our buffer to the temporary input file. */
- file_put_contents($tmpin, $this->_mimepart->getContents());
-
- /* Execute the enscript command. */
- $lang = escapeshellarg($this->_typeToLang($this->_mimepart->getType()));
- $results = shell_exec($this->_conf['location'] . " -E$lang --language=html --color --output=- < $tmpin");
-
- /* Strip out the extraneous HTML from enscript. */
- $res_arr = preg_split('/\<\/?pre\>/i', $results);
- if (count($res_arr) == 3) {
- $results = trim($res_arr[1]);
- }
-
- return $this->_lineNumber($results);
- }
-
- /**
- * Attempts to determine what language to use for the enscript program
- * from a MIME type.
- *
- * @param string $type The MIME type.
- *
- * @return string The enscript 'language' parameter string.
- */
- protected function _typeToLang($type)
- {
- $ext = Horde_Mime_Magic::MIMEToExt($type);
-
- switch ($ext) {
- case 'cs':
- return 'java';
-
- case 'el':
- return 'elisp';
-
- case 'h':
- return 'c';
-
- case 'C':
- case 'H':
- case 'cc':
- case 'hh':
- case 'c++':
- case 'cxx':
- case 'cpp':
- return 'cpp';
-
- case 'htm':
- case 'shtml':
- case 'xml':
- return 'html';
-
- case 'js':
- return 'javascript';
-
- case 'pas':
- return 'pascal';
-
- case 'al':
- case 'cgi':
- case 'pl':
- case 'pm':
- return 'perl';
-
- case 'ps':
- return 'postscript';
-
- case 'vb':
- return 'vba';
-
- case 'vhd':
- return 'vhdl';
-
- case 'patch':
- case 'diff':
- return 'diffu';
-
- default:
- return $ext;
- }
- }
-}
<?php
/**
* The Horde_Mime_Viewer_Srchighlite class renders out various content in HTML
- * format by using Source-highlight.
+ * 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/)
*
* 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
*/
-class Horde_Mime_Viewer_Srchighlite extends Horde_Mime_Viewer_Source
+class Horde_Mime_Viewer_Srchighlite extends Horde_Mime_Viewer_Driver
{
/**
* This driver's display capabilities.
{
$ret = $this->_renderInline();
- // Need Horde headers for CSS tags.
reset($ret);
- Horde::startBuffer();
- require $GLOBALS['registry']->get('templates', 'horde') . '/common-header.inc';
- echo $ret[key($ret)]['data'];
- require $GLOBALS['registry']->get('templates', 'horde') . '/common-footer.inc';
- $ret[key($ret)]['data'] = Horde::endBuffer();
+ $ret[key($ret)]['data'] = '<html><body>' .
+ $ret[key($ret)]['data'] .
+ '</body></html>';
return $ret;
}
$lang = $this->_typeToLang($this->_mimepart->getType());
/* Execute Source-Highlite. */
- exec($this->_conf['location'] . " --src-lang $lang --out-format xhtml --input $tmpin --output $tmpout");
+ exec($this->_conf['location'] . " --src-lang $lang --out-format html --input $tmpin --output $tmpout");
$results = file_get_contents($tmpout);
unlink($tmpout);
return array(
$this->_mimepart->getMimeId() => array(
- 'data' => $this->_lineNumber($results),
+ 'data' => $results,
'status' => array(),
'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset()
)
*/
protected function _typeToLang($type)
{
- // TODO: 'prolog', 'flex', 'changelog', 'ruby'
-
switch ($type) {
- case 'text/x-java':
- return 'java';
-
- case 'text/x-csrc':
- case 'text/x-c++src':
- case 'text/cpp':
- return 'cpp';
+ case 'application/x-javascript':
+ return 'js';
case 'application/x-perl':
return 'perl';
case 'application/x-httpd-php':
case 'application/x-httpd-php3':
case 'application/x-httpd-phps':
- return 'php3';
+ 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++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-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';
}
}
+
}
+++ /dev/null
-<?php
-/**
- * The Horde_Mime_Viewer_Webcpp class renders out various content in HTML
- * format by using Web C Plus Plus.
- *
- * Web C Plus plus: http://webcpp.sourceforge.net/
- *
- * Copyright 2002-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>
- * @category Horde
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @package Mime
- */
-class Horde_Mime_Viewer_Webcpp extends Horde_Mime_Viewer_Driver
-{
- /**
- * 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 Horde_Mime_Viewer_Driver::render().
- */
- protected function _render()
- {
- $ret = $this->_toHTML();
-
- /* The first 2 lines are the Content-Type line and a blank line so
- * remove them before outputting. */
- reset($ret);
- $ret[key($ret)]['data'] = preg_replace("/.*\n.*\n/", '', $ret[key($ret)]['data'], 1);
-
- return $ret;
- }
-
- /**
- * 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();
- reset($ret);
- $data = $ret[key($ret)]['data'];
-
- /* Extract the style sheet, removing any global body formatting
- * if we're displaying inline. */
- $res = preg_split(';(</style>)|(<style type="text/css">);', $data);
- $style = $res[1];
- $style = preg_replace('/\nbody\s+?{.*?}/s', '', $style);
-
- /* Extract the content. */
- $res = preg_split('/\<\/?pre\>/', $data);
- $body = $res[1];
-
- $ret[key($ret)]['data'] = '<style>' . $style . '</style><div class="webcpp" style="white-space:pre;font-family:Lucida Console,Courier,monospace;">' . $body . '</div>';
-
- return $ret;
- }
-
- /**
- * Converts the code to HTML.
- *
- * @return string The HTML-ified version of the MIME part contents.
- */
- protected function _toHTML()
- {
- /* 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. */
- $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(
- $this->_mimepart->getMimeId() => array(
- 'data' => $results,
- 'status' => array(),
- 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset()
- )
- );
- }
-}
* css CSS Styles
* deb Debian packages
* enriched Enriched text format
- * enscript GNU enscript
* html HTML data
* images Image files
* msword Microsoft Word files via AbiWord
* tgz Tarballs, including gzipped ones
* tnef MS-TNEF attachments
* vcard vCards
- * webcpp Web C Plus Plus
* wordperfect WordPerfect documents via wpd2html
* zip Zip files
*
/* The following mime drivers require external applications to be
* installed and are disabled by default. */
// 'deb',
- // 'enscript',
// 'msword',
// 'msexcel',
// 'mspowerpoint',
// 'rpm',
// 'rtf',
// 'srchighlite',
- // 'webcpp',
// 'wordperfect',
);
$mime_drivers['horde']['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-php',
+ 'x-extension/phps',
+ 'x-extension/php3s',
+ 'application/x-httpd-php',
+ 'application/x-httpd-php3',
'application/x-httpd-phps'
),
'icons' => array(
$mime_drivers['horde']['css'] = array(
'inline' => true,
'handles' => array(
- 'text/css', 'x-extension/css'
+ 'text/css',
+ 'x-extension/css'
),
'icons' => array(
'default' => 'html.png'
/**
- * Web C Plus Plus driver settings
- * http://webcpp.sourceforge.net/
- */
-$mime_drivers['horde']['webcpp'] = array(
- 'location' => '/usr/bin/webcpp',
- 'inline' => true,
- 'handles' => array(
- 'text/xml', 'text/sgml', 'application/xml', 'application/x-sh',
- 'application/x-javascript', 'application/x-tcl', 'x-extension/asm',
- 'application/x-asp', 'x-extension/bas', 'x-extension/cs',
- 'text/x-csrc', 'x-extension/rc', 'text/x-c++src', 'text/x-c++src',
- 'text/x-c++src', 'text/x-chdr', 'x-extension/bat', 'text/x-fortran',
- 'x-extension/f77', 'x-extension/f90', 'x-extension/for',
- 'x-extension/ftn', 'text/x-java', 'application/x-javascript',
- 'text/sgml', 'text/xml', 'text/x-pascal', 'application/x-cgi',
- 'application/x-perl', 'application/x-python', 'text/x-sql',
- 'text/x-tcl', 'application/x-shellscript', 'x-extension/vhd',
- 'x-extension/vhdl'
- ),
- 'icons' => array(
- 'default' => 'text.png',
- 'text/xml' => 'xml.png',
- 'text/x-csrc' => 'source-c.png',
- 'text/x-chdr' => 'source-h.png',
- 'text/x-java' => 'source-java.png',
- 'application/x-javascript' => 'script-js.png'
- )
-);
-
-
-/**
* Source-Highlight driver settings
* http://www.gnu.org/software/src-highlite/
*/
'location' => '/usr/bin/source-highlight',
'inline' => true,
'handles' => array(
- 'text/x-csrc', 'text/x-c++src', 'text/x-java', 'application/x-perl',
- 'application/x-python', 'text/x-c++src', 'text/cpp'
- ),
- 'icons' => array(
- 'default' => 'text.png',
- 'text/x-csrc' => 'source-c.png',
- 'text/x-c++src' => 'source-c.png',
- 'text/cpp' => 'source-c.png',
- 'text/x-java' => 'source-java.png'
- )
-);
-
-
-/**
- * GNU Enscript driver settings
- */
-$mime_drivers['horde']['enscript'] = array(
- 'location' => '/usr/bin/enscript',
- 'inline' => true,
- 'handles' => array(
- 'application/x-cgi', 'application/x-shellscript',
- 'application/x-javascript', 'application/x-perl', 'application/xml',
- 'text/xml', 'text/diff', 'text/x-diff', 'text/x-patch', 'text/x-csrc',
- 'x-extension/cs', 'text/x-java', 'text/x-chdr', 'text/x-c++src',
- 'text/x-c++hdr', 'x-extension/vhd', 'x-extension/vhdl', 'text/x-sql',
- 'x-extension/vb', 'x-extension/vba', 'text/x-emacs-lisp', 'text/x-tex'
+ 'application/x-httpd-php',
+ 'application/x-httpd-php3',
+ 'application/x-httpd-phps',
+ 'application/x-javascript',
+ 'application/x-perl',
+ 'application/x-php',
+ 'application/x-python',
+ 'application/x-ruby',
+ 'application/x-sh',
+ 'application/x-shellscript',
+ 'application/x-tcl',
+ 'application/xml',
+ 'text/cpp',
+ 'text/css',
+ 'text/diff',
+ 'text/x-c++hdr',
+ 'text/x-c++src',
+ '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/cs',
+ 'x-extension/css'
+ 'x-extension/f77',
+ 'x-extension/f90',
+ 'x-extension/for',
+ 'x-extension/ftn',
+ 'x-extension/php3s',
+ 'x-extension/phps',
+ 'x-extension/rc',
+ 'x-extension/vb',
+ 'x-extension/vba'
),
'icons' => array(
- 'default' => 'text.png',
- 'text/xml' => 'xml.png',
- 'application/xml' => 'xml.png',
- 'text/x-csrc' => 'source-c.png',
- 'text/x-chdr' => 'source-h.png',
- 'text/x-java' => 'source-java.png',
- 'application/x-javascript' => 'script-js.png'
+ 'default' => 'text.png',
+ 'application/x-httpd-php' => 'php.png',
+ 'application/x-httpd-php3' => 'php.png',
+ 'application/x-httpd-phps' => 'php.png',
+ 'application/x-javascript' => 'script-js.png',
+ 'application/x-php' => 'php.png',
+ 'application/x-python' => 'source-python.png',
+ 'application/x-sh' => 'shell.png',
+ 'application/x-shellscript' => 'shell.png',
+ 'application/xml' => 'xml.png',
+ 'text/cpp' => 'source-c.png',
+ 'text/css' => 'html.png',
+ 'text/x-c++hdr' => 'source-c.png',
+ 'text/x-c++src' => 'source-c.png',
+ 'text/x-chdr' => 'source-h.png',
+ 'text/x-csrc' => 'source-c.png',
+ 'text/x-java' => 'source-java.png',
+ 'text/x-sql' => 'sql.png',
+ 'text/xml' => 'xml.png',
+ 'x-extension/css' => 'html.png',
+ 'x-extension/php3s' => 'php.png',
+ 'x-extension/phps' => 'php.png',
+ 'x-extension/rc' => 'xml.png'
)
);
$mime_drivers['horde']['tgz'] = array(
'inline' => true,
'handles' => array(
- 'application/x-compressed-tar', 'application/x-tar',
- 'application/x-tgz', 'application/x-gzip', 'application/x-gtar',
- 'application/gzip', 'application/x-gzip-compressed'
+ 'application/gzip',
+ 'application/x-compressed-tar',
+ 'application/x-gtar',
+ 'application/x-gzip',
+ 'application/x-gzip-compressed',
+ 'application/x-tar',
+ 'application/x-tgz'
),
'icons' => array(
'default' => 'compressed.png'
$mime_drivers['horde']['zip'] = array(
'inline' => true,
'handles' => array(
- 'application/zip', 'application/x-compressed',
- 'application/x-zip-compressed'
+ 'application/x-compressed',
+ 'application/x-zip-compressed',
+ 'application/zip'
),
'icons' => array(
'default' => 'compressed.png'
$mime_drivers['horde']['rar'] = array(
'inline' => true,
'handles' => array(
- 'application/x-rar', 'application/x-rar-compressed'
+ 'application/x-rar',
+ 'application/x-rar-compressed'
),
'icons' => array(
'default' => 'compressed.png'
'location' => '/usr/bin/abiword',
'inline' => false,
'handles' => array(
- 'application/vnd.ms-word', 'application/msword'
+ 'application/msword',
+ 'application/vnd.ms-word'
),
'icons' => array(
'default' => 'msword.png'
'location' => '/usr/bin/ssconvert',
'inline' => false,
'handles' => array(
- 'application/vnd.ms-excel', 'application/msexcel',
- 'application/x-msexcel'
+ 'application/msexcel',
+ 'application/x-msexcel',
+ 'application/vnd.ms-excel'
),
'icons' => array(
'default' => 'msexcel.png'
'location' => '/usr/bin/ppthtml',
'inline' => false,
'handles' => array(
- 'application/vnd.ms-powerpoint', 'application/mspowerpoint'
+ 'application/mspowerpoint',
+ 'application/vnd.ms-powerpoint'
),
'icons' => array(
'default' => 'mspowerpoint.png'
*/
$mime_drivers['horde']['vcard'] = array(
'handles' => array(
- 'text/vcard', 'text/x-vcard', 'text/directory'
+ 'text/directory',
+ 'text/vcard',
+ 'text/x-vcard'
),
'icons' => array(
'default' => 'vcard.png'
'location' => '/usr/bin/dpkg',
'inline' => false,
'handles' => array(
- 'application/x-deb', 'application/x-debian-package'
+ 'application/x-deb',
+ 'application/x-debian-package'
),
'icons' => array(
'default' => 'deb.png'
$mime_drivers['horde']['security'] = array(
'inline' => true,
'handles' => array(
- 'multipart/encrypted', 'multipart/signed'
+ 'multipart/encrypted',
+ 'multipart/signed'
),
'icons' => array(
'default' => 'encryption.png'
$mime_drivers['horde']['rfc822'] = array(
'inline' => false,
'handles' => array(
- 'message/rfc822', 'x-extension/eml'
+ 'message/rfc822',
+ 'x-extension/eml'
),
'icons' => array(
'default' => 'mail.png'
/* This setting is irrelevant - PDF files can not be displayed inline. */
'inline' => false,
'handles' => array(
- 'application/pdf', 'application/x-pdf', 'image/pdf'
+ 'application/pdf',
+ 'application/x-pdf',
+ 'image/pdf'
),
'icons' => array(
'default' => 'pdf.png'
'location' => '/usr/bin/unrtf',
'inline' => false,
'handles' => array(
- 'text/rtf', 'application/rtf'
+ 'application/rtf',
+ 'text/rtf'
),
'icons' => array(
'default' => 'text.png'
'location' => '/usr/bin/wpd2html',
'inline' => false,
'handles' => array(
- 'application/vnd.wordperfect', 'application/wordperf',
- 'application/wordperfect', 'application/wpd', 'application/x-wpwin'
+ 'application/vnd.wordperfect',
+ 'application/wordperf',
+ 'application/wordperfect',
+ 'application/wpd',
+ 'application/x-wpwin'
),
'icons' => array(
'default' => 'wordperfect.png'