[ 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/ -> msword.php (source)

   1  <?php
   2  /**
   3   * The MIME_Viewer_msword class renders out Microsoft Word
   4   * documents in HTML format by using the wvWare package.
   5   *
   6   * $Horde: framework/MIME/MIME/Viewer/msword.php,v 1.25.10.8 2006/01/01 21:28:25 jan Exp $
   7   *
   8   * Copyright 1999-2006 Anil Madhavapeddy <anil@recoil.org>
   9   *
  10   * See the enclosed file COPYING for license information (LGPL). If you
  11   * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  12   *
  13   * @author  Anil Madhavapeddy <anil@recoil.org>
  14   * @since   Horde 1.3
  15   * @package Horde_MIME_Viewer
  16   */
  17  class MIME_Viewer_msword extends MIME_Viewer {
  18  
  19      /**
  20       * Render out the current data using wvWare.
  21       *
  22       * @param array $params  Any parameters the Viewer may need.
  23       *
  24       * @return string  The rendered contents.
  25       */
  26      function render($params = array())
  27      {
  28          global $mime_drivers;
  29  
  30          /* Check to make sure the program actually exists. */
  31          if (!file_exists($mime_drivers['horde']['msword']['location'])) {
  32              return '<pre>' . sprintf(_("The program used to view this data type (%s) was not found on the system."), $mime_drivers['horde']['msword']['location']) . '</pre>';
  33          }
  34  
  35          $data = '';
  36          $tmp_word   = Horde::getTempFile('msword');
  37          $tmp_output = Horde::getTempFile('msword');
  38          $tmp_dir    = Horde::getTempDir();
  39          $tmp_file   = str_replace($tmp_dir . '/', '', $tmp_output);
  40  
  41          if (OS_WINDOWS) {
  42              $args = ' -x ' . dirname($mime_drivers['horde']['msword']['location']) . "\\wvHtml.xml -d $tmp_dir -1 $tmp_word > $tmp_output";
  43          } else {
  44              $version = exec($mime_drivers['horde']['msword']['location'] . ' --version');
  45              if (version_compare($version, '0.7.0') >= 0) {
  46                  $args = " --charset=" . NLS::getCharset() . " --targetdir=$tmp_dir $tmp_word $tmp_file";
  47              } else {
  48                  $args = " $tmp_word $tmp_output";
  49              }
  50          }
  51  
  52          $fh = fopen($tmp_word, 'w');
  53          fwrite($fh, $this->mime_part->getContents());
  54          fclose($fh);
  55  
  56          exec($mime_drivers['horde']['msword']['location'] . $args);
  57  
  58          if (!file_exists($tmp_output)) {
  59              return _("Unable to translate this Word document");
  60          }
  61  
  62          $fh = fopen($tmp_output, 'r');
  63          while (($rc = fgets($fh, 8192))) {
  64              $data .= $rc;
  65          }
  66          fclose($fh);
  67  
  68          return $data;
  69      }
  70  
  71      /**
  72       * Return the MIME content type of the rendered content.
  73       *
  74       * @return string  The content type of the output.
  75       */
  76      function getType()
  77      {
  78          return 'text/html; charset=' . NLS::getCharset();
  79      }
  80  
  81  }


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