[ Indice ]

Riferimento incrociato di Joomla! 1.5.14 - VM 1.1.4

Servizio fornito da VMItalia
Classe:   Funzione:   Variabile:   Costante:  
Storico Ricerche +

titolo

Corpo

[chiudi]

/libraries/joomla/filesystem/archive/ -> tar.php (sorgente)

   1  <?php
   2  /**
   3   * @version        $Id:tar.php 6961 2007-03-15 16:06:53Z tcp $
   4   * @package        Joomla.Framework
   5   * @subpackage    FileSystem
   6   * @copyright    Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
   7   * @license        GNU/GPL, see LICENSE.php
   8   * Joomla! is free software. This version may have been modified pursuant
   9   * to the GNU General Public License, and as distributed it includes or
  10   * is derivative of works licensed under the GNU General Public License or
  11   * other free or open source software licenses.
  12   * See COPYRIGHT.php for copyright notices and details.
  13   */
  14  
  15  // Check to ensure this file is within the rest of the framework
  16  defined('JPATH_BASE') or die();
  17  
  18  /**
  19   * Tar format adapter for the JArchive class
  20   *
  21   * This class is inspired from and draws heavily in code and concept from the Compress package of
  22   * The Horde Project <http://www.horde.org>
  23   *
  24   * @contributor  Michael Slusarz <slusarz@horde.org>
  25   * @contributor  Michael Cochrane <mike@graftonhall.co.nz>
  26   *
  27   * @package     Joomla.Framework
  28   * @subpackage    FileSystem
  29   * @since        1.5
  30   */
  31  class JArchiveTar extends JObject
  32  {
  33      /**
  34       * Tar file types.
  35       * @var array
  36       */
  37      var $_types = array (
  38          0x0 => 'Unix file',
  39          0x30 => 'File',
  40          0x31 => 'Link',
  41          0x32 => 'Symbolic link',
  42          0x33 => 'Character special file',
  43          0x34 => 'Block special file',
  44          0x35 => 'Directory',
  45          0x36 => 'FIFO special file',
  46          0x37 => 'Contiguous file'
  47      );
  48  
  49      /**
  50       * Tar file flags.
  51       * @var array
  52       */
  53      var $_flags = array (
  54          'FTEXT' => 0x01,
  55          'FHCRC' => 0x02,
  56          'FEXTRA' => 0x04,
  57          'FNAME' => 0x08,
  58          'FCOMMENT' => 0x10
  59      );
  60  
  61      /**
  62       * Tar file data buffer
  63       * @var string
  64       */
  65      var $_data = null;
  66  
  67      /**
  68       * Tar file metadata array
  69       * @var array
  70       */
  71      var $_metadata = null;
  72  
  73      /**
  74      * Extract a ZIP compressed file to a given path
  75      *
  76      * @access    public
  77      * @param    string    $archive        Path to ZIP archive to extract
  78      * @param    string    $destination    Path to extract archive into
  79      * @param    array    $options        Extraction options [unused]
  80      * @return    boolean    True if successful
  81      * @since    1.5
  82      */
  83  	function extract($archive, $destination, $options = array ())
  84      {
  85          // Initialize variables
  86          $this->_data = null;
  87          $this->_metadata = null;
  88  
  89          if (!$this->_data = JFile::read($archive))
  90          {
  91              $this->set('error.message', 'Unable to read archive');
  92              return JError::raiseWarning(100, $this->get('error.message'));
  93          }
  94  
  95          if (!$this->_getTarInfo($this->_data))
  96          {
  97              return JError::raiseWarning(100, $this->get('error.message'));
  98          }
  99  
 100          for ($i=0,$n=count($this->_metadata);$i<$n;$i++)
 101          {
 102              $type    = strtolower( $this->_metadata[$i]['type'] );
 103              if ($type == 'file' || $type == 'unix file')
 104              {
 105                  $buffer = $this->_metadata[$i]['data'];
 106                  $path = JPath::clean($destination.DS.$this->_metadata[$i]['name']);
 107                  // Make sure the destination folder exists
 108                  if (!JFolder::create(dirname($path)))
 109                  {
 110                      $this->set('error.message', 'Unable to create destination');
 111                      return JError::raiseWarning(100, $this->get('error.message'));
 112                  }
 113                  if (JFile::write($path, $buffer) === false)
 114                  {
 115                      $this->set('error.message', 'Unable to write entry');
 116                      return JError::raiseWarning(100, $this->get('error.message'));
 117                  }
 118              }
 119          }
 120          return true;
 121      }
 122  
 123      /**
 124       * Get the list of files/data from a Tar archive buffer.
 125       *
 126       * @access    private
 127       * @param     string    $data    The Tar archive buffer.
 128       * @return    array    Archive metadata array
 129       * <pre>
 130       * KEY: Position in the array
 131       * VALUES: 'attr'  --  File attributes
 132       *         'data'  --  Raw file contents
 133       *         'date'  --  File modification time
 134       *         'name'  --  Filename
 135       *         'size'  --  Original file size
 136       *         'type'  --  File type
 137       * </pre>
 138       * @since    1.5
 139       */
 140  	function _getTarInfo(& $data)
 141      {
 142          $position = 0;
 143          $return_array = array ();
 144  
 145          while ($position < strlen($data))
 146          {
 147              $info = @ unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/Ctypeflag/a100link/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor", substr($data, $position));
 148              if (!$info) {
 149                  $this->set('error.message', 'Unable to decompress data');
 150                  return false;
 151              }
 152  
 153              $position += 512;
 154              $contents = substr($data, $position, octdec($info['size']));
 155              $position += ceil(octdec($info['size']) / 512) * 512;
 156  
 157              if ($info['filename']) {
 158                  $file = array (
 159                      'attr' => null,
 160                      'data' => null,
 161                      'date' => octdec($info['mtime']
 162                  ), 'name' => trim($info['filename']), 'size' => octdec($info['size']), 'type' => isset ($this->_types[$info['typeflag']]) ? $this->_types[$info['typeflag']] : null);
 163  
 164                  if (($info['typeflag'] == 0) || ($info['typeflag'] == 0x30) || ($info['typeflag'] == 0x35)) {
 165                      /* File or folder. */
 166                      $file['data'] = $contents;
 167  
 168                      $mode = hexdec(substr($info['mode'], 4, 3));
 169                      $file['attr'] = (($info['typeflag'] == 0x35) ? 'd' : '-') .
 170                       (($mode & 0x400) ? 'r' : '-') .
 171                       (($mode & 0x200) ? 'w' : '-') .
 172                       (($mode & 0x100) ? 'x' : '-') .
 173                       (($mode & 0x040) ? 'r' : '-') .
 174                       (($mode & 0x020) ? 'w' : '-') .
 175                       (($mode & 0x010) ? 'x' : '-') .
 176                       (($mode & 0x004) ? 'r' : '-') .
 177                       (($mode & 0x002) ? 'w' : '-') .
 178                       (($mode & 0x001) ? 'x' : '-');
 179                  } else {
 180                      /* Some other type. */
 181                  }
 182                  $return_array[] = $file;
 183              }
 184          }
 185          $this->_metadata = $return_array;
 186          return true;
 187      }
 188  }


Generato il: Mon Oct 19 20:29:27 2009 Generato con PHPXref 0.7