[ Index ] |
|
Code source de Horde 3.1.3 |
1 <?php 2 /** 3 * The MIME_Viewer_webcpp class renders out various content 4 * in HTML format by using Web C Plus Plus. 5 * 6 * Web C Plus plus: http://webcpp.sourceforge.net/ 7 * 8 * $Horde: framework/MIME/MIME/Viewer/webcpp.php,v 1.11.10.8 2006/01/01 21:28:25 jan Exp $ 9 * 10 * Copyright 2002-2006 Mike Cochrane <mike@graftonhall.co.nz> 11 * 12 * See the enclosed file COPYING for license information (LGPL). If you 13 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. 14 * 15 * @author Mike Cochrane <mike@graftonhall.co.nz> 16 * @since Horde 3.0 17 * @package Horde_MIME_Viewer 18 */ 19 class MIME_Viewer_webcpp extends MIME_Viewer { 20 21 /** 22 * Render out the currently set contents using Web C Plus Plus. 23 * 24 * @param array $params Any parameters the Viewer may need. 25 * 26 * @return string The rendered contents. 27 */ 28 function render($params = array()) 29 { 30 global $mime_drivers; 31 32 require_once 'Horde/MIME/Contents.php'; 33 $attachment = MIME_Contents::viewAsAttachment(); 34 35 /* Check to make sure the program actually exists. */ 36 if (!file_exists($mime_drivers['horde']['webcpp']['location'])) { 37 return '<pre>' . sprintf(_("The program used to view this data type (%s) was not found on the system."), $mime_drivers['horde']['webcpp']['location']) . '</pre>'; 38 } 39 40 /* Create temporary files for Webcpp. */ 41 $tmpin = Horde::getTempFile('WebcppIn'); 42 $tmpout = Horde::getTempFile('WebcppOut'); 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 /* Get the extension for the mime type. */ 51 include_once 'Horde/MIME/Magic.php'; 52 $ext = MIME_Magic::MIMEToExt($this->mime_part->getType()); 53 54 /* Execute Web C Plus Plus. Specifying the in and out files didn't 55 work for me but pipes did. */ 56 exec($mime_drivers['horde']['webcpp']['location'] . " --pipe --pipe -x=$ext -l -a -t < $tmpin > $tmpout"); 57 $results = file_get_contents($tmpout); 58 59 /* If we are not displaying inline, all the formatting is already 60 * done for us. */ 61 if ($attachment) { 62 /* The first 2 lines are the Content-Type line and a blank line 63 * so we should remove them before outputting. */ 64 return preg_replace("/.*\n.*\n/", '', $results, 1); 65 } 66 67 /* Extract the style sheet, removing any global body formatting 68 * if we're displaying inline. */ 69 $res = preg_split(';(</style>)|(<style type="text/css">);', $results); 70 $style = $res[1]; 71 $style = preg_replace('/\nbody\s+?{.*?}/s', '', $style); 72 73 /* Extract the content. */ 74 $res = preg_split('/\<\/?pre\>/', $results); 75 $body = $res[1]; 76 77 return '<style>' . $style . '</style><div class="webcpp" style="white-space:pre;font-family:monospace">' . $body . '</div>'; 78 } 79 80 /** 81 * Return the MIME content type of the rendered content. 82 * 83 * @return string The content type of the output. 84 */ 85 function getType() 86 { 87 return 'text/html; charset=' . NLS::getCharset(); 88 } 89 90 }
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 |