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

   1  <?php
   2  /**
   3   * The MIME_Viewer_tgz class renders out plain or gzipped tarballs in HTML.
   4   *
   5   * $Horde: framework/MIME/MIME/Viewer/tgz.php,v 1.37.10.13 2006/01/26 10:22:46 jan Exp $
   6   *
   7   * Copyright 1999-2006 Anil Madhavapeddy <anil@recoil.org>
   8   * Copyright 2002-2006 Michael Cochrane <mike@graftonhall.co.nz>
   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   * @author  Michael Cochrane <mike@graftonhall.co.nz>
  15   * @since   Horde 1.3
  16   * @package Horde_MIME_Viewer
  17   */
  18  class MIME_Viewer_tgz extends MIME_Viewer {
  19  
  20      /**
  21       * Render out the currently set tar file contents.
  22       *
  23       * @param array $params  Any parameters the Viewer may need.
  24       *
  25       * @return string  The rendered contents.
  26       */
  27      function render($params = array())
  28      {
  29          require_once 'Horde/Compress.php';
  30  
  31          $contents = $this->mime_part->getContents();
  32  
  33          /* Only decompress gzipped files. */
  34          $subtype = $this->mime_part->getSubType();
  35          if (($subtype == 'x-compressed-tar') ||
  36              ($subtype == 'tgz') ||
  37              ($subtype == 'x-tgz') ||
  38              ($subtype == 'gzip') ||
  39              ($subtype == 'x-gzip') ||
  40              ($subtype == 'x-gzip-compressed') ||
  41              ($subtype == 'x-gtar')) {
  42              $gzip = &Horde_Compress::singleton('gzip');
  43              $contents = $gzip->decompress($contents);
  44              if (empty($contents)) {
  45                  return '<pre>' . _("Unable to open compressed archive.") . '</pre>';
  46              } elseif (is_a($contents, 'PEAR_Error')) {
  47                  return '<pre>' . $contents->getMessage() . '</pre>';
  48              }
  49          }
  50  
  51          if ($subtype == 'gzip' ||
  52              $subtype == 'x-gzip' ||
  53              $subtype == 'x-gzip-compressed') {
  54              global $conf;
  55              require_once 'Horde/MIME/Magic.php';
  56              $mime_type = MIME_Magic::analyzeData($contents, isset($conf['mime']['magic_db']) ? $conf['mime']['magic_db'] : null);
  57              if (!$mime_type) {
  58                  $mime_type = _("Unknown");
  59              }
  60              return '<pre>' . _("Content type of compressed file: ") . $mime_type . '</pre>';
  61          }
  62  
  63          /* Obtain the list of files/data in the tar file. */
  64          $tar = &Horde_Compress::singleton('tar');
  65  
  66          $tarData = $tar->decompress($contents);
  67          if (is_a($tarData, 'PEAR_Error')) {
  68              return '<pre>' . $tarData->getMessage() . '</pre>';
  69          }
  70  
  71          $fileCount = count($tarData);
  72  
  73          include_once 'Horde/Text.php';
  74  
  75          $text  = '<strong>' . htmlspecialchars(sprintf(_("Contents of \"%s\""), $this->mime_part->getName())) . ':</strong>' . "\n";
  76          $text .= '<table><tr><td align="left"><tt><span class="fixed">';
  77          $text .= Text::htmlAllSpaces(_("Archive Name") . ':  ' . $this->mime_part->getName()) . "\n";
  78          $text .= Text::htmlAllSpaces(_("Archive File Size") . ': ' . strlen($contents) . ' bytes') . "\n";
  79          $text .= Text::htmlAllSpaces(($fileCount != 1) ? sprintf(_("File Count: %s files"), $fileCount) : sprintf(_("File Count: %s file"), $fileCount));
  80          $text .= "\n\n";
  81          $text .= Text::htmlAllSpaces(
  82                       str_pad(_("File Name"),     62, ' ', STR_PAD_RIGHT) .
  83                       str_pad(_("Attributes"),    15, ' ', STR_PAD_LEFT) .
  84                       str_pad(_("Size"),          10, ' ', STR_PAD_LEFT) .
  85                       str_pad(_("Modified Date"), 19, ' ', STR_PAD_LEFT)
  86                   ) . "\n";
  87  
  88          $text .= str_repeat('-', 106) . "\n";
  89  
  90          foreach ($tarData as $val) {
  91             $text .= Text::htmlAllSpaces(
  92                          str_pad($val['name'], 62, ' ', STR_PAD_RIGHT) .
  93                          str_pad($val['attr'], 15, ' ', STR_PAD_LEFT) .
  94                          str_pad($val['size'], 10, ' ', STR_PAD_LEFT) .
  95                          str_pad(strftime("%d-%b-%Y %H:%M", $val['date']), 19, ' ', STR_PAD_LEFT)
  96                      ) . "\n";
  97          }
  98  
  99          $text .= str_repeat('-', 106) . "\n";
 100          $text .= '</span></tt></td></tr></table>';
 101  
 102          return nl2br($text);
 103      }
 104  
 105      /**
 106       * Return the content-type
 107       *
 108       * @return string  The content-type of the output.
 109       */
 110      function getType()
 111      {
 112          return 'text/html; charset=' . NLS::getCharset();
 113      }
 114  
 115  }


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