From: Michael M Slusarz Date: Mon, 26 Jul 2010 06:02:52 +0000 (-0600) Subject: One source driver viewer. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=23472425ab20835f7899c928e78fd1c361d565cc;p=horde.git One source driver viewer. Remove Webcpp and Enscript drivers. Use a single driver (GNU source-highlight) to render code data. --- diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Enscript.php b/framework/Mime/lib/Horde/Mime/Viewer/Enscript.php deleted file mode 100644 index 144310272..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Enscript.php +++ /dev/null @@ -1,161 +0,0 @@ - - * @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; - } - } -} diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Srchighlite.php b/framework/Mime/lib/Horde/Mime/Viewer/Srchighlite.php index b9e381298..35949a0d9 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/Srchighlite.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/Srchighlite.php @@ -1,9 +1,10 @@ + * @author Michael Slusarz * @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. @@ -38,13 +40,10 @@ class Horde_Mime_Viewer_Srchighlite extends Horde_Mime_Viewer_Source { $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'] = '' . + $ret[key($ret)]['data'] . + ''; return $ret; } @@ -73,13 +72,13 @@ class Horde_Mime_Viewer_Srchighlite extends Horde_Mime_Viewer_Source $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() ) @@ -96,16 +95,9 @@ class Horde_Mime_Viewer_Srchighlite extends Horde_Mime_Viewer_Source */ 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'; @@ -116,10 +108,78 @@ class Horde_Mime_Viewer_Srchighlite extends Horde_Mime_Viewer_Source 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'; } } + } diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Webcpp.php b/framework/Mime/lib/Horde/Mime/Viewer/Webcpp.php deleted file mode 100644 index 70e35648d..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Webcpp.php +++ /dev/null @@ -1,111 +0,0 @@ - - * @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(';()|(
' . $body . '
'; - - 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() - ) - ); - } -} diff --git a/framework/Mime/package.xml b/framework/Mime/package.xml index a1ad7b145..706ecaa39 100644 --- a/framework/Mime/package.xml +++ b/framework/Mime/package.xml @@ -31,7 +31,9 @@ http://pear.php.net/dtd/package-2.0.xsd"> alpha LGPL - * No need to generate Content-Transfer-Encoding header if part data is 7bit. + * Removed Webcpp and Enscript viewers. Source code highlighting is now + exclusively handled by the Srchighlight driver. + * No need to generate Content-Transfer-Encoding header if part data is 7bit. * Default disposition should be empty by default, not inline (RFC 2183 [2]). * Request #8556: Allow specifying a header charset for a part. * Add 'raw' render view to Horde_Mime_Viewer. @@ -68,7 +70,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> - @@ -92,7 +93,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> - @@ -231,7 +231,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> - @@ -255,7 +254,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> - diff --git a/horde/config/mime_drivers.php.dist b/horde/config/mime_drivers.php.dist index d9d641062..8430ef1e5 100644 --- a/horde/config/mime_drivers.php.dist +++ b/horde/config/mime_drivers.php.dist @@ -10,7 +10,6 @@ * 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 @@ -34,7 +33,6 @@ * tgz Tarballs, including gzipped ones * tnef MS-TNEF attachments * vcard vCards - * webcpp Web C Plus Plus * wordperfect WordPerfect documents via wpd2html * zip Zip files * @@ -48,14 +46,12 @@ $mime_drivers_map['horde']['registered'] = array( /* 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', ); @@ -166,8 +162,11 @@ $mime_drivers['horde']['smil'] = array( $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( @@ -182,7 +181,8 @@ $mime_drivers['horde']['php'] = 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' @@ -236,37 +236,6 @@ $mime_drivers['horde']['richtext'] = array( /** - * 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/ */ @@ -274,41 +243,72 @@ $mime_drivers['horde']['srchighlite'] = array( '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' ) ); @@ -321,9 +321,13 @@ $mime_drivers['horde']['enscript'] = array( $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' @@ -337,8 +341,9 @@ $mime_drivers['horde']['tgz'] = array( $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' @@ -352,7 +357,8 @@ $mime_drivers['horde']['zip'] = array( $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' @@ -369,7 +375,8 @@ $mime_drivers['horde']['msword'] = array( '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' @@ -386,8 +393,9 @@ $mime_drivers['horde']['msexcel'] = array( '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' @@ -404,7 +412,8 @@ $mime_drivers['horde']['mspowerpoint'] = array( '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' @@ -417,7 +426,9 @@ $mime_drivers['horde']['mspowerpoint'] = array( */ $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' @@ -447,7 +458,8 @@ $mime_drivers['horde']['deb'] = array( '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' @@ -461,7 +473,8 @@ $mime_drivers['horde']['deb'] = array( $mime_drivers['horde']['security'] = array( 'inline' => true, 'handles' => array( - 'multipart/encrypted', 'multipart/signed' + 'multipart/encrypted', + 'multipart/signed' ), 'icons' => array( 'default' => 'encryption.png' @@ -503,7 +516,8 @@ $mime_drivers['horde']['tnef'] = array( $mime_drivers['horde']['rfc822'] = array( 'inline' => false, 'handles' => array( - 'message/rfc822', 'x-extension/eml' + 'message/rfc822', + 'x-extension/eml' ), 'icons' => array( 'default' => 'mail.png' @@ -575,7 +589,9 @@ $mime_drivers['horde']['pdf'] = array( /* 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' @@ -592,7 +608,8 @@ $mime_drivers['horde']['rtf'] = array( 'location' => '/usr/bin/unrtf', 'inline' => false, 'handles' => array( - 'text/rtf', 'application/rtf' + 'application/rtf', + 'text/rtf' ), 'icons' => array( 'default' => 'text.png' @@ -609,8 +626,11 @@ $mime_drivers['horde']['wordperfect'] = array( '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' diff --git a/horde/docs/UPGRADING b/horde/docs/UPGRADING index 3fa3bf659..a2240a9ed 100644 --- a/horde/docs/UPGRADING +++ b/horde/docs/UPGRADING @@ -47,6 +47,8 @@ Removed support for dBase, Frontbase, and mSQL database servers. Removed support for krb5 authentication driver. +Removed Mime Viewer drivers: Enscript & Webcpp. Use 'Srchighlite' instead. + Upgrading Horde from 3.3.x to 3.3.5 ===================================