Commit 227adfac9010039de1f6e8ae4f2071910e7277d9
1 parent
d88cd616
Merged in from DEV trunk...
KTS-2912
"Document Indexing Diagnostics shows that there is a problem indixing a PDF file"
Fixed.
Commited By: Conrad Vermeulen
Reviewed By: Jonathan Byrne
KTS-2892
"Search for user by username returns all users and filter is ignored."
Fixed. The sql function to get the list of users was overwriting the filter.
Committed by: Megan Watson
Reviewed by: Conrad Vermeulen
KTS-2873
"Double quote (") is not accepted as valid input for metadata when the name of a Lookup field or a Tree field has a Double quote in."
Fixed. Sanitised the values.
Committed by: Megan Watson
Reviewed by: Conrad Vermeulen
KTC-331
"Bulk upload throws an exception shown on attached screenshot"
Fixed. The upload is successful regardless of the exception, put @ in front of the chgrp() to suppress the error message.
Committed by: Megan Watson
Reviewed by: Conrad Vermeulen
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/STABLE/trunk@8031 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
9 changed files
with
305 additions
and
295 deletions
lib/documentmanagement/MDTree.inc
| ... | ... | @@ -5,32 +5,32 @@ |
| 5 | 5 | * KnowledgeTree Open Source Edition |
| 6 | 6 | * Document Management Made Simple |
| 7 | 7 | * Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited |
| 8 | - * | |
| 8 | + * | |
| 9 | 9 | * This program is free software; you can redistribute it and/or modify it under |
| 10 | 10 | * the terms of the GNU General Public License version 3 as published by the |
| 11 | 11 | * Free Software Foundation. |
| 12 | - * | |
| 12 | + * | |
| 13 | 13 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 14 | 14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 15 | 15 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 16 | 16 | * details. |
| 17 | - * | |
| 17 | + * | |
| 18 | 18 | * You should have received a copy of the GNU General Public License |
| 19 | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | - * | |
| 20 | + * | |
| 21 | 21 | * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, |
| 22 | 22 | * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. |
| 23 | - * | |
| 23 | + * | |
| 24 | 24 | * The interactive user interfaces in modified source and object code versions |
| 25 | 25 | * of this program must display Appropriate Legal Notices, as required under |
| 26 | 26 | * Section 5 of the GNU General Public License version 3. |
| 27 | - * | |
| 27 | + * | |
| 28 | 28 | * In accordance with Section 7(b) of the GNU General Public License version 3, |
| 29 | 29 | * these Appropriate Legal Notices must retain the display of the "Powered by |
| 30 | - * KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 30 | + * KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 31 | 31 | * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices |
| 32 | - * must display the words "Powered by KnowledgeTree" and retain the original | |
| 33 | - * copyright notice. | |
| 32 | + * must display the words "Powered by KnowledgeTree" and retain the original | |
| 33 | + * copyright notice. | |
| 34 | 34 | * Contributor( s): ______________________________________ |
| 35 | 35 | * |
| 36 | 36 | */ |
| ... | ... | @@ -44,7 +44,7 @@ require_once(KT_LIB_DIR . "/util/sanitize.inc"); |
| 44 | 44 | class MDTreeNode extends KTEntity { |
| 45 | 45 | /** boilerplate DB code. */ |
| 46 | 46 | /** primary key */ |
| 47 | - var $iId = -1; | |
| 47 | + var $iId = -1; | |
| 48 | 48 | var $iFieldId; |
| 49 | 49 | var $sName; |
| 50 | 50 | var $iParentNode; |
| ... | ... | @@ -81,7 +81,7 @@ class MDTreeNode extends KTEntity { |
| 81 | 81 | |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | -/* simple class to encapsulate tree-as-a-whole behaviour. | |
| 84 | +/* simple class to encapsulate tree-as-a-whole behaviour. | |
| 85 | 85 | NBM - should this move, be refactored? It certainly doesn't belong in the DB, |
| 86 | 86 | since its just an aggregate utility. |
| 87 | 87 | */ |
| ... | ... | @@ -100,11 +100,11 @@ class MDTree { |
| 100 | 100 | $this->contents = null; |
| 101 | 101 | $this->mapnodes = null; |
| 102 | 102 | $this->root = null; |
| 103 | - $this->lookups = null; | |
| 103 | + $this->lookups = null; | |
| 104 | 104 | $this->field_id = null; |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - /* function buildForField | |
| 107 | + /* function buildForField | |
| 108 | 108 | * |
| 109 | 109 | * build a tree for a particular field instance. |
| 110 | 110 | * sets contents, so we can edit "stuff". |
| ... | ... | @@ -112,7 +112,7 @@ class MDTree { |
| 112 | 112 | function buildForField($iFieldId) |
| 113 | 113 | { |
| 114 | 114 | global $default; |
| 115 | - // before we start, we need to check that | |
| 115 | + // before we start, we need to check that | |
| 116 | 116 | // the specified field exists and is organised into a tree. |
| 117 | 117 | $organisedField =& DocumentField::get($iFieldId); |
| 118 | 118 | if (PEAR::isError($organisedField) || ($organisedField === false)) { |
| ... | ... | @@ -182,8 +182,8 @@ class MDTree { |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | $leafArray = null; |
| 185 | - if (!array_key_exists("leaves", $target_set)) { | |
| 186 | - $target_set["leaves"] = array($lookup_value->getId()); | |
| 185 | + if (!array_key_exists("leaves", $target_set)) { | |
| 186 | + $target_set["leaves"] = array($lookup_value->getId()); | |
| 187 | 187 | } |
| 188 | 188 | else |
| 189 | 189 | { |
| ... | ... | @@ -193,14 +193,14 @@ class MDTree { |
| 193 | 193 | |
| 194 | 194 | $this->lookups[$lookup_value->getId()] = $lookup_value; |
| 195 | 195 | |
| 196 | - } | |
| 196 | + } | |
| 197 | 197 | $this->root =& $this->contents[0]; |
| 198 | 198 | $default->log->debug("MDTree::buildForField done: " . print_r($this, true)); |
| 199 | - | |
| 199 | + | |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | // handle deleting subtrees |
| 203 | - function deleteNode($iNode) { | |
| 203 | + function deleteNode($iNode) { | |
| 204 | 204 | $stack = array(); |
| 205 | 205 | array_push($stack, $iNode); |
| 206 | 206 | while (count($stack) != 0) |
| ... | ... | @@ -215,7 +215,7 @@ class MDTree { |
| 215 | 215 | $this->lookups[$leaf]->setTreeParent(0); |
| 216 | 216 | $this->lookups[$leaf]->update(); |
| 217 | 217 | $this->contents[0]["leaves"][] = $leaf; |
| 218 | - } | |
| 218 | + } | |
| 219 | 219 | } |
| 220 | 220 | else array_push($stack, $value); |
| 221 | 221 | } |
| ... | ... | @@ -225,7 +225,7 @@ class MDTree { |
| 225 | 225 | $iParent = $this->mapnodes[$iNode]->getParentNode(); |
| 226 | 226 | foreach ($this->contents[$iParent] as $index => $val) |
| 227 | 227 | if ($iNode === $val) unset($this->contents[$iParent][$index]); |
| 228 | - } | |
| 228 | + } | |
| 229 | 229 | |
| 230 | 230 | // add a node to the mapping after the fact (e.g. created later in the process.) |
| 231 | 231 | function addNode($oNode) { |
| ... | ... | @@ -244,7 +244,7 @@ class MDTree { |
| 244 | 244 | $oNewParent = $this->mapnodes[$destination_parent_id]; |
| 245 | 245 | // we will have failed by here if its bogus. |
| 246 | 246 | //$default->log->debug('MDTree::reparentKeyword '.print_r($oNewParent, true)); |
| 247 | - | |
| 247 | + | |
| 248 | 248 | // if its 0 or NULL, we reparent to null. |
| 249 | 249 | if (($oNewParent === null) or ($desintation_parent_id === 0)) { |
| 250 | 250 | $new_home = 0; |
| ... | ... | @@ -256,19 +256,19 @@ class MDTree { |
| 256 | 256 | if (!empty($this->contents[$oldparent])) { |
| 257 | 257 | $KWIndex = array_search($lookup_id, $this->contents[$oldParent]["leaves"]); |
| 258 | 258 | unset($this->contents[$oldParent]["leaves"][$KWIndex]); |
| 259 | - | |
| 259 | + | |
| 260 | 260 | } |
| 261 | 261 | $this->contents[$new_home]["leaves"][] = $oKeyword->getId(); |
| 262 | 262 | $oKeyword->update(); |
| 263 | - } | |
| 264 | - | |
| 263 | + } | |
| 264 | + | |
| 265 | 265 | |
| 266 | 266 | // STUB FUNCTIONS: need to be filled in. |
| 267 | - | |
| 267 | + | |
| 268 | 268 | |
| 269 | 269 | // REALLY need to deprecate this, but how? |
| 270 | 270 | function render($bEditable) { return null; } // render using a template (with edit / buttons.) FIXME build a widget / renderer. |
| 271 | - | |
| 271 | + | |
| 272 | 272 | |
| 273 | 273 | /* ----------------------- EVIL HACK -------------------------- |
| 274 | 274 | * |
| ... | ... | @@ -307,7 +307,7 @@ class MDTree { |
| 307 | 307 | } |
| 308 | 308 | $treeStr .= '</ul>'; |
| 309 | 309 | return $treeStr; |
| 310 | - | |
| 310 | + | |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | // I can't seem to do recursion in smarty, and recursive templates seems a bad solution. |
| ... | ... | @@ -348,7 +348,8 @@ class MDTree { |
| 348 | 348 | if ($leaf === $this->activevalue) { |
| 349 | 349 | $is_selected=' checked="checked"'; |
| 350 | 350 | } |
| 351 | - $treeStr .= '<li class="leafnode"><input type="radio" name="'.$inputname.'" value="'.$treeToRender->lookups[$leaf]->getName().'" '.$is_selected.'>' . $treeToRender->lookups[$leaf]->getName() .'</input>'; | |
| 351 | + $sValue = htmlentities($treeToRender->lookups[$leaf]->getName()); | |
| 352 | + $treeStr .= '<li class="leafnode"><input type="radio" name="'.$inputname.'" value="'.$sValue.'" '.$is_selected.'>' . $sValue .'</input>'; | |
| 352 | 353 | $treeStr .= '</li>'; |
| 353 | 354 | } |
| 354 | 355 | } |
| ... | ... | @@ -357,9 +358,9 @@ class MDTree { |
| 357 | 358 | //$treeStr .= '</li></ul>'; |
| 358 | 359 | |
| 359 | 360 | return $treeStr; |
| 360 | - | |
| 361 | + | |
| 361 | 362 | } |
| 362 | - | |
| 363 | + | |
| 363 | 364 | // again, not pretty. set a particular item as "active" |
| 364 | 365 | function setActiveItem($sMetadataMatch) { |
| 365 | 366 | // also need to: | ... | ... |
lib/users/User.inc
| ... | ... | @@ -323,10 +323,19 @@ class User extends KTEntity { |
| 323 | 323 | * @return Array array of User objects, false otherwise and set $_SESSION["errorMessage"] |
| 324 | 324 | */ |
| 325 | 325 | function getList($sWhereClause = null, $aOptions = null) { |
| 326 | - if(!is_array($aOptions)) $aOptions = array($aOptions); | |
| 327 | - $aOptions['orderby'] = KTUtil::arrayGet($aOptions, 'orderby', 'name'); | |
| 328 | - //if disabled = 2 then the user is deleted | |
| 329 | - $sWhereClause = 'disabled != \'2\''; | |
| 326 | + if(!is_array($aOptions)) $aOptions = array($aOptions); | |
| 327 | + $aOptions['orderby'] = KTUtil::arrayGet($aOptions, 'orderby', 'name'); | |
| 328 | + | |
| 329 | + // don't include deleted users: disabled = 2 | |
| 330 | + if(!empty($sWhereClause)){ | |
| 331 | + if(strpos(strtolower($sWhereClause), 'where ') === false){ | |
| 332 | + $sWhereClause = '('.$sWhereClause.')'; | |
| 333 | + } | |
| 334 | + $sWhereClause .= ' AND disabled != 2'; | |
| 335 | + }else{ | |
| 336 | + $sWhereClause = 'disabled != 2'; | |
| 337 | + } | |
| 338 | + | |
| 330 | 339 | return KTEntityUtil::getList2('User', $sWhereClause, $aOptions); |
| 331 | 340 | } |
| 332 | 341 | ... | ... |
search2/indexing/extractorCore.inc.php
| ... | ... | @@ -370,7 +370,7 @@ abstract class ExternalDocumentExtractor extends DocumentExtractor |
| 370 | 370 | $script_name = $script_prefix . '.bat'; |
| 371 | 371 | |
| 372 | 372 | $script = "rem This is an auto generated file. \n"; |
| 373 | - $script .= $cmd . ' 2> ' . $script_out . "\r\n"; | |
| 373 | + $script .= $cmd . ' 2> "' . $script_out . "\"\r\n"; | |
| 374 | 374 | } |
| 375 | 375 | else |
| 376 | 376 | { |
| ... | ... | @@ -378,7 +378,7 @@ abstract class ExternalDocumentExtractor extends DocumentExtractor |
| 378 | 378 | |
| 379 | 379 | $script = "#!/bin/sh\n"; |
| 380 | 380 | $script .= "# This is an auto generated file. \n"; |
| 381 | - $script .= $cmd . ' 2> ' . $script_out . "\n"; | |
| 381 | + $script .= $cmd . ' 2> "' . $script_out . "\"\n"; | |
| 382 | 382 | $script .= "exit $?\n"; |
| 383 | 383 | } |
| 384 | 384 | ... | ... |
search2/indexing/extractors/OpenXmlTextExtractor.inc.php
| ... | ... | @@ -43,7 +43,7 @@ class OpenXmlTextExtractor extends ExternalDocumentExtractor |
| 43 | 43 | $config = KTConfig::getSingleton(); |
| 44 | 44 | |
| 45 | 45 | $this->unzip = KTUtil::findCommand("import/unzip", 'unzip'); |
| 46 | - $this->unzip_params = $config->get('extractorParameters/unzip', '\'{source}\' \'{part}\' -d \'{target_dir}\''); | |
| 46 | + $this->unzip_params = $config->get('extractorParameters/unzip', '"{source}" "{part}" -d "{target_dir}"'); | |
| 47 | 47 | parent::__construct(); |
| 48 | 48 | } |
| 49 | 49 | ... | ... |
search2/indexing/extractors/PDFExtractor.inc.php
| ... | ... | @@ -41,7 +41,7 @@ class PDFExtractor extends ApplicationExtractor |
| 41 | 41 | public function __construct() |
| 42 | 42 | { |
| 43 | 43 | $config = KTConfig::getSingleton(); |
| 44 | - $params = $config->get('extractorParameters/pdftotext', '-nopgbrk -enc UTF-8 \'{source}\' \'{target}\''); | |
| 44 | + $params = $config->get('extractorParameters/pdftotext', '-nopgbrk -enc UTF-8 "{source}" "{target}"'); | |
| 45 | 45 | |
| 46 | 46 | parent::__construct('externalBinary','pdftotext','pdftotext',_kt('PDF Text Extractor'),$params); |
| 47 | 47 | } | ... | ... |
search2/indexing/extractors/PSExtractor.inc.php
| ... | ... | @@ -41,7 +41,7 @@ class PSExtractor extends ApplicationExtractor |
| 41 | 41 | public function __construct() |
| 42 | 42 | { |
| 43 | 43 | $config = KTConfig::getSingleton(); |
| 44 | - $params = $config->get('extractorParameters/pstotext', '\'{source}\' > \'{target}\''); | |
| 44 | + $params = $config->get('extractorParameters/pstotext', '"{source}" > "{target}"'); | |
| 45 | 45 | |
| 46 | 46 | parent::__construct('externalBinary','pstotext','pstotext',_kt('PostScript Text Extractor'), $params); |
| 47 | 47 | } | ... | ... |
templates/kt3/fields/lookup.smarty
| ... | ... | @@ -13,7 +13,7 @@ |
| 13 | 13 | |
| 14 | 14 | <select name="{$name}" {if $has_id}id="{$id}"{/if} {if $options.multi}multiple="true"{/if} {if $options.size}size="{$options.size}"{/if}> |
| 15 | 15 | {foreach item=lookup key=lookup_key from=$options.vocab} |
| 16 | - <option value="{$lookup_key}" {if ($value == $lookup_key)}selected="selected"{/if}>{$lookup|sanitize}</option> | |
| 16 | + <option value="{$lookup_key|sanitize}" {if ($value == $lookup_key)}selected="selected"{/if}>{$lookup|sanitize}</option> | |
| 17 | 17 | {/foreach} |
| 18 | 18 | </select> |
| 19 | 19 | <input type="hidden" name="kt_core_fieldsets_expect[{$name}]" value ="1" /> | ... | ... |
templates/ktcore/forms/widgets/selection.smarty
| 1 | 1 | {if empty($vocab)} |
| 2 | 2 | <div class="ktInfoMessage"><span>{$context->sEmptyMessage}</span></div> |
| 3 | 3 | {else} |
| 4 | - <select name="{$name}" | |
| 5 | - {if $has_id}id="{$id}"{/if} | |
| 6 | - {if $options.multi}multiple="true"{/if} | |
| 4 | + <select name="{$name}" | |
| 5 | + {if $has_id}id="{$id}"{/if} | |
| 6 | + {if $options.multi}multiple="true"{/if} | |
| 7 | 7 | > |
| 8 | 8 | {if $options.initial_string} |
| 9 | 9 | <option value="">{$options.initial_string}</option> |
| 10 | - {/if} | |
| 10 | + {/if} | |
| 11 | 11 | {foreach item=lookup key=lookup_key from=$vocab} |
| 12 | 12 | |
| 13 | - <option value="{$lookup_key}" {if ($value == $lookup_key)}selected="selected"{/if}>{$lookup}</option> | |
| 13 | + <option value="{$lookup_key|sanitize}" {if ($value == $lookup_key)}selected="selected"{/if}>{$lookup|sanitize}</option> | |
| 14 | 14 | {/foreach} |
| 15 | 15 | </select> |
| 16 | 16 | {/if} | ... | ... |
thirdparty/pear/File/Archive/Writer/Files.php
| 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 | - | |
| 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 | 250 | ?> |
| 251 | 251 | \ No newline at end of file | ... | ... |