Commit 7006e76e11388a398f07adc6cb85d816a4eb2fec
1 parent
dd90bb71
KTS-2613
"Bulk import from archive file should support common compression systems such as rar, tar" Fixed. Added the pear library file archive to take care of additional compression formats. Committed by: Megan Watson Reviewed by: Conrad Vermeulen git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7856 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
56 changed files
with
10970 additions
and
42 deletions
lib/import/zipimportstorage.inc.php
| ... | ... | @@ -7,71 +7,140 @@ |
| 7 | 7 | * KnowledgeTree Open Source Edition |
| 8 | 8 | * Document Management Made Simple |
| 9 | 9 | * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited |
| 10 | - * | |
| 10 | + * | |
| 11 | 11 | * This program is free software; you can redistribute it and/or modify it under |
| 12 | 12 | * the terms of the GNU General Public License version 3 as published by the |
| 13 | 13 | * Free Software Foundation. |
| 14 | - * | |
| 14 | + * | |
| 15 | 15 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 16 | 16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 17 | 17 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 18 | 18 | * details. |
| 19 | - * | |
| 19 | + * | |
| 20 | 20 | * You should have received a copy of the GNU General Public License |
| 21 | 21 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 | - * | |
| 22 | + * | |
| 23 | 23 | * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, |
| 24 | 24 | * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. |
| 25 | - * | |
| 25 | + * | |
| 26 | 26 | * The interactive user interfaces in modified source and object code versions |
| 27 | 27 | * of this program must display Appropriate Legal Notices, as required under |
| 28 | 28 | * Section 5 of the GNU General Public License version 3. |
| 29 | - * | |
| 29 | + * | |
| 30 | 30 | * In accordance with Section 7(b) of the GNU General Public License version 3, |
| 31 | 31 | * these Appropriate Legal Notices must retain the display of the "Powered by |
| 32 | - * KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 32 | + * KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 33 | 33 | * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices |
| 34 | - * must display the words "Powered by KnowledgeTree" and retain the original | |
| 35 | - * copyright notice. | |
| 34 | + * must display the words "Powered by KnowledgeTree" and retain the original | |
| 35 | + * copyright notice. | |
| 36 | 36 | * Contributor( s): ______________________________________ |
| 37 | 37 | */ |
| 38 | 38 | |
| 39 | 39 | require_once(KT_LIB_DIR . '/filelike/fsfilelike.inc.php'); |
| 40 | 40 | require_once(KT_LIB_DIR . '/import/fsimportstorage.inc.php'); |
| 41 | 41 | |
| 42 | +require_once('File/Archive.php'); | |
| 43 | + | |
| 42 | 44 | class KTZipImportStorage extends KTFSImportStorage { |
| 43 | - function KTZipImportStorage($sZipPath) { | |
| 44 | - $this->sZipPath = $sZipPath; | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * The archive extension. | |
| 48 | + * @var string | |
| 49 | + */ | |
| 50 | + var $sExtension = 'zip'; | |
| 51 | + | |
| 52 | + var $sZipPath = ''; | |
| 53 | + | |
| 54 | + var $sBasePath = ''; | |
| 55 | + | |
| 56 | + var $aFile = array(); | |
| 57 | + | |
| 58 | + var $allowed_extensions = array('tgz', 'tar', 'gz', 'gzip', 'zip', 'deb', 'ar'); | |
| 59 | + | |
| 60 | + function KTZipImportStorage($sFilesName) { | |
| 61 | + $this->aFile = $_FILES[$sFilesName]; | |
| 62 | + $this->sZipPath = $this->aFile['tmp_name']; | |
| 63 | + | |
| 64 | + // Check the bzip2 lib functions are available | |
| 65 | + if(function_exists('bzopen')){ | |
| 66 | + $this->allowed_extensions = array_merge($this->allowed_extensions, array('bz2', 'bzip2', 'tbz')); | |
| 67 | + } | |
| 68 | + } | |
| 69 | + | |
| 70 | + function CheckFormat(){ | |
| 71 | + // Get the file extension | |
| 72 | + $aFilename = explode('.', $this->aFile['name']); | |
| 73 | + $cnt = count($aFilename); | |
| 74 | + $sExtension = $aFilename[$cnt - 1]; | |
| 75 | + | |
| 76 | + // check if its in the list of supported extensions | |
| 77 | + if(!in_array($sExtension, $this->allowed_extensions)){ | |
| 78 | + return false; | |
| 79 | + } | |
| 80 | + | |
| 81 | + $this->sExtension = (!empty($sExtension)) ? $sExtension : 'zip'; | |
| 82 | + | |
| 83 | + // Check if the archive is a .tar.gz or .tar.bz, etc | |
| 84 | + if($cnt > 2){ | |
| 85 | + if($aFilename[$cnt-2] == 'tar'){ | |
| 86 | + switch($this->sExtension){ | |
| 87 | + case 'gz': | |
| 88 | + $this->sExtension = 'tgz'; | |
| 89 | + break; | |
| 90 | + case 'bz2': | |
| 91 | + $this->sExtension = 'tbz'; | |
| 92 | + break; | |
| 93 | + } | |
| 94 | + } | |
| 95 | + } | |
| 96 | + | |
| 97 | + return true; | |
| 98 | + } | |
| 99 | + | |
| 100 | + function getFormats(){ | |
| 101 | + return implode(', ', $this->allowed_extensions); | |
| 45 | 102 | } |
| 46 | 103 | |
| 47 | 104 | function init() { |
| 48 | 105 | $oKTConfig =& KTConfig::getSingleton(); |
| 49 | - $sBasedir = $oKTConfig->get("urls/tmpDirectory"); | |
| 50 | - | |
| 51 | - $sTmpPath = tempnam($sBasedir, 'zipimportstorage'); | |
| 106 | + $sBasedir = $oKTConfig->get("urls/tmpDirectory"); | |
| 107 | + | |
| 108 | + $sTmpPath = tempnam($sBasedir, 'archiveimportstorage'); | |
| 52 | 109 | if ($sTmpPath === false) { |
| 53 | - return PEAR::raiseError(_kt("Could not create temporary directory for zip storage")); | |
| 110 | + return PEAR::raiseError(_kt("Could not create temporary directory for archive storage")); | |
| 54 | 111 | } |
| 55 | 112 | if (!file_exists($this->sZipPath)) { |
| 56 | - return PEAR::raiseError(_kt("Zip file given does not exist")); | |
| 113 | + return PEAR::raiseError(_kt("Archive file given does not exist")); | |
| 57 | 114 | } |
| 58 | 115 | unlink($sTmpPath); |
| 59 | 116 | mkdir($sTmpPath, 0700); |
| 60 | 117 | $this->sBasePath = $sTmpPath; |
| 61 | - $sUnzipCommand = KTUtil::findCommand("import/unzip", "unzip"); | |
| 62 | - if (empty($sUnzipCommand)) { | |
| 63 | - return PEAR::raiseError(_kt("unzip command not found on system")); | |
| 64 | - } | |
| 65 | - $aArgs = array( | |
| 66 | - $sUnzipCommand, | |
| 67 | - "-q", "-n", | |
| 68 | - "-d", $sTmpPath, | |
| 69 | - $this->sZipPath, | |
| 70 | - ); | |
| 71 | - $aRes = KTUtil::pexec($aArgs); | |
| 72 | - | |
| 73 | - if ($aRes['ret'] !== 0) { | |
| 74 | - return PEAR::raiseError(_kt("Could not retrieve contents from zip storage")); | |
| 118 | + | |
| 119 | + // File Archive doesn't unzip properly so sticking to the original unzip functionality | |
| 120 | + if($this->sExtension == 'zip'){ | |
| 121 | + // ** Original zip functionality | |
| 122 | + $sUnzipCommand = KTUtil::findCommand("import/unzip", "unzip"); | |
| 123 | + if (empty($sUnzipCommand)) { | |
| 124 | + return PEAR::raiseError(_kt("unzip command not found on system")); | |
| 125 | + } | |
| 126 | + $aArgs = array( | |
| 127 | + $sUnzipCommand, | |
| 128 | + "-q", "-n", | |
| 129 | + "-d", $sTmpPath, | |
| 130 | + $this->sZipPath, | |
| 131 | + ); | |
| 132 | + $aRes = KTUtil::pexec($aArgs); | |
| 133 | + | |
| 134 | + if ($aRes['ret'] !== 0) { | |
| 135 | + return PEAR::raiseError(_kt("Could not retrieve contents from zip storage")); | |
| 136 | + } | |
| 137 | + }else{ | |
| 138 | + File_Archive::extract( | |
| 139 | + File_Archive::readArchive( | |
| 140 | + $this->sExtension, File_Archive::readUploadedFile('file') | |
| 141 | + ), | |
| 142 | + $dst = $sTmpPath | |
| 143 | + ); | |
| 75 | 144 | } |
| 76 | 145 | } |
| 77 | 146 | |
| ... | ... | @@ -83,4 +152,4 @@ class KTZipImportStorage extends KTFSImportStorage { |
| 83 | 152 | } |
| 84 | 153 | } |
| 85 | 154 | |
| 86 | 155 | -?> |
| 156 | +?> | |
| 87 | 157 | \ No newline at end of file | ... | ... |
plugins/ktcore/folder/BulkUpload.php
| ... | ... | @@ -115,16 +115,6 @@ class KTBulkUploadFolderAction extends KTFolderAction { |
| 115 | 115 | unset($aErrorOptions['message']); |
| 116 | 116 | $aFile = $this->oValidator->validateFile($_FILES['file'], $aErrorOptions); |
| 117 | 117 | |
| 118 | - // Ensure file is a zip file | |
| 119 | - $sMime = $aFile['type']; | |
| 120 | - $pos = strpos($sMime, 'x-zip-compressed'); | |
| 121 | - $pos2 = strpos($sMime, 'application/zip'); | |
| 122 | - if($pos === false && $pos2 === false){ | |
| 123 | - $this->addErrorMessage(_kt("Bulk Upload failed: File is not a zip file.")); | |
| 124 | - controllerRedirect("browse", 'fFolderId=' . $this->oFolder->getID()); | |
| 125 | - exit(0); | |
| 126 | - } | |
| 127 | - | |
| 128 | 118 | $matches = array(); |
| 129 | 119 | $aFields = array(); |
| 130 | 120 | foreach ($_REQUEST as $k => $v) { |
| ... | ... | @@ -138,7 +128,14 @@ class KTBulkUploadFolderAction extends KTFolderAction { |
| 138 | 128 | 'metadata' => $aFields, |
| 139 | 129 | ); |
| 140 | 130 | |
| 141 | - $fs =& new KTZipImportStorage($aFile['tmp_name']); | |
| 131 | + $fs =& new KTZipImportStorage('file'); | |
| 132 | + if(!$fs->CheckFormat()){ | |
| 133 | + $sFormats = $fs->getFormats(); | |
| 134 | + $this->addErrorMessage(_kt("Bulk Upload failed. Archive is not an accepted format. Accepted formats are: ".$sFormats)); | |
| 135 | + controllerRedirect("browse", 'fFolderId=' . $this->oFolder->getID()); | |
| 136 | + exit; | |
| 137 | + } | |
| 138 | + | |
| 142 | 139 | $bm =& new KTBulkImportManager($this->oFolder, $fs, $this->oUser, $aOptions); |
| 143 | 140 | $this->startTransaction(); |
| 144 | 141 | $res = $bm->import(); |
| ... | ... | @@ -152,3 +149,4 @@ class KTBulkUploadFolderAction extends KTFolderAction { |
| 152 | 149 | exit(0); |
| 153 | 150 | } |
| 154 | 151 | } |
| 152 | +?> | |
| 155 | 153 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Factory to access the most common File_Archive features | |
| 6 | + * It uses lazy include, so you dont have to include the files from | |
| 7 | + * File/Archive/* directories | |
| 8 | + * | |
| 9 | + * PHP versions 4 and 5 | |
| 10 | + * | |
| 11 | + * This library is free software; you can redistribute it and/or | |
| 12 | + * modify it under the terms of the GNU Lesser General Public | |
| 13 | + * License as published by the Free Software Foundation; either | |
| 14 | + * version 2.1 of the License, or (at your option) any later version. | |
| 15 | + * | |
| 16 | + * This library is distributed in the hope that it will be useful, | |
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 19 | + * Lesser General Public License for more details. | |
| 20 | + * | |
| 21 | + * You should have received a copy of the GNU Lesser General Public | |
| 22 | + * License along with this library; if not, write to the Free Software | |
| 23 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 24 | + * | |
| 25 | + * @category File Formats | |
| 26 | + * @package File_Archive | |
| 27 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 28 | + * @copyright 1997-2005 The PHP Group | |
| 29 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 30 | + * @version CVS: $Id: Archive.php,v 1.85 2005/08/16 08:48:59 vincentlascaux Exp $ | |
| 31 | + * @link http://pear.php.net/package/File_Archive | |
| 32 | + */ | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * To have access to PEAR::isError and PEAR::raiseError | |
| 36 | + * We should probably use lazy include and remove this inclusion... | |
| 37 | + */ | |
| 38 | +require_once "PEAR.php"; | |
| 39 | + | |
| 40 | +function File_Archive_cleanCache($file, $group) | |
| 41 | +{ | |
| 42 | + $file = split('_', $file); | |
| 43 | + if (count($file) != 3) { | |
| 44 | + return false; //not a File_Archive file, keep it | |
| 45 | + } | |
| 46 | + | |
| 47 | + $name = $file[2]; | |
| 48 | + $name = urldecode($name); | |
| 49 | + | |
| 50 | + $group = $file[1]; | |
| 51 | + | |
| 52 | + //clean the cache only for files in File_Archive groups | |
| 53 | + return substr($group, 0, 11) == 'FileArchive' && | |
| 54 | + !file_exists($name); //and only if the related file no longer exists | |
| 55 | +} | |
| 56 | + | |
| 57 | +/** | |
| 58 | + * Factory to access the most common File_Archive features | |
| 59 | + * It uses lazy include, so you dont have to include the files from | |
| 60 | + * File/Archive/* directories | |
| 61 | + */ | |
| 62 | +class File_Archive | |
| 63 | +{ | |
| 64 | + function& _option($name) | |
| 65 | + { | |
| 66 | + static $container = array( | |
| 67 | + 'zipCompressionLevel' => 9, | |
| 68 | + 'gzCompressionLevel' => 9, | |
| 69 | + 'tmpDirectory' => '.', | |
| 70 | + 'cache' => null, | |
| 71 | + 'appendRemoveDuplicates' => false, | |
| 72 | + 'blockSize' => 65536, | |
| 73 | + 'cacheCondition' => false | |
| 74 | + ); | |
| 75 | + return $container[$name]; | |
| 76 | + } | |
| 77 | + /** | |
| 78 | + * Sets an option that will be used by default by all readers or writers | |
| 79 | + * Option names are case sensitive | |
| 80 | + * Currently, the following options are used: | |
| 81 | + * | |
| 82 | + * "cache" | |
| 83 | + * Instance of a Cache_Lite object used to cache some compressed | |
| 84 | + * data to speed up future compressions of files | |
| 85 | + * Default: null (no cache used) | |
| 86 | + * | |
| 87 | + * "zipCompressionLevel" | |
| 88 | + * Value between 0 and 9 specifying the default compression level used | |
| 89 | + * by Zip writers (0 no compression, 9 highest compression) | |
| 90 | + * Default: 9 | |
| 91 | + * | |
| 92 | + * "gzCompressionLevel" | |
| 93 | + * Value between 0 and 9 specifying the default compression level used | |
| 94 | + * by Gz writers (0 no compression, 9 highest compression) | |
| 95 | + * Default: 9 | |
| 96 | + * | |
| 97 | + * "tmpDirectory" | |
| 98 | + * Directory where the temporary files generated by File_Archive will | |
| 99 | + * be created | |
| 100 | + * Default: '.' | |
| 101 | + * | |
| 102 | + * "appendRemoveDuplicates" | |
| 103 | + * If set to true, the appender created will by default remove the | |
| 104 | + * file present in the archive when adding a new one. This will slow the | |
| 105 | + * appending of files to archives | |
| 106 | + * Default: false | |
| 107 | + * | |
| 108 | + * "blockSize" | |
| 109 | + * To transfer data from a reader to a writer, some chunks a read from the | |
| 110 | + * source and written to the writer. This parameter controls the size of the | |
| 111 | + * chunks | |
| 112 | + * Default: 64kB | |
| 113 | + * | |
| 114 | + * "cacheCondition" | |
| 115 | + * This parameter specifies when a cache should be used. When the cache is | |
| 116 | + * used, the data of the reader is saved in a temporary file for future access. | |
| 117 | + * The cached reader will be read only once, even if you read it several times. | |
| 118 | + * This can be usefull to read compressed files or downloaded files (from http or ftp) | |
| 119 | + * The possible values for this option are | |
| 120 | + * - false: never use cache | |
| 121 | + * - a regexp: A cache will be used if the specified URL matches the regexp | |
| 122 | + * preg_match is used | |
| 123 | + * Default: false | |
| 124 | + * Example: '/^(http|ftp):\/\//' will cache all files downloaded via http or ftp | |
| 125 | + * | |
| 126 | + */ | |
| 127 | + function setOption($name, $value) | |
| 128 | + { | |
| 129 | + $option =& File_Archive::_option($name); | |
| 130 | + $option = $value; | |
| 131 | + if ($name == 'cache' && $value !== null) { | |
| 132 | + //TODO: ask to Cache_Lite to allow that | |
| 133 | + $value->_fileNameProtection = false; | |
| 134 | + } | |
| 135 | + } | |
| 136 | + | |
| 137 | + /** | |
| 138 | + * Retrieve the value of an option | |
| 139 | + */ | |
| 140 | + function getOption($name) | |
| 141 | + { | |
| 142 | + return File_Archive::_option($name); | |
| 143 | + } | |
| 144 | + | |
| 145 | + /** | |
| 146 | + * Create a reader to read the URL $URL. | |
| 147 | + * If the URL is a directory, it will recursively read that directory. | |
| 148 | + * If $uncompressionLevel is not null, the archives (files with extension | |
| 149 | + * tar, zip, gz or tgz) will be considered as directories (up to a depth of | |
| 150 | + * $uncompressionLevel if $uncompressionLevel > 0). The reader will only | |
| 151 | + * read files with a directory depth of $directoryDepth. It reader will | |
| 152 | + * replace the given URL ($URL) with $symbolic in the public filenames | |
| 153 | + * The default symbolic name is the last filename in the URL (or '' for | |
| 154 | + * directories) | |
| 155 | + * | |
| 156 | + * Examples: | |
| 157 | + * Considere the following file system | |
| 158 | + * <pre> | |
| 159 | + * a.txt | |
| 160 | + * b.tar (archive that contains the following files) | |
| 161 | + * c.txt | |
| 162 | + * d.tgz (archive that contains the following files) | |
| 163 | + * e.txt | |
| 164 | + * dir1/ | |
| 165 | + * f.txt | |
| 166 | + * dir2/ | |
| 167 | + * g.txt | |
| 168 | + * dir3/ | |
| 169 | + * h.tar (archive that contains the following files) | |
| 170 | + * i.txt | |
| 171 | + * </pre> | |
| 172 | + * | |
| 173 | + * read('.') will return a reader that gives access to following | |
| 174 | + * files (recursively read current dir): | |
| 175 | + * <pre> | |
| 176 | + * a.txt | |
| 177 | + * b.tar | |
| 178 | + * dir2/g.txt | |
| 179 | + * dir2/dir3/h.tar | |
| 180 | + * </pre> | |
| 181 | + * | |
| 182 | + * read('.', 'myBaseDir') will return the following reader: | |
| 183 | + * <pre> | |
| 184 | + * myBaseDir/a.txt | |
| 185 | + * myBaseDir/b.tar | |
| 186 | + * myBaseDir/dir2/g.txt | |
| 187 | + * myBaseDir/dir2/dir3/h.tar | |
| 188 | + * </pre> | |
| 189 | + * | |
| 190 | + * read('.', '', -1) will return the following reader (uncompress | |
| 191 | + * everything) | |
| 192 | + * <pre> | |
| 193 | + * a.txt | |
| 194 | + * b.tar/c.txt | |
| 195 | + * b.tar/d.tgz/e.txt | |
| 196 | + * b.tar/d.tgz/dir1/f.txt | |
| 197 | + * dir2/g.txt | |
| 198 | + * dir2/dir3/h.tar/i.txt | |
| 199 | + * </pre> | |
| 200 | + * | |
| 201 | + * read('.', '', 1) will uncompress only one level (so d.tgz will | |
| 202 | + * not be uncompressed): | |
| 203 | + * <pre> | |
| 204 | + * a.txt | |
| 205 | + * b.tar/c.txt | |
| 206 | + * b.tar/d.tgz | |
| 207 | + * dir2/g.txt | |
| 208 | + * dir2/dir3/h.tar/i.txt | |
| 209 | + * </pre> | |
| 210 | + * | |
| 211 | + * read('.', '', 0, 0) will not recurse into subdirectories | |
| 212 | + * <pre> | |
| 213 | + * a.txt | |
| 214 | + * b.tar | |
| 215 | + * </pre> | |
| 216 | + * | |
| 217 | + * read('.', '', 0, 1) will recurse only one level in | |
| 218 | + * subdirectories | |
| 219 | + * <pre> | |
| 220 | + * a.txt | |
| 221 | + * b.tar | |
| 222 | + * dir2/g.txt | |
| 223 | + * </pre> | |
| 224 | + * | |
| 225 | + * read('.', '', -1, 2) will uncompress everything and recurse in | |
| 226 | + * only 2 levels in subdirectories or archives | |
| 227 | + * <pre> | |
| 228 | + * a.txt | |
| 229 | + * b.tar/c.txt | |
| 230 | + * b.tar/d.tgz/e.txt | |
| 231 | + * dir2/g.txt | |
| 232 | + * </pre> | |
| 233 | + * | |
| 234 | + * The recursion level is determined by the real path, not the symbolic one. | |
| 235 | + * So read('.', 'myBaseDir', -1, 2) will result to the same files: | |
| 236 | + * <pre> | |
| 237 | + * myBaseDir/a.txt | |
| 238 | + * myBaseDir/b.tar/c.txt | |
| 239 | + * myBaseDir/b.tar/d.tgz/e.txt (accepted because the real depth is 2) | |
| 240 | + * myBaseDir/dir2/g.txt | |
| 241 | + * </pre> | |
| 242 | + * | |
| 243 | + * Use readSource to do the same thing, reading from a specified reader instead of | |
| 244 | + * reading from the system files | |
| 245 | + * | |
| 246 | + * To read a single file, you can do read('a.txt', 'public_name.txt') | |
| 247 | + * If no public name is provided, the default one is the name of the file | |
| 248 | + * read('dir2/g.txt') contains the single file named 'g.txt' | |
| 249 | + * read('b.tar/c.txt') contains the single file named 'c.txt' | |
| 250 | + * | |
| 251 | + * Note: This function uncompress files reading their extension | |
| 252 | + * The compressed files must have a tar, zip, gz or tgz extension | |
| 253 | + * Since it is impossible for some URLs to use is_dir or is_file, this | |
| 254 | + * function may not work with | |
| 255 | + * URLs containing folders which name ends with such an extension | |
| 256 | + */ | |
| 257 | + function readSource(&$source, $URL, $symbolic = null, | |
| 258 | + $uncompression = 0, $directoryDepth = -1) | |
| 259 | + { | |
| 260 | + return File_Archive::_readSource($source, $URL, $reachable, $baseDir, | |
| 261 | + $symbolic, $uncompression, $directoryDepth); | |
| 262 | + } | |
| 263 | + | |
| 264 | + /** | |
| 265 | + * This function performs exactly as readSource, but with two additional parameters | |
| 266 | + * ($reachable and $baseDir) that will be set so that $reachable."/".$baseDir == $URL | |
| 267 | + * and $reachable can be reached (in case of error) | |
| 268 | + * | |
| 269 | + * @access private | |
| 270 | + */ | |
| 271 | + function _readSource(&$toConvert, $URL, &$reachable, &$baseDir, $symbolic = null, | |
| 272 | + $uncompression = 0, $directoryDepth = -1) | |
| 273 | + { | |
| 274 | + $source =& File_Archive::_convertToReader($toConvert); | |
| 275 | + if (PEAR::isError($source)) { | |
| 276 | + return $source; | |
| 277 | + } | |
| 278 | + if (is_array($URL)) { | |
| 279 | + $converted = array(); | |
| 280 | + foreach($URL as $key => $foo) { | |
| 281 | + $converted[] =& File_Archive::_convertToReader($URL[$key]); | |
| 282 | + } | |
| 283 | + return File_Archive::readMulti($converted); | |
| 284 | + } | |
| 285 | + | |
| 286 | + //No need to uncompress more than $directoryDepth | |
| 287 | + //That's not perfect, and some archives will still be uncompressed just | |
| 288 | + //to be filtered out :( | |
| 289 | + if ($directoryDepth >= 0) { | |
| 290 | + $uncompressionLevel = min($uncompression, $directoryDepth); | |
| 291 | + } else { | |
| 292 | + $uncompressionLevel = $uncompression; | |
| 293 | + } | |
| 294 | + | |
| 295 | + require_once 'File/Archive/Reader.php'; | |
| 296 | + $std = File_Archive_Reader::getStandardURL($URL); | |
| 297 | + | |
| 298 | + //Modify the symbolic name if necessary | |
| 299 | + $slashPos = strrpos($std, '/'); | |
| 300 | + if ($symbolic === null) { | |
| 301 | + if ($slashPos === false) { | |
| 302 | + $realSymbolic = $std; | |
| 303 | + } else { | |
| 304 | + $realSymbolic = substr($std, $slashPos+1); | |
| 305 | + } | |
| 306 | + } else { | |
| 307 | + $realSymbolic = $symbolic; | |
| 308 | + } | |
| 309 | + if ($slashPos !== false) { | |
| 310 | + $baseFile = substr($std, 0, $slashPos+1); | |
| 311 | + $lastFile = substr($std, $slashPos+1); | |
| 312 | + } else { | |
| 313 | + $baseFile = ''; | |
| 314 | + $lastFile = $std; | |
| 315 | + } | |
| 316 | + | |
| 317 | + if (strpos($lastFile, '*')!==false || | |
| 318 | + strpos($lastFile, '?')!==false) { | |
| 319 | + //We have to build a regexp here | |
| 320 | + $regexp = str_replace( | |
| 321 | + array('\*', '\?'), | |
| 322 | + array('[^/]*', '[^/]'), | |
| 323 | + preg_quote($lastFile) | |
| 324 | + ); | |
| 325 | + $result = File_Archive::_readSource($source, $baseFile, | |
| 326 | + $reachable, $baseDir, null, 0, -1); | |
| 327 | + return File_Archive::filter( | |
| 328 | + File_Archive::predEreg('^'.$regexp.'$'), | |
| 329 | + $result | |
| 330 | + ); | |
| 331 | + } | |
| 332 | + | |
| 333 | + //If the URL can be interpreted as a directory, and we are reading from the file system | |
| 334 | + if ((empty($URL) || is_dir($URL)) && $source === null) { | |
| 335 | + require_once "File/Archive/Reader/Directory.php"; | |
| 336 | + require_once "File/Archive/Reader/ChangeName.php"; | |
| 337 | + | |
| 338 | + if ($uncompressionLevel != 0) { | |
| 339 | + require_once "File/Archive/Reader/Uncompress.php"; | |
| 340 | + $result = new File_Archive_Reader_Uncompress( | |
| 341 | + new File_Archive_Reader_Directory($std, '', $directoryDepth), | |
| 342 | + $uncompressionLevel | |
| 343 | + ); | |
| 344 | + } else { | |
| 345 | + $result = new File_Archive_Reader_Directory($std, '', $directoryDepth); | |
| 346 | + } | |
| 347 | + | |
| 348 | + if ($directoryDepth >= 0) { | |
| 349 | + require_once 'File/Archive/Reader/Filter.php'; | |
| 350 | + require_once 'File/Archive/Predicate/MaxDepth.php'; | |
| 351 | + | |
| 352 | + $tmp =& File_Archive::filter( | |
| 353 | + new File_Archive_Predicate_MaxDepth($directoryDepth), | |
| 354 | + $result | |
| 355 | + ); | |
| 356 | + unset($result); | |
| 357 | + $result =& $tmp; | |
| 358 | + } | |
| 359 | + if (!empty($realSymbolic)) { | |
| 360 | + if ($symbolic === null) { | |
| 361 | + $realSymbolic = ''; | |
| 362 | + } | |
| 363 | + $tmp =& new File_Archive_Reader_AddBaseName( | |
| 364 | + $realSymbolic, | |
| 365 | + $result | |
| 366 | + ); | |
| 367 | + unset($result); | |
| 368 | + $result =& $tmp; | |
| 369 | + } | |
| 370 | + | |
| 371 | + //If the URL can be interpreted as a file, and we are reading from the file system | |
| 372 | + } else if (is_file($URL) && substr($URL, -1)!='/' && $source === null) { | |
| 373 | + require_once "File/Archive/Reader/File.php"; | |
| 374 | + $result = new File_Archive_Reader_File($URL, $realSymbolic); | |
| 375 | + | |
| 376 | + //Else, we will have to build a complex reader | |
| 377 | + } else { | |
| 378 | + require_once "File/Archive/Reader/File.php"; | |
| 379 | + | |
| 380 | + $realPath = $std; | |
| 381 | + | |
| 382 | + // Try to find a file with a known extension in the path ( | |
| 383 | + // (to manage URLs like archive.tar/directory/file) | |
| 384 | + $pos = 0; | |
| 385 | + do { | |
| 386 | + if ($pos+1<strlen($realPath)) { | |
| 387 | + $pos = strpos($realPath, '/', $pos+1); | |
| 388 | + } else { | |
| 389 | + $pos = false; | |
| 390 | + } | |
| 391 | + if ($pos === false) { | |
| 392 | + $pos = strlen($realPath); | |
| 393 | + } | |
| 394 | + | |
| 395 | + $file = substr($realPath, 0, $pos); | |
| 396 | + $baseDir = substr($realPath, $pos+1); | |
| 397 | + $dotPos = strrpos($file, '.'); | |
| 398 | + $extension = ''; | |
| 399 | + if ($dotPos !== false) { | |
| 400 | + $extension = substr($file, $dotPos+1); | |
| 401 | + } | |
| 402 | + } while ($pos < strlen($realPath) && | |
| 403 | + (!File_Archive::isKnownExtension($extension) || | |
| 404 | + (is_dir($file) && $source==null))); | |
| 405 | + | |
| 406 | + $reachable = $file; | |
| 407 | + | |
| 408 | + //If we are reading from the file system | |
| 409 | + if ($source === null) { | |
| 410 | + //Create a file reader | |
| 411 | + $result = new File_Archive_Reader_File($file); | |
| 412 | + } else { | |
| 413 | + //Select in the source the file $file | |
| 414 | + | |
| 415 | + require_once "File/Archive/Reader/Select.php"; | |
| 416 | + $result = new File_Archive_Reader_Select($file, $source); | |
| 417 | + } | |
| 418 | + | |
| 419 | + require_once "File/Archive/Reader/Uncompress.php"; | |
| 420 | + $tmp = new File_Archive_Reader_Uncompress($result, $uncompressionLevel); | |
| 421 | + unset($result); | |
| 422 | + $result = $tmp; | |
| 423 | + | |
| 424 | + //Select the requested folder in the uncompress reader | |
| 425 | + $isDir = $result->setBaseDir($std); | |
| 426 | + if (PEAR::isError($isDir)) { | |
| 427 | + return $isDir; | |
| 428 | + } | |
| 429 | + if ($isDir && $symbolic==null) { | |
| 430 | + //Default symbolic name for directories is empty | |
| 431 | + $realSymbolic = ''; | |
| 432 | + } | |
| 433 | + | |
| 434 | + if ($directoryDepth >= 0) { | |
| 435 | + //Limit the maximum depth if necessary | |
| 436 | + require_once "File/Archive/Predicate/MaxDepth.php"; | |
| 437 | + | |
| 438 | + $tmp = new File_Archive_Reader_Filter( | |
| 439 | + new File_Archive_Predicate( | |
| 440 | + $directoryDepth + | |
| 441 | + substr_count(substr($std, $pos+1), '/') | |
| 442 | + ), | |
| 443 | + $result | |
| 444 | + ); | |
| 445 | + unset($result); | |
| 446 | + $result =& $tmp; | |
| 447 | + } | |
| 448 | + | |
| 449 | + if ($std != $realSymbolic) { | |
| 450 | + require_once "File/Archive/Reader/ChangeName.php"; | |
| 451 | + | |
| 452 | + //Change the base name to the symbolic one if necessary | |
| 453 | + $tmp = new File_Archive_Reader_ChangeBaseName( | |
| 454 | + $std, | |
| 455 | + $realSymbolic, | |
| 456 | + $result | |
| 457 | + ); | |
| 458 | + unset($result); | |
| 459 | + $result =& $tmp; | |
| 460 | + } | |
| 461 | + } | |
| 462 | + | |
| 463 | + $cacheCondition = File_Archive::getOption('cacheCondition'); | |
| 464 | + if ($cacheCondition !== false && | |
| 465 | + preg_match($cacheCondition, $URL)) { | |
| 466 | + $tmp =& File_Archive::cache($result); | |
| 467 | + unset($result); | |
| 468 | + $result =& $tmp; | |
| 469 | + } | |
| 470 | + | |
| 471 | + return $result; | |
| 472 | + } | |
| 473 | + function read($URL, $symbolic = null, | |
| 474 | + $uncompression = 0, $directoryDepth = -1) | |
| 475 | + { | |
| 476 | + $source = null; | |
| 477 | + return File_Archive::readSource($source, $URL, $symbolic, $uncompression, $directoryDepth); | |
| 478 | + } | |
| 479 | + | |
| 480 | + /** | |
| 481 | + * Create a file reader on an uploaded file. The reader will read | |
| 482 | + * $_FILES[$name]['tmp_name'] and will have $_FILES[$name]['name'] | |
| 483 | + * as a symbolic filename. | |
| 484 | + * | |
| 485 | + * A PEAR error is returned if one of the following happen | |
| 486 | + * - $_FILES[$name] is not set | |
| 487 | + * - $_FILES[$name]['error'] is not 0 | |
| 488 | + * - is_uploaded_file returns false | |
| 489 | + * | |
| 490 | + * @param string $name Index of the file in the $_FILES array | |
| 491 | + * @return File_Archive_Reader File reader on the uploaded file | |
| 492 | + */ | |
| 493 | + function readUploadedFile($name) | |
| 494 | + { | |
| 495 | + if (!isset($_FILES[$name])) { | |
| 496 | + return PEAR::raiseError("File $name has not been uploaded"); | |
| 497 | + } | |
| 498 | + switch ($_FILES[$name]['error']) { | |
| 499 | + case 0: | |
| 500 | + //No error | |
| 501 | + break; | |
| 502 | + case 1: | |
| 503 | + return PEAR::raiseError( | |
| 504 | + "The upload size limit didn't allow to upload file ". | |
| 505 | + $_FILES[$name]['name'] | |
| 506 | + ); | |
| 507 | + case 2: | |
| 508 | + return PEAR::raiseError( | |
| 509 | + "The form size limit didn't allow to upload file ". | |
| 510 | + $_FILES[$name]['name'] | |
| 511 | + ); | |
| 512 | + case 3: | |
| 513 | + return PEAR::raiseError( | |
| 514 | + "The file was not entirely uploaded" | |
| 515 | + ); | |
| 516 | + case 4: | |
| 517 | + return PEAR::raiseError( | |
| 518 | + "The uploaded file is empty" | |
| 519 | + ); | |
| 520 | + default: | |
| 521 | + return PEAR::raiseError( | |
| 522 | + "Unknown error ".$_FILES[$name]['error']." in file upload. ". | |
| 523 | + "Please, report a bug" | |
| 524 | + ); | |
| 525 | + } | |
| 526 | + if (!is_uploaded_file($_FILES[$name]['tmp_name'])) { | |
| 527 | + return PEAR::raiseError("The file is not an uploaded file"); | |
| 528 | + } | |
| 529 | + | |
| 530 | + require_once "File/Archive/Reader/File.php"; | |
| 531 | + return new File_Archive_Reader_File( | |
| 532 | + $_FILES[$name]['tmp_name'], | |
| 533 | + $_FILES[$name]['name'], | |
| 534 | + $_FILES[$name]['type'] | |
| 535 | + ); | |
| 536 | + } | |
| 537 | + | |
| 538 | + /** | |
| 539 | + * Adds a cache layer above the specified reader | |
| 540 | + * The data of the reader is saved in a temporary file for future access. | |
| 541 | + * The cached reader will be read only once, even if you read it several times. | |
| 542 | + * This can be usefull to read compressed files or downloaded files (from http or ftp) | |
| 543 | + * | |
| 544 | + * @param mixed $toConvert The reader to cache | |
| 545 | + * It can be a File_Archive_Reader or a string, which will be converted using the | |
| 546 | + * read function | |
| 547 | + */ | |
| 548 | + function cache(&$toConvert) | |
| 549 | + { | |
| 550 | + $source =& File_Archive::_convertToReader($toConvert); | |
| 551 | + if (PEAR::isError($source)) { | |
| 552 | + return $source; | |
| 553 | + } | |
| 554 | + | |
| 555 | + require_once 'File/Archive/Reader/Cache.php'; | |
| 556 | + return new File_Archive_Reader_Cache($source); | |
| 557 | + } | |
| 558 | + | |
| 559 | + /** | |
| 560 | + * Try to interpret the object as a reader | |
| 561 | + * Strings are converted to readers using File_Archive::read | |
| 562 | + * Arrays are converted to readers using File_Archive::readMulti | |
| 563 | + * | |
| 564 | + * @access private | |
| 565 | + */ | |
| 566 | + function &_convertToReader(&$source) | |
| 567 | + { | |
| 568 | + if (is_string($source)) { | |
| 569 | + $cacheCondition = File_Archive::getOption('cacheCondition'); | |
| 570 | + if ($cacheCondition !== false && | |
| 571 | + preg_match($cacheCondition, $source)) { | |
| 572 | + return File_Archive::cache(File_Archive::read($source)); | |
| 573 | + } else { | |
| 574 | + return File_Archive::read($source); | |
| 575 | + } | |
| 576 | + } else if (is_array($source)) { | |
| 577 | + return File_Archive::readMulti($source); | |
| 578 | + } else { | |
| 579 | + return $source; | |
| 580 | + } | |
| 581 | + } | |
| 582 | + | |
| 583 | + /** | |
| 584 | + * Try to interpret the object as a writer | |
| 585 | + * Strings are converted to writers using File_Archive::appender | |
| 586 | + * Arrays are converted to writers using a multi writer | |
| 587 | + * | |
| 588 | + * @access private | |
| 589 | + */ | |
| 590 | + function &_convertToWriter(&$dest) | |
| 591 | + { | |
| 592 | + if (is_string($dest)) { | |
| 593 | + return File_Archive::appender($dest); | |
| 594 | + } else if (is_array($dest)) { | |
| 595 | + require_once 'File/Archive/Writer/Multi.php'; | |
| 596 | + $writer = new File_Archive_Writer_Multi(); | |
| 597 | + foreach($dest as $key => $foo) { | |
| 598 | + $writer->addWriter($dest[$key]); | |
| 599 | + } | |
| 600 | + } else { | |
| 601 | + return $dest; | |
| 602 | + } | |
| 603 | + } | |
| 604 | + | |
| 605 | + /** | |
| 606 | + * Check if a file with a specific extension can be read as an archive | |
| 607 | + * with File_Archive::read* | |
| 608 | + * This function is case sensitive. | |
| 609 | + * | |
| 610 | + * @param string $extension the checked extension | |
| 611 | + * @return bool whether this file can be understood reading its extension | |
| 612 | + * Currently, supported extensions are tar, zip, gz, tgz, tbz, bz2, | |
| 613 | + * bzip2, ar, deb | |
| 614 | + */ | |
| 615 | + function isKnownExtension($extension) | |
| 616 | + { | |
| 617 | + return $extension == 'tar' || | |
| 618 | + $extension == 'zip' || | |
| 619 | + $extension == 'gz' || | |
| 620 | + $extension == 'tgz' || | |
| 621 | + $extension == 'tbz' || | |
| 622 | + $extension == 'bz2' || | |
| 623 | + $extension == 'bzip2' || | |
| 624 | + $extension == 'ar' || | |
| 625 | + $extension == 'deb' /* || | |
| 626 | + $extension == 'cab' || | |
| 627 | + $extension == 'rar' */; | |
| 628 | + } | |
| 629 | + | |
| 630 | + /** | |
| 631 | + * Create a reader that will read the single file source $source as | |
| 632 | + * a specific archive | |
| 633 | + * | |
| 634 | + * @param string $extension determines the kind of archive $source contains | |
| 635 | + * $extension is case sensitive | |
| 636 | + * @param File_Archive_Reader $source stores the archive | |
| 637 | + * @param bool $sourceOpened specifies if the archive is already opened | |
| 638 | + * if false, next will be called on source | |
| 639 | + * Closing the returned archive will close $source iif $sourceOpened | |
| 640 | + * is true | |
| 641 | + * @return A File_Archive_Reader that uncompresses the archive contained in | |
| 642 | + * $source interpreting it as a $extension archive | |
| 643 | + * If $extension is not handled return false | |
| 644 | + */ | |
| 645 | + function readArchive($extension, &$toConvert, $sourceOpened = false) | |
| 646 | + { | |
| 647 | + $source =& File_Archive::_convertToReader($toConvert); | |
| 648 | + if (PEAR::isError($source)) { | |
| 649 | + return $source; | |
| 650 | + } | |
| 651 | + | |
| 652 | + switch($extension) { | |
| 653 | + case 'tgz': | |
| 654 | + return File_Archive::readArchive('tar', | |
| 655 | + File_Archive::readArchive('gz', $source, $sourceOpened) | |
| 656 | + ); | |
| 657 | + case 'tbz': | |
| 658 | + return File_Archive::readArchive('tar', | |
| 659 | + File_Archive::readArchive('bz2', $source, $sourceOpened) | |
| 660 | + ); | |
| 661 | + case 'tar': | |
| 662 | + require_once 'File/Archive/Reader/Tar.php'; | |
| 663 | + return new File_Archive_Reader_Tar($source, $sourceOpened); | |
| 664 | + | |
| 665 | + case 'gz': | |
| 666 | + case 'gzip': | |
| 667 | + require_once 'File/Archive/Reader/Gzip.php'; | |
| 668 | + return new File_Archive_Reader_Gzip($source, $sourceOpened); | |
| 669 | + | |
| 670 | + case 'zip': | |
| 671 | + require_once 'File/Archive/Reader/Zip.php'; | |
| 672 | + return new File_Archive_Reader_Zip($source, $sourceOpened); | |
| 673 | + | |
| 674 | + case 'bz2': | |
| 675 | + case 'bzip2': | |
| 676 | + require_once 'File/Archive/Reader/Bzip2.php'; | |
| 677 | + return new File_Archive_Reader_Bzip2($source, $sourceOpened); | |
| 678 | + | |
| 679 | + case 'deb': | |
| 680 | + case 'ar': | |
| 681 | + require_once 'File/Archive/Reader/Ar.php'; | |
| 682 | + return new File_Archive_Reader_Ar($source, $sourceOpened); | |
| 683 | + | |
| 684 | +/* case 'cab': | |
| 685 | + require_once 'File/Archive/Reader/Cab.php'; | |
| 686 | + return new File_Archive_Reader_Cab($source, $sourceOpened); | |
| 687 | + | |
| 688 | + | |
| 689 | + case 'rar': | |
| 690 | + require_once "File/Archive/Reader/Rar.php"; | |
| 691 | + return new File_Archive_Reader_Rar($source, $sourceOpened); */ | |
| 692 | + | |
| 693 | + default: | |
| 694 | + return false; | |
| 695 | + } | |
| 696 | + } | |
| 697 | + | |
| 698 | + /** | |
| 699 | + * Contains only one file with data read from a memory buffer | |
| 700 | + * | |
| 701 | + * @param string $memory content of the file | |
| 702 | + * @param string $filename public name of the file | |
| 703 | + * @param array $stat statistics of the file. Index 7 (size) will be | |
| 704 | + * overwritten to match the size of $memory | |
| 705 | + * @param string $mime mime type of the file. Default will determine the | |
| 706 | + * mime type thanks to the extension of $filename | |
| 707 | + * @see File_Archive_Reader_Memory | |
| 708 | + */ | |
| 709 | + function readMemory($memory, $filename, $stat=array(), $mime=null) | |
| 710 | + { | |
| 711 | + require_once "File/Archive/Reader/Memory.php"; | |
| 712 | + return new File_Archive_Reader_Memory($memory, $filename, $stat, $mime); | |
| 713 | + } | |
| 714 | + | |
| 715 | + /** | |
| 716 | + * Contains several other sources. Take care the sources don't have several | |
| 717 | + * files with the same filename. The sources are given as a parameter, or | |
| 718 | + * can be added thanks to the reader addSource method | |
| 719 | + * | |
| 720 | + * @param array $sources Array of strings or readers that will be added to | |
| 721 | + * the multi reader. If the parameter is a string, a reader will be | |
| 722 | + * built thanks to the read function | |
| 723 | + * @see File_Archive_Reader_Multi, File_Archive::read() | |
| 724 | + */ | |
| 725 | + function readMulti($sources = array()) | |
| 726 | + { | |
| 727 | + require_once "File/Archive/Reader/Multi.php"; | |
| 728 | + $result = new File_Archive_Reader_Multi(); | |
| 729 | + foreach ($sources as $index => $foo) { | |
| 730 | + $s =& File_Archive::_convertToReader($sources[$index]); | |
| 731 | + if (PEAR::isError($s)) { | |
| 732 | + return $s; | |
| 733 | + } else { | |
| 734 | + $result->addSource($s); | |
| 735 | + } | |
| 736 | + } | |
| 737 | + return $result; | |
| 738 | + } | |
| 739 | + /** | |
| 740 | + * Make the files of a source appear as one large file whose content is the | |
| 741 | + * concatenation of the content of all the files | |
| 742 | + * | |
| 743 | + * @param File_Archive_Reader $source The source whose files must be | |
| 744 | + * concatened | |
| 745 | + * @param string $filename name of the only file of the created reader | |
| 746 | + * @param array $stat statistics of the file. Index 7 (size) will be | |
| 747 | + * overwritten to match the total size of the files | |
| 748 | + * @param string $mime mime type of the file. Default will determine the | |
| 749 | + * mime type thanks to the extension of $filename | |
| 750 | + * @see File_Archive_Reader_Concat | |
| 751 | + */ | |
| 752 | + function readConcat(&$toConvert, $filename, $stat=array(), $mime=null) | |
| 753 | + { | |
| 754 | + $source =& File_Archive::_convertToReader($toConvert); | |
| 755 | + if (PEAR::isError($source)) { | |
| 756 | + return $source; | |
| 757 | + } | |
| 758 | + | |
| 759 | + require_once "File/Archive/Reader/Concat.php"; | |
| 760 | + return new File_Archive_Reader_Concat($source, $filename, $stat, $mime); | |
| 761 | + } | |
| 762 | + | |
| 763 | + /** | |
| 764 | + * Removes from a source the files that do not follow a given predicat | |
| 765 | + * | |
| 766 | + * @param File_Archive_Predicate $predicate Only the files for which | |
| 767 | + * $predicate->isTrue() will be kept | |
| 768 | + * @param File_Archive_Reader $source Source that will be filtered | |
| 769 | + * @see File_Archive_Reader_Filter | |
| 770 | + */ | |
| 771 | + function filter($predicate, &$toConvert) | |
| 772 | + { | |
| 773 | + $source =& File_Archive::_convertToReader($toConvert); | |
| 774 | + if (PEAR::isError($source)) { | |
| 775 | + return $source; | |
| 776 | + } | |
| 777 | + | |
| 778 | + require_once "File/Archive/Reader/Filter.php"; | |
| 779 | + return new File_Archive_Reader_Filter($predicate, $source); | |
| 780 | + } | |
| 781 | + /** | |
| 782 | + * Predicate that always evaluate to true | |
| 783 | + * | |
| 784 | + * @see File_Archive_Predicate_True | |
| 785 | + */ | |
| 786 | + function predTrue() | |
| 787 | + { | |
| 788 | + require_once "File/Archive/Predicate/True.php"; | |
| 789 | + return new File_Archive_Predicate_True(); | |
| 790 | + } | |
| 791 | + /** | |
| 792 | + * Predicate that always evaluate to false | |
| 793 | + * | |
| 794 | + * @see File_Archive_Predicate_False | |
| 795 | + */ | |
| 796 | + function predFalse() | |
| 797 | + { | |
| 798 | + require_once "File/Archive/Predicate/False.php"; | |
| 799 | + return new File_Archive_Predicate_False(); | |
| 800 | + } | |
| 801 | + /** | |
| 802 | + * Predicate that evaluates to the logical AND of the parameters | |
| 803 | + * You can add other predicates thanks to the | |
| 804 | + * File_Archive_Predicate_And::addPredicate() function | |
| 805 | + * | |
| 806 | + * @param File_Archive_Predicate (any number of them) | |
| 807 | + * @see File_Archive_Predicate_And | |
| 808 | + */ | |
| 809 | + function predAnd() | |
| 810 | + { | |
| 811 | + require_once "File/Archive/Predicate/And.php"; | |
| 812 | + $pred = new File_Archive_Predicate_And(); | |
| 813 | + $args = func_get_args(); | |
| 814 | + foreach ($args as $p) { | |
| 815 | + $pred->addPredicate($p); | |
| 816 | + } | |
| 817 | + return $pred; | |
| 818 | + } | |
| 819 | + /** | |
| 820 | + * Predicate that evaluates to the logical OR of the parameters | |
| 821 | + * You can add other predicates thanks to the | |
| 822 | + * File_Archive_Predicate_Or::addPredicate() function | |
| 823 | + * | |
| 824 | + * @param File_Archive_Predicate (any number of them) | |
| 825 | + * @see File_Archive_Predicate_Or | |
| 826 | + */ | |
| 827 | + function predOr() | |
| 828 | + { | |
| 829 | + require_once "File/Archive/Predicate/Or.php"; | |
| 830 | + $pred = new File_Archive_Predicate_Or(); | |
| 831 | + $args = func_get_args(); | |
| 832 | + foreach ($args as $p) { | |
| 833 | + $pred->addPredicate($p); | |
| 834 | + } | |
| 835 | + return $pred; | |
| 836 | + } | |
| 837 | + /** | |
| 838 | + * Negate a predicate | |
| 839 | + * | |
| 840 | + * @param File_Archive_Predicate $pred Predicate to negate | |
| 841 | + * @see File_Archive_Predicate_Not | |
| 842 | + */ | |
| 843 | + function predNot($pred) | |
| 844 | + { | |
| 845 | + require_once "File/Archive/Predicate/Not.php"; | |
| 846 | + return new File_Archive_Predicate_Not($pred); | |
| 847 | + } | |
| 848 | + /** | |
| 849 | + * Evaluates to true iif the file is larger than a given size | |
| 850 | + * | |
| 851 | + * @param int $size the minimal size of the files (in Bytes) | |
| 852 | + * @see File_Archive_Predicate_MinSize | |
| 853 | + */ | |
| 854 | + function predMinSize($size) | |
| 855 | + { | |
| 856 | + require_once "File/Archive/Predicate/MinSize.php"; | |
| 857 | + return new File_Archive_Predicate_MinSize($size); | |
| 858 | + } | |
| 859 | + /** | |
| 860 | + * Evaluates to true iif the file has been modified after a given time | |
| 861 | + * | |
| 862 | + * @param int $time Unix timestamp of the minimal modification time of the | |
| 863 | + * files | |
| 864 | + * @see File_Archive_Predicate_MinTime | |
| 865 | + */ | |
| 866 | + function predMinTime($time) | |
| 867 | + { | |
| 868 | + require_once "File/Archive/Predicate/MinTime.php"; | |
| 869 | + return new File_Archive_Predicate_MinTime($time); | |
| 870 | + } | |
| 871 | + /** | |
| 872 | + * Evaluates to true iif the file has less that a given number of | |
| 873 | + * directories in its path | |
| 874 | + * | |
| 875 | + * @param int $depth Maximal number of directories in path of the files | |
| 876 | + * @see File_Archive_Predicate_MaxDepth | |
| 877 | + */ | |
| 878 | + function predMaxDepth($depth) | |
| 879 | + { | |
| 880 | + require_once "File/Archive/Predicate/MaxDepth.php"; | |
| 881 | + return new File_Archive_Predicate_MaxDepth($depth); | |
| 882 | + } | |
| 883 | + /** | |
| 884 | + * Evaluates to true iif the extension of the file is in a given list | |
| 885 | + * | |
| 886 | + * @param array or string $list List or comma separated string of possible | |
| 887 | + * extension of the files | |
| 888 | + * @see File_Archive_Predicate_Extension | |
| 889 | + */ | |
| 890 | + function predExtension($list) | |
| 891 | + { | |
| 892 | + require_once "File/Archive/Predicate/Extension.php"; | |
| 893 | + return new File_Archive_Predicate_Extension($list); | |
| 894 | + } | |
| 895 | + /** | |
| 896 | + * Evaluates to true iif the MIME type of the file is in a given list | |
| 897 | + * | |
| 898 | + * @param array or string $list List or comma separated string of possible | |
| 899 | + * MIME types of the files. You may enter wildcards like "image/*" to | |
| 900 | + * select all the MIME in class image | |
| 901 | + * @see File_Archive_Predicate_MIME, MIME_Type::isWildcard() | |
| 902 | + */ | |
| 903 | + function predMIME($list) | |
| 904 | + { | |
| 905 | + require_once "File/Archive/Predicate/MIME.php"; | |
| 906 | + return new File_Archive_Predicate_MIME($list); | |
| 907 | + } | |
| 908 | + /** | |
| 909 | + * Evaluates to true iif the name of the file follow a given regular | |
| 910 | + * expression | |
| 911 | + * | |
| 912 | + * @param string $ereg regular expression that the filename must follow | |
| 913 | + * @see File_Archive_Predicate_Ereg, ereg() | |
| 914 | + */ | |
| 915 | + function predEreg($ereg) | |
| 916 | + { | |
| 917 | + require_once "File/Archive/Predicate/Ereg.php"; | |
| 918 | + return new File_Archive_Predicate_Ereg($ereg); | |
| 919 | + } | |
| 920 | + /** | |
| 921 | + * Evaluates to true iif the name of the file follow a given regular | |
| 922 | + * expression (case insensitive version) | |
| 923 | + * | |
| 924 | + * @param string $ereg regular expression that the filename must follow | |
| 925 | + * @see File_Archive_Predicate_Eregi, eregi | |
| 926 | + */ | |
| 927 | + function predEregi($ereg) | |
| 928 | + { | |
| 929 | + require_once "File/Archive/Predicate/Eregi.php"; | |
| 930 | + return new File_Archive_Predicate_Eregi($ereg); | |
| 931 | + } | |
| 932 | + /** | |
| 933 | + * Evaluates to true only after a given number of evaluations | |
| 934 | + * This can be used to select files by index since the evaluation is done | |
| 935 | + * once per file | |
| 936 | + * | |
| 937 | + * @param array The indexes for which the returned predicate will return true | |
| 938 | + * are the keys of the array | |
| 939 | + * The predicate will return true if isset($indexes[$pos]) | |
| 940 | + */ | |
| 941 | + function predIndex($indexes) | |
| 942 | + { | |
| 943 | + require_once "File/Archive/Predicate/Index.php"; | |
| 944 | + return new File_Archive_Predicate_Index($indexes); | |
| 945 | + } | |
| 946 | + /** | |
| 947 | + * Custom predicate built by supplying a string expression | |
| 948 | + * | |
| 949 | + * Here are different ways to create a predicate that keeps only files | |
| 950 | + * with names shorter than 100 chars | |
| 951 | + * <sample> | |
| 952 | + * File_Archive::predCustom("return strlen($name)<100;") | |
| 953 | + * File_Archive::predCustom("strlen($name)<100;") | |
| 954 | + * File_Archive::predCustom("strlen($name)<100") | |
| 955 | + * File_Archive::predCustom("strlen($source->getFilename())<100") | |
| 956 | + * </sample> | |
| 957 | + * | |
| 958 | + * @param string $expression String containing an expression that evaluates | |
| 959 | + * to a boolean. If the expression doesn't contain a return | |
| 960 | + * statement, it will be added at the begining of the expression | |
| 961 | + * A ';' will be added at the end of the expression so that you don't | |
| 962 | + * have to write it. You may use the $name variable to refer to the | |
| 963 | + * current filename (with path...), $time for the modification time | |
| 964 | + * (unix timestamp), $size for the size of the file in bytes, $mime | |
| 965 | + * for the MIME type of the file | |
| 966 | + * @see File_Archive_Predicate_Custom | |
| 967 | + */ | |
| 968 | + function predCustom($expression) | |
| 969 | + { | |
| 970 | + require_once "File/Archive/Predicate/Custom.php"; | |
| 971 | + return new File_Archive_Predicate_Custom($expression); | |
| 972 | + } | |
| 973 | + | |
| 974 | + /** | |
| 975 | + * Send the files as a mail attachment | |
| 976 | + * | |
| 977 | + * @param Mail $mail Object used to send mail (see Mail::factory) | |
| 978 | + * @param array or String $to An array or a string with comma separated | |
| 979 | + * recipients | |
| 980 | + * @param array $headers The headers that will be passed to the Mail_mime | |
| 981 | + * object | |
| 982 | + * @param string $message Text body of the mail | |
| 983 | + * @see File_Archive_Writer_Mail | |
| 984 | + */ | |
| 985 | + function toMail($to, $headers, $message, $mail = null) | |
| 986 | + { | |
| 987 | + require_once "File/Archive/Writer/Mail.php"; | |
| 988 | + return new File_Archive_Writer_Mail($to, $headers, $message, $mail); | |
| 989 | + } | |
| 990 | + /** | |
| 991 | + * Write the files on the hard drive | |
| 992 | + * | |
| 993 | + * @param string $baseDir if specified, the files will be created in that | |
| 994 | + * directory. If they don't exist, the directories will automatically | |
| 995 | + * be created | |
| 996 | + * @see File_Archive_Writer_Files | |
| 997 | + */ | |
| 998 | + function toFiles($baseDir = "") | |
| 999 | + { | |
| 1000 | + require_once "File/Archive/Writer/Files.php"; | |
| 1001 | + return new File_Archive_Writer_Files($baseDir); | |
| 1002 | + } | |
| 1003 | + /** | |
| 1004 | + * Send the content of the files to a memory buffer | |
| 1005 | + * | |
| 1006 | + * toMemory returns a writer where the data will be written. | |
| 1007 | + * In this case, the data is accessible using the getData member | |
| 1008 | + * | |
| 1009 | + * toVariable returns a writer that will write into the given | |
| 1010 | + * variable | |
| 1011 | + * | |
| 1012 | + * @param out $data if specified, the data will be written to this buffer | |
| 1013 | + * Else, you can retrieve the buffer with the | |
| 1014 | + * File_Archive_Writer_Memory::getData() function | |
| 1015 | + * @see File_Archive_Writer_Memory | |
| 1016 | + */ | |
| 1017 | + function toMemory() | |
| 1018 | + { | |
| 1019 | + $v = ''; | |
| 1020 | + return File_Archive::toVariable($v); | |
| 1021 | + } | |
| 1022 | + function toVariable(&$v) | |
| 1023 | + { | |
| 1024 | + require_once "File/Archive/Writer/Memory.php"; | |
| 1025 | + return new File_Archive_Writer_Memory($v); | |
| 1026 | + } | |
| 1027 | + /** | |
| 1028 | + * Duplicate the writing operation on two writers | |
| 1029 | + * | |
| 1030 | + * @param File_Archive_Writer $a, $b writers where data will be duplicated | |
| 1031 | + * @see File_Archive_Writer_Multi | |
| 1032 | + */ | |
| 1033 | + function toMulti(&$aC, &$bC) | |
| 1034 | + { | |
| 1035 | + $a =& File_Archive::_convertToWriter($aC); | |
| 1036 | + $b =& File_Archive::_convertToWriter($bC); | |
| 1037 | + | |
| 1038 | + if (PEAR::isError($a)) { | |
| 1039 | + return $a; | |
| 1040 | + } | |
| 1041 | + if (PEAR::isError($b)) { | |
| 1042 | + return $b; | |
| 1043 | + } | |
| 1044 | + | |
| 1045 | + require_once "File/Archive/Writer/Multi.php"; | |
| 1046 | + $writer = new File_Archive_Writer_Multi(); | |
| 1047 | + $writer->addWriter($a); | |
| 1048 | + $writer->addWriter($b); | |
| 1049 | + return $writer; | |
| 1050 | + } | |
| 1051 | + /** | |
| 1052 | + * Send the content of the files to the standard output (so to the client | |
| 1053 | + * for a website) | |
| 1054 | + * | |
| 1055 | + * @param bool $sendHeaders If true some headers will be sent to force the | |
| 1056 | + * download of the file. Default value is true | |
| 1057 | + * @see File_Archive_Writer_Output | |
| 1058 | + */ | |
| 1059 | + function toOutput($sendHeaders = true) | |
| 1060 | + { | |
| 1061 | + require_once "File/Archive/Writer/Output.php"; | |
| 1062 | + return new File_Archive_Writer_Output($sendHeaders); | |
| 1063 | + } | |
| 1064 | + /** | |
| 1065 | + * Compress the data to a tar, gz, tar/gz or zip format | |
| 1066 | + * | |
| 1067 | + * @param string $filename name of the archive file | |
| 1068 | + * @param File_Archive_Writer $innerWriter writer where the archive will be | |
| 1069 | + * written | |
| 1070 | + * @param string $type can be one of tgz, tbz, tar, zip, gz, gzip, bz2, | |
| 1071 | + * bzip2 (default is the extension of $filename) or any composition | |
| 1072 | + * of them (for example tar.gz or tar.bz2). The case of this | |
| 1073 | + * parameter is not important. | |
| 1074 | + * @param array $stat Statistics of the archive (see stat function) | |
| 1075 | + * @param bool $autoClose If set to true, $innerWriter will be closed when | |
| 1076 | + * the returned archive is close. Default value is true. | |
| 1077 | + */ | |
| 1078 | + function toArchive($filename, &$toConvert, $type = null, | |
| 1079 | + $stat = array(), $autoClose = true) | |
| 1080 | + { | |
| 1081 | + $innerWriter =& File_Archive::_convertToWriter($toConvert); | |
| 1082 | + if (PEAR::isError($innerWriter)) { | |
| 1083 | + return $innerWriter; | |
| 1084 | + } | |
| 1085 | + $shortcuts = array("tgz" , "tbz" ); | |
| 1086 | + $reals = array("tar.gz", "tar.bz2"); | |
| 1087 | + | |
| 1088 | + if ($type === null) { | |
| 1089 | + $extensions = strtolower($filename); | |
| 1090 | + } else { | |
| 1091 | + $extensions = strtolower($type); | |
| 1092 | + } | |
| 1093 | + $extensions = explode('.', str_replace($shortcuts, $reals, $extensions)); | |
| 1094 | + if ($innerWriter !== null) { | |
| 1095 | + $writer =& $innerWriter; | |
| 1096 | + } else { | |
| 1097 | + $writer = File_Archive::toFiles(); | |
| 1098 | + } | |
| 1099 | + $nbCompressions = 0; | |
| 1100 | + $currentFilename = $filename; | |
| 1101 | + while (($extension = array_pop($extensions)) !== null) { | |
| 1102 | + unset($next); | |
| 1103 | + switch($extension) { | |
| 1104 | + case "tar": | |
| 1105 | + require_once "File/Archive/Writer/Tar.php"; | |
| 1106 | + $next = new File_Archive_Writer_Tar( | |
| 1107 | + $currentFilename, $writer, $stat, $autoClose | |
| 1108 | + ); | |
| 1109 | + unset($writer); $writer =& $next; | |
| 1110 | + break; | |
| 1111 | + case "zip": | |
| 1112 | + require_once "File/Archive/Writer/Zip.php"; | |
| 1113 | + $next = new File_Archive_Writer_Zip( | |
| 1114 | + $currentFilename, $writer, $stat, $autoClose | |
| 1115 | + ); | |
| 1116 | + unset($writer); $writer =& $next; | |
| 1117 | + break; | |
| 1118 | + case "gz": | |
| 1119 | + case "gzip": | |
| 1120 | + require_once "File/Archive/Writer/Gzip.php"; | |
| 1121 | + $next = new File_Archive_Writer_Gzip( | |
| 1122 | + $currentFilename, $writer, $stat, $autoClose | |
| 1123 | + ); | |
| 1124 | + unset($writer); $writer =& $next; | |
| 1125 | + break; | |
| 1126 | + case "bz2": | |
| 1127 | + case "bzip2": | |
| 1128 | + require_once "File/Archive/Writer/Bzip2.php"; | |
| 1129 | + $next = new File_Archive_Writer_Bzip2( | |
| 1130 | + $currentFilename, $writer, $stat, $autoClose | |
| 1131 | + ); | |
| 1132 | + unset($writer); $writer =& $next; | |
| 1133 | + break; | |
| 1134 | + case "deb": | |
| 1135 | + case "ar": | |
| 1136 | + require_once "File/Archive/Writer/Ar.php"; | |
| 1137 | + $next = new File_Archive_Writer_Ar( | |
| 1138 | + $currentFilename, $writer, $stat, $autoClose | |
| 1139 | + ); | |
| 1140 | + unset($writer); $writer =& $next; | |
| 1141 | + break; | |
| 1142 | + default: | |
| 1143 | + if ($type !== null || $nbCompressions == 0) { | |
| 1144 | + return PEAR::raiseError("Archive $extension unknown"); | |
| 1145 | + } | |
| 1146 | + break; | |
| 1147 | + } | |
| 1148 | + $nbCompressions ++; | |
| 1149 | + $autoClose = true; | |
| 1150 | + $currentFilename = implode(".", $extensions); | |
| 1151 | + } | |
| 1152 | + return $writer; | |
| 1153 | + } | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + /** | |
| 1157 | + * File_Archive::extract($source, $dest) is equivalent to $source->extract($dest) | |
| 1158 | + * If $source is a PEAR error, the error will be returned | |
| 1159 | + * It is thus easier to use this function than $source->extract, since it reduces the number of | |
| 1160 | + * error checking and doesn't force you to define a variable $source | |
| 1161 | + * | |
| 1162 | + * You may use strings as source and dest. In that case the source is automatically | |
| 1163 | + * converted to a reader using File_Archive::read and the dest is converted to a | |
| 1164 | + * writer using File_Archive::appender | |
| 1165 | + * Since PHP doesn't allow to pass literal strings by ref, you will have to use temporary | |
| 1166 | + * variables. | |
| 1167 | + * File_Archive::extract($src = 'archive.zip/', $dest = 'dir') will extract the archive to 'dir' | |
| 1168 | + * It is the same as | |
| 1169 | + * File_Archive::extract( | |
| 1170 | + * File_Archive::read('archive.zip/'), | |
| 1171 | + * File_Archive::appender('dir') | |
| 1172 | + * ); | |
| 1173 | + * You may use any variable in the extract function ($from/$to, $a/$b...). | |
| 1174 | + * | |
| 1175 | + * @param File_Archive_Reader $source The source that will be read | |
| 1176 | + * @param File_Archive_Writer $dest Where to copy $source files | |
| 1177 | + * @param bool $autoClose if true (default), $dest will be closed after the extraction | |
| 1178 | + * @param int $bufferSize Size of the buffer to use to move data from the reader to the buffer | |
| 1179 | + * If $bufferSize <= 0 (default), the blockSize option is used | |
| 1180 | + * You shouldn't need to change that | |
| 1181 | + * @return null or a PEAR error if an error occured | |
| 1182 | + */ | |
| 1183 | + function extract(&$sourceToConvert, &$destToConvert, $autoClose = true, $bufferSize = 0) | |
| 1184 | + { | |
| 1185 | + $source =& File_Archive::_convertToReader($sourceToConvert); | |
| 1186 | + if (PEAR::isError($source)) { | |
| 1187 | + return $source; | |
| 1188 | + } | |
| 1189 | + $dest =& File_Archive::_convertToWriter($destToConvert); | |
| 1190 | + return $source->extract($dest, $autoClose, $bufferSize); | |
| 1191 | + } | |
| 1192 | + | |
| 1193 | + /** | |
| 1194 | + * Create a writer that can be used to append files to an archive inside a source | |
| 1195 | + * If the archive can't be found in the source, it will be created | |
| 1196 | + * If source is set to null, File_Archive::toFiles will be assumed | |
| 1197 | + * If type is set to null, the type of the archive will be determined looking at | |
| 1198 | + * the extension in the URL | |
| 1199 | + * stat is the array of stat (returned by stat() PHP function of Reader getStat()) | |
| 1200 | + * to use if the archive must be created | |
| 1201 | + * | |
| 1202 | + * This function allows to create or append data to nested archives. Only one | |
| 1203 | + * archive will be created and if your creation requires creating several nested | |
| 1204 | + * archives, a PEAR error will be returned | |
| 1205 | + * | |
| 1206 | + * After this call, $source will be closed and should not be used until the | |
| 1207 | + * returned writer is closed. | |
| 1208 | + * | |
| 1209 | + * @param File_Archive_Reader $source A reader where some files will be appended | |
| 1210 | + * @param string $URL URL to reach the archive in the source. | |
| 1211 | + * if $URL is null, a writer to append files to the $source reader will | |
| 1212 | + * be returned | |
| 1213 | + * @param bool $unique If true, the duplicate files will be deleted on close | |
| 1214 | + * Default is false (and setting it to true may have some performance | |
| 1215 | + * consequences) | |
| 1216 | + * @param string $type Extension of the archive (or null to use the one in the URL) | |
| 1217 | + * @param array $stat Used only if archive is created, array of stat as returned | |
| 1218 | + * by PHP stat function or Reader getStat function: stats of the archive) | |
| 1219 | + * Time (index 9) will be overwritten to current time | |
| 1220 | + * @return File_Archive_Writer a writer that you can use to append files to the reader | |
| 1221 | + */ | |
| 1222 | + function appenderFromSource(&$toConvert, $URL = null, $unique = null, | |
| 1223 | + $type = null, $stat = array()) | |
| 1224 | + { | |
| 1225 | + $source =& File_Archive::_convertToReader($toConvert); | |
| 1226 | + if (PEAR::isError($source)) { | |
| 1227 | + return $source; | |
| 1228 | + } | |
| 1229 | + if ($unique == null) { | |
| 1230 | + $unique = File_Archive::getOption("appendRemoveDuplicates"); | |
| 1231 | + } | |
| 1232 | + | |
| 1233 | + //Do not report the fact that the archive does not exist as an error | |
| 1234 | + PEAR::pushErrorHandling(PEAR_ERROR_RETURN); | |
| 1235 | + | |
| 1236 | + if ($URL === null) { | |
| 1237 | + $result =& $source; | |
| 1238 | + } else { | |
| 1239 | + if ($type === null) { | |
| 1240 | + $result = File_Archive::_readSource($source, $URL.'/', $reachable, $baseDir); | |
| 1241 | + } else { | |
| 1242 | + $result = File_Archive::readArchive( | |
| 1243 | + $type, | |
| 1244 | + File_Archive::_readSource($source, $URL, $reachable, $baseDir) | |
| 1245 | + ); | |
| 1246 | + } | |
| 1247 | + } | |
| 1248 | + | |
| 1249 | + PEAR::popErrorHandling(); | |
| 1250 | + | |
| 1251 | + if (!PEAR::isError($result)) { | |
| 1252 | + if ($unique) { | |
| 1253 | + require_once "File/Archive/Writer/UniqueAppender.php"; | |
| 1254 | + return new File_Archive_Writer_UniqueAppender($result); | |
| 1255 | + } else { | |
| 1256 | + return $result->makeAppendWriter(); | |
| 1257 | + } | |
| 1258 | + } | |
| 1259 | + | |
| 1260 | + //The source can't be found and has to be created | |
| 1261 | + $stat[9] = $stat['mtime'] = time(); | |
| 1262 | + | |
| 1263 | + if (empty($baseDir)) { | |
| 1264 | + if ($source !== null) { | |
| 1265 | + $writer =& $source->makeWriter(); | |
| 1266 | + } else { | |
| 1267 | + $writer =& File_Archive::toFiles(); | |
| 1268 | + } | |
| 1269 | + if (PEAR::isError($writer)) { | |
| 1270 | + return $writer; | |
| 1271 | + } | |
| 1272 | + | |
| 1273 | + PEAR::pushErrorHandling(PEAR_ERROR_RETURN); | |
| 1274 | + $result = File_Archive::toArchive($reachable, $writer, $type); | |
| 1275 | + PEAR::popErrorHandling(); | |
| 1276 | + | |
| 1277 | + if (PEAR::isError($result)) { | |
| 1278 | + $result = File_Archive::toFiles($reachable); | |
| 1279 | + } | |
| 1280 | + } else { | |
| 1281 | + $reachedSource = File_Archive::readSource($source, $reachable); | |
| 1282 | + if (PEAR::isError($reachedSource)) { | |
| 1283 | + return $reachedSource; | |
| 1284 | + } | |
| 1285 | + $writer = $reachedSource->makeWriter(); | |
| 1286 | + if (PEAR::isError($writer)) { | |
| 1287 | + return $writer; | |
| 1288 | + } | |
| 1289 | + | |
| 1290 | + PEAR::pushErrorHandling(PEAR_ERROR_RETURN); | |
| 1291 | + $result = File_Archive::toArchive($baseDir, $writer, $type); | |
| 1292 | + PEAR::popErrorHandling(); | |
| 1293 | + | |
| 1294 | + if (PEAR::isError($result)) { | |
| 1295 | + require_once "File/Archive/Writer/AddBaseName.php"; | |
| 1296 | + $result = new File_Archive_Writer_AddBaseName( | |
| 1297 | + $baseDir, $writer); | |
| 1298 | + if (PEAR::isError($result)) { | |
| 1299 | + return $result; | |
| 1300 | + } | |
| 1301 | + } | |
| 1302 | + } | |
| 1303 | + return $result; | |
| 1304 | + } | |
| 1305 | + | |
| 1306 | + /** | |
| 1307 | + * Create a writer that allows appending new files to an existing archive | |
| 1308 | + * This function actes as appendToSource with source being the system files | |
| 1309 | + * $URL can't be null here | |
| 1310 | + * | |
| 1311 | + * @param File_Archive_Reader $source A reader where some files will be appended | |
| 1312 | + * @return File_Archive_Writer a writer that you can use to append files to the reader | |
| 1313 | + */ | |
| 1314 | + function appender($URL, $unique = null, $type = null, $stat = array()) | |
| 1315 | + { | |
| 1316 | + $source = null; | |
| 1317 | + return File_Archive::appenderFromSource($source, $URL, $unique, $type, $stat); | |
| 1318 | + } | |
| 1319 | + | |
| 1320 | + /** | |
| 1321 | + * Remove the files that follow a given predicate from the source | |
| 1322 | + * If URL is null, the files will be removed from the source directly | |
| 1323 | + * Else, URL must link to a source from which the files will be removed | |
| 1324 | + * | |
| 1325 | + * @param File_Archive_Predicate $pred The files that follow the predicate | |
| 1326 | + * (for which $pred->isTrue($source) is true) will be erased | |
| 1327 | + * @param File_Archive_Reader $source A reader that contains the files to remove | |
| 1328 | + */ | |
| 1329 | + function removeFromSource(&$pred, &$toConvert, $URL = null) | |
| 1330 | + { | |
| 1331 | + $source =& File_Archive::_convertToReader($toConvert); | |
| 1332 | + if (PEAR::isError($source)) { | |
| 1333 | + return $source; | |
| 1334 | + } | |
| 1335 | + if ($URL === null) { | |
| 1336 | + $result = &$source; | |
| 1337 | + } else { | |
| 1338 | + if (substr($URL, -1) !== '/') { | |
| 1339 | + $URL .= '/'; | |
| 1340 | + } | |
| 1341 | + $result = File_Archive::readSource($source, $URL); | |
| 1342 | + } | |
| 1343 | + | |
| 1344 | + $writer = $result->makeWriterRemoveFiles($pred); | |
| 1345 | + if (PEAR::isError($writer)) { | |
| 1346 | + return $writer; | |
| 1347 | + } | |
| 1348 | + $writer->close(); | |
| 1349 | + } | |
| 1350 | + | |
| 1351 | + /** | |
| 1352 | + * Remove the files that follow a given predicate from the archive specified | |
| 1353 | + * in $URL | |
| 1354 | + * | |
| 1355 | + * @param $URL URL of the archive where some files must be removed | |
| 1356 | + */ | |
| 1357 | + function remove($pred, $URL) | |
| 1358 | + { | |
| 1359 | + $source = null; | |
| 1360 | + return File_Archive::removeFromSource($pred, $source, $URL); | |
| 1361 | + } | |
| 1362 | + | |
| 1363 | + /** | |
| 1364 | + * Remove duplicates from a source, keeping the most recent one (or the one that has highest pos in | |
| 1365 | + * the archive if the files have same date or no date specified) | |
| 1366 | + * | |
| 1367 | + * @param File_Archive_Reader a reader that may contain duplicates | |
| 1368 | + */ | |
| 1369 | + function removeDuplicatesFromSource(&$toConvert, $URL = null) | |
| 1370 | + { | |
| 1371 | + $source =& File_Archive::_convertToReader($toConvert); | |
| 1372 | + if (PEAR::isError($source)) { | |
| 1373 | + return $source; | |
| 1374 | + } | |
| 1375 | + if ($URL !== null && substr($URL, -1) != '/') { | |
| 1376 | + $URL .= '/'; | |
| 1377 | + } | |
| 1378 | + | |
| 1379 | + if ($source === null) { | |
| 1380 | + $source = File_Archive::read($URL); | |
| 1381 | + } | |
| 1382 | + | |
| 1383 | + require_once "File/Archive/Predicate/Duplicate.php"; | |
| 1384 | + $pred = new File_Archive_Predicate_Duplicate($source); | |
| 1385 | + $source->close(); | |
| 1386 | + return File_Archive::removeFromSource( | |
| 1387 | + $pred, | |
| 1388 | + $source, | |
| 1389 | + null | |
| 1390 | + ); | |
| 1391 | + } | |
| 1392 | + | |
| 1393 | + /** | |
| 1394 | + * Remove duplicates from the archive specified in the URL | |
| 1395 | + */ | |
| 1396 | + function removeDuplicates($URL) | |
| 1397 | + { | |
| 1398 | + $source = null; | |
| 1399 | + return File_Archive::removeDuplicatesFromSource($source, $URL); | |
| 1400 | + } | |
| 1401 | +} | |
| 1402 | + | |
| 1403 | +?> | |
| 0 | 1404 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Predicate.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * A predicate is an object that can evaluate to true or false depending on the | |
| 6 | + * file currently read by a File_Archive_Reader | |
| 7 | + * | |
| 8 | + * @see File_Archive_Reader_Filter | |
| 9 | + * | |
| 10 | + * PHP versions 4 and 5 | |
| 11 | + * | |
| 12 | + * This library is free software; you can redistribute it and/or | |
| 13 | + * modify it under the terms of the GNU Lesser General Public | |
| 14 | + * License as published by the Free Software Foundation; either | |
| 15 | + * version 2.1 of the License, or (at your option) any later version. | |
| 16 | + * | |
| 17 | + * This library is distributed in the hope that it will be useful, | |
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 20 | + * Lesser General Public License for more details. | |
| 21 | + * | |
| 22 | + * You should have received a copy of the GNU Lesser General Public | |
| 23 | + * License along with this library; if not, write to the Free Software | |
| 24 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 25 | + * | |
| 26 | + * @category File Formats | |
| 27 | + * @package File_Archive | |
| 28 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 29 | + * @copyright 1997-2005 The PHP Group | |
| 30 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 31 | + * @version CVS: $Id: Predicate.php,v 1.7 2005/05/26 21:30:18 vincentlascaux Exp $ | |
| 32 | + * @link http://pear.php.net/package/File_Archive | |
| 33 | + */ | |
| 34 | + | |
| 35 | +require_once "File/Archive/Reader.php"; | |
| 36 | + | |
| 37 | +/** | |
| 38 | + * A predicate is an object that can evaluate to true or false depending on the | |
| 39 | + * file currently read by a File_Archive_Reader | |
| 40 | + * | |
| 41 | + * @see File_Archive_Reader_Filter | |
| 42 | + */ | |
| 43 | +class File_Archive_Predicate | |
| 44 | +{ | |
| 45 | + /** | |
| 46 | + * Indicates whether the current file from the reader should be kept | |
| 47 | + * | |
| 48 | + * @param File_Archive_Reader $source Reader which will be filtered | |
| 49 | + * @return bool False iif the current file must be filtered out | |
| 50 | + */ | |
| 51 | + function isTrue(&$source) | |
| 52 | + { | |
| 53 | + return PEAR::raiseError("Predicat abstract function call"); | |
| 54 | + } | |
| 55 | +} | |
| 56 | + | |
| 57 | +?> | |
| 0 | 58 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Predicate/And.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Evaluates to true iif all predicates given as constructor parameters evaluate | |
| 6 | + * to true | |
| 7 | + * | |
| 8 | + * PHP versions 4 and 5 | |
| 9 | + * | |
| 10 | + * This library is free software; you can redistribute it and/or | |
| 11 | + * modify it under the terms of the GNU Lesser General Public | |
| 12 | + * License as published by the Free Software Foundation; either | |
| 13 | + * version 2.1 of the License, or (at your option) any later version. | |
| 14 | + * | |
| 15 | + * This library is distributed in the hope that it will be useful, | |
| 16 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 17 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 18 | + * Lesser General Public License for more details. | |
| 19 | + * | |
| 20 | + * You should have received a copy of the GNU Lesser General Public | |
| 21 | + * License along with this library; if not, write to the Free Software | |
| 22 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 23 | + * | |
| 24 | + * @category File Formats | |
| 25 | + * @package File_Archive | |
| 26 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 27 | + * @copyright 1997-2005 The PHP Group | |
| 28 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 29 | + * @version CVS: $Id: And.php,v 1.8 2005/04/21 10:01:46 vincentlascaux Exp $ | |
| 30 | + * @link http://pear.php.net/package/File_Archive | |
| 31 | + */ | |
| 32 | + | |
| 33 | +require_once "File/Archive/Predicate.php"; | |
| 34 | + | |
| 35 | +/** | |
| 36 | + * Evaluates to true iif all predicates given as constructor parameters evaluate | |
| 37 | + * to true | |
| 38 | + * | |
| 39 | + * Example: | |
| 40 | + * new File_Archive_Predicate_And($pred1, $pred2, $pred3) | |
| 41 | + * | |
| 42 | + * @see File_Archive_Predicate, File_Archive_Reader_Filter | |
| 43 | + */ | |
| 44 | +class File_Archive_Predicate_And extends File_Archive_Predicate | |
| 45 | +{ | |
| 46 | + /** | |
| 47 | + * @var Array List of File_Archive_Predicate objects given as an argument | |
| 48 | + * @access private | |
| 49 | + */ | |
| 50 | + var $preds; | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * Build the predicate using the optional File_Archive_Predicates given as | |
| 54 | + * arguments | |
| 55 | + * | |
| 56 | + * Example: | |
| 57 | + * new File_Archive_Predicate_And($pred1, $pred2, $pred3) | |
| 58 | + */ | |
| 59 | + function File_Archive_Predicate_And() | |
| 60 | + { | |
| 61 | + $this->preds = func_get_args(); | |
| 62 | + } | |
| 63 | + | |
| 64 | + /** | |
| 65 | + * Add a new predicate to the list | |
| 66 | + * | |
| 67 | + * @param File_Archive_Predicate The predicate to add | |
| 68 | + */ | |
| 69 | + function addPredicate($pred) | |
| 70 | + { | |
| 71 | + $this->preds[] = $pred; | |
| 72 | + } | |
| 73 | + /** | |
| 74 | + * @see File_Archive_Predicate::isTrue() | |
| 75 | + */ | |
| 76 | + function isTrue(&$source) | |
| 77 | + { | |
| 78 | + foreach ($this->preds as $p) { | |
| 79 | + if (!$p->isTrue($source)) { | |
| 80 | + return false; | |
| 81 | + } | |
| 82 | + } | |
| 83 | + return true; | |
| 84 | + } | |
| 85 | +} | |
| 86 | + | |
| 87 | +?> | |
| 0 | 88 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Predicate/Current.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Evaluates to true only once, and then always to false | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: Current.php,v 1.1 2005/05/28 23:17:28 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "File/Archive/Predicate.php"; | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * Evaluates to true only once, and then always to false | |
| 36 | + */ | |
| 37 | +class File_Archive_Predicate_Current extends File_Archive_Predicate | |
| 38 | +{ | |
| 39 | + var $value = true; | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * @see File_Archive_Predicate::isTrue() | |
| 43 | + */ | |
| 44 | + function isTrue(&$source) | |
| 45 | + { | |
| 46 | + $tmp = $this->value; | |
| 47 | + $this->value = false; | |
| 48 | + return $tmp; | |
| 49 | + } | |
| 50 | +} | |
| 51 | + | |
| 52 | +?> | |
| 0 | 53 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Predicate/Custom.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Custom predicate built by supplying a string expression | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: Custom.php,v 1.7 2005/04/21 10:01:46 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "File/Archive/Predicate.php"; | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * Custom predicate built by supplying a string expression | |
| 36 | + * | |
| 37 | + * Example: | |
| 38 | + * new File_Archive_Predicate_Custom("return strlen($name)<100;") | |
| 39 | + * new File_Archive_Predicate_Custom("strlen($name)<100;") | |
| 40 | + * new File_Archive_Predicate_Custom("strlen($name)<100") | |
| 41 | + * new File_Archive_Predicate_Custom("strlen($source->getFilename())<100") | |
| 42 | + * | |
| 43 | + * @see File_Archive_Predicate, File_Archive_Reader_Filter | |
| 44 | + */ | |
| 45 | +class File_Archive_Predicate_Custom extends File_Archive_Predicate | |
| 46 | +{ | |
| 47 | + var $expression; | |
| 48 | + var $useName; | |
| 49 | + var $useStat; | |
| 50 | + var $useMIME; | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * @param string $expression PHP code that evaluates too a boolean | |
| 54 | + * It can use the $source variable. If return is ommited, it will be | |
| 55 | + * added to the begining of the expression. A ; will also be added at | |
| 56 | + * the end so that you don't need to write it | |
| 57 | + */ | |
| 58 | + function File_Archive_Predicate_Custom($expression) | |
| 59 | + { | |
| 60 | + $this->expression = $expression.";"; | |
| 61 | + if (strpos($this->expression, "return") === false) { | |
| 62 | + $this->expression = "return ".$this->expression; | |
| 63 | + } | |
| 64 | + $this->useName = (strpos($this->expression, '$name') !== false); | |
| 65 | + $this->useStat = (strpos($this->expression, '$stat') !== false); | |
| 66 | + $this->useMIME = (strpos($this->expression, '$mime') !== false); | |
| 67 | + } | |
| 68 | + /** | |
| 69 | + * @see File_Archive_Predicate::isTrue() | |
| 70 | + */ | |
| 71 | + function isTrue(&$source) | |
| 72 | + { | |
| 73 | + if ($this->useName) { | |
| 74 | + $name = $source->getFilename(); | |
| 75 | + } | |
| 76 | + if ($this->useStat) { | |
| 77 | + $stat = $source->getStat(); | |
| 78 | + $size = $stat[7]; | |
| 79 | + $time = (isset($stat[9]) ? $stat[9] : null); | |
| 80 | + } | |
| 81 | + if ($this->useMIME) { | |
| 82 | + $mime = $source->getMIME(); | |
| 83 | + } | |
| 84 | + return eval($this->expression); | |
| 85 | + } | |
| 86 | +} | |
| 87 | + | |
| 88 | +?> | |
| 0 | 89 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Predicate/Duplicate.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Evaluates to true if a for the files for which a newer version | |
| 6 | + * can be found in a specified archive | |
| 7 | + * Comparison is by default made on dates of the files, or position | |
| 8 | + * in the archive (if two files have the same date or the date of a | |
| 9 | + * file is not specified). | |
| 10 | + * | |
| 11 | + * PHP versions 4 and 5 | |
| 12 | + * | |
| 13 | + * This library is free software; you can redistribute it and/or | |
| 14 | + * modify it under the terms of the GNU Lesser General Public | |
| 15 | + * License as published by the Free Software Foundation; either | |
| 16 | + * version 2.1 of the License, or (at your option) any later version. | |
| 17 | + * | |
| 18 | + * This library is distributed in the hope that it will be useful, | |
| 19 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 20 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 21 | + * Lesser General Public License for more details. | |
| 22 | + * | |
| 23 | + * You should have received a copy of the GNU Lesser General Public | |
| 24 | + * License along with this library; if not, write to the Free Software | |
| 25 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 26 | + * | |
| 27 | + * @category File Formats | |
| 28 | + * @package File_Archive | |
| 29 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 30 | + * @copyright 1997-2005 The PHP Group | |
| 31 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 32 | + * @version CVS: $Id: Duplicate.php,v 1.1 2005/05/30 17:18:11 vincentlascaux Exp $ | |
| 33 | + * @link http://pear.php.net/package/File_Archive | |
| 34 | + */ | |
| 35 | + | |
| 36 | +require_once "File/Archive/Predicate.php"; | |
| 37 | + | |
| 38 | +/** | |
| 39 | + * Evaluates to true if a for the files for which a newer version | |
| 40 | + * can be found in a specified archive | |
| 41 | + * Comparison is by default made on dates of the files, or position | |
| 42 | + * in the archive (if two files have the same date or the date of a | |
| 43 | + * file is not specified). | |
| 44 | + */ | |
| 45 | +class File_Archive_Predicate_Duplicate extends File_Archive_Predicate | |
| 46 | +{ | |
| 47 | + /** | |
| 48 | + * @var array Key is the filename, value is an array of date (index 0) and | |
| 49 | + * position in the archive (index) 1 of the newest entry with this filename | |
| 50 | + */ | |
| 51 | + var $newest = array(); | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * @var int The current position of the file in the source | |
| 55 | + */ | |
| 56 | + var $pos = 0; | |
| 57 | + | |
| 58 | + /** | |
| 59 | + * @param File_Archive_Reader $source The source will be inspected to find | |
| 60 | + * the date of old files | |
| 61 | + * The predicate should then be used on the same source to remove the | |
| 62 | + * old duplicate files | |
| 63 | + */ | |
| 64 | + function File_Archive_Predicate_Duplicate(&$source) | |
| 65 | + { | |
| 66 | + //Ensure we are at the begining of the file | |
| 67 | + $source->close(); | |
| 68 | + $pos = 0; | |
| 69 | + while ($source->next()) { | |
| 70 | + $filename = $source->getFilename(); | |
| 71 | + $stat = $source->getStat(); | |
| 72 | + $value = isset($this->newest[$filename]) ? $this->newest[$filename] : null; | |
| 73 | + | |
| 74 | + if ($value === null || | |
| 75 | + $this->compare($stat[9], $value[0]) >= 0 | |
| 76 | + ) { | |
| 77 | + $this->newest[$filename] = array($stat[9], $pos); | |
| 78 | + } | |
| 79 | + $pos++; | |
| 80 | + } | |
| 81 | + } | |
| 82 | + | |
| 83 | + /** | |
| 84 | + * Compare the dates of two files. null is considered infinitely old | |
| 85 | + * | |
| 86 | + * @return int < 0 if $a can be considered older than $b | |
| 87 | + * = 0 if $a and $b can be considered same age | |
| 88 | + * > 0 if $a can be considered newer than $b | |
| 89 | + */ | |
| 90 | + function compare($a, $b) { | |
| 91 | + return ($a === null ? -1 : $a) - ($b === null ? -1 : $b); | |
| 92 | + } | |
| 93 | + | |
| 94 | + /** | |
| 95 | + * @see File_Archive_Predicate::isTrue() | |
| 96 | + */ | |
| 97 | + function isTrue(&$source) | |
| 98 | + { | |
| 99 | + $filename = $source->getFilename(); | |
| 100 | + $stat = $source->getStat(); | |
| 101 | + $value = isset($this->newest[$filename]) ? $this->newest[$filename] : null; | |
| 102 | + if ($value === null) { | |
| 103 | + $delete = false; | |
| 104 | + } else { | |
| 105 | + $comp = $this->compare($stat[9], $value[0]); | |
| 106 | + | |
| 107 | + $delete = $comp < 0 || | |
| 108 | + ($comp == 0 && $this->pos != $value[1]); | |
| 109 | + | |
| 110 | + } | |
| 111 | + $this->pos++; | |
| 112 | + return $delete; | |
| 113 | + } | |
| 114 | +} | |
| 115 | + | |
| 116 | +?> | |
| 0 | 117 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Predicate/Ereg.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Keep only the files which name follow a given regular expression | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: Ereg.php,v 1.5 2005/04/21 10:01:46 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "File/Archive/Predicate.php"; | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * Keep only the files which name follow a given regular expression | |
| 36 | + * | |
| 37 | + * @see File_Archive_Predicate, File_Archive_Reader_Filter ereg | |
| 38 | + */ | |
| 39 | +class File_Archive_Predicate_Ereg extends File_Archive_Predicate | |
| 40 | +{ | |
| 41 | + var $ereg; | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * @param string $ereg is the regular expression | |
| 45 | + */ | |
| 46 | + function File_Archive_Predicate_Ereg($ereg) | |
| 47 | + { | |
| 48 | + $this->ereg = $ereg; | |
| 49 | + } | |
| 50 | + /** | |
| 51 | + * @see File_Archive_Predicate::isTrue() | |
| 52 | + */ | |
| 53 | + function isTrue(&$source) | |
| 54 | + { | |
| 55 | + return ereg($this->ereg, $source->getFilename()); | |
| 56 | + } | |
| 57 | +} | |
| 58 | + | |
| 59 | +?> | |
| 0 | 60 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Predicate/Eregi.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Keep only the files which name follow a given case insensitive regular | |
| 6 | + * expression | |
| 7 | + * | |
| 8 | + * PHP versions 4 and 5 | |
| 9 | + * | |
| 10 | + * This library is free software; you can redistribute it and/or | |
| 11 | + * modify it under the terms of the GNU Lesser General Public | |
| 12 | + * License as published by the Free Software Foundation; either | |
| 13 | + * version 2.1 of the License, or (at your option) any later version. | |
| 14 | + * | |
| 15 | + * This library is distributed in the hope that it will be useful, | |
| 16 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 17 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 18 | + * Lesser General Public License for more details. | |
| 19 | + * | |
| 20 | + * You should have received a copy of the GNU Lesser General Public | |
| 21 | + * License along with this library; if not, write to the Free Software | |
| 22 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 23 | + * | |
| 24 | + * @category File Formats | |
| 25 | + * @package File_Archive | |
| 26 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 27 | + * @copyright 1997-2005 The PHP Group | |
| 28 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 29 | + * @version CVS: $Id: Eregi.php,v 1.6 2005/04/21 10:01:46 vincentlascaux Exp $ | |
| 30 | + * @link http://pear.php.net/package/File_Archive | |
| 31 | + */ | |
| 32 | + | |
| 33 | +require_once "File/Archive/Predicate.php"; | |
| 34 | + | |
| 35 | +/** | |
| 36 | + * Keep only the files which name follow a given case insensitive regular | |
| 37 | + * expression | |
| 38 | + * | |
| 39 | + * @see File_Archive_Predicate, File_Archive_Reader_Filter eregi | |
| 40 | + */ | |
| 41 | +class File_Archive_Predicate_Eregi extends File_Archive_Predicate | |
| 42 | +{ | |
| 43 | + var $ereg; | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * @param string $ereg is the regular expression | |
| 47 | + */ | |
| 48 | + function File_Archive_Predicate_Eregi($ereg) | |
| 49 | + { | |
| 50 | + $this->ereg = $ereg; | |
| 51 | + } | |
| 52 | + /** | |
| 53 | + * @see File_Archive_Predicate::isTrue() | |
| 54 | + */ | |
| 55 | + function isTrue(&$source) | |
| 56 | + { | |
| 57 | + return eregi($this->ereg, $source->getFilename()); | |
| 58 | + } | |
| 59 | +} | |
| 60 | + | |
| 61 | +?> | |
| 0 | 62 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Predicate/Extension.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Keep only the files that have a specific extension | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: Extension.php,v 1.5 2005/04/21 10:01:46 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "File/Archive/Predicate.php"; | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * Keep only the files that have a specific extension | |
| 36 | + * | |
| 37 | + * @see File_Archive_Predicate, File_Archive_Reader_Filter | |
| 38 | + */ | |
| 39 | +class File_Archive_Predicate_Extension extends File_Archive_Predicate | |
| 40 | +{ | |
| 41 | + var $extensions; | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * @param $extensions array or comma separated string of allowed extensions | |
| 45 | + */ | |
| 46 | + function File_Archive_Predicate_Extension($extensions) | |
| 47 | + { | |
| 48 | + if (is_string($extensions)) { | |
| 49 | + $this->extensions = explode(",",$extensions); | |
| 50 | + } else { | |
| 51 | + $this->extensions = $extensions; | |
| 52 | + } | |
| 53 | + } | |
| 54 | + /** | |
| 55 | + * @see File_Archive_Predicate::isTrue() | |
| 56 | + */ | |
| 57 | + function isTrue(&$source) | |
| 58 | + { | |
| 59 | + $filename = $source->getFilename(); | |
| 60 | + $pos = strrpos($filename, '.'); | |
| 61 | + $extension = ""; | |
| 62 | + if ($pos !== FALSE) { | |
| 63 | + $extension = strtolower(substr($filename, $pos+1)); | |
| 64 | + } | |
| 65 | + $result = in_array($extension, $this->extensions); | |
| 66 | + | |
| 67 | + return $result; | |
| 68 | + } | |
| 69 | +} | |
| 70 | + | |
| 71 | +?> | |
| 0 | 72 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Predicate/False.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Always evaluate to false | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: False.php,v 1.5 2005/04/21 10:01:46 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "File/Archive/Predicate.php"; | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * Always evaluate to false | |
| 36 | + * | |
| 37 | + * @see File_Archive_Predicate, File_Archive_Reader_Filter | |
| 38 | + */ | |
| 39 | +class File_Archive_Predicate_False extends File_Archive_Predicate | |
| 40 | +{ | |
| 41 | + /** | |
| 42 | + * @see File_Archive_Predicate::isTrue() | |
| 43 | + */ | |
| 44 | + function isTrue(&$source) { return false; } | |
| 45 | +} | |
| 46 | + | |
| 47 | +?> | |
| 0 | 48 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Predicate/Index.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Evaluates to true if the index is in a given array of indexes | |
| 6 | + * The array has the indexes in key (so you may want to call | |
| 7 | + * array_flip if your array has indexes as value) | |
| 8 | + * | |
| 9 | + * PHP versions 4 and 5 | |
| 10 | + * | |
| 11 | + * This library is free software; you can redistribute it and/or | |
| 12 | + * modify it under the terms of the GNU Lesser General Public | |
| 13 | + * License as published by the Free Software Foundation; either | |
| 14 | + * version 2.1 of the License, or (at your option) any later version. | |
| 15 | + * | |
| 16 | + * This library is distributed in the hope that it will be useful, | |
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 19 | + * Lesser General Public License for more details. | |
| 20 | + * | |
| 21 | + * You should have received a copy of the GNU Lesser General Public | |
| 22 | + * License along with this library; if not, write to the Free Software | |
| 23 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 24 | + * | |
| 25 | + * @category File Formats | |
| 26 | + * @package File_Archive | |
| 27 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 28 | + * @copyright 1997-2005 The PHP Group | |
| 29 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 30 | + * @version CVS: $Id: Index.php,v 1.1 2005/05/30 19:44:53 vincentlascaux Exp $ | |
| 31 | + * @link http://pear.php.net/package/File_Archive | |
| 32 | + */ | |
| 33 | + | |
| 34 | +require_once "File/Archive/Predicate.php"; | |
| 35 | + | |
| 36 | +/** | |
| 37 | + * Evaluates to true if the index is in a given array of indexes | |
| 38 | + * The array has the indexes in key (so you may want to call | |
| 39 | + * array_flip if your array has indexes as value) | |
| 40 | + */ | |
| 41 | +class File_Archive_Predicate_Index extends File_Archive_Predicate | |
| 42 | +{ | |
| 43 | + var $indexes; | |
| 44 | + var $pos = 0; | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * @param $extensions array or comma separated string of allowed extensions | |
| 48 | + */ | |
| 49 | + function File_Archive_Predicate_Index($indexes) | |
| 50 | + { | |
| 51 | + $this->indexes = $indexes; | |
| 52 | + } | |
| 53 | + /** | |
| 54 | + * @see File_Archive_Predicate::isTrue() | |
| 55 | + */ | |
| 56 | + function isTrue(&$source) | |
| 57 | + { | |
| 58 | + return isset($this->indexes[$this->pos++]); | |
| 59 | + } | |
| 60 | +} | |
| 61 | + | |
| 62 | +?> | |
| 0 | 63 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Predicate/MIME.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Keep only the files that have a specific MIME type | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: MIME.php,v 1.5 2005/04/21 10:01:46 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "File/Archive/Predicate.php"; | |
| 33 | +require_once "MIME/Type.php"; | |
| 34 | + | |
| 35 | +/** | |
| 36 | + * Keep only the files that have a specific MIME type | |
| 37 | + * | |
| 38 | + * @see File_Archive_Predicate, File_Archive_Reader_Filter | |
| 39 | + */ | |
| 40 | +class File_Archive_Predicate_MIME extends File_Archive_Predicate | |
| 41 | +{ | |
| 42 | + var $mimes; | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * @param $extensions array or comma separated string of allowed extensions | |
| 46 | + */ | |
| 47 | + function File_Archive_Predicate_MIME($mimes) | |
| 48 | + { | |
| 49 | + if (is_string($mimes)) { | |
| 50 | + $this->mimes = explode(",",$mimes); | |
| 51 | + } else { | |
| 52 | + $this->mimes = $mimes; | |
| 53 | + } | |
| 54 | + } | |
| 55 | + /** | |
| 56 | + * @see File_Archive_Predicate::isTrue() | |
| 57 | + */ | |
| 58 | + function isTrue(&$source) | |
| 59 | + { | |
| 60 | + $sourceMIME = $source->getMIME(); | |
| 61 | + foreach ($this->mimes as $mime) { | |
| 62 | + if (MIME_Type::isWildcard($mime)) { | |
| 63 | + $result = MIME_Type::wildcardMatch($mime, $sourceMIME); | |
| 64 | + } else { | |
| 65 | + $result = ($mime == $sourceMIME); | |
| 66 | + } | |
| 67 | + if ($result !== false) { | |
| 68 | + return $result; | |
| 69 | + } | |
| 70 | + } | |
| 71 | + return false; | |
| 72 | + } | |
| 73 | +} | |
| 74 | + | |
| 75 | +?> | |
| 0 | 76 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Predicate/MaxDepth.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Remove the URLs with a too high number of nested directories | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: MaxDepth.php,v 1.6 2005/04/21 10:01:46 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "File/Archive/Predicate.php"; | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * Remove the URLs with a too high number of nested directories | |
| 36 | + * | |
| 37 | + * @see File_Archive_Predicate, File_Archive_Reader_Filter | |
| 38 | + */ | |
| 39 | +class File_Archive_Predicate_MaxDepth extends File_Archive_Predicate | |
| 40 | +{ | |
| 41 | + var $maxDepth; | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * @param int $maxDepth Maximal number of folders before the actual file in | |
| 45 | + * $source->getFilename(). | |
| 46 | + * '1/2/3/4/foo.txt' will be accepted with $maxDepth == 4 and | |
| 47 | + * rejected with $maxDepth == 5 | |
| 48 | + */ | |
| 49 | + function File_Archive_Predicate_MaxDepth($maxDepth) | |
| 50 | + { | |
| 51 | + $this->maxDepth = $maxDepth; | |
| 52 | + } | |
| 53 | + /** | |
| 54 | + * @see File_Archive_Predicate::isTrue() | |
| 55 | + */ | |
| 56 | + function isTrue(&$source) | |
| 57 | + { | |
| 58 | + $url = parse_url($source->getFilename()); | |
| 59 | + return substr_count($url['path'], '/') <= $this->maxDepth ; | |
| 60 | + } | |
| 61 | +} | |
| 62 | + | |
| 63 | +?> | |
| 0 | 64 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Predicate/MinSize.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Keep only the files larger than a given size | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: MinSize.php,v 1.5 2005/04/21 10:01:47 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "File/Archive/Predicate.php"; | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * Keep only the files larger than a given size | |
| 36 | + * | |
| 37 | + * @see File_Archive_Predicate, File_Archive_Reader_Filter | |
| 38 | + */ | |
| 39 | +class File_Archive_Predicate_MinSize extends File_Archive_Predicate | |
| 40 | +{ | |
| 41 | + var $minSize = 0; | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * @param int $minSize minimal size of the file (in Bytes) | |
| 45 | + */ | |
| 46 | + function File_Archive_Predicate_MinSize($minSize) | |
| 47 | + { | |
| 48 | + $this->minSize = $minSize; | |
| 49 | + } | |
| 50 | + /** | |
| 51 | + * @see File_Archive_Predicate::isTrue() | |
| 52 | + */ | |
| 53 | + function isTrue(&$source) | |
| 54 | + { | |
| 55 | + $stat = $source->getStat(); | |
| 56 | + return !isset($stat[7]) || $stat[7]>=$this->minSize; | |
| 57 | + } | |
| 58 | +} | |
| 59 | +?> | |
| 0 | 60 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Predicate/MinTime.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Keep only the files modified after a given date (or with unknown modification | |
| 6 | + * date) | |
| 7 | + * | |
| 8 | + * PHP versions 4 and 5 | |
| 9 | + * | |
| 10 | + * This library is free software; you can redistribute it and/or | |
| 11 | + * modify it under the terms of the GNU Lesser General Public | |
| 12 | + * License as published by the Free Software Foundation; either | |
| 13 | + * version 2.1 of the License, or (at your option) any later version. | |
| 14 | + * | |
| 15 | + * This library is distributed in the hope that it will be useful, | |
| 16 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 17 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 18 | + * Lesser General Public License for more details. | |
| 19 | + * | |
| 20 | + * You should have received a copy of the GNU Lesser General Public | |
| 21 | + * License along with this library; if not, write to the Free Software | |
| 22 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 23 | + * | |
| 24 | + * @category File Formats | |
| 25 | + * @package File_Archive | |
| 26 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 27 | + * @copyright 1997-2005 The PHP Group | |
| 28 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 29 | + * @version CVS: $Id: MinTime.php,v 1.6 2005/04/21 10:01:47 vincentlascaux Exp $ | |
| 30 | + * @link http://pear.php.net/package/File_Archive | |
| 31 | + */ | |
| 32 | + | |
| 33 | +require_once "File/Archive/Predicate.php"; | |
| 34 | + | |
| 35 | +/** | |
| 36 | + * Keep only the files modified after a given date (or with unknown modification | |
| 37 | + * date) | |
| 38 | + * | |
| 39 | + * @see File_Archive_Predicate, File_Archive_Reader_Filter | |
| 40 | + */ | |
| 41 | +class File_Archive_Predicate_MinTime extends File_Archive_Predicate | |
| 42 | +{ | |
| 43 | + var $minTime = 0; | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * @param int $minTime Unix timestamp of the minimal modification date of | |
| 47 | + * the files | |
| 48 | + */ | |
| 49 | + function File_Archive_Predicate_MinTime($minTime) | |
| 50 | + { | |
| 51 | + $this->minTime = $minTime; | |
| 52 | + | |
| 53 | + } | |
| 54 | + /** | |
| 55 | + * @see File_Archive_Predicate::isTrue() | |
| 56 | + */ | |
| 57 | + function isTrue(&$source) | |
| 58 | + { | |
| 59 | + $stat = $source->getStat(); | |
| 60 | + return !isset($stat[9]) || $stat[9]>=$this->minTime; | |
| 61 | + } | |
| 62 | +} | |
| 63 | +?> | |
| 0 | 64 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Predicate/Not.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Evaluates to true iif the predicate given in parameter evaluates to false | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: Not.php,v 1.5 2005/04/21 10:01:47 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "File/Archive/Predicate.php"; | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * Evaluates to true iif the predicate given in parameter evaluates to false | |
| 36 | + * | |
| 37 | + * @see File_Archive_Predicate, File_Archive_Reader_Filter | |
| 38 | + */ | |
| 39 | +class File_Archive_Predicate_Not extends File_Archive_Predicate | |
| 40 | +{ | |
| 41 | + var $pred; | |
| 42 | + function File_Archive_Predicate_Not($pred) | |
| 43 | + { | |
| 44 | + $this->pred = $pred; | |
| 45 | + } | |
| 46 | + /** | |
| 47 | + * @see File_Archive_Predicate::isTrue() | |
| 48 | + */ | |
| 49 | + function isTrue(&$source) | |
| 50 | + { | |
| 51 | + return !$this->pred->isTrue($source); | |
| 52 | + } | |
| 53 | +} | |
| 54 | + | |
| 55 | +?> | |
| 0 | 56 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Predicate/Or.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Evaluates to true iif one at least of the predicates | |
| 6 | + * given as constructor parameters evaluate to true | |
| 7 | + * | |
| 8 | + * PHP versions 4 and 5 | |
| 9 | + * | |
| 10 | + * This library is free software; you can redistribute it and/or | |
| 11 | + * modify it under the terms of the GNU Lesser General Public | |
| 12 | + * License as published by the Free Software Foundation; either | |
| 13 | + * version 2.1 of the License, or (at your option) any later version. | |
| 14 | + * | |
| 15 | + * This library is distributed in the hope that it will be useful, | |
| 16 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 17 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 18 | + * Lesser General Public License for more details. | |
| 19 | + * | |
| 20 | + * You should have received a copy of the GNU Lesser General Public | |
| 21 | + * License along with this library; if not, write to the Free Software | |
| 22 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 23 | + * | |
| 24 | + * @category File Formats | |
| 25 | + * @package File_Archive | |
| 26 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 27 | + * @copyright 1997-2005 The PHP Group | |
| 28 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 29 | + * @version CVS: $Id: Or.php,v 1.8 2005/04/21 10:01:47 vincentlascaux Exp $ | |
| 30 | + * @link http://pear.php.net/package/File_Archive | |
| 31 | + */ | |
| 32 | + | |
| 33 | +require_once "File/Archive/Predicate.php"; | |
| 34 | + | |
| 35 | +/** | |
| 36 | + * Evaluates to true iif one at least of the predicates | |
| 37 | + * given as constructor parameters evaluate to true | |
| 38 | + * | |
| 39 | + * @see File_Archive_Predicate, File_Archive_Reader_Filter | |
| 40 | + */ | |
| 41 | +class File_Archive_Predicate_Or extends File_Archive_Predicate | |
| 42 | +{ | |
| 43 | + /** | |
| 44 | + * @var Array List of File_Archive_Predicate objects given as an argument | |
| 45 | + * @access private | |
| 46 | + */ | |
| 47 | + var $preds; | |
| 48 | + | |
| 49 | + /** | |
| 50 | + * Build the predicate using the optional File_Archive_Predicates given as | |
| 51 | + * arguments | |
| 52 | + * | |
| 53 | + * Example: | |
| 54 | + * new File_Archive_Predicate_And($pred1, $pred2, $pred3) | |
| 55 | + */ | |
| 56 | + function File_Archive_Predicate_And() | |
| 57 | + { | |
| 58 | + $this->preds = func_get_args(); | |
| 59 | + } | |
| 60 | + | |
| 61 | + /** | |
| 62 | + * Add a new predicate to the list | |
| 63 | + * | |
| 64 | + * @param File_Archive_Predicate The predicate to add | |
| 65 | + */ | |
| 66 | + function addPredicate($pred) | |
| 67 | + { | |
| 68 | + $this->preds[] = $pred; | |
| 69 | + } | |
| 70 | + | |
| 71 | + /** | |
| 72 | + * @see File_Archive_Predicate::isTrue() | |
| 73 | + */ | |
| 74 | + function isTrue(&$source) | |
| 75 | + { | |
| 76 | + foreach ($this->preds as $p) { | |
| 77 | + if ($p->isTrue($source)) { | |
| 78 | + return true; | |
| 79 | + } | |
| 80 | + } | |
| 81 | + return false; | |
| 82 | + } | |
| 83 | +} | |
| 84 | + | |
| 85 | +?> | |
| 0 | 86 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Predicate/True.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Always evaluate to true | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: True.php,v 1.5 2005/04/21 10:01:47 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "File/Archive/Predicate.php"; | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * Always evaluate to true | |
| 36 | + */ | |
| 37 | +class File_Archive_Predicate_True extends File_Archive_Predicate | |
| 38 | +{ | |
| 39 | + /** | |
| 40 | + * @see File_Archive_Predicate::isTrue() | |
| 41 | + */ | |
| 42 | + function isTrue(&$source) { return true; } | |
| 43 | +} | |
| 44 | + | |
| 45 | +?> | |
| 0 | 46 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Reader.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Abstract base class for all the readers | |
| 6 | + * | |
| 7 | + * A reader is a compilation of serveral files that can be read | |
| 8 | + * | |
| 9 | + * PHP versions 4 and 5 | |
| 10 | + * | |
| 11 | + * This library is free software; you can redistribute it and/or | |
| 12 | + * modify it under the terms of the GNU Lesser General Public | |
| 13 | + * License as published by the Free Software Foundation; either | |
| 14 | + * version 2.1 of the License, or (at your option) any later version. | |
| 15 | + * | |
| 16 | + * This library is distributed in the hope that it will be useful, | |
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 19 | + * Lesser General Public License for more details. | |
| 20 | + * | |
| 21 | + * You should have received a copy of the GNU Lesser General Public | |
| 22 | + * License along with this library; if not, write to the Free Software | |
| 23 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 24 | + * | |
| 25 | + * @category File Formats | |
| 26 | + * @package File_Archive | |
| 27 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 28 | + * @copyright 1997-2005 The PHP Group | |
| 29 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 30 | + * @version CVS: $Id: Reader.php,v 1.33 2005/07/07 12:24:57 vincentlascaux Exp $ | |
| 31 | + * @link http://pear.php.net/package/File_Archive | |
| 32 | + */ | |
| 33 | + | |
| 34 | +require_once "PEAR.php"; | |
| 35 | + | |
| 36 | +/** | |
| 37 | + * Abstract base class for all the readers | |
| 38 | + * | |
| 39 | + * A reader is a compilation of serveral files that can be read | |
| 40 | + */ | |
| 41 | +class File_Archive_Reader | |
| 42 | +{ | |
| 43 | + /** | |
| 44 | + * Move to the next file in the reader | |
| 45 | + * | |
| 46 | + * @return bool false iif no more files are available | |
| 47 | + */ | |
| 48 | + function next() | |
| 49 | + { | |
| 50 | + return false; | |
| 51 | + } | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * Move to the next file whose name is in directory $filename | |
| 55 | + * or is exactly $filename | |
| 56 | + * | |
| 57 | + * @param string $filename Name of the file to find in the archive | |
| 58 | + * @param bool $close If true, close the reader and search from the first file | |
| 59 | + * @return bool whether the file was found in the archive or not | |
| 60 | + */ | |
| 61 | + function select($filename, $close = true) | |
| 62 | + { | |
| 63 | + $std = $this->getStandardURL($filename); | |
| 64 | + | |
| 65 | + if ($close) { | |
| 66 | + $error = $this->close(); | |
| 67 | + if (PEAR::isError($error)) { | |
| 68 | + return $error; | |
| 69 | + } | |
| 70 | + } | |
| 71 | + while (($error = $this->next()) === true) { | |
| 72 | + $sourceName = $this->getFilename(); | |
| 73 | + if ( | |
| 74 | + empty($std) || | |
| 75 | + | |
| 76 | + //$std is a file | |
| 77 | + $std == $sourceName || | |
| 78 | + | |
| 79 | + //$std is a directory | |
| 80 | + strncmp($std.'/', $sourceName, strlen($std)+1) == 0 | |
| 81 | + ) { | |
| 82 | + return true; | |
| 83 | + } | |
| 84 | + } | |
| 85 | + return $error; | |
| 86 | + } | |
| 87 | + | |
| 88 | + /** | |
| 89 | + * Returns the standard path | |
| 90 | + * Changes \ to / | |
| 91 | + * Removes the .. and . from the URL | |
| 92 | + * @param string $path a valid URL that may contain . or .. and \ | |
| 93 | + * @static | |
| 94 | + */ | |
| 95 | + function getStandardURL($path) | |
| 96 | + { | |
| 97 | + if ($path == '.') { | |
| 98 | + return ''; | |
| 99 | + } | |
| 100 | + $std = str_replace("\\", "/", $path); | |
| 101 | + while ($std != ($std = preg_replace("/[^\/:?]+\/\.\.\//", "", $std))) ; | |
| 102 | + $std = str_replace("/./", "", $std); | |
| 103 | + if (strncmp($std, "./", 2) == 0) { | |
| 104 | + return substr($std, 2); | |
| 105 | + } else { | |
| 106 | + return $std; | |
| 107 | + } | |
| 108 | + } | |
| 109 | + | |
| 110 | + /** | |
| 111 | + * Returns the name of the file currently read by the reader | |
| 112 | + * | |
| 113 | + * Warning: undefined behaviour if no call to next have been | |
| 114 | + * done or if last call to next has returned false | |
| 115 | + * | |
| 116 | + * @return string Name of the current file | |
| 117 | + */ | |
| 118 | + function getFilename() | |
| 119 | + { | |
| 120 | + return PEAR::raiseError("Reader abstract function call (getFilename)"); | |
| 121 | + } | |
| 122 | + | |
| 123 | + /** | |
| 124 | + * Returns the list of filenames from the current pos to the end of the source | |
| 125 | + * The source will be closed after having called this function | |
| 126 | + * This function goes through the whole archive (which may be slow). | |
| 127 | + * If you intend to work on the reader, doing it in one pass would be faster | |
| 128 | + * | |
| 129 | + * @return array filenames from the current pos to the end of the source | |
| 130 | + */ | |
| 131 | + function getFileList() | |
| 132 | + { | |
| 133 | + $result = array(); | |
| 134 | + while ( ($error = $this->next()) === true) { | |
| 135 | + $result[] = $this->getFilename(); | |
| 136 | + } | |
| 137 | + $this->close(); | |
| 138 | + if (PEAR::isError($error)) { | |
| 139 | + return $error; | |
| 140 | + } else { | |
| 141 | + return $result; | |
| 142 | + } | |
| 143 | + } | |
| 144 | + | |
| 145 | + /** | |
| 146 | + * Returns an array of statistics about the file | |
| 147 | + * (see the PHP stat function for more information) | |
| 148 | + * | |
| 149 | + * The returned array may be empty, even if readers should try | |
| 150 | + * their best to return as many data as possible | |
| 151 | + */ | |
| 152 | + function getStat() { return array(); } | |
| 153 | + | |
| 154 | + /** | |
| 155 | + * Returns the MIME associated with the current file | |
| 156 | + * The default function does that by looking at the extension of the file | |
| 157 | + */ | |
| 158 | + function getMime() | |
| 159 | + { | |
| 160 | + require_once "File/Archive/Reader/MimeList.php"; | |
| 161 | + return File_Archive_Reader_GetMime($this->getFilename()); | |
| 162 | + } | |
| 163 | + | |
| 164 | + /** | |
| 165 | + * If the current file of the archive is a physical file, | |
| 166 | + * | |
| 167 | + * @return the name of the physical file containing the data | |
| 168 | + * or null if no such file exists | |
| 169 | + * | |
| 170 | + * The data filename may not be the same as the filename. | |
| 171 | + */ | |
| 172 | + function getDataFilename() { return null; } | |
| 173 | + | |
| 174 | + /** | |
| 175 | + * Reads some data from the current file | |
| 176 | + * If the end of the file is reached, returns null | |
| 177 | + * If $length is not specified, reads up to the end of the file | |
| 178 | + * If $length is specified reads up to $length | |
| 179 | + */ | |
| 180 | + function getData($length = -1) | |
| 181 | + { | |
| 182 | + return PEAR::raiseError("Reader abstract function call (getData)"); | |
| 183 | + } | |
| 184 | + | |
| 185 | + /** | |
| 186 | + * Skip some data and returns how many bytes have been skipped | |
| 187 | + * This is strictly equivalent to | |
| 188 | + * return strlen(getData($length)) | |
| 189 | + * But could be far more efficient | |
| 190 | + */ | |
| 191 | + function skip($length = -1) | |
| 192 | + { | |
| 193 | + $data = $this->getData($length); | |
| 194 | + if (PEAR::isError($data)) { | |
| 195 | + return $data; | |
| 196 | + } else { | |
| 197 | + return strlen($data); | |
| 198 | + } | |
| 199 | + } | |
| 200 | + | |
| 201 | + /** | |
| 202 | + * Move the current position back of a given amount of bytes. | |
| 203 | + * Not all readers may implement this function (a PEAR error will | |
| 204 | + * be returned if the reader can't rewind) | |
| 205 | + * | |
| 206 | + * @param int $length number of bytes to seek before the current pos | |
| 207 | + * or -1 to move back to the begining of the current file | |
| 208 | + * @return the number of bytes really rewinded (which may be less than | |
| 209 | + * $length if the current pos is less than $length | |
| 210 | + */ | |
| 211 | + function rewind($length = -1) | |
| 212 | + { | |
| 213 | + return PEAR::raiseError('Rewind function is not implemented on this reader'); | |
| 214 | + } | |
| 215 | + | |
| 216 | + /** | |
| 217 | + * Returns the current offset in the current file | |
| 218 | + */ | |
| 219 | + function tell() | |
| 220 | + { | |
| 221 | + $offset = $this->rewind(); | |
| 222 | + $this->skip($offset); | |
| 223 | + return $offset; | |
| 224 | + } | |
| 225 | + | |
| 226 | + /** | |
| 227 | + * Put back the reader in the state it was before the first call | |
| 228 | + * to next() | |
| 229 | + */ | |
| 230 | + function close() | |
| 231 | + { | |
| 232 | + } | |
| 233 | + | |
| 234 | + /** | |
| 235 | + * Sends the current file to the Writer $writer | |
| 236 | + * The data will be sent by chunks of at most $bufferSize bytes | |
| 237 | + * If $bufferSize <= 0 (default), the blockSize option is used | |
| 238 | + */ | |
| 239 | + function sendData(&$writer, $bufferSize = 0) | |
| 240 | + { | |
| 241 | + if (PEAR::isError($writer)) { | |
| 242 | + return $writer; | |
| 243 | + } | |
| 244 | + if ($bufferSize <= 0) { | |
| 245 | + $bufferSize = File_Archive::getOption('blockSize'); | |
| 246 | + } | |
| 247 | + | |
| 248 | + $filename = $this->getDataFilename(); | |
| 249 | + if ($filename !== null) { | |
| 250 | + $error = $writer->writeFile($filename); | |
| 251 | + if (PEAR::isError($error)) { | |
| 252 | + return $error; | |
| 253 | + } | |
| 254 | + } else { | |
| 255 | + while (($data = $this->getData($bufferSize)) !== null) { | |
| 256 | + if (PEAR::isError($data)) { | |
| 257 | + return $data; | |
| 258 | + } | |
| 259 | + $error = $writer->writeData($data); | |
| 260 | + if (PEAR::isError($error)) { | |
| 261 | + return $error; | |
| 262 | + } | |
| 263 | + } | |
| 264 | + } | |
| 265 | + } | |
| 266 | + | |
| 267 | + /** | |
| 268 | + * Sends the whole reader to $writer and close the reader | |
| 269 | + * | |
| 270 | + * @param File_Archive_Writer $writer Where to write the files of the reader | |
| 271 | + * @param bool $autoClose If true, close $writer at the end of the function. | |
| 272 | + * Default value is true | |
| 273 | + * @param int $bufferSize Size of the chunks that will be sent to the writer | |
| 274 | + * If $bufferSize <= 0 (default value), the blockSize option is used | |
| 275 | + */ | |
| 276 | + function extract(&$writer, $autoClose = true, $bufferSize = 0) | |
| 277 | + { | |
| 278 | + if (PEAR::isError($writer)) { | |
| 279 | + $this->close(); | |
| 280 | + return $writer; | |
| 281 | + } | |
| 282 | + | |
| 283 | + while (($error = $this->next()) === true) { | |
| 284 | + if ($writer->newFileNeedsMIME()) { | |
| 285 | + $mime = $this->getMime(); | |
| 286 | + } else { | |
| 287 | + $mime = null; | |
| 288 | + } | |
| 289 | + $error = $writer->newFile( | |
| 290 | + $this->getFilename(), | |
| 291 | + $this->getStat(), | |
| 292 | + $mime | |
| 293 | + ); | |
| 294 | + if (PEAR::isError($error)) { | |
| 295 | + break; | |
| 296 | + } | |
| 297 | + $error = $this->sendData($writer, $bufferSize); | |
| 298 | + if (PEAR::isError($error)) { | |
| 299 | + break; | |
| 300 | + } | |
| 301 | + } | |
| 302 | + $this->close(); | |
| 303 | + if ($autoClose) { | |
| 304 | + $writer->close(); | |
| 305 | + } | |
| 306 | + if (PEAR::isError($error)) { | |
| 307 | + return $error; | |
| 308 | + } | |
| 309 | + } | |
| 310 | + | |
| 311 | + /** | |
| 312 | + * Extract only one file (given by the URL) | |
| 313 | + * | |
| 314 | + * @param string $filename URL of the file to extract from this | |
| 315 | + * @param File_Archive_Writer $writer Where to write the file | |
| 316 | + * @param bool $autoClose If true, close $writer at the end of the function | |
| 317 | + * Default value is true | |
| 318 | + * @param int $bufferSize Size of the chunks that will be sent to the writer | |
| 319 | + * If $bufferSize <= 0 (default value), the blockSize option is used | |
| 320 | + */ | |
| 321 | + function extractFile($filename, &$writer, | |
| 322 | + $autoClose = true, $bufferSize = 0) | |
| 323 | + { | |
| 324 | + if (PEAR::isError($writer)) { | |
| 325 | + return $writer; | |
| 326 | + } | |
| 327 | + | |
| 328 | + if (($error = $this->select($filename)) === true) { | |
| 329 | + $result = $this->sendData($writer, $bufferSize); | |
| 330 | + if (!PEAR::isError($result)) { | |
| 331 | + $result = true; | |
| 332 | + } | |
| 333 | + } else if ($error === false) { | |
| 334 | + $result = PEAR::raiseError("File $filename not found"); | |
| 335 | + } else { | |
| 336 | + $result = $error; | |
| 337 | + } | |
| 338 | + if ($autoClose) { | |
| 339 | + $error = $writer->close(); | |
| 340 | + if (PEAR::isError($error)) { | |
| 341 | + return $error; | |
| 342 | + } | |
| 343 | + } | |
| 344 | + return $result; | |
| 345 | + } | |
| 346 | + | |
| 347 | + /** | |
| 348 | + * Return a writer that allows appending files to the archive | |
| 349 | + * After having called makeAppendWriter, $this is closed and should not be | |
| 350 | + * used until the returned writer is closed. | |
| 351 | + * | |
| 352 | + * @return a writer that will allow to append files to an existing archive | |
| 353 | + * @see makeWriter | |
| 354 | + */ | |
| 355 | + function makeAppendWriter() | |
| 356 | + { | |
| 357 | + require_once "File/Archive/Predicate/False.php"; | |
| 358 | + return $this->makeWriterRemoveFiles(new File_Archive_Predicate_False()); | |
| 359 | + } | |
| 360 | + | |
| 361 | + /** | |
| 362 | + * Return a writer that has the same properties as the one returned by | |
| 363 | + * makeAppendWriter, but after having removed all the files that follow a | |
| 364 | + * given predicate. | |
| 365 | + * After a call to makeWriterRemoveFiles, $this is closed and should not | |
| 366 | + * be used until the returned writer is closed | |
| 367 | + * | |
| 368 | + * @param File_Archive_Predicate $pred the predicate verified by removed files | |
| 369 | + * @return File_Archive_Writer that allows to append files to the archive | |
| 370 | + */ | |
| 371 | + function makeWriterRemoveFiles($pred) | |
| 372 | + { | |
| 373 | + return PEAR::raiseError("Reader abstract function call (makeWriterRemoveFiles)"); | |
| 374 | + } | |
| 375 | + | |
| 376 | + /** | |
| 377 | + * Returns a writer that removes the current file | |
| 378 | + * This is a syntaxic sugar for makeWriterRemoveFiles(new File_Archive_Predicate_Current()); | |
| 379 | + */ | |
| 380 | + function makeWriterRemove() | |
| 381 | + { | |
| 382 | + require_once "File/Archive/Predicate/Current.php"; | |
| 383 | + return $this->makeWriterRemoveFiles(new File_Archive_Predicate_Current()); | |
| 384 | + } | |
| 385 | + | |
| 386 | + /** | |
| 387 | + * Removes the current file from the reader | |
| 388 | + */ | |
| 389 | + function remove() | |
| 390 | + { | |
| 391 | + $writer = $this->makeWriterRemove(); | |
| 392 | + if (PEAR::isError($writer)) { | |
| 393 | + return $writer; | |
| 394 | + } | |
| 395 | + $writer->close(); | |
| 396 | + } | |
| 397 | + | |
| 398 | + /** | |
| 399 | + * Return a writer that has the same properties as the one returned by makeWriter, but after | |
| 400 | + * having removed a block of data from the current file. The writer will append data to the current file | |
| 401 | + * no data (other than the block) will be removed | |
| 402 | + * | |
| 403 | + * @param array Lengths of the blocks. The first one will be discarded, the second one kept, the third | |
| 404 | + * one discarded... If the sum of the blocks is less than the size of the file, the comportment is the | |
| 405 | + * same as if a last block was set in the array to reach the size of the file | |
| 406 | + * if $length is -1, the file is truncated from the specified pos | |
| 407 | + * It is possible to specify blocks of size 0 | |
| 408 | + * @param int $seek relative pos of the block | |
| 409 | + */ | |
| 410 | + function makeWriterRemoveBlocks($blocks, $seek = 0) | |
| 411 | + { | |
| 412 | + return PEAR::raiseError("Reader abstract function call (makeWriterRemoveBlocks)"); | |
| 413 | + } | |
| 414 | +} | |
| 415 | + | |
| 416 | +?> | |
| 0 | 417 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Reader/Ar.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Read a file saved in Ar file format | |
| 4 | + * | |
| 5 | + * PHP versions 4 and 5 | |
| 6 | + * | |
| 7 | + * This library is free software; you can redistribute it and/or | |
| 8 | + * modify it under the terms of the GNU Lesser General Public | |
| 9 | + * License as published by the Free Software Foundation; either | |
| 10 | + * version 2.1 of the License, or (at your option) any later version. | |
| 11 | + * | |
| 12 | + * This library is distributed in the hope that it will be useful, | |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 15 | + * Lesser General Public License for more details. | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU Lesser General Public | |
| 18 | + * License along with this library; if not, write to the Free Software | |
| 19 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 20 | + * | |
| 21 | + * @category File Formats | |
| 22 | + * @package File_Archive | |
| 23 | + * @author Pablo Fischer <pablo@pablo.com.mx> | |
| 24 | + * @copyright 1997-2005 The PHP Group | |
| 25 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 26 | + * @version CVS: $Id: | |
| 27 | + * @link http://pear.php.net/package/File_Archive | |
| 28 | + */ | |
| 29 | + | |
| 30 | +require_once "File/Archive/Reader/Archive.php"; | |
| 31 | + | |
| 32 | +/** | |
| 33 | + * Read an Ar archive | |
| 34 | + */ | |
| 35 | +class File_Archive_Reader_Ar extends File_Archive_Reader_Archive | |
| 36 | +{ | |
| 37 | + /** | |
| 38 | + * @var int The number of files to read to reach the end of the | |
| 39 | + * current ar file | |
| 40 | + * | |
| 41 | + * @access private | |
| 42 | + */ | |
| 43 | + var $_nbBytesLeft = 0; | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * @var int The size of the header in number of bytes | |
| 47 | + * The header is not always 60 bytes since it sometimes | |
| 48 | + * contains a long filename | |
| 49 | + * @access private | |
| 50 | + */ | |
| 51 | + var $_header = 0; | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * @var boolean Flag set if their is a 1 byte footer after the data | |
| 55 | + * of the current ar file | |
| 56 | + * | |
| 57 | + * @access private | |
| 58 | + */ | |
| 59 | + var $_footer = false; | |
| 60 | + | |
| 61 | + /** | |
| 62 | + * @var boolean Flag that has tell us if we have read the header of the | |
| 63 | + * current file | |
| 64 | + * @access private | |
| 65 | + */ | |
| 66 | + var $_alreadyRead = false; | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * @var string Name of the file being read | |
| 70 | + * @access private | |
| 71 | + */ | |
| 72 | + var $_currentFilename = null; | |
| 73 | + | |
| 74 | + /** | |
| 75 | + * @var string Stat properties of the file being read | |
| 76 | + * It has: name, utime, uid, gid, mode, size and data | |
| 77 | + * @access private | |
| 78 | + */ | |
| 79 | + var $_currentStat = null; | |
| 80 | + | |
| 81 | + /** | |
| 82 | + * @see File_Archive_Reader::getFilename() | |
| 83 | + */ | |
| 84 | + function getFilename() | |
| 85 | + { | |
| 86 | + return $this->_currentFilename; | |
| 87 | + } | |
| 88 | + | |
| 89 | + /** | |
| 90 | + * @see File_Archive_Reader::close() | |
| 91 | + */ | |
| 92 | + function close() | |
| 93 | + { | |
| 94 | + $this->_currentFilename = null; | |
| 95 | + $this->_currentStat = null; | |
| 96 | + $this->_nbBytesLeft = 0; | |
| 97 | + $this->_header = 0; | |
| 98 | + $this->_footer = false; | |
| 99 | + $this->_alreadyRead = false; | |
| 100 | + return parent::close(); | |
| 101 | + } | |
| 102 | + | |
| 103 | + /** | |
| 104 | + * @see File_Archive_Reader::getStat() | |
| 105 | + */ | |
| 106 | + function getStat() | |
| 107 | + { | |
| 108 | + return $this->_currentStat; | |
| 109 | + } | |
| 110 | + | |
| 111 | + /** | |
| 112 | + * @see File_Archive_Reader::next() | |
| 113 | + */ | |
| 114 | + function next() | |
| 115 | + { | |
| 116 | + $error = parent::next(); | |
| 117 | + if ($error !== true) { | |
| 118 | + return $error; | |
| 119 | + } | |
| 120 | + | |
| 121 | + $this->source->skip( | |
| 122 | + $this->_nbBytesLeft + ($this->_footer ? 1 : 0) | |
| 123 | + ); | |
| 124 | + | |
| 125 | + $filename = $this->source->getDataFilename(); | |
| 126 | + | |
| 127 | + if (!$this->_alreadyRead) { | |
| 128 | + $header = $this->source->getData(8); | |
| 129 | + if ($header != "!<arch>\n") { | |
| 130 | + return PEAR::raiseError("File {$filename} is not a valid Ar file format (starts with $header)"); | |
| 131 | + } | |
| 132 | + $this->_alreadyRead = true; | |
| 133 | + } | |
| 134 | + | |
| 135 | + | |
| 136 | + $name = $this->source->getData(16); | |
| 137 | + $mtime = $this->source->getData(12); | |
| 138 | + $uid = $this->source->getData(6); | |
| 139 | + $gid = $this->source->getData(6); | |
| 140 | + $mode = $this->source->getData(8); | |
| 141 | + $size = $this->source->getData(10); | |
| 142 | + $delim = $this->source->getData(2); | |
| 143 | + | |
| 144 | + if ($delim === null) { | |
| 145 | + return false; | |
| 146 | + } | |
| 147 | + | |
| 148 | + // All files inside should have more than 0 bytes of size | |
| 149 | + if ($size < 0) { | |
| 150 | + return PEAR::raiseError("Files must be at least one byte long"); | |
| 151 | + } | |
| 152 | + | |
| 153 | + $this->_footer = ($size % 2 == 1); | |
| 154 | + | |
| 155 | + // if the filename starts with a length, then just read the bytes of it | |
| 156 | + if (preg_match("/\#1\/(\d+)/", $name, $matches)) { | |
| 157 | + $this->_header = 60 + $matches[1]; | |
| 158 | + $name = $this->source->getData($matches[1]); | |
| 159 | + $size -= $matches[1]; | |
| 160 | + } else { | |
| 161 | + // strip trailing spaces in name, so we can distinguish spaces in a filename with padding | |
| 162 | + $this->_header = 60; | |
| 163 | + $name = preg_replace ("/\s+$/", "", $name); | |
| 164 | + } | |
| 165 | + | |
| 166 | + $this->_nbBytesLeft = $size; | |
| 167 | + if (empty($name) || empty($mtime) || empty($uid) || | |
| 168 | + empty($gid) || empty($mode) || empty($size)) { | |
| 169 | + return PEAR::raiseError("An ar field is empty"); | |
| 170 | + } | |
| 171 | + | |
| 172 | + $this->_currentFilename = $this->getStandardURL($name); | |
| 173 | + $this->_currentStat = array( | |
| 174 | + 2 => $mode, | |
| 175 | + 'mode' => $mode, | |
| 176 | + 4 => $uid, | |
| 177 | + 'uid' => $uid, | |
| 178 | + 5 => $gid, | |
| 179 | + 'gid' => $gid, | |
| 180 | + 7 => $size, | |
| 181 | + 'size' => $size, | |
| 182 | + 9 => $mtime, | |
| 183 | + 'mtime' => $mtime | |
| 184 | + ); | |
| 185 | + | |
| 186 | + return true; | |
| 187 | + } | |
| 188 | + | |
| 189 | + /** | |
| 190 | + * @see File_Archive_Reader::getData() | |
| 191 | + */ | |
| 192 | + function getData($length = -1) | |
| 193 | + { | |
| 194 | + if ($length == -1) { | |
| 195 | + $length = $this->_nbBytesLeft; | |
| 196 | + } else { | |
| 197 | + $length = min($length, $this->_nbBytesLeft); | |
| 198 | + } | |
| 199 | + if ($length == 0) { | |
| 200 | + return null; | |
| 201 | + } else { | |
| 202 | + $this->_nbBytesLeft -= $length; | |
| 203 | + $data = $this->source->getData($length); | |
| 204 | + if (PEAR::isError($data)) { | |
| 205 | + return $data; | |
| 206 | + } | |
| 207 | + if (strlen($data) != $length) { | |
| 208 | + return PEAR::raiseError('Unexpected end of Ar archive'); | |
| 209 | + } | |
| 210 | + return $data; | |
| 211 | + } | |
| 212 | + } | |
| 213 | + | |
| 214 | + /** | |
| 215 | + * @see File_Archive_Reader::skip | |
| 216 | + */ | |
| 217 | + function skip($length = -1) | |
| 218 | + { | |
| 219 | + if ($length == -1) { | |
| 220 | + $length = $this->_nbBytesLeft; | |
| 221 | + } else { | |
| 222 | + $length = min($length, $this->_nbBytesLeft); | |
| 223 | + } | |
| 224 | + if ($length == 0) { | |
| 225 | + return 0; | |
| 226 | + } else { | |
| 227 | + $this->_nbBytesLeft -= $length; | |
| 228 | + $skipped = $this->source->skip($length); | |
| 229 | + if (PEAR::isError($skipped)) { | |
| 230 | + return $skipped; | |
| 231 | + } | |
| 232 | + if ($skipped != $length) { | |
| 233 | + return PEAR::raiseError('Unexpected end of Ar archive'); | |
| 234 | + } | |
| 235 | + return $skipped; | |
| 236 | + } | |
| 237 | + } | |
| 238 | + | |
| 239 | + /** | |
| 240 | + * @see File_Archive_Reader::rewind | |
| 241 | + */ | |
| 242 | + function rewind($length = -1) | |
| 243 | + { | |
| 244 | + if ($length == -1) { | |
| 245 | + $length = $this->_currentStat[7] - $this->_nbBytesLeft; | |
| 246 | + } else { | |
| 247 | + $length = min($length, $this->_currentStat[7] - $this->_nbBytesLeft); | |
| 248 | + } | |
| 249 | + if ($length == 0) { | |
| 250 | + return 0; | |
| 251 | + } else { | |
| 252 | + $rewinded = $this->source->rewind($length); | |
| 253 | + if (!PEAR::isError($rewinded)) { | |
| 254 | + $this->_nbBytesLeft += $rewinded; | |
| 255 | + } | |
| 256 | + return $rewinded; | |
| 257 | + } | |
| 258 | + } | |
| 259 | + | |
| 260 | + /** | |
| 261 | + * @see File_Archive_Reader::tell() | |
| 262 | + */ | |
| 263 | + function tell() | |
| 264 | + { | |
| 265 | + return $this->_currentStat[7] - $this->_nbBytesLeft; | |
| 266 | + } | |
| 267 | + | |
| 268 | + /** | |
| 269 | + * @see File_Archive_Reader::makeWriterRemoveFiles() | |
| 270 | + */ | |
| 271 | + function makeWriterRemoveFiles($pred) | |
| 272 | + { | |
| 273 | + require_once "File/Archive/Writer/Ar.php"; | |
| 274 | + | |
| 275 | + $blocks = array(); | |
| 276 | + $seek = null; | |
| 277 | + $gap = 0; | |
| 278 | + if ($this->_currentFilename !== null && $pred->isTrue($this)) { | |
| 279 | + $seek = $this->_header + $this->_currentStat[7] + ($this->_footer ? 1 : 0); | |
| 280 | + $blocks[] = $seek; //Remove this file | |
| 281 | + } | |
| 282 | + | |
| 283 | + while (($error = $this->next()) === true) { | |
| 284 | + $size = $this->_header + $this->_currentStat[7] + ($this->_footer ? 1 : 0); | |
| 285 | + if ($pred->isTrue($this)) { | |
| 286 | + if ($seek === null) { | |
| 287 | + $seek = $size; | |
| 288 | + $blocks[] = $size; | |
| 289 | + } else if ($gap > 0) { | |
| 290 | + $blocks[] = $gap; //Don't remove the files between the gap | |
| 291 | + $blocks[] = $size; | |
| 292 | + $seek += $size; | |
| 293 | + } else { | |
| 294 | + $blocks[count($blocks)-1] += $size; //Also remove this file | |
| 295 | + $seek += $size; | |
| 296 | + } | |
| 297 | + $gap = 0; | |
| 298 | + } else { | |
| 299 | + if ($seek !== null) { | |
| 300 | + $seek += $size; | |
| 301 | + $gap += $size; | |
| 302 | + } | |
| 303 | + } | |
| 304 | + } | |
| 305 | + if ($seek === null) { | |
| 306 | + $seek = 0; | |
| 307 | + } else { | |
| 308 | + if ($gap == 0) { | |
| 309 | + array_pop($blocks); | |
| 310 | + } else { | |
| 311 | + $blocks[] = $gap; | |
| 312 | + } | |
| 313 | + } | |
| 314 | + | |
| 315 | + $writer = new File_Archive_Writer_Ar(null, | |
| 316 | + $this->source->makeWriterRemoveBlocks($blocks, -$seek) | |
| 317 | + ); | |
| 318 | + $this->close(); | |
| 319 | + return $writer; | |
| 320 | + } | |
| 321 | + | |
| 322 | + /** | |
| 323 | + * @see File_Archive_Reader::makeWriterRemoveBlocks() | |
| 324 | + */ | |
| 325 | + function makeWriterRemoveBlocks($blocks, $seek = 0) | |
| 326 | + { | |
| 327 | + if ($this->_currentStat === null) { | |
| 328 | + return PEAR::raiseError('No file selected'); | |
| 329 | + } | |
| 330 | + | |
| 331 | + $blockPos = $this->_currentStat[7] - $this->_nbBytesLeft + $seek; | |
| 332 | + | |
| 333 | + $this->rewind(); | |
| 334 | + $keep = false; | |
| 335 | + | |
| 336 | + $data = $this->getData($blockPos); | |
| 337 | + foreach ($blocks as $length) { | |
| 338 | + if ($keep) { | |
| 339 | + $data .= $this->getData($length); | |
| 340 | + } else { | |
| 341 | + $this->skip($length); | |
| 342 | + } | |
| 343 | + $keep = !$keep; | |
| 344 | + } | |
| 345 | + if ($keep) { | |
| 346 | + $data .= $this->getData(); | |
| 347 | + } | |
| 348 | + | |
| 349 | + $filename = $this->_currentFilename; | |
| 350 | + $stat = $this->_currentStat; | |
| 351 | + | |
| 352 | + $writer = $this->makeWriterRemove(); | |
| 353 | + if (PEAR::isError($writer)) { | |
| 354 | + return $writer; | |
| 355 | + } | |
| 356 | + | |
| 357 | + unset($stat[7]); | |
| 358 | + $writer->newFile($filename, $stat); | |
| 359 | + $writer->writeData($data); | |
| 360 | + return $writer; | |
| 361 | + } | |
| 362 | + | |
| 363 | + /** | |
| 364 | + * @see File_Archive_Reader::makeAppendWriter | |
| 365 | + */ | |
| 366 | + function makeAppendWriter() | |
| 367 | + { | |
| 368 | + require_once "File/Archive/Writer/Ar.php"; | |
| 369 | + | |
| 370 | + while (($error = $this->next()) === true) { } | |
| 371 | + if (PEAR::isError($error)) { | |
| 372 | + $this->close(); | |
| 373 | + return $error; | |
| 374 | + } | |
| 375 | + | |
| 376 | + $innerWriter = $this->source->makeWriterRemoveBlocks(array()); | |
| 377 | + if (PEAR::isError($innerWriter)) { | |
| 378 | + return $innerWriter; | |
| 379 | + } | |
| 380 | + | |
| 381 | + unset($this->source); | |
| 382 | + $this->close(); | |
| 383 | + | |
| 384 | + return new File_Archive_Writer_Ar(null, $innerWriter); | |
| 385 | + } | |
| 386 | +} | |
| 387 | +?> | |
| 0 | 388 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Reader/Archive.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Base class for all the archive readers (that read from a single file) | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: Archive.php,v 1.12 2005/05/23 19:25:24 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "File/Archive/Reader.php"; | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * Base class for all the archive readers (that read from a single file) | |
| 36 | + */ | |
| 37 | +class File_Archive_Reader_Archive extends File_Archive_Reader | |
| 38 | +{ | |
| 39 | + /** | |
| 40 | + * @var File_Archive_Reader Single file source that contains the archive | |
| 41 | + * to uncompress | |
| 42 | + * @access protected | |
| 43 | + */ | |
| 44 | + var $source = null; | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * @var bool Indicate whether the $source is currently opened | |
| 48 | + * @access private | |
| 49 | + */ | |
| 50 | + var $sourceOpened = false; | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * The source was let in this state at the end | |
| 54 | + * | |
| 55 | + * @var bool Indicate whether the $source was given opened | |
| 56 | + * @access private | |
| 57 | + */ | |
| 58 | + var $sourceInitiallyOpened; | |
| 59 | + | |
| 60 | +//ABSTRACT | |
| 61 | + /** | |
| 62 | + * @see File_Archive_Reader::next() | |
| 63 | + * | |
| 64 | + * Open the source if necessary | |
| 65 | + */ | |
| 66 | + function next() | |
| 67 | + { | |
| 68 | + if (!$this->sourceOpened && ($error = $this->source->next()) !== true) { | |
| 69 | + return $error; | |
| 70 | + } | |
| 71 | + | |
| 72 | + $this->sourceOpened = true; | |
| 73 | + return true; | |
| 74 | + } | |
| 75 | + | |
| 76 | +//PUBLIC | |
| 77 | + function File_Archive_Reader_Archive(&$source, $sourceOpened = false) | |
| 78 | + { | |
| 79 | + $this->source =& $source; | |
| 80 | + $this->sourceOpened = $this->sourceInitiallyOpened = $sourceOpened; | |
| 81 | + } | |
| 82 | + /** | |
| 83 | + * Close the source if it was given closed in the constructor | |
| 84 | + * | |
| 85 | + * @see File_Archive_Reader::close() | |
| 86 | + */ | |
| 87 | + function close() | |
| 88 | + { | |
| 89 | + if (!$this->sourceInitiallyOpened && $this->sourceOpened) { | |
| 90 | + $this->sourceOpened = false; | |
| 91 | + if ($this->source !== null) { | |
| 92 | + return $this->source->close(); | |
| 93 | + } | |
| 94 | + } | |
| 95 | + } | |
| 96 | +} | |
| 97 | + | |
| 98 | +?> | |
| 0 | 99 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Reader/Bzip2.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Uncompress a file that was compressed in the Bzip2 format | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: Bzip2.php,v 1.19 2005/07/26 09:06:03 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "File/Archive/Reader/Archive.php"; | |
| 33 | +require_once "File/Archive/Writer/Files.php"; | |
| 34 | + | |
| 35 | +/** | |
| 36 | + * Uncompress a file that was compressed in the Bzip2 format | |
| 37 | + */ | |
| 38 | +class File_Archive_Reader_Bzip2 extends File_Archive_Reader_Archive | |
| 39 | +{ | |
| 40 | + var $nbRead = 0; | |
| 41 | + var $bzfile = null; | |
| 42 | + var $tmpName = null; | |
| 43 | + var $filePos = 0; | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * @see File_Archive_Reader::close() | |
| 47 | + */ | |
| 48 | + function close($innerClose = true) | |
| 49 | + { | |
| 50 | + if ($this->bzfile !== null) | |
| 51 | + bzclose($this->bzfile); | |
| 52 | + if ($this->tmpName !== null) | |
| 53 | + unlink($this->tmpName); | |
| 54 | + | |
| 55 | + $this->bzfile = null; | |
| 56 | + $this->tmpName = null; | |
| 57 | + $this->nbRead = 0; | |
| 58 | + $this->filePos = 0; | |
| 59 | + return parent::close($innerClose); | |
| 60 | + } | |
| 61 | + | |
| 62 | + /** | |
| 63 | + * @see File_Archive_Reader::next() | |
| 64 | + */ | |
| 65 | + function next() | |
| 66 | + { | |
| 67 | + if (!parent::next()) { | |
| 68 | + return false; | |
| 69 | + } | |
| 70 | + | |
| 71 | + $this->nbRead++; | |
| 72 | + if ($this->nbRead > 1) { | |
| 73 | + return false; | |
| 74 | + } | |
| 75 | + | |
| 76 | + $dataFilename = $this->source->getDataFilename(); | |
| 77 | + if ($dataFilename !== null) | |
| 78 | + { | |
| 79 | + $this->tmpName = null; | |
| 80 | + $this->bzfile = @bzopen($dataFilename, 'r'); | |
| 81 | + if ($this->bzfile === false) { | |
| 82 | + return PEAR::raiseError("bzopen failed to open $dataFilename"); | |
| 83 | + } | |
| 84 | + } else { | |
| 85 | + $this->tmpName = tempnam(File_Archive::getOption('tmpDirectory'), 'far'); | |
| 86 | + | |
| 87 | + //Generate the tmp data | |
| 88 | + $dest = new File_Archive_Writer_Files(); | |
| 89 | + $dest->newFile($this->tmpName); | |
| 90 | + $this->source->sendData($dest); | |
| 91 | + $dest->close(); | |
| 92 | + | |
| 93 | + $this->bzfile = bzopen($this->tmpName, 'r'); | |
| 94 | + } | |
| 95 | + | |
| 96 | + return true; | |
| 97 | + } | |
| 98 | + /** | |
| 99 | + * Return the name of the single file contained in the archive | |
| 100 | + * deduced from the name of the archive (the extension is removed) | |
| 101 | + * | |
| 102 | + * @see File_Archive_Reader::getFilename() | |
| 103 | + */ | |
| 104 | + function getFilename() | |
| 105 | + { | |
| 106 | + $name = $this->source->getFilename(); | |
| 107 | + $pos = strrpos($name, "."); | |
| 108 | + if ($pos === false || $pos === 0) { | |
| 109 | + return $name; | |
| 110 | + } else { | |
| 111 | + return substr($name, 0, $pos); | |
| 112 | + } | |
| 113 | + } | |
| 114 | + /** | |
| 115 | + * @see File_Archive_Reader::getData() | |
| 116 | + */ | |
| 117 | + function getData($length = -1) | |
| 118 | + { | |
| 119 | + if ($length == -1) { | |
| 120 | + $data = ''; | |
| 121 | + do { | |
| 122 | + $newData = bzread($this->bzfile); | |
| 123 | + $data .= $newData; | |
| 124 | + } while ($newData != ''); | |
| 125 | + $this->filePos += strlen($data); | |
| 126 | + } else if ($length == 0) { | |
| 127 | + return ''; | |
| 128 | + } else { | |
| 129 | + $data = ''; | |
| 130 | + | |
| 131 | + //The loop is here to correct what appears to be a bzread bug | |
| 132 | + while (strlen($data) < $length) { | |
| 133 | + $newData = bzread($this->bzfile, $length - strlen($data)); | |
| 134 | + if ($newData == '') { | |
| 135 | + break; | |
| 136 | + } | |
| 137 | + $data .= $newData; | |
| 138 | + } | |
| 139 | + $this->filePos += strlen($data); | |
| 140 | + } | |
| 141 | + | |
| 142 | + return $data == '' ? null : $data; | |
| 143 | + } | |
| 144 | + | |
| 145 | + /** | |
| 146 | + * @see File_Archive_Reader::rewind | |
| 147 | + */ | |
| 148 | + function rewind($length = -1) | |
| 149 | + { | |
| 150 | + $before = $this->filePos; | |
| 151 | + | |
| 152 | + bzclose($this->bzfile); | |
| 153 | + if ($this->tmpName === null) { | |
| 154 | + $this->bzfile = bzopen($this->source->getDataFilename(), 'r'); | |
| 155 | + } else { | |
| 156 | + $this->bzfile = bzopen($this->tmpName, 'r'); | |
| 157 | + } | |
| 158 | + $this->filePos = 0; | |
| 159 | + | |
| 160 | + if ($length != -1) { | |
| 161 | + $this->skip($before - $length); | |
| 162 | + } | |
| 163 | + return $before - $this->filePos; | |
| 164 | + } | |
| 165 | + | |
| 166 | + /** | |
| 167 | + * @see File_Archive_Reader::tell() | |
| 168 | + */ | |
| 169 | + function tell() | |
| 170 | + { | |
| 171 | + return $this->filePos; | |
| 172 | + } | |
| 173 | + | |
| 174 | + /** | |
| 175 | + * @see File_Archive_Reader::makeAppendWriter() | |
| 176 | + */ | |
| 177 | + function makeAppendWriter() | |
| 178 | + { | |
| 179 | + return PEAR::raiseError('Unable to append files to a bzip2 archive'); | |
| 180 | + } | |
| 181 | + | |
| 182 | + /** | |
| 183 | + * @see File_Archive_Reader::makeWriterRemoveFiles() | |
| 184 | + */ | |
| 185 | + function makeWriterRemoveFiles($pred) | |
| 186 | + { | |
| 187 | + return PEAR::raiseError('Unable to remove files from a bzip2 archive'); | |
| 188 | + } | |
| 189 | + | |
| 190 | + /** | |
| 191 | + * @see File_Archive_Reader::makeWriterRemoveBlocks() | |
| 192 | + */ | |
| 193 | + function makeWriterRemoveBlocks($blocks, $seek = 0) | |
| 194 | + { | |
| 195 | + require_once "File/Archive/Writer/Bzip2.php"; | |
| 196 | + | |
| 197 | + if ($this->nbRead == 0) { | |
| 198 | + return PEAR::raiseError('No file selected'); | |
| 199 | + } | |
| 200 | + | |
| 201 | + //Uncompress data to a temporary file | |
| 202 | + $tmp = tmpfile(); | |
| 203 | + $expectedPos = $this->filePos + $seek; | |
| 204 | + | |
| 205 | + $this->rewind(); | |
| 206 | + | |
| 207 | + //Read the begining of the file | |
| 208 | + while ($this->filePos < $expectedPos && | |
| 209 | + ($data = $this->getData(min($expectedPos - $this->filePos, 8192))) !== null) { | |
| 210 | + fwrite($tmp, $data); | |
| 211 | + } | |
| 212 | + | |
| 213 | + $keep = false; | |
| 214 | + foreach ($blocks as $length) { | |
| 215 | + if ($keep) { | |
| 216 | + $expectedPos = $this->filePos + $length; | |
| 217 | + while ($this->filePos < $expectedPos && | |
| 218 | + ($data = $this->getData(min($expectedPos - $this->filePos, 8192))) !== null) { | |
| 219 | + fwrite($tmp, $data); | |
| 220 | + } | |
| 221 | + } else { | |
| 222 | + $this->skip($length); | |
| 223 | + } | |
| 224 | + $keep = !$keep; | |
| 225 | + } | |
| 226 | + if ($keep) { | |
| 227 | + //Read the end of the file | |
| 228 | + while(($data = $this->getData(8192)) !== null) { | |
| 229 | + fwrite($tmp, $data); | |
| 230 | + } | |
| 231 | + } | |
| 232 | + fseek($tmp, 0); | |
| 233 | + | |
| 234 | + //Create the writer | |
| 235 | + $this->source->rewind(); | |
| 236 | + $innerWriter = $this->source->makeWriterRemoveBlocks(array()); //Truncate the source | |
| 237 | + unset($this->source); | |
| 238 | + $writer = new File_Archive_Writer_Bzip2(null, $innerWriter); | |
| 239 | + | |
| 240 | + //And compress data from the temporary file | |
| 241 | + while (!feof($tmp)) { | |
| 242 | + $data = fread($tmp, 8192); | |
| 243 | + $writer->writeData($data); | |
| 244 | + } | |
| 245 | + fclose($tmp); | |
| 246 | + | |
| 247 | + //Do not close inner writer since makeWriter was called | |
| 248 | + $this->close(); | |
| 249 | + | |
| 250 | + return $writer; | |
| 251 | + } | |
| 252 | +} | |
| 253 | + | |
| 254 | +?> | |
| 0 | 255 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Reader/Cache.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * This reader caches the files of another reader | |
| 6 | + * It allow fast access to files. This is usefull if the access to the reader | |
| 7 | + * is slow (HTTP, FTP...), but will need more IO if the file is only extracted | |
| 8 | + * | |
| 9 | + * PHP versions 4 and 5 | |
| 10 | + * | |
| 11 | + * This library is free software; you can redistribute it and/or | |
| 12 | + * modify it under the terms of the GNU Lesser General Public | |
| 13 | + * License as published by the Free Software Foundation; either | |
| 14 | + * version 2.1 of the License, or (at your option) any later version. | |
| 15 | + * | |
| 16 | + * This library is distributed in the hope that it will be useful, | |
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 19 | + * Lesser General Public License for more details. | |
| 20 | + * | |
| 21 | + * You should have received a copy of the GNU Lesser General Public | |
| 22 | + * License along with this library; if not, write to the Free Software | |
| 23 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 24 | + * | |
| 25 | + * @category File Formats | |
| 26 | + * @package File_Archive | |
| 27 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 28 | + * @copyright 1997-2005 The PHP Group | |
| 29 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 30 | + * @version CVS: $Id: Cache.php,v 1.1 2005/07/07 12:24:58 vincentlascaux Exp $ | |
| 31 | + * @link http://pear.php.net/package/File_Archive | |
| 32 | + */ | |
| 33 | + | |
| 34 | +require_once "File/Archive/Reader.php"; | |
| 35 | + | |
| 36 | +/** | |
| 37 | + * This reader caches the files of another reader | |
| 38 | + * It allow fast access to files. This is usefull if the access to the reader | |
| 39 | + * is slow (HTTP, FTP...), but will need more IO if the file is only extracted | |
| 40 | + */ | |
| 41 | +class File_Archive_Reader_Cache extends File_Archive_Reader | |
| 42 | +{ | |
| 43 | + var $tmpFile; | |
| 44 | + var $files = array(); | |
| 45 | + var $pos = 0; | |
| 46 | + var $fromSource = true; | |
| 47 | + var $endOfSource = false; | |
| 48 | + var $source; | |
| 49 | + | |
| 50 | + /** | |
| 51 | + * $source is the reader to filter | |
| 52 | + */ | |
| 53 | + function File_Archive_Reader_Cache(&$source) | |
| 54 | + { | |
| 55 | + $this->source =& $source; | |
| 56 | + $this->tmpFile = tmpfile(); | |
| 57 | + } | |
| 58 | + | |
| 59 | + function _writeEndOfFile() | |
| 60 | + { | |
| 61 | + $bufferSize = File_Archive::getOption('blockSize'); | |
| 62 | + while (($data = $this->source->getData($bufferSize))!=null) { | |
| 63 | + fwrite($this->tmpFile, $data); | |
| 64 | + } | |
| 65 | + } | |
| 66 | + /** | |
| 67 | + * @see File_Archive_Reader::next() | |
| 68 | + */ | |
| 69 | + function next() | |
| 70 | + { | |
| 71 | + //Write the end of the current file to the temp file | |
| 72 | + if ($this->fromSource && !empty($this->files)) { | |
| 73 | + $this->_writeEndOfFile(); | |
| 74 | + } | |
| 75 | + | |
| 76 | + if ($this->pos+1 < count($this->files) && !$this->fromSource) { | |
| 77 | + $this->pos++; | |
| 78 | + fseek($this->tmpFile, $this->files[$this->pos]['pos'], SEEK_SET); | |
| 79 | + return true; | |
| 80 | + } else { | |
| 81 | + $this->fromSource = true; | |
| 82 | + if ($this->endOfSource) { | |
| 83 | + return false; | |
| 84 | + } | |
| 85 | + | |
| 86 | + $ret = $this->source->next(); | |
| 87 | + if ($ret !== true) { | |
| 88 | + $this->endOfSource = true; | |
| 89 | + $this->source->close(); | |
| 90 | + return $ret; | |
| 91 | + } | |
| 92 | + | |
| 93 | + $this->endOfSource = false; | |
| 94 | + fseek($this->tmpFile, 0, SEEK_END); | |
| 95 | + $this->files[] = array( | |
| 96 | + 'name' => $this->source->getFilename(), | |
| 97 | + 'stat' => $this->source->getStat(), | |
| 98 | + 'mime' => $this->source->getMime(), | |
| 99 | + 'pos' => ftell($this->tmpFile) | |
| 100 | + ); | |
| 101 | + $this->pos = count($this->files)-1; | |
| 102 | + | |
| 103 | + return true; | |
| 104 | + } | |
| 105 | + } | |
| 106 | + | |
| 107 | + /** | |
| 108 | + * @see File_Archive_Reader::getFilename() | |
| 109 | + */ | |
| 110 | + function getFilename() { return $this->files[$this->pos]['name']; } | |
| 111 | + /** | |
| 112 | + * @see File_Archive_Reader::getStat() | |
| 113 | + */ | |
| 114 | + function getStat() { return $this->files[$this->pos]['stat']; } | |
| 115 | + /** | |
| 116 | + * @see File_Archive_Reader::getMime() | |
| 117 | + */ | |
| 118 | + function getMime() { return $this->files[$this->pos]['mime']; } | |
| 119 | + /** | |
| 120 | + * @see File_Archive_Reader::getDataFilename() | |
| 121 | + */ | |
| 122 | + function getDataFilename() { return null; } | |
| 123 | + /** | |
| 124 | + * @see File_Archive_Reader::getData() | |
| 125 | + */ | |
| 126 | + function getData($length = -1) | |
| 127 | + { | |
| 128 | + if ($this->fromSource) { | |
| 129 | + $data = $this->source->getData($length); | |
| 130 | + if (PEAR::isError($data)) { | |
| 131 | + return $data; | |
| 132 | + } | |
| 133 | + | |
| 134 | + fwrite($this->tmpFile, $data); | |
| 135 | + return $data; | |
| 136 | + } else { | |
| 137 | + if ($length == 0) { | |
| 138 | + return ''; | |
| 139 | + } | |
| 140 | + | |
| 141 | + if ($length > 0 && $this->pos+1 < count($this->files)) { | |
| 142 | + $maxSize = $this->files[$this->pos+1]['pos'] - ftell($this->tmpFile); | |
| 143 | + if ($maxSize == 0) { | |
| 144 | + return null; | |
| 145 | + } | |
| 146 | + if ($length > $maxSize) { | |
| 147 | + $length = $maxSize; | |
| 148 | + } | |
| 149 | + return fread($this->tmpFile, $length); | |
| 150 | + } else { | |
| 151 | + $contents = ''; | |
| 152 | + $blockSize = File_Archive::getOption('blockSize'); | |
| 153 | + while (!feof($this->tmpFile)) { | |
| 154 | + $contents .= fread($this->tmpFile, $blockSize); | |
| 155 | + } | |
| 156 | + return $contents == '' ? null : $contents; | |
| 157 | + } | |
| 158 | + } | |
| 159 | + } | |
| 160 | + /** | |
| 161 | + * @see File_Archive_Reader::skip() | |
| 162 | + */ | |
| 163 | + function skip($length = -1) | |
| 164 | + { | |
| 165 | + if ($this->fromSource) { | |
| 166 | + return strlen($this->getData($length)); | |
| 167 | + } else { | |
| 168 | + if ($length >= 0 && $this->pos+1 < count($this->files)) { | |
| 169 | + $maxSize = $this->files[$this->pos+1]['pos'] - ftell($this->tmpFile); | |
| 170 | + if ($maxSize == 0) { | |
| 171 | + return null; | |
| 172 | + } | |
| 173 | + if ($length > $maxSize) { | |
| 174 | + $length = $maxSize; | |
| 175 | + } | |
| 176 | + fseek($this->tmpFile, $length, SEEK_CUR); | |
| 177 | + return $length; | |
| 178 | + } else { | |
| 179 | + $before = ftell($this->tmpFile); | |
| 180 | + fseek($this->tmpFile, 0, SEEK_SET); | |
| 181 | + $after = fteel($this->tmpFile); | |
| 182 | + return $after - $before; | |
| 183 | + } | |
| 184 | + } | |
| 185 | + } | |
| 186 | + /** | |
| 187 | + * @see File_Archive_Reader::rewind() | |
| 188 | + */ | |
| 189 | + function rewind($length = -1) | |
| 190 | + { | |
| 191 | + if ($this->fromSource) { | |
| 192 | + $this->_writeEndOfFile(); | |
| 193 | + $this->fromSource = false; | |
| 194 | + } | |
| 195 | + $before = ftell($this->tmpFile); | |
| 196 | + $pos = $this->files[$this->pos]['pos']; | |
| 197 | + fseek($this->tmpFile, $pos, SEEK_SET); | |
| 198 | + return $pos - $before; | |
| 199 | + } | |
| 200 | + /** | |
| 201 | + * @see File_Archive_Reader::tell() | |
| 202 | + */ | |
| 203 | + function tell() | |
| 204 | + { | |
| 205 | + return ftell($this->tmpFile) - $this->files[$this->pos]['pos']; | |
| 206 | + } | |
| 207 | + /** | |
| 208 | + * @see File_Archive_Reader::close() | |
| 209 | + */ | |
| 210 | + function close() | |
| 211 | + { | |
| 212 | + $this->fromSource = false; | |
| 213 | + $this->pos = 0; | |
| 214 | + fseek($this->tmpFile, 0, SEEK_SET); | |
| 215 | + } | |
| 216 | + function _closeAndReset() | |
| 217 | + { | |
| 218 | + $this->close(); | |
| 219 | + | |
| 220 | + fclose($this->tmpFile); | |
| 221 | + $this->tmpFile = tmpfile(); | |
| 222 | + $this->endOfSource = false; | |
| 223 | + $this->files = array(); | |
| 224 | + $this->source->close(); | |
| 225 | + } | |
| 226 | + /** | |
| 227 | + * @see File_Archive_Reader::makeAppendWriter() | |
| 228 | + */ | |
| 229 | + function makeAppendWriter() | |
| 230 | + { | |
| 231 | + $writer = $this->source->makeAppendWriter(); | |
| 232 | + if (!PEAR::isError($writer)) { | |
| 233 | + $this->_closeAndReset(); | |
| 234 | + } | |
| 235 | + | |
| 236 | + return $writer; | |
| 237 | + } | |
| 238 | + /** | |
| 239 | + * @see File_Archive_Reader::makeWriterRemoveFiles() | |
| 240 | + */ | |
| 241 | + function makeWriterRemoveFiles($pred) | |
| 242 | + { | |
| 243 | + $writer = $this->source->makeWriterRemoveFiles($pred); | |
| 244 | + if (!PEAR::isError($writer)) { | |
| 245 | + $this->_closeAndReset(); | |
| 246 | + } | |
| 247 | + return $writer; | |
| 248 | + } | |
| 249 | + /** | |
| 250 | + * @see File_Archive_Reader::makeWriterRemoveBlocks() | |
| 251 | + */ | |
| 252 | + function makeWriterRemoveBlocks($blocks, $seek = 0) | |
| 253 | + { | |
| 254 | + $writer = $this->source->makeWriterRemoveBlocks($blocks, $seek); | |
| 255 | + if (!PEAR::isError($writer)) { | |
| 256 | + $this->_closeAndReset(); | |
| 257 | + } | |
| 258 | + return $writer; | |
| 259 | + } | |
| 260 | +} | |
| 261 | + | |
| 262 | +?> | |
| 0 | 263 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Reader/ChangeName.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Add a directory to the public name of all the files of a reader | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: ChangeName.php,v 1.19 2005/07/09 12:54:35 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "File/Archive/Reader/Relay.php"; | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * Add a directory to the public name of all the files of a reader | |
| 36 | + * | |
| 37 | + * Example: | |
| 38 | + * If archive.tar is a file archive containing files a.txt and foo/b.txt | |
| 39 | + * new File_Archive_Reader_AddBaseName('bar', | |
| 40 | + * new File_Archive_Reader_Tar( | |
| 41 | + * new File_Archive_Reader_File('archive.tar') | |
| 42 | + * ) | |
| 43 | + * ) is a reader containing files bar/a.txt and bar/foo/b.txt | |
| 44 | + */ | |
| 45 | +class File_Archive_Reader_AddBaseName extends File_Archive_Reader_Relay | |
| 46 | +{ | |
| 47 | + var $baseName; | |
| 48 | + function File_Archive_Reader_AddBaseName($baseName, &$source) | |
| 49 | + { | |
| 50 | + parent::File_Archive_Reader_Relay($source); | |
| 51 | + $this->baseName = $this->getStandardURL($baseName); | |
| 52 | + } | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * Modify the name by adding baseName to it | |
| 56 | + */ | |
| 57 | + function modifyName($name) | |
| 58 | + { | |
| 59 | + return $this->baseName. | |
| 60 | + (empty($this->baseName) || empty($name) ? '': '/'). | |
| 61 | + $name; | |
| 62 | + } | |
| 63 | + | |
| 64 | + /** | |
| 65 | + * Remove baseName from the name | |
| 66 | + * Return false if the name doesn't start with baseName | |
| 67 | + */ | |
| 68 | + function unmodifyName($name) | |
| 69 | + { | |
| 70 | + if (strncmp($name, $this->baseName.'/', strlen($this->baseName)+1) == 0) { | |
| 71 | + $res = substr($name, strlen($this->baseName)+1); | |
| 72 | + if ($res === false) { | |
| 73 | + return ''; | |
| 74 | + } else { | |
| 75 | + return $res; | |
| 76 | + } | |
| 77 | + } else if (empty($this->baseName)) { | |
| 78 | + return $name; | |
| 79 | + } else if ($name == $this->baseName) { | |
| 80 | + return ''; | |
| 81 | + } else { | |
| 82 | + return false; | |
| 83 | + } | |
| 84 | + } | |
| 85 | + | |
| 86 | + /** | |
| 87 | + * @see File_Archive_Reader::getFilename() | |
| 88 | + */ | |
| 89 | + function getFilename() | |
| 90 | + { | |
| 91 | + return $this->modifyName(parent::getFilename()); | |
| 92 | + } | |
| 93 | + /** | |
| 94 | + * @see File_Archive_Reader::getFileList() | |
| 95 | + */ | |
| 96 | + function getFileList() | |
| 97 | + { | |
| 98 | + $list = parent::getFileList(); | |
| 99 | + $result = array(); | |
| 100 | + foreach ($list as $name) { | |
| 101 | + $result[] = $this->modifyName($name); | |
| 102 | + } | |
| 103 | + return $result; | |
| 104 | + } | |
| 105 | + /** | |
| 106 | + * @see File_Archive_Reader::select() | |
| 107 | + */ | |
| 108 | + function select($filename, $close = true) | |
| 109 | + { | |
| 110 | + $name = $this->unmodifyName($filename); | |
| 111 | + if ($name === false) { | |
| 112 | + return false; | |
| 113 | + } else { | |
| 114 | + return $this->source->select($name, $close); | |
| 115 | + } | |
| 116 | + } | |
| 117 | +} | |
| 118 | + | |
| 119 | +/** | |
| 120 | + * Change a directory name to another | |
| 121 | + * | |
| 122 | + * Example: | |
| 123 | + * If archive.tar is a file archive containing files a.txt and foo/b.txt | |
| 124 | + * new File_Archive_Reader_ChangeBaseName('foo', 'bar' | |
| 125 | + * new File_Archive_Reader_Tar( | |
| 126 | + * new File_Archive_Reader_File('archive.tar') | |
| 127 | + * ) | |
| 128 | + * ) is a reader containing files a.txt and bar/b.txt | |
| 129 | + */ | |
| 130 | +class File_Archive_Reader_ChangeBaseName extends File_Archive_Reader_Relay | |
| 131 | +{ | |
| 132 | + var $oldBaseName; | |
| 133 | + var $newBaseName; | |
| 134 | + | |
| 135 | + function File_Archive_Reader_ChangeBaseName | |
| 136 | + ($oldBaseName, $newBaseName, &$source) | |
| 137 | + { | |
| 138 | + parent::File_Archive_Reader_Relay($source); | |
| 139 | + $this->oldBaseName = $this->getStandardURL($oldBaseName); | |
| 140 | + if (substr($this->oldBaseName, -1) == '/') { | |
| 141 | + $this->oldBaseName = substr($this->oldBaseName, 0, -1); | |
| 142 | + } | |
| 143 | + | |
| 144 | + $this->newBaseName = $this->getStandardURL($newBaseName); | |
| 145 | + if (substr($this->newBaseName, -1) == '/') { | |
| 146 | + $this->newBaseName = substr($this->newBaseName, 0, -1); | |
| 147 | + } | |
| 148 | + } | |
| 149 | + | |
| 150 | + function modifyName($name) | |
| 151 | + { | |
| 152 | + if (empty($this->oldBaseName) || | |
| 153 | + !strncmp($name, $this->oldBaseName.'/', strlen($this->oldBaseName)+1) || | |
| 154 | + strcmp($name, $this->oldBaseName) == 0) { | |
| 155 | + return $this->newBaseName. | |
| 156 | + ( | |
| 157 | + empty($this->newBaseName) || | |
| 158 | + strlen($name)<=strlen($this->oldBaseName)+1 ? | |
| 159 | + '' : '/' | |
| 160 | + ). | |
| 161 | + substr($name, strlen($this->oldBaseName)+1); | |
| 162 | + } else { | |
| 163 | + return $name; | |
| 164 | + } | |
| 165 | + } | |
| 166 | + function unmodifyName($name) | |
| 167 | + { | |
| 168 | + if (empty($this->newBaseName) || | |
| 169 | + !strncmp($name, $this->newBaseName.'/', strlen($this->newBaseName)+1) || | |
| 170 | + strcmp($name, $this->newBaseName) == 0) { | |
| 171 | + return $this->oldBaseName. | |
| 172 | + ( | |
| 173 | + empty($this->oldBaseName) || | |
| 174 | + strlen($name)<=strlen($this->newBaseName)+1 ? | |
| 175 | + '' : '/' | |
| 176 | + ). | |
| 177 | + substr($name, strlen($this->newBaseName)+1); | |
| 178 | + } else { | |
| 179 | + return $name; | |
| 180 | + } | |
| 181 | + } | |
| 182 | + | |
| 183 | + /** | |
| 184 | + * @see File_Archive_Reader::getFilename() | |
| 185 | + */ | |
| 186 | + function getFilename() | |
| 187 | + { | |
| 188 | + return $this->modifyName(parent::getFilename()); | |
| 189 | + } | |
| 190 | + /** | |
| 191 | + * @see File_Archive_Reader::getFileList() | |
| 192 | + */ | |
| 193 | + function getFileList() | |
| 194 | + { | |
| 195 | + $list = parent::getFileList(); | |
| 196 | + $result = array(); | |
| 197 | + foreach ($list as $name) { | |
| 198 | + $result[] = $this->modifyName($name); | |
| 199 | + } | |
| 200 | + return $result; | |
| 201 | + } | |
| 202 | + /** | |
| 203 | + * @see File_Archive_Reader::select() | |
| 204 | + */ | |
| 205 | + function select($filename, $close = true) | |
| 206 | + { | |
| 207 | + return $this->source->select($this->unmodifyName($filename)); | |
| 208 | + } | |
| 209 | + | |
| 210 | +} | |
| 211 | + | |
| 212 | +?> | |
| 0 | 213 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Reader/Concat.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * A reader that concatene the data of the files of a source | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: Concat.php,v 1.17 2005/07/07 15:48:28 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "File/Archive/Reader/Relay.php"; | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * This reader provides one single file that is the concatenation of the data of | |
| 36 | + * all the files of another reader | |
| 37 | + */ | |
| 38 | +class File_Archive_Reader_Concat extends File_Archive_Reader | |
| 39 | +{ | |
| 40 | + var $source; | |
| 41 | + var $filename; | |
| 42 | + var $stat; | |
| 43 | + var $mime; | |
| 44 | + var $opened = false; | |
| 45 | + var $filePos = 0; | |
| 46 | + | |
| 47 | + function File_Archive_Reader_Concat(&$source, $filename, | |
| 48 | + $stat=array(), $mime=null) | |
| 49 | + { | |
| 50 | + $this->source =& $source; | |
| 51 | + $this->filename = $filename; | |
| 52 | + $this->stat = $stat; | |
| 53 | + $this->mime = $mime; | |
| 54 | + | |
| 55 | + //Compute the total length | |
| 56 | + $this->stat[7] = 0; | |
| 57 | + while (($error = $source->next()) === true) { | |
| 58 | + $sourceStat = $source->getStat(); | |
| 59 | + if (isset($sourceStat[7])) { | |
| 60 | + $this->stat[7] += $sourceStat[7]; | |
| 61 | + } else { | |
| 62 | + unset($this->stat[7]); | |
| 63 | + break; | |
| 64 | + } | |
| 65 | + } | |
| 66 | + if (isset($this->stat[7])) { | |
| 67 | + $this->stat['size'] = $this->stat[7]; | |
| 68 | + } | |
| 69 | + if (PEAR::isError($error) || PEAR::isError($source->close())) { | |
| 70 | + die("Error in File_Archive_Reader_Concat constructor ". | |
| 71 | + '('.$error->getMessage().'), cannot continue'); | |
| 72 | + } | |
| 73 | + } | |
| 74 | + | |
| 75 | + /** | |
| 76 | + * @see File_Archive_Reader::next() | |
| 77 | + */ | |
| 78 | + function next() | |
| 79 | + { | |
| 80 | + if (!$this->opened) { | |
| 81 | + return $this->opened = $this->source->next(); | |
| 82 | + } else { | |
| 83 | + return false; | |
| 84 | + } | |
| 85 | + } | |
| 86 | + /** | |
| 87 | + * @see File_Archive_Reader::getFilename() | |
| 88 | + */ | |
| 89 | + function getFilename() { return $this->filename; } | |
| 90 | + /** | |
| 91 | + * @see File_Archive_Reader::getStat() | |
| 92 | + */ | |
| 93 | + function getStat() { return $this->stat; } | |
| 94 | + /** | |
| 95 | + * @see File_Archive_Reader::getMime() | |
| 96 | + */ | |
| 97 | + function getMime() | |
| 98 | + { | |
| 99 | + return $this->mime==null ? parent::getMime() : $this->mime; | |
| 100 | + } | |
| 101 | + /** | |
| 102 | + * @see File_Archive_Reader::getData() | |
| 103 | + */ | |
| 104 | + function getData($length = -1) | |
| 105 | + { | |
| 106 | + if ($length == 0) { | |
| 107 | + return ''; | |
| 108 | + } | |
| 109 | + | |
| 110 | + $result = ''; | |
| 111 | + while ($length == -1 || strlen($result)<$length) { | |
| 112 | + $sourceData = $this->source->getData( | |
| 113 | + $length==-1 ? -1 : $length - strlen($result) | |
| 114 | + ); | |
| 115 | + | |
| 116 | + if (PEAR::isError($sourceData)) { | |
| 117 | + return $sourceData; | |
| 118 | + } | |
| 119 | + | |
| 120 | + if ($sourceData === null) { | |
| 121 | + $error = $this->source->next(); | |
| 122 | + if (PEAR::isError($error)) { | |
| 123 | + return $error; | |
| 124 | + } | |
| 125 | + if (!$error) { | |
| 126 | + break; | |
| 127 | + } | |
| 128 | + } else { | |
| 129 | + $result .= $sourceData; | |
| 130 | + } | |
| 131 | + } | |
| 132 | + $this->filePos += strlen($result); | |
| 133 | + return $result == '' ? null : $result; | |
| 134 | + } | |
| 135 | + /** | |
| 136 | + * @see File_Archive_Reader::skip() | |
| 137 | + */ | |
| 138 | + function skip($length = -1) | |
| 139 | + { | |
| 140 | + $skipped = 0; | |
| 141 | + while ($skipped < $length) { | |
| 142 | + $sourceSkipped = $this->source->skip($length); | |
| 143 | + if (PEAR::isError($sourceSkipped)) { | |
| 144 | + return $skipped; | |
| 145 | + } | |
| 146 | + $skipped += $sourceSkipped; | |
| 147 | + $filePos += $sourceSkipped; | |
| 148 | + } | |
| 149 | + return $skipped; | |
| 150 | + } | |
| 151 | + /** | |
| 152 | + * @see File_Archive_Reader::rewind() | |
| 153 | + */ | |
| 154 | + function rewind($length = -1) | |
| 155 | + { | |
| 156 | + //TODO: implement rewind | |
| 157 | + return parent::rewind($length); | |
| 158 | + } | |
| 159 | + | |
| 160 | + /** | |
| 161 | + * @see File_Archive_Reader::tell() | |
| 162 | + */ | |
| 163 | + function tell() | |
| 164 | + { | |
| 165 | + return $this->filePos; | |
| 166 | + } | |
| 167 | + | |
| 168 | + /** | |
| 169 | + * @see File_Archive_Reader::close() | |
| 170 | + */ | |
| 171 | + function close() | |
| 172 | + { | |
| 173 | + $this->opened = false; | |
| 174 | + $this->filePos = 0; | |
| 175 | + return $this->source->close(); | |
| 176 | + } | |
| 177 | + | |
| 178 | + /** | |
| 179 | + * @see File_Archive_Reader::makeWriter | |
| 180 | + */ | |
| 181 | + function makeWriter($fileModif = true, $seek = 0) | |
| 182 | + { | |
| 183 | + return $this->source->makeWriter($fileModif, $seek); | |
| 184 | + } | |
| 185 | +} | |
| 186 | + | |
| 187 | +?> | |
| 0 | 188 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Reader/Directory.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Recursively reads a directory | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: Directory.php,v 1.21 2005/07/07 12:24:58 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "File/Archive/Reader/Relay.php"; | |
| 33 | +require_once "File/Archive/Reader/File.php"; | |
| 34 | + | |
| 35 | +/** | |
| 36 | + * Recursively reads a directory | |
| 37 | + */ | |
| 38 | +class File_Archive_Reader_Directory extends File_Archive_Reader_Relay | |
| 39 | +{ | |
| 40 | + /** | |
| 41 | + * @var String URL of the directory that must be read | |
| 42 | + * @access private | |
| 43 | + */ | |
| 44 | + var $directory; | |
| 45 | + /** | |
| 46 | + * @var Int The subdirectories will be read up to a depth of maxRecurs | |
| 47 | + * If maxRecurs == 0, the subdirectories will not be read | |
| 48 | + * If maxRecurs == -1, the depth is considered infinite | |
| 49 | + * @access private | |
| 50 | + */ | |
| 51 | + var $maxRecurs; | |
| 52 | + /** | |
| 53 | + * @var Object Handle returned by the openedDirectory function | |
| 54 | + * @access private | |
| 55 | + */ | |
| 56 | + var $directoryHandle = null; | |
| 57 | + | |
| 58 | + /** | |
| 59 | + * $directory is the path of the directory that must be read | |
| 60 | + * If $maxRecurs is specified, the subdirectories will be read up to a depth | |
| 61 | + * of $maxRecurs. In particular, if $maxRecurs == 0, the subdirectories | |
| 62 | + * won't be read. | |
| 63 | + */ | |
| 64 | + function File_Archive_Reader_Directory($directory, $symbolic='', | |
| 65 | + $maxRecurs=-1) | |
| 66 | + { | |
| 67 | + parent::File_Archive_Reader_Relay($tmp = null); | |
| 68 | + $this->directory = empty($directory) ? '.' : $directory; | |
| 69 | + $this->symbolic = $this->getStandardURL($symbolic); | |
| 70 | + $this->maxRecurs = $maxRecurs; | |
| 71 | + } | |
| 72 | + | |
| 73 | + /** | |
| 74 | + * @see File_Archive_Reader::close() | |
| 75 | + */ | |
| 76 | + function close() | |
| 77 | + { | |
| 78 | + $error = parent::close(); | |
| 79 | + | |
| 80 | + if ($this->directoryHandle !== null) { | |
| 81 | + closedir($this->directoryHandle); | |
| 82 | + $this->directoryHandle = null; | |
| 83 | + } | |
| 84 | + | |
| 85 | + return $error; | |
| 86 | + } | |
| 87 | + | |
| 88 | + /** | |
| 89 | + * @see File_Archive_Reader::next() | |
| 90 | + * | |
| 91 | + * The files are returned in the same order as readdir | |
| 92 | + */ | |
| 93 | + function next() | |
| 94 | + { | |
| 95 | + if ($this->directoryHandle === null) { | |
| 96 | + $this->directoryHandle = opendir($this->directory); | |
| 97 | + if (!is_resource($this->directoryHandle)) { | |
| 98 | + return PEAR::raiseError( | |
| 99 | + "Directory {$this->directory} not found" | |
| 100 | + ); | |
| 101 | + } | |
| 102 | + } | |
| 103 | + | |
| 104 | + while ($this->source === null || | |
| 105 | + ($error = $this->source->next()) !== true) { | |
| 106 | + | |
| 107 | + if ($this->source !== null) { | |
| 108 | + $this->source->close(); | |
| 109 | + } | |
| 110 | + | |
| 111 | + $file = readdir($this->directoryHandle); | |
| 112 | + if ($file == '.' || $file == '..') { | |
| 113 | + continue; | |
| 114 | + } | |
| 115 | + if ($file === false) { | |
| 116 | + return false; | |
| 117 | + } | |
| 118 | + | |
| 119 | + $current = $this->directory.'/'.$file; | |
| 120 | + if (is_dir($current)) { | |
| 121 | + if ($this->maxRecurs != 0) { | |
| 122 | + $this->source = new File_Archive_Reader_Directory( | |
| 123 | + $current, $file.'/', $this->maxRecurs-1 | |
| 124 | + ); | |
| 125 | + } | |
| 126 | + } else { | |
| 127 | + $this->source = new File_Archive_Reader_File($current, $file); | |
| 128 | + } | |
| 129 | + } | |
| 130 | + | |
| 131 | + return $error; | |
| 132 | + } | |
| 133 | + | |
| 134 | + /** | |
| 135 | + * @see File_Archive_Reader::getFilename() | |
| 136 | + */ | |
| 137 | + function getFilename() { return $this->symbolic . parent::getFilename(); } | |
| 138 | + | |
| 139 | + /** | |
| 140 | + * @see File_Archive_Reader::makeWriterRemoveFiles() | |
| 141 | + */ | |
| 142 | + function makeWriterRemoveFiles($pred) | |
| 143 | + { | |
| 144 | + if ($source !== null && $pred->isTrue($this)) { | |
| 145 | + $toUnlink = $this->getDataFilename(); | |
| 146 | + } else { | |
| 147 | + $toUnlink = null; | |
| 148 | + } | |
| 149 | + | |
| 150 | + while ($this->next()) { | |
| 151 | + if ($toUnlink !== null && | |
| 152 | + !@unlink($toUnlink)) { | |
| 153 | + return PEAR::raiseError("Unable to unlink $toUnlink"); | |
| 154 | + } | |
| 155 | + $toUnlink = ($pred->isTrue($this) ? $this->getDataFilename() : null); | |
| 156 | + } | |
| 157 | + if ($toUnlink !== null && | |
| 158 | + !@unlink("Unable to unlink $toUnlink")) { | |
| 159 | + return PEAR::raiseError($pred); | |
| 160 | + } | |
| 161 | + | |
| 162 | + require_once "File/Archive/Writer/Files.php"; | |
| 163 | + | |
| 164 | + $writer = new File_Archive_Writer_Files($this->directory); | |
| 165 | + $this->close(); | |
| 166 | + return $writer; | |
| 167 | + } | |
| 168 | + | |
| 169 | + function &getLastSource() | |
| 170 | + { | |
| 171 | + if ($this->source === null || | |
| 172 | + is_a($this->source, 'File_Archive_Reader_File')) { | |
| 173 | + return $this->source; | |
| 174 | + } else { | |
| 175 | + return $this->source->getLastSource(); | |
| 176 | + } | |
| 177 | + } | |
| 178 | + | |
| 179 | + /** | |
| 180 | + * @see File_Archive_Reader::makeWriterRemoveBlocks() | |
| 181 | + */ | |
| 182 | + function makeWriterRemoveBlocks($blocks, $seek = 0) | |
| 183 | + { | |
| 184 | + $lastSource = &$this->getLastSource(); | |
| 185 | + if ($lastSource === null) { | |
| 186 | + return PEAR::raiseError('No file selected'); | |
| 187 | + } | |
| 188 | + | |
| 189 | + require_once "File/Archive/Writer/Files.php"; | |
| 190 | + | |
| 191 | + $writer = $lastSource->makeWriterRemoveBlocks($blocks, $seek); | |
| 192 | + if (!PEAR::isError($writer)) { | |
| 193 | + $writer->basePath = $this->directory; | |
| 194 | + $this->close(); | |
| 195 | + } | |
| 196 | + | |
| 197 | + return $writer; | |
| 198 | + } | |
| 199 | + | |
| 200 | + /** | |
| 201 | + * @see File_Archive_Reader::makeAppendWriter | |
| 202 | + */ | |
| 203 | + function makeAppendWriter() | |
| 204 | + { | |
| 205 | + require_once "File/Archive/Writer/Files.php"; | |
| 206 | + | |
| 207 | + if ($this->source === null || | |
| 208 | + is_a($this->source, 'File_Archive_Reader_File') ) { | |
| 209 | + $writer = new File_Archive_Writer_Files($this->directory); | |
| 210 | + } else { | |
| 211 | + $writer = $this->source->makeAppendWriter($seek); | |
| 212 | + } | |
| 213 | + | |
| 214 | + $this->close(); | |
| 215 | + | |
| 216 | + return $writer; | |
| 217 | + } | |
| 218 | +} | |
| 219 | + | |
| 220 | +?> | |
| 0 | 221 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Reader/File.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Reader that represents a single file | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: File.php,v 1.30 2005/07/11 11:53:53 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "File/Archive/Reader.php"; | |
| 33 | +require_once "MIME/Type.php"; | |
| 34 | + | |
| 35 | +/** | |
| 36 | + * Reader that represents a single file | |
| 37 | + */ | |
| 38 | +class File_Archive_Reader_File extends File_Archive_Reader | |
| 39 | +{ | |
| 40 | + /** | |
| 41 | + * @var object Handle to the file being read | |
| 42 | + * @access private | |
| 43 | + */ | |
| 44 | + var $handle = null; | |
| 45 | + /** | |
| 46 | + * @var string Name of the physical file being read | |
| 47 | + * @access private | |
| 48 | + */ | |
| 49 | + var $filename; | |
| 50 | + /** | |
| 51 | + * @var string Name of the file returned by the reader | |
| 52 | + * @access private | |
| 53 | + */ | |
| 54 | + var $symbolic; | |
| 55 | + /** | |
| 56 | + * @var array Stats of the file | |
| 57 | + * Will only be set after a call to $this->getStat() | |
| 58 | + * @access private | |
| 59 | + */ | |
| 60 | + var $stat = null; | |
| 61 | + /** | |
| 62 | + * @var string Mime type of the file | |
| 63 | + * Will only be set after a call to $this->getMime() | |
| 64 | + */ | |
| 65 | + var $mime = null; | |
| 66 | + /** | |
| 67 | + * @var boolean Has the file already been read | |
| 68 | + * @access private | |
| 69 | + */ | |
| 70 | + var $alreadyRead = false; | |
| 71 | + | |
| 72 | + /** | |
| 73 | + * $filename is the physical file to read | |
| 74 | + * $symbolic is the name declared by the reader | |
| 75 | + * If $symbolic is not specified, $filename is assumed | |
| 76 | + */ | |
| 77 | + function File_Archive_Reader_File($filename, $symbolic = null, $mime = null) | |
| 78 | + { | |
| 79 | + $this->filename = $filename; | |
| 80 | + $this->mime = $mime; | |
| 81 | + if ($symbolic === null) { | |
| 82 | + $this->symbolic = $this->getStandardURL($filename); | |
| 83 | + } else { | |
| 84 | + $this->symbolic = $this->getStandardURL($symbolic); | |
| 85 | + } | |
| 86 | + } | |
| 87 | + /** | |
| 88 | + * @see File_Archive_Reader::close() | |
| 89 | + * | |
| 90 | + * Close the file handle | |
| 91 | + */ | |
| 92 | + function close() | |
| 93 | + { | |
| 94 | + $this->alreadyRead = false; | |
| 95 | + if ($this->handle !== null) { | |
| 96 | + fclose($this->handle); | |
| 97 | + $this->handle = null; | |
| 98 | + } | |
| 99 | + } | |
| 100 | + /** | |
| 101 | + * @see File_Archive_Reader::next() | |
| 102 | + * | |
| 103 | + * The first time next is called, it will open the file handle and return | |
| 104 | + * true. Then it will return false | |
| 105 | + * Raise an error if the file does not exist | |
| 106 | + */ | |
| 107 | + function next() | |
| 108 | + { | |
| 109 | + if ($this->alreadyRead) { | |
| 110 | + return false; | |
| 111 | + } else { | |
| 112 | + $this->alreadyRead = true; | |
| 113 | + return true; | |
| 114 | + } | |
| 115 | + } | |
| 116 | + /** | |
| 117 | + * @see File_Archive_Reader::getFilename() | |
| 118 | + */ | |
| 119 | + function getFilename() { return $this->symbolic; } | |
| 120 | + /** | |
| 121 | + * @see File_Archive_Reader::getDataFilename() | |
| 122 | + * | |
| 123 | + * Return the name of the file | |
| 124 | + */ | |
| 125 | + function getDataFilename() { return $this->filename; } | |
| 126 | + /** | |
| 127 | + * @see File_Archive_Reader::getStat() stat() | |
| 128 | + */ | |
| 129 | + function getStat() | |
| 130 | + { | |
| 131 | + if ($this->stat === null) { | |
| 132 | + $this->stat = @stat($this->filename); | |
| 133 | + | |
| 134 | + //If we can't use the stat function | |
| 135 | + if ($this->stat === false) { | |
| 136 | + $this->stat = array(); | |
| 137 | + } | |
| 138 | + } | |
| 139 | + return $this->stat; | |
| 140 | + } | |
| 141 | + | |
| 142 | + /** | |
| 143 | + * @see File_Archive_Reader::getMime | |
| 144 | + */ | |
| 145 | + function getMime() | |
| 146 | + { | |
| 147 | + if ($this->mime === null) { | |
| 148 | + PEAR::pushErrorHandling(PEAR_ERROR_RETURN); | |
| 149 | + $this->mime = MIME_Type::autoDetect($this->getDataFilename()); | |
| 150 | + PEAR::popErrorHandling(); | |
| 151 | + | |
| 152 | + if (PEAR::isError($this->mime)) { | |
| 153 | + $this->mime = parent::getMime(); | |
| 154 | + } | |
| 155 | + } | |
| 156 | + return $this->mime; | |
| 157 | + } | |
| 158 | + | |
| 159 | + /** | |
| 160 | + * Opens the file if it was not already opened | |
| 161 | + */ | |
| 162 | + function _ensureFileOpened() | |
| 163 | + { | |
| 164 | + if ($this->handle === null) { | |
| 165 | + $this->handle = @fopen($this->filename, "r"); | |
| 166 | + | |
| 167 | + if (!is_resource($this->handle)) { | |
| 168 | + $this->handle = null; | |
| 169 | + return PEAR::raiseError("Can't open {$this->filename} for reading"); | |
| 170 | + } | |
| 171 | + if ($this->handle === false) { | |
| 172 | + $this->handle = null; | |
| 173 | + return PEAR::raiseError("File {$this->filename} not found"); | |
| 174 | + } | |
| 175 | + } | |
| 176 | + } | |
| 177 | + | |
| 178 | + /** | |
| 179 | + * @see File_Archive_Reader::getData() | |
| 180 | + */ | |
| 181 | + function getData($length = -1) | |
| 182 | + { | |
| 183 | + $error = $this->_ensureFileOpened(); | |
| 184 | + if (PEAR::isError($error)) { | |
| 185 | + return $error; | |
| 186 | + } | |
| 187 | + | |
| 188 | + if (feof($this->handle)) { | |
| 189 | + return null; | |
| 190 | + } | |
| 191 | + if ($length == -1) { | |
| 192 | + $contents = ''; | |
| 193 | + $blockSize = File_Archive::getOption('blockSize'); | |
| 194 | + while (!feof($this->handle)) { | |
| 195 | + $contents .= fread($this->handle, $blockSize); | |
| 196 | + } | |
| 197 | + return $contents; | |
| 198 | + } else { | |
| 199 | + if ($length == 0) { | |
| 200 | + return ""; | |
| 201 | + } else { | |
| 202 | + return fread($this->handle, $length); | |
| 203 | + } | |
| 204 | + } | |
| 205 | + } | |
| 206 | + | |
| 207 | + /** | |
| 208 | + * @see File_Archive_Reader::skip() | |
| 209 | + */ | |
| 210 | + function skip($length = -1) | |
| 211 | + { | |
| 212 | + $error = $this->_ensureFileOpened(); | |
| 213 | + if (PEAR::isError($error)) { | |
| 214 | + return $error; | |
| 215 | + } | |
| 216 | + | |
| 217 | + $before = ftell($this->handle); | |
| 218 | + if (($length == -1 && @fseek($this->handle, 0, SEEK_END) === -1) || | |
| 219 | + ($length >= 0 && @fseek($this->handle, $length, SEEK_CUR) === -1)) { | |
| 220 | + return parent::skip($length); | |
| 221 | + } else { | |
| 222 | + return ftell($this->handle) - $before; | |
| 223 | + } | |
| 224 | + } | |
| 225 | + | |
| 226 | + /** | |
| 227 | + * @see File_Archive_Reader::rewind | |
| 228 | + */ | |
| 229 | + function rewind($length = -1) | |
| 230 | + { | |
| 231 | + if ($this->handle === null) { | |
| 232 | + return 0; | |
| 233 | + } | |
| 234 | + | |
| 235 | + $before = ftell($this->handle); | |
| 236 | + if (($length == -1 && @fseek($this->handle, 0, SEEK_SET) === -1) || | |
| 237 | + ($length >= 0 && @fseek($this->handle, -$length, SEEK_CUR) === -1)) { | |
| 238 | + return parent::rewind($length); | |
| 239 | + } else { | |
| 240 | + return $before - ftell($this->handle); | |
| 241 | + } | |
| 242 | + } | |
| 243 | + | |
| 244 | + /** | |
| 245 | + * @see File_Archive_Reader::tell() | |
| 246 | + */ | |
| 247 | + function tell() | |
| 248 | + { | |
| 249 | + if ($this->handle === null) { | |
| 250 | + return 0; | |
| 251 | + } else { | |
| 252 | + return ftell($this->handle); | |
| 253 | + } | |
| 254 | + } | |
| 255 | + | |
| 256 | + | |
| 257 | + /** | |
| 258 | + * @see File_Archive_Reader::makeWriterRemoveFiles() | |
| 259 | + */ | |
| 260 | + function makeWriterRemoveFiles($pred) | |
| 261 | + { | |
| 262 | + return PEAR::raiseError( | |
| 263 | + 'File_Archive_Reader_File represents a single file, you cant remove it'); | |
| 264 | + } | |
| 265 | + | |
| 266 | + /** | |
| 267 | + * @see File_Archive_Reader::makeWriterRemoveBlocks() | |
| 268 | + */ | |
| 269 | + function makeWriterRemoveBlocks($blocks, $seek = 0) | |
| 270 | + { | |
| 271 | + require_once "File/Archive/Writer/Files.php"; | |
| 272 | + | |
| 273 | + $writer = new File_Archive_Writer_Files(); | |
| 274 | + | |
| 275 | + $file = $this->getDataFilename(); | |
| 276 | + $pos = $this->tell(); | |
| 277 | + $this->close(); | |
| 278 | + | |
| 279 | + $writer->openFileRemoveBlock($file, $pos + $seek, $blocks); | |
| 280 | + | |
| 281 | + return $writer; | |
| 282 | + } | |
| 283 | + | |
| 284 | + /** | |
| 285 | + * @see File_Archive_Reader::makeAppendWriter | |
| 286 | + */ | |
| 287 | + function makeAppendWriter() | |
| 288 | + { | |
| 289 | + return PEAR::raiseError( | |
| 290 | + 'File_Archive_Reader_File represents a single file.'. | |
| 291 | + ' makeAppendWriter cant be executed on it' | |
| 292 | + ); | |
| 293 | + } | |
| 294 | +} | |
| 295 | + | |
| 296 | +?> | |
| 0 | 297 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Reader/Filter.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Filter out the files that do not respect a given predicat | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: Filter.php,v 1.10 2005/07/09 12:54:35 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "File/Archive/Reader/Relay.php"; | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * Filter out the files that do not respect a given predicat | |
| 36 | + */ | |
| 37 | +class File_Archive_Reader_Filter extends File_Archive_Reader_Relay | |
| 38 | +{ | |
| 39 | + /** | |
| 40 | + * @var File_Archive_Reader_Predicat | |
| 41 | + * @access private | |
| 42 | + */ | |
| 43 | + var $predicate; | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * $source is the reader to filter | |
| 47 | + */ | |
| 48 | + function File_Archive_Reader_Filter($predicate, &$source) | |
| 49 | + { | |
| 50 | + parent::File_Archive_Reader_Relay($source); | |
| 51 | + $this->predicate = $predicate; | |
| 52 | + } | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * @see File_Archive_Reader::next() | |
| 56 | + */ | |
| 57 | + function next() | |
| 58 | + { | |
| 59 | + do { | |
| 60 | + $error = $this->source->next(); | |
| 61 | + if ($error !== true) { | |
| 62 | + return $error; | |
| 63 | + } | |
| 64 | + } while (!$this->predicate->isTrue($this->source)); | |
| 65 | + return true; | |
| 66 | + } | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * @see File_Archive_Reader::select() | |
| 70 | + */ | |
| 71 | + function select($filename, $close = true) | |
| 72 | + { | |
| 73 | + if ($close) { | |
| 74 | + $error = $this->close(); | |
| 75 | + if (PEAR::isError($error)) { | |
| 76 | + return $error; | |
| 77 | + } | |
| 78 | + } | |
| 79 | + | |
| 80 | + do { | |
| 81 | + $error = $this->source->select($filename, false); | |
| 82 | + if ($error !== true) { | |
| 83 | + return $error; | |
| 84 | + } | |
| 85 | + } while (!$this->predicate->isTrue($this->source)); | |
| 86 | + return true; | |
| 87 | + } | |
| 88 | +} | |
| 89 | + | |
| 90 | +?> | |
| 0 | 91 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Reader/Gzip.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Uncompress a file that was compressed in the Gzip format | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: Gzip.php,v 1.27 2005/06/19 20:09:57 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "File/Archive/Reader/Archive.php"; | |
| 33 | +require_once "File/Archive/Writer/Files.php"; | |
| 34 | + | |
| 35 | +/** | |
| 36 | + * Uncompress a file that was compressed in the Gzip format | |
| 37 | + */ | |
| 38 | +class File_Archive_Reader_Gzip extends File_Archive_Reader_Archive | |
| 39 | +{ | |
| 40 | + var $nbRead = 0; | |
| 41 | + var $filePos = 0; | |
| 42 | + var $gzfile = null; | |
| 43 | + var $tmpName = null; | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * @see File_Archive_Reader::close() | |
| 47 | + */ | |
| 48 | + function close($innerClose = true) | |
| 49 | + { | |
| 50 | + if ($this->gzfile !== null) { | |
| 51 | + gzclose($this->gzfile); | |
| 52 | + } | |
| 53 | + if ($this->tmpName !== null) { | |
| 54 | + unlink($this->tmpName); | |
| 55 | + } | |
| 56 | + | |
| 57 | + $this->nbRead = 0; | |
| 58 | + $this->filePos = 0; | |
| 59 | + $this->gzfile = null; | |
| 60 | + $this->tmpName = null; | |
| 61 | + | |
| 62 | + return parent::close($innerClose); | |
| 63 | + } | |
| 64 | + | |
| 65 | + /** | |
| 66 | + * @see File_Archive_Reader::next() | |
| 67 | + */ | |
| 68 | + function next() | |
| 69 | + { | |
| 70 | + if (!parent::next()) { | |
| 71 | + return false; | |
| 72 | + } | |
| 73 | + | |
| 74 | + $this->nbRead++; | |
| 75 | + $this->filePos = 0; | |
| 76 | + if ($this->nbRead > 1) { | |
| 77 | + return false; | |
| 78 | + } | |
| 79 | + | |
| 80 | + $dataFilename = $this->source->getDataFilename(); | |
| 81 | + if ($dataFilename !== null) | |
| 82 | + { | |
| 83 | + $this->tmpName = null; | |
| 84 | + $this->gzfile = gzopen($dataFilename, 'r'); | |
| 85 | + } else { | |
| 86 | + $this->tmpName = tempnam(File_Archive::getOption('tmpDirectory'), 'far'); | |
| 87 | + | |
| 88 | + //Generate the tmp data | |
| 89 | + $dest = new File_Archive_Writer_Files(); | |
| 90 | + $dest->newFile($this->tmpName); | |
| 91 | + $this->source->sendData($dest); | |
| 92 | + $dest->close(); | |
| 93 | + | |
| 94 | + $this->gzfile = gzopen($this->tmpName, 'r'); | |
| 95 | + } | |
| 96 | + | |
| 97 | + return true; | |
| 98 | + } | |
| 99 | + | |
| 100 | + /** | |
| 101 | + * Return the name of the single file contained in the archive | |
| 102 | + * deduced from the name of the archive (the extension is removed) | |
| 103 | + * | |
| 104 | + * @see File_Archive_Reader::getFilename() | |
| 105 | + */ | |
| 106 | + function getFilename() | |
| 107 | + { | |
| 108 | + $name = $this->source->getFilename(); | |
| 109 | + $slashPos = strrpos($name, '/'); | |
| 110 | + if ($slashPos !== false) { | |
| 111 | + $name = substr($name, $slashPos+1); | |
| 112 | + } | |
| 113 | + $dotPos = strrpos($name, '.'); | |
| 114 | + if ($dotPos !== false && $dotPos > 0) { | |
| 115 | + $name = substr($name, 0, $dotPos); | |
| 116 | + } | |
| 117 | + | |
| 118 | + return $name; | |
| 119 | + } | |
| 120 | + | |
| 121 | + /** | |
| 122 | + * @see File_Archive_Reader::getData() | |
| 123 | + */ | |
| 124 | + function getData($length = -1) | |
| 125 | + { | |
| 126 | + if ($length == -1) { | |
| 127 | + $data = ''; | |
| 128 | + do | |
| 129 | + { | |
| 130 | + $newData = gzread($this->gzfile, 8192); | |
| 131 | + $data .= $newData; | |
| 132 | + } while ($newData != ''); | |
| 133 | + } else if ($length == 0) { | |
| 134 | + return ''; | |
| 135 | + } else { | |
| 136 | + $data = gzread($this->gzfile, $length); | |
| 137 | + } | |
| 138 | + | |
| 139 | + $this->filePos += strlen($data); | |
| 140 | + return $data == '' ? null : $data; | |
| 141 | + } | |
| 142 | + | |
| 143 | + /** | |
| 144 | + * @see File_Archive_Reader::skip() | |
| 145 | + */ | |
| 146 | + function skip($length = -1) | |
| 147 | + { | |
| 148 | + if($length == -1) { | |
| 149 | + do | |
| 150 | + { | |
| 151 | + $tmp = gzread($this->gzfile, 8192); | |
| 152 | + $this->filePos += strlen($tmp); | |
| 153 | + } while ($tmp != ''); | |
| 154 | + } else { | |
| 155 | + if (@gzseek($this->gzfile, $this->filePos + $length) === -1) { | |
| 156 | + return parent::skip($length); | |
| 157 | + } else { | |
| 158 | + $this->filePos += $length; | |
| 159 | + return $length; | |
| 160 | + } | |
| 161 | + } | |
| 162 | + } | |
| 163 | + | |
| 164 | + /** | |
| 165 | + * @see File_Archive_Reader::rewind() | |
| 166 | + */ | |
| 167 | + function rewind($length = -1) | |
| 168 | + { | |
| 169 | + if ($length == -1) { | |
| 170 | + if (@gzseek($this->gzfile, 0) === -1) { | |
| 171 | + return parent::rewind($length); | |
| 172 | + } else { | |
| 173 | + $tmp = $this->filePos; | |
| 174 | + $this->filePos = 0; | |
| 175 | + return $tmp; | |
| 176 | + } | |
| 177 | + } else { | |
| 178 | + $length = min($length, $this->filePos); | |
| 179 | + if (@gzseek($this->gzfile, $this->filePos - $length) === -1) { | |
| 180 | + return parent::rewind($length); | |
| 181 | + } else { | |
| 182 | + $this->filePos -= $length; | |
| 183 | + return $length; | |
| 184 | + } | |
| 185 | + } | |
| 186 | + } | |
| 187 | + | |
| 188 | + /** | |
| 189 | + * @see File_Archive_Reader::tell() | |
| 190 | + */ | |
| 191 | + function tell() | |
| 192 | + { | |
| 193 | + return $this->filePos; | |
| 194 | + } | |
| 195 | + | |
| 196 | + /** | |
| 197 | + * @see File_Archive_Reader::makeAppendWriter() | |
| 198 | + */ | |
| 199 | + function makeAppendWriter() | |
| 200 | + { | |
| 201 | + return PEAR::raiseError('Unable to append files to a gzip archive'); | |
| 202 | + } | |
| 203 | + | |
| 204 | + /** | |
| 205 | + * @see File_Archive_Reader::makeWriterRemoveFiles() | |
| 206 | + */ | |
| 207 | + function makeWriterRemoveFiles($pred) | |
| 208 | + { | |
| 209 | + return PEAR::raiseError('Unable to remove files from a gzip archive'); | |
| 210 | + } | |
| 211 | + | |
| 212 | + /** | |
| 213 | + * @see File_Archive_Reader::makeWriterRemoveBlocks() | |
| 214 | + */ | |
| 215 | + function makeWriterRemoveBlocks($blocks, $seek = 0) | |
| 216 | + { | |
| 217 | + require_once "File/Archive/Writer/Gzip.php"; | |
| 218 | + | |
| 219 | + if ($this->nbRead == 0) { | |
| 220 | + return PEAR::raiseError('No file selected'); | |
| 221 | + } | |
| 222 | + | |
| 223 | + //Uncompress data to a temporary file | |
| 224 | + $tmp = tmpfile(); | |
| 225 | + $expectedPos = $this->filePos + $seek; | |
| 226 | + $this->rewind(); | |
| 227 | + | |
| 228 | + //Read the begining of the file | |
| 229 | + while ($this->filePos < $expectedPos && | |
| 230 | + ($data = $this->getData(min($expectedPos - $this->filePos, 8192))) !== null) { | |
| 231 | + fwrite($tmp, $data); | |
| 232 | + } | |
| 233 | + | |
| 234 | + $keep = false; | |
| 235 | + foreach ($blocks as $length) { | |
| 236 | + if ($keep) { | |
| 237 | + $expectedPos = $this->filePos + $length; | |
| 238 | + while ($this->filePos < $expectedPos && | |
| 239 | + ($data = $this->getData(min($expectedPos - $this->filePos, 8192))) !== null) { | |
| 240 | + fwrite($tmp, $data); | |
| 241 | + } | |
| 242 | + } else { | |
| 243 | + $this->skip($length); | |
| 244 | + } | |
| 245 | + $keep = !$keep; | |
| 246 | + } | |
| 247 | + if ($keep) { | |
| 248 | + //Read the end of the file | |
| 249 | + while(($data = $this->getData(8192)) !== null) { | |
| 250 | + fwrite($tmp, $data); | |
| 251 | + } | |
| 252 | + } | |
| 253 | + fseek($tmp, 0); | |
| 254 | + | |
| 255 | + //Create the writer | |
| 256 | + $this->source->rewind(); | |
| 257 | + $innerWriter = $this->source->makeWriterRemoveBlocks(array()); //Truncate the source | |
| 258 | + unset($this->source); | |
| 259 | + $writer = new File_Archive_Writer_Gzip(null, $innerWriter); | |
| 260 | + | |
| 261 | + //And compress data from the temporary file | |
| 262 | + while (!feof($tmp)) { | |
| 263 | + $data = fread($tmp, 8192); | |
| 264 | + $writer->writeData($data); | |
| 265 | + } | |
| 266 | + fclose($tmp); | |
| 267 | + | |
| 268 | + //Do not close inner writer since makeWriter was called | |
| 269 | + $this->close(); | |
| 270 | + | |
| 271 | + return $writer; | |
| 272 | + } | |
| 273 | + | |
| 274 | +} | |
| 275 | + | |
| 276 | +?> | |
| 0 | 277 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Reader/Memory.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * A reader that takes its input from a memory buffer | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: Memory.php,v 1.19 2005/06/19 20:09:57 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "File/Archive/Reader.php"; | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * A reader that takes its input from a memory buffer | |
| 36 | + */ | |
| 37 | +class File_Archive_Reader_Memory extends File_Archive_Reader | |
| 38 | +{ | |
| 39 | + /** | |
| 40 | + * @var String Name of the file exported by this reader | |
| 41 | + * @access private | |
| 42 | + */ | |
| 43 | + var $filename; | |
| 44 | + /** | |
| 45 | + * @var Array Stat of the file exported by this reader | |
| 46 | + * @access private | |
| 47 | + */ | |
| 48 | + var $stat; | |
| 49 | + /** | |
| 50 | + * @var String MIME type of the file exported by this reader | |
| 51 | + * @access private | |
| 52 | + */ | |
| 53 | + var $mime; | |
| 54 | + /** | |
| 55 | + * @var String Memory buffer that contains the data of the file | |
| 56 | + * @access private | |
| 57 | + */ | |
| 58 | + var $memory; | |
| 59 | + /** | |
| 60 | + * @var Int Current position in the file | |
| 61 | + * @access private | |
| 62 | + */ | |
| 63 | + var $offset = 0; | |
| 64 | + /** | |
| 65 | + * @var Boolean Has the file already been read | |
| 66 | + * @access private | |
| 67 | + */ | |
| 68 | + var $alreadyRead = false; | |
| 69 | + | |
| 70 | + /** | |
| 71 | + * @param string $memory is the content of the file. | |
| 72 | + * This parameter is passed as a reference for performance | |
| 73 | + * reasons. The content should not be changer after the constructor | |
| 74 | + * @param string $filename is the name of the file | |
| 75 | + * @param array $stat are the statistics of the file. The size will be | |
| 76 | + * recomputed from $memory | |
| 77 | + * @param string $mime is the mime type of the file | |
| 78 | + */ | |
| 79 | + function File_Archive_Reader_Memory(&$memory, $filename, | |
| 80 | + $stat=array(), $mime=null) | |
| 81 | + { | |
| 82 | + $this->memory = &$memory; | |
| 83 | + $this->filename = $this->getStandardURL($filename); | |
| 84 | + $this->stat = $stat; | |
| 85 | + $this->stat[7] = $this->stat['size'] = strlen($this->memory); | |
| 86 | + $this->mime = $mime; | |
| 87 | + } | |
| 88 | + | |
| 89 | + /** | |
| 90 | + * The subclass should overwrite this function to change the filename, stat | |
| 91 | + * and memory | |
| 92 | + */ | |
| 93 | + function next() | |
| 94 | + { | |
| 95 | + if ($this->alreadyRead) { | |
| 96 | + return false; | |
| 97 | + } else { | |
| 98 | + $this->alreadyRead = true; | |
| 99 | + return true; | |
| 100 | + } | |
| 101 | + } | |
| 102 | + | |
| 103 | + /** | |
| 104 | + * @see File_Archive_Reader::getFilename() | |
| 105 | + */ | |
| 106 | + function getFilename() { return $this->filename; } | |
| 107 | + /** | |
| 108 | + * @see File_Archive_Reader::getStat() | |
| 109 | + */ | |
| 110 | + function getStat() { return $this->stat; } | |
| 111 | + /** | |
| 112 | + * @see File_Archive_Reader::getMime() | |
| 113 | + */ | |
| 114 | + function getMime() | |
| 115 | + { | |
| 116 | + return $this->mime==null ? parent::getMime() : $this->mime; | |
| 117 | + } | |
| 118 | + | |
| 119 | + /** | |
| 120 | + * @see File_Archive_Reader::getData() | |
| 121 | + */ | |
| 122 | + function getData($length = -1) | |
| 123 | + { | |
| 124 | + if ($this->offset == strlen($this->memory)) { | |
| 125 | + return null; | |
| 126 | + } | |
| 127 | + if ($length == -1) { | |
| 128 | + $actualLength = strlen($this->memory) - $this->offset; | |
| 129 | + } else { | |
| 130 | + $actualLength = min($length, strlen($this->memory) - $this->offset); | |
| 131 | + } | |
| 132 | + $result = substr($this->memory, $this->offset, $actualLength); | |
| 133 | + $this->offset += $actualLength; | |
| 134 | + return $result; | |
| 135 | + } | |
| 136 | + | |
| 137 | + /** | |
| 138 | + * @see File_Archive_Reader::skip() | |
| 139 | + */ | |
| 140 | + function skip($length = -1) | |
| 141 | + { | |
| 142 | + if ($length == -1) { | |
| 143 | + $length = strlen($this->memory) - $this->offset; | |
| 144 | + } else { | |
| 145 | + $length = min($length, strlen($this->memory) - $this->offset); | |
| 146 | + } | |
| 147 | + $this->offset += $length; | |
| 148 | + return $length; | |
| 149 | + } | |
| 150 | + | |
| 151 | + /** | |
| 152 | + * @see File_Archive_Reader::rewind() | |
| 153 | + */ | |
| 154 | + function rewind($length = -1) | |
| 155 | + { | |
| 156 | + if ($length == -1) { | |
| 157 | + $tmp = $this->offset; | |
| 158 | + $this->offset = 0; | |
| 159 | + return $tmp; | |
| 160 | + } else { | |
| 161 | + $length = min($length, $this->offset); | |
| 162 | + $this->offset -= $length; | |
| 163 | + return $length; | |
| 164 | + } | |
| 165 | + } | |
| 166 | + | |
| 167 | + /** | |
| 168 | + * @see File_Archive_Reader::tell() | |
| 169 | + */ | |
| 170 | + function tell() | |
| 171 | + { | |
| 172 | + return $this->offset; | |
| 173 | + } | |
| 174 | + | |
| 175 | + /** | |
| 176 | + * @see File_Archive_Reader::close() | |
| 177 | + */ | |
| 178 | + function close() | |
| 179 | + { | |
| 180 | + $this->offset = 0; | |
| 181 | + $this->alreadyRead = false; | |
| 182 | + } | |
| 183 | + | |
| 184 | + /** | |
| 185 | + * @see File_Archive_Reader::makeAppendWriter() | |
| 186 | + */ | |
| 187 | + function makeAppendWriter() | |
| 188 | + { | |
| 189 | + return PEAR::raiseError('Unable to append files to a memory archive'); | |
| 190 | + } | |
| 191 | + | |
| 192 | + /** | |
| 193 | + * @see File_Archive_Reader::makeWriterRemoveFiles() | |
| 194 | + */ | |
| 195 | + function makeWriterRemoveFiles($pred) | |
| 196 | + { | |
| 197 | + return PEAR::raiseError('Unable to remove files from a memory archive'); | |
| 198 | + } | |
| 199 | + | |
| 200 | + /** | |
| 201 | + * @see File_Archive_Reader::makeWriterRemoveBlocks() | |
| 202 | + */ | |
| 203 | + function makeWriterRemoveBlocks($blocks, $seek = 0) | |
| 204 | + { | |
| 205 | + require_once "File/Archive/Writer/Memory.php"; | |
| 206 | + $data = substr($this->memory, 0, $this->offset + $seek); | |
| 207 | + $this->memory = substr($this->memory, $this->offset + $seek); | |
| 208 | + | |
| 209 | + $keep = false; | |
| 210 | + foreach ($blocks as $length) { | |
| 211 | + if ($keep) { | |
| 212 | + $data .= substr($this->memory, 0, $length); | |
| 213 | + } | |
| 214 | + $this->memory = substr($this->memory, $length); | |
| 215 | + $keep = !$keep; | |
| 216 | + } | |
| 217 | + if ($keep) { | |
| 218 | + $this->memory = $data . $this->memory; | |
| 219 | + } else { | |
| 220 | + $this->memory = $data; | |
| 221 | + } | |
| 222 | + $this->close(); | |
| 223 | + return new File_Archive_Writer_Memory($this->memory, strlen($this->memory)); | |
| 224 | + } | |
| 225 | +} | |
| 226 | + | |
| 227 | +?> | |
| 0 | 228 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Reader/MimeList.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Retrieve the MIME of a file thanks to its extension | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: MimeList.php,v 1.7 2005/02/23 20:11:42 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +/** | |
| 33 | + * Returns the MIME of the filename, deducted from its extension | |
| 34 | + * If the extension is unknown, returns "application/octet-stream" | |
| 35 | + */ | |
| 36 | +function File_Archive_Reader_GetMime($filename) | |
| 37 | +{ | |
| 38 | + $pos = strrpos($filename, '.'); | |
| 39 | + $extension = ""; | |
| 40 | + if ($pos !== false) { | |
| 41 | + $extension = strtolower(substr($filename, $pos+1)); | |
| 42 | + } | |
| 43 | + | |
| 44 | + switch($extension) { | |
| 45 | + case '3dmf': | |
| 46 | + return 'x-world/x-3dmf'; | |
| 47 | + case 'a': | |
| 48 | + return 'application/octet-stream'; | |
| 49 | + case 'aab': | |
| 50 | + return 'application/x-authorware-bin'; | |
| 51 | + case 'aam': | |
| 52 | + return 'application/x-authorware-map'; | |
| 53 | + case 'aas': | |
| 54 | + return 'application/x-authorware-seg'; | |
| 55 | + case 'abc': | |
| 56 | + return 'text/vnd.abc'; | |
| 57 | + case 'acgi': | |
| 58 | + return 'text/html'; | |
| 59 | + case 'afl': | |
| 60 | + return 'video/animaflex'; | |
| 61 | + case 'ai': | |
| 62 | + return 'application/postscript'; | |
| 63 | + case 'aif': | |
| 64 | + return 'audio/aiff'; | |
| 65 | + case 'aifc': | |
| 66 | + return 'audio/aiff'; | |
| 67 | + case 'aiff': | |
| 68 | + return 'audio/aiff'; | |
| 69 | + case 'aim': | |
| 70 | + return 'application/x-aim'; | |
| 71 | + case 'aip': | |
| 72 | + return 'text/x-audiosoft-intra'; | |
| 73 | + case 'ani': | |
| 74 | + return 'application/x-navi-animation'; | |
| 75 | + case 'aos': | |
| 76 | + return 'application/x-nokia-9000-communicator-add-on-software'; | |
| 77 | + case 'aps': | |
| 78 | + return 'application/mime'; | |
| 79 | + case 'arc': | |
| 80 | + return 'application/octet-stream'; | |
| 81 | + case 'arj': | |
| 82 | + return 'application/arj'; | |
| 83 | + case 'art': | |
| 84 | + return 'image/x-jg'; | |
| 85 | + case 'asf': | |
| 86 | + return 'video/x-ms-asf'; | |
| 87 | + case 'asm': | |
| 88 | + return 'text/x-asm'; | |
| 89 | + case 'asp': | |
| 90 | + return 'text/asp'; | |
| 91 | + case 'asx': | |
| 92 | + return 'application/x-mplayer2'; | |
| 93 | + case 'au': | |
| 94 | + return 'audio/basic'; | |
| 95 | + case 'avi': | |
| 96 | + return 'application/x-troff-msvideo'; | |
| 97 | + case 'avs': | |
| 98 | + return 'video/avs-video'; | |
| 99 | + case 'bcpio': | |
| 100 | + return 'application/x-bcpio'; | |
| 101 | + case 'bin': | |
| 102 | + return 'application/x-binary'; | |
| 103 | + case 'bm': | |
| 104 | + return 'image/bmp'; | |
| 105 | + case 'bmp': | |
| 106 | + return 'image/bmp'; | |
| 107 | + case 'boo': | |
| 108 | + return 'application/book'; | |
| 109 | + case 'book': | |
| 110 | + return 'application/book'; | |
| 111 | + case 'boz': | |
| 112 | + return 'application/x-bzip2'; | |
| 113 | + case 'bsh': | |
| 114 | + return 'application/x-bsh'; | |
| 115 | + case 'bz': | |
| 116 | + return 'application/x-bzip'; | |
| 117 | + case 'bz2': | |
| 118 | + return 'application/x-bzip2'; | |
| 119 | + case 'c': | |
| 120 | + return 'text/plain'; | |
| 121 | + case 'c++': | |
| 122 | + return 'text/plain'; | |
| 123 | + case 'cat': | |
| 124 | + return 'application/vnd.ms-pki.seccat'; | |
| 125 | + case 'cc': | |
| 126 | + return 'text/plain'; | |
| 127 | + case 'ccad': | |
| 128 | + return 'application/clariscad'; | |
| 129 | + case 'cco': | |
| 130 | + return 'application/x-cocoa'; | |
| 131 | + case 'cdf': | |
| 132 | + return 'application/cdf'; | |
| 133 | + case 'cer': | |
| 134 | + return 'application/pkix-cert'; | |
| 135 | + case 'cha': | |
| 136 | + return 'application/x-chat'; | |
| 137 | + case 'chat': | |
| 138 | + return 'application/x-chat'; | |
| 139 | + case 'class': | |
| 140 | + return 'application/java'; | |
| 141 | + case 'com': | |
| 142 | + return 'application/octet-stream'; | |
| 143 | + case 'conf': | |
| 144 | + return 'text/plain'; | |
| 145 | + case 'cpio': | |
| 146 | + return 'application/x-cpio'; | |
| 147 | + case 'cpp': | |
| 148 | + return 'text/x-c'; | |
| 149 | + case 'cpt': | |
| 150 | + return 'application/mac-compactpro'; | |
| 151 | + case 'crl': | |
| 152 | + return 'application/pkcs-crl'; | |
| 153 | + case 'csh': | |
| 154 | + return 'application/x-csh'; | |
| 155 | + case 'css': | |
| 156 | + return 'text/css'; | |
| 157 | + case 'cxx': | |
| 158 | + return 'text/plain'; | |
| 159 | + case 'dcr': | |
| 160 | + return 'application/x-director'; | |
| 161 | + case 'deepv': | |
| 162 | + return 'application/x-deepv'; | |
| 163 | + case 'def': | |
| 164 | + return 'text/plain'; | |
| 165 | + case 'der': | |
| 166 | + return 'application/x-x509-ca-cert'; | |
| 167 | + case 'dif': | |
| 168 | + return 'video/x-dv'; | |
| 169 | + case 'dir': | |
| 170 | + return 'application/x-director'; | |
| 171 | + case 'dl': | |
| 172 | + return 'video/dl'; | |
| 173 | + case 'doc': | |
| 174 | + return 'application/msword'; | |
| 175 | + case 'dot': | |
| 176 | + return 'application/msword'; | |
| 177 | + case 'dp': | |
| 178 | + return 'application/commonground'; | |
| 179 | + case 'drw': | |
| 180 | + return 'application/drafting'; | |
| 181 | + case 'dump': | |
| 182 | + return 'application/octet-stream'; | |
| 183 | + case 'dv': | |
| 184 | + return 'video/x-dv'; | |
| 185 | + case 'dvi': | |
| 186 | + return 'application/x-dvi'; | |
| 187 | + case 'dwf': | |
| 188 | + return 'drawing/x-dwf (old)'; | |
| 189 | + case 'dwg': | |
| 190 | + return 'application/acad'; | |
| 191 | + case 'dxf': | |
| 192 | + return 'application/dxf'; | |
| 193 | + case 'dxr': | |
| 194 | + return 'application/x-director'; | |
| 195 | + case 'el': | |
| 196 | + return 'text/x-script.elisp'; | |
| 197 | + case 'elc': | |
| 198 | + return 'application/x-bytecode.elisp (compiled elisp)'; | |
| 199 | + case 'env': | |
| 200 | + return 'application/x-envoy'; | |
| 201 | + case 'eps': | |
| 202 | + return 'application/postscript'; | |
| 203 | + case 'es': | |
| 204 | + return 'application/x-esrehber'; | |
| 205 | + case 'etx': | |
| 206 | + return 'text/x-setext'; | |
| 207 | + case 'evy': | |
| 208 | + return 'application/envoy'; | |
| 209 | + case 'exe': | |
| 210 | + return 'application/octet-stream'; | |
| 211 | + case 'f': | |
| 212 | + return 'text/plain'; | |
| 213 | + case 'f77': | |
| 214 | + return 'text/x-fortran'; | |
| 215 | + case 'f90': | |
| 216 | + return 'text/plain'; | |
| 217 | + case 'fdf': | |
| 218 | + return 'application/vnd.fdf'; | |
| 219 | + case 'fif': | |
| 220 | + return 'application/fractals'; | |
| 221 | + case 'fli': | |
| 222 | + return 'video/fli'; | |
| 223 | + case 'flo': | |
| 224 | + return 'image/florian'; | |
| 225 | + case 'flx': | |
| 226 | + return 'text/vnd.fmi.flexstor'; | |
| 227 | + case 'fmf': | |
| 228 | + return 'video/x-atomic3d-feature'; | |
| 229 | + case 'for': | |
| 230 | + return 'text/plain'; | |
| 231 | + case 'fpx': | |
| 232 | + return 'image/vnd.fpx'; | |
| 233 | + case 'frl': | |
| 234 | + return 'application/freeloader'; | |
| 235 | + case 'funk': | |
| 236 | + return 'audio/make'; | |
| 237 | + case 'g': | |
| 238 | + return 'text/plain'; | |
| 239 | + case 'g3': | |
| 240 | + return 'image/g3fax'; | |
| 241 | + case 'gif': | |
| 242 | + return 'image/gif'; | |
| 243 | + case 'gl': | |
| 244 | + return 'video/gl'; | |
| 245 | + case 'gsd': | |
| 246 | + return 'audio/x-gsm'; | |
| 247 | + case 'gsm': | |
| 248 | + return 'audio/x-gsm'; | |
| 249 | + case 'gsp': | |
| 250 | + return 'application/x-gsp'; | |
| 251 | + case 'gss': | |
| 252 | + return 'application/x-gss'; | |
| 253 | + case 'gtar': | |
| 254 | + return 'application/x-gtar'; | |
| 255 | + case 'gz': | |
| 256 | + return 'application/x-compressed'; | |
| 257 | + case 'gzip': | |
| 258 | + return 'application/x-gzip'; | |
| 259 | + case 'h': | |
| 260 | + return 'text/plain'; | |
| 261 | + case 'hdf': | |
| 262 | + return 'application/x-hdf'; | |
| 263 | + case 'help': | |
| 264 | + return 'application/x-helpfile'; | |
| 265 | + case 'hgl': | |
| 266 | + return 'application/vnd.hp-hpgl'; | |
| 267 | + case 'hh': | |
| 268 | + return 'text/plain'; | |
| 269 | + case 'hlb': | |
| 270 | + return 'text/x-script'; | |
| 271 | + case 'hlp': | |
| 272 | + return 'application/hlp'; | |
| 273 | + case 'hpg': | |
| 274 | + return 'application/vnd.hp-hpgl'; | |
| 275 | + case 'hpgl': | |
| 276 | + return 'application/vnd.hp-hpgl'; | |
| 277 | + case 'hqx': | |
| 278 | + return 'application/binhex'; | |
| 279 | + case 'hta': | |
| 280 | + return 'application/hta'; | |
| 281 | + case 'htc': | |
| 282 | + return 'text/x-component'; | |
| 283 | + case 'htm': | |
| 284 | + return 'text/html'; | |
| 285 | + case 'html': | |
| 286 | + return 'text/html'; | |
| 287 | + case 'htmls': | |
| 288 | + return 'text/html'; | |
| 289 | + case 'htt': | |
| 290 | + return 'text/webviewhtml'; | |
| 291 | + case 'htx': | |
| 292 | + return 'text/html'; | |
| 293 | + case 'ice': | |
| 294 | + return 'x-conference/x-cooltalk'; | |
| 295 | + case 'ico': | |
| 296 | + return 'image/x-icon'; | |
| 297 | + case 'idc': | |
| 298 | + return 'text/plain'; | |
| 299 | + case 'ief': | |
| 300 | + return 'image/ief'; | |
| 301 | + case 'iefs': | |
| 302 | + return 'image/ief'; | |
| 303 | + case 'iges': | |
| 304 | + return 'application/iges'; | |
| 305 | + case 'igs': | |
| 306 | + return 'application/iges'; | |
| 307 | + case 'ima': | |
| 308 | + return 'application/x-ima'; | |
| 309 | + case 'imap': | |
| 310 | + return 'application/x-httpd-imap'; | |
| 311 | + case 'inf': | |
| 312 | + return 'application/inf'; | |
| 313 | + case 'ins': | |
| 314 | + return 'application/x-internett-signup'; | |
| 315 | + case 'ip': | |
| 316 | + return 'application/x-ip2'; | |
| 317 | + case 'isu': | |
| 318 | + return 'video/x-isvideo'; | |
| 319 | + case 'it': | |
| 320 | + return 'audio/it'; | |
| 321 | + case 'iv': | |
| 322 | + return 'application/x-inventor'; | |
| 323 | + case 'ivr': | |
| 324 | + return 'i-world/i-vrml'; | |
| 325 | + case 'ivy': | |
| 326 | + return 'application/x-livescreen'; | |
| 327 | + case 'jam': | |
| 328 | + return 'audio/x-jam'; | |
| 329 | + case 'jav': | |
| 330 | + return 'text/plain'; | |
| 331 | + case 'java': | |
| 332 | + return 'text/plain'; | |
| 333 | + case 'jcm': | |
| 334 | + return 'application/x-java-commerce'; | |
| 335 | + case 'jfif': | |
| 336 | + return 'image/jpeg'; | |
| 337 | + case 'jfif-tbnl': | |
| 338 | + return 'image/jpeg'; | |
| 339 | + case 'jpe': | |
| 340 | + return 'image/jpeg'; | |
| 341 | + case 'jpeg': | |
| 342 | + return 'image/jpeg'; | |
| 343 | + case 'jpg': | |
| 344 | + return 'image/jpeg'; | |
| 345 | + case 'jps': | |
| 346 | + return 'image/x-jps'; | |
| 347 | + case 'js': | |
| 348 | + return 'application/x-javascript'; | |
| 349 | + case 'jut': | |
| 350 | + return 'image/jutvision'; | |
| 351 | + case 'kar': | |
| 352 | + return 'audio/midi'; | |
| 353 | + case 'ksh': | |
| 354 | + return 'application/x-ksh'; | |
| 355 | + case 'la': | |
| 356 | + return 'audio/nspaudio'; | |
| 357 | + case 'lam': | |
| 358 | + return 'audio/x-liveaudio'; | |
| 359 | + case 'latex': | |
| 360 | + return 'application/x-latex'; | |
| 361 | + case 'lha': | |
| 362 | + return 'application/lha'; | |
| 363 | + case 'lhx': | |
| 364 | + return 'application/octet-stream'; | |
| 365 | + case 'list': | |
| 366 | + return 'text/plain'; | |
| 367 | + case 'lma': | |
| 368 | + return 'audio/nspaudio'; | |
| 369 | + case 'log': | |
| 370 | + return 'text/plain'; | |
| 371 | + case 'lsp': | |
| 372 | + return 'application/x-lisp'; | |
| 373 | + case 'lst': | |
| 374 | + return 'text/plain'; | |
| 375 | + case 'lsx': | |
| 376 | + return 'text/x-la-asf'; | |
| 377 | + case 'ltx': | |
| 378 | + return 'application/x-latex'; | |
| 379 | + case 'lzh': | |
| 380 | + return 'application/octet-stream'; | |
| 381 | + case 'lzx': | |
| 382 | + return 'application/lzx'; | |
| 383 | + case 'm': | |
| 384 | + return 'text/plain'; | |
| 385 | + case 'm1v': | |
| 386 | + return 'video/mpeg'; | |
| 387 | + case 'm2a': | |
| 388 | + return 'audio/mpeg'; | |
| 389 | + case 'm2v': | |
| 390 | + return 'video/mpeg'; | |
| 391 | + case 'm3u': | |
| 392 | + return 'audio/x-mpequrl'; | |
| 393 | + case 'man': | |
| 394 | + return 'application/x-troff-man'; | |
| 395 | + case 'map': | |
| 396 | + return 'application/x-navimap'; | |
| 397 | + case 'mar': | |
| 398 | + return 'text/plain'; | |
| 399 | + case 'mbd': | |
| 400 | + return 'application/mbedlet'; | |
| 401 | + case 'mc$': | |
| 402 | + return 'application/x-magic-cap-package-1.0'; | |
| 403 | + case 'mcd': | |
| 404 | + return 'application/mcad'; | |
| 405 | + case 'mcf': | |
| 406 | + return 'image/vasa'; | |
| 407 | + case 'mcp': | |
| 408 | + return 'application/netmc'; | |
| 409 | + case 'me': | |
| 410 | + return 'application/x-troff-me'; | |
| 411 | + case 'mht': | |
| 412 | + return 'message/rfc822'; | |
| 413 | + case 'mhtml': | |
| 414 | + return 'message/rfc822'; | |
| 415 | + case 'mid': | |
| 416 | + return 'application/x-midi'; | |
| 417 | + case 'midi': | |
| 418 | + return 'audio/midi'; | |
| 419 | + case 'mif': | |
| 420 | + return 'application/x-frame'; | |
| 421 | + case 'mime': | |
| 422 | + return 'message/rfc822'; | |
| 423 | + case 'mjf': | |
| 424 | + return 'audio/x-vnd.audioexplosion.mjuicemediafile'; | |
| 425 | + case 'mjpg': | |
| 426 | + return 'video/x-motion-jpeg'; | |
| 427 | + case 'mm': | |
| 428 | + return 'application/base64'; | |
| 429 | + case 'mme': | |
| 430 | + return 'application/base64'; | |
| 431 | + case 'mod': | |
| 432 | + return 'audio/mod'; | |
| 433 | + case 'moov': | |
| 434 | + return 'video/quicktime'; | |
| 435 | + case 'mov': | |
| 436 | + return 'video/quicktime'; | |
| 437 | + case 'movie': | |
| 438 | + return 'video/x-sgi-movie'; | |
| 439 | + case 'mp2': | |
| 440 | + return 'video/mpeg'; | |
| 441 | + case 'mp3': | |
| 442 | + return 'video/mpeg'; | |
| 443 | + case 'mpa': | |
| 444 | + return 'audio/mpeg'; | |
| 445 | + case 'mpc': | |
| 446 | + return 'application/x-project'; | |
| 447 | + case 'mpe': | |
| 448 | + return 'video/mpeg'; | |
| 449 | + case 'mpeg': | |
| 450 | + return 'video/mpeg'; | |
| 451 | + case 'mpg': | |
| 452 | + return 'video/mpeg'; | |
| 453 | + case 'mpga': | |
| 454 | + return 'audio/mpeg'; | |
| 455 | + case 'mpp': | |
| 456 | + return 'application/vnd.ms-project'; | |
| 457 | + case 'mpt': | |
| 458 | + return 'application/x-project'; | |
| 459 | + case 'mpv': | |
| 460 | + return 'application/x-project'; | |
| 461 | + case 'mpx': | |
| 462 | + return 'application/x-project'; | |
| 463 | + case 'mrc': | |
| 464 | + return 'application/marc'; | |
| 465 | + case 'ms': | |
| 466 | + return 'application/x-troff-ms'; | |
| 467 | + case 'mv': | |
| 468 | + return 'video/x-sgi-movie'; | |
| 469 | + case 'my': | |
| 470 | + return 'audio/make'; | |
| 471 | + case 'mzz': | |
| 472 | + return 'application/x-vnd.audioexplosion.mzz'; | |
| 473 | + case 'nap': | |
| 474 | + return 'image/naplps'; | |
| 475 | + case 'naplps': | |
| 476 | + return 'image/naplps'; | |
| 477 | + case 'nc': | |
| 478 | + return 'application/x-netcdf'; | |
| 479 | + case 'ncm': | |
| 480 | + return 'application/vnd.nokia.configuration-message'; | |
| 481 | + case 'nif': | |
| 482 | + return 'image/x-niff'; | |
| 483 | + case 'niff': | |
| 484 | + return 'image/x-niff'; | |
| 485 | + case 'nix': | |
| 486 | + return 'application/x-mix-transfer'; | |
| 487 | + case 'nsc': | |
| 488 | + return 'application/x-conference'; | |
| 489 | + case 'nvd': | |
| 490 | + return 'application/x-navidoc'; | |
| 491 | + case 'o': | |
| 492 | + return 'application/octet-stream'; | |
| 493 | + case 'oda': | |
| 494 | + return 'application/oda'; | |
| 495 | + case 'omc': | |
| 496 | + return 'application/x-omc'; | |
| 497 | + case 'omcd': | |
| 498 | + return 'application/x-omcdatamaker'; | |
| 499 | + case 'omcr': | |
| 500 | + return 'application/x-omcregerator'; | |
| 501 | + case 'p': | |
| 502 | + return 'text/x-pascal'; | |
| 503 | + case 'p10': | |
| 504 | + return 'application/pkcs10'; | |
| 505 | + case 'p12': | |
| 506 | + return 'application/pkcs-12'; | |
| 507 | + case 'p7a': | |
| 508 | + return 'application/x-pkcs7-signature'; | |
| 509 | + case 'p7c': | |
| 510 | + return 'application/pkcs7-mime'; | |
| 511 | + case 'p7m': | |
| 512 | + return 'application/pkcs7-mime'; | |
| 513 | + case 'p7r': | |
| 514 | + return 'application/x-pkcs7-certreqresp'; | |
| 515 | + case 'p7s': | |
| 516 | + return 'application/pkcs7-signature'; | |
| 517 | + case 'part': | |
| 518 | + return 'application/pro_eng'; | |
| 519 | + case 'pas': | |
| 520 | + return 'text/pascal'; | |
| 521 | + case 'pbm': | |
| 522 | + return 'image/x-portable-bitmap'; | |
| 523 | + case 'pcl': | |
| 524 | + return 'application/vnd.hp-pcl'; | |
| 525 | + case 'pct': | |
| 526 | + return 'image/x-pict'; | |
| 527 | + case 'pcx': | |
| 528 | + return 'image/x-pcx'; | |
| 529 | + case 'pdb': | |
| 530 | + return 'chemical/x-pdb'; | |
| 531 | + case 'pdf': | |
| 532 | + return 'application/pdf'; | |
| 533 | + case 'pfunk': | |
| 534 | + return 'audio/make'; | |
| 535 | + case 'pgm': | |
| 536 | + return 'image/x-portable-graymap'; | |
| 537 | + case 'pic': | |
| 538 | + return 'image/pict'; | |
| 539 | + case 'pict': | |
| 540 | + return 'image/pict'; | |
| 541 | + case 'pkg': | |
| 542 | + return 'application/x-newton-compatible-pkg'; | |
| 543 | + case 'pko': | |
| 544 | + return 'application/vnd.ms-pki.pko'; | |
| 545 | + case 'pl': | |
| 546 | + return 'text/plain'; | |
| 547 | + case 'plx': | |
| 548 | + return 'application/x-pixclscript'; | |
| 549 | + case 'pm': | |
| 550 | + return 'image/x-xpixmap'; | |
| 551 | + case 'pm4': | |
| 552 | + return 'application/x-pagemaker'; | |
| 553 | + case 'pm5': | |
| 554 | + return 'application/x-pagemaker'; | |
| 555 | + case 'png': | |
| 556 | + return 'image/png'; | |
| 557 | + case 'pnm': | |
| 558 | + return 'application/x-portable-anymap'; | |
| 559 | + case 'pot': | |
| 560 | + return 'application/mspowerpoint'; | |
| 561 | + case 'pov': | |
| 562 | + return 'model/x-pov'; | |
| 563 | + case 'ppa': | |
| 564 | + return 'application/vnd.ms-powerpoint'; | |
| 565 | + case 'ppm': | |
| 566 | + return 'image/x-portable-pixmap'; | |
| 567 | + case 'pps': | |
| 568 | + return 'application/mspowerpoint'; | |
| 569 | + case 'ppt': | |
| 570 | + return 'application/mspowerpoint'; | |
| 571 | + case 'ppz': | |
| 572 | + return 'application/mspowerpoint'; | |
| 573 | + case 'pre': | |
| 574 | + return 'application/x-freelance'; | |
| 575 | + case 'prt': | |
| 576 | + return 'application/pro_eng'; | |
| 577 | + case 'ps': | |
| 578 | + return 'application/postscript'; | |
| 579 | + case 'psd': | |
| 580 | + return 'application/octet-stream'; | |
| 581 | + case 'pvu': | |
| 582 | + return 'paleovu/x-pv'; | |
| 583 | + case 'pwz': | |
| 584 | + return 'application/vnd.ms-powerpoint'; | |
| 585 | + case 'py': | |
| 586 | + return 'text/x-script.phyton'; | |
| 587 | + case 'pyc': | |
| 588 | + return 'applicaiton/x-bytecode.python'; | |
| 589 | + case 'qcp': | |
| 590 | + return 'audio/vnd.qcelp'; | |
| 591 | + case 'qd3': | |
| 592 | + return 'x-world/x-3dmf'; | |
| 593 | + case 'qd3d': | |
| 594 | + return 'x-world/x-3dmf'; | |
| 595 | + case 'qif': | |
| 596 | + return 'image/x-quicktime'; | |
| 597 | + case 'qt': | |
| 598 | + return 'video/quicktime'; | |
| 599 | + case 'qtc': | |
| 600 | + return 'video/x-qtc'; | |
| 601 | + case 'qti': | |
| 602 | + return 'image/x-quicktime'; | |
| 603 | + case 'qtif': | |
| 604 | + return 'image/x-quicktime'; | |
| 605 | + case 'ra': | |
| 606 | + return 'audio/x-pn-realaudio'; | |
| 607 | + case 'ram': | |
| 608 | + return 'audio/x-pn-realaudio'; | |
| 609 | + case 'ras': | |
| 610 | + return 'application/x-cmu-raster'; | |
| 611 | + case 'rast': | |
| 612 | + return 'image/cmu-raster'; | |
| 613 | + case 'rexx': | |
| 614 | + return 'text/x-script.rexx'; | |
| 615 | + case 'rf': | |
| 616 | + return 'image/vnd.rn-realflash'; | |
| 617 | + case 'rgb': | |
| 618 | + return 'image/x-rgb'; | |
| 619 | + case 'rm': | |
| 620 | + return 'application/vnd.rn-realmedia'; | |
| 621 | + case 'rmi': | |
| 622 | + return 'audio/mid'; | |
| 623 | + case 'rmm': | |
| 624 | + return 'audio/x-pn-realaudio'; | |
| 625 | + case 'rmp': | |
| 626 | + return 'audio/x-pn-realaudio'; | |
| 627 | + case 'rng': | |
| 628 | + return 'application/ringing-tones'; | |
| 629 | + case 'rnx': | |
| 630 | + return 'application/vnd.rn-realplayer'; | |
| 631 | + case 'roff': | |
| 632 | + return 'application/x-troff'; | |
| 633 | + case 'rp': | |
| 634 | + return 'image/vnd.rn-realpix'; | |
| 635 | + case 'rpm': | |
| 636 | + return 'audio/x-pn-realaudio-plugin'; | |
| 637 | + case 'rt': | |
| 638 | + return 'text/richtext'; | |
| 639 | + case 'rtf': | |
| 640 | + return 'application/rtf'; | |
| 641 | + case 'rtx': | |
| 642 | + return 'text/richtext'; | |
| 643 | + case 'rv': | |
| 644 | + return 'video/vnd.rn-realvideo'; | |
| 645 | + case 's': | |
| 646 | + return 'text/x-asm'; | |
| 647 | + case 's3m': | |
| 648 | + return 'audio/s3m'; | |
| 649 | + case 'saveme': | |
| 650 | + return 'application/octet-stream'; | |
| 651 | + case 'sbk': | |
| 652 | + return 'application/x-tbook'; | |
| 653 | + case 'scm': | |
| 654 | + return 'application/x-lotusscreencam'; | |
| 655 | + case 'sdml': | |
| 656 | + return 'text/plain'; | |
| 657 | + case 'sdp': | |
| 658 | + return 'application/sdp'; | |
| 659 | + case 'sdr': | |
| 660 | + return 'application/sounder'; | |
| 661 | + case 'sea': | |
| 662 | + return 'application/sea'; | |
| 663 | + case 'set': | |
| 664 | + return 'application/set'; | |
| 665 | + case 'sgm': | |
| 666 | + return 'text/sgml'; | |
| 667 | + case 'sgml': | |
| 668 | + return 'text/sgml'; | |
| 669 | + case 'sh': | |
| 670 | + return 'application/x-bsh'; | |
| 671 | + case 'shar': | |
| 672 | + return 'application/x-bsh'; | |
| 673 | + case 'shtml': | |
| 674 | + return 'text/html'; | |
| 675 | + case 'sid': | |
| 676 | + return 'audio/x-psid'; | |
| 677 | + case 'sit': | |
| 678 | + return 'application/x-sit'; | |
| 679 | + case 'skd': | |
| 680 | + return 'application/x-koan'; | |
| 681 | + case 'skm': | |
| 682 | + return 'application/x-koan'; | |
| 683 | + case 'skp': | |
| 684 | + return 'application/x-koan'; | |
| 685 | + case 'skt': | |
| 686 | + return 'application/x-koan'; | |
| 687 | + case 'sl': | |
| 688 | + return 'application/x-seelogo'; | |
| 689 | + case 'smi': | |
| 690 | + return 'application/smil'; | |
| 691 | + case 'smil': | |
| 692 | + return 'application/smil'; | |
| 693 | + case 'snd': | |
| 694 | + return 'audio/basic'; | |
| 695 | + case 'sol': | |
| 696 | + return 'application/solids'; | |
| 697 | + case 'spc': | |
| 698 | + return 'application/x-pkcs7-certificates'; | |
| 699 | + case 'spl': | |
| 700 | + return 'application/futuresplash'; | |
| 701 | + case 'spr': | |
| 702 | + return 'application/x-sprite'; | |
| 703 | + case 'sprite': | |
| 704 | + return 'application/x-sprite'; | |
| 705 | + case 'src': | |
| 706 | + return 'application/x-wais-source'; | |
| 707 | + case 'ssi': | |
| 708 | + return 'text/x-server-parsed-html'; | |
| 709 | + case 'ssm': | |
| 710 | + return 'application/streamingmedia'; | |
| 711 | + case 'sst': | |
| 712 | + return 'application/vnd.ms-pki.certstore'; | |
| 713 | + case 'step': | |
| 714 | + return 'application/step'; | |
| 715 | + case 'stl': | |
| 716 | + return 'application/sla'; | |
| 717 | + case 'stp': | |
| 718 | + return 'application/step'; | |
| 719 | + case 'sv4cpio': | |
| 720 | + return 'application/x-sv4cpio'; | |
| 721 | + case 'sv4crc': | |
| 722 | + return 'application/x-sv4crc'; | |
| 723 | + case 'svf': | |
| 724 | + return 'image/vnd.dwg'; | |
| 725 | + case 'svr': | |
| 726 | + return 'application/x-world'; | |
| 727 | + case 'swf': | |
| 728 | + return 'application/x-shockwave-flash'; | |
| 729 | + case 't': | |
| 730 | + return 'application/x-troff'; | |
| 731 | + case 'talk': | |
| 732 | + return 'text/x-speech'; | |
| 733 | + case 'tar': | |
| 734 | + return 'application/x-tar'; | |
| 735 | + case 'tbk': | |
| 736 | + return 'application/toolbook'; | |
| 737 | + case 'tcl': | |
| 738 | + return 'application/x-tcl'; | |
| 739 | + case 'tcsh': | |
| 740 | + return 'text/x-script.tcsh'; | |
| 741 | + case 'tex': | |
| 742 | + return 'application/x-tex'; | |
| 743 | + case 'texi': | |
| 744 | + return 'application/x-texinfo'; | |
| 745 | + case 'texinfo': | |
| 746 | + return 'application/x-texinfo'; | |
| 747 | + case 'text': | |
| 748 | + return 'text/plain'; | |
| 749 | + case 'tgz': | |
| 750 | + return 'application/x-compressed'; | |
| 751 | + case 'tif': | |
| 752 | + return 'image/tiff'; | |
| 753 | + case 'tiff': | |
| 754 | + return 'image/tiff'; | |
| 755 | + case 'tr': | |
| 756 | + return 'application/x-troff'; | |
| 757 | + case 'tsi': | |
| 758 | + return 'audio/tsp-audio'; | |
| 759 | + case 'tsp': | |
| 760 | + return 'application/dsptype'; | |
| 761 | + case 'tsv': | |
| 762 | + return 'text/tab-separated-values'; | |
| 763 | + case 'turbot': | |
| 764 | + return 'image/florian'; | |
| 765 | + case 'txt': | |
| 766 | + return 'text/plain'; | |
| 767 | + case 'uil': | |
| 768 | + return 'text/x-uil'; | |
| 769 | + case 'uni': | |
| 770 | + return 'text/uri-list'; | |
| 771 | + case 'unis': | |
| 772 | + return 'text/uri-list'; | |
| 773 | + case 'unv': | |
| 774 | + return 'application/i-deas'; | |
| 775 | + case 'uri': | |
| 776 | + return 'text/uri-list'; | |
| 777 | + case 'uris': | |
| 778 | + return 'text/uri-list'; | |
| 779 | + case 'ustar': | |
| 780 | + return 'multipart/x-ustar'; | |
| 781 | + case 'uu': | |
| 782 | + return 'application/octet-stream'; | |
| 783 | + case 'uue': | |
| 784 | + return 'text/x-uuencode'; | |
| 785 | + case 'vcd': | |
| 786 | + return 'application/x-cdlink'; | |
| 787 | + case 'vcs': | |
| 788 | + return 'text/x-vcalendar'; | |
| 789 | + case 'vda': | |
| 790 | + return 'application/vda'; | |
| 791 | + case 'vdo': | |
| 792 | + return 'video/vdo'; | |
| 793 | + case 'vew': | |
| 794 | + return 'application/groupwise'; | |
| 795 | + case 'viv': | |
| 796 | + return 'video/vivo'; | |
| 797 | + case 'vivo': | |
| 798 | + return 'video/vivo'; | |
| 799 | + case 'vmd': | |
| 800 | + return 'application/vocaltec-media-desc'; | |
| 801 | + case 'vmf': | |
| 802 | + return 'application/vocaltec-media-file'; | |
| 803 | + case 'voc': | |
| 804 | + return 'audio/voc'; | |
| 805 | + case 'vos': | |
| 806 | + return 'video/vosaic'; | |
| 807 | + case 'vox': | |
| 808 | + return 'audio/voxware'; | |
| 809 | + case 'vqe': | |
| 810 | + return 'audio/x-twinvq-plugin'; | |
| 811 | + case 'vqf': | |
| 812 | + return 'audio/x-twinvq'; | |
| 813 | + case 'vql': | |
| 814 | + return 'audio/x-twinvq-plugin'; | |
| 815 | + case 'vrml': | |
| 816 | + return 'application/x-vrml'; | |
| 817 | + case 'vrt': | |
| 818 | + return 'x-world/x-vrt'; | |
| 819 | + case 'vsd': | |
| 820 | + return 'application/x-visio'; | |
| 821 | + case 'vst': | |
| 822 | + return 'application/x-visio'; | |
| 823 | + case 'vsw': | |
| 824 | + return 'application/x-visio'; | |
| 825 | + case 'w60': | |
| 826 | + return 'application/wordperfect6.0'; | |
| 827 | + case 'w61': | |
| 828 | + return 'application/wordperfect6.1'; | |
| 829 | + case 'w6w': | |
| 830 | + return 'application/msword'; | |
| 831 | + case 'wav': | |
| 832 | + return 'audio/wav'; | |
| 833 | + case 'wb1': | |
| 834 | + return 'application/x-qpro'; | |
| 835 | + case 'wbmp': | |
| 836 | + return 'image/vnd.wap.wbmp'; | |
| 837 | + case 'web': | |
| 838 | + return 'application/vnd.xara'; | |
| 839 | + case 'wiz': | |
| 840 | + return 'application/msword'; | |
| 841 | + case 'wk1': | |
| 842 | + return 'application/x-123'; | |
| 843 | + case 'wmf': | |
| 844 | + return 'windows/metafile'; | |
| 845 | + case 'wml': | |
| 846 | + return 'text/vnd.wap.wml'; | |
| 847 | + case 'wmlc': | |
| 848 | + return 'application/vnd.wap.wmlc'; | |
| 849 | + case 'wmls': | |
| 850 | + return 'text/vnd.wap.wmlscript'; | |
| 851 | + case 'wmlsc': | |
| 852 | + return 'application/vnd.wap.wmlscriptc'; | |
| 853 | + case 'word': | |
| 854 | + return 'application/msword'; | |
| 855 | + case 'wp': | |
| 856 | + return 'application/wordperfect'; | |
| 857 | + case 'wp5': | |
| 858 | + return 'application/wordperfect6.0'; | |
| 859 | + case 'wp6': | |
| 860 | + return 'application/wordperfect'; | |
| 861 | + case 'wpd': | |
| 862 | + return 'application/x-wpwin'; | |
| 863 | + case 'wq1': | |
| 864 | + return 'application/x-lotus'; | |
| 865 | + case 'wri': | |
| 866 | + return 'application/mswrite'; | |
| 867 | + case 'wrl': | |
| 868 | + return 'model/vrml'; | |
| 869 | + case 'wrz': | |
| 870 | + return 'model/vrml'; | |
| 871 | + case 'wsc': | |
| 872 | + return 'text/scriplet'; | |
| 873 | + case 'wsrc': | |
| 874 | + return 'application/x-wais-source'; | |
| 875 | + case 'wtk': | |
| 876 | + return 'application/x-wintalk'; | |
| 877 | + case 'xbm': | |
| 878 | + return 'image/x-xbitmap'; | |
| 879 | + case 'xdr': | |
| 880 | + return 'video/x-amt-demorun'; | |
| 881 | + case 'xgz': | |
| 882 | + return 'xgl/drawing'; | |
| 883 | + case 'xif': | |
| 884 | + return 'image/vnd.xiff'; | |
| 885 | + case 'xl': | |
| 886 | + return 'application/excel'; | |
| 887 | + case 'xla': | |
| 888 | + return 'application/excel'; | |
| 889 | + case 'xlb': | |
| 890 | + return 'application/excel'; | |
| 891 | + case 'xlc': | |
| 892 | + return 'application/excel'; | |
| 893 | + case 'xld': | |
| 894 | + return 'application/excel'; | |
| 895 | + case 'xlk': | |
| 896 | + return 'application/excel'; | |
| 897 | + case 'xll': | |
| 898 | + return 'application/excel'; | |
| 899 | + case 'xlm': | |
| 900 | + return 'application/excel'; | |
| 901 | + case 'xls': | |
| 902 | + return 'application/excel'; | |
| 903 | + case 'xlt': | |
| 904 | + return 'application/excel'; | |
| 905 | + case 'xlv': | |
| 906 | + return 'application/excel'; | |
| 907 | + case 'xlw': | |
| 908 | + return 'application/excel'; | |
| 909 | + case 'xm': | |
| 910 | + return 'audio/xm'; | |
| 911 | + case 'xml': | |
| 912 | + return 'application/xml'; | |
| 913 | + case 'xmz': | |
| 914 | + return 'xgl/movie'; | |
| 915 | + case 'xpix': | |
| 916 | + return 'application/x-vnd.ls-xpix'; | |
| 917 | + case 'xpm': | |
| 918 | + return 'image/xpm'; | |
| 919 | + case 'x-png': | |
| 920 | + return 'image/png'; | |
| 921 | + case 'xsr': | |
| 922 | + return 'video/x-amt-showrun'; | |
| 923 | + case 'xwd': | |
| 924 | + return 'image/x-xwd'; | |
| 925 | + case 'xyz': | |
| 926 | + return 'chemical/x-pdb'; | |
| 927 | + case 'z': | |
| 928 | + return 'application/x-compress'; | |
| 929 | + case 'zip': | |
| 930 | + return 'application/x-compressed'; | |
| 931 | + case 'zoo': | |
| 932 | + return 'application/octet-stream'; | |
| 933 | + case 'zsh': | |
| 934 | + return 'text/x-script.zsh'; | |
| 935 | + default: | |
| 936 | + return 'application/octet-stream'; | |
| 937 | + } | |
| 938 | +} | |
| 939 | +?> | |
| 0 | 940 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Reader/Multi.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Regroups several readers to make them appear as a single one | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: Multi.php,v 1.10 2005/05/26 21:30:18 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "File/Archive/Reader/Relay.php"; | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * Regroups several readers to make them appear as a single one | |
| 36 | + */ | |
| 37 | +class File_Archive_Reader_Multi extends File_Archive_Reader_Relay | |
| 38 | +{ | |
| 39 | + /** | |
| 40 | + * @var Array All the sources regrouped in this reader | |
| 41 | + * @access private | |
| 42 | + */ | |
| 43 | + var $sources = array(); | |
| 44 | + /** | |
| 45 | + * @var Int Index of the source being read currently | |
| 46 | + * @access private | |
| 47 | + */ | |
| 48 | + var $currentIndex = 0; | |
| 49 | + | |
| 50 | + function File_Archive_Reader_Multi() | |
| 51 | + { | |
| 52 | + parent::File_Archive_Reader_Relay($tmp = null); | |
| 53 | + } | |
| 54 | + | |
| 55 | + /** | |
| 56 | + * Add a new reader to the list of readers | |
| 57 | + * @param File_Archive_Reader $source The source to add | |
| 58 | + */ | |
| 59 | + function addSource(&$source) | |
| 60 | + { | |
| 61 | + $this->sources[] =& $source; | |
| 62 | + } | |
| 63 | + | |
| 64 | + /** | |
| 65 | + * @see File_Archive_Reader::next() | |
| 66 | + */ | |
| 67 | + function next() | |
| 68 | + { | |
| 69 | + while (array_key_exists($this->currentIndex, $this->sources)) { | |
| 70 | + $this->source =& $this->sources[$this->currentIndex]; | |
| 71 | + | |
| 72 | + if (($error = $this->source->next()) === false) { | |
| 73 | + $error = $this->source->close(); | |
| 74 | + if (PEAR::isError($error)) { | |
| 75 | + return $error; | |
| 76 | + } | |
| 77 | + $this->currentIndex++; | |
| 78 | + } else { | |
| 79 | + return $error; | |
| 80 | + } | |
| 81 | + } | |
| 82 | + return false; | |
| 83 | + } | |
| 84 | + /** | |
| 85 | + * @see File_Archive_Reader::close() | |
| 86 | + */ | |
| 87 | + function close() | |
| 88 | + { | |
| 89 | + $error = parent::close(); | |
| 90 | + $this->currentIndex = 0; | |
| 91 | + return $error; | |
| 92 | + } | |
| 93 | +} | |
| 94 | + | |
| 95 | +?> | |
| 0 | 96 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Reader/Relay.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * A reader that appears exactly as another does | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: Relay.php,v 1.19 2005/07/09 12:54:35 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "File/Archive/Reader.php"; | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * This reader appear exactly as $source does | |
| 36 | + * This is usefull if you want to dynamically change $source or change | |
| 37 | + * its behaviour | |
| 38 | + */ | |
| 39 | +class File_Archive_Reader_Relay extends File_Archive_Reader | |
| 40 | +{ | |
| 41 | + /** | |
| 42 | + * @var File_Archive_Reader This reader will have the same comportment as | |
| 43 | + * $source | |
| 44 | + * @access protected | |
| 45 | + */ | |
| 46 | + var $source; | |
| 47 | + | |
| 48 | + function File_Archive_Reader_Relay(&$source) | |
| 49 | + { | |
| 50 | + $this->source =& $source; | |
| 51 | + } | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * @see File_Archive_Reader::next() | |
| 55 | + */ | |
| 56 | + function next() { return $this->source->next(); } | |
| 57 | + /** | |
| 58 | + * @see File_Archive_Reader::getFilename() | |
| 59 | + */ | |
| 60 | + function getFilename() { return $this->source->getFilename(); } | |
| 61 | + /** | |
| 62 | + * @see File_Archive_Reader::getStat() | |
| 63 | + */ | |
| 64 | + function getStat() { return $this->source->getStat(); } | |
| 65 | + /** | |
| 66 | + * @see File_Archive_Reader::getMime() | |
| 67 | + */ | |
| 68 | + function getMime() { return $this->source->getMime(); } | |
| 69 | + /** | |
| 70 | + * @see File_Archive_Reader::getDataFilename() | |
| 71 | + */ | |
| 72 | + function getDataFilename() { return $this->source->getDataFilename(); } | |
| 73 | + /** | |
| 74 | + * @see File_Archive_Reader::getData() | |
| 75 | + */ | |
| 76 | + function getData($length = -1) { return $this->source->getData($length); } | |
| 77 | + /** | |
| 78 | + * @see File_Archive_Reader::skip() | |
| 79 | + */ | |
| 80 | + function skip($length = -1) { return $this->source->skip($length); } | |
| 81 | + /** | |
| 82 | + * @see File_Archive_Reader::rewind() | |
| 83 | + */ | |
| 84 | + function rewind($length = -1) { return $this->source->rewind($length); } | |
| 85 | + /** | |
| 86 | + * @see File_Archive_Reader::tell() | |
| 87 | + */ | |
| 88 | + function tell() { return $this->source->tell(); } | |
| 89 | + | |
| 90 | + /** | |
| 91 | + * @see File_Archive_Reader::close() | |
| 92 | + */ | |
| 93 | + function close() | |
| 94 | + { | |
| 95 | + if ($this->source !== null) { | |
| 96 | + return $this->source->close(); | |
| 97 | + } | |
| 98 | + } | |
| 99 | + /** | |
| 100 | + * @see File_Archive_Reader::makeAppendWriter() | |
| 101 | + */ | |
| 102 | + function makeAppendWriter() | |
| 103 | + { | |
| 104 | + $writer = $this->source->makeAppendWriter(); | |
| 105 | + if (!PEAR::isError($writer)) { | |
| 106 | + $this->close(); | |
| 107 | + } | |
| 108 | + return $writer; | |
| 109 | + } | |
| 110 | + /** | |
| 111 | + * @see File_Archive_Reader::makeWriterRemoveFiles() | |
| 112 | + */ | |
| 113 | + function makeWriterRemoveFiles($pred) | |
| 114 | + { | |
| 115 | + $writer = $this->source->makeWriterRemoveFiles($pred); | |
| 116 | + if (!PEAR::isError($writer)) { | |
| 117 | + $this->close(); | |
| 118 | + } | |
| 119 | + return $writer; | |
| 120 | + } | |
| 121 | + /** | |
| 122 | + * @see File_Archive_Reader::makeWriterRemoveBlocks() | |
| 123 | + */ | |
| 124 | + function makeWriterRemoveBlocks($blocks, $seek = 0) | |
| 125 | + { | |
| 126 | + $writer = $this->source->makeWriterRemoveBlocks($blocks, $seek); | |
| 127 | + if (!PEAR::isError($writer)) { | |
| 128 | + $this->close(); | |
| 129 | + } | |
| 130 | + return $writer; | |
| 131 | + } | |
| 132 | +} | |
| 133 | + | |
| 134 | +?> | |
| 0 | 135 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Reader/Select.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Reader that keeps the files selected by File_Archive::select function | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: Select.php,v 1.3 2005/05/26 21:30:18 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "File/Archive/Reader/Relay.php"; | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * Reader that keeps the files selected by File_Archive::select function | |
| 36 | + */ | |
| 37 | +class File_Archive_Reader_Select extends File_Archive_Reader_Relay | |
| 38 | +{ | |
| 39 | + /** | |
| 40 | + * @var File_Archive_Reader_Predicat | |
| 41 | + * @access private | |
| 42 | + */ | |
| 43 | + var $filename; | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * $source is the reader to filter | |
| 47 | + */ | |
| 48 | + function File_Archive_Reader_Select($filename, &$source) | |
| 49 | + { | |
| 50 | + parent::File_Archive_Reader_Relay($source); | |
| 51 | + $this->filename = $filename; | |
| 52 | + } | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * @see File_Archive_Reader::next() | |
| 56 | + */ | |
| 57 | + function next() | |
| 58 | + { | |
| 59 | + return $this->source->select($this->filename, false); | |
| 60 | + } | |
| 61 | +} | |
| 62 | + | |
| 63 | +?> | |
| 0 | 64 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Reader/Tar.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Read a tar archive | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: Tar.php,v 1.29 2005/07/11 11:53:53 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "File/Archive/Reader/Archive.php"; | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * Read a tar archive | |
| 36 | + */ | |
| 37 | +class File_Archive_Reader_Tar extends File_Archive_Reader_Archive | |
| 38 | +{ | |
| 39 | + /** | |
| 40 | + * @var String Name of the file being read | |
| 41 | + * @access private | |
| 42 | + */ | |
| 43 | + var $currentFilename = null; | |
| 44 | + /** | |
| 45 | + * @var Array Stats of the file being read | |
| 46 | + * In TAR reader, indexes 2, 4, 5, 7, 9 are set | |
| 47 | + * @access private | |
| 48 | + */ | |
| 49 | + var $currentStat = null; | |
| 50 | + /** | |
| 51 | + * @var int Number of bytes that still have to be read before the end of | |
| 52 | + * file | |
| 53 | + * @access private | |
| 54 | + */ | |
| 55 | + var $leftLength = 0; | |
| 56 | + /** | |
| 57 | + * @var int Size of the footer | |
| 58 | + * A TAR file is made of chunks of 512 bytes. If 512 does not | |
| 59 | + * divide the file size a footer is added | |
| 60 | + * @access private | |
| 61 | + */ | |
| 62 | + var $footerLength = 0; | |
| 63 | + /** | |
| 64 | + * @var int nb bytes to seek back in order to reach the end of the archive | |
| 65 | + * or null if the end of the archive has not been reached | |
| 66 | + */ | |
| 67 | + var $seekToEnd = null; | |
| 68 | + | |
| 69 | + /** | |
| 70 | + * @see File_Archive_Reader::skip() | |
| 71 | + */ | |
| 72 | + function skip($length = -1) | |
| 73 | + { | |
| 74 | + if ($length == -1) { | |
| 75 | + $length = $this->leftLength; | |
| 76 | + } else { | |
| 77 | + $length = min($this->leftLength, $length); | |
| 78 | + } | |
| 79 | + $skipped = $this->source->skip($length); | |
| 80 | + if (!PEAR::isError($skipped)) { | |
| 81 | + $this->leftLength -= $skipped; | |
| 82 | + } | |
| 83 | + return $skipped; | |
| 84 | + } | |
| 85 | + | |
| 86 | + /** | |
| 87 | + * @see File_Archive_Reader::rewind() | |
| 88 | + */ | |
| 89 | + function rewind($length = -1) | |
| 90 | + { | |
| 91 | + if ($length == -1) { | |
| 92 | + $length = $this->currentStat[7] - $this->leftLength; | |
| 93 | + } else { | |
| 94 | + $length = min($length, $this->currentStat[7] - $this->leftLength); | |
| 95 | + } | |
| 96 | + $rewinded = $this->source->rewind($length); | |
| 97 | + if (!PEAR::isError($rewinded)) { | |
| 98 | + $this->leftLength += $rewinded; | |
| 99 | + } | |
| 100 | + return $rewinded; | |
| 101 | + } | |
| 102 | + | |
| 103 | + /** | |
| 104 | + * @see File_Archive_Reader::tell() | |
| 105 | + */ | |
| 106 | + function tell() | |
| 107 | + { | |
| 108 | + return $this->currentStat[7] - $this->leftLength; | |
| 109 | + } | |
| 110 | + | |
| 111 | + /** | |
| 112 | + * @see File_Archive_Reader::close() | |
| 113 | + */ | |
| 114 | + function close() | |
| 115 | + { | |
| 116 | + $this->leftLength = 0; | |
| 117 | + $this->currentFilename = null; | |
| 118 | + $this->currentStat = null; | |
| 119 | + $this->seekToEnd = null; | |
| 120 | + return parent::close(); | |
| 121 | + } | |
| 122 | + | |
| 123 | + /** | |
| 124 | + * @see File_Archive_Reader::getFilename() | |
| 125 | + */ | |
| 126 | + function getFilename() { return $this->currentFilename; } | |
| 127 | + /** | |
| 128 | + * @see File_Archive_Reader::getStat() | |
| 129 | + */ | |
| 130 | + function getStat() { return $this->currentStat; } | |
| 131 | + | |
| 132 | + /** | |
| 133 | + * @see File_Archive_Reader::next() | |
| 134 | + */ | |
| 135 | + function next() | |
| 136 | + { | |
| 137 | + $error = parent::next(); | |
| 138 | + if ($error !== true) { | |
| 139 | + return $error; | |
| 140 | + } | |
| 141 | + if ($this->seekToEnd !== null) { | |
| 142 | + return false; | |
| 143 | + } | |
| 144 | + | |
| 145 | + do | |
| 146 | + { | |
| 147 | + $error = $this->source->skip($this->leftLength + $this->footerLength); | |
| 148 | + if (PEAR::isError($error)) { | |
| 149 | + return $error; | |
| 150 | + } | |
| 151 | + $rawHeader = $this->source->getData(512); | |
| 152 | + if (PEAR::isError($rawHeader)) { | |
| 153 | + return $rawHeader; | |
| 154 | + } | |
| 155 | + if (strlen($rawHeader)<512 || $rawHeader == pack("a512", "")) { | |
| 156 | + $this->seekToEnd = strlen($rawHeader); | |
| 157 | + $this->currentFilename = null; | |
| 158 | + return false; | |
| 159 | + } | |
| 160 | + | |
| 161 | + $header = unpack( | |
| 162 | + "a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/". | |
| 163 | + "a8checksum/a1type/a100linkname/a6magic/a2version/". | |
| 164 | + "a32uname/a32gname/a8devmajor/a8devminor/a155prefix", | |
| 165 | + $rawHeader); | |
| 166 | + $this->currentStat = array( | |
| 167 | + 2 => octdec($header['mode']), | |
| 168 | + 4 => octdec($header['uid']), | |
| 169 | + 5 => octdec($header['gid']), | |
| 170 | + 7 => octdec($header['size']), | |
| 171 | + 9 => octdec($header['mtime']) | |
| 172 | + ); | |
| 173 | + $this->currentStat['mode'] = $this->currentStat[2]; | |
| 174 | + $this->currentStat['uid'] = $this->currentStat[4]; | |
| 175 | + $this->currentStat['gid'] = $this->currentStat[5]; | |
| 176 | + $this->currentStat['size'] = $this->currentStat[7]; | |
| 177 | + $this->currentStat['mtime'] = $this->currentStat[9]; | |
| 178 | + | |
| 179 | + if ($header['magic'] == 'ustar') { | |
| 180 | + $this->currentFilename = $this->getStandardURL( | |
| 181 | + $header['prefix'] . $header['filename'] | |
| 182 | + ); | |
| 183 | + } else { | |
| 184 | + $this->currentFilename = $this->getStandardURL( | |
| 185 | + $header['filename'] | |
| 186 | + ); | |
| 187 | + } | |
| 188 | + | |
| 189 | + $this->leftLength = $this->currentStat[7]; | |
| 190 | + if ($this->leftLength % 512 == 0) { | |
| 191 | + $this->footerLength = 0; | |
| 192 | + } else { | |
| 193 | + $this->footerLength = 512 - $this->leftLength%512; | |
| 194 | + } | |
| 195 | + | |
| 196 | + $checksum = 8*ord(" "); | |
| 197 | + for ($i = 0; $i < 148; $i++) { | |
| 198 | + $checksum += ord($rawHeader{$i}); | |
| 199 | + } | |
| 200 | + for ($i = 156; $i < 512; $i++) { | |
| 201 | + $checksum += ord($rawHeader{$i}); | |
| 202 | + } | |
| 203 | + | |
| 204 | + if (octdec($header['checksum']) != $checksum) { | |
| 205 | + die('Checksum error on entry '.$this->currentFilename); | |
| 206 | + } | |
| 207 | + } while ($header['type'] != 0); | |
| 208 | + | |
| 209 | + return true; | |
| 210 | + } | |
| 211 | + | |
| 212 | + /** | |
| 213 | + * @see File_Archive_Reader::getData() | |
| 214 | + */ | |
| 215 | + function getData($length = -1) | |
| 216 | + { | |
| 217 | + if ($length == -1) { | |
| 218 | + $actualLength = $this->leftLength; | |
| 219 | + } else { | |
| 220 | + $actualLength = min($this->leftLength, $length); | |
| 221 | + } | |
| 222 | + | |
| 223 | + if ($this->leftLength == 0) { | |
| 224 | + return null; | |
| 225 | + } else { | |
| 226 | + $data = $this->source->getData($actualLength); | |
| 227 | + if (strlen($data) != $actualLength) { | |
| 228 | + return PEAR::raiseError('Unexpected end of tar archive'); | |
| 229 | + } | |
| 230 | + $this->leftLength -= $actualLength; | |
| 231 | + return $data; | |
| 232 | + } | |
| 233 | + } | |
| 234 | + | |
| 235 | + /** | |
| 236 | + * @see File_Archive_Reader::makeWriterRemoveFiles() | |
| 237 | + */ | |
| 238 | + function makeWriterRemoveFiles($pred) | |
| 239 | + { | |
| 240 | + require_once "File/Archive/Writer/Tar.php"; | |
| 241 | + | |
| 242 | + $blocks = array(); | |
| 243 | + $seek = null; | |
| 244 | + $gap = 0; | |
| 245 | + if ($this->currentFilename !== null && $pred->isTrue($this)) { | |
| 246 | + $seek = 512 + $this->currentStat[7] + $this->footerLength; | |
| 247 | + $blocks[] = $seek; //Remove this file | |
| 248 | + } | |
| 249 | + | |
| 250 | + while (($error = $this->next()) === true) { | |
| 251 | + $size = 512 + $this->currentStat[7] + $this->footerLength; | |
| 252 | + if ($pred->isTrue($this)) { | |
| 253 | + if ($seek === null) { | |
| 254 | + $seek = $size; | |
| 255 | + $blocks[] = $size; | |
| 256 | + } else if ($gap > 0) { | |
| 257 | + $blocks[] = $gap; //Don't remove the files between the gap | |
| 258 | + $blocks[] = $size; | |
| 259 | + $seek += $size; | |
| 260 | + } else { | |
| 261 | + $blocks[count($blocks)-1] += $size; //Also remove this file | |
| 262 | + $seek += $size; | |
| 263 | + } | |
| 264 | + $gap = 0; | |
| 265 | + } else { | |
| 266 | + if ($seek !== null) { | |
| 267 | + $seek += $size; | |
| 268 | + $gap += $size; | |
| 269 | + } | |
| 270 | + } | |
| 271 | + } | |
| 272 | + if ($seek === null) { | |
| 273 | + $seek = $this->seekToEnd; | |
| 274 | + } else { | |
| 275 | + $seek += $this->seekToEnd; | |
| 276 | + if ($gap == 0) { | |
| 277 | + array_pop($blocks); | |
| 278 | + } else { | |
| 279 | + $blocks[] = $gap; | |
| 280 | + } | |
| 281 | + } | |
| 282 | + | |
| 283 | + $writer = new File_Archive_Writer_Tar(null, | |
| 284 | + $this->source->makeWriterRemoveBlocks($blocks, -$seek) | |
| 285 | + ); | |
| 286 | + $this->close(); | |
| 287 | + return $writer; | |
| 288 | + } | |
| 289 | + | |
| 290 | + /** | |
| 291 | + * @see File_Archive_Reader::makeWriterRemoveBlocks() | |
| 292 | + */ | |
| 293 | + function makeWriterRemoveBlocks($blocks, $seek = 0) | |
| 294 | + { | |
| 295 | + if ($this->seekToEnd !== null || $this->currentStat === null) { | |
| 296 | + return PEAR::raiseError('No file selected'); | |
| 297 | + } | |
| 298 | + | |
| 299 | + $blockPos = $this->currentStat[7] - $this->leftLength + $seek; | |
| 300 | + | |
| 301 | + $this->rewind(); | |
| 302 | + $keep = false; | |
| 303 | + | |
| 304 | + $data = $this->getData($blockPos); | |
| 305 | + foreach ($blocks as $length) { | |
| 306 | + if ($keep) { | |
| 307 | + $data .= $this->getData($length); | |
| 308 | + } else { | |
| 309 | + $this->skip($length); | |
| 310 | + } | |
| 311 | + $keep = !$keep; | |
| 312 | + } | |
| 313 | + if ($keep) { | |
| 314 | + $data .= $this->getData(); | |
| 315 | + } | |
| 316 | + | |
| 317 | + $filename = $this->currentFilename; | |
| 318 | + $stat = $this->currentStat; | |
| 319 | + | |
| 320 | + $writer = $this->makeWriterRemove(); | |
| 321 | + if (PEAR::isError($writer)) { | |
| 322 | + return $writer; | |
| 323 | + } | |
| 324 | + | |
| 325 | + unset($stat[7]); | |
| 326 | + $stat[9] = $stat['mtime'] = time(); | |
| 327 | + $writer->newFile($filename, $stat); | |
| 328 | + $writer->writeData($data); | |
| 329 | + return $writer; | |
| 330 | + } | |
| 331 | + | |
| 332 | + /** | |
| 333 | + * @see File_Archive_Reader::makeAppendWriter | |
| 334 | + */ | |
| 335 | + function makeAppendWriter() | |
| 336 | + { | |
| 337 | + require_once "File/Archive/Writer/Tar.php"; | |
| 338 | + | |
| 339 | + while (($error = $this->next()) === true) { } | |
| 340 | + if (PEAR::isError($error)) { | |
| 341 | + $this->close(); | |
| 342 | + return $error; | |
| 343 | + } | |
| 344 | + | |
| 345 | + $innerWriter = $this->source->makeWriterRemoveBlocks(array(), -$this->seekToEnd); | |
| 346 | + if (PEAR::isError($innerWriter)) { | |
| 347 | + return $innerWriter; | |
| 348 | + } | |
| 349 | + | |
| 350 | + $this->close(); | |
| 351 | + return new File_Archive_Writer_Tar(null, $innerWriter); | |
| 352 | + } | |
| 353 | +} | |
| 354 | + | |
| 355 | +?> | |
| 0 | 356 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Reader/Uncompress.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Recursively uncompress every file it finds | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: Uncompress.php,v 1.32 2005/07/09 12:54:35 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "File/Archive/Reader.php"; | |
| 33 | +require_once "File/Archive/Reader/ChangeName.php"; | |
| 34 | + | |
| 35 | +/** | |
| 36 | + * Recursively uncompress every file it finds | |
| 37 | + */ | |
| 38 | +class File_Archive_Reader_Uncompress extends File_Archive_Reader_Relay | |
| 39 | +{ | |
| 40 | + /** | |
| 41 | + * @var Array Stack of readers | |
| 42 | + * @access private | |
| 43 | + */ | |
| 44 | + var $readers = array(); | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * @var array of readers to close when closing $this | |
| 48 | + * @access private | |
| 49 | + */ | |
| 50 | + var $toClose = array(); | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * @var File_Archive_Reader Reader from which all started (usefull to be | |
| 54 | + * able to close) | |
| 55 | + * @access private | |
| 56 | + */ | |
| 57 | + var $startReader; | |
| 58 | + | |
| 59 | + /** | |
| 60 | + * @var Int Maximum depth of uncompression after the basicDir | |
| 61 | + * (that may contain some uncompression also) | |
| 62 | + * -1 means no limit | |
| 63 | + * @access private | |
| 64 | + */ | |
| 65 | + var $uncompressionLevel; | |
| 66 | + | |
| 67 | + /** | |
| 68 | + * @var array Only files starting with $baseDir will be reported | |
| 69 | + * This array contains explode('/', $directoryName) | |
| 70 | + * @access private | |
| 71 | + */ | |
| 72 | + var $baseDir = ''; | |
| 73 | + | |
| 74 | + /** | |
| 75 | + * @var int Compression level required to go to reach the baseDir | |
| 76 | + * or null if it is currently being computed | |
| 77 | + * @access private | |
| 78 | + */ | |
| 79 | + var $baseDirCompressionLevel = null; | |
| 80 | + | |
| 81 | + /** | |
| 82 | + * @var int We are selecting substr($baseDir, 0, $baseDirProgression) | |
| 83 | + */ | |
| 84 | + var $baseDirProgression = 0; | |
| 85 | + | |
| 86 | + /** | |
| 87 | + * @var boolean Flag set to indicate that the current file has not been | |
| 88 | + * displayed | |
| 89 | + */ | |
| 90 | + var $currentFileNotDisplayed = false; | |
| 91 | + | |
| 92 | + function File_Archive_Reader_Uncompress( | |
| 93 | + &$innerReader, $uncompressionLevel = -1) | |
| 94 | + { | |
| 95 | + parent::File_Archive_Reader_Relay($innerReader); | |
| 96 | + $this->startReader =& $innerReader; | |
| 97 | + $this->uncompressionLevel = $uncompressionLevel; | |
| 98 | + } | |
| 99 | + | |
| 100 | + /** | |
| 101 | + * Attempt to change the current source (if the current file is an archive) | |
| 102 | + * If this is the case, push the current source onto the stack and make the | |
| 103 | + * good archive reader the current source. A file is considered as an | |
| 104 | + * archive if its extension is one of tar, gz, zip, tgz | |
| 105 | + * | |
| 106 | + * @return bool whether the source has been pushed or not | |
| 107 | + * @access private | |
| 108 | + */ | |
| 109 | + function push() | |
| 110 | + { | |
| 111 | + if ($this->uncompressionLevel >= 0 && | |
| 112 | + $this->baseDirCompressionLevel !== null && | |
| 113 | + count($this->readers) >= $this->uncompressionLevel | |
| 114 | + ) { | |
| 115 | + return false; | |
| 116 | + } | |
| 117 | + | |
| 118 | + // Check the extension of the file (maybe we need to uncompress it?) | |
| 119 | + $filename = $this->source->getFilename(); | |
| 120 | + | |
| 121 | + $extensions = explode('.', strtolower($filename)); | |
| 122 | + | |
| 123 | + $reader =& $this->source; | |
| 124 | + $nbUncompressions = 0; | |
| 125 | + | |
| 126 | + while (($extension = array_pop($extensions)) !== null) { | |
| 127 | + $nbUncompressions++; | |
| 128 | + unset($next); | |
| 129 | + $next = File_Archive::readArchive($extension, $reader, $nbUncompressions == 1); | |
| 130 | + if ($next === false) { | |
| 131 | + $extensions = array(); | |
| 132 | + } else { | |
| 133 | + unset($reader); | |
| 134 | + $reader =& $next; | |
| 135 | + } | |
| 136 | + } | |
| 137 | + if ($nbUncompressions == 1) { | |
| 138 | + return false; | |
| 139 | + } else { | |
| 140 | + $this->readers[count($this->readers)] =& $this->source; | |
| 141 | + unset($this->source); | |
| 142 | + $this->source = new File_Archive_Reader_AddBaseName( | |
| 143 | + $filename, $reader | |
| 144 | + ); | |
| 145 | + return true; | |
| 146 | + } | |
| 147 | + } | |
| 148 | + /** | |
| 149 | + * @see File_Archive_Reader::close() | |
| 150 | + */ | |
| 151 | + function next() | |
| 152 | + { | |
| 153 | + if ($this->currentFileNotDisplayed) { | |
| 154 | + $this->currentFileNotDisplayed = false; | |
| 155 | + return true; | |
| 156 | + } | |
| 157 | + | |
| 158 | + do { | |
| 159 | + do { | |
| 160 | + $selection = substr($this->baseDir, 0, $this->baseDirProgression); | |
| 161 | + if ($selection === false) { | |
| 162 | + $selection = ''; | |
| 163 | + } | |
| 164 | + | |
| 165 | + $error = $this->source->select($selection, false); | |
| 166 | + if (PEAR::isError($error)) { | |
| 167 | + return $error; | |
| 168 | + } | |
| 169 | + if (!$error) { | |
| 170 | + if (empty($this->readers)) { | |
| 171 | + return false; | |
| 172 | + } | |
| 173 | + $this->source->close(); | |
| 174 | + unset($this->source); | |
| 175 | + $this->source =& $this->readers[count($this->readers)-1]; | |
| 176 | + unset($this->readers[count($this->readers)-1]); | |
| 177 | + } | |
| 178 | + } while (!$error); | |
| 179 | + | |
| 180 | + $filename = $this->source->getFilename(); | |
| 181 | + if (strlen($filename) < strlen($this->baseDir)) { | |
| 182 | + $goodFile = (strncmp($filename, $this->baseDir, strlen($filename)) == 0 && | |
| 183 | + $this->baseDir{strlen($filename)} == '/'); | |
| 184 | + if ($goodFile) { | |
| 185 | + if (strlen($filename) + 2 < strlen($this->baseDirProgression)) { | |
| 186 | + $this->baseDirProgression = strpos($this->baseDir, '/', strlen($filename)+2); | |
| 187 | + if ($this->baseDirProgression === false) { | |
| 188 | + $this->baseDirProgression = strlen($this->baseDir); | |
| 189 | + } | |
| 190 | + } else { | |
| 191 | + $this->baseDirProgression = strlen($this->baseDir); | |
| 192 | + } | |
| 193 | + } | |
| 194 | + } else { | |
| 195 | + $goodFile = (strncmp($filename, $this->baseDir, strlen($this->baseDir)) == 0); | |
| 196 | + if ($goodFile) { | |
| 197 | + $this->baseDirProgression = strlen($this->baseDir); | |
| 198 | + } | |
| 199 | + } | |
| 200 | + } while ($goodFile && $this->push()); | |
| 201 | + | |
| 202 | + return true; | |
| 203 | + } | |
| 204 | + | |
| 205 | + /** | |
| 206 | + * Efficiently filter out the files which URL does not start with $baseDir | |
| 207 | + * Throws an error if the $baseDir can't be found | |
| 208 | + * @return bool Whether baseDir was a directory or a file | |
| 209 | + */ | |
| 210 | + function setBaseDir($baseDir) | |
| 211 | + { | |
| 212 | + $this->baseDir = $baseDir; | |
| 213 | + $this->baseDirProgression = strpos($baseDir, '/'); | |
| 214 | + if ($this->baseDirProgression === false) { | |
| 215 | + $this->baseDirProgression = strlen($baseDir); | |
| 216 | + } | |
| 217 | + | |
| 218 | + $error = $this->next(); | |
| 219 | + if ($error === false) { | |
| 220 | + return PEAR::raiseError("No directory $baseDir in inner reader"); | |
| 221 | + } else if (PEAR::isError($error)) { | |
| 222 | + return $error; | |
| 223 | + } | |
| 224 | + | |
| 225 | + $this->currentFileNotDisplayed = true; | |
| 226 | + return strlen($this->getFilename())>strlen($baseDir); | |
| 227 | + } | |
| 228 | + /** | |
| 229 | + * @see File_Archive_Reader::select() | |
| 230 | + */ | |
| 231 | + function select($filename, $close = true) | |
| 232 | + { | |
| 233 | + if ($close) { | |
| 234 | + $error = $this->close(); | |
| 235 | + if (PEAR::isError($close)) { | |
| 236 | + return $error; | |
| 237 | + } | |
| 238 | + } | |
| 239 | + | |
| 240 | + $oldBaseDir = $this->baseDir; | |
| 241 | + $oldProgression = $this->baseDirProgression; | |
| 242 | + | |
| 243 | + $this->baseDir = $filename; | |
| 244 | + $this->baseDirProgression = 0; | |
| 245 | + | |
| 246 | + $res = $this->next(); | |
| 247 | + | |
| 248 | + $this->baseDir = $oldBaseDir; | |
| 249 | + $this->baseDirProgression = $oldProgression; | |
| 250 | + | |
| 251 | + return $res; | |
| 252 | + } | |
| 253 | + | |
| 254 | + /** | |
| 255 | + * @see File_Archive_Reader::close() | |
| 256 | + */ | |
| 257 | + function close() | |
| 258 | + { | |
| 259 | + for ($i=0; $i<count($this->readers); ++$i) { | |
| 260 | + $this->readers[$i]->close(); | |
| 261 | + } | |
| 262 | + //var_dump($this->toClose); | |
| 263 | + for ($i=0; $i<count($this->toClose); ++$i) { | |
| 264 | + if ($this->toClose[$i] !== null) { | |
| 265 | + $this->toClose[$i]->close(); | |
| 266 | + } | |
| 267 | + } | |
| 268 | + | |
| 269 | + $this->readers = array(); | |
| 270 | + $this->toClose = array(); | |
| 271 | + $error = parent::close(); | |
| 272 | + $this->baseDirCompressionLevel = null; | |
| 273 | + $this->baseDirProgression = 0; | |
| 274 | + | |
| 275 | + unset($this->source); | |
| 276 | + $this->source =& $this->startReader; | |
| 277 | + $this->source->close(); | |
| 278 | + $this->currentFileNotDisplayed = false; | |
| 279 | + | |
| 280 | + return $error; | |
| 281 | + } | |
| 282 | + | |
| 283 | + /** | |
| 284 | + * @see File_Archive_Reader::makeAppendWriter() | |
| 285 | + */ | |
| 286 | + function makeAppendWriter() | |
| 287 | + { | |
| 288 | + //The reader needs to be open so that the base dir is found | |
| 289 | + $error = $this->next(); | |
| 290 | + if (PEAR::isError($error)) { | |
| 291 | + return $error; | |
| 292 | + } | |
| 293 | + | |
| 294 | + return parent::makeAppendWriter(); | |
| 295 | + } | |
| 296 | + | |
| 297 | + /** | |
| 298 | + * @see File_Archive_Reader::makeWriterRemoveFiles() | |
| 299 | + */ | |
| 300 | + function makeWriterRemoveFiles($pred) | |
| 301 | + { | |
| 302 | + //The reader needs to be open so that the base dir is found | |
| 303 | + $error = $this->next(); | |
| 304 | + if (PEAR::isError($error)) { | |
| 305 | + return $error; | |
| 306 | + } | |
| 307 | + | |
| 308 | + return parent::makeWriterRemoveFiles($pred); | |
| 309 | + } | |
| 310 | +} | |
| 311 | + | |
| 312 | +?> | |
| 0 | 313 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Reader/Zip.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * ZIP archive reader | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: Zip.php,v 1.26 2005/06/19 20:09:58 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "File/Archive/Reader/Archive.php"; | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * ZIP archive reader | |
| 36 | + * Currently only allows to browse the archive (getData is not available) | |
| 37 | + */ | |
| 38 | +class File_Archive_Reader_Zip extends File_Archive_Reader_Archive | |
| 39 | +{ | |
| 40 | + var $currentFilename = null; | |
| 41 | + var $currentStat = null; | |
| 42 | + var $header = null; | |
| 43 | + var $offset = 0; | |
| 44 | + var $data = null; | |
| 45 | + var $files = array(); | |
| 46 | + var $seekToEnd = 0; | |
| 47 | + | |
| 48 | + var $centralDirectory = null; | |
| 49 | + | |
| 50 | + /** | |
| 51 | + * @see File_Archive_Reader::close() | |
| 52 | + */ | |
| 53 | + function close() | |
| 54 | + { | |
| 55 | + $this->currentFilename = null; | |
| 56 | + $this->currentStat = null; | |
| 57 | + $this->compLength = 0; | |
| 58 | + $this->data = null; | |
| 59 | + $this->seekToEnd = 0; | |
| 60 | + $this->files = array(); | |
| 61 | + $this->centralDirectory = null; | |
| 62 | + | |
| 63 | + return parent::close(); | |
| 64 | + } | |
| 65 | + | |
| 66 | + /** | |
| 67 | + * @see File_Archive_Reader::getFilename() | |
| 68 | + */ | |
| 69 | + function getFilename() { return $this->currentFilename; } | |
| 70 | + /** | |
| 71 | + * @see File_Archive_Reader::getStat() | |
| 72 | + */ | |
| 73 | + function getStat() { return $this->currentStat; } | |
| 74 | + | |
| 75 | + /** | |
| 76 | + * Go to next entry in ZIP archive | |
| 77 | + * This function may stop on a folder, so it does not comply to the | |
| 78 | + * File_Archive_Reader::next specs | |
| 79 | + * | |
| 80 | + * @see File_Archive_Reader::next() | |
| 81 | + */ | |
| 82 | + function nextWithFolders() | |
| 83 | + { | |
| 84 | + if ($this->seekToEnd > 0) { | |
| 85 | + return false; | |
| 86 | + } | |
| 87 | + | |
| 88 | + //Skip the data and the footer if they haven't been uncompressed | |
| 89 | + if ($this->header !== null && $this->data === null) { | |
| 90 | + $toSkip = $this->header['CLen']; | |
| 91 | + $error = $this->source->skip($toSkip); | |
| 92 | + if (PEAR::isError($error)) { | |
| 93 | + return $error; | |
| 94 | + } | |
| 95 | + } | |
| 96 | + | |
| 97 | + $this->offset = 0; | |
| 98 | + $this->data = null; | |
| 99 | + | |
| 100 | + //Read the header | |
| 101 | + $header = $this->source->getData(4); | |
| 102 | + if (PEAR::isError($header)) { | |
| 103 | + return $header; | |
| 104 | + } | |
| 105 | + if ($header == "\x50\x4b\x03\x04") { | |
| 106 | + //New entry | |
| 107 | + $header = $this->source->getData(26); | |
| 108 | + if (PEAR::isError($header)) { | |
| 109 | + return $header; | |
| 110 | + } | |
| 111 | + $this->header = unpack( | |
| 112 | + "vVersion/vFlag/vMethod/vTime/vDate/VCRC/VCLen/VNLen/vFile/vExtra", | |
| 113 | + $header); | |
| 114 | + | |
| 115 | + //Check the compression method | |
| 116 | + if ($this->header['Method'] != 0 && | |
| 117 | + $this->header['Method'] != 8 && | |
| 118 | + $this->header['Method'] != 12) { | |
| 119 | + return PEAR::raiseError("File_Archive_Reader_Zip doesn't ". | |
| 120 | + "handle compression method {$this->header['Method']}"); | |
| 121 | + } | |
| 122 | + if ($this->header['Flag'] & 1) { | |
| 123 | + return PEAR::raiseError("File_Archive_Reader_Zip doesn't ". | |
| 124 | + "handle encrypted files"); | |
| 125 | + } | |
| 126 | + if ($this->header['Flag'] & 8) { | |
| 127 | + if ($this->centralDirectory === null) { | |
| 128 | + $this->readCentralDirectory(); | |
| 129 | + } | |
| 130 | + $centralDirEntry = $this->centralDirectory[count($this->files)]; | |
| 131 | + | |
| 132 | + $this->header['CRC'] = $centralDirEntry['CRC']; | |
| 133 | + $this->header['CLen'] = $centralDirEntry['CLen']; | |
| 134 | + $this->header['NLen'] = $centralDirEntry['NLen']; | |
| 135 | + } | |
| 136 | + if ($this->header['Flag'] & 32) { | |
| 137 | + return PEAR::raiseError("File_Archive_Reader_Zip doesn't ". | |
| 138 | + "handle compressed patched data"); | |
| 139 | + } | |
| 140 | + if ($this->header['Flag'] & 64) { | |
| 141 | + return PEAR::raiseError("File_Archive_Reader_Zip doesn't ". | |
| 142 | + "handle strong encrypted files"); | |
| 143 | + } | |
| 144 | + | |
| 145 | + $this->currentStat = array( | |
| 146 | + 7=>$this->header['NLen'], | |
| 147 | + 9=>mktime( | |
| 148 | + ($this->header['Time'] & 0xF800) >> 11, //hour | |
| 149 | + ($this->header['Time'] & 0x07E0) >> 5, //minute | |
| 150 | + ($this->header['Time'] & 0x001F) >> 1, //second | |
| 151 | + ($this->header['Date'] & 0x01E0) >> 5, //month | |
| 152 | + ($this->header['Date'] & 0x001F) , //day | |
| 153 | + (($this->header['Date'] & 0xFE00) >> 9) + 1980 //year | |
| 154 | + ) | |
| 155 | + ); | |
| 156 | + $this->currentStat['size'] = $this->currentStat[7]; | |
| 157 | + $this->currentStat['mtime'] = $this->currentStat[9]; | |
| 158 | + | |
| 159 | + $this->currentFilename = $this->source->getData($this->header['File']); | |
| 160 | + | |
| 161 | + $error = $this->source->skip($this->header['Extra']); | |
| 162 | + if (PEAR::isError($error)) { | |
| 163 | + return $error; | |
| 164 | + } | |
| 165 | + | |
| 166 | + $this->files[] = array('name' => $this->currentFilename, | |
| 167 | + 'stat' => $this->currentStat, | |
| 168 | + 'CRC' => $this->header['CRC'], | |
| 169 | + 'CLen' => $this->header['CLen'] | |
| 170 | + ); | |
| 171 | + | |
| 172 | + return true; | |
| 173 | + } else { | |
| 174 | + //Begining of central area | |
| 175 | + $this->seekToEnd = 4; | |
| 176 | + $this->currentFilename = null; | |
| 177 | + return false; | |
| 178 | + } | |
| 179 | + } | |
| 180 | + /** | |
| 181 | + * Go to next file entry in ZIP archive | |
| 182 | + * This function will not stop on a folder entry | |
| 183 | + * @see File_Archive_Reader::next() | |
| 184 | + */ | |
| 185 | + function next() | |
| 186 | + { | |
| 187 | + if (!parent::next()) { | |
| 188 | + return false; | |
| 189 | + } | |
| 190 | + | |
| 191 | + do { | |
| 192 | + $result = $this->nextWithFolders(); | |
| 193 | + if ($result !== true) { | |
| 194 | + return $result; | |
| 195 | + } | |
| 196 | + } while (substr($this->getFilename(), -1) == '/'); | |
| 197 | + | |
| 198 | + return true; | |
| 199 | + } | |
| 200 | + | |
| 201 | + /** | |
| 202 | + * @see File_Archive_Reader::getData() | |
| 203 | + */ | |
| 204 | + function getData($length = -1) | |
| 205 | + { | |
| 206 | + if ($this->offset >= $this->currentStat[7]) { | |
| 207 | + return null; | |
| 208 | + } | |
| 209 | + | |
| 210 | + if ($length>=0) { | |
| 211 | + $actualLength = min($length, $this->currentStat[7]-$this->offset); | |
| 212 | + } else { | |
| 213 | + $actualLength = $this->currentStat[7]-$this->offset; | |
| 214 | + } | |
| 215 | + | |
| 216 | + $error = $this->uncompressData(); | |
| 217 | + if (PEAR::isError($error)) { | |
| 218 | + return $error; | |
| 219 | + } | |
| 220 | + $result = substr($this->data, $this->offset, $actualLength); | |
| 221 | + $this->offset += $actualLength; | |
| 222 | + return $result; | |
| 223 | + } | |
| 224 | + /** | |
| 225 | + * @see File_Archive_Reader::skip() | |
| 226 | + */ | |
| 227 | + function skip($length = -1) | |
| 228 | + { | |
| 229 | + $before = $this->offset; | |
| 230 | + if ($length == -1) { | |
| 231 | + $this->offset = $this->currentStat[7]; | |
| 232 | + } else { | |
| 233 | + $this->offset = min($this->offset + $length, $this->currentStat[7]); | |
| 234 | + } | |
| 235 | + return $this->offset - $before; | |
| 236 | + } | |
| 237 | + /** | |
| 238 | + * @see File_Archive_Reader::rewind() | |
| 239 | + */ | |
| 240 | + function rewind($length = -1) | |
| 241 | + { | |
| 242 | + $before = $this->offset; | |
| 243 | + if ($length == -1) { | |
| 244 | + $this->offset = 0; | |
| 245 | + } else { | |
| 246 | + $this->offset = min(0, $this->offset - $length); | |
| 247 | + } | |
| 248 | + return $before - $this->offset; | |
| 249 | + } | |
| 250 | + /** | |
| 251 | + * @see File_Archive_Reader::tell() | |
| 252 | + */ | |
| 253 | + function tell() | |
| 254 | + { | |
| 255 | + return $this->offset; | |
| 256 | + } | |
| 257 | + | |
| 258 | + function uncompressData() | |
| 259 | + { | |
| 260 | + if ($this->data !== null) | |
| 261 | + return; | |
| 262 | + | |
| 263 | + $this->data = $this->source->getData($this->header['CLen']); | |
| 264 | + if (PEAR::isError($this->data)) { | |
| 265 | + return $this->data; | |
| 266 | + } | |
| 267 | + if ($this->header['Method'] == 8) { | |
| 268 | + $this->data = gzinflate($this->data); | |
| 269 | + } | |
| 270 | + if ($this->header['Method'] == 12) { | |
| 271 | + $this->data = bzdecompress($this->data); | |
| 272 | + } | |
| 273 | + | |
| 274 | + if (crc32($this->data) != $this->header['CRC']) { | |
| 275 | + return PEAR::raiseError("Zip archive: CRC fails on entry ". | |
| 276 | + $this->currentFilename); | |
| 277 | + } | |
| 278 | + } | |
| 279 | + | |
| 280 | + /** | |
| 281 | + * @see File_Archive_Reader::makeWriterRemoveFiles() | |
| 282 | + */ | |
| 283 | + function makeWriterRemoveFiles($pred) | |
| 284 | + { | |
| 285 | + require_once "File/Archive/Writer/Zip.php"; | |
| 286 | + | |
| 287 | + $blocks = array(); | |
| 288 | + $seek = null; | |
| 289 | + $gap = 0; | |
| 290 | + if ($this->currentFilename !== null && $pred->isTrue($this)) { | |
| 291 | + $seek = 30 + $this->header['File'] + $this->header['Extra'] + $this->header['CLen']; | |
| 292 | + $blocks[] = $seek; //Remove this file | |
| 293 | + array_pop($this->files); | |
| 294 | + } | |
| 295 | + | |
| 296 | + while (($error = $this->nextWithFolders()) === true) { | |
| 297 | + $size = 30 + $this->header['File'] + $this->header['Extra'] + $this->header['CLen']; | |
| 298 | + if (substr($this->getFilename(), -1) == '/' || $pred->isTrue($this)) { | |
| 299 | + array_pop($this->files); | |
| 300 | + if ($seek === null) { | |
| 301 | + $seek = $size; | |
| 302 | + $blocks[] = $size; | |
| 303 | + } else if ($gap > 0) { | |
| 304 | + $blocks[] = $gap; //Don't remove the files between the gap | |
| 305 | + $blocks[] = $size; | |
| 306 | + $seek += $size; | |
| 307 | + } else { | |
| 308 | + $blocks[count($blocks)-1] += $size; //Also remove this file | |
| 309 | + $seek += $size; | |
| 310 | + } | |
| 311 | + $gap = 0; | |
| 312 | + } else { | |
| 313 | + if ($seek !== null) { | |
| 314 | + $seek += $size; | |
| 315 | + $gap += $size; | |
| 316 | + } | |
| 317 | + } | |
| 318 | + } | |
| 319 | + if (PEAR::isError($error)) { | |
| 320 | + return $error; | |
| 321 | + } | |
| 322 | + | |
| 323 | + if ($seek === null) { | |
| 324 | + $seek = 4; | |
| 325 | + } else { | |
| 326 | + $seek += 4; | |
| 327 | + if ($gap == 0) { | |
| 328 | + array_pop($blocks); | |
| 329 | + } else { | |
| 330 | + $blocks[] = $gap; | |
| 331 | + } | |
| 332 | + } | |
| 333 | + | |
| 334 | + $writer = new File_Archive_Writer_Zip(null, | |
| 335 | + $this->source->makeWriterRemoveBlocks($blocks, -$seek) | |
| 336 | + ); | |
| 337 | + if (PEAR::isError($writer)) { | |
| 338 | + return $writer; | |
| 339 | + } | |
| 340 | + | |
| 341 | + foreach ($this->files as $file) { | |
| 342 | + $writer->alreadyWrittenFile($file['name'], $file['stat'], $file['CRC'], $file['CLen']); | |
| 343 | + } | |
| 344 | + | |
| 345 | + $this->close(); | |
| 346 | + return $writer; | |
| 347 | + } | |
| 348 | + | |
| 349 | + /** | |
| 350 | + * @see File_Archive_Reader::makeWriterRemoveBlocks() | |
| 351 | + */ | |
| 352 | + function makeWriterRemoveBlocks($blocks, $seek = 0) | |
| 353 | + { | |
| 354 | + if ($this->currentFilename === null) { | |
| 355 | + return PEAR::raiseError('No file selected'); | |
| 356 | + } | |
| 357 | + | |
| 358 | + $keep = false; | |
| 359 | + | |
| 360 | + $this->uncompressData(); | |
| 361 | + $newData = substr($this->data, 0, $this->offset + $seek); | |
| 362 | + $this->data = substr($this->data, $this->offset + $seek); | |
| 363 | + foreach ($blocks as $length) { | |
| 364 | + if ($keep) { | |
| 365 | + $newData .= substr($this->data, 0, $length); | |
| 366 | + } | |
| 367 | + $this->data = substr($this->data, $length); | |
| 368 | + $keep = !$keep; | |
| 369 | + } | |
| 370 | + if ($keep) { | |
| 371 | + $newData .= $this->data; | |
| 372 | + } | |
| 373 | + | |
| 374 | + $filename = $this->currentFilename; | |
| 375 | + $stat = $this->currentStat; | |
| 376 | + | |
| 377 | + $writer = $this->makeWriterRemove(); | |
| 378 | + if (PEAR::isError($writer)) { | |
| 379 | + return $writer; | |
| 380 | + } | |
| 381 | + | |
| 382 | + unset($stat[7]); | |
| 383 | + $stat[9] = $stat['mtime'] = time(); | |
| 384 | + $writer->newFile($filename, $stat); | |
| 385 | + $writer->writeData($newData); | |
| 386 | + return $writer; | |
| 387 | + } | |
| 388 | + | |
| 389 | + /** | |
| 390 | + * @see File_Archive_Reader::makeAppendWriter | |
| 391 | + */ | |
| 392 | + function makeAppendWriter() | |
| 393 | + { | |
| 394 | + require_once "File/Archive/Writer/Zip.php"; | |
| 395 | + | |
| 396 | + while (($error = $this->next()) === true) { } | |
| 397 | + if (PEAR::isError($error)) { | |
| 398 | + $this->close(); | |
| 399 | + return $error; | |
| 400 | + } | |
| 401 | + | |
| 402 | + $writer = new File_Archive_Writer_Zip(null, | |
| 403 | + $this->source->makeWriterRemoveBlocks(array(), -4) | |
| 404 | + ); | |
| 405 | + | |
| 406 | + foreach ($this->files as $file) { | |
| 407 | + $writer->alreadyWrittenFile($file['name'], $file['stat'], $file['CRC'], $file['CLen']); | |
| 408 | + } | |
| 409 | + | |
| 410 | + $this->close(); | |
| 411 | + return $writer; | |
| 412 | + } | |
| 413 | + | |
| 414 | + /** | |
| 415 | + * This function seeks to the start of the [end of central directory] field, | |
| 416 | + * just after the \x50\x4b\x05\x06 signature and returns the number of bytes | |
| 417 | + * skipped | |
| 418 | + * | |
| 419 | + * The stream must initially be positioned before the end of central directory | |
| 420 | + */ | |
| 421 | + function seekToEndOfCentralDirectory() | |
| 422 | + { | |
| 423 | + $nbSkipped = $this->source->skip(); | |
| 424 | + | |
| 425 | + $nbSkipped -= $this->source->rewind(22) - 4; | |
| 426 | + if ($this->source->getData(4) == "\x50\x4b\x05\x06") { | |
| 427 | + return $nbSkipped; | |
| 428 | + } | |
| 429 | + | |
| 430 | + while ($nbSkipped > 0) { | |
| 431 | + | |
| 432 | + $nbRewind = $this->source->rewind(min(100, $nbSkipped)); | |
| 433 | + while ($nbRewind >= -4) { | |
| 434 | + if ($nbRewind-- && $this->source->getData(1) == "\x50" && | |
| 435 | + $nbRewind-- && $this->source->getData(1) == "\x4b" && | |
| 436 | + $nbRewind-- && $this->source->getData(1) == "\x05" && | |
| 437 | + $nbRewind-- && $this->source->getData(1) == "\x06") { | |
| 438 | + //We finally found it! | |
| 439 | + return $nbSkipped - $nbRewind; | |
| 440 | + } | |
| 441 | + } | |
| 442 | + $nbSkipped -= $nbRewind; | |
| 443 | + } | |
| 444 | + | |
| 445 | + return PEAR::raiseError('End of central directory not found. The file is probably not a zip archive'); | |
| 446 | + } | |
| 447 | + | |
| 448 | + /** | |
| 449 | + * This function will fill the central directory variable | |
| 450 | + * and seek back to where it was called | |
| 451 | + */ | |
| 452 | + function readCentralDirectory() | |
| 453 | + { | |
| 454 | + $nbSkipped = $this->seekToEndOfCentralDirectory(); | |
| 455 | + if (PEAR::isError($nbSkipped)) { | |
| 456 | + return $nbSkipped; | |
| 457 | + } | |
| 458 | + | |
| 459 | + $this->source->skip(12); | |
| 460 | + $offset = $this->source->getData(4); | |
| 461 | + $nbSkipped += 16; | |
| 462 | + if (PEAR::isError($offset)) { | |
| 463 | + return $offset; | |
| 464 | + } | |
| 465 | + | |
| 466 | + $offset = unpack("Vvalue", $offset); | |
| 467 | + $offset = $offset['value']; | |
| 468 | + | |
| 469 | + $current = $this->source->tell(); | |
| 470 | + $nbSkipped -= $this->source->rewind($current - $offset); | |
| 471 | + | |
| 472 | + //Now we are the right pos to read the central directory | |
| 473 | + $this->centralDirectory = array(); | |
| 474 | + while ($this->source->getData(4) == "\x50\x4b\x01\x02") { | |
| 475 | + $this->source->skip(12); | |
| 476 | + $header = $this->source->getData(16); | |
| 477 | + $nbSkipped += 32; | |
| 478 | + | |
| 479 | + if (PEAR::isError($header)) { | |
| 480 | + return $header; | |
| 481 | + } | |
| 482 | + | |
| 483 | + $header = unpack('VCRC/VCLen/VNLen/vFileLength/vExtraLength', $header); | |
| 484 | + $this->centralDirectory[] = array('CRC' => $header['CRC'], | |
| 485 | + 'CLen' => $header['CLen'], | |
| 486 | + 'NLen' => $header['NLen']); | |
| 487 | + $nbSkipped += $this->source->skip(14 + $header['FileLength'] + $header['ExtraLength']); | |
| 488 | + } | |
| 489 | + | |
| 490 | + $this->source->rewind($nbSkipped+4); | |
| 491 | + } | |
| 492 | +} | |
| 493 | +?> | |
| 0 | 494 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Writer.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Base class for any writer | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: Writer.php,v 1.12 2005/05/31 21:22:02 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "PEAR.php"; | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * Base class for any writer | |
| 36 | + */ | |
| 37 | +class File_Archive_Writer | |
| 38 | +{ | |
| 39 | + /** | |
| 40 | + * Create a new file in the writer | |
| 41 | + * | |
| 42 | + * @param string $filename Name of the file, eventually including a path | |
| 43 | + * @param array $stat Its Statistics. None of the indexes are required | |
| 44 | + * @param string $mime MIME type of the file | |
| 45 | + */ | |
| 46 | + function newFile($filename, $stat = array(), $mime = "application/octet-stream") | |
| 47 | + { | |
| 48 | + } | |
| 49 | + | |
| 50 | + /** | |
| 51 | + * Create a new file in the writer with the content of the physical file $filename | |
| 52 | + * and then unlink $filename. | |
| 53 | + * newFromTempFile($tmpfile, $filename, $stat, $mime) is equivalent to | |
| 54 | + * newFile($filename, $stat, $mime); writeFile($tmpfile); unlink($tmpfile); | |
| 55 | + * but can be more efficient. | |
| 56 | + * A typical use is for File_Archive_Writer_Files: it renames the temporary | |
| 57 | + * file instead of copy/delete | |
| 58 | + * | |
| 59 | + * @param string $tmpfile Name of the physical file that contains data and will be unlinked | |
| 60 | + * @param string $filename Name of the file, eventually including a path | |
| 61 | + * @param array $stat Its Statistics. None of the indexes are required | |
| 62 | + * @param string $mime MIME type of the file | |
| 63 | + */ | |
| 64 | + function newFromTempFile($tmpfile, $filename, $stat = array(), $mime = "application/octet-stream") | |
| 65 | + { | |
| 66 | + $this->newFile($filename, $stat, $mime); | |
| 67 | + $this->writeFile($tmpfile); | |
| 68 | + unlink($tmpfile); | |
| 69 | + } | |
| 70 | + | |
| 71 | + /** | |
| 72 | + * Returns whether the writer newFile function needs the $mime parameter | |
| 73 | + * Default is false | |
| 74 | + */ | |
| 75 | + function newFileNeedsMIME() | |
| 76 | + { | |
| 77 | + return false; | |
| 78 | + } | |
| 79 | + | |
| 80 | + /** | |
| 81 | + * Append the specified data to the writer | |
| 82 | + * | |
| 83 | + * @param String $data the data to append to the writer | |
| 84 | + */ | |
| 85 | + function writeData($data) | |
| 86 | + { | |
| 87 | + } | |
| 88 | + | |
| 89 | + /** | |
| 90 | + * Append the content of the physical file $filename to the writer | |
| 91 | + * writeFile($filename) must be equivalent to | |
| 92 | + * writeData(file_get_contents($filename)) but can be more efficient | |
| 93 | + * | |
| 94 | + * @param string $filename Name of the file which content must be appended | |
| 95 | + * to the writer | |
| 96 | + */ | |
| 97 | + function writeFile($filename) | |
| 98 | + { | |
| 99 | + $handle = fopen($filename, "r"); | |
| 100 | + if (!is_resource($handle)) { | |
| 101 | + return PEAR::raiseError("Unable to write to $filename"); | |
| 102 | + } | |
| 103 | + while (!feof($handle)) { | |
| 104 | + $error = $this->writeData(fread($handle, 102400)); | |
| 105 | + if (PEAR::isError($error)) { | |
| 106 | + return $error; | |
| 107 | + } | |
| 108 | + } | |
| 109 | + fclose($handle); | |
| 110 | + } | |
| 111 | + | |
| 112 | + /** | |
| 113 | + * Close the writer, eventually flush the data, write the footer... | |
| 114 | + * This function must be called before the end of the script | |
| 115 | + */ | |
| 116 | + function close() { } | |
| 117 | +} | |
| 118 | + | |
| 119 | +?> | |
| 0 | 120 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Writer/AddBaseName.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Writer wrapper that adds a directory to the written file | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: AddBaseName.php,v 1.1 2005/06/02 22:45:58 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "File/Archive/Writer.php"; | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * Writer wrapper that adds a directory to the written file | |
| 36 | + */ | |
| 37 | +class File_Archive_Writer_AddBaseName | |
| 38 | +{ | |
| 39 | + var $writer; | |
| 40 | + var $baseName; | |
| 41 | + | |
| 42 | + function File_Archive_Writer_AddBaseName($baseName, &$writer) | |
| 43 | + { | |
| 44 | + if (substr($baseName, -1) == '/') { | |
| 45 | + $this->baseName = $baseName; | |
| 46 | + } else { | |
| 47 | + $this->baseName = $baseName.'/'; | |
| 48 | + } | |
| 49 | + | |
| 50 | + $this->writer =& $writer; | |
| 51 | + } | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * @see File_Archive_Writer::newFile() | |
| 55 | + */ | |
| 56 | + function newFile($filename, $stat = array(), $mime = "application/octet-stream") | |
| 57 | + { | |
| 58 | + $this->writer->newFile($this->baseName.$filename, $stat, $mime); | |
| 59 | + } | |
| 60 | + | |
| 61 | + /** | |
| 62 | + * @see File_Archive_Writer::newFromTempFile() | |
| 63 | + */ | |
| 64 | + function newFromTempFile($tmpfile, $filename, $stat = array(), $mime = "application/octet-stream") | |
| 65 | + { | |
| 66 | + $this->writer->newFromTempFile($tmpfilen $this->baseName.$filename, $stat, $mime); | |
| 67 | + } | |
| 68 | + | |
| 69 | + /** | |
| 70 | + * @see File_Archive_Writer::newFileNeedsMIME() | |
| 71 | + */ | |
| 72 | + function newFileNeedsMIME() | |
| 73 | + { | |
| 74 | + return $this->writer->newFileNeedsMIME(); | |
| 75 | + } | |
| 76 | + | |
| 77 | + /** | |
| 78 | + * @see File_Archive_Writer::writeData() | |
| 79 | + */ | |
| 80 | + function writeData($data) | |
| 81 | + { | |
| 82 | + $this->writer->writeData($data); | |
| 83 | + } | |
| 84 | + | |
| 85 | + /** | |
| 86 | + * @see File_Archive_Writer::writeFile() | |
| 87 | + */ | |
| 88 | + function writeFile($filename) | |
| 89 | + { | |
| 90 | + $this->writer->writeFile($filename); | |
| 91 | + } | |
| 92 | + | |
| 93 | + /** | |
| 94 | + * @see File_Archive_Writer::close() | |
| 95 | + */ | |
| 96 | + function close() | |
| 97 | + { | |
| 98 | + $this->writer->close(); | |
| 99 | + } | |
| 100 | +} | |
| 101 | + | |
| 102 | +?> | |
| 0 | 103 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Writer/Ar.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Write data to a file and save as an ar | |
| 4 | + * | |
| 5 | + * PHP versions 4 and 5 | |
| 6 | + * | |
| 7 | + * This library is free software; you can redistribute it and/or | |
| 8 | + * modify it under the terms of the GNU Lesser General Public | |
| 9 | + * License as published by the Free Software Foundation; either | |
| 10 | + * version 2.1 of the License, or (at your option) any later version. | |
| 11 | + * | |
| 12 | + * This library is distributed in the hope that it will be useful, | |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 15 | + * Lesser General Public License for more details. | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU Lesser General Public | |
| 18 | + * License along with this library; if not, write to the Free Software | |
| 19 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 20 | + * | |
| 21 | + * @category File Formats | |
| 22 | + * @package File_Archive | |
| 23 | + * @author Pablo Fischer <pablo@pablo.com.mx> | |
| 24 | + * @copyright 1997-2005 The PHP Group | |
| 25 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 26 | + * @version CVS: $Id: | |
| 27 | + * @link http://pear.php.net/package/File_Archive | |
| 28 | + */ | |
| 29 | + | |
| 30 | +require_once "File/Archive/Writer/Archive.php"; | |
| 31 | + | |
| 32 | +/** | |
| 33 | + * Write the files as an AR archive | |
| 34 | + */ | |
| 35 | +class File_Archive_Writer_Ar extends File_Archive_Writer_Archive | |
| 36 | +{ | |
| 37 | + | |
| 38 | + /** | |
| 39 | + * @var string Current data of the file. | |
| 40 | + * @access private | |
| 41 | + */ | |
| 42 | + var $_buffer = ""; | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * @var string Filename of the current filename | |
| 46 | + * @access private | |
| 47 | + */ | |
| 48 | + var $_currentFilename = null; | |
| 49 | + | |
| 50 | + /** | |
| 51 | + * @var boolean Flag: use buffer or not. | |
| 52 | + * @access private | |
| 53 | + */ | |
| 54 | + var $_useBuffer; | |
| 55 | + | |
| 56 | + /** | |
| 57 | + * @var array Stats of the current filename | |
| 58 | + * @access private | |
| 59 | + */ | |
| 60 | + var $_currentStat = array (); | |
| 61 | + | |
| 62 | + /** | |
| 63 | + * @var boolean Flag: beginning of the archive or not | |
| 64 | + * @access private | |
| 65 | + */ | |
| 66 | + var $_atStart = true; | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * Returns the header of the current file. | |
| 70 | + * | |
| 71 | + * More Info: | |
| 72 | + * http://publibn.boulder.ibm.com/doc_link/en_US/a_doc_lib/files/aixfiles/ar_IA64.htm | |
| 73 | + * | |
| 74 | + * @access private | |
| 75 | + * @param string $filename Name of the current file | |
| 76 | + * @param array $stat Stat array of the current file | |
| 77 | + * @return string The built header struct | |
| 78 | + */ | |
| 79 | + function arHeader ($filename, $stat) | |
| 80 | + { | |
| 81 | + $mode = isset($stat[2]) ? $stat[2] : 0x8000; | |
| 82 | + $uid = isset($stat[4]) ? $stat[4] : 0; | |
| 83 | + $gid = isset($stat[5]) ? $stat[5] : 0; | |
| 84 | + $size = $stat[7]; | |
| 85 | + $time = isset($stat[9]) ? $stat[9] : time(); | |
| 86 | + | |
| 87 | + $struct = ""; | |
| 88 | + $currentSize = $size; | |
| 89 | + //if file length is > than 16.. | |
| 90 | + if (strlen($filename) > 16) { | |
| 91 | + $currentSize += strlen($filename); | |
| 92 | + $struct .= sprintf("#1/%-13d", strlen($filename)); | |
| 93 | + $struct .= sprintf("%-12d%-6d%-6d%-8s%-10d", | |
| 94 | + $time, $uid, $gid, $mode, $currentSize); | |
| 95 | + $struct .= "`\n".$filename; | |
| 96 | + } else { | |
| 97 | + $struct .= sprintf("%-16s", $filename); | |
| 98 | + $struct .= sprintf("%-12d%-6d%-6d%-8s%-10d`\n", | |
| 99 | + $time, $uid, $gid, $mode, $size); | |
| 100 | + } | |
| 101 | + return $struct; | |
| 102 | + } | |
| 103 | + | |
| 104 | + /** | |
| 105 | + * Returns the footer of the current file, the footer depends | |
| 106 | + * of the size of the file | |
| 107 | + * | |
| 108 | + * @access private | |
| 109 | + * @param string $filename Name of the file, the footer depends on its length | |
| 110 | + * @param int $size Size of the current file, here the size does matters! | |
| 111 | + * @return string The footer struct | |
| 112 | + */ | |
| 113 | + function arFooter($filename, $size) | |
| 114 | + { | |
| 115 | + $size = (strlen ($filename) > 16) ? $size + strlen($filename) : $size; | |
| 116 | + | |
| 117 | + return ($size % 2 == 1) ? "\n" : ""; | |
| 118 | + } | |
| 119 | + | |
| 120 | + | |
| 121 | + /** | |
| 122 | + * Flush the memory we have in the ar. | |
| 123 | + * | |
| 124 | + * Build the buffer if its called at the end or initialize | |
| 125 | + * it if we are just creating it from the start. | |
| 126 | + */ | |
| 127 | + function flush() | |
| 128 | + { | |
| 129 | + if ($this->_atStart) { | |
| 130 | + $this->innerWriter->writeData("!<arch>\n"); | |
| 131 | + $this->_atStart = false; | |
| 132 | + } | |
| 133 | + if ($this->_currentFilename !== null) { | |
| 134 | + $this->_currentStat[7] = strlen($this->_buffer); | |
| 135 | + if ($this->_useBuffer) { | |
| 136 | + $this->innerWriter->writeData( | |
| 137 | + $this->arHeader($this->_currentFilename, $this->_currentStat) | |
| 138 | + ); | |
| 139 | + $this->innerWriter->writeData($this->_buffer); | |
| 140 | + } | |
| 141 | + $this->innerWriter->writeData($this->arFooter($this->_currentFilename, $this->_currentStat[7])); | |
| 142 | + } | |
| 143 | + $this->_buffer = ""; | |
| 144 | + } | |
| 145 | + | |
| 146 | + /** | |
| 147 | + * @see File_Archive_Writer::newFile() | |
| 148 | + * | |
| 149 | + */ | |
| 150 | + function newFile($filename, $stat = array (), | |
| 151 | + $mime = "application/octet-stream") | |
| 152 | + { | |
| 153 | + $this->flush(); | |
| 154 | + /* | |
| 155 | + * If the file is empty, there's no reason to have a buffer | |
| 156 | + * or use memory | |
| 157 | + */ | |
| 158 | + $this->_useBuffer = !isset($stats[7]); | |
| 159 | + /* | |
| 160 | + * Becaue ar fileformats doesn't support files in directories, | |
| 161 | + * then we need to just save with the filename an ommit the | |
| 162 | + * directory | |
| 163 | + */ | |
| 164 | + $this->_currentFilename = basename($filename); | |
| 165 | + $this->_currentStat = $stat; | |
| 166 | + | |
| 167 | + if(!$this->_useBuffer) { | |
| 168 | + return $this->innerWriter->writeData($this->arHeader($filename, $stat)); | |
| 169 | + } | |
| 170 | + } | |
| 171 | + | |
| 172 | + /** | |
| 173 | + * @see File_Archive_Writer::close() | |
| 174 | + */ | |
| 175 | + function close() | |
| 176 | + { | |
| 177 | + $this->flush(); | |
| 178 | + parent::close(); | |
| 179 | + } | |
| 180 | + | |
| 181 | + /** | |
| 182 | + * @see File_Archive_Writer::writeData() | |
| 183 | + */ | |
| 184 | + function writeData($data) | |
| 185 | + { | |
| 186 | + if ($this->_useBuffer) { | |
| 187 | + $this->_buffer .= $data; | |
| 188 | + } else { | |
| 189 | + $this->innerWriter->writeData($data); | |
| 190 | + } | |
| 191 | + | |
| 192 | + } | |
| 193 | + /** | |
| 194 | + * @see File_Archive_Writer::writeFile() | |
| 195 | + */ | |
| 196 | + function writeFile($filename) | |
| 197 | + { | |
| 198 | + if ($this->_useBuffer) { | |
| 199 | + $this->_buffer .= file_get_contents($filename); | |
| 200 | + } else { | |
| 201 | + $this->innerWriter->writeFile($filename); | |
| 202 | + } | |
| 203 | + } | |
| 204 | +} | |
| 0 | 205 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Writer/Archive.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Base class for all the transformation writers that will generate one single | |
| 6 | + * file | |
| 7 | + * | |
| 8 | + * PHP versions 4 and 5 | |
| 9 | + * | |
| 10 | + * This library is free software; you can redistribute it and/or | |
| 11 | + * modify it under the terms of the GNU Lesser General Public | |
| 12 | + * License as published by the Free Software Foundation; either | |
| 13 | + * version 2.1 of the License, or (at your option) any later version. | |
| 14 | + * | |
| 15 | + * This library is distributed in the hope that it will be useful, | |
| 16 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 17 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 18 | + * Lesser General Public License for more details. | |
| 19 | + * | |
| 20 | + * You should have received a copy of the GNU Lesser General Public | |
| 21 | + * License along with this library; if not, write to the Free Software | |
| 22 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 23 | + * | |
| 24 | + * @category File Formats | |
| 25 | + * @package File_Archive | |
| 26 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 27 | + * @copyright 1997-2005 The PHP Group | |
| 28 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 29 | + * @version CVS: $Id: Archive.php,v 1.12 2005/06/02 12:24:43 vincentlascaux Exp $ | |
| 30 | + * @link http://pear.php.net/package/File_Archive | |
| 31 | + */ | |
| 32 | + | |
| 33 | +require_once "File/Archive/Writer.php"; | |
| 34 | + | |
| 35 | +/** | |
| 36 | + * Base class for all the transformation writers that will generate one single | |
| 37 | + * file | |
| 38 | + */ | |
| 39 | +class File_Archive_Writer_Archive extends File_Archive_Writer | |
| 40 | +{ | |
| 41 | + /** | |
| 42 | + * @var File_Archive_Writer The compressed data will be written to this | |
| 43 | + * writer | |
| 44 | + * @access protected | |
| 45 | + */ | |
| 46 | + var $innerWriter; | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * @var bool If true, the innerWriter will be closed when closing this | |
| 50 | + * @access private | |
| 51 | + */ | |
| 52 | + var $autoClose; | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * @param String $filename Name to give to the archive (the name will | |
| 56 | + * be used by the inner writer) | |
| 57 | + * If $filename is null, the innerWriter is considered already | |
| 58 | + * opened (and thus newFile will not be called) | |
| 59 | + * @param File_Archive_Writer $innerWriter The inner writer to which the | |
| 60 | + * compressed data will be written | |
| 61 | + * @param array $stat The stat of the archive (see the PHP stat() function). | |
| 62 | + * No element are required in this array | |
| 63 | + * @param bool $autoClose Indicate if the inner writer must be closed when | |
| 64 | + * closing this | |
| 65 | + */ | |
| 66 | + function File_Archive_Writer_Archive($filename, &$innerWriter, | |
| 67 | + $stat = array(), $autoClose = true) | |
| 68 | + { | |
| 69 | + $this->innerWriter =& $innerWriter; | |
| 70 | + $this->autoClose = $autoClose; | |
| 71 | + if ($filename !== null) { | |
| 72 | + $this->innerWriter->newFile($filename, $stat, $this->getMime()); | |
| 73 | + } | |
| 74 | + } | |
| 75 | + | |
| 76 | +//MUST REWRITE FUNCTIONS | |
| 77 | + //function newFile($filename, $stat, $mime) { } | |
| 78 | + | |
| 79 | + /** | |
| 80 | + * @return the MIME extension of the files generated by this writer | |
| 81 | + */ | |
| 82 | + function getMime() { return "application/octet-stream"; } | |
| 83 | + | |
| 84 | + /** | |
| 85 | + * @see File_Archive_Writer::close() | |
| 86 | + */ | |
| 87 | + function close() | |
| 88 | + { | |
| 89 | + if ($this->autoClose) { | |
| 90 | + return $this->innerWriter->close(); | |
| 91 | + } | |
| 92 | + } | |
| 93 | +// function writeData($data) | |
| 94 | + | |
| 95 | +//SHOULD REWRITE FUNCTIONS | |
| 96 | +// function writeFile($filename) | |
| 97 | +} | |
| 98 | + | |
| 99 | +?> | |
| 0 | 100 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Writer/Bzip2.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Compress a single file to Bzip2 format | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: Bzip2.php,v 1.9 2005/06/02 16:22:47 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "File/Archive/Writer.php"; | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * Compress a single file to Bzip2 format | |
| 36 | + */ | |
| 37 | +class File_Archive_Writer_Bzip2 extends File_Archive_Writer | |
| 38 | +{ | |
| 39 | + var $compressionLevel=9; | |
| 40 | + var $bzfile; | |
| 41 | + var $tmpName; | |
| 42 | + var $nbFiles = 0; | |
| 43 | + | |
| 44 | + var $innerWriter; | |
| 45 | + var $autoClose; | |
| 46 | + var $filename; | |
| 47 | + var $stat; | |
| 48 | + | |
| 49 | + /** | |
| 50 | + * @param string $filename Name to give to the archive | |
| 51 | + * @param File_Archive_Writer $innerWriter The inner writer to which the | |
| 52 | + * compressed data will be written | |
| 53 | + * @param array $stat The stat of the archive (see the PHP stat() function). | |
| 54 | + * No element are required in this array | |
| 55 | + * @param bool $autoClose Indicate if the inner writer must be closed when | |
| 56 | + * closing this | |
| 57 | + */ | |
| 58 | + function File_Archive_Writer_Bzip2($filename, &$innerWriter, | |
| 59 | + $stat = array(), $autoClose = true) | |
| 60 | + { | |
| 61 | + $this->innerWriter =& $innerWriter; | |
| 62 | + $this->autoClose = $autoClose; | |
| 63 | + | |
| 64 | + $this->filename = $filename; | |
| 65 | + $this->stat = $stat; | |
| 66 | + | |
| 67 | + if ($this->filename === null) { | |
| 68 | + $this->newFile(null); | |
| 69 | + } | |
| 70 | + } | |
| 71 | + | |
| 72 | + /** | |
| 73 | + * Set the compression level | |
| 74 | + * | |
| 75 | + * @param int $compressionLevel From 0 (no compression) to 9 (best | |
| 76 | + * compression) | |
| 77 | + */ | |
| 78 | + function setCompressionLevel($compressionLevel) | |
| 79 | + { | |
| 80 | + $this->compressionLevel = $compressionLevel; | |
| 81 | + } | |
| 82 | + | |
| 83 | + /** | |
| 84 | + * @see File_Archive_Writer::newFile() | |
| 85 | + * | |
| 86 | + * Check that one single file is written in the BZip2 archive | |
| 87 | + */ | |
| 88 | + function newFile($filename, $stat = array(), | |
| 89 | + $mime = "application/octet-stream") | |
| 90 | + { | |
| 91 | + if ($this->nbFiles > 1) { | |
| 92 | + return PEAR::raiseError("A Bzip2 archive can only contain one single file.". | |
| 93 | + "Use Tbz archive to be able to write several files"); | |
| 94 | + } | |
| 95 | + $this->nbFiles++; | |
| 96 | + | |
| 97 | + $this->tmpName = tempnam(File_Archive::getOption('tmpDirectory'), 'far'); | |
| 98 | + $this->bzfile = bzopen($this->tmpName, 'w'.$this->compressionLevel); | |
| 99 | + | |
| 100 | + return true; | |
| 101 | + } | |
| 102 | + | |
| 103 | + /** | |
| 104 | + * Actually write the tmp file to the inner writer | |
| 105 | + * Close and delete temporary file | |
| 106 | + * | |
| 107 | + * @see File_Archive_Writer::close() | |
| 108 | + */ | |
| 109 | + function close() | |
| 110 | + { | |
| 111 | + bzclose($this->bzfile); | |
| 112 | + | |
| 113 | + if ($this->filename === null) { | |
| 114 | + //Assume innerWriter is already opened on a file... | |
| 115 | + $this->innerWriter->writeFile($this->tmpName); | |
| 116 | + unlink($this->tmpName); | |
| 117 | + } else { | |
| 118 | + $this->innerWriter->newFromTempFile( | |
| 119 | + $this->tmpName, $this->filename, $this->stat, 'application/x-compressed' | |
| 120 | + ); | |
| 121 | + } | |
| 122 | + | |
| 123 | + if ($this->autoClose) { | |
| 124 | + return $this->innerWriter->close(); | |
| 125 | + } | |
| 126 | + } | |
| 127 | + | |
| 128 | + /** | |
| 129 | + * @see File_Archive_Writer::writeData() | |
| 130 | + */ | |
| 131 | + function writeData($data) | |
| 132 | + { | |
| 133 | + bzwrite($this->bzfile, $data); | |
| 134 | + } | |
| 135 | +} | |
| 136 | + | |
| 137 | +?> | |
| 0 | 138 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Writer/Files.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Writer to files | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: Files.php,v 1.21 2005/06/18 23:08:16 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "File/Archive/Writer.php"; | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * Writer to files | |
| 36 | + */ | |
| 37 | +class File_Archive_Writer_Files extends File_Archive_Writer | |
| 38 | +{ | |
| 39 | + /** | |
| 40 | + * @var Object Handle to the file where the data are currently written | |
| 41 | + * @access private | |
| 42 | + */ | |
| 43 | + var $handle = null; | |
| 44 | + var $basePath; | |
| 45 | + var $stat = array(); | |
| 46 | + var $filename; | |
| 47 | + | |
| 48 | + function File_Archive_Writer_Files($base = '') | |
| 49 | + { | |
| 50 | + if ($base === null || $base == '') { | |
| 51 | + $this->basePath = ''; | |
| 52 | + } else { | |
| 53 | + if (substr($base, -1) == '/') { | |
| 54 | + $this->basePath = $base; | |
| 55 | + } else { | |
| 56 | + $this->basePath = $base.'/'; | |
| 57 | + } | |
| 58 | + } | |
| 59 | + } | |
| 60 | + | |
| 61 | + function getFilename($filename) | |
| 62 | + { | |
| 63 | + return $this->basePath.$filename; | |
| 64 | + } | |
| 65 | + | |
| 66 | + /** | |
| 67 | + * Ensure that $pathname exists, or create it if it does not | |
| 68 | + * @access private | |
| 69 | + */ | |
| 70 | + function mkdirr($pathname) | |
| 71 | + { | |
| 72 | + // Check if directory already exists | |
| 73 | + if (is_dir($pathname) || empty($pathname)) { | |
| 74 | + return; | |
| 75 | + } | |
| 76 | + | |
| 77 | + // Ensure a file does not already exist with the same name | |
| 78 | + if (is_file($pathname)) { | |
| 79 | + return PEAR::raiseError( | |
| 80 | + "File $pathname exists, unable to create directory" | |
| 81 | + ); | |
| 82 | + } | |
| 83 | + | |
| 84 | + // Crawl up the directory tree | |
| 85 | + $next_pathname = substr( | |
| 86 | + $pathname, | |
| 87 | + 0, strrpos($pathname, "/")); | |
| 88 | + $error = $this->mkdirr($next_pathname); | |
| 89 | + if (PEAR::isError($error)) { | |
| 90 | + return $error; | |
| 91 | + } | |
| 92 | + if (!@mkdir($pathname)) { | |
| 93 | + return PEAR::raiseError("Unable to create directory $pathname"); | |
| 94 | + } | |
| 95 | + } | |
| 96 | + | |
| 97 | + /** | |
| 98 | + * Open a file for writing from a given position | |
| 99 | + * | |
| 100 | + * @param string $filename The name of the file to open | |
| 101 | + * @param int $pos the initial position in the file | |
| 102 | + * @param $stat the stats of the file | |
| 103 | + */ | |
| 104 | + function openFile($filename, $pos = 0) | |
| 105 | + { | |
| 106 | + $this->close(); | |
| 107 | + | |
| 108 | + $this->handle = fopen($filename, 'r+'); | |
| 109 | + $this->stat = array(); | |
| 110 | + $this->filename = $filename; | |
| 111 | + | |
| 112 | + if (!is_resource($this->handle)) { | |
| 113 | + return PEAR::raiseError("Unable to open file $filename"); | |
| 114 | + } | |
| 115 | + | |
| 116 | + if ($pos > 0) { | |
| 117 | + if (fseek($this->handle, $pos) == -1) { | |
| 118 | + fread($this->handle, $pos); | |
| 119 | + } | |
| 120 | + } | |
| 121 | + } | |
| 122 | + | |
| 123 | + /** | |
| 124 | + * Open a file for appending after having removed a block of data from it | |
| 125 | + * See File_Archive_Reader::makeWriterRemoveBlocks | |
| 126 | + */ | |
| 127 | + function openFileRemoveBlock($filename, $pos, $blocks) | |
| 128 | + { | |
| 129 | + $error = $this->openFile($filename, $pos); | |
| 130 | + if (PEAR::isError($error)) { | |
| 131 | + return $error; | |
| 132 | + } | |
| 133 | + | |
| 134 | + if (!empty($blocks)) { | |
| 135 | + //This will be used to read the initial file | |
| 136 | + //The data, with the unusefull block removed will be written to $this->handle | |
| 137 | + $read = fopen($filename, 'r'); | |
| 138 | + if ($pos > 0) { | |
| 139 | + if (fseek($this->handle, $pos) == -1) { | |
| 140 | + fread($this->handle, $pos); | |
| 141 | + } | |
| 142 | + } | |
| 143 | + | |
| 144 | + $keep = false; | |
| 145 | + $data = ''; | |
| 146 | + foreach ($blocks as $length) { | |
| 147 | + if ($keep) { | |
| 148 | + while ($length > 0 && | |
| 149 | + ($data = fread($read, min($length, 8192))) != '') { | |
| 150 | + $length -= strlen($data); | |
| 151 | + fwrite($this->handle, $data); | |
| 152 | + } | |
| 153 | + } else { | |
| 154 | + fseek($read, $length, SEEK_CUR); | |
| 155 | + } | |
| 156 | + $keep = !$keep; | |
| 157 | + } | |
| 158 | + if ($keep) { | |
| 159 | + while(!feof($this->handle)) { | |
| 160 | + fwrite($this->handle, fread($read, 8196)); | |
| 161 | + } | |
| 162 | + } | |
| 163 | + | |
| 164 | + fclose($read); | |
| 165 | + } | |
| 166 | + | |
| 167 | + ftruncate($this->handle, ftell($this->handle)); | |
| 168 | + } | |
| 169 | + | |
| 170 | + | |
| 171 | + /** | |
| 172 | + * @see File_Archive_Writer::newFile() | |
| 173 | + */ | |
| 174 | + function newFile($filename, $stat = array(), $mime = "application/octet-stream") | |
| 175 | + { | |
| 176 | + $this->close(); | |
| 177 | + $this->stat = $stat; | |
| 178 | + $this->filename = $this->getFilename($filename); | |
| 179 | + | |
| 180 | + $pos = strrpos($this->filename, "/"); | |
| 181 | + if ($pos !== false) { | |
| 182 | + $error = $this->mkdirr(substr($this->filename, 0, $pos)); | |
| 183 | + if (PEAR::isError($error)) { | |
| 184 | + return $error; | |
| 185 | + } | |
| 186 | + } | |
| 187 | + $this->handle = @fopen($this->filename, "w"); | |
| 188 | + if (!is_resource($this->handle)) { | |
| 189 | + return PEAR::raiseError("Unable to write to file $filename"); | |
| 190 | + } | |
| 191 | + } | |
| 192 | + /** | |
| 193 | + * @see File_Archive_Writer::writeData() | |
| 194 | + */ | |
| 195 | + function writeData($data) { fwrite($this->handle, $data); } | |
| 196 | + /** | |
| 197 | + * @see File_Archive_Writer::newFromTempFile() | |
| 198 | + */ | |
| 199 | + function newFromTempFile($tmpfile, $filename, $stat = array(), $mime = "application/octet-stream") | |
| 200 | + { | |
| 201 | + $this->filename = filename; | |
| 202 | + $complete = $this->getFilename($filename); | |
| 203 | + $pos = strrpos($complete, "/"); | |
| 204 | + if ($pos !== false) { | |
| 205 | + $error = $this->mkdirr(substr($complete, 0, $pos)); | |
| 206 | + if (PEAR::isError($error)) { | |
| 207 | + return $error; | |
| 208 | + } | |
| 209 | + } | |
| 210 | + | |
| 211 | + if ((file_exists($complete) && !@unlink($complete)) || | |
| 212 | + !@rename($tmpfile, $complete)) { | |
| 213 | + return parent::newFromTempFile($tmpfile, $filename, $stat, $mime); | |
| 214 | + } | |
| 215 | + } | |
| 216 | + | |
| 217 | + | |
| 218 | + /** | |
| 219 | + * @see File_Archive_Writer::close() | |
| 220 | + */ | |
| 221 | + function close() | |
| 222 | + { | |
| 223 | + if ($this->handle !== null) { | |
| 224 | + fclose($this->handle); | |
| 225 | + $this->handle = null; | |
| 226 | + | |
| 227 | + if (isset($this->stat[9])) { | |
| 228 | + if (isset($this->stat[8])) { | |
| 229 | + touch($this->filename, $this->stat[9], $this->stat[8]); | |
| 230 | + } else { | |
| 231 | + touch($this->filename, $this->stat[9]); | |
| 232 | + } | |
| 233 | + } else if (isset($this->stat[8])) { | |
| 234 | + touch($this->filename, time(), $this->stat[8]); | |
| 235 | + } | |
| 236 | + | |
| 237 | + if (isset($this->stat[2])) { | |
| 238 | + chmod($this->filename, $this->stat[2]); | |
| 239 | + } | |
| 240 | + if (isset($this->stat[5])) { | |
| 241 | + chgrp($this->filename, $this->stat[5]); | |
| 242 | + } | |
| 243 | + if (isset($this->stat[4])) { | |
| 244 | + chown($this->filename, $this->stat[4]); | |
| 245 | + } | |
| 246 | + } | |
| 247 | + } | |
| 248 | +} | |
| 249 | + | |
| 250 | +?> | |
| 0 | 251 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Writer/Gzip.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Compress a single file to Gzip format | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: Gzip.php,v 1.15 2005/06/02 16:22:48 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "File/Archive/Writer.php"; | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * Compress a single file to Gzip format | |
| 36 | + */ | |
| 37 | +class File_Archive_Writer_Gzip extends File_Archive_Writer | |
| 38 | +{ | |
| 39 | + var $compressionLevel=9; | |
| 40 | + var $gzfile; | |
| 41 | + var $tmpName; | |
| 42 | + var $nbFiles = 0; | |
| 43 | + | |
| 44 | + var $innerWriter; | |
| 45 | + var $autoClose; | |
| 46 | + var $filename; | |
| 47 | + var $stat; | |
| 48 | + | |
| 49 | + /** | |
| 50 | + * @param string $filename Name to give to the archive | |
| 51 | + * @param File_Archive_Writer $innerWriter The inner writer to which the | |
| 52 | + * compressed data will be written | |
| 53 | + * @param array $stat The stat of the archive (see the PHP stat() function). | |
| 54 | + * No element are required in this array | |
| 55 | + * @param bool $autoClose Indicate if the inner writer must be closed when | |
| 56 | + * closing this | |
| 57 | + */ | |
| 58 | + function File_Archive_Writer_Gzip($filename, &$innerWriter, | |
| 59 | + $stat = array(), $autoClose = true) | |
| 60 | + { | |
| 61 | + $this->innerWriter =& $innerWriter; | |
| 62 | + $this->autoClose = $autoClose; | |
| 63 | + | |
| 64 | + $this->filename = $filename; | |
| 65 | + $this->stat = $stat; | |
| 66 | + | |
| 67 | + if ($this->filename === null) { | |
| 68 | + $this->newFile(null); | |
| 69 | + } | |
| 70 | + | |
| 71 | + $compressionLevel = File_Archive::getOption('gzCompressionLevel', 9); | |
| 72 | + } | |
| 73 | + | |
| 74 | + /** | |
| 75 | + * Set the compression level | |
| 76 | + * | |
| 77 | + * @param int $compressionLevel From 0 (no compression) to 9 (best | |
| 78 | + * compression) | |
| 79 | + */ | |
| 80 | + function setCompressionLevel($compressionLevel) | |
| 81 | + { | |
| 82 | + $this->compressionLevel = $compressionLevel; | |
| 83 | + } | |
| 84 | + | |
| 85 | + /** | |
| 86 | + * @see File_Archive_Writer::newFile() | |
| 87 | + * | |
| 88 | + * Check that one single file is written in the GZip archive | |
| 89 | + */ | |
| 90 | + function newFile($filename, $stat = array(), | |
| 91 | + $mime = "application/octet-stream") | |
| 92 | + { | |
| 93 | + if ($this->nbFiles > 1) { | |
| 94 | + return PEAR::raiseError("A Gz archive can only contain one single file.". | |
| 95 | + "Use Tgz archive to be able to write several files"); | |
| 96 | + } | |
| 97 | + $this->nbFiles++; | |
| 98 | + | |
| 99 | + $this->tmpName = tempnam(File_Archive::getOption('tmpDirectory'), 'far'); | |
| 100 | + $this->gzfile = gzopen($this->tmpName, 'w'.$this->compressionLevel); | |
| 101 | + | |
| 102 | + return true; | |
| 103 | + } | |
| 104 | + | |
| 105 | + | |
| 106 | + /** | |
| 107 | + * Actually write the tmp file to the inner writer | |
| 108 | + * Close and delete temporary file | |
| 109 | + * | |
| 110 | + * @see File_Archive_Writer::close() | |
| 111 | + */ | |
| 112 | + function close() | |
| 113 | + { | |
| 114 | + gzclose($this->gzfile); | |
| 115 | + if ($this->filename === null) { | |
| 116 | + //Assume innerWriter is already opened on a file... | |
| 117 | + $this->innerWriter->writeFile($this->tmpName); | |
| 118 | + unlink($this->tmpName); | |
| 119 | + } else { | |
| 120 | + $this->innerWriter->newFromTempFile( | |
| 121 | + $this->tmpName, $this->filename, $this->stat, 'application/x-compressed' | |
| 122 | + ); | |
| 123 | + } | |
| 124 | + | |
| 125 | + if ($this->autoClose) { | |
| 126 | + return $this->innerWriter->close(); | |
| 127 | + } | |
| 128 | + } | |
| 129 | + | |
| 130 | + /** | |
| 131 | + * @see File_Archive_Writer::writeData() | |
| 132 | + */ | |
| 133 | + function writeData($data) | |
| 134 | + { | |
| 135 | + gzwrite($this->gzfile, $data); | |
| 136 | + } | |
| 137 | +} | |
| 138 | + | |
| 139 | +?> | |
| 0 | 140 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Writer/Mail.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Send the files attached to a mail. | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: Mail.php,v 1.11 2005/06/02 12:24:43 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "File/Archive/Writer.php"; | |
| 33 | +require_once "Mail.php"; | |
| 34 | +require_once "Mail/mime.php"; | |
| 35 | + | |
| 36 | +/** | |
| 37 | + * Send the files attached to a mail. | |
| 38 | + */ | |
| 39 | +class File_Archive_Writer_Mail extends File_Archive_Writer | |
| 40 | +{ | |
| 41 | + /** | |
| 42 | + * @var Mail_mime object | |
| 43 | + * @access private | |
| 44 | + */ | |
| 45 | + var $mime; | |
| 46 | + | |
| 47 | + /** | |
| 48 | + * @var Mail object used to send email (built thanks to the factory) | |
| 49 | + * @access private | |
| 50 | + */ | |
| 51 | + var $mail; | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * @var Array or String An array or a string with comma separated recipients | |
| 55 | + * @access private | |
| 56 | + */ | |
| 57 | + var $to; | |
| 58 | + | |
| 59 | + /** | |
| 60 | + * @var Array The headers that will be passed to the Mail_mime object | |
| 61 | + * @access private | |
| 62 | + */ | |
| 63 | + var $headers; | |
| 64 | + | |
| 65 | + /** | |
| 66 | + * @var String Data read from the current file so far | |
| 67 | + * @access private | |
| 68 | + */ | |
| 69 | + var $currentData = null; | |
| 70 | + | |
| 71 | + /** | |
| 72 | + * @var String Name of the file being attached | |
| 73 | + * @access private | |
| 74 | + */ | |
| 75 | + var $currentFilename = null; | |
| 76 | + | |
| 77 | + /** | |
| 78 | + * @var String MIME of the file being attached | |
| 79 | + * @access private | |
| 80 | + */ | |
| 81 | + var $currentMime = null; | |
| 82 | + | |
| 83 | + /** | |
| 84 | + * @param Mail $mail Object used to send mail (see Mail::factory) | |
| 85 | + * @param array or string $to An array or a string with comma separated | |
| 86 | + * recipients | |
| 87 | + * @param array $headers The headers that will be passed to the Mail_mime | |
| 88 | + * object | |
| 89 | + * @param string $message Text body of the mail | |
| 90 | + */ | |
| 91 | + function File_Archive_Writer_Mail($to, $headers, $message, &$mail) | |
| 92 | + { | |
| 93 | + $this->mime = new Mail_mime(); | |
| 94 | + $this->mime->setTXTBody($message); | |
| 95 | + if (!empty($htmlMessage)) { | |
| 96 | + $this->mime->setHTMLBody($htmlMessage); | |
| 97 | + } | |
| 98 | + | |
| 99 | + if ($mail === null) | |
| 100 | + $this->mail = Mail::factory("mail"); | |
| 101 | + else | |
| 102 | + $this->mail =& $mail; | |
| 103 | + | |
| 104 | + $this->to = $to; | |
| 105 | + $this->headers = $headers; | |
| 106 | + } | |
| 107 | + | |
| 108 | + /** | |
| 109 | + * @see Mail_Mime::setHTMLBody() | |
| 110 | + */ | |
| 111 | + function setHTMLBody($data, $isfile = false) | |
| 112 | + { | |
| 113 | + return $this->mime->setHTMLBody($data, $isfile); | |
| 114 | + } | |
| 115 | + /** | |
| 116 | + * @see Mail_Mime::addHTMLImage() | |
| 117 | + */ | |
| 118 | + function addHTMLImage($file, $c_type = 'application/octet-stream', | |
| 119 | + $name = '', $isfile = true) | |
| 120 | + { | |
| 121 | + return $this->mime->addHTMLImage($file, $c_type, $name, $isfile); | |
| 122 | + } | |
| 123 | + | |
| 124 | + /** | |
| 125 | + * @see File_Archive_Writer::writeData() | |
| 126 | + * | |
| 127 | + * This function just put the data in $currentData until the end of file | |
| 128 | + * At that time, addCurrentData is called to attach $currentData to the mail | |
| 129 | + * and to clear $currentData for a new file | |
| 130 | + */ | |
| 131 | + function writeData($data) | |
| 132 | + { | |
| 133 | + $this->currentData .= $data; | |
| 134 | + } | |
| 135 | + /** | |
| 136 | + * Called when a file is finished and must be added as attachment to the mail | |
| 137 | + */ | |
| 138 | + function addCurrentData() | |
| 139 | + { | |
| 140 | + if ($this->currentFilename === null) { | |
| 141 | + return; | |
| 142 | + } | |
| 143 | + | |
| 144 | + $error = $this->mime->addAttachment( | |
| 145 | + $this->currentData, | |
| 146 | + $this->currentMime, | |
| 147 | + $this->currentFilename, | |
| 148 | + false); | |
| 149 | + $this->currentData = ""; | |
| 150 | + return $error; | |
| 151 | + } | |
| 152 | + /** | |
| 153 | + * @see File_Archive_Writer::newFile() | |
| 154 | + */ | |
| 155 | + function newFile($filename, $stat, $mime = "application/octet-stream") | |
| 156 | + { | |
| 157 | + $error = $this->addCurrentData(); | |
| 158 | + if (PEAR::isError($error)) { | |
| 159 | + return $error; | |
| 160 | + } | |
| 161 | + | |
| 162 | + $this->currentFilename = $filename; | |
| 163 | + $this->currentMime = $mime; | |
| 164 | + } | |
| 165 | + /** | |
| 166 | + * @see File_Archive_Writer::newFileNeedsMIME() | |
| 167 | + */ | |
| 168 | + function newFileNeedsMIME() | |
| 169 | + { | |
| 170 | + return true; | |
| 171 | + } | |
| 172 | + | |
| 173 | + /** | |
| 174 | + * @see File_Archive_Writer::close() | |
| 175 | + */ | |
| 176 | + function close() | |
| 177 | + { | |
| 178 | + $error = parent::close(); | |
| 179 | + if (PEAR::isError($error)) { | |
| 180 | + return $error; | |
| 181 | + } | |
| 182 | + $error = $this->addCurrentData(); | |
| 183 | + if (PEAR::isError($error)) { | |
| 184 | + return $error; | |
| 185 | + } | |
| 186 | + | |
| 187 | + $body = $this->mime->get(); | |
| 188 | + $headers = $this->mime->headers($this->headers); | |
| 189 | + | |
| 190 | + if (!$this->mail->send( | |
| 191 | + $this->to, | |
| 192 | + $headers, | |
| 193 | + $body) | |
| 194 | + ) { | |
| 195 | + return PEAR::raiseError("Error sending mail"); | |
| 196 | + } | |
| 197 | + } | |
| 198 | +} | |
| 199 | + | |
| 200 | +?> | |
| 0 | 201 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Writer/Memory.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Write the concatenation of the files in a buffer | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: Memory.php,v 1.14 2005/06/02 12:24:43 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "File/Archive/Writer.php"; | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * Write the concatenation of the files in a buffer | |
| 36 | + */ | |
| 37 | +class File_Archive_Writer_Memory extends File_Archive_Writer | |
| 38 | +{ | |
| 39 | + /** | |
| 40 | + * @var string $data The buffer | |
| 41 | + * @access private | |
| 42 | + */ | |
| 43 | + var $data = ""; | |
| 44 | + /** | |
| 45 | + * Information about the file being written into this writer | |
| 46 | + * @access private | |
| 47 | + */ | |
| 48 | + var $filename; | |
| 49 | + var $stat; | |
| 50 | + var $mime; | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * @param reference $data If provided, the data will be output in this | |
| 54 | + * variable. Any existent data in $data will be overwritten by the | |
| 55 | + * actual data of the writer. You should not modify manually this | |
| 56 | + * variable while using this writer (you can safely use all the | |
| 57 | + * functions of the archive, like clear for example) | |
| 58 | + * @param int keptData is the offset from where to start writing in $data | |
| 59 | + * Any data located after $seek will be erased | |
| 60 | + * The default value is 0 | |
| 61 | + */ | |
| 62 | + function File_Archive_Writer_Memory(&$data, $seek = 0) | |
| 63 | + { | |
| 64 | + $this->data =& $data; | |
| 65 | + $this->data = substr($data, 0, $seek); | |
| 66 | + } | |
| 67 | + | |
| 68 | + function writeData($d) { $this->data .= $d; } | |
| 69 | + | |
| 70 | + /** | |
| 71 | + * @see File_Archive_Writer::newFile() | |
| 72 | + */ | |
| 73 | + function newFile($filename, $stat, $mime = "application/octet-stream") | |
| 74 | + { | |
| 75 | + $this->filename = $filename; | |
| 76 | + $this->stat = $stat; | |
| 77 | + $this->mime = $mime; | |
| 78 | + } | |
| 79 | + /** | |
| 80 | + * @see File_Archive_Writer::newFileNeedsMIME | |
| 81 | + */ | |
| 82 | + function newFileNeedsMIME() | |
| 83 | + { | |
| 84 | + return true; | |
| 85 | + } | |
| 86 | + | |
| 87 | + /** | |
| 88 | + * Retrieve the concatenated data | |
| 89 | + * The value is returned by reference for performance problems, but you | |
| 90 | + * should not manually modify it | |
| 91 | + * | |
| 92 | + * @return string buffer | |
| 93 | + */ | |
| 94 | + function &getData() { return $this->data; } | |
| 95 | + | |
| 96 | + /** | |
| 97 | + * Clear the buffer | |
| 98 | + */ | |
| 99 | + function clear() { $this->data = ""; } | |
| 100 | + | |
| 101 | + /** | |
| 102 | + * Returns true iif the buffer is empty | |
| 103 | + */ | |
| 104 | + function isEmpty() { return empty($this->data); } | |
| 105 | + | |
| 106 | + /** | |
| 107 | + * Create a reader from this writer | |
| 108 | + * | |
| 109 | + * @param string $filename Name of the file provided by the reader | |
| 110 | + * @param array $stat Statistics of the file provided by the reader | |
| 111 | + * @param string $mime Mime type of the file provided by the reader | |
| 112 | + * | |
| 113 | + * Any unspecified parameter will be set to the value of the last file | |
| 114 | + * written in this writer | |
| 115 | + */ | |
| 116 | + function makeReader($filename = null, $stat = null, $mime = null) | |
| 117 | + { | |
| 118 | + require_once "File/Archive/Reader/Memory.php"; | |
| 119 | + return new File_Archive_Reader_Memory( | |
| 120 | + $this->data, | |
| 121 | + $filename === null ? $this->filename : $filename, | |
| 122 | + $stat === null ? $this->stat : $stat, | |
| 123 | + $mime === null ? $this->mime : $mime); | |
| 124 | + } | |
| 125 | +} | |
| 126 | + | |
| 127 | +?> | |
| 0 | 128 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Writer/MemoryArchive.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Base class for all the archiveWriters that can only work on complete files | |
| 6 | + * (the write data function may be called with small chunks of data) | |
| 7 | + * | |
| 8 | + * PHP versions 4 and 5 | |
| 9 | + * | |
| 10 | + * This library is free software; you can redistribute it and/or | |
| 11 | + * modify it under the terms of the GNU Lesser General Public | |
| 12 | + * License as published by the Free Software Foundation; either | |
| 13 | + * version 2.1 of the License, or (at your option) any later version. | |
| 14 | + * | |
| 15 | + * This library is distributed in the hope that it will be useful, | |
| 16 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 17 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 18 | + * Lesser General Public License for more details. | |
| 19 | + * | |
| 20 | + * You should have received a copy of the GNU Lesser General Public | |
| 21 | + * License along with this library; if not, write to the Free Software | |
| 22 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 23 | + * | |
| 24 | + * @category File Formats | |
| 25 | + * @package File_Archive | |
| 26 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 27 | + * @copyright 1997-2005 The PHP Group | |
| 28 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 29 | + * @version CVS: $Id: MemoryArchive.php,v 1.16 2005/06/02 12:24:43 vincentlascaux Exp $ | |
| 30 | + * @link http://pear.php.net/package/File_Archive | |
| 31 | + */ | |
| 32 | + | |
| 33 | +require_once "File/Archive/Writer/Archive.php"; | |
| 34 | +require_once "File/Archive/Writer/Memory.php"; | |
| 35 | + | |
| 36 | +/** | |
| 37 | + * Base class for all the archiveWriters that can only work on complete files | |
| 38 | + * (the write data function may be called with small chunks of data) | |
| 39 | + */ | |
| 40 | +class File_Archive_Writer_MemoryArchive extends File_Archive_Writer_Archive | |
| 41 | +{ | |
| 42 | + /** | |
| 43 | + * @var File_Archive_Writer_Memory A buffer where the data will be put | |
| 44 | + * waiting for the file to be complete | |
| 45 | + * @access private | |
| 46 | + */ | |
| 47 | + var $buffer = ''; | |
| 48 | + /** | |
| 49 | + * @var string Name of the file which data are coming | |
| 50 | + * @access private | |
| 51 | + */ | |
| 52 | + var $currentFilename = null; | |
| 53 | + /** | |
| 54 | + * @var array Stats of the file which data are coming | |
| 55 | + * @access private | |
| 56 | + */ | |
| 57 | + var $currentStat = null; | |
| 58 | + /** | |
| 59 | + * @var string URL of the file being treated if it is a physical file | |
| 60 | + * @access private | |
| 61 | + */ | |
| 62 | + var $currentDataFile = null; | |
| 63 | + /** | |
| 64 | + * @var int Number of times newFile function has been called | |
| 65 | + * @access protected | |
| 66 | + */ | |
| 67 | + var $nbFiles = 0; | |
| 68 | + | |
| 69 | + /** | |
| 70 | + * @see File_Archive_Writer::File_Archive_Writer() | |
| 71 | + */ | |
| 72 | + function File_Archive_Writer_MemoryArchive | |
| 73 | + ($filename, &$t, $stat = array(), $autoClose = true) | |
| 74 | + { | |
| 75 | + parent::File_Archive_Writer_Archive($filename, $t, $stat, $autoClose); | |
| 76 | + } | |
| 77 | + | |
| 78 | + /** | |
| 79 | + * @see File_Archive_Writer::newFile() | |
| 80 | + */ | |
| 81 | + function newFile($filename, $stat = array(), | |
| 82 | + $mime = "application/octet-stream") | |
| 83 | + { | |
| 84 | + if ($this->nbFiles == 0) { | |
| 85 | + $error = $this->sendHeader(); | |
| 86 | + if (PEAR::isError($error)) { | |
| 87 | + return $error; | |
| 88 | + } | |
| 89 | + } else { | |
| 90 | + $error = $this->flush(); | |
| 91 | + if (PEAR::isError($error)) { | |
| 92 | + return $error; | |
| 93 | + } | |
| 94 | + } | |
| 95 | + | |
| 96 | + $this->nbFiles++; | |
| 97 | + | |
| 98 | + $this->currentFilename = $filename; | |
| 99 | + $this->currentStat = $stat; | |
| 100 | + | |
| 101 | + return true; | |
| 102 | + } | |
| 103 | + /** | |
| 104 | + * @see File_Archive_Writer::close() | |
| 105 | + */ | |
| 106 | + function close() | |
| 107 | + { | |
| 108 | + $error = $this->flush(); | |
| 109 | + if (PEAR::isError($error)) { | |
| 110 | + return $error; | |
| 111 | + } | |
| 112 | + $error = $this->sendFooter(); | |
| 113 | + if (PEAR::isError($error)) { | |
| 114 | + return $error; | |
| 115 | + } | |
| 116 | + | |
| 117 | + return parent::close(); | |
| 118 | + } | |
| 119 | + /** | |
| 120 | + * Indicate that all the data have been read from the current file | |
| 121 | + * and send it to appendFileData | |
| 122 | + * Send the current data to the appendFileData function | |
| 123 | + * | |
| 124 | + * @access private | |
| 125 | + */ | |
| 126 | + function flush() | |
| 127 | + { | |
| 128 | + if ($this->currentFilename !== null) { | |
| 129 | + if ($this->currentDataFile !== null) { | |
| 130 | + $error = $this->appendFile($this->currentFilename, | |
| 131 | + $this->currentDataFile); | |
| 132 | + } else { | |
| 133 | + $error = $this->appendFileData($this->currentFilename, | |
| 134 | + $this->currentStat, | |
| 135 | + $this->buffer); | |
| 136 | + } | |
| 137 | + if (PEAR::isError($error)) { | |
| 138 | + return $error; | |
| 139 | + } | |
| 140 | + | |
| 141 | + $this->currentFilename = null; | |
| 142 | + $this->currentDataFile = null; | |
| 143 | + $this->buffer = ''; | |
| 144 | + } | |
| 145 | + } | |
| 146 | + /** | |
| 147 | + * @see File_Archive_Writer::writeData() | |
| 148 | + */ | |
| 149 | + function writeData($data) | |
| 150 | + { | |
| 151 | + if ($this->currentDataFile !== null) { | |
| 152 | + $this->buffer .= file_get_contents($this->currentDataFile); | |
| 153 | + $this->currentDataFile = null; | |
| 154 | + } | |
| 155 | + $this->buffer .= $data; | |
| 156 | + } | |
| 157 | + /** | |
| 158 | + * @see File_Archive_Writer::writeFile() | |
| 159 | + */ | |
| 160 | + function writeFile($filename) | |
| 161 | + { | |
| 162 | + if ($this->currentDataFile === null && empty($this->buffer)) { | |
| 163 | + $this->currentDataFile = $filename; | |
| 164 | + } else { | |
| 165 | + if ($this->currentDataFile !== null) { | |
| 166 | + $this->buffer .= file_get_contents($this->currentDataFile); | |
| 167 | + $this->currentDataFile = null; | |
| 168 | + } | |
| 169 | + $this->buffer .= file_get_contents($filename); | |
| 170 | + } | |
| 171 | + } | |
| 172 | + | |
| 173 | +//MUST REWRITE FUNCTIONS | |
| 174 | + /** | |
| 175 | + * The subclass must treat the data $data | |
| 176 | + * $data is the entire data of the filename $filename | |
| 177 | + * $stat is the stat of the file | |
| 178 | + * | |
| 179 | + * @access protected | |
| 180 | + */ | |
| 181 | + function appendFileData($filename, $stat, &$data) { } | |
| 182 | + | |
| 183 | +//SHOULD REWRITE FUNCTIONS | |
| 184 | + /** | |
| 185 | + * The subclass may rewrite the sendHeader function if it needs to execute | |
| 186 | + * code before the first file | |
| 187 | + * | |
| 188 | + * @access protected | |
| 189 | + */ | |
| 190 | + function sendHeader() { } | |
| 191 | + /** | |
| 192 | + * The subclass may rewrite the sendFooter function if it needs to execute | |
| 193 | + * code before closing the archive | |
| 194 | + * | |
| 195 | + * @access protected | |
| 196 | + */ | |
| 197 | + function sendFooter() { } | |
| 198 | + /** | |
| 199 | + * The subclass may rewrite this class if it knows an efficient way to treat | |
| 200 | + * a physical file. | |
| 201 | + * | |
| 202 | + * @access protected | |
| 203 | + */ | |
| 204 | + function appendFile($filename, $dataFilename) | |
| 205 | + { | |
| 206 | + return $this->appendFileData( | |
| 207 | + $filename, | |
| 208 | + stat($dataFilename), | |
| 209 | + file_get_contents($dataFilename)); | |
| 210 | + } | |
| 211 | +} | |
| 212 | + | |
| 213 | +?> | |
| 0 | 214 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Writer/Multi.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Write to several writers | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: Multi.php,v 1.10 2005/06/05 18:19:33 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "File/Archive/Writer.php"; | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * Write to several writers | |
| 36 | + */ | |
| 37 | +class File_Archive_Writer_Multi extends File_Archive_Writer | |
| 38 | +{ | |
| 39 | + /** | |
| 40 | + * @var File_Archive_Writer_Writer Data will be copied to these two writers | |
| 41 | + * @access private | |
| 42 | + */ | |
| 43 | + var $writers; | |
| 44 | + | |
| 45 | + function addWriter(&$writer) | |
| 46 | + { | |
| 47 | + $this->writers[] =& $writer; | |
| 48 | + } | |
| 49 | + | |
| 50 | + /** | |
| 51 | + * @see File_Archive_Writer::newFile() | |
| 52 | + */ | |
| 53 | + function newFile($filename, $stat = array(), $mime = "application/octet-stream") | |
| 54 | + { | |
| 55 | + $globalError = null; | |
| 56 | + foreach($this->writers as $key => $foo) { | |
| 57 | + $error = $this->writers[$key]->newFile($filename, $stat, $mime); | |
| 58 | + if (PEAR::isError($error)) { | |
| 59 | + $globalError = $error; | |
| 60 | + } | |
| 61 | + } | |
| 62 | + if (PEAR::isError($globalError)) { | |
| 63 | + return $globalError; | |
| 64 | + } | |
| 65 | + } | |
| 66 | + /** | |
| 67 | + * @see File_Archive_Writer::newFileNeedsMIME() | |
| 68 | + */ | |
| 69 | + function newFileNeedsMIME() | |
| 70 | + { | |
| 71 | + foreach($this->writers as $key => $foo) { | |
| 72 | + if ($this->writers[$key]->newFileNeedsMIME()) { | |
| 73 | + return true; | |
| 74 | + } | |
| 75 | + } | |
| 76 | + return false; | |
| 77 | + } | |
| 78 | + | |
| 79 | + /** | |
| 80 | + * @see File_Archive_Writer::writeData() | |
| 81 | + */ | |
| 82 | + function writeData($data) | |
| 83 | + { | |
| 84 | + $globalError = null; | |
| 85 | + foreach($this->writers as $key => $foo) { | |
| 86 | + $error = $this->writers[$key]->writeData($data); | |
| 87 | + if (PEAR::isError($error)) { | |
| 88 | + $globalError = $error; | |
| 89 | + } | |
| 90 | + } | |
| 91 | + if (PEAR::isError($globalError)) { | |
| 92 | + return $globalError; | |
| 93 | + } | |
| 94 | + } | |
| 95 | + | |
| 96 | + /** | |
| 97 | + * @see File_Archive_Writer::writeFile() | |
| 98 | + */ | |
| 99 | + function writeFile($filename) | |
| 100 | + { | |
| 101 | + $globalError = null; | |
| 102 | + foreach($this->writers as $key => $foo) { | |
| 103 | + $error = $this->writers[$key]->writeFile($filename); | |
| 104 | + if (PEAR::isError($error)) { | |
| 105 | + $globalError = $error; | |
| 106 | + } | |
| 107 | + } | |
| 108 | + if (PEAR::isError($globalError)) { | |
| 109 | + return $globalError; | |
| 110 | + } | |
| 111 | + } | |
| 112 | + | |
| 113 | + /** | |
| 114 | + * @see File_Archive_Writer::close() | |
| 115 | + */ | |
| 116 | + function close() | |
| 117 | + { | |
| 118 | + $globalError = null; | |
| 119 | + foreach($this->writers as $key => $foo) { | |
| 120 | + $error = $this->writers[$key]->close(); | |
| 121 | + if (PEAR::isError($error)) { | |
| 122 | + $globalError = $error; | |
| 123 | + } | |
| 124 | + } | |
| 125 | + if (PEAR::isError($globalError)) { | |
| 126 | + return $globalError; | |
| 127 | + } | |
| 128 | + } | |
| 129 | +} | |
| 130 | +?> | |
| 0 | 131 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Writer/Output.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Writer to the standard output | |
| 6 | + * It will concatenate the files that it receive | |
| 7 | + * It may send some headers, but will do so only for the first file | |
| 8 | + * | |
| 9 | + * PHP versions 4 and 5 | |
| 10 | + * | |
| 11 | + * This library is free software; you can redistribute it and/or | |
| 12 | + * modify it under the terms of the GNU Lesser General Public | |
| 13 | + * License as published by the Free Software Foundation; either | |
| 14 | + * version 2.1 of the License, or (at your option) any later version. | |
| 15 | + * | |
| 16 | + * This library is distributed in the hope that it will be useful, | |
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 19 | + * Lesser General Public License for more details. | |
| 20 | + * | |
| 21 | + * You should have received a copy of the GNU Lesser General Public | |
| 22 | + * License along with this library; if not, write to the Free Software | |
| 23 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 24 | + * | |
| 25 | + * @category File Formats | |
| 26 | + * @package File_Archive | |
| 27 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 28 | + * @copyright 1997-2005 The PHP Group | |
| 29 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 30 | + * @version CVS: $Id: Output.php,v 1.8 2005/05/30 15:25:14 vincentlascaux Exp $ | |
| 31 | + * @link http://pear.php.net/package/File_Archive | |
| 32 | + */ | |
| 33 | + | |
| 34 | +require_once "File/Archive/Writer.php"; | |
| 35 | + | |
| 36 | +/** | |
| 37 | + * Writer to the standard output | |
| 38 | + * It will concatenate the files that it receive | |
| 39 | + * It may send some headers, but will do so only for the first file | |
| 40 | + */ | |
| 41 | +class File_Archive_Writer_Output extends File_Archive_Writer | |
| 42 | +{ | |
| 43 | + /** | |
| 44 | + * @var bool If true, the Content-type and Content-disposition headers | |
| 45 | + * will be sent. The file will be considered as an attachment and | |
| 46 | + * the MIME will be deduced from its extension | |
| 47 | + * @access private | |
| 48 | + */ | |
| 49 | + var $sendHeaders; | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * @param $sendHeaders see the variable | |
| 53 | + */ | |
| 54 | + function File_Archive_Writer_Output($sendHeaders = true) | |
| 55 | + { | |
| 56 | + $this->sendHeaders = $sendHeaders; | |
| 57 | + } | |
| 58 | + /** | |
| 59 | + * @see File_Archive_Writer::newFile() | |
| 60 | + */ | |
| 61 | + function newFile($filename, $stat = array(), $mime = "application/octet-stream") | |
| 62 | + { | |
| 63 | + if ($this->sendHeaders) { | |
| 64 | + if(headers_sent()) { | |
| 65 | + return PEAR::raiseError( | |
| 66 | + 'The headers have already been sent. '. | |
| 67 | + 'Use File_Archive::toOutput(false) to write '. | |
| 68 | + 'to output without sending headers'); | |
| 69 | + } | |
| 70 | + | |
| 71 | + header("Content-type: $mime"); | |
| 72 | + header("Content-disposition: attachment; filename=$filename"); | |
| 73 | + $this->sendHeaders = false; | |
| 74 | + } | |
| 75 | + } | |
| 76 | + /** | |
| 77 | + * @see File_Archive_Writer::newFileNeedsMIME | |
| 78 | + */ | |
| 79 | + function newFileNeedsMIME() | |
| 80 | + { | |
| 81 | + return $this->sendHeaders; | |
| 82 | + } | |
| 83 | + /** | |
| 84 | + * @see File_Archive_Writer::writeData() | |
| 85 | + */ | |
| 86 | + function writeData($data) { echo $data; } | |
| 87 | + /** | |
| 88 | + * @see File_Archive_Writer::writeFile() | |
| 89 | + */ | |
| 90 | + function writeFile($filename) { readfile($filename); } | |
| 91 | +} | |
| 92 | + | |
| 93 | +?> | |
| 0 | 94 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Writer/Tar.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Write the files as a TAR archive | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: Tar.php,v 1.18 2005/06/02 12:24:43 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "File/Archive/Writer/Archive.php"; | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * Write the files as a TAR archive | |
| 36 | + */ | |
| 37 | +class File_Archive_Writer_Tar extends File_Archive_Writer_Archive | |
| 38 | +{ | |
| 39 | + var $buffer; | |
| 40 | + var $useBuffer; | |
| 41 | + | |
| 42 | + var $filename = null; | |
| 43 | + var $stats = null; | |
| 44 | + | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * Creates the TAR header for a file | |
| 48 | + * | |
| 49 | + * @param string $filename name of the file | |
| 50 | + * @param array $stat statistics of the file | |
| 51 | + * @return string A 512 byte header for the file | |
| 52 | + * @access private | |
| 53 | + */ | |
| 54 | + function tarHeader($filename, $stat) | |
| 55 | + { | |
| 56 | + $mode = isset($stat[2]) ? $stat[2] : 0x8000; | |
| 57 | + $uid = isset($stat[4]) ? $stat[4] : 0; | |
| 58 | + $gid = isset($stat[5]) ? $stat[5] : 0; | |
| 59 | + $size = $stat[7]; | |
| 60 | + $time = isset($stat[9]) ? $stat[9] : time(); | |
| 61 | + $link = ""; | |
| 62 | + | |
| 63 | + if ($mode & 0x4000) { | |
| 64 | + $type = 5; // Directory | |
| 65 | + } else if ($mode & 0x8000) { | |
| 66 | + $type = 0; // Regular | |
| 67 | + } else if ($mode & 0xA000) { | |
| 68 | + $type = 1; // Link | |
| 69 | + $link = @readlink($current); | |
| 70 | + } else { | |
| 71 | + $type = 9; // Unknown | |
| 72 | + } | |
| 73 | + | |
| 74 | + $filePrefix = ''; | |
| 75 | + if (strlen($filename) > 255) { | |
| 76 | + return PEAR::raiseError( | |
| 77 | + "$filename is too long to be put in a tar archive" | |
| 78 | + ); | |
| 79 | + } else if (strlen($filename) > 100) { | |
| 80 | + $filePrefix = substr($filename, 0, strlen($filename)-100); | |
| 81 | + $filename = substr($filename, -100); | |
| 82 | + } | |
| 83 | + | |
| 84 | + $blockbeg = pack("a100a8a8a8a12a12", | |
| 85 | + $filename, | |
| 86 | + decoct($mode), | |
| 87 | + sprintf("%6s ",decoct($uid)), | |
| 88 | + sprintf("%6s ",decoct($gid)), | |
| 89 | + sprintf("%11s ",decoct($size)), | |
| 90 | + sprintf("%11s ",decoct($time)) | |
| 91 | + ); | |
| 92 | + | |
| 93 | + $blockend = pack("a1a100a6a2a32a32a8a8a155a12", | |
| 94 | + $type, | |
| 95 | + $link, | |
| 96 | + "ustar", | |
| 97 | + "00", | |
| 98 | + "Unknown", | |
| 99 | + "Unknown", | |
| 100 | + "", | |
| 101 | + "", | |
| 102 | + $filePrefix, | |
| 103 | + ""); | |
| 104 | + | |
| 105 | + $checksum = 8*ord(" "); | |
| 106 | + for ($i = 0; $i < 148; $i++) { | |
| 107 | + $checksum += ord($blockbeg{$i}); | |
| 108 | + } | |
| 109 | + for ($i = 0; $i < 356; $i++) { | |
| 110 | + $checksum += ord($blockend{$i}); | |
| 111 | + } | |
| 112 | + | |
| 113 | + $checksum = pack("a8",sprintf("%6s ",decoct($checksum))); | |
| 114 | + | |
| 115 | + return $blockbeg . $checksum . $blockend; | |
| 116 | + } | |
| 117 | + /** | |
| 118 | + * Creates the TAR footer for a file | |
| 119 | + * | |
| 120 | + * @param int $size the size of the data that has been written to the TAR | |
| 121 | + * @return string A string made of less than 512 characteres to fill the | |
| 122 | + * last 512 byte long block | |
| 123 | + * @access private | |
| 124 | + */ | |
| 125 | + function tarFooter($size) | |
| 126 | + { | |
| 127 | + if ($size % 512 > 0) { | |
| 128 | + return pack("a".(512 - $size%512), ""); | |
| 129 | + } else { | |
| 130 | + return ""; | |
| 131 | + } | |
| 132 | + } | |
| 133 | + | |
| 134 | + function flush() | |
| 135 | + { | |
| 136 | + if ($this->filename !== null) { | |
| 137 | + if ($this->useBuffer) { | |
| 138 | + $this->stats[7] = strlen($this->buffer); | |
| 139 | + | |
| 140 | + $this->innerWriter->writeData( | |
| 141 | + $this->tarHeader($this->filename, $this->stats) | |
| 142 | + ); | |
| 143 | + $this->innerWriter->writeData( | |
| 144 | + $this->buffer | |
| 145 | + ); | |
| 146 | + } | |
| 147 | + $this->innerWriter->writeData( | |
| 148 | + $this->tarFooter($this->stats[7]) | |
| 149 | + ); | |
| 150 | + } | |
| 151 | + $this->buffer = ""; | |
| 152 | + } | |
| 153 | + | |
| 154 | + function newFile($filename, $stats = array(), | |
| 155 | + $mime = "application/octet-stream") | |
| 156 | + { | |
| 157 | + $this->flush(); | |
| 158 | + | |
| 159 | + $this->useBuffer = !isset($stats[7]); | |
| 160 | + $this->filename = $filename; | |
| 161 | + $this->stats = $stats; | |
| 162 | + | |
| 163 | + if (!$this->useBuffer) { | |
| 164 | + return $this->innerWriter->writeData( | |
| 165 | + $this->tarHeader($filename, $stats) | |
| 166 | + ); | |
| 167 | + } | |
| 168 | + } | |
| 169 | + | |
| 170 | + /** | |
| 171 | + * @see File_Archive_Writer::close() | |
| 172 | + */ | |
| 173 | + function close() | |
| 174 | + { | |
| 175 | + $this->flush(); | |
| 176 | + $this->innerWriter->writeData(pack("a1024", "")); | |
| 177 | + parent::close(); | |
| 178 | + } | |
| 179 | + /** | |
| 180 | + * @see File_Archive_Writer::writeData() | |
| 181 | + */ | |
| 182 | + function writeData($data) | |
| 183 | + { | |
| 184 | + if ($this->useBuffer) { | |
| 185 | + $this->buffer .= $data; | |
| 186 | + } else { | |
| 187 | + $this->innerWriter->writeData($data); | |
| 188 | + } | |
| 189 | + | |
| 190 | + } | |
| 191 | + /** | |
| 192 | + * @see File_Archive_Writer::writeFile() | |
| 193 | + */ | |
| 194 | + function writeFile($filename) | |
| 195 | + { | |
| 196 | + if ($this->useBuffer) { | |
| 197 | + $this->buffer .= file_get_contents($filename); | |
| 198 | + } else { | |
| 199 | + $this->innerWriter->writeFile($filename); | |
| 200 | + } | |
| 201 | + } | |
| 202 | + /** | |
| 203 | + * @see File_Archive_Writer::getMime() | |
| 204 | + */ | |
| 205 | + function getMime() { return "application/x-tar"; } | |
| 206 | +} | |
| 207 | + | |
| 208 | + | |
| 209 | +/** | |
| 210 | + * A tar archive cannot contain files with name of folders longer than 255 chars | |
| 211 | + * This filter removes them | |
| 212 | + * | |
| 213 | + * @see File_Archive_Predicate, File_Archive_Reader_Filter | |
| 214 | + */ | |
| 215 | +require_once "File/Archive/Predicate.php"; | |
| 216 | +class File_Archive_Predicate_TARCompatible extends File_Archive_Predicate | |
| 217 | +{ | |
| 218 | + function isTrue($source) | |
| 219 | + { | |
| 220 | + return strlen($source->getFilename()) <= 255; | |
| 221 | + } | |
| 222 | +} | |
| 223 | + | |
| 224 | +?> | |
| 0 | 225 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Writer/UniqueAppender.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * A writer wrapper that will remove the files the eventual duplicate | |
| 6 | + * files from the reader to keep only the new ones | |
| 7 | + * When calling newFile, the file with the highest index in the reader | |
| 8 | + * and the same filename will be removed | |
| 9 | + * Note that it ensure that the archive won't have duplicates only if | |
| 10 | + * it didn't have duplicates before, and if no two calls to newFile with | |
| 11 | + * the same filename is done | |
| 12 | + * | |
| 13 | + * This library is free software; you can redistribute it and/or | |
| 14 | + * modify it under the terms of the GNU Lesser General Public | |
| 15 | + * License as published by the Free Software Foundation; either | |
| 16 | + * version 2.1 of the License, or (at your option) any later version. | |
| 17 | + * | |
| 18 | + * This library is distributed in the hope that it will be useful, | |
| 19 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 20 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 21 | + * Lesser General Public License for more details. | |
| 22 | + * | |
| 23 | + * You should have received a copy of the GNU Lesser General Public | |
| 24 | + * License along with this library; if not, write to the Free Software | |
| 25 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 26 | + * | |
| 27 | + * @category File Formats | |
| 28 | + * @package File_Archive | |
| 29 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 30 | + * @copyright 1997-2005 The PHP Group | |
| 31 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 32 | + * @version CVS: $Id: UniqueAppender.php,v 1.1 2005/05/30 19:44:53 vincentlascaux Exp $ | |
| 33 | + * @link http://pear.php.net/package/File_Archive | |
| 34 | + */ | |
| 35 | + | |
| 36 | +require_once "File/Archive/Writer.php"; | |
| 37 | +require_once "File/Archive/Reader.php"; | |
| 38 | +require_once "File/Archive/Predicate/Index.php"; | |
| 39 | + | |
| 40 | +/** | |
| 41 | + * A writer wrapper that will remove the files the eventual duplicate | |
| 42 | + * files from the reader to keep only the new ones | |
| 43 | + * If there were already some duplications in the provided reader, not | |
| 44 | + * all duplication will be removed | |
| 45 | + * If you use newFile with the same filename several file, only the latest | |
| 46 | + * write will be kept (no time comparision is done) | |
| 47 | + */ | |
| 48 | +class File_Archive_Writer_UniqueAppender extends File_Archive_Writer | |
| 49 | +{ | |
| 50 | + var $reader; | |
| 51 | + var $writer; | |
| 52 | + var $fileList = array(); | |
| 53 | + var $toDelete = array(); | |
| 54 | + | |
| 55 | + /** | |
| 56 | + * Construct a unique writer that will write to the specified writer | |
| 57 | + * and remove duplicate files from the reader on close | |
| 58 | + */ | |
| 59 | + function File_Archive_Writer_UniqueAppender(&$reader) | |
| 60 | + { | |
| 61 | + $reader->close(); | |
| 62 | + $pos = 0; | |
| 63 | + while ($reader->next()) { | |
| 64 | + $this->fileList[$reader->getFilename()] = $pos++; | |
| 65 | + } | |
| 66 | + | |
| 67 | + $this->reader =& $reader; | |
| 68 | + $this->writer = $reader->makeAppendWriter(); | |
| 69 | + } | |
| 70 | + | |
| 71 | + /** | |
| 72 | + * @see File_Archive_Writer::newFile() | |
| 73 | + */ | |
| 74 | + function newFile($filename, $stat = array(), $mime = "application/octet-stream") | |
| 75 | + { | |
| 76 | + if (isset($this->fileList[$filename])) { | |
| 77 | + $this->toDelete[$this->fileList[$filename]] = true; | |
| 78 | + } | |
| 79 | + | |
| 80 | + return $this->writer->newFile($filename, $stat, $mime); | |
| 81 | + } | |
| 82 | + | |
| 83 | + /** | |
| 84 | + * @see File_Archive_Writer::newFromTempFile() | |
| 85 | + */ | |
| 86 | + function newFromTempFile($tmpfile, $filename, $stat = array(), $mime = "application/octet-stream") | |
| 87 | + { | |
| 88 | + if (isset($this->fileList[$filename])) { | |
| 89 | + $this->toDelete[$this->fileList[$filename]] = true; | |
| 90 | + } | |
| 91 | + | |
| 92 | + return $this->writer->newFromTempFile($tmpfile, $filename, $stat, $mime); | |
| 93 | + } | |
| 94 | + | |
| 95 | + /** | |
| 96 | + * @see File_Archive_Writer::newFileNeedsMIME() | |
| 97 | + */ | |
| 98 | + function newFileNeedsMIME() | |
| 99 | + { | |
| 100 | + return $this->writer->newFileNeedsMIME(); | |
| 101 | + } | |
| 102 | + | |
| 103 | + /** | |
| 104 | + * @see File_Archive_Writer::writeData() | |
| 105 | + */ | |
| 106 | + function writeData($data) | |
| 107 | + { | |
| 108 | + return $this->writer->writeData($data); | |
| 109 | + } | |
| 110 | + | |
| 111 | + /** | |
| 112 | + * @see File_Archive_Writer::writeFile() | |
| 113 | + */ | |
| 114 | + function writeFile($filename) | |
| 115 | + { | |
| 116 | + return $this->writer->writeFile($filename); | |
| 117 | + } | |
| 118 | + | |
| 119 | + /** | |
| 120 | + * Close the writer, eventually flush the data, write the footer... | |
| 121 | + * This function must be called before the end of the script | |
| 122 | + */ | |
| 123 | + function close() | |
| 124 | + { | |
| 125 | + $error = $this->writer->close(); | |
| 126 | + if (PEAR::isError($error)) { | |
| 127 | + return $error; | |
| 128 | + } | |
| 129 | + | |
| 130 | + if (!empty($this->toDelete)) { | |
| 131 | + $tmp = $this->reader->makeWriterRemoveFiles( | |
| 132 | + new File_Archive_Predicate_Index($this->toDelete) | |
| 133 | + ); | |
| 134 | + if (PEAR::isError($tmp)) { | |
| 135 | + return $tmp; | |
| 136 | + } | |
| 137 | + | |
| 138 | + return $tmp->close(); | |
| 139 | + } | |
| 140 | + } | |
| 141 | +} | |
| 142 | + | |
| 143 | +?> | |
| 0 | 144 | \ No newline at end of file | ... | ... |
thirdparty/pear/File/Archive/Writer/Zip.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * ZIP archive writer | |
| 6 | + * | |
| 7 | + * PHP versions 4 and 5 | |
| 8 | + * | |
| 9 | + * This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with this library; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA | |
| 22 | + * | |
| 23 | + * @category File Formats | |
| 24 | + * @package File_Archive | |
| 25 | + * @author Vincent Lascaux <vincentlascaux@php.net> | |
| 26 | + * @copyright 1997-2005 The PHP Group | |
| 27 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL | |
| 28 | + * @version CVS: $Id: Zip.php,v 1.20 2005/08/15 18:03:03 vincentlascaux Exp $ | |
| 29 | + * @link http://pear.php.net/package/File_Archive | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once "File/Archive/Writer/MemoryArchive.php"; | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * ZIP archive writer | |
| 36 | + */ | |
| 37 | +class File_Archive_Writer_Zip extends File_Archive_Writer_MemoryArchive | |
| 38 | +{ | |
| 39 | + /** | |
| 40 | + * @var int Compression level | |
| 41 | + * @access private | |
| 42 | + */ | |
| 43 | + var $compressionLevel; | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * @var int Current position in the writer | |
| 47 | + * @access private | |
| 48 | + */ | |
| 49 | + var $offset = 0; | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * @var string Optionnal comment to add to the zip | |
| 53 | + * @access private | |
| 54 | + */ | |
| 55 | + var $comment = ""; | |
| 56 | + | |
| 57 | + /** | |
| 58 | + * @var string Data written at the end of the ZIP file | |
| 59 | + * @access private | |
| 60 | + */ | |
| 61 | + var $central = ""; | |
| 62 | + | |
| 63 | + function File_Archive_Writer_Zip($filename, &$innerWriter, | |
| 64 | + $stat=array(), $autoClose = true) | |
| 65 | + { | |
| 66 | + global $_File_Archive_Options; | |
| 67 | + parent::File_Archive_Writer_MemoryArchive( | |
| 68 | + $filename, $innerWriter, $stat, $autoClose | |
| 69 | + ); | |
| 70 | + | |
| 71 | + $this->compressionLevel = File_Archive::getOption('zipCompressionLevel', 9); | |
| 72 | + } | |
| 73 | + | |
| 74 | + /** | |
| 75 | + * Change the level of the compression. This may be done between two files | |
| 76 | + * | |
| 77 | + * @param Int $compressionLevel New compression level from 0 to 9 | |
| 78 | + */ | |
| 79 | + function setCompressionLevel($compressionLevel) | |
| 80 | + { | |
| 81 | + $this->compressionLevel = $compressionLevel; | |
| 82 | + } | |
| 83 | + | |
| 84 | + /** | |
| 85 | + * Set a comment on the ZIP file | |
| 86 | + */ | |
| 87 | + function setComment($comment) { $this->comment = $comment; } | |
| 88 | + | |
| 89 | + /** | |
| 90 | + * @param int $time Unix timestamp of the date to convert | |
| 91 | + * @return the date formated as a ZIP date | |
| 92 | + */ | |
| 93 | + function getMTime($time) | |
| 94 | + { | |
| 95 | + $mtime = ($time !== null ? getdate($time) : getdate()); | |
| 96 | + $mtime = preg_replace( | |
| 97 | + "/(..){1}(..){1}(..){1}(..){1}/", | |
| 98 | + "\\x\\4\\x\\3\\x\\2\\x\\1", | |
| 99 | + dechex(($mtime['year']-1980<<25)| | |
| 100 | + ($mtime['mon' ]<<21)| | |
| 101 | + ($mtime['mday' ]<<16)| | |
| 102 | + ($mtime['hours' ]<<11)| | |
| 103 | + ($mtime['minutes']<<5)| | |
| 104 | + ($mtime['seconds']>>1))); | |
| 105 | + eval('$mtime = "'.$mtime.'";'); | |
| 106 | + return $mtime; | |
| 107 | + } | |
| 108 | + | |
| 109 | + /** | |
| 110 | + * Inform the archive that $filename is present. | |
| 111 | + * Consequences are the same as appendFileData, but no data is output | |
| 112 | + * to the inner writer. | |
| 113 | + * This is used by File_Archive_Reader_Zip::makeWriter() | |
| 114 | + * | |
| 115 | + * @param string $filename name of the file | |
| 116 | + * @param array $stat stats of the file, indexes 9 and 7 must be present | |
| 117 | + * @param int $crc32 checksum of the file | |
| 118 | + * @param int $compLength length of the compressed data | |
| 119 | + */ | |
| 120 | + function alreadyWrittenFile($filename, $stat, $crc32, $complength) | |
| 121 | + { | |
| 122 | + $filename = preg_replace("/^(\.{1,2}(\/|\\\))+/","",$filename); | |
| 123 | + | |
| 124 | + $mtime = $this->getMTime(isset($stat[9]) ? $stat[9] : null); | |
| 125 | + $normlength = $stat[7]; | |
| 126 | + | |
| 127 | + $this->nbFiles++; | |
| 128 | + | |
| 129 | + $this->central .= "\x50\x4b\x01\x02\x00\x00\x14\x00\x00\x00\x08\x00". | |
| 130 | + $mtime. | |
| 131 | + pack("VVVvvvvvVV", | |
| 132 | + $crc32, $complength, $normlength, | |
| 133 | + strlen($filename), 0x00,0x00,0x00,0x00, | |
| 134 | + 0x0000,$this->offset). | |
| 135 | + $filename; | |
| 136 | + | |
| 137 | + $this->offset += 30 + strlen($filename) + $complength; | |
| 138 | + } | |
| 139 | + | |
| 140 | + /** | |
| 141 | + * @see File_Archive_Writer_MemoryArchive::appendFileData() | |
| 142 | + * @access protected | |
| 143 | + */ | |
| 144 | + function appendFileData($filename, $stat, $data) | |
| 145 | + { | |
| 146 | + $crc32 = crc32($data); | |
| 147 | + $normlength = strlen($data); | |
| 148 | + $data = gzcompress($data,$this->compressionLevel); | |
| 149 | + $data = substr($data,2,strlen($data)-6); | |
| 150 | + | |
| 151 | + return $this->appendCompressedData($filename, $stat, $data, $crc32, $normlength); | |
| 152 | + } | |
| 153 | + | |
| 154 | + function appendCompressedData($filename, $stat, $data, $crc32, $normlength) | |
| 155 | + { | |
| 156 | + $filename = preg_replace("/^(\.{1,2}(\/|\\\))+/","",$filename); | |
| 157 | + $mtime = $this->getMTime(isset($stat[9]) ? $stat[9] : null); | |
| 158 | + | |
| 159 | + $complength = strlen($data); | |
| 160 | + | |
| 161 | + $zipData = "\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00". | |
| 162 | + $mtime. | |
| 163 | + pack("VVVvv", | |
| 164 | + $crc32, | |
| 165 | + $complength, | |
| 166 | + $normlength, | |
| 167 | + strlen($filename), | |
| 168 | + 0x00). | |
| 169 | + $filename. | |
| 170 | + $data; | |
| 171 | + | |
| 172 | + $error = $this->innerWriter->writeData($zipData); | |
| 173 | + if (PEAR::isError($error)) { | |
| 174 | + return $error; | |
| 175 | + } | |
| 176 | + | |
| 177 | + $this->central .= "\x50\x4b\x01\x02\x00\x00\x14\x00\x00\x00\x08\x00". | |
| 178 | + $mtime. | |
| 179 | + pack("VVVvvvvvVV", | |
| 180 | + $crc32, $complength, $normlength, | |
| 181 | + strlen($filename), 0x00,0x00,0x00,0x00, | |
| 182 | + 0x0000,$this->offset). | |
| 183 | + $filename; | |
| 184 | + | |
| 185 | + $this->offset += strlen($zipData); | |
| 186 | + } | |
| 187 | + | |
| 188 | + function appendFile($filename, $dataFilename) | |
| 189 | + { | |
| 190 | + //Try to read from the cache | |
| 191 | + $cache = File_Archive::getOption('cache', null); | |
| 192 | + if ($cache !== null && $this->compressionLevel > 0) { | |
| 193 | + $id = realpath($dataFilename); | |
| 194 | + $id = urlencode($id); | |
| 195 | + $id = str_replace('_', '%5F', $id); | |
| 196 | + | |
| 197 | + $group = 'FileArchiveZip'.$this->compressionLevel; | |
| 198 | + $mtime = filemtime($dataFilename); | |
| 199 | + | |
| 200 | + //Tries to read from cache | |
| 201 | + if (($data = $cache->get($id, $group)) !== false) { | |
| 202 | + $info = unpack('Vmtime/Vcrc/Vnlength', substr($data, 0, 12)); | |
| 203 | + $data = substr($data, 12); | |
| 204 | + } | |
| 205 | + | |
| 206 | + //If cache failed or file modified since then | |
| 207 | + if ($data === false || | |
| 208 | + $info['mtime'] != $mtime) { | |
| 209 | + | |
| 210 | + $data = file_get_contents($dataFilename); | |
| 211 | + | |
| 212 | + $info = array( | |
| 213 | + 'crc' => crc32($data), | |
| 214 | + 'nlength' => strlen($data), | |
| 215 | + 'mtime' => $mtime | |
| 216 | + ); | |
| 217 | + | |
| 218 | + $data = gzcompress($data,$this->compressionLevel); | |
| 219 | + $data = substr($data,2,strlen($data)-6); | |
| 220 | + $data = pack('VVV', $info['mtime'], $info['crc'], $info['nlength']).$data; | |
| 221 | + $cache->save($data, $id, $group); | |
| 222 | + } | |
| 223 | + | |
| 224 | + return $this->appendCompressedData( | |
| 225 | + $filename, | |
| 226 | + stat($dataFilename), | |
| 227 | + $data, | |
| 228 | + $info['crc'], | |
| 229 | + $info['nlength'] | |
| 230 | + ); | |
| 231 | + | |
| 232 | + } | |
| 233 | + | |
| 234 | + //If no cache system, use the standard way | |
| 235 | + return parent::appendFile($filename, $dataFilename); | |
| 236 | + } | |
| 237 | + | |
| 238 | + /** | |
| 239 | + * @see File_Archive_Writer_MemoryArchive::sendFooter() | |
| 240 | + * @access protected | |
| 241 | + */ | |
| 242 | + function sendFooter() | |
| 243 | + { | |
| 244 | + return $this->innerWriter->writeData( | |
| 245 | + $this->central. | |
| 246 | + "\x50\x4b\x05\x06\x00\x00\x00\x00". | |
| 247 | + pack("vvVVv", | |
| 248 | + $this->nbFiles,$this->nbFiles, | |
| 249 | + strlen($this->central),$this->offset, | |
| 250 | + strlen($this->comment)). | |
| 251 | + $this->comment | |
| 252 | + ); | |
| 253 | + } | |
| 254 | + /** | |
| 255 | + * @see File_Archive_Writer::getMime() | |
| 256 | + */ | |
| 257 | + function getMime() { return "application/zip"; } | |
| 258 | +} | |
| 259 | + | |
| 260 | +?> | |
| 0 | 261 | \ No newline at end of file | ... | ... |
thirdparty/pear/MIME/Type.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4: */ | |
| 3 | +// +----------------------------------------------------------------------+ | |
| 4 | +// | PHP version 4 | | |
| 5 | +// +----------------------------------------------------------------------+ | |
| 6 | +// | Copyright (c) 1997-2002 The PHP Group | | |
| 7 | +// +----------------------------------------------------------------------+ | |
| 8 | +// | This source file is subject to version 3.0 of the PHP license, | | |
| 9 | +// | that is bundled with this package in the file LICENSE, and is | | |
| 10 | +// | available at through the world-wide-web at | | |
| 11 | +// | http://www.php.net/license/3_0.txt. | | |
| 12 | +// | If you did not receive a copy of the PHP license and are unable to | | |
| 13 | +// | obtain it through the world-wide-web, please send a note to | | |
| 14 | +// | license@php.net so we can mail you a copy immediately. | | |
| 15 | +// +----------------------------------------------------------------------+ | |
| 16 | +// | Authors: Ian Eure <ieure@php.net> | | |
| 17 | +// +----------------------------------------------------------------------+ | |
| 18 | +// | |
| 19 | +// $Id: Type.php,v 1.2 2004/08/07 22:19:04 ieure Exp $ | |
| 20 | + | |
| 21 | +require_once 'PEAR.php'; | |
| 22 | + | |
| 23 | +$_fileCmd = &PEAR::getStaticProperty('MIME_Type', 'fileCmd'); | |
| 24 | +$_fileCmd = 'file'; | |
| 25 | + | |
| 26 | +/** | |
| 27 | + * Class for working with MIME types | |
| 28 | + * | |
| 29 | + * @version @version@ | |
| 30 | + * @package @package@ | |
| 31 | + * @author Ian Eure <ieure@php.net> | |
| 32 | + */ | |
| 33 | +class MIME_Type { | |
| 34 | + /** | |
| 35 | + * The MIME media type | |
| 36 | + * | |
| 37 | + * @var string | |
| 38 | + */ | |
| 39 | + var $media = ''; | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * The MIME media sub-type | |
| 43 | + * | |
| 44 | + * @var string | |
| 45 | + */ | |
| 46 | + var $subType = ''; | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * Optional MIME parameters | |
| 50 | + * | |
| 51 | + * @var array | |
| 52 | + */ | |
| 53 | + var $parameters = array(); | |
| 54 | + | |
| 55 | + /** | |
| 56 | + * List of valid media types | |
| 57 | + * | |
| 58 | + * @var array | |
| 59 | + */ | |
| 60 | + var $validMediaTypes = array( | |
| 61 | + 'text', | |
| 62 | + 'image', | |
| 63 | + 'audio', | |
| 64 | + 'video', | |
| 65 | + 'application', | |
| 66 | + 'multipart', | |
| 67 | + 'message' | |
| 68 | + ); | |
| 69 | + | |
| 70 | + | |
| 71 | + /** | |
| 72 | + * Constructor. | |
| 73 | + * | |
| 74 | + * If $type is set, if will be parsed and the appropriate class vars set. If not, | |
| 75 | + * you get an empty class. This is useful, but not quite as useful as parsing a | |
| 76 | + * type. | |
| 77 | + * | |
| 78 | + * @param string $type MIME type | |
| 79 | + * @return void | |
| 80 | + */ | |
| 81 | + function MIME_Type($type = false) | |
| 82 | + { | |
| 83 | + if ($type) { | |
| 84 | + $this->parse($type); | |
| 85 | + } | |
| 86 | + } | |
| 87 | + | |
| 88 | + | |
| 89 | + /** | |
| 90 | + * Parse a mime-type | |
| 91 | + * | |
| 92 | + * @param $type string MIME type to parse | |
| 93 | + * @return void | |
| 94 | + */ | |
| 95 | + function parse($type) | |
| 96 | + { | |
| 97 | + $this->media = $this->getMedia($type); | |
| 98 | + $this->subType = $this->getSubType($type); | |
| 99 | + if (MIME_Type::hasParameters($type)) { | |
| 100 | + require_once 'MIME/Type/Parameter.php'; | |
| 101 | + foreach (MIME_Type::getParameters($type) as $param) { | |
| 102 | + $param = &new MIME_Type_Parameter($param); | |
| 103 | + $this->parameters[$param->name] = $param; | |
| 104 | + } | |
| 105 | + } | |
| 106 | + } | |
| 107 | + | |
| 108 | + | |
| 109 | + /** | |
| 110 | + * Does this type have any parameters? | |
| 111 | + * | |
| 112 | + * @param $type string MIME type to check | |
| 113 | + * @return boolean true if $type has parameters, false otherwise | |
| 114 | + * @static | |
| 115 | + */ | |
| 116 | + function hasParameters($type) | |
| 117 | + { | |
| 118 | + if (strstr($type, ';')) { | |
| 119 | + return true; | |
| 120 | + } | |
| 121 | + return false; | |
| 122 | + } | |
| 123 | + | |
| 124 | + | |
| 125 | + /** | |
| 126 | + * Get a MIME type's parameters | |
| 127 | + * | |
| 128 | + * @param $type string MIME type to get parameters of | |
| 129 | + * @return array $type's parameters | |
| 130 | + * @static | |
| 131 | + */ | |
| 132 | + function getParameters($type) | |
| 133 | + { | |
| 134 | + $params = array(); | |
| 135 | + $tmp = explode(';', $type); | |
| 136 | + for ($i = 1; $i < count($tmp); $i++) { | |
| 137 | + $params[] = trim($tmp[$i]); | |
| 138 | + } | |
| 139 | + return $params; | |
| 140 | + } | |
| 141 | + | |
| 142 | + | |
| 143 | + /** | |
| 144 | + * Strip paramaters from a MIME type string | |
| 145 | + * | |
| 146 | + * @param string $type MIME type string | |
| 147 | + * @return string MIME type with parameters removed | |
| 148 | + * @static | |
| 149 | + */ | |
| 150 | + function stripParameters($type) | |
| 151 | + { | |
| 152 | + if (strstr($type, ';')) { | |
| 153 | + return substr($type, 0, strpos($type, ';')); | |
| 154 | + } | |
| 155 | + return $type; | |
| 156 | + } | |
| 157 | + | |
| 158 | + | |
| 159 | + /** | |
| 160 | + * Get a MIME type's media | |
| 161 | + * | |
| 162 | + * @note 'media' refers to the portion before the first slash | |
| 163 | + * @param $type string MIME type to get media of | |
| 164 | + * @return string $type's media | |
| 165 | + * @static | |
| 166 | + */ | |
| 167 | + function getMedia($type) | |
| 168 | + { | |
| 169 | + $tmp = explode('/', $type); | |
| 170 | + return strtolower($tmp[0]); | |
| 171 | + } | |
| 172 | + | |
| 173 | + | |
| 174 | + /** | |
| 175 | + * Get a MIME type's subtype | |
| 176 | + * | |
| 177 | + * @param $type string MIME type to get subtype of | |
| 178 | + * @return string $type's subtype | |
| 179 | + * @static | |
| 180 | + */ | |
| 181 | + function getSubType($type) | |
| 182 | + { | |
| 183 | + $tmp = explode('/', $type); | |
| 184 | + $tmp = explode(';', $tmp[1]); | |
| 185 | + return strtolower(trim($tmp[0])); | |
| 186 | + } | |
| 187 | + | |
| 188 | + | |
| 189 | + /** | |
| 190 | + * Create a textual MIME type from object values | |
| 191 | + * | |
| 192 | + * This function performs the opposite function of parse(). | |
| 193 | + * | |
| 194 | + * @return string MIME type string | |
| 195 | + */ | |
| 196 | + function get() | |
| 197 | + { | |
| 198 | + $type = strtolower($this->media.'/'.$this->subType); | |
| 199 | + if (count($this->parameters)) { | |
| 200 | + foreach ($this->parameters as $key => $null) { | |
| 201 | + $type .= '; '.$this->parameters[$key]->get(); | |
| 202 | + } | |
| 203 | + } | |
| 204 | + return $type; | |
| 205 | + } | |
| 206 | + | |
| 207 | + | |
| 208 | + /** | |
| 209 | + * Is this type experimental? | |
| 210 | + * | |
| 211 | + * @note Experimental types are denoted by a leading 'x-' in the media or | |
| 212 | + * subtype, e.g. text/x-vcard or x-world/x-vrml. | |
| 213 | + * @param string $type MIME type to check | |
| 214 | + * @return boolean true if $type is experimental, false otherwise | |
| 215 | + * @static | |
| 216 | + */ | |
| 217 | + function isExperimental($type) | |
| 218 | + { | |
| 219 | + if (substr(MIME_Type::getMedia($type), 0, 2) == 'x-' || | |
| 220 | + substr(MIME_Type::getSubType($type), 0, 2) == 'x-') { | |
| 221 | + return true; | |
| 222 | + } | |
| 223 | + return false; | |
| 224 | + } | |
| 225 | + | |
| 226 | + | |
| 227 | + /** | |
| 228 | + * Is this a vendor MIME type? | |
| 229 | + * | |
| 230 | + * @note Vendor types are denoted with a leading 'vnd. in the subtype. | |
| 231 | + * @param string $type MIME type to check | |
| 232 | + * @return boolean true if $type is a vendor type, false otherwise | |
| 233 | + * @static | |
| 234 | + */ | |
| 235 | + function isVendor($type) | |
| 236 | + { | |
| 237 | + if (substr(MIME_Type::getSubType($type), 0, 4) == 'vnd.') { | |
| 238 | + return true; | |
| 239 | + } | |
| 240 | + return false; | |
| 241 | + } | |
| 242 | + | |
| 243 | + | |
| 244 | + /** | |
| 245 | + * Is this a wildcard type? | |
| 246 | + * | |
| 247 | + * @param string $type MIME type to check | |
| 248 | + * @return boolean true if $type is a wildcard, false otherwise | |
| 249 | + * @static | |
| 250 | + */ | |
| 251 | + function isWildcard($type) | |
| 252 | + { | |
| 253 | + if ($type == '*/*' || MIME_Type::getSubtype($type) == '*') { | |
| 254 | + return true; | |
| 255 | + } | |
| 256 | + return false; | |
| 257 | + } | |
| 258 | + | |
| 259 | + | |
| 260 | + /** | |
| 261 | + * Perform a wildcard match on a MIME type | |
| 262 | + * | |
| 263 | + * Example: | |
| 264 | + * MIME_Type::wildcardMatch('image/*', 'image/png') | |
| 265 | + * | |
| 266 | + * @param string $card Wildcard to check against | |
| 267 | + * @param string $type MIME type to check | |
| 268 | + * @return boolean true if there was a match, false otherwise | |
| 269 | + */ | |
| 270 | + function wildcardMatch($card, $type) | |
| 271 | + { | |
| 272 | + if (!MIME_Type::isWildcard($card)) { | |
| 273 | + return false; | |
| 274 | + } | |
| 275 | + | |
| 276 | + if ($card == '*/*') { | |
| 277 | + return true; | |
| 278 | + } | |
| 279 | + | |
| 280 | + if (MIME_Type::getMedia($card) == | |
| 281 | + MIME_Type::getMedia($type)) { | |
| 282 | + return true; | |
| 283 | + } | |
| 284 | + return false; | |
| 285 | + } | |
| 286 | + | |
| 287 | + | |
| 288 | + /** | |
| 289 | + * Add a parameter to this type | |
| 290 | + * | |
| 291 | + * @param string $name Attribute name | |
| 292 | + * @param string $value Attribute value | |
| 293 | + * @param string $comment Comment for this parameter | |
| 294 | + * @return void | |
| 295 | + */ | |
| 296 | + function addParameter($name, $value, $comment = false) | |
| 297 | + { | |
| 298 | + $tmp = &new MIME_Type_Parameter; | |
| 299 | + $tmp->name = $name; | |
| 300 | + $tmp->value = $value; | |
| 301 | + $tmp->comment = $comment; | |
| 302 | + $this->parameters[$name] = $tmp; | |
| 303 | + } | |
| 304 | + | |
| 305 | + | |
| 306 | + /** | |
| 307 | + * Remove a parameter from this type | |
| 308 | + * | |
| 309 | + * @param string $name Parameter name | |
| 310 | + * @return void | |
| 311 | + */ | |
| 312 | + function removeParameter($name) | |
| 313 | + { | |
| 314 | + unset ($this->parameters[$name]); | |
| 315 | + } | |
| 316 | + | |
| 317 | + | |
| 318 | + /** | |
| 319 | + * Autodetect a file's MIME-type | |
| 320 | + * | |
| 321 | + * This function may be called staticly. | |
| 322 | + * | |
| 323 | + * @param string $file Path to the file to get the type of | |
| 324 | + * @param bool $params Append MIME parameters if true | |
| 325 | + * @return string $file's MIME-type on success, PEAR_Error otherwise | |
| 326 | + * @since 1.0.0beta1 | |
| 327 | + * @static | |
| 328 | + */ | |
| 329 | + function autoDetect($file, $params = false) | |
| 330 | + { | |
| 331 | + @include_once 'System/Command.php'; | |
| 332 | + if (function_exists('mime_content_type')) { | |
| 333 | + $type = mime_content_type($file); | |
| 334 | + } else if (class_exists('System_Command')) { | |
| 335 | + $type = MIME_Type::_fileAutoDetect($file); | |
| 336 | + } else { | |
| 337 | + return PEAR::raiseError("Sorry, can't autodetect; you need the mime_magic extension or System_Command and 'file' installed to use this function."); | |
| 338 | + } | |
| 339 | + | |
| 340 | + // _fileAutoDetect() may have returned an error. | |
| 341 | + if (PEAR::isError($type)) { | |
| 342 | + return $type; | |
| 343 | + } | |
| 344 | + | |
| 345 | + // Don't return an empty string | |
| 346 | + if (!$type || !strlen($type)) { | |
| 347 | + return PEAR::raiseError("Sorry, couldn't determine file type."); | |
| 348 | + } | |
| 349 | + | |
| 350 | + // Strip parameters if present & requested | |
| 351 | + if (MIME_Type::hasParameters($type) && !$params) { | |
| 352 | + $type = MIME_Type::stripParameters($type); | |
| 353 | + } | |
| 354 | + | |
| 355 | + return $type; | |
| 356 | + } | |
| 357 | + | |
| 358 | + /** | |
| 359 | + * Autodetect a file's MIME-type with 'file' and System_Command | |
| 360 | + * | |
| 361 | + * This function may be called staticly. | |
| 362 | + * | |
| 363 | + * @param string $file Path to the file to get the type of | |
| 364 | + * @return string $file's MIME-type | |
| 365 | + * @since 1.0.0beta1 | |
| 366 | + * @static | |
| 367 | + */ | |
| 368 | + function _fileAutoDetect($file) | |
| 369 | + { | |
| 370 | + // Sanity checks | |
| 371 | + if (!file_exists($file)) { | |
| 372 | + return PEAR::raiseError("File \"$file\" doesn't exist"); | |
| 373 | + } | |
| 374 | + | |
| 375 | + if (!is_readable($file)) { | |
| 376 | + return PEAR::raiseError("File \"$file\" is not readable"); | |
| 377 | + } | |
| 378 | + | |
| 379 | + $cmd = new System_Command; | |
| 380 | + | |
| 381 | + | |
| 382 | + // Make sure we have the 'file' command. | |
| 383 | + $fileCmd = PEAR::getStaticProperty('MIME_Type', 'fileCmd'); | |
| 384 | + if (!$cmd->which($fileCmd)) { | |
| 385 | + unset($cmd); | |
| 386 | + return PEAR::raiseError("Can't find file command \"{$fileCmd}\""); | |
| 387 | + } | |
| 388 | + | |
| 389 | + $cmd->pushCommand($fileCmd, "-bi '{$file}'"); | |
| 390 | + $res = $cmd->execute(); | |
| 391 | + unset($cmd); | |
| 392 | + | |
| 393 | + return $res; | |
| 394 | + } | |
| 395 | +} | |
| 0 | 396 | \ No newline at end of file | ... | ... |
thirdparty/pear/MIME/Type/Parameter.php
0 โ 100644
| 1 | +<?php | |
| 2 | +/* vim: set expandtab tabstop=4 shiftwidth=4: */ | |
| 3 | +// +----------------------------------------------------------------------+ | |
| 4 | +// | PHP version 4 | | |
| 5 | +// +----------------------------------------------------------------------+ | |
| 6 | +// | Copyright (c) 1997-2002 The PHP Group | | |
| 7 | +// +----------------------------------------------------------------------+ | |
| 8 | +// | This source file is subject to version 3.0 of the PHP license, | | |
| 9 | +// | that is bundled with this package in the file LICENSE, and is | | |
| 10 | +// | available at through the world-wide-web at | | |
| 11 | +// | http://www.php.net/license/3_0.txt. | | |
| 12 | +// | If you did not receive a copy of the PHP license and are unable to | | |
| 13 | +// | obtain it through the world-wide-web, please send a note to | | |
| 14 | +// | license@php.net so we can mail you a copy immediately. | | |
| 15 | +// +----------------------------------------------------------------------+ | |
| 16 | +// | Authors: Ian Eure <ieure@php.net> | | |
| 17 | +// +----------------------------------------------------------------------+ | |
| 18 | +// | |
| 19 | +// $Id: Parameter.php,v 1.1 2004/06/16 08:46:19 ieure Exp $ | |
| 20 | + | |
| 21 | +/** | |
| 22 | + * Class for working with MIME type parameters | |
| 23 | + * | |
| 24 | + * @version @version@ | |
| 25 | + * @package @package@ | |
| 26 | + * @author Ian Eure <ieure@php.net> | |
| 27 | + */ | |
| 28 | +class MIME_Type_Parameter { | |
| 29 | + /** | |
| 30 | + * Parameter name | |
| 31 | + * | |
| 32 | + * @var string | |
| 33 | + */ | |
| 34 | + var $name; | |
| 35 | + | |
| 36 | + /** | |
| 37 | + * Parameter value | |
| 38 | + * | |
| 39 | + * @var string | |
| 40 | + */ | |
| 41 | + var $value; | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * Parameter comment | |
| 45 | + * | |
| 46 | + * @var string | |
| 47 | + */ | |
| 48 | + var $comment; | |
| 49 | + | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * Constructor. | |
| 53 | + * | |
| 54 | + * @param string $param MIME parameter to parse, if set. | |
| 55 | + * @return void | |
| 56 | + */ | |
| 57 | + function MIME_Type_Parameter($param = false) | |
| 58 | + { | |
| 59 | + if ($param) { | |
| 60 | + $this->parse($param); | |
| 61 | + } | |
| 62 | + } | |
| 63 | + | |
| 64 | + | |
| 65 | + /** | |
| 66 | + * Parse a MIME type parameter and set object fields | |
| 67 | + * | |
| 68 | + * @param string $param MIME type parameter to parse | |
| 69 | + * @return void | |
| 70 | + */ | |
| 71 | + function parse($param) | |
| 72 | + { | |
| 73 | + $this->name = $this->getAttribute($param); | |
| 74 | + $this->value = $this->getValue($param); | |
| 75 | + if ($this->hasComment($param)) { | |
| 76 | + $this->comment = $this->getComment($param); | |
| 77 | + } | |
| 78 | + } | |
| 79 | + | |
| 80 | + | |
| 81 | + /** | |
| 82 | + * Get a parameter attribute (e.g. name) | |
| 83 | + * | |
| 84 | + * @param string MIME type parameter | |
| 85 | + * @return string Attribute name | |
| 86 | + * @static | |
| 87 | + */ | |
| 88 | + function getAttribute($param) | |
| 89 | + { | |
| 90 | + $tmp = explode('=', $param); | |
| 91 | + return trim($tmp[0]); | |
| 92 | + } | |
| 93 | + | |
| 94 | + | |
| 95 | + /** | |
| 96 | + * Get a parameter value | |
| 97 | + * | |
| 98 | + * @param string $param MIME type parameter | |
| 99 | + * @return string Value | |
| 100 | + * @static | |
| 101 | + */ | |
| 102 | + function getValue($param) | |
| 103 | + { | |
| 104 | + $tmp = explode('=', $param); | |
| 105 | + $value = $tmp[1]; | |
| 106 | + if (MIME_Type_Parameter::hasComment($param)) { | |
| 107 | + $cs = strpos($value, '('); | |
| 108 | + $value = substr($value, 0, $cs); | |
| 109 | + } | |
| 110 | + return trim($value, '" '); | |
| 111 | + } | |
| 112 | + | |
| 113 | + | |
| 114 | + /** | |
| 115 | + * Get a parameter comment | |
| 116 | + * | |
| 117 | + * @param string $param MIME type parameter | |
| 118 | + * @return string Parameter comment | |
| 119 | + * @see getComment() | |
| 120 | + * @static | |
| 121 | + */ | |
| 122 | + function getComment($param) | |
| 123 | + { | |
| 124 | + $cs = strpos($param, '('); | |
| 125 | + $comment = substr($param, $cs); | |
| 126 | + return trim($comment, '() '); | |
| 127 | + } | |
| 128 | + | |
| 129 | + | |
| 130 | + /** | |
| 131 | + * Does this parameter have a comment? | |
| 132 | + * | |
| 133 | + * @param string $param MIME type parameter | |
| 134 | + * @return boolean true if $param has a comment, false otherwise | |
| 135 | + * @static | |
| 136 | + */ | |
| 137 | + function hasComment($param) | |
| 138 | + { | |
| 139 | + if (strstr($param, '(')) { | |
| 140 | + return true; | |
| 141 | + } | |
| 142 | + return false; | |
| 143 | + } | |
| 144 | + | |
| 145 | + | |
| 146 | + /** | |
| 147 | + * Get a string representation of this parameter | |
| 148 | + * | |
| 149 | + * This function performs the oppsite of parse() | |
| 150 | + * | |
| 151 | + * @return string String representation of parameter | |
| 152 | + */ | |
| 153 | + function get() | |
| 154 | + { | |
| 155 | + $val = $this->name.'="'.$this->value.'"'; | |
| 156 | + if ($this->comment) { | |
| 157 | + $val .= ' ('.$this->comment.')'; | |
| 158 | + } | |
| 159 | + return $val; | |
| 160 | + } | |
| 161 | +} | |
| 162 | +?> | |
| 0 | 163 | \ No newline at end of file | ... | ... |