[ Index ] |
|
Code source de Horde 3.1.3 |
1 <?php 2 3 require_once dirname(__FILE__) . '/source.php'; 4 5 /** 6 * The MIME_Viewer_enscript class renders out various content 7 * in HTML format by using GNU Enscript. 8 * 9 * $Horde: framework/MIME/MIME/Viewer/enscript.php,v 1.39.10.8 2006/06/01 03:08:53 chuck Exp $ 10 * 11 * Copyright 1999-2006 Anil Madhavapeddy <anil@recoil.org> 12 * 13 * See the enclosed file COPYING for license information (LGPL). If you 14 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. 15 * 16 * @author Anil Madhavapeddy <anil@recoil.org> 17 * @since Horde 1.3 18 * @package Horde_MIME_Viewer 19 */ 20 class MIME_Viewer_enscript extends MIME_Viewer_source { 21 22 /** 23 * Render out the data using Enscript. 24 * 25 * @param array $params Any parameters the Viewer may need. 26 * 27 * @return string The rendered data. 28 */ 29 function render($params = array()) 30 { 31 global $mime_drivers; 32 33 /* Check to make sure the program actually exists. */ 34 if (!file_exists($mime_drivers['horde']['enscript']['location'])) { 35 return '<pre>' . sprintf(_("The program used to view this data type (%s) was not found on the system."), $mime_drivers['horde']['enscript']['location']) . '</pre>'; 36 } 37 38 /* Create temporary files for input to Enscript. Note that we 39 cannot use a pipe, since enscript must have access to the 40 whole file to determine its type for coloured syntax 41 highlighting. */ 42 $tmpin = Horde::getTempFile('EnscriptIn'); 43 44 /* Write the contents of our buffer to the temporary input file. */ 45 $contents = $this->mime_part->getContents(); 46 $fh = fopen($tmpin, 'wb'); 47 fwrite($fh, $contents, strlen($contents)); 48 fclose($fh); 49 50 /* Execute the enscript command. */ 51 $lang = escapeshellarg($this->_typeToLang($this->mime_part->getType())); 52 $results = shell_exec($mime_drivers['horde']['enscript']['location'] . " -E$lang --language=html --color --output=- < $tmpin"); 53 54 /* Strip out the extraneous HTML from Enscript, and output it. */ 55 $res_arr = preg_split('/\<\/?pre\>/i', $results); 56 if (count($res_arr) == 3) { 57 $results = trim($res_arr[1]); 58 } 59 60 /* Educated Guess at whether we are inline or not. */ 61 if (headers_sent() || ob_get_length()) { 62 return $this->lineNumber($results); 63 } else { 64 return Util::bufferOutput('require', $GLOBALS['registry']->get('templates', 'horde') . '/common-header.inc') . 65 $this->lineNumber($results) . 66 Util::bufferOutput('require', $GLOBALS['registry']->get('templates', 'horde') . '/common-footer.inc'); 67 } 68 } 69 70 /** 71 * Attempts to determine what language to use for the enscript program 72 * from a MIME type. 73 * 74 * @access private 75 * 76 * @param string $type The MIME type. 77 * 78 * @return string The enscript 'language' parameter string. 79 */ 80 function _typeToLang($type) 81 { 82 include_once dirname(__FILE__) . '/../Magic.php'; 83 84 $ext = MIME_Magic::MIMEToExt($type); 85 86 switch ($ext) { 87 case 'cs': 88 return 'java'; 89 90 case 'el': 91 return 'elisp'; 92 93 case 'h': 94 return 'c'; 95 96 case 'C': 97 case 'H': 98 case 'cc': 99 case 'hh': 100 case 'c++': 101 case 'cxx': 102 case 'cpp': 103 return 'cpp'; 104 105 case 'htm': 106 case 'shtml': 107 case 'xml': 108 return 'html'; 109 110 case 'js': 111 return 'javascript'; 112 113 case 'pas': 114 return 'pascal'; 115 116 case 'al': 117 case 'cgi': 118 case 'pl': 119 case 'pm': 120 return 'perl'; 121 122 case 'ps': 123 return 'postscript'; 124 125 case 'vb': 126 return 'vba'; 127 128 case 'vhd': 129 return 'vhdl'; 130 131 case 'patch': 132 case 'diff': 133 return 'diffu'; 134 135 default: 136 return $ext; 137 } 138 } 139 140 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 18:01:28 2007 | par Balluche grâce à PHPXref 0.7 |