[ Index ]
 

Code source de Horde 3.1.3

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/Horde/MIME/Viewer/ -> srchighlite.php (source)

   1  <?php
   2  
   3  require_once dirname(__FILE__) . '/source.php';
   4  
   5  /**
   6   * The MIME_Viewer_srchighlite class renders out various content in HTML
   7   * format by using Source-highlight.
   8   *
   9   * Source-highlight: http://www.gnu.org/software/src-highlite/
  10   *
  11   * $Horde: framework/MIME/MIME/Viewer/srchighlite.php,v 1.14.10.8 2006/06/01 03:08:53 chuck Exp $
  12   *
  13   * Copyright 2003-2006 Mike Cochrane <mike@graftonhall.co.nz>
  14   *
  15   * See the enclosed file COPYING for license information (LGPL). If you did
  16   * not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  17   *
  18   * @author  Mike Cochrane <mike@graftonhall.co.nz>
  19   * @since   Horde 3.0
  20   * @package Horde_MIME_Viewer
  21   */
  22  class MIME_Viewer_srchighlite extends MIME_Viewer_source {
  23  
  24      /**
  25       * Render out the currently set contents using Source-highlight
  26       *
  27       * @param array $params  Any parameters the viewer may need.
  28       *
  29       * @return string  The rendered contents.
  30       */
  31      function render($params = array())
  32      {
  33          global $mime_drivers;
  34  
  35          /* Check to make sure the program actually exists. */
  36          if (!file_exists($mime_drivers['horde']['srchighlite']['location'])) {
  37              return '<pre>' . sprintf(_("The program used to view this data type (%s) was not found on the system."), $mime_drivers['horde']['srchighlite']['location']) . '</pre>';
  38          }
  39  
  40          /* Create temporary files for Webcpp. */
  41          $tmpin  = Horde::getTempFile('SrcIn');
  42          $tmpout = Horde::getTempFile('SrcOut', false);
  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          /* Determine the language from the mime type. */
  51          $lang = '';
  52          switch ($this->mime_part->getType()) {
  53          case 'text/x-java':
  54              $lang = 'java';
  55              break;
  56  
  57          case 'text/x-csrc':
  58          case 'text/x-c++src':
  59          case 'text/cpp':
  60              $lang = 'cpp';
  61              break;
  62  
  63          case 'application/x-perl':
  64              $lang = 'perl';
  65              break;
  66  
  67          case 'application/x-php':
  68          case 'x-extension/phps':
  69          case 'x-extension/php3s':
  70          case 'application/x-httpd-php':
  71          case 'application/x-httpd-php3':
  72          case 'application/x-httpd-phps':
  73              $lang = 'php3';
  74              break;
  75  
  76          case 'application/x-python':
  77              $lang = 'python';
  78              break;
  79  
  80              // $lang = 'prolog';
  81              // break;
  82  
  83              // $lang = 'flex';
  84              // break;
  85  
  86              // $lang = 'changelog';
  87              // break;
  88  
  89              // $lang = 'ruby';
  90              // break;
  91          }
  92  
  93          /* Execute Source-Highlite. */
  94          exec($mime_drivers['horde']['srchighlite']['location'] . " --src-lang $lang --out-format xhtml --input $tmpin --output $tmpout");
  95          $results = file_get_contents($tmpout);
  96          unlink($tmpout);
  97  
  98          /* Educated Guess at whether we are inline or not. */
  99          if (headers_sent() || ob_get_length()) {
 100              return $this->lineNumber($results);
 101          } else {
 102              return Util::bufferOutput('require', $GLOBALS['registry']->get('templates', 'horde') . '/common-header.inc') .
 103                  $this->lineNumber($results) .
 104                  Util::bufferOutput('require', $GLOBALS['registry']->get('templates', 'horde') . '/common-footer.inc');
 105          }
 106      }
 107  
 108  }


Généré le : Sun Feb 25 18:01:28 2007 par Balluche grâce à PHPXref 0.7