| [ Index ] |
PHP Cross Reference of Joomla 1.5.26 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @version $Id:gzip.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 * Gzip 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 JArchiveGzip extends JObject 32 { 33 /** 34 * Gzip file flags. 35 * @var array 36 */ 37 var $_flags = array ( 38 'FTEXT' => 0x01, 39 'FHCRC' => 0x02, 40 'FEXTRA' => 0x04, 41 'FNAME' => 0x08, 42 'FCOMMENT' => 0x10 43 ); 44 45 /** 46 * Gzip file data buffer 47 * @var string 48 */ 49 var $_data = null; 50 51 /** 52 * Extract a Gzip compressed file to a given path 53 * 54 * @access public 55 * @param string $archive Path to ZIP archive to extract 56 * @param string $destination Path to extract archive to 57 * @param array $options Extraction options [unused] 58 * @return boolean True if successful 59 * @since 1.5 60 */ 61 function extract($archive, $destination, $options = array ()) 62 { 63 // Initialize variables 64 $this->_data = null; 65 66 if (!extension_loaded('zlib')) { 67 $this->set('error.message', 'Zlib Not Supported'); 68 return JError::raiseWarning(100, $this->get('error.message')); 69 } 70 71 if (!$this->_data = JFile::read($archive)) { 72 $this->set('error.message', 'Unable to read archive'); 73 return JError::raiseWarning(100, $this->get('error.message')); 74 } 75 76 $position = $this->_getFilePosition(); 77 $buffer = gzinflate(substr($this->_data, $position, strlen($this->_data) - $position)); 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 90 /** 91 * Get file data offset for archive 92 * 93 * @access public 94 * @return int Data position marker for archive 95 * @since 1.5 96 */ 97 function _getFilePosition() 98 { 99 // gzipped file... unpack it first 100 $position = 0; 101 $info = @ unpack('CCM/CFLG/VTime/CXFL/COS', substr($this->_data, $position +2)); 102 if (!$info) { 103 $this->set('error.message', 'Unable to decompress data'); 104 return false; 105 } 106 $position += 10; 107 108 if ($info['FLG'] & $this->_flags['FEXTRA']) { 109 $XLEN = unpack('vLength', substr($this->_data, $position +0, 2)); 110 $XLEN = $XLEN['Length']; 111 $position += $XLEN +2; 112 } 113 114 if ($info['FLG'] & $this->_flags['FNAME']) { 115 $filenamePos = strpos($this->_data, "\x0", $position); 116 $filename = substr($this->_data, $position, $filenamePos - $position); 117 $position = $filenamePos +1; 118 } 119 120 if ($info['FLG'] & $this->_flags['FCOMMENT']) { 121 $commentPos = strpos($this->_data, "\x0", $position); 122 $comment = substr($this->_data, $position, $commentPos - $position); 123 $position = $commentPos +1; 124 } 125 126 if ($info['FLG'] & $this->_flags['FHCRC']) { 127 $hcrc = unpack('vCRC', substr($this->_data, $position +0, 2)); 128 $hcrc = $hcrc['CRC']; 129 $position += 2; 130 } 131 132 return $position; 133 } 134 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Mar 28 15:54:07 2012 | Cross-referenced by PHPXref 0.7.1 |