[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/libraries/joomla/filesystem/archive/ -> bzip2.php (source)

   1  <?php
   2  /**
   3   * @version        $Id:bzip2.php 6961 2007-03-15 16:06:53Z tcp $
   4   * @package        Joomla.Framework
   5   * @subpackage    FileSystem
   6   * @copyright    Copyright (C) 2005 - 2010 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   * Bzip2 format adapter for the JArchive class
  20   *
  21   * @package     Joomla.Framework
  22   * @subpackage    FileSystem
  23   * @since        1.5
  24   */
  25  class JArchiveBzip2 extends JObject
  26  {
  27      /**
  28       * Bzip2 file data buffer
  29       * @var string
  30       */
  31      var $_data = null;
  32  
  33      /**
  34       * Constructor tries to load the bz2 extension of not loaded
  35       *
  36       * @access    protected
  37       * @return    void
  38       * @since    1.5
  39       */
  40  	function __construct()
  41      {
  42          // Is bz2 extension loaded?  If not try to load it
  43          if (!extension_loaded('bz2')) {
  44              if (JPATH_ISWIN) {
  45                  @ dl('php_bz2.dll');
  46              } else {
  47                  @ dl('bz2.so');
  48              }
  49          }
  50      }
  51  
  52      /**
  53      * Extract a Bzip2 compressed file to a given path
  54      *
  55      * @access    public
  56      * @param    string    $archive        Path to Bzip2 archive to extract
  57      * @param    string    $destination    Path to extract archive to
  58      * @param    array    $options        Extraction options [unused]
  59      * @return    boolean    True if successful
  60      * @since    1.5
  61      */
  62  	function extract($archive, $destination, $options = array ())
  63      {
  64          // Initialize variables
  65          $this->_data = null;
  66  
  67          if (!extension_loaded('bz2')) {
  68              $this->set('error.message', 'BZip2 Not Supported');
  69              return JError::raiseWarning(100, $this->get('error.message'));
  70          }
  71  
  72          if (!$this->_data = JFile::read($archive)) {
  73              $this->set('error.message', 'Unable to read archive');
  74              return JError::raiseWarning(100, $this->get('error.message'));
  75          }
  76  
  77          $buffer = bzdecompress($this->_data);
  78          if (empty ($buffer)) {
  79              $this->set('error.message', 'Unable to decompress data');
  80              return JError::raiseWarning(100, $this->get('error.message'));
  81          }
  82  
  83          if (JFile::write($destination, $buffer) === false) {
  84              $this->set('error.message', 'Unable to write archive');
  85              return JError::raiseWarning(100, $this->get('error.message'));
  86          }
  87          return true;
  88      }
  89  }


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1