diff --git a/Classes/PHPExcel/Calculation.php b/Classes/PHPExcel/Calculation.php
index 6a21bcac..5a792217 100644
--- a/Classes/PHPExcel/Calculation.php
+++ b/Classes/PHPExcel/Calculation.php
@@ -269,7 +269,7 @@ class PHPExcel_Calculation
'NULL' => null
);
- // PHPExcel functions
+ // PHPExcel functions
private static $PHPExcelFunctions = array( // PHPExcel functions
'ABS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'abs',
@@ -1703,12 +1703,11 @@ class PHPExcel_Calculation
)
);
-
// Internal functions used for special control purposes
private static $controlFunctions = array(
'MKMATRIX' => array(
'argumentCount' => '*',
- 'functionCall' => 'self::_mkMatrix'
+ 'functionCall' => 'self::_mkMatrix'
)
);
@@ -1739,7 +1738,7 @@ class PHPExcel_Calculation
}
}
- private static function _loadLocales()
+ private static function loadLocales()
{
$localeFileDirectory = PHPEXCEL_ROOT.'PHPExcel/locale/';
foreach (glob($localeFileDirectory.'/*', GLOB_ONLYDIR) as $filename) {
@@ -1981,7 +1980,7 @@ class PHPExcel_Calculation
}
if (count(self::$validLocaleLanguages) == 1) {
- self::_loadLocales();
+ self::loadLocales();
}
// Test whether we have any language data for this language (any locale)
if (in_array($language, self::$validLocaleLanguages)) {
@@ -2439,7 +2438,7 @@ class PHPExcel_Calculation
if (($wsTitle{0} !== "\x00") && ($this->cyclicReferenceStack->onStack($wsCellReference))) {
if ($this->cyclicFormulaCount <= 0) {
$this->cyclicFormulaCell = '';
- return $this->_raiseFormulaError('Cyclic Reference in Formula');
+ return $this->raiseFormulaError('Cyclic Reference in Formula');
} elseif ($this->cyclicFormulaCell === $wsCellReference) {
++$this->cyclicFormulaCounter;
if ($this->cyclicFormulaCounter >= $this->cyclicFormulaCount) {
@@ -2736,15 +2735,15 @@ class PHPExcel_Calculation
// Trap for mismatched braces and trigger an appropriate error
if ($openCount < $closeCount) {
if ($openCount > 0) {
- return $this->_raiseFormulaError("Formula Error: Mismatched matrix braces '}'");
+ return $this->raiseFormulaError("Formula Error: Mismatched matrix braces '}'");
} else {
- return $this->_raiseFormulaError("Formula Error: Unexpected '}' encountered");
+ return $this->raiseFormulaError("Formula Error: Unexpected '}' encountered");
}
} elseif ($openCount > $closeCount) {
if ($closeCount > 0) {
- return $this->_raiseFormulaError("Formula Error: Mismatched matrix braces '{'");
+ return $this->raiseFormulaError("Formula Error: Mismatched matrix braces '{'");
} else {
- return $this->_raiseFormulaError("Formula Error: Unexpected '{' encountered");
+ return $this->raiseFormulaError("Formula Error: Unexpected '{' encountered");
}
}
}
@@ -2846,7 +2845,7 @@ class PHPExcel_Calculation
//echo 'Element is a Positive number, not Plus operator', PHP_EOL;
++$index; // Drop the redundant plus symbol
} elseif ((($opCharacter == '~') || ($opCharacter == '|')) && (!$isOperandOrFunction)) { // We have to explicitly deny a tilde or pipe, because they are legal
- return $this->_raiseFormulaError("Formula Error: Illegal character '~'"); // on the stack but not in the input expression
+ return $this->raiseFormulaError("Formula Error: Illegal character '~'"); // on the stack but not in the input expression
} elseif ((isset(self::$operators[$opCharacter]) or $isOperandOrFunction) && $expectingOperator) { // Are we putting an operator on the stack?
//echo 'Element with value '.$opCharacter.' is an Operator', PHP_EOL;
@@ -2865,7 +2864,7 @@ class PHPExcel_Calculation
$expectingOperand = false;
while (($o2 = $stack->pop()) && $o2['value'] != '(') { // Pop off the stack back to the last (
if ($o2 === null) {
- return $this->_raiseFormulaError('Formula Error: Unexpected closing brace ")"');
+ return $this->raiseFormulaError('Formula Error: Unexpected closing brace ")"');
} else {
$output[] = $o2;
}
@@ -2894,7 +2893,7 @@ class PHPExcel_Calculation
$expectedArgumentCount = self::$PHPExcelFunctions[$functionName]['argumentCount'];
$functionCall = self::$PHPExcelFunctions[$functionName]['functionCall'];
} else { // did we somehow push a non-function on the stack? this should never happen
- return $this->_raiseFormulaError("Formula Error: Internal error, non-function on stack");
+ return $this->raiseFormulaError("Formula Error: Internal error, non-function on stack");
}
// Check the argument count
$argumentCountError = false;
@@ -2938,7 +2937,7 @@ class PHPExcel_Calculation
}
}
if ($argumentCountError) {
- return $this->_raiseFormulaError("Formula Error: Wrong number of arguments for $functionName() function: $argumentCount given, ".$expectedArgumentCountString." expected");
+ return $this->raiseFormulaError("Formula Error: Wrong number of arguments for $functionName() function: $argumentCount given, ".$expectedArgumentCountString." expected");
}
}
++$index;
@@ -2947,7 +2946,7 @@ class PHPExcel_Calculation
//echo 'Element is a Function argument separator', PHP_EOL;
while (($o2 = $stack->pop()) && $o2['value'] != '(') { // Pop off the stack back to the last (
if ($o2 === null) {
- return $this->_raiseFormulaError("Formula Error: Unexpected ,");
+ return $this->raiseFormulaError("Formula Error: Unexpected ,");
} else {
$output[] = $o2; // pop the argument expression stuff and push onto the output
}
@@ -2960,7 +2959,7 @@ class PHPExcel_Calculation
// make sure there was a function
$d = $stack->last(2);
if (!preg_match('/^'.self::CALCULATION_REGEXP_FUNCTION.'$/i', $d['value'], $matches)) {
- return $this->_raiseFormulaError("Formula Error: Unexpected ,");
+ return $this->raiseFormulaError("Formula Error: Unexpected ,");
}
$d = $stack->pop();
$stack->push($d['type'], ++$d['value'], $d['reference']); // increment the argument count
@@ -3016,7 +3015,7 @@ class PHPExcel_Calculation
$val = $startMatches[2].'!'.$val;
}
} else {
- return $this->_raiseFormulaError("3D Range references are not yet supported");
+ return $this->raiseFormulaError("3D Range references are not yet supported");
}
}
@@ -3095,19 +3094,19 @@ class PHPExcel_Calculation
$expectingOperand = false;
$expectingOperator = true;
} else {
- return $this->_raiseFormulaError("Formula Error: Unexpected ')'");
+ return $this->raiseFormulaError("Formula Error: Unexpected ')'");
}
} elseif (isset(self::$operators[$opCharacter]) && !$expectingOperator) {
- return $this->_raiseFormulaError("Formula Error: Unexpected operator '$opCharacter'");
+ return $this->raiseFormulaError("Formula Error: Unexpected operator '$opCharacter'");
} else { // I don't even want to know what you did to get here
- return $this->_raiseFormulaError("Formula Error: An unexpected error occured");
+ return $this->raiseFormulaError("Formula Error: An unexpected error occured");
}
// Test for end of formula string
if ($index == strlen($formula)) {
// Did we end with an operator?.
// Only valid for the % unary operator
if ((isset(self::$operators[$opCharacter])) && ($opCharacter != '%')) {
- return $this->_raiseFormulaError("Formula Error: Operator '$opCharacter' has no operands");
+ return $this->raiseFormulaError("Formula Error: Operator '$opCharacter' has no operands");
} else {
break;
}
@@ -3140,7 +3139,7 @@ class PHPExcel_Calculation
while (($op = $stack->pop()) !== null) { // pop everything off the stack and push onto output
if ((is_array($op) && $op['value'] == '(') || ($op === '(')) {
- return $this->_raiseFormulaError("Formula Error: Expecting ')'"); // if there are any opening braces on the stack, then braces were unbalanced
+ return $this->raiseFormulaError("Formula Error: Expecting ')'"); // if there are any opening braces on the stack, then braces were unbalanced
}
$output[] = $op;
}
@@ -3187,10 +3186,10 @@ class PHPExcel_Calculation
// echo 'Token is a binary operator
';
// We must have two operands, error if we don't
if (($operand2Data = $stack->pop()) === null) {
- return $this->_raiseFormulaError('Internal error - Operand value missing from stack');
+ return $this->raiseFormulaError('Internal error - Operand value missing from stack');
}
if (($operand1Data = $stack->pop()) === null) {
- return $this->_raiseFormulaError('Internal error - Operand value missing from stack');
+ return $this->raiseFormulaError('Internal error - Operand value missing from stack');
}
$operand1 = self::_dataTestReference($operand1Data);
@@ -3212,7 +3211,7 @@ class PHPExcel_Calculation
case '<=': // Less than or Equal to
case '=': // Equality
case '<>': // Inequality
- $this->_executeBinaryComparisonOperation($cellID, $operand1, $operand2, $token, $stack);
+ $this->executeBinaryComparisonOperation($cellID, $operand1, $operand2, $token, $stack);
break;
// Binary Operators
case ':': // Range
@@ -3258,7 +3257,7 @@ class PHPExcel_Calculation
if ($pCellParent !== null) {
$cellValue = $this->extractCellRange($cellRef, $this->workbook->getSheetByName($sheet1), false);
} else {
- return $this->_raiseFormulaError('Unable to access Cell Reference');
+ return $this->raiseFormulaError('Unable to access Cell Reference');
}
$stack->push('Cell Reference', $cellValue, $cellRef);
} else {
@@ -3266,19 +3265,19 @@ class PHPExcel_Calculation
}
break;
case '+': // Addition
- $this->_executeNumericBinaryOperation($cellID, $operand1, $operand2, $token, 'plusEquals', $stack);
+ $this->executeNumericBinaryOperation($cellID, $operand1, $operand2, $token, 'plusEquals', $stack);
break;
case '-': // Subtraction
- $this->_executeNumericBinaryOperation($cellID, $operand1, $operand2, $token, 'minusEquals', $stack);
+ $this->executeNumericBinaryOperation($cellID, $operand1, $operand2, $token, 'minusEquals', $stack);
break;
case '*': // Multiplication
- $this->_executeNumericBinaryOperation($cellID, $operand1, $operand2, $token, 'arrayTimesEquals', $stack);
+ $this->executeNumericBinaryOperation($cellID, $operand1, $operand2, $token, 'arrayTimesEquals', $stack);
break;
case '/': // Division
- $this->_executeNumericBinaryOperation($cellID, $operand1, $operand2, $token, 'arrayRightDivide', $stack);
+ $this->executeNumericBinaryOperation($cellID, $operand1, $operand2, $token, 'arrayRightDivide', $stack);
break;
case '^': // Exponential
- $this->_executeNumericBinaryOperation($cellID, $operand1, $operand2, $token, 'power', $stack);
+ $this->executeNumericBinaryOperation($cellID, $operand1, $operand2, $token, 'power', $stack);
break;
case '&': // Concatenation
// If either of the operands is a matrix, we need to treat them both as matrices
@@ -3329,7 +3328,7 @@ class PHPExcel_Calculation
} elseif (($token === '~') || ($token === '%')) {
// echo 'Token is a unary operator
';
if (($arg = $stack->pop()) === null) {
- return $this->_raiseFormulaError('Internal error - Operand value missing from stack');
+ return $this->raiseFormulaError('Internal error - Operand value missing from stack');
}
$arg = $arg['value'];
if ($token === '~') {
@@ -3354,7 +3353,7 @@ class PHPExcel_Calculation
$this->_debugLog->writeDebugLog('Evaluation Result is ', $this->_showTypeDetails($result));
$stack->push('Value', $result);
} else {
- $this->_executeNumericBinaryOperation($cellID, $multiplier, $arg, '*', 'arrayTimesEquals', $stack);
+ $this->executeNumericBinaryOperation($cellID, $multiplier, $arg, '*', 'arrayTimesEquals', $stack);
}
} elseif (preg_match('/^'.self::CALCULATION_REGEXP_CELLREF.'$/i', $token, $matches)) {
@@ -3371,7 +3370,7 @@ class PHPExcel_Calculation
$matches[2] = trim($matches[2], "\"'");
if ((strpos($matches[2], '[') !== false) || (strpos($matches[2], ']') !== false)) {
// It's a Reference to an external workbook (not currently supported)
- return $this->_raiseFormulaError('Unable to access External Workbook');
+ return $this->raiseFormulaError('Unable to access External Workbook');
}
$matches[2] = trim($matches[2], "\"'");
// echo '$cellRef='.$cellRef.' in worksheet '.$matches[2].'
';
@@ -3379,7 +3378,7 @@ class PHPExcel_Calculation
if ($pCellParent !== null) {
$cellValue = $this->extractCellRange($cellRef, $this->workbook->getSheetByName($matches[2]), false);
} else {
- return $this->_raiseFormulaError('Unable to access Cell Reference');
+ return $this->raiseFormulaError('Unable to access Cell Reference');
}
$this->_debugLog->writeDebugLog('Evaluation Result for cells ', $cellRef, ' in worksheet ', $matches[2], ' is ', $this->_showTypeDetails($cellValue));
// $cellRef = $matches[2].'!'.$cellRef;
@@ -3389,7 +3388,7 @@ class PHPExcel_Calculation
if ($pCellParent !== null) {
$cellValue = $this->extractCellRange($cellRef, $pCellWorksheet, false);
} else {
- return $this->_raiseFormulaError('Unable to access Cell Reference');
+ return $this->raiseFormulaError('Unable to access Cell Reference');
}
$this->_debugLog->writeDebugLog('Evaluation Result for cells ', $cellRef, ' is ', $this->_showTypeDetails($cellValue));
}
@@ -3405,7 +3404,7 @@ class PHPExcel_Calculation
$matches[2] = trim($matches[2], "\"'");
if ((strpos($matches[2], '[') !== false) || (strpos($matches[2], ']') !== false)) {
// It's a Reference to an external workbook (not currently supported)
- return $this->_raiseFormulaError('Unable to access External Workbook');
+ return $this->raiseFormulaError('Unable to access External Workbook');
}
// echo '$cellRef='.$cellRef.' in worksheet '.$matches[2].'
';
$this->_debugLog->writeDebugLog('Evaluating Cell ', $cellRef, ' in worksheet ', $matches[2]);
@@ -3418,7 +3417,7 @@ class PHPExcel_Calculation
$cellValue = null;
}
} else {
- return $this->_raiseFormulaError('Unable to access Cell Reference');
+ return $this->raiseFormulaError('Unable to access Cell Reference');
}
$this->_debugLog->writeDebugLog('Evaluation Result for cell ', $cellRef, ' in worksheet ', $matches[2], ' is ', $this->_showTypeDetails($cellValue));
// $cellRef = $matches[2].'!'.$cellRef;
@@ -3561,13 +3560,13 @@ class PHPExcel_Calculation
$this->_debugLog->writeDebugLog('Evaluation Result for named range ', $namedRange, ' is ', $this->_showTypeDetails($cellValue));
$stack->push('Named Range', $cellValue, $namedRange);
} else {
- return $this->_raiseFormulaError("undefined variable '$token'");
+ return $this->raiseFormulaError("undefined variable '$token'");
}
}
}
// when we're out of tokens, the stack should have a single element, the final result
if ($stack->count() != 1) {
- return $this->_raiseFormulaError("internal error");
+ return $this->raiseFormulaError("internal error");
}
$output = $stack->pop();
$output = $output['value'];
@@ -3579,7 +3578,7 @@ class PHPExcel_Calculation
}
- private function _validateBinaryOperand($cellID, &$operand, &$stack)
+ private function validateBinaryOperand($cellID, &$operand, &$stack)
{
if (is_array($operand)) {
if ((count($operand, COUNT_RECURSIVE) - count($operand)) == 1) {
@@ -3616,7 +3615,7 @@ class PHPExcel_Calculation
}
- private function _executeBinaryComparisonOperation($cellID, $operand1, $operand2, $operation, &$stack, $recursingArrays = false)
+ private function executeBinaryComparisonOperation($cellID, $operand1, $operand2, $operation, &$stack, $recursingArrays = false)
{
// If we're dealing with matrix operations, we want a matrix result
if ((is_array($operand1)) || (is_array($operand2))) {
@@ -3624,14 +3623,14 @@ class PHPExcel_Calculation
if ((is_array($operand1)) && (!is_array($operand2))) {
foreach ($operand1 as $x => $operandData) {
$this->_debugLog->writeDebugLog('Evaluating Comparison ', $this->_showValue($operandData), ' ', $operation, ' ', $this->_showValue($operand2));
- $this->_executeBinaryComparisonOperation($cellID, $operandData, $operand2, $operation, $stack);
+ $this->executeBinaryComparisonOperation($cellID, $operandData, $operand2, $operation, $stack);
$r = $stack->pop();
$result[$x] = $r['value'];
}
} elseif ((!is_array($operand1)) && (is_array($operand2))) {
foreach ($operand2 as $x => $operandData) {
$this->_debugLog->writeDebugLog('Evaluating Comparison ', $this->_showValue($operand1), ' ', $operation, ' ', $this->_showValue($operandData));
- $this->_executeBinaryComparisonOperation($cellID, $operand1, $operandData, $operation, $stack);
+ $this->executeBinaryComparisonOperation($cellID, $operand1, $operandData, $operation, $stack);
$r = $stack->pop();
$result[$x] = $r['value'];
}
@@ -3641,7 +3640,7 @@ class PHPExcel_Calculation
}
foreach ($operand1 as $x => $operandData) {
$this->_debugLog->writeDebugLog('Evaluating Comparison ', $this->_showValue($operandData), ' ', $operation, ' ', $this->_showValue($operand2[$x]));
- $this->_executeBinaryComparisonOperation($cellID, $operandData, $operand2[$x], $operation, $stack, true);
+ $this->executeBinaryComparisonOperation($cellID, $operandData, $operand2[$x], $operation, $stack, true);
$r = $stack->pop();
$result[$x] = $r['value'];
}
@@ -3750,13 +3749,13 @@ class PHPExcel_Calculation
return strcmp($inversedStr1, $inversedStr2);
}
- private function _executeNumericBinaryOperation($cellID, $operand1, $operand2, $operation, $matrixFunction, &$stack)
+ private function executeNumericBinaryOperation($cellID, $operand1, $operand2, $operation, $matrixFunction, &$stack)
{
// Validate the two operands
- if (!$this->_validateBinaryOperand($cellID, $operand1, $stack)) {
+ if (!$this->validateBinaryOperand($cellID, $operand1, $stack)) {
return false;
}
- if (!$this->_validateBinaryOperand($cellID, $operand2, $stack)) {
+ if (!$this->validateBinaryOperand($cellID, $operand2, $stack)) {
return false;
}
@@ -3825,7 +3824,7 @@ class PHPExcel_Calculation
// trigger an error, but nicely, if need be
- protected function _raiseFormulaError($errorMessage)
+ protected function raiseFormulaError($errorMessage)
{
$this->formulaError = $errorMessage;
$this->cyclicReferenceStack->clear();
diff --git a/Classes/PHPExcel/Chart/Legend.php b/Classes/PHPExcel/Chart/Legend.php
index 60f47c80..e850eb59 100644
--- a/Classes/PHPExcel/Chart/Legend.php
+++ b/Classes/PHPExcel/Chart/Legend.php
@@ -41,7 +41,7 @@ class PHPExcel_Chart_Legend
const POSITION_TOP = 't';
const POSITION_TOPRIGHT = 'tr';
- private static $_positionXLref = array(
+ private static $positionXLref = array(
self::xlLegendPositionBottom => self::POSITION_BOTTOM,
self::xlLegendPositionCorner => self::POSITION_TOPRIGHT,
self::xlLegendPositionCustom => '??',
@@ -99,7 +99,7 @@ class PHPExcel_Chart_Legend
*/
public function setPosition($position = self::POSITION_RIGHT)
{
- if (!in_array($position, self::$_positionXLref)) {
+ if (!in_array($position, self::$positionXLref)) {
return false;
}
@@ -114,7 +114,7 @@ class PHPExcel_Chart_Legend
*/
public function getPositionXL()
{
- return array_search($this->position, self::$_positionXLref);
+ return array_search($this->position, self::$positionXLref);
}
/**
@@ -124,11 +124,11 @@ class PHPExcel_Chart_Legend
*/
public function setPositionXL($positionXL = self::xlLegendPositionRight)
{
- if (!array_key_exists($positionXL, self::$_positionXLref)) {
+ if (!array_key_exists($positionXL, self::$positionXLref)) {
return false;
}
- $this->position = self::$_positionXLref[$positionXL];
+ $this->position = self::$positionXLref[$positionXL];
return true;
}
diff --git a/Classes/PHPExcel/Chart/Renderer/jpgraph.php b/Classes/PHPExcel/Chart/Renderer/jpgraph.php
index b95f3b28..b3d7396f 100644
--- a/Classes/PHPExcel/Chart/Renderer/jpgraph.php
+++ b/Classes/PHPExcel/Chart/Renderer/jpgraph.php
@@ -752,16 +752,19 @@ class PHPExcel_Chart_Renderer_jpgraph
switch ($chartType) {
case 'area3DChart':
$dimensions = '3d';
+ // no break
case 'areaChart':
$this->renderPlotLine($i, true, true, $dimensions);
break;
case 'bar3DChart':
$dimensions = '3d';
+ // no break
case 'barChart':
$this->renderPlotBar($i, $dimensions);
break;
case 'line3DChart':
$dimensions = '3d';
+ // no break
case 'lineChart':
$this->renderPlotLine($i, false, true, $dimensions);
break;
@@ -812,26 +815,31 @@ class PHPExcel_Chart_Renderer_jpgraph
switch ($chartType) {
case 'area3DChart':
$dimensions = '3d';
+ // no break
case 'areaChart':
$this->renderAreaChart($groupCount, $dimensions);
break;
case 'bar3DChart':
$dimensions = '3d';
+ // no break
case 'barChart':
$this->renderBarChart($groupCount, $dimensions);
break;
case 'line3DChart':
$dimensions = '3d';
+ // no break
case 'lineChart':
$this->renderLineChart($groupCount, $dimensions);
break;
case 'pie3DChart':
$dimensions = '3d';
+ // no break
case 'pieChart':
$this->renderPieChart($groupCount, $dimensions, false, false);
break;
case 'doughnut3DChart':
$dimensions = '3d';
+ // no break
case 'doughnutChart':
$this->renderPieChart($groupCount, $dimensions, true, true);
break;
@@ -846,6 +854,7 @@ class PHPExcel_Chart_Renderer_jpgraph
break;
case 'surface3DChart':
$dimensions = '3d';
+ // no break
case 'surfaceChart':
$this->renderContourChart($groupCount, $dimensions);
break;
diff --git a/Classes/PHPExcel/DocumentProperties.php b/Classes/PHPExcel/DocumentProperties.php
index 535c0c6d..f52059f5 100644
--- a/Classes/PHPExcel/DocumentProperties.php
+++ b/Classes/PHPExcel/DocumentProperties.php
@@ -535,7 +535,7 @@ class PHPExcel_DocumentProperties
return strtotime($propertyValue);
break;
case 'bool': // Boolean
- return ($propertyValue == 'true') ? True : False;
+ return ($propertyValue == 'true') ? true : false;
break;
case 'cy': // Currency
case 'error': // Error Status Code
@@ -556,7 +556,8 @@ class PHPExcel_DocumentProperties
return $propertyValue;
}
- public static function convertPropertyType($propertyType) {
+ public static function convertPropertyType($propertyType)
+ {
switch ($propertyType) {
case 'i1': // 1-Byte Signed Integer
case 'i2': // 2-Byte Signed Integer
@@ -607,5 +608,4 @@ class PHPExcel_DocumentProperties
}
return self::PROPERTY_TYPE_UNKNOWN;
}
-
}
diff --git a/Classes/PHPExcel/DocumentSecurity.php b/Classes/PHPExcel/DocumentSecurity.php
index 0887a2c3..ecea0da1 100644
--- a/Classes/PHPExcel/DocumentSecurity.php
+++ b/Classes/PHPExcel/DocumentSecurity.php
@@ -32,35 +32,35 @@ class PHPExcel_DocumentSecurity
*
* @var boolean
*/
- private $_lockRevision;
+ private $lockRevision;
/**
* LockStructure
*
* @var boolean
*/
- private $_lockStructure;
+ private $lockStructure;
/**
* LockWindows
*
* @var boolean
*/
- private $_lockWindows;
+ private $lockWindows;
/**
* RevisionsPassword
*
* @var string
*/
- private $_revisionsPassword;
+ private $revisionsPassword;
/**
* WorkbookPassword
*
* @var string
*/
- private $_workbookPassword;
+ private $workbookPassword;
/**
* Create a new PHPExcel_DocumentSecurity
@@ -68,11 +68,11 @@ class PHPExcel_DocumentSecurity
public function __construct()
{
// Initialise values
- $this->_lockRevision = false;
- $this->_lockStructure = false;
- $this->_lockWindows = false;
- $this->_revisionsPassword = '';
- $this->_workbookPassword = '';
+ $this->lockRevision = false;
+ $this->lockStructure = false;
+ $this->lockWindows = false;
+ $this->revisionsPassword = '';
+ $this->workbookPassword = '';
}
/**
@@ -82,9 +82,9 @@ class PHPExcel_DocumentSecurity
*/
public function isSecurityEnabled()
{
- return $this->_lockRevision ||
- $this->_lockStructure ||
- $this->_lockWindows;
+ return $this->lockRevision ||
+ $this->lockStructure ||
+ $this->lockWindows;
}
/**
@@ -94,7 +94,7 @@ class PHPExcel_DocumentSecurity
*/
public function getLockRevision()
{
- return $this->_lockRevision;
+ return $this->lockRevision;
}
/**
@@ -105,7 +105,7 @@ class PHPExcel_DocumentSecurity
*/
public function setLockRevision($pValue = false)
{
- $this->_lockRevision = $pValue;
+ $this->lockRevision = $pValue;
return $this;
}
@@ -116,7 +116,7 @@ class PHPExcel_DocumentSecurity
*/
public function getLockStructure()
{
- return $this->_lockStructure;
+ return $this->lockStructure;
}
/**
@@ -127,7 +127,7 @@ class PHPExcel_DocumentSecurity
*/
public function setLockStructure($pValue = false)
{
- $this->_lockStructure = $pValue;
+ $this->lockStructure = $pValue;
return $this;
}
@@ -138,7 +138,7 @@ class PHPExcel_DocumentSecurity
*/
public function getLockWindows()
{
- return $this->_lockWindows;
+ return $this->lockWindows;
}
/**
@@ -149,7 +149,7 @@ class PHPExcel_DocumentSecurity
*/
public function setLockWindows($pValue = false)
{
- $this->_lockWindows = $pValue;
+ $this->lockWindows = $pValue;
return $this;
}
@@ -160,7 +160,7 @@ class PHPExcel_DocumentSecurity
*/
public function getRevisionsPassword()
{
- return $this->_revisionsPassword;
+ return $this->revisionsPassword;
}
/**
@@ -175,7 +175,7 @@ class PHPExcel_DocumentSecurity
if (!$pAlreadyHashed) {
$pValue = PHPExcel_Shared_PasswordHasher::hashPassword($pValue);
}
- $this->_revisionsPassword = $pValue;
+ $this->revisionsPassword = $pValue;
return $this;
}
@@ -186,7 +186,7 @@ class PHPExcel_DocumentSecurity
*/
public function getWorkbookPassword()
{
- return $this->_workbookPassword;
+ return $this->workbookPassword;
}
/**
@@ -201,7 +201,7 @@ class PHPExcel_DocumentSecurity
if (!$pAlreadyHashed) {
$pValue = PHPExcel_Shared_PasswordHasher::hashPassword($pValue);
}
- $this->_workbookPassword = $pValue;
+ $this->workbookPassword = $pValue;
return $this;
}
diff --git a/Classes/PHPExcel/HashTable.php b/Classes/PHPExcel/HashTable.php
index 6fca1431..f752a363 100644
--- a/Classes/PHPExcel/HashTable.php
+++ b/Classes/PHPExcel/HashTable.php
@@ -66,7 +66,7 @@ class PHPExcel_HashTable
// Check if an array was passed
if ($pSource == null) {
return;
- } else if (!is_array($pSource)) {
+ } elseif (!is_array($pSource)) {
throw new PHPExcel_Exception('Invalid array parameter passed.');
}
diff --git a/Classes/PHPExcel/Helper/HTML.php b/Classes/PHPExcel/Helper/HTML.php
index 86cbe31f..28bf6b10 100644
--- a/Classes/PHPExcel/Helper/HTML.php
+++ b/Classes/PHPExcel/Helper/HTML.php
@@ -3,7 +3,7 @@
class PHPExcel_Helper_HTML
{
protected static $colourMap = array(
- 'aliceblue' => 'f0f8ff',
+ 'aliceblue' => 'f0f8ff',
'antiquewhite' => 'faebd7',
'antiquewhite1' => 'ffefdb',
'antiquewhite2' => 'eedfcc',
@@ -573,7 +573,8 @@ class PHPExcel_Helper_HTML
protected $richTextObject;
- protected function initialise() {
+ protected function initialise()
+ {
$this->face = $this->size = $this->color = null;
$this->bold = $this->italic = $this->underline = $this->superscript = $this->subscript = $this->strikethrough = false;
@@ -582,7 +583,8 @@ class PHPExcel_Helper_HTML
$this->stringData = '';
}
- public function toRichTextObject($html) {
+ public function toRichTextObject($html)
+ {
$this->initialise();
// Create a new DOM object
@@ -594,15 +596,17 @@ class PHPExcel_Helper_HTML
// Discard excess white space
$dom->preserveWhiteSpace = false;
- $this->richTextObject = new PHPExcel_RichText();;
+ $this->richTextObject = new PHPExcel_RichText();
$this->parseElements($dom);
return $this->richTextObject;
}
- protected function buildTextRun() {
+ protected function buildTextRun()
+ {
$text = $this->stringData;
- if (trim($text) === '')
+ if (trim($text) === '') {
return;
+ }
$richtextRun = $this->richTextObject->createTextRun($this->stringData);
if ($this->face) {
@@ -612,7 +616,7 @@ class PHPExcel_Helper_HTML
$richtextRun->getFont()->setSize($this->size);
}
if ($this->color) {
- $richtextRun->getFont()->setColor( new PHPExcel_Style_Color( 'ff' . $this->color ) );
+ $richtextRun->getFont()->setColor(new PHPExcel_Style_Color('ff' . $this->color));
}
if ($this->bold) {
$richtextRun->getFont()->setBold(true);
@@ -635,7 +639,8 @@ class PHPExcel_Helper_HTML
$this->stringData = '';
}
- protected function rgbToColour($rgb) {
+ protected function rgbToColour($rgb)
+ {
preg_match_all('/\d+/', $rgb, $values);
foreach ($values[0] as &$value) {
$value = str_pad(dechex($value), 2, '0', STR_PAD_LEFT);
@@ -643,11 +648,13 @@ class PHPExcel_Helper_HTML
return implode($values[0]);
}
- protected function colourNameLookup($rgb) {
+ protected function colourNameLookup($rgb)
+ {
return self::$colourMap[$rgb];
}
- protected function startFontTag($tag) {
+ protected function startFontTag($tag)
+ {
foreach ($tag->attributes as $attribute) {
$attributeName = strtolower($attribute->name);
$attributeValue = $attribute->value;
@@ -666,69 +673,85 @@ class PHPExcel_Helper_HTML
}
}
- protected function endFontTag() {
+ protected function endFontTag()
+ {
$this->face = $this->size = $this->color = null;
}
- protected function startBoldTag() {
+ protected function startBoldTag()
+ {
$this->bold = true;
}
- protected function endBoldTag() {
+ protected function endBoldTag()
+ {
$this->bold = false;
}
- protected function startItalicTag() {
+ protected function startItalicTag()
+ {
$this->italic = true;
}
- protected function endItalicTag() {
+ protected function endItalicTag()
+ {
$this->italic = false;
}
- protected function startUnderlineTag() {
+ protected function startUnderlineTag()
+ {
$this->underline = true;
}
- protected function endUnderlineTag() {
+ protected function endUnderlineTag()
+ {
$this->underline = false;
}
- protected function startSubscriptTag() {
+ protected function startSubscriptTag()
+ {
$this->subscript = true;
}
- protected function endSubscriptTag() {
+ protected function endSubscriptTag()
+ {
$this->subscript = false;
}
- protected function startSuperscriptTag() {
+ protected function startSuperscriptTag()
+ {
$this->superscript = true;
}
- protected function endSuperscriptTag() {
+ protected function endSuperscriptTag()
+ {
$this->superscript = false;
}
- protected function startStrikethruTag() {
+ protected function startStrikethruTag()
+ {
$this->strikethrough = true;
}
- protected function endStrikethruTag() {
+ protected function endStrikethruTag()
+ {
$this->strikethrough = false;
}
- protected function breakTag() {
+ protected function breakTag()
+ {
$this->stringData .= PHP_EOL;
}
- protected function parseTextNode(DOMText $textNode) {
+ protected function parseTextNode(DOMText $textNode)
+ {
$domText = preg_replace('/\s+/u', ' ', ltrim($textNode->nodeValue));
$this->stringData .= $domText;
$this->buildTextRun();
}
- protected function handleCallback($element, $callbackTag, $callbacks) {
+ protected function handleCallback($element, $callbackTag, $callbacks)
+ {
if (isset($callbacks[$callbackTag])) {
$elementHandler = $callbacks[$callbackTag];
if (method_exists($this, $elementHandler)) {
@@ -737,7 +760,8 @@ class PHPExcel_Helper_HTML
}
}
- protected function parseElementNode(DOMElement $element) {
+ protected function parseElementNode(DOMElement $element)
+ {
$callbackTag = strtolower($element->nodeName);
$this->stack[] = $callbackTag;
@@ -750,7 +774,8 @@ class PHPExcel_Helper_HTML
$this->handleCallback($element, $callbackTag, $this->endTagCallbacks);
}
- protected function parseElements(DOMNode $element) {
+ protected function parseElements(DOMNode $element)
+ {
foreach ($element->childNodes as $child) {
if ($child instanceof DOMText) {
$this->parseTextNode($child);
diff --git a/Classes/PHPExcel/IOFactory.php b/Classes/PHPExcel/IOFactory.php
index 8b063cd7..bc1d99e3 100644
--- a/Classes/PHPExcel/IOFactory.php
+++ b/Classes/PHPExcel/IOFactory.php
@@ -70,7 +70,7 @@ class PHPExcel_IOFactory
* Private constructor for PHPExcel_IOFactory
*/
private function __construct()
- {
+ {
}
/**
diff --git a/Classes/PHPExcel/Reader/Abstract.php b/Classes/PHPExcel/Reader/Abstract.php
index a0201366..08f8dbd1 100644
--- a/Classes/PHPExcel/Reader/Abstract.php
+++ b/Classes/PHPExcel/Reader/Abstract.php
@@ -42,7 +42,7 @@ abstract class PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader
*
* @var boolean
*/
- protected $_readDataOnly = FALSE;
+ protected $_readDataOnly = false;
/**
* Read charts that are defined in the workbook?
@@ -50,7 +50,7 @@ abstract class PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader
*
* @var boolean
*/
- protected $_includeCharts = FALSE;
+ protected $_includeCharts = false;
/**
* Restrict which sheets should be loaded?
@@ -58,16 +58,16 @@ abstract class PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader
*
* @var array of string
*/
- protected $_loadSheetsOnly = NULL;
+ protected $_loadSheetsOnly = null;
/**
* PHPExcel_Reader_IReadFilter instance
*
* @var PHPExcel_Reader_IReadFilter
*/
- protected $_readFilter = NULL;
+ protected $_readFilter = null;
- protected $_fileHandle = NULL;
+ protected $_fileHandle = null;
/**
@@ -77,7 +77,8 @@ abstract class PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader
*
* @return boolean
*/
- public function getReadDataOnly() {
+ public function getReadDataOnly()
+ {
return $this->_readDataOnly;
}
@@ -90,7 +91,8 @@ abstract class PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader
*
* @return PHPExcel_Reader_IReader
*/
- public function setReadDataOnly($pValue = FALSE) {
+ public function setReadDataOnly($pValue = false)
+ {
$this->_readDataOnly = $pValue;
return $this;
}
@@ -103,7 +105,8 @@ abstract class PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader
*
* @return boolean
*/
- public function getIncludeCharts() {
+ public function getIncludeCharts()
+ {
return $this->_includeCharts;
}
@@ -117,7 +120,8 @@ abstract class PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader
*
* @return PHPExcel_Reader_IReader
*/
- public function setIncludeCharts($pValue = FALSE) {
+ public function setIncludeCharts($pValue = false)
+ {
$this->_includeCharts = (boolean) $pValue;
return $this;
}
@@ -143,13 +147,13 @@ abstract class PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader
*
* @return PHPExcel_Reader_IReader
*/
- public function setLoadSheetsOnly($value = NULL)
+ public function setLoadSheetsOnly($value = null)
{
- if ($value === NULL)
+ if ($value === null) {
return $this->setLoadAllSheets();
+ }
- $this->_loadSheetsOnly = is_array($value) ?
- $value : array($value);
+ $this->_loadSheetsOnly = is_array($value) ? $value : array($value);
return $this;
}
@@ -161,7 +165,7 @@ abstract class PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader
*/
public function setLoadAllSheets()
{
- $this->_loadSheetsOnly = NULL;
+ $this->_loadSheetsOnly = null;
return $this;
}
@@ -170,7 +174,8 @@ abstract class PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader
*
* @return PHPExcel_Reader_IReadFilter
*/
- public function getReadFilter() {
+ public function getReadFilter()
+ {
return $this->_readFilter;
}
@@ -180,7 +185,8 @@ abstract class PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader
* @param PHPExcel_Reader_IReadFilter $pValue
* @return PHPExcel_Reader_IReader
*/
- public function setReadFilter(PHPExcel_Reader_IReadFilter $pValue) {
+ public function setReadFilter(PHPExcel_Reader_IReadFilter $pValue)
+ {
$this->_readFilter = $pValue;
return $this;
}
@@ -201,7 +207,7 @@ abstract class PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader
// Open file
$this->_fileHandle = fopen($pFilename, 'r');
- if ($this->_fileHandle === FALSE) {
+ if ($this->_fileHandle === false) {
throw new PHPExcel_Reader_Exception("Could not open file " . $pFilename . " for reading.");
}
}
@@ -219,11 +225,11 @@ abstract class PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader
try {
$this->_openFile($pFilename);
} catch (Exception $e) {
- return FALSE;
+ return false;
}
$readable = $this->_isValidFormat();
- fclose ($this->_fileHandle);
+ fclose($this->_fileHandle);
return $readable;
}
@@ -236,7 +242,7 @@ abstract class PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader
public function securityScan($xml)
{
$pattern = '/\\0?' . implode('\\0?', str_split('_readFilter = new PHPExcel_Reader_DefaultReadFilter();
}
@@ -238,8 +239,8 @@ class PHPExcel_Reader_Excel2003XML extends PHPExcel_Reader_Abstract implements P
return $this->loadIntoExisting($pFilename, $objPHPExcel);
}
-
- protected static function identifyFixedStyleValue($styleList,&$styleAttributeValue) {
+ protected static function identifyFixedStyleValue($styleList,&$styleAttributeValue)
+ {
$styleAttributeValue = strtolower($styleAttributeValue);
foreach ($styleList as $style) {
if ($styleAttributeValue == strtolower($style)) {
@@ -250,13 +251,13 @@ class PHPExcel_Reader_Excel2003XML extends PHPExcel_Reader_Abstract implements P
return false;
}
-
/**
* pixel units to excel width units(units of 1/256th of a character width)
* @param pxs
* @return
*/
- protected static function _pixel2WidthUnits($pxs) {
+ protected static function _pixel2WidthUnits($pxs)
+ {
$UNIT_OFFSET_MAP = array(0, 36, 73, 109, 146, 182, 219);
$widthUnits = 256 * ($pxs / 7);
@@ -264,25 +265,24 @@ class PHPExcel_Reader_Excel2003XML extends PHPExcel_Reader_Abstract implements P
return $widthUnits;
}
-
/**
* excel width units(units of 1/256th of a character width) to pixel units
* @param widthUnits
* @return
*/
- protected static function _widthUnits2Pixel($widthUnits) {
+ protected static function _widthUnits2Pixel($widthUnits)
+ {
$pixels = ($widthUnits / 256) * 7;
$offsetWidthUnits = $widthUnits % 256;
$pixels += round($offsetWidthUnits / (256 / 7));
return $pixels;
}
-
- protected static function _hex2str($hex) {
+ protected static function _hex2str($hex)
+ {
return chr(hexdec($hex[1]));
}
-
/**
* Loads PHPExcel from file into PHPExcel instance
*
@@ -293,35 +293,34 @@ class PHPExcel_Reader_Excel2003XML extends PHPExcel_Reader_Abstract implements P
*/
public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel)
{
- $fromFormats = array('\-', '\ ');
- $toFormats = array('-', ' ');
+ $fromFormats = array('\-', '\ ');
+ $toFormats = array('-', ' ');
$underlineStyles = array (
- PHPExcel_Style_Font::UNDERLINE_NONE,
- PHPExcel_Style_Font::UNDERLINE_DOUBLE,
- PHPExcel_Style_Font::UNDERLINE_DOUBLEACCOUNTING,
- PHPExcel_Style_Font::UNDERLINE_SINGLE,
- PHPExcel_Style_Font::UNDERLINE_SINGLEACCOUNTING
- );
+ PHPExcel_Style_Font::UNDERLINE_NONE,
+ PHPExcel_Style_Font::UNDERLINE_DOUBLE,
+ PHPExcel_Style_Font::UNDERLINE_DOUBLEACCOUNTING,
+ PHPExcel_Style_Font::UNDERLINE_SINGLE,
+ PHPExcel_Style_Font::UNDERLINE_SINGLEACCOUNTING
+ );
$verticalAlignmentStyles = array (
- PHPExcel_Style_Alignment::VERTICAL_BOTTOM,
- PHPExcel_Style_Alignment::VERTICAL_TOP,
- PHPExcel_Style_Alignment::VERTICAL_CENTER,
- PHPExcel_Style_Alignment::VERTICAL_JUSTIFY
- );
+ PHPExcel_Style_Alignment::VERTICAL_BOTTOM,
+ PHPExcel_Style_Alignment::VERTICAL_TOP,
+ PHPExcel_Style_Alignment::VERTICAL_CENTER,
+ PHPExcel_Style_Alignment::VERTICAL_JUSTIFY
+ );
$horizontalAlignmentStyles = array (
- PHPExcel_Style_Alignment::HORIZONTAL_GENERAL,
- PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
- PHPExcel_Style_Alignment::HORIZONTAL_RIGHT,
- PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
- PHPExcel_Style_Alignment::HORIZONTAL_CENTER_CONTINUOUS,
- PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY
- );
+ PHPExcel_Style_Alignment::HORIZONTAL_GENERAL,
+ PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
+ PHPExcel_Style_Alignment::HORIZONTAL_RIGHT,
+ PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
+ PHPExcel_Style_Alignment::HORIZONTAL_CENTER_CONTINUOUS,
+ PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY
+ );
$timezoneObj = new DateTimeZone('Europe/London');
$GMT = new DateTimeZone('UTC');
-
// Check if file exists
if (!file_exists($pFilename)) {
throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist.");
@@ -339,40 +338,40 @@ class PHPExcel_Reader_Excel2003XML extends PHPExcel_Reader_Abstract implements P
foreach ($xml->DocumentProperties[0] as $propertyName => $propertyValue) {
switch ($propertyName) {
case 'Title' :
- $docProps->setTitle(self::_convertStringEncoding($propertyValue, $this->_charSet));
- break;
+ $docProps->setTitle(self::_convertStringEncoding($propertyValue, $this->_charSet));
+ break;
case 'Subject' :
- $docProps->setSubject(self::_convertStringEncoding($propertyValue, $this->_charSet));
- break;
+ $docProps->setSubject(self::_convertStringEncoding($propertyValue, $this->_charSet));
+ break;
case 'Author' :
- $docProps->setCreator(self::_convertStringEncoding($propertyValue, $this->_charSet));
- break;
+ $docProps->setCreator(self::_convertStringEncoding($propertyValue, $this->_charSet));
+ break;
case 'Created' :
- $creationDate = strtotime($propertyValue);
- $docProps->setCreated($creationDate);
- break;
+ $creationDate = strtotime($propertyValue);
+ $docProps->setCreated($creationDate);
+ break;
case 'LastAuthor' :
- $docProps->setLastModifiedBy(self::_convertStringEncoding($propertyValue, $this->_charSet));
- break;
+ $docProps->setLastModifiedBy(self::_convertStringEncoding($propertyValue, $this->_charSet));
+ break;
case 'LastSaved' :
- $lastSaveDate = strtotime($propertyValue);
- $docProps->setModified($lastSaveDate);
- break;
+ $lastSaveDate = strtotime($propertyValue);
+ $docProps->setModified($lastSaveDate);
+ break;
case 'Company' :
- $docProps->setCompany(self::_convertStringEncoding($propertyValue, $this->_charSet));
- break;
+ $docProps->setCompany(self::_convertStringEncoding($propertyValue, $this->_charSet));
+ break;
case 'Category' :
- $docProps->setCategory(self::_convertStringEncoding($propertyValue, $this->_charSet));
- break;
+ $docProps->setCategory(self::_convertStringEncoding($propertyValue, $this->_charSet));
+ break;
case 'Manager' :
- $docProps->setManager(self::_convertStringEncoding($propertyValue, $this->_charSet));
- break;
+ $docProps->setManager(self::_convertStringEncoding($propertyValue, $this->_charSet));
+ break;
case 'Keywords' :
- $docProps->setKeywords(self::_convertStringEncoding($propertyValue, $this->_charSet));
- break;
+ $docProps->setKeywords(self::_convertStringEncoding($propertyValue, $this->_charSet));
+ break;
case 'Description' :
- $docProps->setDescription(self::_convertStringEncoding($propertyValue, $this->_charSet));
- break;
+ $docProps->setDescription(self::_convertStringEncoding($propertyValue, $this->_charSet));
+ break;
}
}
}
@@ -421,113 +420,113 @@ class PHPExcel_Reader_Excel2003XML extends PHPExcel_Reader_Abstract implements P
// echo $styleType.'
';
switch ($styleType) {
case 'Alignment' :
- foreach ($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
+ foreach ($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
// echo $styleAttributeKey.' = '.$styleAttributeValue.'
';
- $styleAttributeValue = (string) $styleAttributeValue;
- switch ($styleAttributeKey) {
- case 'Vertical' :
- if (self::identifyFixedStyleValue($verticalAlignmentStyles, $styleAttributeValue)) {
- $this->_styles[$styleID]['alignment']['vertical'] = $styleAttributeValue;
- }
- break;
- case 'Horizontal' :
- if (self::identifyFixedStyleValue($horizontalAlignmentStyles, $styleAttributeValue)) {
- $this->_styles[$styleID]['alignment']['horizontal'] = $styleAttributeValue;
- }
- break;
- case 'WrapText' :
- $this->_styles[$styleID]['alignment']['wrap'] = true;
- break;
- }
+ $styleAttributeValue = (string) $styleAttributeValue;
+ switch ($styleAttributeKey) {
+ case 'Vertical' :
+ if (self::identifyFixedStyleValue($verticalAlignmentStyles, $styleAttributeValue)) {
+ $this->_styles[$styleID]['alignment']['vertical'] = $styleAttributeValue;
+ }
+ break;
+ case 'Horizontal' :
+ if (self::identifyFixedStyleValue($horizontalAlignmentStyles, $styleAttributeValue)) {
+ $this->_styles[$styleID]['alignment']['horizontal'] = $styleAttributeValue;
+ }
+ break;
+ case 'WrapText' :
+ $this->_styles[$styleID]['alignment']['wrap'] = true;
+ break;
}
- break;
+ }
+ break;
case 'Borders' :
- foreach ($styleData->Border as $borderStyle) {
- $borderAttributes = $borderStyle->attributes($namespaces['ss']);
- $thisBorder = array();
- foreach ($borderAttributes as $borderStyleKey => $borderStyleValue) {
+ foreach ($styleData->Border as $borderStyle) {
+ $borderAttributes = $borderStyle->attributes($namespaces['ss']);
+ $thisBorder = array();
+ foreach ($borderAttributes as $borderStyleKey => $borderStyleValue) {
// echo $borderStyleKey.' = '.$borderStyleValue.'
';
- switch ($borderStyleKey) {
- case 'LineStyle' :
- $thisBorder['style'] = PHPExcel_Style_Border::BORDER_MEDIUM;
+ switch ($borderStyleKey) {
+ case 'LineStyle' :
+ $thisBorder['style'] = PHPExcel_Style_Border::BORDER_MEDIUM;
// $thisBorder['style'] = $borderStyleValue;
- break;
- case 'Weight' :
+ break;
+ case 'Weight' :
// $thisBorder['style'] = $borderStyleValue;
- break;
- case 'Position' :
- $borderPosition = strtolower($borderStyleValue);
- break;
- case 'Color' :
- $borderColour = substr($borderStyleValue,1);
- $thisBorder['color']['rgb'] = $borderColour;
- break;
- }
- }
- if (!empty($thisBorder)) {
- if (($borderPosition == 'left') || ($borderPosition == 'right') || ($borderPosition == 'top') || ($borderPosition == 'bottom')) {
- $this->_styles[$styleID]['borders'][$borderPosition] = $thisBorder;
- }
+ break;
+ case 'Position' :
+ $borderPosition = strtolower($borderStyleValue);
+ break;
+ case 'Color' :
+ $borderColour = substr($borderStyleValue,1);
+ $thisBorder['color']['rgb'] = $borderColour;
+ break;
}
}
- break;
+ if (!empty($thisBorder)) {
+ if (($borderPosition == 'left') || ($borderPosition == 'right') || ($borderPosition == 'top') || ($borderPosition == 'bottom')) {
+ $this->_styles[$styleID]['borders'][$borderPosition] = $thisBorder;
+ }
+ }
+ }
+ break;
case 'Font' :
- foreach ($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
+ foreach ($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
// echo $styleAttributeKey.' = '.$styleAttributeValue.'
';
- $styleAttributeValue = (string) $styleAttributeValue;
- switch ($styleAttributeKey) {
- case 'FontName' :
- $this->_styles[$styleID]['font']['name'] = $styleAttributeValue;
- break;
- case 'Size' :
- $this->_styles[$styleID]['font']['size'] = $styleAttributeValue;
- break;
- case 'Color' :
- $this->_styles[$styleID]['font']['color']['rgb'] = substr($styleAttributeValue,1);
- break;
- case 'Bold' :
- $this->_styles[$styleID]['font']['bold'] = true;
- break;
- case 'Italic' :
- $this->_styles[$styleID]['font']['italic'] = true;
- break;
- case 'Underline' :
- if (self::identifyFixedStyleValue($underlineStyles, $styleAttributeValue)) {
- $this->_styles[$styleID]['font']['underline'] = $styleAttributeValue;
- }
- break;
- }
+ $styleAttributeValue = (string) $styleAttributeValue;
+ switch ($styleAttributeKey) {
+ case 'FontName' :
+ $this->_styles[$styleID]['font']['name'] = $styleAttributeValue;
+ break;
+ case 'Size' :
+ $this->_styles[$styleID]['font']['size'] = $styleAttributeValue;
+ break;
+ case 'Color' :
+ $this->_styles[$styleID]['font']['color']['rgb'] = substr($styleAttributeValue,1);
+ break;
+ case 'Bold' :
+ $this->_styles[$styleID]['font']['bold'] = true;
+ break;
+ case 'Italic' :
+ $this->_styles[$styleID]['font']['italic'] = true;
+ break;
+ case 'Underline' :
+ if (self::identifyFixedStyleValue($underlineStyles, $styleAttributeValue)) {
+ $this->_styles[$styleID]['font']['underline'] = $styleAttributeValue;
+ }
+ break;
}
- break;
+ }
+ break;
case 'Interior' :
- foreach ($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
+ foreach ($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
// echo $styleAttributeKey.' = '.$styleAttributeValue.'
';
- switch ($styleAttributeKey) {
- case 'Color' :
- $this->_styles[$styleID]['fill']['color']['rgb'] = substr($styleAttributeValue,1);
- break;
- }
+ switch ($styleAttributeKey) {
+ case 'Color' :
+ $this->_styles[$styleID]['fill']['color']['rgb'] = substr($styleAttributeValue,1);
+ break;
}
- break;
+ }
+ break;
case 'NumberFormat' :
- foreach ($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
+ foreach ($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
// echo $styleAttributeKey.' = '.$styleAttributeValue.'
';
- $styleAttributeValue = str_replace($fromFormats, $toFormats, $styleAttributeValue);
- switch ($styleAttributeValue) {
- case 'Short Date' :
- $styleAttributeValue = 'dd/mm/yyyy';
- break;
- }
- if ($styleAttributeValue > '') {
- $this->_styles[$styleID]['numberformat']['code'] = $styleAttributeValue;
- }
+ $styleAttributeValue = str_replace($fromFormats, $toFormats, $styleAttributeValue);
+ switch ($styleAttributeValue) {
+ case 'Short Date' :
+ $styleAttributeValue = 'dd/mm/yyyy';
+ break;
}
- break;
+ if ($styleAttributeValue > '') {
+ $this->_styles[$styleID]['numberformat']['code'] = $styleAttributeValue;
+ }
+ }
+ break;
case 'Protection' :
- foreach ($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
+ foreach ($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
// echo $styleAttributeKey.' = '.$styleAttributeValue.'
';
- }
- break;
+ }
+ break;
}
}
// print_r($this->_styles[$styleID]);
@@ -588,14 +587,13 @@ class PHPExcel_Reader_Excel2003XML extends PHPExcel_Reader_Abstract implements P
$columnID = 'A';
foreach ($rowData->Cell as $cell) {
-
$cell_ss = $cell->attributes($namespaces['ss']);
if (isset($cell_ss['Index'])) {
$columnID = PHPExcel_Cell::stringFromColumnIndex($cell_ss['Index']-1);
}
$cellRange = $columnID.$rowID;
- if ($this->getReadFilter() !== NULL) {
+ if ($this->getReadFilter() !== null) {
if (!$this->getReadFilter()->readCell($columnID, $rowID, $worksheetName)) {
continue;
}
@@ -643,27 +641,27 @@ class PHPExcel_Reader_Excel2003XML extends PHPExcel_Reader_Abstract implements P
const TYPE_ERROR = 'e';
*/
case 'String' :
- $cellValue = self::_convertStringEncoding($cellValue, $this->_charSet);
- $type = PHPExcel_Cell_DataType::TYPE_STRING;
- break;
+ $cellValue = self::_convertStringEncoding($cellValue, $this->_charSet);
+ $type = PHPExcel_Cell_DataType::TYPE_STRING;
+ break;
case 'Number' :
- $type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
- $cellValue = (float) $cellValue;
- if (floor($cellValue) == $cellValue) {
- $cellValue = (integer) $cellValue;
- }
- break;
+ $type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
+ $cellValue = (float) $cellValue;
+ if (floor($cellValue) == $cellValue) {
+ $cellValue = (integer) $cellValue;
+ }
+ break;
case 'Boolean' :
- $type = PHPExcel_Cell_DataType::TYPE_BOOL;
- $cellValue = ($cellValue != 0);
- break;
+ $type = PHPExcel_Cell_DataType::TYPE_BOOL;
+ $cellValue = ($cellValue != 0);
+ break;
case 'DateTime' :
- $type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
- $cellValue = PHPExcel_Shared_Date::PHPToExcel(strtotime($cellValue));
- break;
+ $type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
+ $cellValue = PHPExcel_Shared_Date::PHPToExcel(strtotime($cellValue));
+ break;
case 'Error' :
- $type = PHPExcel_Cell_DataType::TYPE_ERROR;
- break;
+ $type = PHPExcel_Cell_DataType::TYPE_ERROR;
+ break;
}
}
@@ -700,16 +698,24 @@ class PHPExcel_Reader_Excel2003XML extends PHPExcel_Reader_Abstract implements P
foreach ($cellReferences as $cellReference) {
$rowReference = $cellReference[2][0];
// Empty R reference is the current row
- if ($rowReference == '') $rowReference = $rowID;
+ if ($rowReference == '') {
+ $rowReference = $rowID;
+ }
// Bracketed R references are relative to the current row
- if ($rowReference{0} == '[') $rowReference = $rowID + trim($rowReference,'[]');
+ if ($rowReference{0} == '[') {
+ $rowReference = $rowID + trim($rowReference,'[]');
+ }
$columnReference = $cellReference[4][0];
// Empty C reference is the current column
- if ($columnReference == '') $columnReference = $columnNumber;
+ if ($columnReference == '') {
+ $columnReference = $columnNumber;
+ }
// Bracketed C references are relative to the current column
- if ($columnReference{0} == '[') $columnReference = $columnNumber + trim($columnReference,'[]');
+ if ($columnReference{0} == '[') {
+ $columnReference = $columnNumber + trim($columnReference,'[]');
+ }
$A1CellReference = PHPExcel_Cell::stringFromColumnIndex($columnReference-1).$rowReference;
- $value = substr_replace($value, $A1CellReference, $cellReference[0][1],strlen($cellReference[0][0]));
+ $value = substr_replace($value, $A1CellReference, $cellReference[0][1],strlen($cellReference[0][0]));
}
}
}
@@ -743,9 +749,7 @@ class PHPExcel_Reader_Excel2003XML extends PHPExcel_Reader_Abstract implements P
// echo $annotation,'
';
$annotation = strip_tags($node);
// echo 'Annotation: ', $annotation,'
';
- $objPHPExcel->getActiveSheet()->getComment( $columnID.$rowID )
- ->setAuthor(self::_convertStringEncoding($author , $this->_charSet))
- ->setText($this->_parseRichText($annotation) );
+ $objPHPExcel->getActiveSheet()->getComment($columnID.$rowID)->setAuthor(self::_convertStringEncoding($author , $this->_charSet))->setText($this->_parseRichText($annotation) );
}
if (($cellIsSet) && (isset($cell_ss['StyleID']))) {
@@ -756,7 +760,7 @@ class PHPExcel_Reader_Excel2003XML extends PHPExcel_Reader_Abstract implements P
// print_r($this->_styles[$style]);
// echo '
';
if (!$objPHPExcel->getActiveSheet()->cellExists($columnID.$rowID)) {
- $objPHPExcel->getActiveSheet()->getCell($columnID.$rowID)->setValue(NULL);
+ $objPHPExcel->getActiveSheet()->getCell($columnID.$rowID)->setValue(null);
}
$objPHPExcel->getActiveSheet()->getStyle($cellRange)->applyFromArray($this->_styles[$style]);
}
@@ -790,20 +794,21 @@ class PHPExcel_Reader_Excel2003XML extends PHPExcel_Reader_Abstract implements P
}
- protected static function _convertStringEncoding($string, $charset) {
+ protected static function _convertStringEncoding($string, $charset)
+ {
if ($charset != 'UTF-8') {
- return PHPExcel_Shared_String::ConvertEncoding($string,'UTF-8', $charset);
+ return PHPExcel_Shared_String::ConvertEncoding($string, 'UTF-8', $charset);
}
return $string;
}
- protected function _parseRichText($is = '') {
+ protected function _parseRichText($is = '')
+ {
$value = new PHPExcel_RichText();
$value->createText(self::_convertStringEncoding($is, $this->_charSet));
return $value;
}
-
}
diff --git a/Classes/PHPExcel/Reader/HTML.php b/Classes/PHPExcel/Reader/HTML.php
index 6b60f3f0..a7272e47 100644
--- a/Classes/PHPExcel/Reader/HTML.php
+++ b/Classes/PHPExcel/Reader/HTML.php
@@ -1,7 +1,15 @@
_fileHandle, 2048);
- if ((strpos($data, '<') !== FALSE) &&
+ if ((strpos($data, '<') !== false) &&
(strlen($data) !== strlen(strip_tags($data)))) {
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
}
/**
@@ -173,8 +166,9 @@ class PHPExcel_Reader_HTML extends PHPExcel_Reader_Abstract implements PHPExcel_
protected function _setTableStartColumn($column)
{
- if ($this->_tableLevel == 0)
+ if ($this->_tableLevel == 0) {
$column = 'A';
+ }
++$this->_tableLevel;
$this->_nestedColumn[$this->_tableLevel] = $column;
@@ -235,7 +229,7 @@ class PHPExcel_Reader_HTML extends PHPExcel_Reader_Abstract implements PHPExcel_
}
switch ($child->nodeName) {
- case 'meta' :
+ case 'meta':
foreach ($attributeArray as $attributeName => $attributeValue) {
switch ($attributeName) {
case 'content':
@@ -246,27 +240,29 @@ class PHPExcel_Reader_HTML extends PHPExcel_Reader_Abstract implements PHPExcel_
}
$this->_processDomElement($child, $sheet, $row, $column, $cellContent);
break;
- case 'title' :
+ case 'title':
$this->_processDomElement($child, $sheet, $row, $column, $cellContent);
$sheet->setTitle($cellContent);
$cellContent = '';
break;
- case 'span' :
- case 'div' :
- case 'font' :
- case 'i' :
- case 'em' :
+ case 'span':
+ case 'div':
+ case 'font':
+ case 'i':
+ case 'em':
case 'strong':
- case 'b' :
+ case 'b':
// echo 'STYLING, SPAN OR DIV
';
- if ($cellContent > '')
+ if ($cellContent > '') {
$cellContent .= ' ';
+ }
$this->_processDomElement($child, $sheet, $row, $column, $cellContent);
- if ($cellContent > '')
+ if ($cellContent > '') {
$cellContent .= ' ';
+ }
// echo 'END OF STYLING, SPAN OR DIV
';
break;
- case 'hr' :
+ case 'hr':
$this->_flushCell($sheet, $column, $row, $cellContent);
++$row;
if (isset($this->_formats[$child->nodeName])) {
@@ -276,7 +272,7 @@ class PHPExcel_Reader_HTML extends PHPExcel_Reader_Abstract implements PHPExcel_
$this->_flushCell($sheet, $column, $row, $cellContent);
}
++$row;
- case 'br' :
+ case 'br':
if ($this->_tableLevel > 0) {
// If we're inside a table, replace with a \n
$cellContent .= "\n";
@@ -287,7 +283,7 @@ class PHPExcel_Reader_HTML extends PHPExcel_Reader_Abstract implements PHPExcel_
}
// echo 'HARD LINE BREAK: ' , '
';
break;
- case 'a' :
+ case 'a':
// echo 'START OF HYPERLINK: ' , '
';
foreach ($attributeArray as $attributeName => $attributeValue) {
switch ($attributeName) {
@@ -304,15 +300,15 @@ class PHPExcel_Reader_HTML extends PHPExcel_Reader_Abstract implements PHPExcel_
$this->_processDomElement($child, $sheet, $row, $column, $cellContent);
// echo 'END OF HYPERLINK:' , '
';
break;
- case 'h1' :
- case 'h2' :
- case 'h3' :
- case 'h4' :
- case 'h5' :
- case 'h6' :
- case 'ol' :
- case 'ul' :
- case 'p' :
+ case 'h1':
+ case 'h2':
+ case 'h3':
+ case 'h4':
+ case 'h5':
+ case 'h6':
+ case 'ol':
+ case 'ul':
+ case 'p':
if ($this->_tableLevel > 0) {
// If we're inside a table, replace with a \n
$cellContent .= "\n";
@@ -337,7 +333,7 @@ class PHPExcel_Reader_HTML extends PHPExcel_Reader_Abstract implements PHPExcel_
$column = 'A';
}
break;
- case 'li' :
+ case 'li':
if ($this->_tableLevel > 0) {
// If we're inside a table, replace with a \n
$cellContent .= "\n";
@@ -356,12 +352,13 @@ class PHPExcel_Reader_HTML extends PHPExcel_Reader_Abstract implements PHPExcel_
$column = 'A';
}
break;
- case 'table' :
+ case 'table':
$this->_flushCell($sheet, $column, $row, $cellContent);
$column = $this->_setTableStartColumn($column);
// echo 'START OF TABLE LEVEL ' , $this->_tableLevel , '
';
- if ($this->_tableLevel > 1)
+ if ($this->_tableLevel > 1) {
--$row;
+ }
$this->_processDomElement($child, $sheet, $row, $column, $cellContent);
// echo 'END OF TABLE LEVEL ' , $this->_tableLevel , '
';
$column = $this->_releaseTableStartColumn();
@@ -371,11 +368,11 @@ class PHPExcel_Reader_HTML extends PHPExcel_Reader_Abstract implements PHPExcel_
++$row;
}
break;
- case 'thead' :
- case 'tbody' :
+ case 'thead':
+ case 'tbody':
$this->_processDomElement($child, $sheet, $row, $column, $cellContent);
break;
- case 'tr' :
+ case 'tr':
$column = $this->_getTableStartColumn();
$cellContent = '';
// echo 'START OF TABLE ' , $this->_tableLevel , ' ROW
';
@@ -383,8 +380,8 @@ class PHPExcel_Reader_HTML extends PHPExcel_Reader_Abstract implements PHPExcel_
++$row;
// echo 'END OF TABLE ' , $this->_tableLevel , ' ROW
';
break;
- case 'th' :
- case 'td' :
+ case 'th':
+ case 'td':
// echo 'START OF TABLE ' , $this->_tableLevel , ' CELL
';
$this->_processDomElement($child, $sheet, $row, $column, $cellContent);
// echo 'END OF TABLE ' , $this->_tableLevel , ' CELL
';
@@ -433,7 +430,7 @@ class PHPExcel_Reader_HTML extends PHPExcel_Reader_Abstract implements PHPExcel_
}
++$column;
break;
- case 'body' :
+ case 'body':
$row = 1;
$column = 'A';
$content = '';
@@ -476,7 +473,7 @@ class PHPExcel_Reader_HTML extends PHPExcel_Reader_Abstract implements PHPExcel_
$dom = new domDocument;
// Reload the HTML file into the DOM object
$loaded = $dom->loadHTML($this->securityScanFile($pFilename));
- if ($loaded === FALSE) {
+ if ($loaded === false) {
throw new PHPExcel_Reader_Exception('Failed to load ', $pFilename, ' as a DOM Document');
}
@@ -524,11 +521,9 @@ class PHPExcel_Reader_HTML extends PHPExcel_Reader_Abstract implements PHPExcel_
public function securityScan($xml)
{
$pattern = '/\\0?' . implode('\\0?', str_split('getRow() + $pNumRows);
// Should the cell be updated? Move value and cellXf index from one cell to another.
- if (($cellIndex >= $beforeColumnIndex) &&
- ($cell->getRow() >= $beforeRow)) {
-
+ if (($cellIndex >= $beforeColumnIndex) && ($cell->getRow() >= $beforeRow)) {
// Update cell styles
$pSheet->getCell($newCoordinates)->setXfIndex($cell->getXfIndex());
@@ -471,7 +469,6 @@ class PHPExcel_ReferenceHelper
if ($pNumCols > 0 && $beforeColumnIndex - 2 > 0) {
for ($i = $beforeRow; $i <= $highestRow - 1; ++$i) {
-
// Style
$coordinate = PHPExcel_Cell::stringFromColumnIndex($beforeColumnIndex - 2) . $i;
if ($pSheet->cellExists($coordinate)) {
@@ -495,7 +492,6 @@ class PHPExcel_ReferenceHelper
if ($pNumRows > 0 && $beforeRow - 1 > 0) {
for ($i = $beforeColumnIndex - 1; $i <= PHPExcel_Cell::columnIndexFromString($highestColumn) - 1; ++$i) {
-
// Style
$coordinate = PHPExcel_Cell::stringFromColumnIndex($i) . ($beforeRow - 1);
if ($pSheet->cellExists($coordinate)) {
@@ -547,7 +543,7 @@ class PHPExcel_ReferenceHelper
if ($pNumCols != 0) {
$autoFilterColumns = array_keys($autoFilter->getColumns());
if (count($autoFilterColumns) > 0) {
- sscanf($pBefore,'%[A-Z]%d', $column, $row);
+ sscanf($pBefore, '%[A-Z]%d', $column, $row);
$columnIndex = PHPExcel_Cell::columnIndexFromString($column);
list($rangeStart, $rangeEnd) = PHPExcel_Cell::rangeBoundaries($autoFilterRange);
if ($columnIndex <= $rangeEnd[0]) {
@@ -577,7 +573,7 @@ class PHPExcel_ReferenceHelper
$toColRef = $rangeEnd[0]+$pNumCols;
do {
- $autoFilter->shiftColumn(PHPExcel_Cell::stringFromColumnIndex($endColRef-1),PHPExcel_Cell::stringFromColumnIndex($toColRef-1));
+ $autoFilter->shiftColumn(PHPExcel_Cell::stringFromColumnIndex($endColRef-1), PHPExcel_Cell::stringFromColumnIndex($toColRef-1));
--$endColRef;
--$toColRef;
} while ($startColRef <= $endColRef);
@@ -661,12 +657,12 @@ class PHPExcel_ReferenceHelper
$modified4 = substr($this->updateCellReference('$A'.$match[4], $pBefore, $pNumCols, $pNumRows), 2);
if ($match[3].':'.$match[4] !== $modified3.':'.$modified4) {
- if (($match[2] == '') || (trim($match[2],"'") == $sheetName)) {
+ if (($match[2] == '') || (trim($match[2], "'") == $sheetName)) {
$toString = ($match[2] > '') ? $match[2].'!' : '';
$toString .= $modified3.':'.$modified4;
// Max worksheet size is 1,048,576 rows by 16,384 columns in Excel 2007, so our adjustments need to be at least one digit more
$column = 100000;
- $row = 10000000+trim($match[3],'$');
+ $row = 10000000 + trim($match[3],'$');
$cellIndex = $column.$row;
$newCellTokens[$cellIndex] = preg_quote($toString);
@@ -686,11 +682,11 @@ class PHPExcel_ReferenceHelper
$modified4 = substr($this->updateCellReference($match[4].'$1', $pBefore, $pNumCols, $pNumRows), 0, -2);
if ($match[3].':'.$match[4] !== $modified3.':'.$modified4) {
- if (($match[2] == '') || (trim($match[2],"'") == $sheetName)) {
+ if (($match[2] == '') || (trim($match[2], "'") == $sheetName)) {
$toString = ($match[2] > '') ? $match[2].'!' : '';
$toString .= $modified3.':'.$modified4;
// Max worksheet size is 1,048,576 rows by 16,384 columns in Excel 2007, so our adjustments need to be at least one digit more
- $column = PHPExcel_Cell::columnIndexFromString(trim($match[3],'$')) + 100000;
+ $column = PHPExcel_Cell::columnIndexFromString(trim($match[3], '$')) + 100000;
$row = 10000000;
$cellIndex = $column.$row;
@@ -711,13 +707,13 @@ class PHPExcel_ReferenceHelper
$modified4 = $this->updateCellReference($match[4], $pBefore, $pNumCols, $pNumRows);
if ($match[3].$match[4] !== $modified3.$modified4) {
- if (($match[2] == '') || (trim($match[2],"'") == $sheetName)) {
+ if (($match[2] == '') || (trim($match[2], "'") == $sheetName)) {
$toString = ($match[2] > '') ? $match[2].'!' : '';
$toString .= $modified3.':'.$modified4;
list($column, $row) = PHPExcel_Cell::coordinateFromString($match[3]);
// Max worksheet size is 1,048,576 rows by 16,384 columns in Excel 2007, so our adjustments need to be at least one digit more
- $column = PHPExcel_Cell::columnIndexFromString(trim($column,'$')) + 100000;
- $row = trim($row,'$') + 10000000;
+ $column = PHPExcel_Cell::columnIndexFromString(trim($column, '$')) + 100000;
+ $row = trim($row, '$') + 10000000;
$cellIndex = $column.$row;
$newCellTokens[$cellIndex] = preg_quote($toString);
@@ -737,13 +733,13 @@ class PHPExcel_ReferenceHelper
$modified3 = $this->updateCellReference($match[3], $pBefore, $pNumCols, $pNumRows);
if ($match[3] !== $modified3) {
- if (($match[2] == '') || (trim($match[2],"'") == $sheetName)) {
+ if (($match[2] == '') || (trim($match[2], "'") == $sheetName)) {
$toString = ($match[2] > '') ? $match[2].'!' : '';
$toString .= $modified3;
list($column, $row) = PHPExcel_Cell::coordinateFromString($match[3]);
// Max worksheet size is 1,048,576 rows by 16,384 columns in Excel 2007, so our adjustments need to be at least one digit more
- $column = PHPExcel_Cell::columnIndexFromString(trim($column,'$')) + 100000;
- $row = trim($row,'$') + 10000000;
+ $column = PHPExcel_Cell::columnIndexFromString(trim($column, '$')) + 100000;
+ $row = trim($row, '$') + 10000000;
$cellIndex = $row . $column;
$newCellTokens[$cellIndex] = preg_quote($toString);
@@ -757,11 +753,11 @@ class PHPExcel_ReferenceHelper
if ($pNumCols > 0 || $pNumRows > 0) {
krsort($cellTokens);
krsort($newCellTokens);
- } else {
+ } else {
ksort($cellTokens);
ksort($newCellTokens);
} // Update cell references in the formula
- $formulaBlock = str_replace('\\','',preg_replace($cellTokens, $newCellTokens, $formulaBlock));
+ $formulaBlock = str_replace('\\', '', preg_replace($cellTokens, $newCellTokens, $formulaBlock));
}
}
}
@@ -839,7 +835,7 @@ class PHPExcel_ReferenceHelper
*/
private function _updateCellRange($pCellRange = 'A1:A1', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0)
{
- if (strpos($pCellRange,':') !== false || strpos($pCellRange, ',') !== false) {
+ if (strpos($pCellRange, ':') !== false || strpos($pCellRange, ',') !== false) {
// Update range
$range = PHPExcel_Cell::splitRange($pCellRange);
$ic = count($range);
diff --git a/Classes/PHPExcel/Shared/CodePage.php b/Classes/PHPExcel/Shared/CodePage.php
index cdaf30a1..13c166a3 100644
--- a/Classes/PHPExcel/Shared/CodePage.php
+++ b/Classes/PHPExcel/Shared/CodePage.php
@@ -38,58 +38,155 @@ class PHPExcel_Shared_CodePage
public static function NumberToName($codePage = 1252)
{
switch ($codePage) {
- case 367: return 'ASCII'; break; // ASCII
- case 437: return 'CP437'; break; // OEM US
- case 720: throw new PHPExcel_Exception('Code page 720 not supported.');
- break; // OEM Arabic
- case 737: return 'CP737'; break; // OEM Greek
- case 775: return 'CP775'; break; // OEM Baltic
- case 850: return 'CP850'; break; // OEM Latin I
- case 852: return 'CP852'; break; // OEM Latin II (Central European)
- case 855: return 'CP855'; break; // OEM Cyrillic
- case 857: return 'CP857'; break; // OEM Turkish
- case 858: return 'CP858'; break; // OEM Multilingual Latin I with Euro
- case 860: return 'CP860'; break; // OEM Portugese
- case 861: return 'CP861'; break; // OEM Icelandic
- case 862: return 'CP862'; break; // OEM Hebrew
- case 863: return 'CP863'; break; // OEM Canadian (French)
- case 864: return 'CP864'; break; // OEM Arabic
- case 865: return 'CP865'; break; // OEM Nordic
- case 866: return 'CP866'; break; // OEM Cyrillic (Russian)
- case 869: return 'CP869'; break; // OEM Greek (Modern)
- case 874: return 'CP874'; break; // ANSI Thai
- case 932: return 'CP932'; break; // ANSI Japanese Shift-JIS
- case 936: return 'CP936'; break; // ANSI Chinese Simplified GBK
- case 949: return 'CP949'; break; // ANSI Korean (Wansung)
- case 950: return 'CP950'; break; // ANSI Chinese Traditional BIG5
- case 1200: return 'UTF-16LE'; break; // UTF-16 (BIFF8)
- case 1250: return 'CP1250'; break; // ANSI Latin II (Central European)
- case 1251: return 'CP1251'; break; // ANSI Cyrillic
- case 0: // CodePage is not always correctly set when the xls file was saved by Apple's Numbers program
- case 1252: return 'CP1252'; break; // ANSI Latin I (BIFF4-BIFF7)
- case 1253: return 'CP1253'; break; // ANSI Greek
- case 1254: return 'CP1254'; break; // ANSI Turkish
- case 1255: return 'CP1255'; break; // ANSI Hebrew
- case 1256: return 'CP1256'; break; // ANSI Arabic
- case 1257: return 'CP1257'; break; // ANSI Baltic
- case 1258: return 'CP1258'; break; // ANSI Vietnamese
- case 1361: return 'CP1361'; break; // ANSI Korean (Johab)
- case 10000: return 'MAC'; break; // Apple Roman
- case 10001: return 'CP932'; break; // Macintosh Japanese
- case 10002: return 'CP950'; break; // Macintosh Chinese Traditional
- case 10003: return 'CP1361'; break; // Macintosh Korean
- case 10006: return 'MACGREEK'; break; // Macintosh Greek
- case 10007: return 'MACCYRILLIC'; break; // Macintosh Cyrillic
- case 10008: return 'CP936'; break; // Macintosh - Simplified Chinese (GB 2312)
- case 10029: return 'MACCENTRALEUROPE'; break; // Macintosh Central Europe
- case 10079: return 'MACICELAND'; break; // Macintosh Icelandic
- case 10081: return 'MACTURKISH'; break; // Macintosh Turkish
- case 21010: return 'UTF-16LE'; break; // UTF-16 (BIFF8) This isn't correct, but some Excel writer libraries erroneously use Codepage 21010 for UTF-16LE
- case 32768: return 'MAC'; break; // Apple Roman
- case 32769: throw new PHPExcel_Exception('Code page 32769 not supported.');
- break; // ANSI Latin I (BIFF2-BIFF3)
- case 65000: return 'UTF-7'; break; // Unicode (UTF-7)
- case 65001: return 'UTF-8'; break; // Unicode (UTF-8)
+ case 367:
+ return 'ASCII';
+ break; // ASCII
+ case 437:
+ return 'CP437';
+ break; // OEM US
+ case 720:
+ throw new PHPExcel_Exception('Code page 720 not supported.');
+ break; // OEM Arabic
+ case 737:
+ return 'CP737';
+ break; // OEM Greek
+ case 775:
+ return 'CP775';
+ break; // OEM Baltic
+ case 850:
+ return 'CP850';
+ break; // OEM Latin I
+ case 852:
+ return 'CP852';
+ break; // OEM Latin II (Central European)
+ case 855:
+ return 'CP855';
+ break; // OEM Cyrillic
+ case 857:
+ return 'CP857';
+ break; // OEM Turkish
+ case 858:
+ return 'CP858';
+ break; // OEM Multilingual Latin I with Euro
+ case 860:
+ return 'CP860';
+ break; // OEM Portugese
+ case 861:
+ return 'CP861';
+ break; // OEM Icelandic
+ case 862:
+ return 'CP862';
+ break; // OEM Hebrew
+ case 863:
+ return 'CP863';
+ break; // OEM Canadian (French)
+ case 864:
+ return 'CP864';
+ break; // OEM Arabic
+ case 865:
+ return 'CP865';
+ break; // OEM Nordic
+ case 866:
+ return 'CP866';
+ break; // OEM Cyrillic (Russian)
+ case 869:
+ return 'CP869';
+ break; // OEM Greek (Modern)
+ case 874:
+ return 'CP874';
+ break; // ANSI Thai
+ case 932:
+ return 'CP932';
+ break; // ANSI Japanese Shift-JIS
+ case 936:
+ return 'CP936';
+ break; // ANSI Chinese Simplified GBK
+ case 949:
+ return 'CP949';
+ break; // ANSI Korean (Wansung)
+ case 950:
+ return 'CP950';
+ break; // ANSI Chinese Traditional BIG5
+ case 1200:
+ return 'UTF-16LE';
+ break; // UTF-16 (BIFF8)
+ case 1250:
+ return 'CP1250';
+ break; // ANSI Latin II (Central European)
+ case 1251:
+ return 'CP1251';
+ break; // ANSI Cyrillic
+ case 0:
+ // CodePage is not always correctly set when the xls file was saved by Apple's Numbers program
+ case 1252:
+ return 'CP1252';
+ break; // ANSI Latin I (BIFF4-BIFF7)
+ case 1253:
+ return 'CP1253';
+ break; // ANSI Greek
+ case 1254:
+ return 'CP1254';
+ break; // ANSI Turkish
+ case 1255:
+ return 'CP1255';
+ break; // ANSI Hebrew
+ case 1256:
+ return 'CP1256';
+ break; // ANSI Arabic
+ case 1257:
+ return 'CP1257';
+ break; // ANSI Baltic
+ case 1258:
+ return 'CP1258';
+ break; // ANSI Vietnamese
+ case 1361:
+ return 'CP1361';
+ break; // ANSI Korean (Johab)
+ case 10000:
+ return 'MAC';
+ break; // Apple Roman
+ case 10001:
+ return 'CP932';
+ break; // Macintosh Japanese
+ case 10002:
+ return 'CP950';
+ break; // Macintosh Chinese Traditional
+ case 10003:
+ return 'CP1361';
+ break; // Macintosh Korean
+ case 10006:
+ return 'MACGREEK';
+ break; // Macintosh Greek
+ case 10007:
+ return 'MACCYRILLIC';
+ break; // Macintosh Cyrillic
+ case 10008:
+ return 'CP936';
+ break; // Macintosh - Simplified Chinese (GB 2312)
+ case 10029:
+ return 'MACCENTRALEUROPE';
+ break; // Macintosh Central Europe
+ case 10079:
+ return 'MACICELAND';
+ break; // Macintosh Icelandic
+ case 10081:
+ return 'MACTURKISH';
+ break; // Macintosh Turkish
+ case 21010:
+ return 'UTF-16LE';
+ break; // UTF-16 (BIFF8) This isn't correct, but some Excel writer libraries erroneously use Codepage 21010 for UTF-16LE
+ case 32768:
+ return 'MAC';
+ break; // Apple Roman
+ case 32769:
+ throw new PHPExcel_Exception('Code page 32769 not supported.');
+ break; // ANSI Latin I (BIFF2-BIFF3)
+ case 65000:
+ return 'UTF-7';
+ break; // Unicode (UTF-7)
+ case 65001:
+ return 'UTF-8';
+ break; // Unicode (UTF-8)
}
throw new PHPExcel_Exception('Unknown codepage: ' . $codePage);
}
diff --git a/Classes/PHPExcel/Shared/Date.php b/Classes/PHPExcel/Shared/Date.php
index 09026f83..f860b8a4 100644
--- a/Classes/PHPExcel/Shared/Date.php
+++ b/Classes/PHPExcel/Shared/Date.php
@@ -184,13 +184,9 @@ class PHPExcel_Shared_Date
date_default_timezone_set('UTC');
$retValue = false;
if ((is_object($dateValue)) && ($dateValue instanceof DateTime)) {
- $retValue = self::FormattedPHPToExcel( $dateValue->format('Y'), $dateValue->format('m'), $dateValue->format('d'),
- $dateValue->format('H'), $dateValue->format('i'), $dateValue->format('s')
- );
+ $retValue = self::FormattedPHPToExcel($dateValue->format('Y'), $dateValue->format('m'), $dateValue->format('d'), $dateValue->format('H'), $dateValue->format('i'), $dateValue->format('s'));
} elseif (is_numeric($dateValue)) {
- $retValue = self::FormattedPHPToExcel( date('Y', $dateValue), date('m', $dateValue), date('d', $dateValue),
- date('H', $dateValue), date('i', $dateValue), date('s', $dateValue)
- );
+ $retValue = self::FormattedPHPToExcel(date('Y', $dateValue), date('m', $dateValue), date('d', $dateValue), date('H', $dateValue), date('i', $dateValue), date('s', $dateValue));
}
date_default_timezone_set($saveTimeZone);
@@ -235,8 +231,8 @@ class PHPExcel_Shared_Date
}
// Calculate the Julian Date, then subtract the Excel base date (JD 2415020 = 31-Dec-1899 Giving Excel Date of 0)
- $century = substr($year,0,2);
- $decade = substr($year,2,2);
+ $century = substr($year, 0, 2);
+ $decade = substr($year, 2, 2);
$excelDate = floor((146097 * $century) / 4) + floor((1461 * $decade) / 4) + floor((153 * $month + 2) / 5) + $day + 1721119 - $myexcelBaseDate + $excel1900isLeapYear;
$excelTime = (($hours * 3600) + ($minutes * 60) + $seconds) / 86400;
@@ -273,7 +269,7 @@ class PHPExcel_Shared_Date
}
- private static $possibleDateFormatCharacters = 'eymdHs';
+ private static $possibleDateFormatCharacters = 'eymdHs';
/**
* Is a given number format code a date/time?
@@ -283,12 +279,15 @@ class PHPExcel_Shared_Date
*/
public static function isDateTimeFormatCode($pFormatCode = '')
{
- if (strtolower($pFormatCode) === strtolower(PHPExcel_Style_NumberFormat::FORMAT_GENERAL))
+ if (strtolower($pFormatCode) === strtolower(PHPExcel_Style_NumberFormat::FORMAT_GENERAL)) {
// "General" contains an epoch letter 'e', so we trap for it explicitly here (case-insensitive check)
return false;
- if (preg_match('/[0#]E[+-]0/i', $pFormatCode))
+ }
+ if (preg_match('/[0#]E[+-]0/i', $pFormatCode)) {
// Scientific format
return false;
+ }
+
// Switch on formatcode
switch ($pFormatCode) {
// Explicitly defined date formats
@@ -352,10 +351,12 @@ class PHPExcel_Shared_Date
*/
public static function stringToExcel($dateValue = '')
{
- if (strlen($dateValue) < 2)
+ if (strlen($dateValue) < 2) {
return false;
- if (!preg_match('/^(\d{1,4}[ \.\/\-][A-Z]{3,9}([ \.\/\-]\d{1,4})?|[A-Z]{3,9}[ \.\/\-]\d{1,4}([ \.\/\-]\d{1,4})?|\d{1,4}[ \.\/\-]\d{1,4}([ \.\/\-]\d{1,4})?)( \d{1,2}:\d{1,2}(:\d{1,2})?)?$/iu', $dateValue))
+ }
+ if (!preg_match('/^(\d{1,4}[ \.\/\-][A-Z]{3,9}([ \.\/\-]\d{1,4})?|[A-Z]{3,9}[ \.\/\-]\d{1,4}([ \.\/\-]\d{1,4})?|\d{1,4}[ \.\/\-]\d{1,4}([ \.\/\-]\d{1,4})?)( \d{1,2}:\d{1,2}(:\d{1,2})?)?$/iu', $dateValue)) {
return false;
+ }
$dateValueNew = PHPExcel_Calculation_DateTime::DATEVALUE($dateValue);
diff --git a/Classes/PHPExcel/Shared/Drawing.php b/Classes/PHPExcel/Shared/Drawing.php
index 4125815d..3e027b4a 100644
--- a/Classes/PHPExcel/Shared/Drawing.php
+++ b/Classes/PHPExcel/Shared/Drawing.php
@@ -225,7 +225,7 @@ class PHPExcel_Shared_Drawing
// Using a for-loop with index-calculation instaid of str_split to avoid large memory consumption
// Calculate the next DWORD-position in the body
- for ($i = 0 ; $i < $body_size ; $i += 3) {
+ for ($i = 0; $i < $body_size; $i += 3) {
// Calculate line-ending and padding
if ($x >= $width) {
// If padding needed, ignore image-padding
diff --git a/Classes/PHPExcel/Shared/Escher/DgContainer.php b/Classes/PHPExcel/Shared/Escher/DgContainer.php
index ef855d75..e4d17bc1 100644
--- a/Classes/PHPExcel/Shared/Escher/DgContainer.php
+++ b/Classes/PHPExcel/Shared/Escher/DgContainer.php
@@ -79,5 +79,4 @@ class PHPExcel_Shared_Escher_DgContainer
{
return $this->_spgrContainer = $spgrContainer;
}
-
}
diff --git a/Classes/PHPExcel/Shared/Escher/DggContainer/BstoreContainer.php b/Classes/PHPExcel/Shared/Escher/DggContainer/BstoreContainer.php
index 390f09b6..3f8f81da 100644
--- a/Classes/PHPExcel/Shared/Escher/DggContainer/BstoreContainer.php
+++ b/Classes/PHPExcel/Shared/Escher/DggContainer/BstoreContainer.php
@@ -61,5 +61,4 @@ class PHPExcel_Shared_Escher_DggContainer_BstoreContainer
{
return $this->_BSECollection;
}
-
}
diff --git a/Classes/PHPExcel/Shared/Escher/DggContainer/BstoreContainer/BSE.php b/Classes/PHPExcel/Shared/Escher/DggContainer/BstoreContainer/BSE.php
index 0fac1b8e..1b0fbe2c 100644
--- a/Classes/PHPExcel/Shared/Escher/DggContainer/BstoreContainer/BSE.php
+++ b/Classes/PHPExcel/Shared/Escher/DggContainer/BstoreContainer/BSE.php
@@ -116,5 +116,4 @@ class PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE
{
$this->_blipType = $blipType;
}
-
}
diff --git a/Classes/PHPExcel/Shared/Escher/DggContainer/BstoreContainer/BSE/Blip.php b/Classes/PHPExcel/Shared/Escher/DggContainer/BstoreContainer/BSE/Blip.php
index 4fd743f5..172c03e2 100644
--- a/Classes/PHPExcel/Shared/Escher/DggContainer/BstoreContainer/BSE/Blip.php
+++ b/Classes/PHPExcel/Shared/Escher/DggContainer/BstoreContainer/BSE/Blip.php
@@ -87,5 +87,4 @@ class PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip
{
return $this->_parent;
}
-
}
diff --git a/Classes/PHPExcel/Shared/Excel5.php b/Classes/PHPExcel/Shared/Excel5.php
index 115cc3a4..819092dd 100644
--- a/Classes/PHPExcel/Shared/Excel5.php
+++ b/Classes/PHPExcel/Shared/Excel5.php
@@ -51,22 +51,17 @@ class PHPExcel_Shared_Excel5
$columnDimensions = $sheet->getColumnDimensions();
// first find the true column width in pixels (uncollapsed and unhidden)
- if ( isset($columnDimensions[$col]) and $columnDimensions[$col]->getWidth() != -1 ) {
-
+ if (isset($columnDimensions[$col]) and $columnDimensions[$col]->getWidth() != -1) {
// then we have column dimension with explicit width
$columnDimension = $columnDimensions[$col];
$width = $columnDimension->getWidth();
$pixelWidth = PHPExcel_Shared_Drawing::cellDimensionToPixels($width, $font);
-
} else if ($sheet->getDefaultColumnDimension()->getWidth() != -1) {
-
// then we have default column dimension with explicit width
$defaultColumnDimension = $sheet->getDefaultColumnDimension();
$width = $defaultColumnDimension->getWidth();
$pixelWidth = PHPExcel_Shared_Drawing::cellDimensionToPixels($width, $font);
-
} else {
-
// we don't even have any default column dimension. Width depends on default font
$pixelWidth = PHPExcel_Shared_Font::getDefaultColumnWidthByFont($font, true);
}
@@ -98,30 +93,24 @@ class PHPExcel_Shared_Excel5
$rowDimensions = $sheet->getRowDimensions();
// first find the true row height in pixels (uncollapsed and unhidden)
- if ( isset($rowDimensions[$row]) and $rowDimensions[$row]->getRowHeight() != -1) {
-
+ if (isset($rowDimensions[$row]) and $rowDimensions[$row]->getRowHeight() != -1) {
// then we have a row dimension
$rowDimension = $rowDimensions[$row];
$rowHeight = $rowDimension->getRowHeight();
$pixelRowHeight = (int) ceil(4 * $rowHeight / 3); // here we assume Arial 10
-
} else if ($sheet->getDefaultRowDimension()->getRowHeight() != -1) {
-
// then we have a default row dimension with explicit height
$defaultRowDimension = $sheet->getDefaultRowDimension();
$rowHeight = $defaultRowDimension->getRowHeight();
$pixelRowHeight = PHPExcel_Shared_Drawing::pointsToPixels($rowHeight);
-
} else {
-
// we don't even have any default row dimension. Height depends on default font
$pointRowHeight = PHPExcel_Shared_Font::getDefaultRowHeightByFont($font);
$pixelRowHeight = PHPExcel_Shared_Font::fontSizeToPixels($pointRowHeight);
-
}
// now find the effective row height in pixels
- if ( isset($rowDimensions[$row]) and !$rowDimensions[$row]->getVisible() ) {
+ if (isset($rowDimensions[$row]) and !$rowDimensions[$row]->getVisible()) {
$effectivePixelRowHeight = 0;
} else {
$effectivePixelRowHeight = $pixelRowHeight;
@@ -313,5 +302,4 @@ class PHPExcel_Shared_Excel5
return $twoAnchor;
}
-
}
diff --git a/Classes/PHPExcel/Shared/File.php b/Classes/PHPExcel/Shared/File.php
index e2af00ee..6e04857a 100644
--- a/Classes/PHPExcel/Shared/File.php
+++ b/Classes/PHPExcel/Shared/File.php
@@ -152,18 +152,18 @@ class PHPExcel_Shared_File
// sys_get_temp_dir is only available since PHP 5.2.1
// http://php.net/manual/en/function.sys-get-temp-dir.php#94119
- if ( !function_exists('sys_get_temp_dir')) {
- if ($temp = getenv('TMP') ) {
+ if (!function_exists('sys_get_temp_dir')) {
+ if ($temp = getenv('TMP')) {
if ((!empty($temp)) && (file_exists($temp))) {
return realpath($temp);
}
}
- if ($temp = getenv('TEMP') ) {
+ if ($temp = getenv('TEMP')) {
if ((!empty($temp)) && (file_exists($temp))) {
return realpath($temp);
}
}
- if ($temp = getenv('TMPDIR') ) {
+ if ($temp = getenv('TMPDIR')) {
if ((!empty($temp)) && (file_exists($temp))) {
return realpath($temp);
}
diff --git a/Classes/PHPExcel/Shared/Font.php b/Classes/PHPExcel/Shared/Font.php
index 43451cb9..23d087e7 100644
--- a/Classes/PHPExcel/Shared/Font.php
+++ b/Classes/PHPExcel/Shared/Font.php
@@ -37,7 +37,7 @@ class PHPExcel_Shared_Font
{
/* Methods for resolving autosize value */
const AUTOSIZE_METHOD_APPROX = 'approx';
- const AUTOSIZE_METHOD_EXACT = 'exact';
+ const AUTOSIZE_METHOD_EXACT = 'exact';
private static $_autoSizeMethods = array(
self::AUTOSIZE_METHOD_APPROX,
@@ -48,84 +48,84 @@ class PHPExcel_Shared_Font
const CHARSET_ANSI_LATIN = 0x00;
const CHARSET_SYSTEM_DEFAULT = 0x01;
const CHARSET_SYMBOL = 0x02;
- const CHARSET_APPLE_ROMAN = 0x4D;
+ const CHARSET_APPLE_ROMAN = 0x4D;
const CHARSET_ANSI_JAPANESE_SHIFTJIS = 0x80;
const CHARSET_ANSI_KOREAN_HANGUL = 0x81;
- const CHARSET_ANSI_KOREAN_JOHAB = 0x82;
- const CHARSET_ANSI_CHINESE_SIMIPLIFIED = 0x86; // gb2312
- const CHARSET_ANSI_CHINESE_TRADITIONAL = 0x88; // big5
+ const CHARSET_ANSI_KOREAN_JOHAB = 0x82;
+ const CHARSET_ANSI_CHINESE_SIMIPLIFIED = 0x86; // gb2312
+ const CHARSET_ANSI_CHINESE_TRADITIONAL = 0x88; // big5
const CHARSET_ANSI_GREEK = 0xA1;
- const CHARSET_ANSI_TURKISH = 0xA2;
- const CHARSET_ANSI_VIETNAMESE = 0xA3;
- const CHARSET_ANSI_HEBREW = 0xB1;
- const CHARSET_ANSI_ARABIC = 0xB2;
- const CHARSET_ANSI_BALTIC = 0xBA;
- const CHARSET_ANSI_CYRILLIC = 0xCC;
- const CHARSET_ANSI_THAI = 0xDD;
- const CHARSET_ANSI_LATIN_II = 0xEE;
- const CHARSET_OEM_LATIN_I = 0xFF;
+ const CHARSET_ANSI_TURKISH = 0xA2;
+ const CHARSET_ANSI_VIETNAMESE = 0xA3;
+ const CHARSET_ANSI_HEBREW = 0xB1;
+ const CHARSET_ANSI_ARABIC = 0xB2;
+ const CHARSET_ANSI_BALTIC = 0xBA;
+ const CHARSET_ANSI_CYRILLIC = 0xCC;
+ const CHARSET_ANSI_THAI = 0xDD;
+ const CHARSET_ANSI_LATIN_II = 0xEE;
+ const CHARSET_OEM_LATIN_I = 0xFF;
// XXX: Constants created!
/** Font filenames */
- const ARIAL = 'arial.ttf';
+ const ARIAL = 'arial.ttf';
const ARIAL_BOLD = 'arialbd.ttf';
- const ARIAL_ITALIC = 'ariali.ttf';
- const ARIAL_BOLD_ITALIC = 'arialbi.ttf';
+ const ARIAL_ITALIC = 'ariali.ttf';
+ const ARIAL_BOLD_ITALIC = 'arialbi.ttf';
- const CALIBRI = 'CALIBRI.TTF';
- const CALIBRI_BOLD = 'CALIBRIB.TTF';
+ const CALIBRI = 'CALIBRI.TTF';
+ const CALIBRI_BOLD = 'CALIBRIB.TTF';
const CALIBRI_ITALIC = 'CALIBRII.TTF';
- const CALIBRI_BOLD_ITALIC = 'CALIBRIZ.TTF';
+ const CALIBRI_BOLD_ITALIC = 'CALIBRIZ.TTF';
- const COMIC_SANS_MS = 'comic.ttf';
+ const COMIC_SANS_MS = 'comic.ttf';
const COMIC_SANS_MS_BOLD = 'comicbd.ttf';
- const COURIER_NEW = 'cour.ttf';
- const COURIER_NEW_BOLD = 'courbd.ttf';
+ const COURIER_NEW = 'cour.ttf';
+ const COURIER_NEW_BOLD = 'courbd.ttf';
const COURIER_NEW_ITALIC = 'couri.ttf';
- const COURIER_NEW_BOLD_ITALIC = 'courbi.ttf';
+ const COURIER_NEW_BOLD_ITALIC = 'courbi.ttf';
- const GEORGIA = 'georgia.ttf';
- const GEORGIA_BOLD = 'georgiab.ttf';
+ const GEORGIA = 'georgia.ttf';
+ const GEORGIA_BOLD = 'georgiab.ttf';
const GEORGIA_ITALIC = 'georgiai.ttf';
- const GEORGIA_BOLD_ITALIC = 'georgiaz.ttf';
+ const GEORGIA_BOLD_ITALIC = 'georgiaz.ttf';
const IMPACT = 'impact.ttf';
- const LIBERATION_SANS = 'LiberationSans-Regular.ttf';
- const LIBERATION_SANS_BOLD = 'LiberationSans-Bold.ttf';
+ const LIBERATION_SANS = 'LiberationSans-Regular.ttf';
+ const LIBERATION_SANS_BOLD = 'LiberationSans-Bold.ttf';
const LIBERATION_SANS_ITALIC = 'LiberationSans-Italic.ttf';
- const LIBERATION_SANS_BOLD_ITALIC = 'LiberationSans-BoldItalic.ttf';
+ const LIBERATION_SANS_BOLD_ITALIC = 'LiberationSans-BoldItalic.ttf';
const LUCIDA_CONSOLE = 'lucon.ttf';
- const LUCIDA_SANS_UNICODE = 'l_10646.ttf';
+ const LUCIDA_SANS_UNICODE = 'l_10646.ttf';
- const MICROSOFT_SANS_SERIF = 'micross.ttf';
+ const MICROSOFT_SANS_SERIF = 'micross.ttf';
- const PALATINO_LINOTYPE = 'pala.ttf';
+ const PALATINO_LINOTYPE = 'pala.ttf';
const PALATINO_LINOTYPE_BOLD = 'palab.ttf';
- const PALATINO_LINOTYPE_ITALIC = 'palai.ttf';
- const PALATINO_LINOTYPE_BOLD_ITALIC = 'palabi.ttf';
+ const PALATINO_LINOTYPE_ITALIC = 'palai.ttf';
+ const PALATINO_LINOTYPE_BOLD_ITALIC = 'palabi.ttf';
const SYMBOL = 'symbol.ttf';
const TAHOMA = 'tahoma.ttf';
- const TAHOMA_BOLD = 'tahomabd.ttf';
+ const TAHOMA_BOLD = 'tahomabd.ttf';
- const TIMES_NEW_ROMAN = 'times.ttf';
- const TIMES_NEW_ROMAN_BOLD = 'timesbd.ttf';
+ const TIMES_NEW_ROMAN = 'times.ttf';
+ const TIMES_NEW_ROMAN_BOLD = 'timesbd.ttf';
const TIMES_NEW_ROMAN_ITALIC = 'timesi.ttf';
- const TIMES_NEW_ROMAN_BOLD_ITALIC = 'timesbi.ttf';
+ const TIMES_NEW_ROMAN_BOLD_ITALIC = 'timesbi.ttf';
- const TREBUCHET_MS = 'trebuc.ttf';
- const TREBUCHET_MS_BOLD = 'trebucbd.ttf';
- const TREBUCHET_MS_ITALIC = 'trebucit.ttf';
- const TREBUCHET_MS_BOLD_ITALIC = 'trebucbi.ttf';
+ const TREBUCHET_MS = 'trebuc.ttf';
+ const TREBUCHET_MS_BOLD = 'trebucbd.ttf';
+ const TREBUCHET_MS_ITALIC = 'trebucit.ttf';
+ const TREBUCHET_MS_BOLD_ITALIC = 'trebucbi.ttf';
- const VERDANA = 'verdana.ttf';
- const VERDANA_BOLD = 'verdanab.ttf';
+ const VERDANA = 'verdana.ttf';
+ const VERDANA_BOLD = 'verdanab.ttf';
const VERDANA_ITALIC = 'verdanai.ttf';
- const VERDANA_BOLD_ITALIC = 'verdanaz.ttf';
+ const VERDANA_BOLD_ITALIC = 'verdanaz.ttf';
/**
* AutoSize method
@@ -196,12 +196,12 @@ class PHPExcel_Shared_Font
*/
public static function setAutoSizeMethod($pValue = self::AUTOSIZE_METHOD_APPROX)
{
- if (!in_array($pValue,self::$_autoSizeMethods)) {
- return FALSE;
+ if (!in_array($pValue, self::$_autoSizeMethods)) {
+ return false;
}
self::$autoSizeMethod = $pValue;
- return TRUE;
+ return true;
}
/**
@@ -249,7 +249,8 @@ class PHPExcel_Shared_Font
* @param PHPExcel_Style_Font|NULL $defaultFont Font object
* @return integer Column width
*/
- public static function calculateColumnWidth(PHPExcel_Style_Font $font, $cellText = '', $rotation = 0, PHPExcel_Style_Font $defaultFont = null) {
+ public static function calculateColumnWidth(PHPExcel_Style_Font $font, $cellText = '', $rotation = 0, PHPExcel_Style_Font $defaultFont = null)
+ {
// If it is rich text, use plain text
if ($cellText instanceof PHPExcel_RichText) {
$cellText = $cellText->getPlainText();
@@ -301,7 +302,8 @@ class PHPExcel_Shared_Font
* @return int
* @throws PHPExcel_Exception
*/
- public static function getTextWidthPixelsExact($text, PHPExcel_Style_Font $font, $rotation = 0) {
+ public static function getTextWidthPixelsExact($text, PHPExcel_Style_Font $font, $rotation = 0)
+ {
if (!function_exists('imagettfbbox')) {
throw new PHPExcel_Exception('GD library needs to be enabled');
}
@@ -391,7 +393,8 @@ class PHPExcel_Shared_Font
* @param int $fontSizeInPoints Font size (in points)
* @return int Font size (in pixels)
*/
- public static function fontSizeToPixels($fontSizeInPoints = 11) {
+ public static function fontSizeToPixels($fontSizeInPoints = 11)
+ {
return (int) ((4 / 3) * $fontSizeInPoints);
}
@@ -401,7 +404,8 @@ class PHPExcel_Shared_Font
* @param int $sizeInInch Font size (in inch)
* @return int Size (in pixels)
*/
- public static function inchSizeToPixels($sizeInInch = 1) {
+ public static function inchSizeToPixels($sizeInInch = 1)
+ {
return ($sizeInInch * 96);
}
@@ -411,7 +415,8 @@ class PHPExcel_Shared_Font
* @param int $sizeInCm Font size (in centimeters)
* @return int Size (in pixels)
*/
- public static function centimeterSizeToPixels($sizeInCm = 1) {
+ public static function centimeterSizeToPixels($sizeInCm = 1)
+ {
return ($sizeInCm * 37.795275591);
}
@@ -421,14 +426,15 @@ class PHPExcel_Shared_Font
* @param PHPExcel_Style_Font
* @return string Path to TrueType font file
*/
- public static function getTrueTypeFontFileFromFont($font) {
+ public static function getTrueTypeFontFileFromFont($font)
+ {
if (!file_exists(self::$trueTypeFontPath) || !is_dir(self::$trueTypeFontPath)) {
throw new PHPExcel_Exception('Valid directory to TrueType Font files not specified');
}
$name = $font->getName();
$bold = $font->getBold();
- $italic = $font->getItalic();
+ $italic = $font->getItalic();
// Check if we can map font to true type font file
switch ($name) {
@@ -438,95 +444,79 @@ class PHPExcel_Shared_Font
: ($italic ? self::ARIAL_ITALIC : self::ARIAL)
);
break;
-
case 'Calibri':
$fontFile = (
$bold ? ($italic ? self::CALIBRI_BOLD_ITALIC : self::CALIBRI_BOLD)
: ($italic ? self::CALIBRI_ITALIC : self::CALIBRI)
);
break;
-
case 'Courier New':
$fontFile = (
$bold ? ($italic ? self::COURIER_NEW_BOLD_ITALIC : self::COURIER_NEW_BOLD)
: ($italic ? self::COURIER_NEW_ITALIC : self::COURIER_NEW)
);
break;
-
case 'Comic Sans MS':
$fontFile = (
$bold ? self::COMIC_SANS_MS_BOLD : self::COMIC_SANS_MS
);
break;
-
case 'Georgia':
$fontFile = (
$bold ? ($italic ? self::GEORGIA_BOLD_ITALIC : self::GEORGIA_BOLD)
: ($italic ? self::GEORGIA_ITALIC : self::GEORGIA)
);
break;
-
case 'Impact':
$fontFile = self::IMPACT;
break;
-
case 'Liberation Sans':
$fontFile = (
$bold ? ($italic ? self::LIBERATION_SANS_BOLD_ITALIC : self::LIBERATION_SANS_BOLD)
: ($italic ? self::LIBERATION_SANS_ITALIC : self::LIBERATION_SANS)
);
break;
-
case 'Lucida Console':
$fontFile = self::LUCIDA_CONSOLE;
break;
-
case 'Lucida Sans Unicode':
$fontFile = self::LUCIDA_SANS_UNICODE;
break;
-
case 'Microsoft Sans Serif':
$fontFile = self::MICROSOFT_SANS_SERIF;
break;
-
case 'Palatino Linotype':
$fontFile = (
$bold ? ($italic ? self::PALATINO_LINOTYPE_BOLD_ITALIC : self::PALATINO_LINOTYPE_BOLD)
: ($italic ? self::PALATINO_LINOTYPE_ITALIC : self::PALATINO_LINOTYPE)
);
break;
-
case 'Symbol':
$fontFile = self::SYMBOL;
break;
-
case 'Tahoma':
$fontFile = (
$bold ? self::TAHOMA_BOLD : self::TAHOMA
);
break;
-
case 'Times New Roman':
$fontFile = (
$bold ? ($italic ? self::TIMES_NEW_ROMAN_BOLD_ITALIC : self::TIMES_NEW_ROMAN_BOLD)
: ($italic ? self::TIMES_NEW_ROMAN_ITALIC : self::TIMES_NEW_ROMAN)
);
break;
-
case 'Trebuchet MS':
$fontFile = (
$bold ? ($italic ? self::TREBUCHET_MS_BOLD_ITALIC : self::TREBUCHET_MS_BOLD)
: ($italic ? self::TREBUCHET_MS_ITALIC : self::TREBUCHET_MS)
);
break;
-
case 'Verdana':
$fontFile = (
$bold ? ($italic ? self::VERDANA_BOLD_ITALIC : self::VERDANA_BOLD)
: ($italic ? self::VERDANA_ITALIC : self::VERDANA)
);
break;
-
default:
throw new PHPExcel_Exception('Unknown font name "'. $name .'". Cannot map to TrueType font file');
break;
@@ -536,7 +526,7 @@ class PHPExcel_Shared_Font
// Check if file actually exists
if (!file_exists($fontFile)) {
- throw New PHPExcel_Exception('TrueType Font file not found');
+ throw new PHPExcel_Exception('TrueType Font file not found');
}
return $fontFile;
@@ -552,11 +542,16 @@ class PHPExcel_Shared_Font
{
switch ($name) {
// Add more cases. Check FONT records in real Excel files.
- case 'EucrosiaUPC': return self::CHARSET_ANSI_THAI;
- case 'Wingdings': return self::CHARSET_SYMBOL;
- case 'Wingdings 2': return self::CHARSET_SYMBOL;
- case 'Wingdings 3': return self::CHARSET_SYMBOL;
- default: return self::CHARSET_ANSI_LATIN;
+ case 'EucrosiaUPC':
+ return self::CHARSET_ANSI_THAI;
+ case 'Wingdings':
+ return self::CHARSET_SYMBOL;
+ case 'Wingdings 2':
+ return self::CHARSET_SYMBOL;
+ case 'Wingdings 3':
+ return self::CHARSET_SYMBOL;
+ default:
+ return self::CHARSET_ANSI_LATIN;
}
}
@@ -609,44 +604,36 @@ class PHPExcel_Shared_Font
// inspection of Arial 10 workbook says 12.75pt ~17px
$rowHeight = 12.75;
break;
-
case 9:
// inspection of Arial 9 workbook says 12.00pt ~16px
$rowHeight = 12;
break;
-
case 8:
// inspection of Arial 8 workbook says 11.25pt ~15px
$rowHeight = 11.25;
break;
-
case 7:
// inspection of Arial 7 workbook says 9.00pt ~12px
$rowHeight = 9;
break;
-
case 6:
case 5:
// inspection of Arial 5,6 workbook says 8.25pt ~11px
$rowHeight = 8.25;
break;
-
case 4:
// inspection of Arial 4 workbook says 6.75pt ~9px
$rowHeight = 6.75;
break;
-
case 3:
// inspection of Arial 3 workbook says 6.00pt ~8px
$rowHeight = 6;
break;
-
case 2:
case 1:
// inspection of Arial 1,2 workbook says 5.25pt ~7px
$rowHeight = 5.25;
break;
-
default:
// use Arial 10 workbook as an approximation, extrapolation
$rowHeight = 12.75 * $font->getSize() / 10;
@@ -660,49 +647,40 @@ class PHPExcel_Shared_Font
// inspection of Calibri 11 workbook says 15.00pt ~20px
$rowHeight = 15;
break;
-
case 10:
// inspection of Calibri 10 workbook says 12.75pt ~17px
$rowHeight = 12.75;
break;
-
case 9:
// inspection of Calibri 9 workbook says 12.00pt ~16px
$rowHeight = 12;
break;
-
case 8:
// inspection of Calibri 8 workbook says 11.25pt ~15px
$rowHeight = 11.25;
break;
-
case 7:
// inspection of Calibri 7 workbook says 9.00pt ~12px
$rowHeight = 9;
break;
-
case 6:
case 5:
// inspection of Calibri 5,6 workbook says 8.25pt ~11px
$rowHeight = 8.25;
break;
-
case 4:
// inspection of Calibri 4 workbook says 6.75pt ~9px
$rowHeight = 6.75;
break;
-
case 3:
// inspection of Calibri 3 workbook says 6.00pt ~8px
$rowHeight = 6.00;
break;
-
case 2:
case 1:
// inspection of Calibri 1,2 workbook says 5.25pt ~7px
$rowHeight = 5.25;
break;
-
default:
// use Calibri 11 workbook as an approximation, extrapolation
$rowHeight = 15 * $font->getSize() / 11;
@@ -716,51 +694,42 @@ class PHPExcel_Shared_Font
// inspection of Verdana 10 workbook says 12.75pt ~17px
$rowHeight = 12.75;
break;
-
case 9:
// inspection of Verdana 9 workbook says 11.25pt ~15px
$rowHeight = 11.25;
break;
-
case 8:
// inspection of Verdana 8 workbook says 10.50pt ~14px
$rowHeight = 10.50;
break;
-
case 7:
// inspection of Verdana 7 workbook says 9.00pt ~12px
$rowHeight = 9.00;
break;
-
case 6:
case 5:
// inspection of Verdana 5,6 workbook says 8.25pt ~11px
$rowHeight = 8.25;
break;
-
case 4:
// inspection of Verdana 4 workbook says 6.75pt ~9px
$rowHeight = 6.75;
break;
-
case 3:
// inspection of Verdana 3 workbook says 6.00pt ~8px
$rowHeight = 6;
break;
-
case 2:
case 1:
// inspection of Verdana 1,2 workbook says 5.25pt ~7px
$rowHeight = 5.25;
break;
-
default:
// use Verdana 10 workbook as an approximation, extrapolation
$rowHeight = 12.75 * $font->getSize() / 10;
break;
}
break;
-
default:
// just use Calibri as an approximation
$rowHeight = 15 * $font->getSize() / 11;
@@ -769,5 +738,4 @@ class PHPExcel_Shared_Font
return $rowHeight;
}
-
}
diff --git a/Classes/PHPExcel/Shared/OLE/ChainedBlockStream.php b/Classes/PHPExcel/Shared/OLE/ChainedBlockStream.php
index 10f3f4b4..84d2cc50 100644
--- a/Classes/PHPExcel/Shared/OLE/ChainedBlockStream.php
+++ b/Classes/PHPExcel/Shared/OLE/ChainedBlockStream.php
@@ -1,6 +1,7 @@
params);
- if (!isset($this->params['oleInstanceId'],
- $this->params['blockId'],
- $GLOBALS['_OLE_INSTANCES'][$this->params['oleInstanceId']])) {
-
+ if (!isset($this->params['oleInstanceId'], $this->params['blockId'], $GLOBALS['_OLE_INSTANCES'][$this->params['oleInstanceId']])) {
if ($options & STREAM_REPORT_ERRORS) {
trigger_error('OLE stream not found', E_USER_WARNING);
}
@@ -96,10 +83,7 @@ class PHPExcel_Shared_OLE_ChainedBlockStream
$blockId = $this->params['blockId'];
$this->data = '';
- if (isset($this->params['size']) &&
- $this->params['size'] < $this->ole->bigBlockThreshold &&
- $blockId != $this->ole->root->_StartBlock) {
-
+ if (isset($this->params['size']) && $this->params['size'] < $this->ole->bigBlockThreshold && $blockId != $this->ole->root->_StartBlock) {
// Block id refers to small blocks
$rootPos = $this->ole->_getBlockOffset($this->ole->root->_StartBlock);
while ($blockId != -2) {
diff --git a/Classes/PHPExcel/Shared/OLE/PPS.php b/Classes/PHPExcel/Shared/OLE/PPS.php
index 6699f438..608a892a 100644
--- a/Classes/PHPExcel/Shared/OLE/PPS.php
+++ b/Classes/PHPExcel/Shared/OLE/PPS.php
@@ -169,7 +169,7 @@ class PHPExcel_Shared_OLE_PPS
*/
public function _getPpsWk()
{
- $ret = str_pad($this->Name,64,"\x00");
+ $ret = str_pad($this->Name, 64, "\x00");
$ret .= pack("v", strlen($this->Name) + 2) // 66
. pack("c", $this->Type) // 67
@@ -202,9 +202,9 @@ class PHPExcel_Shared_OLE_PPS
*/
public static function _savePpsSetPnt(&$raList, $to_save, $depth = 0)
{
- if ( !is_array($to_save) || (empty($to_save)) ) {
+ if (!is_array($to_save) || (empty($to_save))) {
return 0xFFFFFFFF;
- } elseif ( count($to_save) == 1 ) {
+ } elseif (count($to_save) == 1) {
$cnt = count($raList);
// If the first entry, it's the root... Don't clone it!
$raList[$cnt] = ( $depth == 0 ) ? $to_save[0] : clone $to_save[0];
diff --git a/Classes/PHPExcel/Shared/OLE/PPS/File.php b/Classes/PHPExcel/Shared/OLE/PPS/File.php
index f0be587a..1ca337cb 100644
--- a/Classes/PHPExcel/Shared/OLE/PPS/File.php
+++ b/Classes/PHPExcel/Shared/OLE/PPS/File.php
@@ -28,7 +28,7 @@
* @package PHPExcel_Shared_OLE
*/
class PHPExcel_Shared_OLE_PPS_File extends PHPExcel_Shared_OLE_PPS
- {
+{
/**
* The constructor
*
@@ -38,17 +38,7 @@ class PHPExcel_Shared_OLE_PPS_File extends PHPExcel_Shared_OLE_PPS
*/
public function __construct($name)
{
- parent::__construct(
- null,
- $name,
- PHPExcel_Shared_OLE::OLE_PPS_TYPE_FILE,
- null,
- null,
- null,
- null,
- null,
- '',
- array());
+ parent::__construct(null, $name, PHPExcel_Shared_OLE::OLE_PPS_TYPE_FILE, null, null, null, null, null, '', array());
}
/**
diff --git a/Classes/PHPExcel/Shared/OLE/PPS/Root.php b/Classes/PHPExcel/Shared/OLE/PPS/Root.php
index 7e50dadf..b2278c4e 100644
--- a/Classes/PHPExcel/Shared/OLE/PPS/Root.php
+++ b/Classes/PHPExcel/Shared/OLE/PPS/Root.php
@@ -28,13 +28,13 @@
* @package PHPExcel_Shared_OLE
*/
class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
- {
+{
/**
* Directory for temporary files
* @var string
*/
- protected $_tmp_dir = NULL;
+ protected $_tmp_dir = null;
/**
* @param integer $time_1st A timestamp
@@ -44,17 +44,7 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
{
$this->_tempDir = PHPExcel_Shared_File::sys_get_temp_dir();
- parent::__construct(
- null,
- PHPExcel_Shared_OLE::Asc2Ucs('Root Entry'),
- PHPExcel_Shared_OLE::OLE_PPS_TYPE_ROOT,
- null,
- null,
- null,
- $time_1st,
- $time_2nd,
- null,
- $raChild);
+ parent::__construct(null, PHPExcel_Shared_OLE::Asc2Ucs('Root Entry'), PHPExcel_Shared_OLE::OLE_PPS_TYPE_ROOT, null, null, null, $time_1st, $time_2nd, null, $raChild);
}
/**
@@ -71,20 +61,24 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
public function save($filename)
{
// Initial Setting for saving
- $this->_BIG_BLOCK_SIZE = pow(2,
- ((isset($this->_BIG_BLOCK_SIZE))? self::_adjust2($this->_BIG_BLOCK_SIZE) : 9));
- $this->_SMALL_BLOCK_SIZE= pow(2,
- ((isset($this->_SMALL_BLOCK_SIZE))? self::_adjust2($this->_SMALL_BLOCK_SIZE): 6));
+ $this->_BIG_BLOCK_SIZE = pow(
+ 2,
+ (isset($this->_BIG_BLOCK_SIZE))? self::_adjust2($this->_BIG_BLOCK_SIZE) : 9
+ );
+ $this->_SMALL_BLOCK_SIZE= pow(
+ 2,
+ (isset($this->_SMALL_BLOCK_SIZE))? self::_adjust2($this->_SMALL_BLOCK_SIZE) : 6
+ );
if (is_resource($filename)) {
$this->_FILEH_ = $filename;
- } else if ($filename == '-' || $filename == '') {
- if ($this->_tmp_dir === NULL)
- $this->_tmp_dir = PHPExcel_Shared_File::sys_get_temp_dir();
- $this->_tmp_filename = tempnam($this->_tmp_dir, "OLE_PPS_Root");
- $this->_FILEH_ = fopen($this->_tmp_filename,"w+b");
- if ($this->_FILEH_ == false) {
- throw new PHPExcel_Writer_Exception("Can't create temporary file.");
+ } else if ($filename == '-' || $filename == '') {
+ if ($this->_tmp_dir === null)
+ $this->_tmp_dir = PHPExcel_Shared_File::sys_get_temp_dir();
+ $this->_tmp_filename = tempnam($this->_tmp_dir, "OLE_PPS_Root");
+ $this->_FILEH_ = fopen($this->_tmp_filename,"w+b");
+ if ($this->_FILEH_ == false) {
+ throw new PHPExcel_Writer_Exception("Can't create temporary file.");
}
} else {
$this->_FILEH_ = fopen($filename, "wb");
@@ -94,7 +88,7 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
}
// Make an array of PPS's (for Save)
$aList = array();
- PHPExcel_Shared_OLE_PPS::_savePpsSetPnt($aList, array($this));
+ PHPExcel_Shared_OLE_PPS::_savePpsSetPnt($aList, array($this));
// calculate values for header
list($iSBDcnt, $iBBcnt, $iPPScnt) = $this->_calcSize($aList); //, $rhInfo);
// Save Header
@@ -447,7 +441,7 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
if ($iBdCnt > $i1stBdL) {
$iN=0;
$iNb=0;
- for ($i = $i1stBdL;$i < $iBdCnt; $i++, ++$iN) {
+ for ($i = $i1stBdL; $i < $iBdCnt; $i++, ++$iN) {
if ($iN >= ($iBbCnt - 1)) {
$iN = 0;
++$iNb;
diff --git a/Classes/PHPExcel/Shared/OLERead.php b/Classes/PHPExcel/Shared/OLERead.php
index 143e22d3..f43567d7 100644
--- a/Classes/PHPExcel/Shared/OLERead.php
+++ b/Classes/PHPExcel/Shared/OLERead.php
@@ -32,39 +32,39 @@ class PHPExcel_Shared_OLERead {
private $data = '';
// OLE identifier
- const IDENTIFIER_OLE = IDENTIFIER_OLE;
+ const IDENTIFIER_OLE = IDENTIFIER_OLE;
// Size of a sector = 512 bytes
const BIG_BLOCK_SIZE = 0x200;
// Size of a short sector = 64 bytes
- const SMALL_BLOCK_SIZE = 0x40;
+ const SMALL_BLOCK_SIZE = 0x40;
// Size of a directory entry always = 128 bytes
- const PROPERTY_STORAGE_BLOCK_SIZE = 0x80;
+ const PROPERTY_STORAGE_BLOCK_SIZE = 0x80;
// Minimum size of a standard stream = 4096 bytes, streams smaller than this are stored as short streams
- const SMALL_BLOCK_THRESHOLD = 0x1000;
+ const SMALL_BLOCK_THRESHOLD = 0x1000;
// header offsets
const NUM_BIG_BLOCK_DEPOT_BLOCKS_POS = 0x2c;
- const ROOT_START_BLOCK_POS = 0x30;
- const SMALL_BLOCK_DEPOT_BLOCK_POS = 0x3c;
- const EXTENSION_BLOCK_POS = 0x44;
- const NUM_EXTENSION_BLOCK_POS = 0x48;
+ const ROOT_START_BLOCK_POS = 0x30;
+ const SMALL_BLOCK_DEPOT_BLOCK_POS = 0x3c;
+ const EXTENSION_BLOCK_POS = 0x44;
+ const NUM_EXTENSION_BLOCK_POS = 0x48;
const BIG_BLOCK_DEPOT_BLOCKS_POS = 0x4c;
// property storage offsets (directory offsets)
- const SIZE_OF_NAME_POS = 0x40;
- const TYPE_POS = 0x42;
- const START_BLOCK_POS = 0x74;
- const SIZE_POS = 0x78;
+ const SIZE_OF_NAME_POS = 0x40;
+ const TYPE_POS = 0x42;
+ const START_BLOCK_POS = 0x74;
+ const SIZE_POS = 0x78;
- public $wrkbook = null;
- public $summaryInformation = null;
- public $documentSummaryInformation = null;
+ public $wrkbook = null;
+ public $summaryInformation = null;
+ public $documentSummaryInformation = null;
/**
@@ -82,7 +82,7 @@ class PHPExcel_Shared_OLERead {
// Get the file identifier
// Don't bother reading the whole file until we know it's a valid OLE file
- $this->data = file_get_contents($sFileName, FALSE, NULL, 0, 8);
+ $this->data = file_get_contents($sFileName, false, null, 0, 8);
// Check OLE identifier
if ($this->data != self::IDENTIFIER_OLE) {
@@ -172,7 +172,7 @@ class PHPExcel_Shared_OLERead {
*/
public function getStream($stream)
{
- if ($stream === NULL) {
+ if ($stream === null) {
return null;
}
@@ -197,7 +197,9 @@ class PHPExcel_Shared_OLERead {
++$numBlocks;
}
- if ($numBlocks == 0) return '';
+ if ($numBlocks == 0) {
+ return '';
+ }
$block = $this->props[$stream]['startBlock'];
@@ -222,18 +224,19 @@ class PHPExcel_Shared_OLERead {
$block = $bl;
$data = '';
- while ($block != -2) {
+ while ($block != -2) {
$pos = ($block + 1) * self::BIG_BLOCK_SIZE;
$data .= substr($this->data, $pos, self::BIG_BLOCK_SIZE);
$block = self::_GetInt4d($this->bigBlockChain, $block*4);
}
return $data;
- }
+ }
/**
* Read entries in the directory stream.
*/
- private function _readPropertySets() {
+ private function _readPropertySets()
+ {
$offset = 0;
// loop through entires, each entry is 128 bytes
@@ -254,14 +257,14 @@ class PHPExcel_Shared_OLERead {
$size = self::_GetInt4d($d, self::SIZE_POS);
- $name = str_replace("\x00", "", substr($d,0, $nameSize));
+ $name = str_replace("\x00", "", substr($d, 0, $nameSize));
-
- $this->props[] = array (
+ $this->props[] = array(
'name' => $name,
'type' => $type,
'startBlock' => $startBlock,
- 'size' => $size);
+ 'size' => $size
+ );
// tmp helper to simplify checks
$upName = strtoupper($name);
@@ -269,8 +272,7 @@ class PHPExcel_Shared_OLERead {
// Workbook directory entry (BIFF5 uses Book, BIFF8 uses Workbook)
if (($upName === 'WORKBOOK') || ($upName === 'BOOK')) {
$this->wrkbook = count($this->props) - 1;
- }
- else if ( $upName === 'ROOT ENTRY' || $upName === 'R') {
+ } else if ($upName === 'ROOT ENTRY' || $upName === 'R') {
// Root entry
$this->rootentry = count($this->props) - 1;
}
@@ -289,7 +291,6 @@ class PHPExcel_Shared_OLERead {
$offset += self::PROPERTY_STORAGE_BLOCK_SIZE;
}
-
}
/**
@@ -313,5 +314,4 @@ class PHPExcel_Shared_OLERead {
}
return ord($data[$pos]) | (ord($data[$pos + 1]) << 8) | (ord($data[$pos + 2]) << 16) | $_ord_24;
}
-
}
diff --git a/Classes/PHPExcel/Shared/PCLZip/pclzip.lib.php b/Classes/PHPExcel/Shared/PCLZip/pclzip.lib.php
index 0805a03c..d0c772a5 100644
--- a/Classes/PHPExcel/Shared/PCLZip/pclzip.lib.php
+++ b/Classes/PHPExcel/Shared/PCLZip/pclzip.lib.php
@@ -1,5692 +1,5203 @@
-zipname = $p_zipname;
- $this->zip_fd = 0;
- $this->magic_quotes_status = -1;
-
- // ----- Return
- return;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function :
- // create($p_filelist, $p_add_dir="", $p_remove_dir="")
- // create($p_filelist, $p_option, $p_option_value, ...)
- // Description :
- // This method supports two different synopsis. The first one is historical.
- // This method creates a Zip Archive. The Zip file is created in the
- // filesystem. The files and directories indicated in $p_filelist
- // are added in the archive. See the parameters description for the
- // supported format of $p_filelist.
- // When a directory is in the list, the directory and its content is added
- // in the archive.
- // In this synopsis, the function takes an optional variable list of
- // options. See bellow the supported options.
- // Parameters :
- // $p_filelist : An array containing file or directory names, or
- // a string containing one filename or one directory name, or
- // a string containing a list of filenames and/or directory
- // names separated by spaces.
- // $p_add_dir : A path to add before the real path of the archived file,
- // in order to have it memorized in the archive.
- // $p_remove_dir : A path to remove from the real path of the file to archive,
- // in order to have a shorter path memorized in the archive.
- // When $p_add_dir and $p_remove_dir are set, $p_remove_dir
- // is removed first, before $p_add_dir is added.
- // Options :
- // PCLZIP_OPT_ADD_PATH :
- // PCLZIP_OPT_REMOVE_PATH :
- // PCLZIP_OPT_REMOVE_ALL_PATH :
- // PCLZIP_OPT_COMMENT :
- // PCLZIP_CB_PRE_ADD :
- // PCLZIP_CB_POST_ADD :
- // Return Values :
- // 0 on failure,
- // The list of the added files, with a status of the add action.
- // (see PclZip::listContent() for list entry format)
- // --------------------------------------------------------------------------------
- function create($p_filelist)
- {
- $v_result=1;
-
- // ----- Reset the error handler
- $this->privErrorReset();
-
- // ----- Set default values
- $v_options = array();
- $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
-
- // ----- Look for variable options arguments
- $v_size = func_num_args();
-
- // ----- Look for arguments
- if ($v_size > 1) {
- // ----- Get the arguments
- $v_arg_list = func_get_args();
-
- // ----- Remove from the options list the first argument
- array_shift($v_arg_list);
- $v_size--;
-
- // ----- Look for first arg
- if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
-
- // ----- Parse the options
- $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
- array (PCLZIP_OPT_REMOVE_PATH => 'optional',
- PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
- PCLZIP_OPT_ADD_PATH => 'optional',
- PCLZIP_CB_PRE_ADD => 'optional',
- PCLZIP_CB_POST_ADD => 'optional',
- PCLZIP_OPT_NO_COMPRESSION => 'optional',
- PCLZIP_OPT_COMMENT => 'optional',
- PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
- PCLZIP_OPT_TEMP_FILE_ON => 'optional',
- PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
- //, PCLZIP_OPT_CRYPT => 'optional'
- ));
- if ($v_result != 1) {
- return 0;
- }
- }
-
- // ----- Look for 2 args
- // Here we need to support the first historic synopsis of the
- // method.
- else {
-
- // ----- Get the first argument
- $v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0];
-
- // ----- Look for the optional second argument
- if ($v_size == 2) {
- $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
- }
- else if ($v_size > 2) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
- "Invalid number / type of arguments");
- return 0;
- }
- }
- }
-
- // ----- Look for default option values
- $this->privOptionDefaultThreshold($v_options);
-
- // ----- Init
- $v_string_list = array();
- $v_att_list = array();
- $v_filedescr_list = array();
- $p_result_list = array();
-
- // ----- Look if the $p_filelist is really an array
- if (is_array($p_filelist)) {
-
- // ----- Look if the first element is also an array
- // This will mean that this is a file description entry
- if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
- $v_att_list = $p_filelist;
- }
-
- // ----- The list is a list of string names
- else {
- $v_string_list = $p_filelist;
- }
- }
-
- // ----- Look if the $p_filelist is a string
- else if (is_string($p_filelist)) {
- // ----- Create a list from the string
- $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
- }
-
- // ----- Invalid variable type for $p_filelist
- else {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist");
- return 0;
- }
-
- // ----- Reformat the string list
- if (sizeof($v_string_list) != 0) {
- foreach ($v_string_list as $v_string) {
- if ($v_string != '') {
- $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
- }
- else {
- }
- }
- }
-
- // ----- For each file in the list check the attributes
- $v_supported_attributes
- = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
- ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
- ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
- ,PCLZIP_ATT_FILE_MTIME => 'optional'
- ,PCLZIP_ATT_FILE_CONTENT => 'optional'
- ,PCLZIP_ATT_FILE_COMMENT => 'optional'
- );
- foreach ($v_att_list as $v_entry) {
- $v_result = $this->privFileDescrParseAtt($v_entry,
- $v_filedescr_list[],
- $v_options,
- $v_supported_attributes);
- if ($v_result != 1) {
- return 0;
- }
- }
-
- // ----- Expand the filelist (expand directories)
- $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
- if ($v_result != 1) {
- return 0;
- }
-
- // ----- Call the create fct
- $v_result = $this->privCreate($v_filedescr_list, $p_result_list, $v_options);
- if ($v_result != 1) {
- return 0;
- }
-
- // ----- Return
- return $p_result_list;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function :
- // add($p_filelist, $p_add_dir="", $p_remove_dir="")
- // add($p_filelist, $p_option, $p_option_value, ...)
- // Description :
- // This method supports two synopsis. The first one is historical.
- // This methods add the list of files in an existing archive.
- // If a file with the same name already exists, it is added at the end of the
- // archive, the first one is still present.
- // If the archive does not exist, it is created.
- // Parameters :
- // $p_filelist : An array containing file or directory names, or
- // a string containing one filename or one directory name, or
- // a string containing a list of filenames and/or directory
- // names separated by spaces.
- // $p_add_dir : A path to add before the real path of the archived file,
- // in order to have it memorized in the archive.
- // $p_remove_dir : A path to remove from the real path of the file to archive,
- // in order to have a shorter path memorized in the archive.
- // When $p_add_dir and $p_remove_dir are set, $p_remove_dir
- // is removed first, before $p_add_dir is added.
- // Options :
- // PCLZIP_OPT_ADD_PATH :
- // PCLZIP_OPT_REMOVE_PATH :
- // PCLZIP_OPT_REMOVE_ALL_PATH :
- // PCLZIP_OPT_COMMENT :
- // PCLZIP_OPT_ADD_COMMENT :
- // PCLZIP_OPT_PREPEND_COMMENT :
- // PCLZIP_CB_PRE_ADD :
- // PCLZIP_CB_POST_ADD :
- // Return Values :
- // 0 on failure,
- // The list of the added files, with a status of the add action.
- // (see PclZip::listContent() for list entry format)
- // --------------------------------------------------------------------------------
- function add($p_filelist)
- {
- $v_result=1;
-
- // ----- Reset the error handler
- $this->privErrorReset();
-
- // ----- Set default values
- $v_options = array();
- $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
-
- // ----- Look for variable options arguments
- $v_size = func_num_args();
-
- // ----- Look for arguments
- if ($v_size > 1) {
- // ----- Get the arguments
- $v_arg_list = func_get_args();
-
- // ----- Remove form the options list the first argument
- array_shift($v_arg_list);
- $v_size--;
-
- // ----- Look for first arg
- if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
-
- // ----- Parse the options
- $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
- array (PCLZIP_OPT_REMOVE_PATH => 'optional',
- PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
- PCLZIP_OPT_ADD_PATH => 'optional',
- PCLZIP_CB_PRE_ADD => 'optional',
- PCLZIP_CB_POST_ADD => 'optional',
- PCLZIP_OPT_NO_COMPRESSION => 'optional',
- PCLZIP_OPT_COMMENT => 'optional',
- PCLZIP_OPT_ADD_COMMENT => 'optional',
- PCLZIP_OPT_PREPEND_COMMENT => 'optional',
- PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
- PCLZIP_OPT_TEMP_FILE_ON => 'optional',
- PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
- //, PCLZIP_OPT_CRYPT => 'optional'
- ));
- if ($v_result != 1) {
- return 0;
- }
- }
-
- // ----- Look for 2 args
- // Here we need to support the first historic synopsis of the
- // method.
- else {
-
- // ----- Get the first argument
- $v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0];
-
- // ----- Look for the optional second argument
- if ($v_size == 2) {
- $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
- }
- else if ($v_size > 2) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
-
- // ----- Return
- return 0;
- }
- }
- }
-
- // ----- Look for default option values
- $this->privOptionDefaultThreshold($v_options);
-
- // ----- Init
- $v_string_list = array();
- $v_att_list = array();
- $v_filedescr_list = array();
- $p_result_list = array();
-
- // ----- Look if the $p_filelist is really an array
- if (is_array($p_filelist)) {
-
- // ----- Look if the first element is also an array
- // This will mean that this is a file description entry
- if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
- $v_att_list = $p_filelist;
- }
-
- // ----- The list is a list of string names
- else {
- $v_string_list = $p_filelist;
- }
- }
-
- // ----- Look if the $p_filelist is a string
- else if (is_string($p_filelist)) {
- // ----- Create a list from the string
- $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
- }
-
- // ----- Invalid variable type for $p_filelist
- else {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist");
- return 0;
- }
-
- // ----- Reformat the string list
- if (sizeof($v_string_list) != 0) {
- foreach ($v_string_list as $v_string) {
- $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
- }
- }
-
- // ----- For each file in the list check the attributes
- $v_supported_attributes
- = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
- ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
- ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
- ,PCLZIP_ATT_FILE_MTIME => 'optional'
- ,PCLZIP_ATT_FILE_CONTENT => 'optional'
- ,PCLZIP_ATT_FILE_COMMENT => 'optional'
- );
- foreach ($v_att_list as $v_entry) {
- $v_result = $this->privFileDescrParseAtt($v_entry,
- $v_filedescr_list[],
- $v_options,
- $v_supported_attributes);
- if ($v_result != 1) {
- return 0;
- }
- }
-
- // ----- Expand the filelist (expand directories)
- $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
- if ($v_result != 1) {
- return 0;
- }
-
- // ----- Call the create fct
- $v_result = $this->privAdd($v_filedescr_list, $p_result_list, $v_options);
- if ($v_result != 1) {
- return 0;
- }
-
- // ----- Return
- return $p_result_list;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : listContent()
- // Description :
- // This public method, gives the list of the files and directories, with their
- // properties.
- // The properties of each entries in the list are (used also in other functions) :
- // filename : Name of the file. For a create or add action it is the filename
- // given by the user. For an extract function it is the filename
- // of the extracted file.
- // stored_filename : Name of the file / directory stored in the archive.
- // size : Size of the stored file.
- // compressed_size : Size of the file's data compressed in the archive
- // (without the headers overhead)
- // mtime : Last known modification date of the file (UNIX timestamp)
- // comment : Comment associated with the file
- // folder : true | false
- // index : index of the file in the archive
- // status : status of the action (depending of the action) :
- // Values are :
- // ok : OK !
- // filtered : the file / dir is not extracted (filtered by user)
- // already_a_directory : the file can not be extracted because a
- // directory with the same name already exists
- // write_protected : the file can not be extracted because a file
- // with the same name already exists and is
- // write protected
- // newer_exist : the file was not extracted because a newer file exists
- // path_creation_fail : the file is not extracted because the folder
- // does not exist and can not be created
- // write_error : the file was not extracted because there was a
- // error while writing the file
- // read_error : the file was not extracted because there was a error
- // while reading the file
- // invalid_header : the file was not extracted because of an archive
- // format error (bad file header)
- // Note that each time a method can continue operating when there
- // is an action error on a file, the error is only logged in the file status.
- // Return Values :
- // 0 on an unrecoverable failure,
- // The list of the files in the archive.
- // --------------------------------------------------------------------------------
- function listContent()
- {
- $v_result=1;
-
- // ----- Reset the error handler
- $this->privErrorReset();
-
- // ----- Check archive
- if (!$this->privCheckFormat()) {
- return(0);
- }
-
- // ----- Call the extracting fct
- $p_list = array();
- if (($v_result = $this->privList($p_list)) != 1)
- {
- unset($p_list);
- return(0);
- }
-
- // ----- Return
- return $p_list;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function :
- // extract($p_path="./", $p_remove_path="")
- // extract([$p_option, $p_option_value, ...])
- // Description :
- // This method supports two synopsis. The first one is historical.
- // This method extract all the files / directories from the archive to the
- // folder indicated in $p_path.
- // If you want to ignore the 'root' part of path of the memorized files
- // you can indicate this in the optional $p_remove_path parameter.
- // By default, if a newer file with the same name already exists, the
- // file is not extracted.
- //
- // If both PCLZIP_OPT_PATH and PCLZIP_OPT_ADD_PATH aoptions
- // are used, the path indicated in PCLZIP_OPT_ADD_PATH is append
- // at the end of the path value of PCLZIP_OPT_PATH.
- // Parameters :
- // $p_path : Path where the files and directories are to be extracted
- // $p_remove_path : First part ('root' part) of the memorized path
- // (if any similar) to remove while extracting.
- // Options :
- // PCLZIP_OPT_PATH :
- // PCLZIP_OPT_ADD_PATH :
- // PCLZIP_OPT_REMOVE_PATH :
- // PCLZIP_OPT_REMOVE_ALL_PATH :
- // PCLZIP_CB_PRE_EXTRACT :
- // PCLZIP_CB_POST_EXTRACT :
- // Return Values :
- // 0 or a negative value on failure,
- // The list of the extracted files, with a status of the action.
- // (see PclZip::listContent() for list entry format)
- // --------------------------------------------------------------------------------
- function extract()
- {
- $v_result=1;
-
- // ----- Reset the error handler
- $this->privErrorReset();
-
- // ----- Check archive
- if (!$this->privCheckFormat()) {
- return(0);
- }
-
- // ----- Set default values
- $v_options = array();
-// $v_path = "./";
- $v_path = '';
- $v_remove_path = "";
- $v_remove_all_path = false;
-
- // ----- Look for variable options arguments
- $v_size = func_num_args();
-
- // ----- Default values for option
- $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
-
- // ----- Look for arguments
- if ($v_size > 0) {
- // ----- Get the arguments
- $v_arg_list = func_get_args();
-
- // ----- Look for first arg
- if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
-
- // ----- Parse the options
- $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
- array (PCLZIP_OPT_PATH => 'optional',
- PCLZIP_OPT_REMOVE_PATH => 'optional',
- PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
- PCLZIP_OPT_ADD_PATH => 'optional',
- PCLZIP_CB_PRE_EXTRACT => 'optional',
- PCLZIP_CB_POST_EXTRACT => 'optional',
- PCLZIP_OPT_SET_CHMOD => 'optional',
- PCLZIP_OPT_BY_NAME => 'optional',
- PCLZIP_OPT_BY_EREG => 'optional',
- PCLZIP_OPT_BY_PREG => 'optional',
- PCLZIP_OPT_BY_INDEX => 'optional',
- PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
- PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional',
- PCLZIP_OPT_REPLACE_NEWER => 'optional'
- ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
- ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
- PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
- PCLZIP_OPT_TEMP_FILE_ON => 'optional',
- PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
- ));
- if ($v_result != 1) {
- return 0;
- }
-
- // ----- Set the arguments
- if (isset($v_options[PCLZIP_OPT_PATH])) {
- $v_path = $v_options[PCLZIP_OPT_PATH];
- }
- if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
- $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
- }
- if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
- $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
- }
- if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
- // ----- Check for '/' in last path char
- if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
- $v_path .= '/';
- }
- $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
- }
- }
-
- // ----- Look for 2 args
- // Here we need to support the first historic synopsis of the
- // method.
- else {
-
- // ----- Get the first argument
- $v_path = $v_arg_list[0];
-
- // ----- Look for the optional second argument
- if ($v_size == 2) {
- $v_remove_path = $v_arg_list[1];
- }
- else if ($v_size > 2) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
-
- // ----- Return
- return 0;
- }
- }
- }
-
- // ----- Look for default option values
- $this->privOptionDefaultThreshold($v_options);
-
- // ----- Trace
-
- // ----- Call the extracting fct
- $p_list = array();
- $v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path,
- $v_remove_all_path, $v_options);
- if ($v_result < 1) {
- unset($p_list);
- return(0);
- }
-
- // ----- Return
- return $p_list;
- }
- // --------------------------------------------------------------------------------
-
-
- // --------------------------------------------------------------------------------
- // Function :
- // extractByIndex($p_index, $p_path="./", $p_remove_path="")
- // extractByIndex($p_index, [$p_option, $p_option_value, ...])
- // Description :
- // This method supports two synopsis. The first one is historical.
- // This method is doing a partial extract of the archive.
- // The extracted files or folders are identified by their index in the
- // archive (from 0 to n).
- // Note that if the index identify a folder, only the folder entry is
- // extracted, not all the files included in the archive.
- // Parameters :
- // $p_index : A single index (integer) or a string of indexes of files to
- // extract. The form of the string is "0,4-6,8-12" with only numbers
- // and '-' for range or ',' to separate ranges. No spaces or ';'
- // are allowed.
- // $p_path : Path where the files and directories are to be extracted
- // $p_remove_path : First part ('root' part) of the memorized path
- // (if any similar) to remove while extracting.
- // Options :
- // PCLZIP_OPT_PATH :
- // PCLZIP_OPT_ADD_PATH :
- // PCLZIP_OPT_REMOVE_PATH :
- // PCLZIP_OPT_REMOVE_ALL_PATH :
- // PCLZIP_OPT_EXTRACT_AS_STRING : The files are extracted as strings and
- // not as files.
- // The resulting content is in a new field 'content' in the file
- // structure.
- // This option must be used alone (any other options are ignored).
- // PCLZIP_CB_PRE_EXTRACT :
- // PCLZIP_CB_POST_EXTRACT :
- // Return Values :
- // 0 on failure,
- // The list of the extracted files, with a status of the action.
- // (see PclZip::listContent() for list entry format)
- // --------------------------------------------------------------------------------
- //function extractByIndex($p_index, options...)
- function extractByIndex($p_index)
- {
- $v_result=1;
-
- // ----- Reset the error handler
- $this->privErrorReset();
-
- // ----- Check archive
- if (!$this->privCheckFormat()) {
- return(0);
- }
-
- // ----- Set default values
- $v_options = array();
-// $v_path = "./";
- $v_path = '';
- $v_remove_path = "";
- $v_remove_all_path = false;
-
- // ----- Look for variable options arguments
- $v_size = func_num_args();
-
- // ----- Default values for option
- $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
-
- // ----- Look for arguments
- if ($v_size > 1) {
- // ----- Get the arguments
- $v_arg_list = func_get_args();
-
- // ----- Remove form the options list the first argument
- array_shift($v_arg_list);
- $v_size--;
-
- // ----- Look for first arg
- if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
-
- // ----- Parse the options
- $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
- array (PCLZIP_OPT_PATH => 'optional',
- PCLZIP_OPT_REMOVE_PATH => 'optional',
- PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
- PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
- PCLZIP_OPT_ADD_PATH => 'optional',
- PCLZIP_CB_PRE_EXTRACT => 'optional',
- PCLZIP_CB_POST_EXTRACT => 'optional',
- PCLZIP_OPT_SET_CHMOD => 'optional',
- PCLZIP_OPT_REPLACE_NEWER => 'optional'
- ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
- ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
- PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
- PCLZIP_OPT_TEMP_FILE_ON => 'optional',
- PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
- ));
- if ($v_result != 1) {
- return 0;
- }
-
- // ----- Set the arguments
- if (isset($v_options[PCLZIP_OPT_PATH])) {
- $v_path = $v_options[PCLZIP_OPT_PATH];
- }
- if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
- $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
- }
- if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
- $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
- }
- if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
- // ----- Check for '/' in last path char
- if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
- $v_path .= '/';
- }
- $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
- }
- if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) {
- $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
- }
- else {
- }
- }
-
- // ----- Look for 2 args
- // Here we need to support the first historic synopsis of the
- // method.
- else {
-
- // ----- Get the first argument
- $v_path = $v_arg_list[0];
-
- // ----- Look for the optional second argument
- if ($v_size == 2) {
- $v_remove_path = $v_arg_list[1];
- }
- else if ($v_size > 2) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
-
- // ----- Return
- return 0;
- }
- }
- }
-
- // ----- Trace
-
- // ----- Trick
- // Here I want to reuse extractByRule(), so I need to parse the $p_index
- // with privParseOptions()
- $v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index);
- $v_options_trick = array();
- $v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick,
- array (PCLZIP_OPT_BY_INDEX => 'optional' ));
- if ($v_result != 1) {
- return 0;
- }
- $v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX];
-
- // ----- Look for default option values
- $this->privOptionDefaultThreshold($v_options);
-
- // ----- Call the extracting fct
- if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) {
- return(0);
- }
-
- // ----- Return
- return $p_list;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function :
- // delete([$p_option, $p_option_value, ...])
- // Description :
- // This method removes files from the archive.
- // If no parameters are given, then all the archive is emptied.
- // Parameters :
- // None or optional arguments.
- // Options :
- // PCLZIP_OPT_BY_INDEX :
- // PCLZIP_OPT_BY_NAME :
- // PCLZIP_OPT_BY_EREG :
- // PCLZIP_OPT_BY_PREG :
- // Return Values :
- // 0 on failure,
- // The list of the files which are still present in the archive.
- // (see PclZip::listContent() for list entry format)
- // --------------------------------------------------------------------------------
- function delete()
- {
- $v_result=1;
-
- // ----- Reset the error handler
- $this->privErrorReset();
-
- // ----- Check archive
- if (!$this->privCheckFormat()) {
- return(0);
- }
-
- // ----- Set default values
- $v_options = array();
-
- // ----- Look for variable options arguments
- $v_size = func_num_args();
-
- // ----- Look for arguments
- if ($v_size > 0) {
- // ----- Get the arguments
- $v_arg_list = func_get_args();
-
- // ----- Parse the options
- $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
- array (PCLZIP_OPT_BY_NAME => 'optional',
- PCLZIP_OPT_BY_EREG => 'optional',
- PCLZIP_OPT_BY_PREG => 'optional',
- PCLZIP_OPT_BY_INDEX => 'optional' ));
- if ($v_result != 1) {
- return 0;
- }
- }
-
- // ----- Magic quotes trick
- $this->privDisableMagicQuotes();
-
- // ----- Call the delete fct
- $v_list = array();
- if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) {
- $this->privSwapBackMagicQuotes();
- unset($v_list);
- return(0);
- }
-
- // ----- Magic quotes trick
- $this->privSwapBackMagicQuotes();
-
- // ----- Return
- return $v_list;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : deleteByIndex()
- // Description :
- // ***** Deprecated *****
- // delete(PCLZIP_OPT_BY_INDEX, $p_index) should be prefered.
- // --------------------------------------------------------------------------------
- function deleteByIndex($p_index)
- {
-
- $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index);
-
- // ----- Return
- return $p_list;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : properties()
- // Description :
- // This method gives the properties of the archive.
- // The properties are :
- // nb : Number of files in the archive
- // comment : Comment associated with the archive file
- // status : not_exist, ok
- // Parameters :
- // None
- // Return Values :
- // 0 on failure,
- // An array with the archive properties.
- // --------------------------------------------------------------------------------
- function properties()
- {
-
- // ----- Reset the error handler
- $this->privErrorReset();
-
- // ----- Magic quotes trick
- $this->privDisableMagicQuotes();
-
- // ----- Check archive
- if (!$this->privCheckFormat()) {
- $this->privSwapBackMagicQuotes();
- return(0);
- }
-
- // ----- Default properties
- $v_prop = array();
- $v_prop['comment'] = '';
- $v_prop['nb'] = 0;
- $v_prop['status'] = 'not_exist';
-
- // ----- Look if file exists
- if (@is_file($this->zipname))
- {
- // ----- Open the zip file
- if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
- {
- $this->privSwapBackMagicQuotes();
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
-
- // ----- Return
- return 0;
- }
-
- // ----- Read the central directory informations
- $v_central_dir = array();
- if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
- {
- $this->privSwapBackMagicQuotes();
- return 0;
- }
-
- // ----- Close the zip file
- $this->privCloseFd();
-
- // ----- Set the user attributes
- $v_prop['comment'] = $v_central_dir['comment'];
- $v_prop['nb'] = $v_central_dir['entries'];
- $v_prop['status'] = 'ok';
- }
-
- // ----- Magic quotes trick
- $this->privSwapBackMagicQuotes();
-
- // ----- Return
- return $v_prop;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : duplicate()
- // Description :
- // This method creates an archive by copying the content of an other one. If
- // the archive already exist, it is replaced by the new one without any warning.
- // Parameters :
- // $p_archive : The filename of a valid archive, or
- // a valid PclZip object.
- // Return Values :
- // 1 on success.
- // 0 or a negative value on error (error code).
- // --------------------------------------------------------------------------------
- function duplicate($p_archive)
- {
- $v_result = 1;
-
- // ----- Reset the error handler
- $this->privErrorReset();
-
- // ----- Look if the $p_archive is a PclZip object
- if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip'))
- {
-
- // ----- Duplicate the archive
- $v_result = $this->privDuplicate($p_archive->zipname);
- }
-
- // ----- Look if the $p_archive is a string (so a filename)
- else if (is_string($p_archive))
- {
-
- // ----- Check that $p_archive is a valid zip file
- // TBC : Should also check the archive format
- if (!is_file($p_archive)) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'");
- $v_result = PCLZIP_ERR_MISSING_FILE;
- }
- else {
- // ----- Duplicate the archive
- $v_result = $this->privDuplicate($p_archive);
- }
- }
-
- // ----- Invalid variable
- else
- {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
- $v_result = PCLZIP_ERR_INVALID_PARAMETER;
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : merge()
- // Description :
- // This method merge the $p_archive_to_add archive at the end of the current
- // one ($this).
- // If the archive ($this) does not exist, the merge becomes a duplicate.
- // If the $p_archive_to_add archive does not exist, the merge is a success.
- // Parameters :
- // $p_archive_to_add : It can be directly the filename of a valid zip archive,
- // or a PclZip object archive.
- // Return Values :
- // 1 on success,
- // 0 or negative values on error (see below).
- // --------------------------------------------------------------------------------
- function merge($p_archive_to_add)
- {
- $v_result = 1;
-
- // ----- Reset the error handler
- $this->privErrorReset();
-
- // ----- Check archive
- if (!$this->privCheckFormat()) {
- return(0);
- }
-
- // ----- Look if the $p_archive_to_add is a PclZip object
- if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip'))
- {
-
- // ----- Merge the archive
- $v_result = $this->privMerge($p_archive_to_add);
- }
-
- // ----- Look if the $p_archive_to_add is a string (so a filename)
- else if (is_string($p_archive_to_add))
- {
-
- // ----- Create a temporary archive
- $v_object_archive = new PclZip($p_archive_to_add);
-
- // ----- Merge the archive
- $v_result = $this->privMerge($v_object_archive);
- }
-
- // ----- Invalid variable
- else
- {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
- $v_result = PCLZIP_ERR_INVALID_PARAMETER;
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
-
-
- // --------------------------------------------------------------------------------
- // Function : errorCode()
- // Description :
- // Parameters :
- // --------------------------------------------------------------------------------
- function errorCode()
- {
- if (PCLZIP_ERROR_EXTERNAL == 1) {
- return(PclErrorCode());
- }
- else {
- return($this->error_code);
- }
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : errorName()
- // Description :
- // Parameters :
- // --------------------------------------------------------------------------------
- function errorName($p_with_code=false)
- {
- $v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR',
- PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL',
- PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL',
- PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER',
- PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE',
- PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG',
- PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP',
- PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE',
- PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL',
- PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION',
- PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT',
- PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL',
- PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL',
- PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM',
- PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP',
- PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE',
- PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE',
- PCLZIP_ERR_UNSUPPORTED_COMPRESSION => 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION',
- PCLZIP_ERR_UNSUPPORTED_ENCRYPTION => 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION'
- ,PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE => 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE'
- ,PCLZIP_ERR_DIRECTORY_RESTRICTION => 'PCLZIP_ERR_DIRECTORY_RESTRICTION'
- );
-
- if (isset($v_name[$this->error_code])) {
- $v_value = $v_name[$this->error_code];
- }
- else {
- $v_value = 'NoName';
- }
-
- if ($p_with_code) {
- return($v_value.' ('.$this->error_code.')');
- }
- else {
- return($v_value);
- }
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : errorInfo()
- // Description :
- // Parameters :
- // --------------------------------------------------------------------------------
- function errorInfo($p_full=false)
- {
- if (PCLZIP_ERROR_EXTERNAL == 1) {
- return(PclErrorString());
- }
- else {
- if ($p_full) {
- return($this->errorName(true)." : ".$this->error_string);
- }
- else {
- return($this->error_string." [code ".$this->error_code."]");
- }
- }
- }
- // --------------------------------------------------------------------------------
-
-
-// --------------------------------------------------------------------------------
-// ***** UNDER THIS LINE ARE DEFINED PRIVATE INTERNAL FUNCTIONS *****
-// ***** *****
-// ***** THESES FUNCTIONS MUST NOT BE USED DIRECTLY *****
-// --------------------------------------------------------------------------------
-
-
-
- // --------------------------------------------------------------------------------
- // Function : privCheckFormat()
- // Description :
- // This method check that the archive exists and is a valid zip archive.
- // Several level of check exists. (futur)
- // Parameters :
- // $p_level : Level of check. Default 0.
- // 0 : Check the first bytes (magic codes) (default value))
- // 1 : 0 + Check the central directory (futur)
- // 2 : 1 + Check each file header (futur)
- // Return Values :
- // true on success,
- // false on error, the error code is set.
- // --------------------------------------------------------------------------------
- function privCheckFormat($p_level=0)
- {
- $v_result = true;
-
- // ----- Reset the file system cache
- clearstatcache();
-
- // ----- Reset the error handler
- $this->privErrorReset();
-
- // ----- Look if the file exits
- if (!is_file($this->zipname)) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'");
- return(false);
- }
-
- // ----- Check that the file is readeable
- if (!is_readable($this->zipname)) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'");
- return(false);
- }
-
- // ----- Check the magic code
- // TBC
-
- // ----- Check the central header
- // TBC
-
- // ----- Check each file header
- // TBC
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privParseOptions()
- // Description :
- // This internal methods reads the variable list of arguments ($p_options_list,
- // $p_size) and generate an array with the options and values ($v_result_list).
- // $v_requested_options contains the options that can be present and those that
- // must be present.
- // $v_requested_options is an array, with the option value as key, and 'optional',
- // or 'mandatory' as value.
- // Parameters :
- // See above.
- // Return Values :
- // 1 on success.
- // 0 on failure.
- // --------------------------------------------------------------------------------
- function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options=false)
- {
- $v_result=1;
-
- // ----- Read the options
- $i=0;
- while ($i<$p_size) {
-
- // ----- Check if the option is supported
- if (!isset($v_requested_options[$p_options_list[$i]])) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Look for next option
- switch ($p_options_list[$i]) {
- // ----- Look for options that request a path value
- case PCLZIP_OPT_PATH :
- case PCLZIP_OPT_REMOVE_PATH :
- case PCLZIP_OPT_ADD_PATH :
- // ----- Check the number of parameters
- if (($i+1) >= $p_size) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Get the value
- $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE);
- $i++;
- break;
-
- case PCLZIP_OPT_TEMP_FILE_THRESHOLD :
- // ----- Check the number of parameters
- if (($i+1) >= $p_size) {
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
- return PclZip::errorCode();
- }
-
- // ----- Check for incompatible options
- if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'");
- return PclZip::errorCode();
- }
-
- // ----- Check the value
- $v_value = $p_options_list[$i+1];
- if ((!is_integer($v_value)) || ($v_value<0)) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Integer expected for option '".PclZipUtilOptionText($p_options_list[$i])."'");
- return PclZip::errorCode();
- }
-
- // ----- Get the value (and convert it in bytes)
- $v_result_list[$p_options_list[$i]] = $v_value*1048576;
- $i++;
- break;
-
- case PCLZIP_OPT_TEMP_FILE_ON :
- // ----- Check for incompatible options
- if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'");
- return PclZip::errorCode();
- }
-
- $v_result_list[$p_options_list[$i]] = true;
- break;
-
- case PCLZIP_OPT_TEMP_FILE_OFF :
- // ----- Check for incompatible options
- if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_ON])) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_ON'");
- return PclZip::errorCode();
- }
- // ----- Check for incompatible options
- if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_THRESHOLD'");
- return PclZip::errorCode();
- }
-
- $v_result_list[$p_options_list[$i]] = true;
- break;
-
- case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION :
- // ----- Check the number of parameters
- if (($i+1) >= $p_size) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Get the value
- if ( is_string($p_options_list[$i+1])
- && ($p_options_list[$i+1] != '')) {
- $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE);
- $i++;
- }
- else {
- }
- break;
-
- // ----- Look for options that request an array of string for value
- case PCLZIP_OPT_BY_NAME :
- // ----- Check the number of parameters
- if (($i+1) >= $p_size) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Get the value
- if (is_string($p_options_list[$i+1])) {
- $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1];
- }
- else if (is_array($p_options_list[$i+1])) {
- $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
- }
- else {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
- $i++;
- break;
-
- // ----- Look for options that request an EREG or PREG expression
- case PCLZIP_OPT_BY_EREG :
- // ereg() is deprecated starting with PHP 5.3. Move PCLZIP_OPT_BY_EREG
- // to PCLZIP_OPT_BY_PREG
- $p_options_list[$i] = PCLZIP_OPT_BY_PREG;
- case PCLZIP_OPT_BY_PREG :
- //case PCLZIP_OPT_CRYPT :
- // ----- Check the number of parameters
- if (($i+1) >= $p_size) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Get the value
- if (is_string($p_options_list[$i+1])) {
- $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
- }
- else {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
- $i++;
- break;
-
- // ----- Look for options that takes a string
- case PCLZIP_OPT_COMMENT :
- case PCLZIP_OPT_ADD_COMMENT :
- case PCLZIP_OPT_PREPEND_COMMENT :
- // ----- Check the number of parameters
- if (($i+1) >= $p_size) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE,
- "Missing parameter value for option '"
- .PclZipUtilOptionText($p_options_list[$i])
- ."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Get the value
- if (is_string($p_options_list[$i+1])) {
- $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
- }
- else {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE,
- "Wrong parameter value for option '"
- .PclZipUtilOptionText($p_options_list[$i])
- ."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
- $i++;
- break;
-
- // ----- Look for options that request an array of index
- case PCLZIP_OPT_BY_INDEX :
- // ----- Check the number of parameters
- if (($i+1) >= $p_size) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Get the value
- $v_work_list = array();
- if (is_string($p_options_list[$i+1])) {
-
- // ----- Remove spaces
- $p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', '');
-
- // ----- Parse items
- $v_work_list = explode(",", $p_options_list[$i+1]);
- }
- else if (is_integer($p_options_list[$i+1])) {
- $v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1];
- }
- else if (is_array($p_options_list[$i+1])) {
- $v_work_list = $p_options_list[$i+1];
- }
- else {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Reduce the index list
- // each index item in the list must be a couple with a start and
- // an end value : [0,3], [5-5], [8-10], ...
- // ----- Check the format of each item
- $v_sort_flag=false;
- $v_sort_value=0;
- for ($j=0; $j= $p_size) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Get the value
- $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
- $i++;
- break;
-
- // ----- Look for options that request a call-back
- case PCLZIP_CB_PRE_EXTRACT :
- case PCLZIP_CB_POST_EXTRACT :
- case PCLZIP_CB_PRE_ADD :
- case PCLZIP_CB_POST_ADD :
- /* for futur use
- case PCLZIP_CB_PRE_DELETE :
- case PCLZIP_CB_POST_DELETE :
- case PCLZIP_CB_PRE_LIST :
- case PCLZIP_CB_POST_LIST :
- */
- // ----- Check the number of parameters
- if (($i+1) >= $p_size) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Get the value
- $v_function_name = $p_options_list[$i+1];
-
- // ----- Check that the value is a valid existing function
- if (!function_exists($v_function_name)) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '".$v_function_name."()' is not an existing function for option '".PclZipUtilOptionText($p_options_list[$i])."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Set the attribute
- $v_result_list[$p_options_list[$i]] = $v_function_name;
- $i++;
- break;
-
- default :
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
- "Unknown parameter '"
- .$p_options_list[$i]."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Next options
- $i++;
- }
-
- // ----- Look for mandatory options
- if ($v_requested_options !== false) {
- for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
- // ----- Look for mandatory option
- if ($v_requested_options[$key] == 'mandatory') {
- // ----- Look if present
- if (!isset($v_result_list[$key])) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
-
- // ----- Return
- return PclZip::errorCode();
- }
- }
- }
- }
-
- // ----- Look for default values
- if (!isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) {
-
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privOptionDefaultThreshold()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privOptionDefaultThreshold(&$p_options)
- {
- $v_result=1;
-
- if (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
- || isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) {
- return $v_result;
- }
-
- // ----- Get 'memory_limit' configuration value
- $v_memory_limit = ini_get('memory_limit');
- $v_memory_limit = trim($v_memory_limit);
- $last = strtolower(substr($v_memory_limit, -1));
-
- if ($last == 'g')
- //$v_memory_limit = $v_memory_limit*1024*1024*1024;
- $v_memory_limit = $v_memory_limit*1073741824;
- if ($last == 'm')
- //$v_memory_limit = $v_memory_limit*1024*1024;
- $v_memory_limit = $v_memory_limit*1048576;
- if ($last == 'k')
- $v_memory_limit = $v_memory_limit*1024;
-
- $p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] = floor($v_memory_limit*PCLZIP_TEMPORARY_FILE_RATIO);
-
-
- // ----- Sanity check : No threshold if value lower than 1M
- if ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] < 1048576) {
- unset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]);
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privFileDescrParseAtt()
- // Description :
- // Parameters :
- // Return Values :
- // 1 on success.
- // 0 on failure.
- // --------------------------------------------------------------------------------
- function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options=false)
- {
- $v_result=1;
-
- // ----- For each file in the list check the attributes
- foreach ($p_file_list as $v_key => $v_value) {
-
- // ----- Check if the option is supported
- if (!isset($v_requested_options[$v_key])) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Look for attribute
- switch ($v_key) {
- case PCLZIP_ATT_FILE_NAME :
- if (!is_string($v_value)) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
- return PclZip::errorCode();
- }
-
- $p_filedescr['filename'] = PclZipUtilPathReduction($v_value);
-
- if ($p_filedescr['filename'] == '') {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'");
- return PclZip::errorCode();
- }
-
- break;
-
- case PCLZIP_ATT_FILE_NEW_SHORT_NAME :
- if (!is_string($v_value)) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
- return PclZip::errorCode();
- }
-
- $p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value);
-
- if ($p_filedescr['new_short_name'] == '') {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'");
- return PclZip::errorCode();
- }
- break;
-
- case PCLZIP_ATT_FILE_NEW_FULL_NAME :
- if (!is_string($v_value)) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
- return PclZip::errorCode();
- }
-
- $p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value);
-
- if ($p_filedescr['new_full_name'] == '') {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'");
- return PclZip::errorCode();
- }
- break;
-
- // ----- Look for options that takes a string
- case PCLZIP_ATT_FILE_COMMENT :
- if (!is_string($v_value)) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
- return PclZip::errorCode();
- }
-
- $p_filedescr['comment'] = $v_value;
- break;
-
- case PCLZIP_ATT_FILE_MTIME :
- if (!is_integer($v_value)) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". Integer expected for attribute '".PclZipUtilOptionText($v_key)."'");
- return PclZip::errorCode();
- }
-
- $p_filedescr['mtime'] = $v_value;
- break;
-
- case PCLZIP_ATT_FILE_CONTENT :
- $p_filedescr['content'] = $v_value;
- break;
-
- default :
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
- "Unknown parameter '".$v_key."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Look for mandatory options
- if ($v_requested_options !== false) {
- for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
- // ----- Look for mandatory option
- if ($v_requested_options[$key] == 'mandatory') {
- // ----- Look if present
- if (!isset($p_file_list[$key])) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
- return PclZip::errorCode();
- }
- }
- }
- }
-
- // end foreach
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privFileDescrExpand()
- // Description :
- // This method look for each item of the list to see if its a file, a folder
- // or a string to be added as file. For any other type of files (link, other)
- // just ignore the item.
- // Then prepare the information that will be stored for that file.
- // When its a folder, expand the folder with all the files that are in that
- // folder (recursively).
- // Parameters :
- // Return Values :
- // 1 on success.
- // 0 on failure.
- // --------------------------------------------------------------------------------
- function privFileDescrExpand(&$p_filedescr_list, &$p_options)
- {
- $v_result=1;
-
- // ----- Create a result list
- $v_result_list = array();
-
- // ----- Look each entry
- for ($i=0; $iprivCalculateStoredFilename($v_descr, $p_options);
-
- // ----- Add the descriptor in result list
- $v_result_list[sizeof($v_result_list)] = $v_descr;
-
- // ----- Look for folder
- if ($v_descr['type'] == 'folder') {
- // ----- List of items in folder
- $v_dirlist_descr = array();
- $v_dirlist_nb = 0;
- if ($v_folder_handler = @opendir($v_descr['filename'])) {
- while (($v_item_handler = @readdir($v_folder_handler)) !== false) {
-
- // ----- Skip '.' and '..'
- if (($v_item_handler == '.') || ($v_item_handler == '..')) {
- continue;
- }
-
- // ----- Compose the full filename
- $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler;
-
- // ----- Look for different stored filename
- // Because the name of the folder was changed, the name of the
- // files/sub-folders also change
- if (($v_descr['stored_filename'] != $v_descr['filename'])
- && (!isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))) {
- if ($v_descr['stored_filename'] != '') {
- $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler;
- }
- else {
- $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_item_handler;
- }
- }
-
- $v_dirlist_nb++;
- }
-
- @closedir($v_folder_handler);
- }
- else {
- // TBC : unable to open folder in read mode
- }
-
- // ----- Expand each element of the list
- if ($v_dirlist_nb != 0) {
- // ----- Expand
- if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) {
- return $v_result;
- }
-
- // ----- Concat the resulting list
- $v_result_list = array_merge($v_result_list, $v_dirlist_descr);
- }
- else {
- }
-
- // ----- Free local array
- unset($v_dirlist_descr);
- }
- }
-
- // ----- Get the result list
- $p_filedescr_list = $v_result_list;
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privCreate()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privCreate($p_filedescr_list, &$p_result_list, &$p_options)
- {
- $v_result=1;
- $v_list_detail = array();
-
- // ----- Magic quotes trick
- $this->privDisableMagicQuotes();
-
- // ----- Open the file in write mode
- if (($v_result = $this->privOpenFd('wb')) != 1)
- {
- // ----- Return
- return $v_result;
- }
-
- // ----- Add the list of files
- $v_result = $this->privAddList($p_filedescr_list, $p_result_list, $p_options);
-
- // ----- Close
- $this->privCloseFd();
-
- // ----- Magic quotes trick
- $this->privSwapBackMagicQuotes();
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privAdd()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privAdd($p_filedescr_list, &$p_result_list, &$p_options)
- {
- $v_result=1;
- $v_list_detail = array();
-
- // ----- Look if the archive exists or is empty
- if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0))
- {
-
- // ----- Do a create
- $v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options);
-
- // ----- Return
- return $v_result;
- }
- // ----- Magic quotes trick
- $this->privDisableMagicQuotes();
-
- // ----- Open the zip file
- if (($v_result=$this->privOpenFd('rb')) != 1)
- {
- // ----- Magic quotes trick
- $this->privSwapBackMagicQuotes();
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Read the central directory informations
- $v_central_dir = array();
- if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
- {
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
- return $v_result;
- }
-
- // ----- Go to beginning of File
- @rewind($this->zip_fd);
-
- // ----- Creates a temporay file
- $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
-
- // ----- Open the temporary file in write mode
- if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
- {
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
-
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Copy the files from the archive to the temporary file
- // TBC : Here I should better append the file and go back to erase the central dir
- $v_size = $v_central_dir['offset'];
- while ($v_size != 0)
- {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = fread($this->zip_fd, $v_read_size);
- @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
-
- // ----- Swap the file descriptor
- // Here is a trick : I swap the temporary fd with the zip fd, in order to use
- // the following methods on the temporary fil and not the real archive
- $v_swap = $this->zip_fd;
- $this->zip_fd = $v_zip_temp_fd;
- $v_zip_temp_fd = $v_swap;
-
- // ----- Add the files
- $v_header_list = array();
- if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)
- {
- fclose($v_zip_temp_fd);
- $this->privCloseFd();
- @unlink($v_zip_temp_name);
- $this->privSwapBackMagicQuotes();
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Store the offset of the central dir
- $v_offset = @ftell($this->zip_fd);
-
- // ----- Copy the block of file headers from the old archive
- $v_size = $v_central_dir['size'];
- while ($v_size != 0)
- {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @fread($v_zip_temp_fd, $v_read_size);
- @fwrite($this->zip_fd, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
-
- // ----- Create the Central Dir files header
- for ($i=0, $v_count=0; $iprivWriteCentralFileHeader($v_header_list[$i])) != 1) {
- fclose($v_zip_temp_fd);
- $this->privCloseFd();
- @unlink($v_zip_temp_name);
- $this->privSwapBackMagicQuotes();
-
- // ----- Return
- return $v_result;
- }
- $v_count++;
- }
-
- // ----- Transform the header to a 'usable' info
- $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
- }
-
- // ----- Zip file comment
- $v_comment = $v_central_dir['comment'];
- if (isset($p_options[PCLZIP_OPT_COMMENT])) {
- $v_comment = $p_options[PCLZIP_OPT_COMMENT];
- }
- if (isset($p_options[PCLZIP_OPT_ADD_COMMENT])) {
- $v_comment = $v_comment.$p_options[PCLZIP_OPT_ADD_COMMENT];
- }
- if (isset($p_options[PCLZIP_OPT_PREPEND_COMMENT])) {
- $v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT].$v_comment;
- }
-
- // ----- Calculate the size of the central header
- $v_size = @ftell($this->zip_fd)-$v_offset;
-
- // ----- Create the central dir footer
- if (($v_result = $this->privWriteCentralHeader($v_count+$v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1)
- {
- // ----- Reset the file list
- unset($v_header_list);
- $this->privSwapBackMagicQuotes();
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Swap back the file descriptor
- $v_swap = $this->zip_fd;
- $this->zip_fd = $v_zip_temp_fd;
- $v_zip_temp_fd = $v_swap;
-
- // ----- Close
- $this->privCloseFd();
-
- // ----- Close the temporary file
- @fclose($v_zip_temp_fd);
-
- // ----- Magic quotes trick
- $this->privSwapBackMagicQuotes();
-
- // ----- Delete the zip file
- // TBC : I should test the result ...
- @unlink($this->zipname);
-
- // ----- Rename the temporary file
- // TBC : I should test the result ...
- //@rename($v_zip_temp_name, $this->zipname);
- PclZipUtilRename($v_zip_temp_name, $this->zipname);
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privOpenFd()
- // Description :
- // Parameters :
- // --------------------------------------------------------------------------------
- function privOpenFd($p_mode)
- {
- $v_result=1;
-
- // ----- Look if already open
- if ($this->zip_fd != 0)
- {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \''.$this->zipname.'\' already open');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Open the zip file
- if (($this->zip_fd = @fopen($this->zipname, $p_mode)) == 0)
- {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privCloseFd()
- // Description :
- // Parameters :
- // --------------------------------------------------------------------------------
- function privCloseFd()
- {
- $v_result=1;
-
- if ($this->zip_fd != 0)
- @fclose($this->zip_fd);
- $this->zip_fd = 0;
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privAddList()
- // Description :
- // $p_add_dir and $p_remove_dir will give the ability to memorize a path which is
- // different from the real path of the file. This is usefull if you want to have PclTar
- // running in any directory, and memorize relative path from an other directory.
- // Parameters :
- // $p_list : An array containing the file or directory names to add in the tar
- // $p_result_list : list of added files with their properties (specially the status field)
- // $p_add_dir : Path to add in the filename path archived
- // $p_remove_dir : Path to remove in the filename path archived
- // Return Values :
- // --------------------------------------------------------------------------------
-// function privAddList($p_list, &$p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, &$p_options)
- function privAddList($p_filedescr_list, &$p_result_list, &$p_options)
- {
- $v_result=1;
-
- // ----- Add the files
- $v_header_list = array();
- if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)
- {
- // ----- Return
- return $v_result;
- }
-
- // ----- Store the offset of the central dir
- $v_offset = @ftell($this->zip_fd);
-
- // ----- Create the Central Dir files header
- for ($i=0, $v_count=0; $iprivWriteCentralFileHeader($v_header_list[$i])) != 1) {
- // ----- Return
- return $v_result;
- }
- $v_count++;
- }
-
- // ----- Transform the header to a 'usable' info
- $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
- }
-
- // ----- Zip file comment
- $v_comment = '';
- if (isset($p_options[PCLZIP_OPT_COMMENT])) {
- $v_comment = $p_options[PCLZIP_OPT_COMMENT];
- }
-
- // ----- Calculate the size of the central header
- $v_size = @ftell($this->zip_fd)-$v_offset;
-
- // ----- Create the central dir footer
- if (($v_result = $this->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment)) != 1)
- {
- // ----- Reset the file list
- unset($v_header_list);
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privAddFileList()
- // Description :
- // Parameters :
- // $p_filedescr_list : An array containing the file description
- // or directory names to add in the zip
- // $p_result_list : list of added files with their properties (specially the status field)
- // Return Values :
- // --------------------------------------------------------------------------------
- function privAddFileList($p_filedescr_list, &$p_result_list, &$p_options)
- {
- $v_result=1;
- $v_header = array();
-
- // ----- Recuperate the current number of elt in list
- $v_nb = sizeof($p_result_list);
-
- // ----- Loop on the files
- for ($j=0; ($jprivAddFile($p_filedescr_list[$j], $v_header,
- $p_options);
- if ($v_result != 1) {
- return $v_result;
- }
-
- // ----- Store the file infos
- $p_result_list[$v_nb++] = $v_header;
- }
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privAddFile()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privAddFile($p_filedescr, &$p_header, &$p_options)
- {
- $v_result=1;
-
- // ----- Working variable
- $p_filename = $p_filedescr['filename'];
-
- // TBC : Already done in the fileAtt check ... ?
- if ($p_filename == "") {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Look for a stored different filename
- /* TBC : Removed
- if (isset($p_filedescr['stored_filename'])) {
- $v_stored_filename = $p_filedescr['stored_filename'];
- }
- else {
- $v_stored_filename = $p_filedescr['stored_filename'];
- }
- */
-
- // ----- Set the file properties
- clearstatcache();
- $p_header['version'] = 20;
- $p_header['version_extracted'] = 10;
- $p_header['flag'] = 0;
- $p_header['compression'] = 0;
- $p_header['crc'] = 0;
- $p_header['compressed_size'] = 0;
- $p_header['filename_len'] = strlen($p_filename);
- $p_header['extra_len'] = 0;
- $p_header['disk'] = 0;
- $p_header['internal'] = 0;
- $p_header['offset'] = 0;
- $p_header['filename'] = $p_filename;
-// TBC : Removed $p_header['stored_filename'] = $v_stored_filename;
- $p_header['stored_filename'] = $p_filedescr['stored_filename'];
- $p_header['extra'] = '';
- $p_header['status'] = 'ok';
- $p_header['index'] = -1;
-
- // ----- Look for regular file
- if ($p_filedescr['type']=='file') {
- $p_header['external'] = 0x00000000;
- $p_header['size'] = filesize($p_filename);
- }
-
- // ----- Look for regular folder
- else if ($p_filedescr['type']=='folder') {
- $p_header['external'] = 0x00000010;
- $p_header['mtime'] = filemtime($p_filename);
- $p_header['size'] = filesize($p_filename);
- }
-
- // ----- Look for virtual file
- else if ($p_filedescr['type'] == 'virtual_file') {
- $p_header['external'] = 0x00000000;
- $p_header['size'] = strlen($p_filedescr['content']);
- }
-
-
- // ----- Look for filetime
- if (isset($p_filedescr['mtime'])) {
- $p_header['mtime'] = $p_filedescr['mtime'];
- }
- else if ($p_filedescr['type'] == 'virtual_file') {
- $p_header['mtime'] = time();
- }
- else {
- $p_header['mtime'] = filemtime($p_filename);
- }
-
- // ------ Look for file comment
- if (isset($p_filedescr['comment'])) {
- $p_header['comment_len'] = strlen($p_filedescr['comment']);
- $p_header['comment'] = $p_filedescr['comment'];
- }
- else {
- $p_header['comment_len'] = 0;
- $p_header['comment'] = '';
- }
-
- // ----- Look for pre-add callback
- if (isset($p_options[PCLZIP_CB_PRE_ADD])) {
-
- // ----- Generate a local information
- $v_local_header = array();
- $this->privConvertHeader2FileInfo($p_header, $v_local_header);
-
- // ----- Call the callback
- // Here I do not use call_user_func() because I need to send a reference to the
- // header.
-// eval('$v_result = '.$p_options[PCLZIP_CB_PRE_ADD].'(PCLZIP_CB_PRE_ADD, $v_local_header);');
- $v_result = $p_options[PCLZIP_CB_PRE_ADD](PCLZIP_CB_PRE_ADD, $v_local_header);
- if ($v_result == 0) {
- // ----- Change the file status
- $p_header['status'] = "skipped";
- $v_result = 1;
- }
-
- // ----- Update the informations
- // Only some fields can be modified
- if ($p_header['stored_filename'] != $v_local_header['stored_filename']) {
- $p_header['stored_filename'] = PclZipUtilPathReduction($v_local_header['stored_filename']);
- }
- }
-
- // ----- Look for empty stored filename
- if ($p_header['stored_filename'] == "") {
- $p_header['status'] = "filtered";
- }
-
- // ----- Check the path length
- if (strlen($p_header['stored_filename']) > 0xFF) {
- $p_header['status'] = 'filename_too_long';
- }
-
- // ----- Look if no error, or file not skipped
- if ($p_header['status'] == 'ok') {
-
- // ----- Look for a file
- if ($p_filedescr['type'] == 'file') {
- // ----- Look for using temporary file to zip
- if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF]))
- && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON])
- || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
- && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_header['size'])) ) ) {
- $v_result = $this->privAddFileUsingTempFile($p_filedescr, $p_header, $p_options);
- if ($v_result < PCLZIP_ERR_NO_ERROR) {
- return $v_result;
- }
- }
-
- // ----- Use "in memory" zip algo
- else {
-
- // ----- Open the source file
- if (($v_file = @fopen($p_filename, "rb")) == 0) {
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
- return PclZip::errorCode();
- }
-
- // ----- Read the file content
- $v_content = @fread($v_file, $p_header['size']);
-
- // ----- Close the file
- @fclose($v_file);
-
- // ----- Calculate the CRC
- $p_header['crc'] = @crc32($v_content);
-
- // ----- Look for no compression
- if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
- // ----- Set header parameters
- $p_header['compressed_size'] = $p_header['size'];
- $p_header['compression'] = 0;
- }
-
- // ----- Look for normal compression
- else {
- // ----- Compress the content
- $v_content = @gzdeflate($v_content);
-
- // ----- Set header parameters
- $p_header['compressed_size'] = strlen($v_content);
- $p_header['compression'] = 8;
- }
-
- // ----- Call the header generation
- if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
- @fclose($v_file);
- return $v_result;
- }
-
- // ----- Write the compressed (or not) content
- @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);
-
- }
-
- }
-
- // ----- Look for a virtual file (a file from string)
- else if ($p_filedescr['type'] == 'virtual_file') {
-
- $v_content = $p_filedescr['content'];
-
- // ----- Calculate the CRC
- $p_header['crc'] = @crc32($v_content);
-
- // ----- Look for no compression
- if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
- // ----- Set header parameters
- $p_header['compressed_size'] = $p_header['size'];
- $p_header['compression'] = 0;
- }
-
- // ----- Look for normal compression
- else {
- // ----- Compress the content
- $v_content = @gzdeflate($v_content);
-
- // ----- Set header parameters
- $p_header['compressed_size'] = strlen($v_content);
- $p_header['compression'] = 8;
- }
-
- // ----- Call the header generation
- if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
- @fclose($v_file);
- return $v_result;
- }
-
- // ----- Write the compressed (or not) content
- @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);
- }
-
- // ----- Look for a directory
- else if ($p_filedescr['type'] == 'folder') {
- // ----- Look for directory last '/'
- if (@substr($p_header['stored_filename'], -1) != '/') {
- $p_header['stored_filename'] .= '/';
- }
-
- // ----- Set the file properties
- $p_header['size'] = 0;
- //$p_header['external'] = 0x41FF0010; // Value for a folder : to be checked
- $p_header['external'] = 0x00000010; // Value for a folder : to be checked
-
- // ----- Call the header generation
- if (($v_result = $this->privWriteFileHeader($p_header)) != 1)
- {
- return $v_result;
- }
- }
- }
-
- // ----- Look for post-add callback
- if (isset($p_options[PCLZIP_CB_POST_ADD])) {
-
- // ----- Generate a local information
- $v_local_header = array();
- $this->privConvertHeader2FileInfo($p_header, $v_local_header);
-
- // ----- Call the callback
- // Here I do not use call_user_func() because I need to send a reference to the
- // header.
-// eval('$v_result = '.$p_options[PCLZIP_CB_POST_ADD].'(PCLZIP_CB_POST_ADD, $v_local_header);');
- $v_result = $p_options[PCLZIP_CB_POST_ADD](PCLZIP_CB_POST_ADD, $v_local_header);
- if ($v_result == 0) {
- // ----- Ignored
- $v_result = 1;
- }
-
- // ----- Update the informations
- // Nothing can be modified
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privAddFileUsingTempFile()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privAddFileUsingTempFile($p_filedescr, &$p_header, &$p_options)
- {
- $v_result=PCLZIP_ERR_NO_ERROR;
-
- // ----- Working variable
- $p_filename = $p_filedescr['filename'];
-
-
- // ----- Open the source file
- if (($v_file = @fopen($p_filename, "rb")) == 0) {
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
- return PclZip::errorCode();
- }
-
- // ----- Creates a compressed temporary file
- $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz';
- if (($v_file_compressed = @gzopen($v_gzip_temp_name, "wb")) == 0) {
- fclose($v_file);
- PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode');
- return PclZip::errorCode();
- }
-
- // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
- $v_size = filesize($p_filename);
- while ($v_size != 0) {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @fread($v_file, $v_read_size);
- //$v_binary_data = pack('a'.$v_read_size, $v_buffer);
- @gzputs($v_file_compressed, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
-
- // ----- Close the file
- @fclose($v_file);
- @gzclose($v_file_compressed);
-
- // ----- Check the minimum file size
- if (filesize($v_gzip_temp_name) < 18) {
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'gzip temporary file \''.$v_gzip_temp_name.'\' has invalid filesize - should be minimum 18 bytes');
- return PclZip::errorCode();
- }
-
- // ----- Extract the compressed attributes
- if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) {
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
- return PclZip::errorCode();
- }
-
- // ----- Read the gzip file header
- $v_binary_data = @fread($v_file_compressed, 10);
- $v_data_header = unpack('a1id1/a1id2/a1cm/a1flag/Vmtime/a1xfl/a1os', $v_binary_data);
-
- // ----- Check some parameters
- $v_data_header['os'] = bin2hex($v_data_header['os']);
-
- // ----- Read the gzip file footer
- @fseek($v_file_compressed, filesize($v_gzip_temp_name)-8);
- $v_binary_data = @fread($v_file_compressed, 8);
- $v_data_footer = unpack('Vcrc/Vcompressed_size', $v_binary_data);
-
- // ----- Set the attributes
- $p_header['compression'] = ord($v_data_header['cm']);
- //$p_header['mtime'] = $v_data_header['mtime'];
- $p_header['crc'] = $v_data_footer['crc'];
- $p_header['compressed_size'] = filesize($v_gzip_temp_name)-18;
-
- // ----- Close the file
- @fclose($v_file_compressed);
-
- // ----- Call the header generation
- if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
- return $v_result;
- }
-
- // ----- Add the compressed data
- if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0)
- {
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
- return PclZip::errorCode();
- }
-
- // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
- fseek($v_file_compressed, 10);
- $v_size = $p_header['compressed_size'];
- while ($v_size != 0)
- {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @fread($v_file_compressed, $v_read_size);
- //$v_binary_data = pack('a'.$v_read_size, $v_buffer);
- @fwrite($this->zip_fd, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
-
- // ----- Close the file
- @fclose($v_file_compressed);
-
- // ----- Unlink the temporary file
- @unlink($v_gzip_temp_name);
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privCalculateStoredFilename()
- // Description :
- // Based on file descriptor properties and global options, this method
- // calculate the filename that will be stored in the archive.
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privCalculateStoredFilename(&$p_filedescr, &$p_options)
- {
- $v_result=1;
-
- // ----- Working variables
- $p_filename = $p_filedescr['filename'];
- if (isset($p_options[PCLZIP_OPT_ADD_PATH])) {
- $p_add_dir = $p_options[PCLZIP_OPT_ADD_PATH];
- }
- else {
- $p_add_dir = '';
- }
- if (isset($p_options[PCLZIP_OPT_REMOVE_PATH])) {
- $p_remove_dir = $p_options[PCLZIP_OPT_REMOVE_PATH];
- }
- else {
- $p_remove_dir = '';
- }
- if (isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
- $p_remove_all_dir = $p_options[PCLZIP_OPT_REMOVE_ALL_PATH];
- }
- else {
- $p_remove_all_dir = 0;
- }
-
-
- // ----- Look for full name change
- if (isset($p_filedescr['new_full_name'])) {
- // ----- Remove drive letter if any
- $v_stored_filename = PclZipUtilTranslateWinPath($p_filedescr['new_full_name']);
- }
-
- // ----- Look for path and/or short name change
- else {
-
- // ----- Look for short name change
- // Its when we cahnge just the filename but not the path
- if (isset($p_filedescr['new_short_name'])) {
- $v_path_info = pathinfo($p_filename);
- $v_dir = '';
- if ($v_path_info['dirname'] != '') {
- $v_dir = $v_path_info['dirname'].'/';
- }
- $v_stored_filename = $v_dir.$p_filedescr['new_short_name'];
- }
- else {
- // ----- Calculate the stored filename
- $v_stored_filename = $p_filename;
- }
-
- // ----- Look for all path to remove
- if ($p_remove_all_dir) {
- $v_stored_filename = basename($p_filename);
- }
- // ----- Look for partial path remove
- else if ($p_remove_dir != "") {
- if (substr($p_remove_dir, -1) != '/')
- $p_remove_dir .= "/";
-
- if ( (substr($p_filename, 0, 2) == "./")
- || (substr($p_remove_dir, 0, 2) == "./")) {
-
- if ( (substr($p_filename, 0, 2) == "./")
- && (substr($p_remove_dir, 0, 2) != "./")) {
- $p_remove_dir = "./".$p_remove_dir;
- }
- if ( (substr($p_filename, 0, 2) != "./")
- && (substr($p_remove_dir, 0, 2) == "./")) {
- $p_remove_dir = substr($p_remove_dir, 2);
- }
- }
-
- $v_compare = PclZipUtilPathInclusion($p_remove_dir,
- $v_stored_filename);
- if ($v_compare > 0) {
- if ($v_compare == 2) {
- $v_stored_filename = "";
- }
- else {
- $v_stored_filename = substr($v_stored_filename,
- strlen($p_remove_dir));
- }
- }
- }
-
- // ----- Remove drive letter if any
- $v_stored_filename = PclZipUtilTranslateWinPath($v_stored_filename);
-
- // ----- Look for path to add
- if ($p_add_dir != "") {
- if (substr($p_add_dir, -1) == "/")
- $v_stored_filename = $p_add_dir.$v_stored_filename;
- else
- $v_stored_filename = $p_add_dir."/".$v_stored_filename;
- }
- }
-
- // ----- Filename (reduce the path of stored name)
- $v_stored_filename = PclZipUtilPathReduction($v_stored_filename);
- $p_filedescr['stored_filename'] = $v_stored_filename;
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privWriteFileHeader()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privWriteFileHeader(&$p_header)
- {
- $v_result=1;
-
- // ----- Store the offset position of the file
- $p_header['offset'] = ftell($this->zip_fd);
-
- // ----- Transform UNIX mtime to DOS format mdate/mtime
- $v_date = getdate($p_header['mtime']);
- $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;
- $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];
-
- // ----- Packed data
- $v_binary_data = pack("VvvvvvVVVvv", 0x04034b50,
- $p_header['version_extracted'], $p_header['flag'],
- $p_header['compression'], $v_mtime, $v_mdate,
- $p_header['crc'], $p_header['compressed_size'],
- $p_header['size'],
- strlen($p_header['stored_filename']),
- $p_header['extra_len']);
-
- // ----- Write the first 148 bytes of the header in the archive
- fputs($this->zip_fd, $v_binary_data, 30);
-
- // ----- Write the variable fields
- if (strlen($p_header['stored_filename']) != 0)
- {
- fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
- }
- if ($p_header['extra_len'] != 0)
- {
- fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privWriteCentralFileHeader()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privWriteCentralFileHeader(&$p_header)
- {
- $v_result=1;
-
- // TBC
- //for(reset($p_header); $key = key($p_header); next($p_header)) {
- //}
-
- // ----- Transform UNIX mtime to DOS format mdate/mtime
- $v_date = getdate($p_header['mtime']);
- $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;
- $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];
-
-
- // ----- Packed data
- $v_binary_data = pack("VvvvvvvVVVvvvvvVV", 0x02014b50,
- $p_header['version'], $p_header['version_extracted'],
- $p_header['flag'], $p_header['compression'],
- $v_mtime, $v_mdate, $p_header['crc'],
- $p_header['compressed_size'], $p_header['size'],
- strlen($p_header['stored_filename']),
- $p_header['extra_len'], $p_header['comment_len'],
- $p_header['disk'], $p_header['internal'],
- $p_header['external'], $p_header['offset']);
-
- // ----- Write the 42 bytes of the header in the zip file
- fputs($this->zip_fd, $v_binary_data, 46);
-
- // ----- Write the variable fields
- if (strlen($p_header['stored_filename']) != 0)
- {
- fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
- }
- if ($p_header['extra_len'] != 0)
- {
- fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
- }
- if ($p_header['comment_len'] != 0)
- {
- fputs($this->zip_fd, $p_header['comment'], $p_header['comment_len']);
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privWriteCentralHeader()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privWriteCentralHeader($p_nb_entries, $p_size, $p_offset, $p_comment)
- {
- $v_result=1;
-
- // ----- Packed data
- $v_binary_data = pack("VvvvvVVv", 0x06054b50, 0, 0, $p_nb_entries,
- $p_nb_entries, $p_size,
- $p_offset, strlen($p_comment));
-
- // ----- Write the 22 bytes of the header in the zip file
- fputs($this->zip_fd, $v_binary_data, 22);
-
- // ----- Write the variable fields
- if (strlen($p_comment) != 0)
- {
- fputs($this->zip_fd, $p_comment, strlen($p_comment));
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privList()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privList(&$p_list)
- {
- $v_result=1;
-
- // ----- Magic quotes trick
- $this->privDisableMagicQuotes();
-
- // ----- Open the zip file
- if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
- {
- // ----- Magic quotes trick
- $this->privSwapBackMagicQuotes();
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Read the central directory informations
- $v_central_dir = array();
- if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
- {
- $this->privSwapBackMagicQuotes();
- return $v_result;
- }
-
- // ----- Go to beginning of Central Dir
- @rewind($this->zip_fd);
- if (@fseek($this->zip_fd, $v_central_dir['offset']))
- {
- $this->privSwapBackMagicQuotes();
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Read each entry
- for ($i=0; $i<$v_central_dir['entries']; $i++)
- {
- // ----- Read the file header
- if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)
- {
- $this->privSwapBackMagicQuotes();
- return $v_result;
- }
- $v_header['index'] = $i;
-
- // ----- Get the only interesting attributes
- $this->privConvertHeader2FileInfo($v_header, $p_list[$i]);
- unset($v_header);
- }
-
- // ----- Close the zip file
- $this->privCloseFd();
-
- // ----- Magic quotes trick
- $this->privSwapBackMagicQuotes();
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privConvertHeader2FileInfo()
- // Description :
- // This function takes the file informations from the central directory
- // entries and extract the interesting parameters that will be given back.
- // The resulting file infos are set in the array $p_info
- // $p_info['filename'] : Filename with full path. Given by user (add),
- // extracted in the filesystem (extract).
- // $p_info['stored_filename'] : Stored filename in the archive.
- // $p_info['size'] = Size of the file.
- // $p_info['compressed_size'] = Compressed size of the file.
- // $p_info['mtime'] = Last modification date of the file.
- // $p_info['comment'] = Comment associated with the file.
- // $p_info['folder'] = true/false : indicates if the entry is a folder or not.
- // $p_info['status'] = status of the action on the file.
- // $p_info['crc'] = CRC of the file content.
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privConvertHeader2FileInfo($p_header, &$p_info)
- {
- $v_result=1;
-
- // ----- Get the interesting attributes
- $v_temp_path = PclZipUtilPathReduction($p_header['filename']);
- $p_info['filename'] = $v_temp_path;
- $v_temp_path = PclZipUtilPathReduction($p_header['stored_filename']);
- $p_info['stored_filename'] = $v_temp_path;
- $p_info['size'] = $p_header['size'];
- $p_info['compressed_size'] = $p_header['compressed_size'];
- $p_info['mtime'] = $p_header['mtime'];
- $p_info['comment'] = $p_header['comment'];
- $p_info['folder'] = (($p_header['external']&0x00000010)==0x00000010);
- $p_info['index'] = $p_header['index'];
- $p_info['status'] = $p_header['status'];
- $p_info['crc'] = $p_header['crc'];
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privExtractByRule()
- // Description :
- // Extract a file or directory depending of rules (by index, by name, ...)
- // Parameters :
- // $p_file_list : An array where will be placed the properties of each
- // extracted file
- // $p_path : Path to add while writing the extracted files
- // $p_remove_path : Path to remove (from the file memorized path) while writing the
- // extracted files. If the path does not match the file path,
- // the file is extracted with its memorized path.
- // $p_remove_path does not apply to 'list' mode.
- // $p_path and $p_remove_path are commulative.
- // Return Values :
- // 1 on success,0 or less on error (see error code list)
- // --------------------------------------------------------------------------------
- function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
- {
- $v_result=1;
-
- // ----- Magic quotes trick
- $this->privDisableMagicQuotes();
-
- // ----- Check the path
- if ( ($p_path == "")
- || ( (substr($p_path, 0, 1) != "/")
- && (substr($p_path, 0, 3) != "../")
- && (substr($p_path,1,2)!=":/")))
- $p_path = "./".$p_path;
-
- // ----- Reduce the path last (and duplicated) '/'
- if (($p_path != "./") && ($p_path != "/"))
- {
- // ----- Look for the path end '/'
- while (substr($p_path, -1) == "/")
- {
- $p_path = substr($p_path, 0, strlen($p_path)-1);
- }
- }
-
- // ----- Look for path to remove format (should end by /)
- if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/'))
- {
- $p_remove_path .= '/';
- }
- $p_remove_path_size = strlen($p_remove_path);
-
- // ----- Open the zip file
- if (($v_result = $this->privOpenFd('rb')) != 1)
- {
- $this->privSwapBackMagicQuotes();
- return $v_result;
- }
-
- // ----- Read the central directory informations
- $v_central_dir = array();
- if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
- {
- // ----- Close the zip file
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
-
- return $v_result;
- }
-
- // ----- Start at beginning of Central Dir
- $v_pos_entry = $v_central_dir['offset'];
-
- // ----- Read each entry
- $j_start = 0;
- for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)
- {
-
- // ----- Read next Central dir entry
- @rewind($this->zip_fd);
- if (@fseek($this->zip_fd, $v_pos_entry))
- {
- // ----- Close the zip file
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Read the file header
- $v_header = array();
- if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)
- {
- // ----- Close the zip file
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
-
- return $v_result;
- }
-
- // ----- Store the index
- $v_header['index'] = $i;
-
- // ----- Store the file position
- $v_pos_entry = ftell($this->zip_fd);
-
- // ----- Look for the specific extract rules
- $v_extract = false;
-
- // ----- Look for extract by name rule
- if ( (isset($p_options[PCLZIP_OPT_BY_NAME]))
- && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
-
- // ----- Look if the filename is in the list
- for ($j=0; ($j strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))
- && (substr($v_header['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
- $v_extract = true;
- }
- }
- // ----- Look for a filename
- elseif ($v_header['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
- $v_extract = true;
- }
- }
- }
-
- // ----- Look for extract by ereg rule
- // ereg() is deprecated with PHP 5.3
- /*
- else if ( (isset($p_options[PCLZIP_OPT_BY_EREG]))
- && ($p_options[PCLZIP_OPT_BY_EREG] != "")) {
-
- if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header['stored_filename'])) {
- $v_extract = true;
- }
- }
- */
-
- // ----- Look for extract by preg rule
- else if ( (isset($p_options[PCLZIP_OPT_BY_PREG]))
- && ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
-
- if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) {
- $v_extract = true;
- }
- }
-
- // ----- Look for extract by index rule
- else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX]))
- && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
-
- // ----- Look if the index is in the list
- for ($j=$j_start; ($j=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
- $v_extract = true;
- }
- if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
- $j_start = $j+1;
- }
-
- if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {
- break;
- }
- }
- }
-
- // ----- Look for no rule, which means extract all the archive
- else {
- $v_extract = true;
- }
-
- // ----- Check compression method
- if ( ($v_extract)
- && ( ($v_header['compression'] != 8)
- && ($v_header['compression'] != 0))) {
- $v_header['status'] = 'unsupported_compression';
-
- // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
- if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
- && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
-
- $this->privSwapBackMagicQuotes();
-
- PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION,
- "Filename '".$v_header['stored_filename']."' is "
- ."compressed by an unsupported compression "
- ."method (".$v_header['compression'].") ");
-
- return PclZip::errorCode();
- }
- }
-
- // ----- Check encrypted files
- if (($v_extract) && (($v_header['flag'] & 1) == 1)) {
- $v_header['status'] = 'unsupported_encryption';
-
- // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
- if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
- && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
-
- $this->privSwapBackMagicQuotes();
-
- PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION,
- "Unsupported encryption for "
- ." filename '".$v_header['stored_filename']
- ."'");
-
- return PclZip::errorCode();
- }
- }
-
- // ----- Look for real extraction
- if (($v_extract) && ($v_header['status'] != 'ok')) {
- $v_result = $this->privConvertHeader2FileInfo($v_header,
- $p_file_list[$v_nb_extracted++]);
- if ($v_result != 1) {
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
- return $v_result;
- }
-
- $v_extract = false;
- }
-
- // ----- Look for real extraction
- if ($v_extract)
- {
-
- // ----- Go to the file position
- @rewind($this->zip_fd);
- if (@fseek($this->zip_fd, $v_header['offset']))
- {
- // ----- Close the zip file
- $this->privCloseFd();
-
- $this->privSwapBackMagicQuotes();
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Look for extraction as string
- if ($p_options[PCLZIP_OPT_EXTRACT_AS_STRING]) {
-
- $v_string = '';
-
- // ----- Extracting the file
- $v_result1 = $this->privExtractFileAsString($v_header, $v_string, $p_options);
- if ($v_result1 < 1) {
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
- return $v_result1;
- }
-
- // ----- Get the only interesting attributes
- if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted])) != 1)
- {
- // ----- Close the zip file
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
-
- return $v_result;
- }
-
- // ----- Set the file content
- $p_file_list[$v_nb_extracted]['content'] = $v_string;
-
- // ----- Next extracted file
- $v_nb_extracted++;
-
- // ----- Look for user callback abort
- if ($v_result1 == 2) {
- break;
- }
- }
- // ----- Look for extraction in standard output
- elseif ( (isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT]))
- && ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) {
- // ----- Extracting the file in standard output
- $v_result1 = $this->privExtractFileInOutput($v_header, $p_options);
- if ($v_result1 < 1) {
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
- return $v_result1;
- }
-
- // ----- Get the only interesting attributes
- if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) {
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
- return $v_result;
- }
-
- // ----- Look for user callback abort
- if ($v_result1 == 2) {
- break;
- }
- }
- // ----- Look for normal extraction
- else {
- // ----- Extracting the file
- $v_result1 = $this->privExtractFile($v_header,
- $p_path, $p_remove_path,
- $p_remove_all_path,
- $p_options);
- if ($v_result1 < 1) {
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
- return $v_result1;
- }
-
- // ----- Get the only interesting attributes
- if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1)
- {
- // ----- Close the zip file
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
-
- return $v_result;
- }
-
- // ----- Look for user callback abort
- if ($v_result1 == 2) {
- break;
- }
- }
- }
- }
-
- // ----- Close the zip file
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privExtractFile()
- // Description :
- // Parameters :
- // Return Values :
- //
- // 1 : ... ?
- // PCLZIP_ERR_USER_ABORTED(2) : User ask for extraction stop in callback
- // --------------------------------------------------------------------------------
- function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
- {
- $v_result=1;
-
- // ----- Read the file header
- if (($v_result = $this->privReadFileHeader($v_header)) != 1)
- {
- // ----- Return
- return $v_result;
- }
-
-
- // ----- Check that the file header is coherent with $p_entry info
- if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
- // TBC
- }
-
- // ----- Look for all path to remove
- if ($p_remove_all_path == true) {
- // ----- Look for folder entry that not need to be extracted
- if (($p_entry['external']&0x00000010)==0x00000010) {
-
- $p_entry['status'] = "filtered";
-
- return $v_result;
- }
-
- // ----- Get the basename of the path
- $p_entry['filename'] = basename($p_entry['filename']);
- }
-
- // ----- Look for path to remove
- else if ($p_remove_path != "")
- {
- if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2)
- {
-
- // ----- Change the file status
- $p_entry['status'] = "filtered";
-
- // ----- Return
- return $v_result;
- }
-
- $p_remove_path_size = strlen($p_remove_path);
- if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path)
- {
-
- // ----- Remove the path
- $p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size);
-
- }
- }
-
- // ----- Add the path
- if ($p_path != '') {
- $p_entry['filename'] = $p_path."/".$p_entry['filename'];
- }
-
- // ----- Check a base_dir_restriction
- if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) {
- $v_inclusion
- = PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION],
- $p_entry['filename']);
- if ($v_inclusion == 0) {
-
- PclZip::privErrorLog(PCLZIP_ERR_DIRECTORY_RESTRICTION,
- "Filename '".$p_entry['filename']."' is "
- ."outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION");
-
- return PclZip::errorCode();
- }
- }
-
- // ----- Look for pre-extract callback
- if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
-
- // ----- Generate a local information
- $v_local_header = array();
- $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
-
- // ----- Call the callback
- // Here I do not use call_user_func() because I need to send a reference to the
- // header.
-// eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
- $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
- if ($v_result == 0) {
- // ----- Change the file status
- $p_entry['status'] = "skipped";
- $v_result = 1;
- }
-
- // ----- Look for abort result
- if ($v_result == 2) {
- // ----- This status is internal and will be changed in 'skipped'
- $p_entry['status'] = "aborted";
- $v_result = PCLZIP_ERR_USER_ABORTED;
- }
-
- // ----- Update the informations
- // Only some fields can be modified
- $p_entry['filename'] = $v_local_header['filename'];
- }
-
-
- // ----- Look if extraction should be done
- if ($p_entry['status'] == 'ok') {
-
- // ----- Look for specific actions while the file exist
- if (file_exists($p_entry['filename']))
- {
-
- // ----- Look if file is a directory
- if (is_dir($p_entry['filename']))
- {
-
- // ----- Change the file status
- $p_entry['status'] = "already_a_directory";
-
- // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
- // For historical reason first PclZip implementation does not stop
- // when this kind of error occurs.
- if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
- && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
-
- PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY,
- "Filename '".$p_entry['filename']."' is "
- ."already used by an existing directory");
-
- return PclZip::errorCode();
- }
- }
- // ----- Look if file is write protected
- else if (!is_writeable($p_entry['filename']))
- {
-
- // ----- Change the file status
- $p_entry['status'] = "write_protected";
-
- // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
- // For historical reason first PclZip implementation does not stop
- // when this kind of error occurs.
- if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
- && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
-
- PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL,
- "Filename '".$p_entry['filename']."' exists "
- ."and is write protected");
-
- return PclZip::errorCode();
- }
- }
-
- // ----- Look if the extracted file is older
- else if (filemtime($p_entry['filename']) > $p_entry['mtime'])
- {
- // ----- Change the file status
- if ( (isset($p_options[PCLZIP_OPT_REPLACE_NEWER]))
- && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) {
- }
- else {
- $p_entry['status'] = "newer_exist";
-
- // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
- // For historical reason first PclZip implementation does not stop
- // when this kind of error occurs.
- if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
- && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
-
- PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL,
- "Newer version of '".$p_entry['filename']."' exists "
- ."and option PCLZIP_OPT_REPLACE_NEWER is not selected");
-
- return PclZip::errorCode();
- }
- }
- }
- else {
- }
- }
-
- // ----- Check the directory availability and create it if necessary
- else {
- if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/'))
- $v_dir_to_check = $p_entry['filename'];
- else if (!strstr($p_entry['filename'], "/"))
- $v_dir_to_check = "";
- else
- $v_dir_to_check = dirname($p_entry['filename']);
-
- if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) {
-
- // ----- Change the file status
- $p_entry['status'] = "path_creation_fail";
-
- // ----- Return
- //return $v_result;
- $v_result = 1;
- }
- }
- }
-
- // ----- Look if extraction should be done
- if ($p_entry['status'] == 'ok') {
-
- // ----- Do the extraction (if not a folder)
- if (!(($p_entry['external']&0x00000010)==0x00000010))
- {
- // ----- Look for not compressed file
- if ($p_entry['compression'] == 0) {
-
- // ----- Opening destination file
- if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0)
- {
-
- // ----- Change the file status
- $p_entry['status'] = "write_error";
-
- // ----- Return
- return $v_result;
- }
-
-
- // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
- $v_size = $p_entry['compressed_size'];
- while ($v_size != 0)
- {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @fread($this->zip_fd, $v_read_size);
- /* Try to speed up the code
- $v_binary_data = pack('a'.$v_read_size, $v_buffer);
- @fwrite($v_dest_file, $v_binary_data, $v_read_size);
- */
- @fwrite($v_dest_file, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
-
- // ----- Closing the destination file
- fclose($v_dest_file);
-
- // ----- Change the file mtime
- touch($p_entry['filename'], $p_entry['mtime']);
-
-
- }
- else {
- // ----- TBC
- // Need to be finished
- if (($p_entry['flag'] & 1) == 1) {
- PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, 'File \''.$p_entry['filename'].'\' is encrypted. Encrypted files are not supported.');
- return PclZip::errorCode();
- }
-
-
- // ----- Look for using temporary file to unzip
- if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF]))
- && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON])
- || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
- && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_entry['size'])) ) ) {
- $v_result = $this->privExtractFileUsingTempFile($p_entry, $p_options);
- if ($v_result < PCLZIP_ERR_NO_ERROR) {
- return $v_result;
- }
- }
-
- // ----- Look for extract in memory
- else {
-
-
- // ----- Read the compressed file in a buffer (one shot)
- $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
-
- // ----- Decompress the file
- $v_file_content = @gzinflate($v_buffer);
- unset($v_buffer);
- if ($v_file_content === FALSE) {
-
- // ----- Change the file status
- // TBC
- $p_entry['status'] = "error";
-
- return $v_result;
- }
-
- // ----- Opening destination file
- if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
-
- // ----- Change the file status
- $p_entry['status'] = "write_error";
-
- return $v_result;
- }
-
- // ----- Write the uncompressed data
- @fwrite($v_dest_file, $v_file_content, $p_entry['size']);
- unset($v_file_content);
-
- // ----- Closing the destination file
- @fclose($v_dest_file);
-
- }
-
- // ----- Change the file mtime
- @touch($p_entry['filename'], $p_entry['mtime']);
- }
-
- // ----- Look for chmod option
- if (isset($p_options[PCLZIP_OPT_SET_CHMOD])) {
-
- // ----- Change the mode of the file
- @chmod($p_entry['filename'], $p_options[PCLZIP_OPT_SET_CHMOD]);
- }
-
- }
- }
-
- // ----- Change abort status
- if ($p_entry['status'] == "aborted") {
- $p_entry['status'] = "skipped";
- }
-
- // ----- Look for post-extract callback
- elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
-
- // ----- Generate a local information
- $v_local_header = array();
- $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
-
- // ----- Call the callback
- // Here I do not use call_user_func() because I need to send a reference to the
- // header.
-// eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
- $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
-
- // ----- Look for abort result
- if ($v_result == 2) {
- $v_result = PCLZIP_ERR_USER_ABORTED;
- }
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privExtractFileUsingTempFile()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privExtractFileUsingTempFile(&$p_entry, &$p_options)
- {
- $v_result=1;
-
- // ----- Creates a temporary file
- $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz';
- if (($v_dest_file = @fopen($v_gzip_temp_name, "wb")) == 0) {
- fclose($v_file);
- PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode');
- return PclZip::errorCode();
- }
-
-
- // ----- Write gz file format header
- $v_binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($p_entry['compression']), Chr(0x00), time(), Chr(0x00), Chr(3));
- @fwrite($v_dest_file, $v_binary_data, 10);
-
- // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
- $v_size = $p_entry['compressed_size'];
- while ($v_size != 0)
- {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @fread($this->zip_fd, $v_read_size);
- //$v_binary_data = pack('a'.$v_read_size, $v_buffer);
- @fwrite($v_dest_file, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
-
- // ----- Write gz file format footer
- $v_binary_data = pack('VV', $p_entry['crc'], $p_entry['size']);
- @fwrite($v_dest_file, $v_binary_data, 8);
-
- // ----- Close the temporary file
- @fclose($v_dest_file);
-
- // ----- Opening destination file
- if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
- $p_entry['status'] = "write_error";
- return $v_result;
- }
-
- // ----- Open the temporary gz file
- if (($v_src_file = @gzopen($v_gzip_temp_name, 'rb')) == 0) {
- @fclose($v_dest_file);
- $p_entry['status'] = "read_error";
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
- return PclZip::errorCode();
- }
-
-
- // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
- $v_size = $p_entry['size'];
- while ($v_size != 0) {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @gzread($v_src_file, $v_read_size);
- //$v_binary_data = pack('a'.$v_read_size, $v_buffer);
- @fwrite($v_dest_file, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
- @fclose($v_dest_file);
- @gzclose($v_src_file);
-
- // ----- Delete the temporary file
- @unlink($v_gzip_temp_name);
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privExtractFileInOutput()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privExtractFileInOutput(&$p_entry, &$p_options)
- {
- $v_result=1;
-
- // ----- Read the file header
- if (($v_result = $this->privReadFileHeader($v_header)) != 1) {
- return $v_result;
- }
-
-
- // ----- Check that the file header is coherent with $p_entry info
- if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
- // TBC
- }
-
- // ----- Look for pre-extract callback
- if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
-
- // ----- Generate a local information
- $v_local_header = array();
- $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
-
- // ----- Call the callback
- // Here I do not use call_user_func() because I need to send a reference to the
- // header.
-// eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
- $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
- if ($v_result == 0) {
- // ----- Change the file status
- $p_entry['status'] = "skipped";
- $v_result = 1;
- }
-
- // ----- Look for abort result
- if ($v_result == 2) {
- // ----- This status is internal and will be changed in 'skipped'
- $p_entry['status'] = "aborted";
- $v_result = PCLZIP_ERR_USER_ABORTED;
- }
-
- // ----- Update the informations
- // Only some fields can be modified
- $p_entry['filename'] = $v_local_header['filename'];
- }
-
- // ----- Trace
-
- // ----- Look if extraction should be done
- if ($p_entry['status'] == 'ok') {
-
- // ----- Do the extraction (if not a folder)
- if (!(($p_entry['external']&0x00000010)==0x00000010)) {
- // ----- Look for not compressed file
- if ($p_entry['compressed_size'] == $p_entry['size']) {
-
- // ----- Read the file in a buffer (one shot)
- $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
-
- // ----- Send the file to the output
- echo $v_buffer;
- unset($v_buffer);
- }
- else {
-
- // ----- Read the compressed file in a buffer (one shot)
- $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
-
- // ----- Decompress the file
- $v_file_content = gzinflate($v_buffer);
- unset($v_buffer);
-
- // ----- Send the file to the output
- echo $v_file_content;
- unset($v_file_content);
- }
- }
- }
-
- // ----- Change abort status
- if ($p_entry['status'] == "aborted") {
- $p_entry['status'] = "skipped";
- }
-
- // ----- Look for post-extract callback
- elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
-
- // ----- Generate a local information
- $v_local_header = array();
- $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
-
- // ----- Call the callback
- // Here I do not use call_user_func() because I need to send a reference to the
- // header.
-// eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
- $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
-
- // ----- Look for abort result
- if ($v_result == 2) {
- $v_result = PCLZIP_ERR_USER_ABORTED;
- }
- }
-
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privExtractFileAsString()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privExtractFileAsString(&$p_entry, &$p_string, &$p_options)
- {
- $v_result=1;
-
- // ----- Read the file header
- $v_header = array();
- if (($v_result = $this->privReadFileHeader($v_header)) != 1)
- {
- // ----- Return
- return $v_result;
- }
-
-
- // ----- Check that the file header is coherent with $p_entry info
- if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
- // TBC
- }
-
- // ----- Look for pre-extract callback
- if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
-
- // ----- Generate a local information
- $v_local_header = array();
- $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
-
- // ----- Call the callback
- // Here I do not use call_user_func() because I need to send a reference to the
- // header.
-// eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
- $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
- if ($v_result == 0) {
- // ----- Change the file status
- $p_entry['status'] = "skipped";
- $v_result = 1;
- }
-
- // ----- Look for abort result
- if ($v_result == 2) {
- // ----- This status is internal and will be changed in 'skipped'
- $p_entry['status'] = "aborted";
- $v_result = PCLZIP_ERR_USER_ABORTED;
- }
-
- // ----- Update the informations
- // Only some fields can be modified
- $p_entry['filename'] = $v_local_header['filename'];
- }
-
-
- // ----- Look if extraction should be done
- if ($p_entry['status'] == 'ok') {
-
- // ----- Do the extraction (if not a folder)
- if (!(($p_entry['external']&0x00000010)==0x00000010)) {
- // ----- Look for not compressed file
- // if ($p_entry['compressed_size'] == $p_entry['size'])
- if ($p_entry['compression'] == 0) {
-
- // ----- Reading the file
- $p_string = @fread($this->zip_fd, $p_entry['compressed_size']);
- }
- else {
-
- // ----- Reading the file
- $v_data = @fread($this->zip_fd, $p_entry['compressed_size']);
-
- // ----- Decompress the file
- if (($p_string = @gzinflate($v_data)) === FALSE) {
- // TBC
- }
- }
-
- // ----- Trace
- }
- else {
- // TBC : error : can not extract a folder in a string
- }
-
- }
-
- // ----- Change abort status
- if ($p_entry['status'] == "aborted") {
- $p_entry['status'] = "skipped";
- }
-
- // ----- Look for post-extract callback
- elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
-
- // ----- Generate a local information
- $v_local_header = array();
- $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
-
- // ----- Swap the content to header
- $v_local_header['content'] = $p_string;
- $p_string = '';
-
- // ----- Call the callback
- // Here I do not use call_user_func() because I need to send a reference to the
- // header.
-// eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
- $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
-
- // ----- Swap back the content to header
- $p_string = $v_local_header['content'];
- unset($v_local_header['content']);
-
- // ----- Look for abort result
- if ($v_result == 2) {
- $v_result = PCLZIP_ERR_USER_ABORTED;
- }
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privReadFileHeader()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privReadFileHeader(&$p_header)
- {
- $v_result=1;
-
- // ----- Read the 4 bytes signature
- $v_binary_data = @fread($this->zip_fd, 4);
- $v_data = unpack('Vid', $v_binary_data);
-
- // ----- Check signature
- if ($v_data['id'] != 0x04034b50)
- {
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Read the first 42 bytes of the header
- $v_binary_data = fread($this->zip_fd, 26);
-
- // ----- Look for invalid block size
- if (strlen($v_binary_data) != 26)
- {
- $p_header['filename'] = "";
- $p_header['status'] = "invalid_header";
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Extract the values
- $v_data = unpack('vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $v_binary_data);
-
- // ----- Get filename
- $p_header['filename'] = fread($this->zip_fd, $v_data['filename_len']);
-
- // ----- Get extra_fields
- if ($v_data['extra_len'] != 0) {
- $p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']);
- }
- else {
- $p_header['extra'] = '';
- }
-
- // ----- Extract properties
- $p_header['version_extracted'] = $v_data['version'];
- $p_header['compression'] = $v_data['compression'];
- $p_header['size'] = $v_data['size'];
- $p_header['compressed_size'] = $v_data['compressed_size'];
- $p_header['crc'] = $v_data['crc'];
- $p_header['flag'] = $v_data['flag'];
- $p_header['filename_len'] = $v_data['filename_len'];
-
- // ----- Recuperate date in UNIX format
- $p_header['mdate'] = $v_data['mdate'];
- $p_header['mtime'] = $v_data['mtime'];
- if ($p_header['mdate'] && $p_header['mtime'])
- {
- // ----- Extract time
- $v_hour = ($p_header['mtime'] & 0xF800) >> 11;
- $v_minute = ($p_header['mtime'] & 0x07E0) >> 5;
- $v_seconde = ($p_header['mtime'] & 0x001F)*2;
-
- // ----- Extract date
- $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;
- $v_month = ($p_header['mdate'] & 0x01E0) >> 5;
- $v_day = $p_header['mdate'] & 0x001F;
-
- // ----- Get UNIX date format
- $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
-
- }
- else
- {
- $p_header['mtime'] = time();
- }
-
- // TBC
- //for(reset($v_data); $key = key($v_data); next($v_data)) {
- //}
-
- // ----- Set the stored filename
- $p_header['stored_filename'] = $p_header['filename'];
-
- // ----- Set the status field
- $p_header['status'] = "ok";
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privReadCentralFileHeader()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privReadCentralFileHeader(&$p_header)
- {
- $v_result=1;
-
- // ----- Read the 4 bytes signature
- $v_binary_data = @fread($this->zip_fd, 4);
- $v_data = unpack('Vid', $v_binary_data);
-
- // ----- Check signature
- if ($v_data['id'] != 0x02014b50)
- {
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Read the first 42 bytes of the header
- $v_binary_data = fread($this->zip_fd, 42);
-
- // ----- Look for invalid block size
- if (strlen($v_binary_data) != 42)
- {
- $p_header['filename'] = "";
- $p_header['status'] = "invalid_header";
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Extract the values
- $p_header = unpack('vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $v_binary_data);
-
- // ----- Get filename
- if ($p_header['filename_len'] != 0)
- $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']);
- else
- $p_header['filename'] = '';
-
- // ----- Get extra
- if ($p_header['extra_len'] != 0)
- $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']);
- else
- $p_header['extra'] = '';
-
- // ----- Get comment
- if ($p_header['comment_len'] != 0)
- $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']);
- else
- $p_header['comment'] = '';
-
- // ----- Extract properties
-
- // ----- Recuperate date in UNIX format
- //if ($p_header['mdate'] && $p_header['mtime'])
- // TBC : bug : this was ignoring time with 0/0/0
- if (1)
- {
- // ----- Extract time
- $v_hour = ($p_header['mtime'] & 0xF800) >> 11;
- $v_minute = ($p_header['mtime'] & 0x07E0) >> 5;
- $v_seconde = ($p_header['mtime'] & 0x001F)*2;
-
- // ----- Extract date
- $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;
- $v_month = ($p_header['mdate'] & 0x01E0) >> 5;
- $v_day = $p_header['mdate'] & 0x001F;
-
- // ----- Get UNIX date format
- $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
-
- }
- else
- {
- $p_header['mtime'] = time();
- }
-
- // ----- Set the stored filename
- $p_header['stored_filename'] = $p_header['filename'];
-
- // ----- Set default status to ok
- $p_header['status'] = 'ok';
-
- // ----- Look if it is a directory
- if (substr($p_header['filename'], -1) == '/') {
- //$p_header['external'] = 0x41FF0010;
- $p_header['external'] = 0x00000010;
- }
-
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privCheckFileHeaders()
- // Description :
- // Parameters :
- // Return Values :
- // 1 on success,
- // 0 on error;
- // --------------------------------------------------------------------------------
- function privCheckFileHeaders(&$p_local_header, &$p_central_header)
- {
- $v_result=1;
-
- // ----- Check the static values
- // TBC
- if ($p_local_header['filename'] != $p_central_header['filename']) {
- }
- if ($p_local_header['version_extracted'] != $p_central_header['version_extracted']) {
- }
- if ($p_local_header['flag'] != $p_central_header['flag']) {
- }
- if ($p_local_header['compression'] != $p_central_header['compression']) {
- }
- if ($p_local_header['mtime'] != $p_central_header['mtime']) {
- }
- if ($p_local_header['filename_len'] != $p_central_header['filename_len']) {
- }
-
- // ----- Look for flag bit 3
- if (($p_local_header['flag'] & 8) == 8) {
- $p_local_header['size'] = $p_central_header['size'];
- $p_local_header['compressed_size'] = $p_central_header['compressed_size'];
- $p_local_header['crc'] = $p_central_header['crc'];
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privReadEndCentralDir()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privReadEndCentralDir(&$p_central_dir)
- {
- $v_result=1;
-
- // ----- Go to the end of the zip file
- $v_size = filesize($this->zipname);
- @fseek($this->zip_fd, $v_size);
- if (@ftell($this->zip_fd) != $v_size)
- {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\'');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- First try : look if this is an archive with no commentaries (most of the time)
- // in this case the end of central dir is at 22 bytes of the file end
- $v_found = 0;
- if ($v_size > 26) {
- @fseek($this->zip_fd, $v_size-22);
- if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22))
- {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Read for bytes
- $v_binary_data = @fread($this->zip_fd, 4);
- $v_data = @unpack('Vid', $v_binary_data);
-
- // ----- Check signature
- if ($v_data['id'] == 0x06054b50) {
- $v_found = 1;
- }
-
- $v_pos = ftell($this->zip_fd);
- }
-
- // ----- Go back to the maximum possible size of the Central Dir End Record
- if (!$v_found) {
- $v_maximum_size = 65557; // 0xFFFF + 22;
- if ($v_maximum_size > $v_size)
- $v_maximum_size = $v_size;
- @fseek($this->zip_fd, $v_size-$v_maximum_size);
- if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size))
- {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Read byte per byte in order to find the signature
- $v_pos = ftell($this->zip_fd);
- $v_bytes = 0x00000000;
- while ($v_pos < $v_size)
- {
- // ----- Read a byte
- $v_byte = @fread($this->zip_fd, 1);
-
- // ----- Add the byte
- //$v_bytes = ($v_bytes << 8) | Ord($v_byte);
- // Note we mask the old value down such that once shifted we can never end up with more than a 32bit number
- // Otherwise on systems where we have 64bit integers the check below for the magic number will fail.
- $v_bytes = ( ($v_bytes & 0xFFFFFF) << 8) | Ord($v_byte);
-
- // ----- Compare the bytes
- if ($v_bytes == 0x504b0506)
- {
- $v_pos++;
- break;
- }
-
- $v_pos++;
- }
-
- // ----- Look if not found end of central dir
- if ($v_pos == $v_size)
- {
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Unable to find End of Central Dir Record signature");
-
- // ----- Return
- return PclZip::errorCode();
- }
- }
-
- // ----- Read the first 18 bytes of the header
- $v_binary_data = fread($this->zip_fd, 18);
-
- // ----- Look for invalid block size
- if (strlen($v_binary_data) != 18)
- {
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data));
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Extract the values
- $v_data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', $v_binary_data);
-
- // ----- Check the global size
- if (($v_pos + $v_data['comment_size'] + 18) != $v_size) {
-
- // ----- Removed in release 2.2 see readme file
- // The check of the file size is a little too strict.
- // Some bugs where found when a zip is encrypted/decrypted with 'crypt'.
- // While decrypted, zip has training 0 bytes
- if (0) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT,
- 'The central dir is not at the end of the archive.'
- .' Some trailing bytes exists after the archive.');
-
- // ----- Return
- return PclZip::errorCode();
- }
- }
-
- // ----- Get comment
- if ($v_data['comment_size'] != 0) {
- $p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']);
- }
- else
- $p_central_dir['comment'] = '';
-
- $p_central_dir['entries'] = $v_data['entries'];
- $p_central_dir['disk_entries'] = $v_data['disk_entries'];
- $p_central_dir['offset'] = $v_data['offset'];
- $p_central_dir['size'] = $v_data['size'];
- $p_central_dir['disk'] = $v_data['disk'];
- $p_central_dir['disk_start'] = $v_data['disk_start'];
-
- // TBC
- //for(reset($p_central_dir); $key = key($p_central_dir); next($p_central_dir)) {
- //}
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privDeleteByRule()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privDeleteByRule(&$p_result_list, &$p_options)
- {
- $v_result=1;
- $v_list_detail = array();
-
- // ----- Open the zip file
- if (($v_result=$this->privOpenFd('rb')) != 1)
- {
- // ----- Return
- return $v_result;
- }
-
- // ----- Read the central directory informations
- $v_central_dir = array();
- if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
- {
- $this->privCloseFd();
- return $v_result;
- }
-
- // ----- Go to beginning of File
- @rewind($this->zip_fd);
-
- // ----- Scan all the files
- // ----- Start at beginning of Central Dir
- $v_pos_entry = $v_central_dir['offset'];
- @rewind($this->zip_fd);
- if (@fseek($this->zip_fd, $v_pos_entry))
- {
- // ----- Close the zip file
- $this->privCloseFd();
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Read each entry
- $v_header_list = array();
- $j_start = 0;
- for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)
- {
-
- // ----- Read the file header
- $v_header_list[$v_nb_extracted] = array();
- if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1)
- {
- // ----- Close the zip file
- $this->privCloseFd();
-
- return $v_result;
- }
-
-
- // ----- Store the index
- $v_header_list[$v_nb_extracted]['index'] = $i;
-
- // ----- Look for the specific extract rules
- $v_found = false;
-
- // ----- Look for extract by name rule
- if ( (isset($p_options[PCLZIP_OPT_BY_NAME]))
- && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
-
- // ----- Look if the filename is in the list
- for ($j=0; ($j strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))
- && (substr($v_header_list[$v_nb_extracted]['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
- $v_found = true;
- }
- elseif ( (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */
- && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
- $v_found = true;
- }
- }
- // ----- Look for a filename
- elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
- $v_found = true;
- }
- }
- }
-
- // ----- Look for extract by ereg rule
- // ereg() is deprecated with PHP 5.3
- /*
- else if ( (isset($p_options[PCLZIP_OPT_BY_EREG]))
- && ($p_options[PCLZIP_OPT_BY_EREG] != "")) {
-
- if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
- $v_found = true;
- }
- }
- */
-
- // ----- Look for extract by preg rule
- else if ( (isset($p_options[PCLZIP_OPT_BY_PREG]))
- && ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
-
- if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
- $v_found = true;
- }
- }
-
- // ----- Look for extract by index rule
- else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX]))
- && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
-
- // ----- Look if the index is in the list
- for ($j=$j_start; ($j=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
- $v_found = true;
- }
- if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
- $j_start = $j+1;
- }
-
- if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {
- break;
- }
- }
- }
- else {
- $v_found = true;
- }
-
- // ----- Look for deletion
- if ($v_found)
- {
- unset($v_header_list[$v_nb_extracted]);
- }
- else
- {
- $v_nb_extracted++;
- }
- }
-
- // ----- Look if something need to be deleted
- if ($v_nb_extracted > 0) {
-
- // ----- Creates a temporay file
- $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
-
- // ----- Creates a temporary zip archive
- $v_temp_zip = new PclZip($v_zip_temp_name);
-
- // ----- Open the temporary zip file in write mode
- if (($v_result = $v_temp_zip->privOpenFd('wb')) != 1) {
- $this->privCloseFd();
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Look which file need to be kept
- for ($i=0; $izip_fd);
- if (@fseek($this->zip_fd, $v_header_list[$i]['offset'])) {
- // ----- Close the zip file
- $this->privCloseFd();
- $v_temp_zip->privCloseFd();
- @unlink($v_zip_temp_name);
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Read the file header
- $v_local_header = array();
- if (($v_result = $this->privReadFileHeader($v_local_header)) != 1) {
- // ----- Close the zip file
- $this->privCloseFd();
- $v_temp_zip->privCloseFd();
- @unlink($v_zip_temp_name);
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Check that local file header is same as central file header
- if ($this->privCheckFileHeaders($v_local_header,
- $v_header_list[$i]) != 1) {
- // TBC
- }
- unset($v_local_header);
-
- // ----- Write the file header
- if (($v_result = $v_temp_zip->privWriteFileHeader($v_header_list[$i])) != 1) {
- // ----- Close the zip file
- $this->privCloseFd();
- $v_temp_zip->privCloseFd();
- @unlink($v_zip_temp_name);
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Read/write the data block
- if (($v_result = PclZipUtilCopyBlock($this->zip_fd, $v_temp_zip->zip_fd, $v_header_list[$i]['compressed_size'])) != 1) {
- // ----- Close the zip file
- $this->privCloseFd();
- $v_temp_zip->privCloseFd();
- @unlink($v_zip_temp_name);
-
- // ----- Return
- return $v_result;
- }
- }
-
- // ----- Store the offset of the central dir
- $v_offset = @ftell($v_temp_zip->zip_fd);
-
- // ----- Re-Create the Central Dir files header
- for ($i=0; $iprivWriteCentralFileHeader($v_header_list[$i])) != 1) {
- $v_temp_zip->privCloseFd();
- $this->privCloseFd();
- @unlink($v_zip_temp_name);
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Transform the header to a 'usable' info
- $v_temp_zip->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
- }
-
-
- // ----- Zip file comment
- $v_comment = '';
- if (isset($p_options[PCLZIP_OPT_COMMENT])) {
- $v_comment = $p_options[PCLZIP_OPT_COMMENT];
- }
-
- // ----- Calculate the size of the central header
- $v_size = @ftell($v_temp_zip->zip_fd)-$v_offset;
-
- // ----- Create the central dir footer
- if (($v_result = $v_temp_zip->privWriteCentralHeader(sizeof($v_header_list), $v_size, $v_offset, $v_comment)) != 1) {
- // ----- Reset the file list
- unset($v_header_list);
- $v_temp_zip->privCloseFd();
- $this->privCloseFd();
- @unlink($v_zip_temp_name);
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Close
- $v_temp_zip->privCloseFd();
- $this->privCloseFd();
-
- // ----- Delete the zip file
- // TBC : I should test the result ...
- @unlink($this->zipname);
-
- // ----- Rename the temporary file
- // TBC : I should test the result ...
- //@rename($v_zip_temp_name, $this->zipname);
- PclZipUtilRename($v_zip_temp_name, $this->zipname);
-
- // ----- Destroy the temporary archive
- unset($v_temp_zip);
- }
-
- // ----- Remove every files : reset the file
- else if ($v_central_dir['entries'] != 0) {
- $this->privCloseFd();
-
- if (($v_result = $this->privOpenFd('wb')) != 1) {
- return $v_result;
- }
-
- if (($v_result = $this->privWriteCentralHeader(0, 0, 0, '')) != 1) {
- return $v_result;
- }
-
- $this->privCloseFd();
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privDirCheck()
- // Description :
- // Check if a directory exists, if not it creates it and all the parents directory
- // which may be useful.
- // Parameters :
- // $p_dir : Directory path to check.
- // Return Values :
- // 1 : OK
- // -1 : Unable to create directory
- // --------------------------------------------------------------------------------
- function privDirCheck($p_dir, $p_is_dir=false)
- {
- $v_result = 1;
-
-
- // ----- Remove the final '/'
- if (($p_is_dir) && (substr($p_dir, -1)=='/'))
- {
- $p_dir = substr($p_dir, 0, strlen($p_dir)-1);
- }
-
- // ----- Check the directory availability
- if ((is_dir($p_dir)) || ($p_dir == ""))
- {
- return 1;
- }
-
- // ----- Extract parent directory
- $p_parent_dir = dirname($p_dir);
-
- // ----- Just a check
- if ($p_parent_dir != $p_dir)
- {
- // ----- Look for parent directory
- if ($p_parent_dir != "")
- {
- if (($v_result = $this->privDirCheck($p_parent_dir)) != 1)
- {
- return $v_result;
- }
- }
- }
-
- // ----- Create the directory
- if (!@mkdir($p_dir, 0777))
- {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL, "Unable to create directory '$p_dir'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privMerge()
- // Description :
- // If $p_archive_to_add does not exist, the function exit with a success result.
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privMerge(&$p_archive_to_add)
- {
- $v_result=1;
-
- // ----- Look if the archive_to_add exists
- if (!is_file($p_archive_to_add->zipname))
- {
-
- // ----- Nothing to merge, so merge is a success
- $v_result = 1;
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Look if the archive exists
- if (!is_file($this->zipname))
- {
-
- // ----- Do a duplicate
- $v_result = $this->privDuplicate($p_archive_to_add->zipname);
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Open the zip file
- if (($v_result=$this->privOpenFd('rb')) != 1)
- {
- // ----- Return
- return $v_result;
- }
-
- // ----- Read the central directory informations
- $v_central_dir = array();
- if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
- {
- $this->privCloseFd();
- return $v_result;
- }
-
- // ----- Go to beginning of File
- @rewind($this->zip_fd);
-
- // ----- Open the archive_to_add file
- if (($v_result=$p_archive_to_add->privOpenFd('rb')) != 1)
- {
- $this->privCloseFd();
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Read the central directory informations
- $v_central_dir_to_add = array();
- if (($v_result = $p_archive_to_add->privReadEndCentralDir($v_central_dir_to_add)) != 1)
- {
- $this->privCloseFd();
- $p_archive_to_add->privCloseFd();
-
- return $v_result;
- }
-
- // ----- Go to beginning of File
- @rewind($p_archive_to_add->zip_fd);
-
- // ----- Creates a temporay file
- $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
-
- // ----- Open the temporary file in write mode
- if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
- {
- $this->privCloseFd();
- $p_archive_to_add->privCloseFd();
-
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Copy the files from the archive to the temporary file
- // TBC : Here I should better append the file and go back to erase the central dir
- $v_size = $v_central_dir['offset'];
- while ($v_size != 0)
- {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = fread($this->zip_fd, $v_read_size);
- @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
-
- // ----- Copy the files from the archive_to_add into the temporary file
- $v_size = $v_central_dir_to_add['offset'];
- while ($v_size != 0)
- {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = fread($p_archive_to_add->zip_fd, $v_read_size);
- @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
-
- // ----- Store the offset of the central dir
- $v_offset = @ftell($v_zip_temp_fd);
-
- // ----- Copy the block of file headers from the old archive
- $v_size = $v_central_dir['size'];
- while ($v_size != 0)
- {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @fread($this->zip_fd, $v_read_size);
- @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
-
- // ----- Copy the block of file headers from the archive_to_add
- $v_size = $v_central_dir_to_add['size'];
- while ($v_size != 0)
- {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @fread($p_archive_to_add->zip_fd, $v_read_size);
- @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
-
- // ----- Merge the file comments
- $v_comment = $v_central_dir['comment'].' '.$v_central_dir_to_add['comment'];
-
- // ----- Calculate the size of the (new) central header
- $v_size = @ftell($v_zip_temp_fd)-$v_offset;
-
- // ----- Swap the file descriptor
- // Here is a trick : I swap the temporary fd with the zip fd, in order to use
- // the following methods on the temporary fil and not the real archive fd
- $v_swap = $this->zip_fd;
- $this->zip_fd = $v_zip_temp_fd;
- $v_zip_temp_fd = $v_swap;
-
- // ----- Create the central dir footer
- if (($v_result = $this->privWriteCentralHeader($v_central_dir['entries']+$v_central_dir_to_add['entries'], $v_size, $v_offset, $v_comment)) != 1)
- {
- $this->privCloseFd();
- $p_archive_to_add->privCloseFd();
- @fclose($v_zip_temp_fd);
- $this->zip_fd = null;
-
- // ----- Reset the file list
- unset($v_header_list);
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Swap back the file descriptor
- $v_swap = $this->zip_fd;
- $this->zip_fd = $v_zip_temp_fd;
- $v_zip_temp_fd = $v_swap;
-
- // ----- Close
- $this->privCloseFd();
- $p_archive_to_add->privCloseFd();
-
- // ----- Close the temporary file
- @fclose($v_zip_temp_fd);
-
- // ----- Delete the zip file
- // TBC : I should test the result ...
- @unlink($this->zipname);
-
- // ----- Rename the temporary file
- // TBC : I should test the result ...
- //@rename($v_zip_temp_name, $this->zipname);
- PclZipUtilRename($v_zip_temp_name, $this->zipname);
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privDuplicate()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privDuplicate($p_archive_filename)
- {
- $v_result=1;
-
- // ----- Look if the $p_archive_filename exists
- if (!is_file($p_archive_filename))
- {
-
- // ----- Nothing to duplicate, so duplicate is a success.
- $v_result = 1;
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Open the zip file
- if (($v_result=$this->privOpenFd('wb')) != 1)
- {
- // ----- Return
- return $v_result;
- }
-
- // ----- Open the temporary file in write mode
- if (($v_zip_temp_fd = @fopen($p_archive_filename, 'rb')) == 0)
- {
- $this->privCloseFd();
-
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive file \''.$p_archive_filename.'\' in binary write mode');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Copy the files from the archive to the temporary file
- // TBC : Here I should better append the file and go back to erase the central dir
- $v_size = filesize($p_archive_filename);
- while ($v_size != 0)
- {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = fread($v_zip_temp_fd, $v_read_size);
- @fwrite($this->zip_fd, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
-
- // ----- Close
- $this->privCloseFd();
-
- // ----- Close the temporary file
- @fclose($v_zip_temp_fd);
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privErrorLog()
- // Description :
- // Parameters :
- // --------------------------------------------------------------------------------
- function privErrorLog($p_error_code=0, $p_error_string='')
- {
- if (PCLZIP_ERROR_EXTERNAL == 1) {
- PclError($p_error_code, $p_error_string);
- }
- else {
- $this->error_code = $p_error_code;
- $this->error_string = $p_error_string;
- }
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privErrorReset()
- // Description :
- // Parameters :
- // --------------------------------------------------------------------------------
- function privErrorReset()
- {
- if (PCLZIP_ERROR_EXTERNAL == 1) {
- PclErrorReset();
- }
- else {
- $this->error_code = 0;
- $this->error_string = '';
- }
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privDisableMagicQuotes()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privDisableMagicQuotes()
- {
- $v_result=1;
-
- // ----- Look if function exists
- if ( (!function_exists("get_magic_quotes_runtime"))
- || (!function_exists("set_magic_quotes_runtime"))) {
- return $v_result;
- }
-
- // ----- Look if already done
- if ($this->magic_quotes_status != -1) {
- return $v_result;
- }
-
- // ----- Get and memorize the magic_quote value
- $this->magic_quotes_status = @get_magic_quotes_runtime();
-
- // ----- Disable magic_quotes
- if ($this->magic_quotes_status == 1) {
- @set_magic_quotes_runtime(0);
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privSwapBackMagicQuotes()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privSwapBackMagicQuotes()
- {
- $v_result=1;
-
- // ----- Look if function exists
- if ( (!function_exists("get_magic_quotes_runtime"))
- || (!function_exists("set_magic_quotes_runtime"))) {
- return $v_result;
- }
-
- // ----- Look if something to do
- if ($this->magic_quotes_status != -1) {
- return $v_result;
- }
-
- // ----- Swap back magic_quotes
- if ($this->magic_quotes_status == 1) {
- @set_magic_quotes_runtime($this->magic_quotes_status);
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- }
- // End of class
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclZipUtilPathReduction()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function PclZipUtilPathReduction($p_dir)
- {
- $v_result = "";
-
- // ----- Look for not empty path
- if ($p_dir != "") {
- // ----- Explode path by directory names
- $v_list = explode("/", $p_dir);
-
- // ----- Study directories from last to first
- $v_skip = 0;
- for ($i=sizeof($v_list)-1; $i>=0; $i--) {
- // ----- Look for current path
- if ($v_list[$i] == ".") {
- // ----- Ignore this directory
- // Should be the first $i=0, but no check is done
- }
- else if ($v_list[$i] == "..") {
- $v_skip++;
- }
- else if ($v_list[$i] == "") {
- // ----- First '/' i.e. root slash
- if ($i == 0) {
- $v_result = "/".$v_result;
- if ($v_skip > 0) {
- // ----- It is an invalid path, so the path is not modified
- // TBC
- $v_result = $p_dir;
- $v_skip = 0;
- }
- }
- // ----- Last '/' i.e. indicates a directory
- else if ($i == (sizeof($v_list)-1)) {
- $v_result = $v_list[$i];
- }
- // ----- Double '/' inside the path
- else {
- // ----- Ignore only the double '//' in path,
- // but not the first and last '/'
- }
- }
- else {
- // ----- Look for item to skip
- if ($v_skip > 0) {
- $v_skip--;
- }
- else {
- $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:"");
- }
- }
- }
-
- // ----- Look for skip
- if ($v_skip > 0) {
- while ($v_skip > 0) {
- $v_result = '../'.$v_result;
- $v_skip--;
- }
- }
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclZipUtilPathInclusion()
- // Description :
- // This function indicates if the path $p_path is under the $p_dir tree. Or,
- // said in an other way, if the file or sub-dir $p_path is inside the dir
- // $p_dir.
- // The function indicates also if the path is exactly the same as the dir.
- // This function supports path with duplicated '/' like '//', but does not
- // support '.' or '..' statements.
- // Parameters :
- // Return Values :
- // 0 if $p_path is not inside directory $p_dir
- // 1 if $p_path is inside directory $p_dir
- // 2 if $p_path is exactly the same as $p_dir
- // --------------------------------------------------------------------------------
- function PclZipUtilPathInclusion($p_dir, $p_path)
- {
- $v_result = 1;
-
- // ----- Look for path beginning by ./
- if ( ($p_dir == '.')
- || ((strlen($p_dir) >=2) && (substr($p_dir, 0, 2) == './'))) {
- $p_dir = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_dir, 1);
- }
- if ( ($p_path == '.')
- || ((strlen($p_path) >=2) && (substr($p_path, 0, 2) == './'))) {
- $p_path = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_path, 1);
- }
-
- // ----- Explode dir and path by directory separator
- $v_list_dir = explode("/", $p_dir);
- $v_list_dir_size = sizeof($v_list_dir);
- $v_list_path = explode("/", $p_path);
- $v_list_path_size = sizeof($v_list_path);
-
- // ----- Study directories paths
- $i = 0;
- $j = 0;
- while (($i < $v_list_dir_size) && ($j < $v_list_path_size) && ($v_result)) {
-
- // ----- Look for empty dir (path reduction)
- if ($v_list_dir[$i] == '') {
- $i++;
- continue;
- }
- if ($v_list_path[$j] == '') {
- $j++;
- continue;
- }
-
- // ----- Compare the items
- if (($v_list_dir[$i] != $v_list_path[$j]) && ($v_list_dir[$i] != '') && ( $v_list_path[$j] != '')) {
- $v_result = 0;
- }
-
- // ----- Next items
- $i++;
- $j++;
- }
-
- // ----- Look if everything seems to be the same
- if ($v_result) {
- // ----- Skip all the empty items
- while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) $j++;
- while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) $i++;
-
- if (($i >= $v_list_dir_size) && ($j >= $v_list_path_size)) {
- // ----- There are exactly the same
- $v_result = 2;
- }
- else if ($i < $v_list_dir_size) {
- // ----- The path is shorter than the dir
- $v_result = 0;
- }
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclZipUtilCopyBlock()
- // Description :
- // Parameters :
- // $p_mode : read/write compression mode
- // 0 : src & dest normal
- // 1 : src gzip, dest normal
- // 2 : src normal, dest gzip
- // 3 : src & dest gzip
- // Return Values :
- // --------------------------------------------------------------------------------
- function PclZipUtilCopyBlock($p_src, $p_dest, $p_size, $p_mode=0)
- {
- $v_result = 1;
-
- if ($p_mode==0)
- {
- while ($p_size != 0)
- {
- $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @fread($p_src, $v_read_size);
- @fwrite($p_dest, $v_buffer, $v_read_size);
- $p_size -= $v_read_size;
- }
- }
- else if ($p_mode==1)
- {
- while ($p_size != 0)
- {
- $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @gzread($p_src, $v_read_size);
- @fwrite($p_dest, $v_buffer, $v_read_size);
- $p_size -= $v_read_size;
- }
- }
- else if ($p_mode==2)
- {
- while ($p_size != 0)
- {
- $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @fread($p_src, $v_read_size);
- @gzwrite($p_dest, $v_buffer, $v_read_size);
- $p_size -= $v_read_size;
- }
- }
- else if ($p_mode==3)
- {
- while ($p_size != 0)
- {
- $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @gzread($p_src, $v_read_size);
- @gzwrite($p_dest, $v_buffer, $v_read_size);
- $p_size -= $v_read_size;
- }
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclZipUtilRename()
- // Description :
- // This function tries to do a simple rename() function. If it fails, it
- // tries to copy the $p_src file in a new $p_dest file and then unlink the
- // first one.
- // Parameters :
- // $p_src : Old filename
- // $p_dest : New filename
- // Return Values :
- // 1 on success, 0 on failure.
- // --------------------------------------------------------------------------------
- function PclZipUtilRename($p_src, $p_dest)
- {
- $v_result = 1;
-
- // ----- Try to rename the files
- if (!@rename($p_src, $p_dest)) {
-
- // ----- Try to copy & unlink the src
- if (!@copy($p_src, $p_dest)) {
- $v_result = 0;
- }
- else if (!@unlink($p_src)) {
- $v_result = 0;
- }
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclZipUtilOptionText()
- // Description :
- // Translate option value in text. Mainly for debug purpose.
- // Parameters :
- // $p_option : the option value.
- // Return Values :
- // The option text value.
- // --------------------------------------------------------------------------------
- function PclZipUtilOptionText($p_option)
- {
-
- $v_list = get_defined_constants();
- for (reset($v_list); $v_key = key($v_list); next($v_list)) {
- $v_prefix = substr($v_key, 0, 10);
- if (( ($v_prefix == 'PCLZIP_OPT')
- || ($v_prefix == 'PCLZIP_CB_')
- || ($v_prefix == 'PCLZIP_ATT'))
- && ($v_list[$v_key] == $p_option)) {
- return $v_key;
- }
- }
-
- $v_result = 'Unknown';
-
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclZipUtilTranslateWinPath()
- // Description :
- // Translate windows path by replacing '\' by '/' and optionally removing
- // drive letter.
- // Parameters :
- // $p_path : path to translate.
- // $p_remove_disk_letter : true | false
- // Return Values :
- // The path translated.
- // --------------------------------------------------------------------------------
- function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter=true)
- {
- if (stristr(php_uname(), 'windows')) {
- // ----- Look for potential disk letter
- if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) {
- $p_path = substr($p_path, $v_position+1);
- }
- // ----- Change potential windows directory separator
- if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) {
- $p_path = strtr($p_path, '\\', '/');
- }
- }
- return $p_path;
- }
- // --------------------------------------------------------------------------------
-
\ No newline at end of file
+zipname = $p_zipname;
+ $this->zip_fd = 0;
+ $this->magic_quotes_status = -1;
+
+ // ----- Return
+ return;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function :
+ // create($p_filelist, $p_add_dir="", $p_remove_dir="")
+ // create($p_filelist, $p_option, $p_option_value, ...)
+ // Description :
+ // This method supports two different synopsis. The first one is historical.
+ // This method creates a Zip Archive. The Zip file is created in the
+ // filesystem. The files and directories indicated in $p_filelist
+ // are added in the archive. See the parameters description for the
+ // supported format of $p_filelist.
+ // When a directory is in the list, the directory and its content is added
+ // in the archive.
+ // In this synopsis, the function takes an optional variable list of
+ // options. See bellow the supported options.
+ // Parameters :
+ // $p_filelist : An array containing file or directory names, or
+ // a string containing one filename or one directory name, or
+ // a string containing a list of filenames and/or directory
+ // names separated by spaces.
+ // $p_add_dir : A path to add before the real path of the archived file,
+ // in order to have it memorized in the archive.
+ // $p_remove_dir : A path to remove from the real path of the file to archive,
+ // in order to have a shorter path memorized in the archive.
+ // When $p_add_dir and $p_remove_dir are set, $p_remove_dir
+ // is removed first, before $p_add_dir is added.
+ // Options :
+ // PCLZIP_OPT_ADD_PATH :
+ // PCLZIP_OPT_REMOVE_PATH :
+ // PCLZIP_OPT_REMOVE_ALL_PATH :
+ // PCLZIP_OPT_COMMENT :
+ // PCLZIP_CB_PRE_ADD :
+ // PCLZIP_CB_POST_ADD :
+ // Return Values :
+ // 0 on failure,
+ // The list of the added files, with a status of the add action.
+ // (see PclZip::listContent() for list entry format)
+ // --------------------------------------------------------------------------------
+ function create($p_filelist)
+ {
+ $v_result=1;
+
+ // ----- Reset the error handler
+ $this->privErrorReset();
+
+ // ----- Set default values
+ $v_options = array();
+ $v_options[PCLZIP_OPT_NO_COMPRESSION] = false;
+
+ // ----- Look for variable options arguments
+ $v_size = func_num_args();
+
+ // ----- Look for arguments
+ if ($v_size > 1) {
+ // ----- Get the arguments
+ $v_arg_list = func_get_args();
+
+ // ----- Remove from the options list the first argument
+ array_shift($v_arg_list);
+ $v_size--;
+
+ // ----- Look for first arg
+ if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
+ // ----- Parse the options
+ $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, array (
+ PCLZIP_OPT_REMOVE_PATH => 'optional',
+ PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
+ PCLZIP_OPT_ADD_PATH => 'optional',
+ PCLZIP_CB_PRE_ADD => 'optional',
+ PCLZIP_CB_POST_ADD => 'optional',
+ PCLZIP_OPT_NO_COMPRESSION => 'optional',
+ PCLZIP_OPT_COMMENT => 'optional',
+ PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
+ PCLZIP_OPT_TEMP_FILE_ON => 'optional',
+ PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
+ //, PCLZIP_OPT_CRYPT => 'optional'
+ ));
+ if ($v_result != 1) {
+ return 0;
+ }
+ } else {
+ // ----- Look for 2 args
+ // Here we need to support the first historic synopsis of the
+ // method.
+ // ----- Get the first argument
+ $v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0];
+
+ // ----- Look for the optional second argument
+ if ($v_size == 2) {
+ $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
+ } else if ($v_size > 2) {
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
+ return 0;
+ }
+ }
+ }
+
+ // ----- Look for default option values
+ $this->privOptionDefaultThreshold($v_options);
+
+ // ----- Init
+ $v_string_list = array();
+ $v_att_list = array();
+ $v_filedescr_list = array();
+ $p_result_list = array();
+
+ // ----- Look if the $p_filelist is really an array
+ if (is_array($p_filelist)) {
+ // ----- Look if the first element is also an array
+ // This will mean that this is a file description entry
+ if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
+ $v_att_list = $p_filelist;
+ } else {
+ // ----- The list is a list of string names
+ $v_string_list = $p_filelist;
+ }
+ } else if (is_string($p_filelist)) {
+ // ----- Look if the $p_filelist is a string
+ // ----- Create a list from the string
+ $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
+ } else {
+ // ----- Invalid variable type for $p_filelist
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist");
+ return 0;
+ }
+
+ // ----- Reformat the string list
+ if (sizeof($v_string_list) != 0) {
+ foreach ($v_string_list as $v_string) {
+ if ($v_string != '') {
+ $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
+ } else {
+ }
+ }
+ }
+
+ // ----- For each file in the list check the attributes
+ $v_supported_attributes = array(
+ PCLZIP_ATT_FILE_NAME => 'mandatory',
+ PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional',
+ PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional',
+ PCLZIP_ATT_FILE_MTIME => 'optional',
+ PCLZIP_ATT_FILE_CONTENT => 'optional',
+ PCLZIP_ATT_FILE_COMMENT => 'optional'
+ );
+ foreach ($v_att_list as $v_entry) {
+ $v_result = $this->privFileDescrParseAtt($v_entry, $v_filedescr_list[], $v_options, $v_supported_attributes);
+ if ($v_result != 1) {
+ return 0;
+ }
+ }
+
+ // ----- Expand the filelist (expand directories)
+ $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
+ if ($v_result != 1) {
+ return 0;
+ }
+
+ // ----- Call the create fct
+ $v_result = $this->privCreate($v_filedescr_list, $p_result_list, $v_options);
+ if ($v_result != 1) {
+ return 0;
+ }
+
+ // ----- Return
+ return $p_result_list;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function :
+ // add($p_filelist, $p_add_dir="", $p_remove_dir="")
+ // add($p_filelist, $p_option, $p_option_value, ...)
+ // Description :
+ // This method supports two synopsis. The first one is historical.
+ // This methods add the list of files in an existing archive.
+ // If a file with the same name already exists, it is added at the end of the
+ // archive, the first one is still present.
+ // If the archive does not exist, it is created.
+ // Parameters :
+ // $p_filelist : An array containing file or directory names, or
+ // a string containing one filename or one directory name, or
+ // a string containing a list of filenames and/or directory
+ // names separated by spaces.
+ // $p_add_dir : A path to add before the real path of the archived file,
+ // in order to have it memorized in the archive.
+ // $p_remove_dir : A path to remove from the real path of the file to archive,
+ // in order to have a shorter path memorized in the archive.
+ // When $p_add_dir and $p_remove_dir are set, $p_remove_dir
+ // is removed first, before $p_add_dir is added.
+ // Options :
+ // PCLZIP_OPT_ADD_PATH :
+ // PCLZIP_OPT_REMOVE_PATH :
+ // PCLZIP_OPT_REMOVE_ALL_PATH :
+ // PCLZIP_OPT_COMMENT :
+ // PCLZIP_OPT_ADD_COMMENT :
+ // PCLZIP_OPT_PREPEND_COMMENT :
+ // PCLZIP_CB_PRE_ADD :
+ // PCLZIP_CB_POST_ADD :
+ // Return Values :
+ // 0 on failure,
+ // The list of the added files, with a status of the add action.
+ // (see PclZip::listContent() for list entry format)
+ // --------------------------------------------------------------------------------
+ function add($p_filelist)
+ {
+ $v_result=1;
+
+ // ----- Reset the error handler
+ $this->privErrorReset();
+
+ // ----- Set default values
+ $v_options = array();
+ $v_options[PCLZIP_OPT_NO_COMPRESSION] = false;
+
+ // ----- Look for variable options arguments
+ $v_size = func_num_args();
+
+ // ----- Look for arguments
+ if ($v_size > 1) {
+ // ----- Get the arguments
+ $v_arg_list = func_get_args();
+
+ // ----- Remove form the options list the first argument
+ array_shift($v_arg_list);
+ $v_size--;
+
+ // ----- Look for first arg
+ if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
+ // ----- Parse the options
+ $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, array (
+ PCLZIP_OPT_REMOVE_PATH => 'optional',
+ PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
+ PCLZIP_OPT_ADD_PATH => 'optional',
+ PCLZIP_CB_PRE_ADD => 'optional',
+ PCLZIP_CB_POST_ADD => 'optional',
+ PCLZIP_OPT_NO_COMPRESSION => 'optional',
+ PCLZIP_OPT_COMMENT => 'optional',
+ PCLZIP_OPT_ADD_COMMENT => 'optional',
+ PCLZIP_OPT_PREPEND_COMMENT => 'optional',
+ PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
+ PCLZIP_OPT_TEMP_FILE_ON => 'optional',
+ PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
+ //, PCLZIP_OPT_CRYPT => 'optional'
+ ));
+ if ($v_result != 1) {
+ return 0;
+ }
+ } else {
+ // ----- Look for 2 args
+ // Here we need to support the first historic synopsis of the
+ // method.
+ // ----- Get the first argument
+ $v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0];
+
+ // ----- Look for the optional second argument
+ if ($v_size == 2) {
+ $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
+ } else if ($v_size > 2) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
+
+ // ----- Return
+ return 0;
+ }
+ }
+ }
+
+ // ----- Look for default option values
+ $this->privOptionDefaultThreshold($v_options);
+
+ // ----- Init
+ $v_string_list = array();
+ $v_att_list = array();
+ $v_filedescr_list = array();
+ $p_result_list = array();
+
+ // ----- Look if the $p_filelist is really an array
+ if (is_array($p_filelist)) {
+ // ----- Look if the first element is also an array
+ // This will mean that this is a file description entry
+ if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
+ $v_att_list = $p_filelist;
+ } else {
+ // ----- The list is a list of string names
+ $v_string_list = $p_filelist;
+ }
+ } else if (is_string($p_filelist)) {
+ // ----- Look if the $p_filelist is a string
+ // ----- Create a list from the string
+ $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
+ } else {
+ // ----- Invalid variable type for $p_filelist
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist");
+ return 0;
+ }
+
+ // ----- Reformat the string list
+ if (sizeof($v_string_list) != 0) {
+ foreach ($v_string_list as $v_string) {
+ $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
+ }
+ }
+
+ // ----- For each file in the list check the attributes
+ $v_supported_attributes = array(
+ PCLZIP_ATT_FILE_NAME => 'mandatory',
+ PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional',
+ PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional',
+ PCLZIP_ATT_FILE_MTIME => 'optional',
+ PCLZIP_ATT_FILE_CONTENT => 'optional',
+ PCLZIP_ATT_FILE_COMMENT => 'optional',
+ );
+ foreach ($v_att_list as $v_entry) {
+ $v_result = $this->privFileDescrParseAtt($v_entry, $v_filedescr_list[], $v_options, $v_supported_attributes);
+ if ($v_result != 1) {
+ return 0;
+ }
+ }
+
+ // ----- Expand the filelist (expand directories)
+ $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
+ if ($v_result != 1) {
+ return 0;
+ }
+
+ // ----- Call the create fct
+ $v_result = $this->privAdd($v_filedescr_list, $p_result_list, $v_options);
+ if ($v_result != 1) {
+ return 0;
+ }
+
+ // ----- Return
+ return $p_result_list;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : listContent()
+ // Description :
+ // This public method, gives the list of the files and directories, with their
+ // properties.
+ // The properties of each entries in the list are (used also in other functions) :
+ // filename : Name of the file. For a create or add action it is the filename
+ // given by the user. For an extract function it is the filename
+ // of the extracted file.
+ // stored_filename : Name of the file / directory stored in the archive.
+ // size : Size of the stored file.
+ // compressed_size : Size of the file's data compressed in the archive
+ // (without the headers overhead)
+ // mtime : Last known modification date of the file (UNIX timestamp)
+ // comment : Comment associated with the file
+ // folder : true | false
+ // index : index of the file in the archive
+ // status : status of the action (depending of the action) :
+ // Values are :
+ // ok : OK !
+ // filtered : the file / dir is not extracted (filtered by user)
+ // already_a_directory : the file can not be extracted because a
+ // directory with the same name already exists
+ // write_protected : the file can not be extracted because a file
+ // with the same name already exists and is
+ // write protected
+ // newer_exist : the file was not extracted because a newer file exists
+ // path_creation_fail : the file is not extracted because the folder
+ // does not exist and can not be created
+ // write_error : the file was not extracted because there was a
+ // error while writing the file
+ // read_error : the file was not extracted because there was a error
+ // while reading the file
+ // invalid_header : the file was not extracted because of an archive
+ // format error (bad file header)
+ // Note that each time a method can continue operating when there
+ // is an action error on a file, the error is only logged in the file status.
+ // Return Values :
+ // 0 on an unrecoverable failure,
+ // The list of the files in the archive.
+ // --------------------------------------------------------------------------------
+ function listContent()
+ {
+ $v_result=1;
+
+ // ----- Reset the error handler
+ $this->privErrorReset();
+
+ // ----- Check archive
+ if (!$this->privCheckFormat()) {
+ return(0);
+ }
+
+ // ----- Call the extracting fct
+ $p_list = array();
+ if (($v_result = $this->privList($p_list)) != 1) {
+ unset($p_list);
+ return(0);
+ }
+
+ // ----- Return
+ return $p_list;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function :
+ // extract($p_path="./", $p_remove_path="")
+ // extract([$p_option, $p_option_value, ...])
+ // Description :
+ // This method supports two synopsis. The first one is historical.
+ // This method extract all the files / directories from the archive to the
+ // folder indicated in $p_path.
+ // If you want to ignore the 'root' part of path of the memorized files
+ // you can indicate this in the optional $p_remove_path parameter.
+ // By default, if a newer file with the same name already exists, the
+ // file is not extracted.
+ //
+ // If both PCLZIP_OPT_PATH and PCLZIP_OPT_ADD_PATH aoptions
+ // are used, the path indicated in PCLZIP_OPT_ADD_PATH is append
+ // at the end of the path value of PCLZIP_OPT_PATH.
+ // Parameters :
+ // $p_path : Path where the files and directories are to be extracted
+ // $p_remove_path : First part ('root' part) of the memorized path
+ // (if any similar) to remove while extracting.
+ // Options :
+ // PCLZIP_OPT_PATH :
+ // PCLZIP_OPT_ADD_PATH :
+ // PCLZIP_OPT_REMOVE_PATH :
+ // PCLZIP_OPT_REMOVE_ALL_PATH :
+ // PCLZIP_CB_PRE_EXTRACT :
+ // PCLZIP_CB_POST_EXTRACT :
+ // Return Values :
+ // 0 or a negative value on failure,
+ // The list of the extracted files, with a status of the action.
+ // (see PclZip::listContent() for list entry format)
+ // --------------------------------------------------------------------------------
+ function extract()
+ {
+ $v_result=1;
+
+ // ----- Reset the error handler
+ $this->privErrorReset();
+
+ // ----- Check archive
+ if (!$this->privCheckFormat()) {
+ return(0);
+ }
+
+ // ----- Set default values
+ $v_options = array();
+ // $v_path = "./";
+ $v_path = '';
+ $v_remove_path = "";
+ $v_remove_all_path = false;
+
+ // ----- Look for variable options arguments
+ $v_size = func_num_args();
+
+ // ----- Default values for option
+ $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = false;
+
+ // ----- Look for arguments
+ if ($v_size > 0) {
+ // ----- Get the arguments
+ $v_arg_list = func_get_args();
+
+ // ----- Look for first arg
+ if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
+ // ----- Parse the options
+ $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, array (
+ PCLZIP_OPT_PATH => 'optional',
+ PCLZIP_OPT_REMOVE_PATH => 'optional',
+ PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
+ PCLZIP_OPT_ADD_PATH => 'optional',
+ PCLZIP_CB_PRE_EXTRACT => 'optional',
+ PCLZIP_CB_POST_EXTRACT => 'optional',
+ PCLZIP_OPT_SET_CHMOD => 'optional',
+ PCLZIP_OPT_BY_NAME => 'optional',
+ PCLZIP_OPT_BY_EREG => 'optional',
+ PCLZIP_OPT_BY_PREG => 'optional',
+ PCLZIP_OPT_BY_INDEX => 'optional',
+ PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
+ PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional',
+ PCLZIP_OPT_REPLACE_NEWER => 'optional',
+ PCLZIP_OPT_STOP_ON_ERROR => 'optional',
+ PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
+ PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
+ PCLZIP_OPT_TEMP_FILE_ON => 'optional',
+ PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
+ ));
+ if ($v_result != 1) {
+ return 0;
+ }
+
+ // ----- Set the arguments
+ if (isset($v_options[PCLZIP_OPT_PATH])) {
+ $v_path = $v_options[PCLZIP_OPT_PATH];
+ }
+ if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
+ $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
+ }
+ if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
+ $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
+ }
+ if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
+ // ----- Check for '/' in last path char
+ if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
+ $v_path .= '/';
+ }
+ $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
+ }
+ } else {
+ // ----- Look for 2 args
+ // Here we need to support the first historic synopsis of the
+ // method.
+ // ----- Get the first argument
+ $v_path = $v_arg_list[0];
+
+ // ----- Look for the optional second argument
+ if ($v_size == 2) {
+ $v_remove_path = $v_arg_list[1];
+ } else if ($v_size > 2) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
+
+ // ----- Return
+ return 0;
+ }
+ }
+ }
+
+ // ----- Look for default option values
+ $this->privOptionDefaultThreshold($v_options);
+
+ // ----- Trace
+
+ // ----- Call the extracting fct
+ $p_list = array();
+ $v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options);
+ if ($v_result < 1) {
+ unset($p_list);
+ return(0);
+ }
+
+ // ----- Return
+ return $p_list;
+ }
+ // --------------------------------------------------------------------------------
+
+
+ // --------------------------------------------------------------------------------
+ // Function :
+ // extractByIndex($p_index, $p_path="./", $p_remove_path="")
+ // extractByIndex($p_index, [$p_option, $p_option_value, ...])
+ // Description :
+ // This method supports two synopsis. The first one is historical.
+ // This method is doing a partial extract of the archive.
+ // The extracted files or folders are identified by their index in the
+ // archive (from 0 to n).
+ // Note that if the index identify a folder, only the folder entry is
+ // extracted, not all the files included in the archive.
+ // Parameters :
+ // $p_index : A single index (integer) or a string of indexes of files to
+ // extract. The form of the string is "0,4-6,8-12" with only numbers
+ // and '-' for range or ',' to separate ranges. No spaces or ';'
+ // are allowed.
+ // $p_path : Path where the files and directories are to be extracted
+ // $p_remove_path : First part ('root' part) of the memorized path
+ // (if any similar) to remove while extracting.
+ // Options :
+ // PCLZIP_OPT_PATH :
+ // PCLZIP_OPT_ADD_PATH :
+ // PCLZIP_OPT_REMOVE_PATH :
+ // PCLZIP_OPT_REMOVE_ALL_PATH :
+ // PCLZIP_OPT_EXTRACT_AS_STRING : The files are extracted as strings and
+ // not as files.
+ // The resulting content is in a new field 'content' in the file
+ // structure.
+ // This option must be used alone (any other options are ignored).
+ // PCLZIP_CB_PRE_EXTRACT :
+ // PCLZIP_CB_POST_EXTRACT :
+ // Return Values :
+ // 0 on failure,
+ // The list of the extracted files, with a status of the action.
+ // (see PclZip::listContent() for list entry format)
+ // --------------------------------------------------------------------------------
+ //function extractByIndex($p_index, options...)
+ function extractByIndex($p_index)
+ {
+ $v_result=1;
+
+ // ----- Reset the error handler
+ $this->privErrorReset();
+
+ // ----- Check archive
+ if (!$this->privCheckFormat()) {
+ return(0);
+ }
+
+ // ----- Set default values
+ $v_options = array();
+ // $v_path = "./";
+ $v_path = '';
+ $v_remove_path = "";
+ $v_remove_all_path = false;
+
+ // ----- Look for variable options arguments
+ $v_size = func_num_args();
+
+ // ----- Default values for option
+ $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = false;
+
+ // ----- Look for arguments
+ if ($v_size > 1) {
+ // ----- Get the arguments
+ $v_arg_list = func_get_args();
+
+ // ----- Remove form the options list the first argument
+ array_shift($v_arg_list);
+ $v_size--;
+
+ // ----- Look for first arg
+ if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
+ // ----- Parse the options
+ $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, array(
+ PCLZIP_OPT_PATH => 'optional',
+ PCLZIP_OPT_REMOVE_PATH => 'optional',
+ PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
+ PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
+ PCLZIP_OPT_ADD_PATH => 'optional',
+ PCLZIP_CB_PRE_EXTRACT => 'optional',
+ PCLZIP_CB_POST_EXTRACT => 'optional',
+ PCLZIP_OPT_SET_CHMOD => 'optional',
+ PCLZIP_OPT_REPLACE_NEWER => 'optional',
+ PCLZIP_OPT_STOP_ON_ERROR => 'optional',
+ PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
+ PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
+ PCLZIP_OPT_TEMP_FILE_ON => 'optional',
+ PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
+ ));
+ if ($v_result != 1) {
+ return 0;
+ }
+
+ // ----- Set the arguments
+ if (isset($v_options[PCLZIP_OPT_PATH])) {
+ $v_path = $v_options[PCLZIP_OPT_PATH];
+ }
+ if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
+ $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
+ }
+ if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
+ $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
+ }
+ if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
+ // ----- Check for '/' in last path char
+ if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
+ $v_path .= '/';
+ }
+ $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
+ }
+ if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) {
+ $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = false;
+ } else {
+ }
+ } else {
+ // ----- Look for 2 args
+ // Here we need to support the first historic synopsis of the
+ // method.
+
+ // ----- Get the first argument
+ $v_path = $v_arg_list[0];
+
+ // ----- Look for the optional second argument
+ if ($v_size == 2) {
+ $v_remove_path = $v_arg_list[1];
+ } else if ($v_size > 2) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
+
+ // ----- Return
+ return 0;
+ }
+ }
+ }
+
+ // ----- Trace
+
+ // ----- Trick
+ // Here I want to reuse extractByRule(), so I need to parse the $p_index
+ // with privParseOptions()
+ $v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index);
+ $v_options_trick = array();
+ $v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick, array (PCLZIP_OPT_BY_INDEX => 'optional'));
+ if ($v_result != 1) {
+ return 0;
+ }
+ $v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX];
+
+ // ----- Look for default option values
+ $this->privOptionDefaultThreshold($v_options);
+
+ // ----- Call the extracting fct
+ if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) {
+ return(0);
+ }
+
+ // ----- Return
+ return $p_list;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function :
+ // delete([$p_option, $p_option_value, ...])
+ // Description :
+ // This method removes files from the archive.
+ // If no parameters are given, then all the archive is emptied.
+ // Parameters :
+ // None or optional arguments.
+ // Options :
+ // PCLZIP_OPT_BY_INDEX :
+ // PCLZIP_OPT_BY_NAME :
+ // PCLZIP_OPT_BY_EREG :
+ // PCLZIP_OPT_BY_PREG :
+ // Return Values :
+ // 0 on failure,
+ // The list of the files which are still present in the archive.
+ // (see PclZip::listContent() for list entry format)
+ // --------------------------------------------------------------------------------
+ function delete()
+ {
+ $v_result=1;
+
+ // ----- Reset the error handler
+ $this->privErrorReset();
+
+ // ----- Check archive
+ if (!$this->privCheckFormat()) {
+ return(0);
+ }
+
+ // ----- Set default values
+ $v_options = array();
+
+ // ----- Look for variable options arguments
+ $v_size = func_num_args();
+
+ // ----- Look for arguments
+ if ($v_size > 0) {
+ // ----- Get the arguments
+ $v_arg_list = func_get_args();
+
+ // ----- Parse the options
+ $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, array (
+ PCLZIP_OPT_BY_NAME => 'optional',
+ PCLZIP_OPT_BY_EREG => 'optional',
+ PCLZIP_OPT_BY_PREG => 'optional',
+ PCLZIP_OPT_BY_INDEX => 'optional'
+ ));
+ if ($v_result != 1) {
+ return 0;
+ }
+ }
+
+ // ----- Magic quotes trick
+ $this->privDisableMagicQuotes();
+
+ // ----- Call the delete fct
+ $v_list = array();
+ if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) {
+ $this->privSwapBackMagicQuotes();
+ unset($v_list);
+ return(0);
+ }
+
+ // ----- Magic quotes trick
+ $this->privSwapBackMagicQuotes();
+
+ // ----- Return
+ return $v_list;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : deleteByIndex()
+ // Description :
+ // ***** Deprecated *****
+ // delete(PCLZIP_OPT_BY_INDEX, $p_index) should be prefered.
+ // --------------------------------------------------------------------------------
+ function deleteByIndex($p_index)
+ {
+
+ $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index);
+
+ // ----- Return
+ return $p_list;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : properties()
+ // Description :
+ // This method gives the properties of the archive.
+ // The properties are :
+ // nb : Number of files in the archive
+ // comment : Comment associated with the archive file
+ // status : not_exist, ok
+ // Parameters :
+ // None
+ // Return Values :
+ // 0 on failure,
+ // An array with the archive properties.
+ // --------------------------------------------------------------------------------
+ function properties()
+ {
+
+ // ----- Reset the error handler
+ $this->privErrorReset();
+
+ // ----- Magic quotes trick
+ $this->privDisableMagicQuotes();
+
+ // ----- Check archive
+ if (!$this->privCheckFormat()) {
+ $this->privSwapBackMagicQuotes();
+ return(0);
+ }
+
+ // ----- Default properties
+ $v_prop = array();
+ $v_prop['comment'] = '';
+ $v_prop['nb'] = 0;
+ $v_prop['status'] = 'not_exist';
+
+ // ----- Look if file exists
+ if (@is_file($this->zipname)) {
+ // ----- Open the zip file
+ if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0) {
+ $this->privSwapBackMagicQuotes();
+
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
+
+ // ----- Return
+ return 0;
+ }
+
+ // ----- Read the central directory informations
+ $v_central_dir = array();
+ if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) {
+ $this->privSwapBackMagicQuotes();
+ return 0;
+ }
+
+ // ----- Close the zip file
+ $this->privCloseFd();
+
+ // ----- Set the user attributes
+ $v_prop['comment'] = $v_central_dir['comment'];
+ $v_prop['nb'] = $v_central_dir['entries'];
+ $v_prop['status'] = 'ok';
+ }
+
+ // ----- Magic quotes trick
+ $this->privSwapBackMagicQuotes();
+
+ // ----- Return
+ return $v_prop;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : duplicate()
+ // Description :
+ // This method creates an archive by copying the content of an other one. If
+ // the archive already exist, it is replaced by the new one without any warning.
+ // Parameters :
+ // $p_archive : The filename of a valid archive, or
+ // a valid PclZip object.
+ // Return Values :
+ // 1 on success.
+ // 0 or a negative value on error (error code).
+ // --------------------------------------------------------------------------------
+ function duplicate($p_archive)
+ {
+ $v_result = 1;
+
+ // ----- Reset the error handler
+ $this->privErrorReset();
+
+ // ----- Look if the $p_archive is a PclZip object
+ if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip')) {
+ // ----- Duplicate the archive
+ $v_result = $this->privDuplicate($p_archive->zipname);
+ } else if (is_string($p_archive)) {
+ // ----- Look if the $p_archive is a string (so a filename)
+ // ----- Check that $p_archive is a valid zip file
+ // TBC : Should also check the archive format
+ if (!is_file($p_archive)) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'");
+ $v_result = PCLZIP_ERR_MISSING_FILE;
+ } else {
+ // ----- Duplicate the archive
+ $v_result = $this->privDuplicate($p_archive);
+ }
+ } else {
+ // ----- Invalid variable
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
+ $v_result = PCLZIP_ERR_INVALID_PARAMETER;
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : merge()
+ // Description :
+ // This method merge the $p_archive_to_add archive at the end of the current
+ // one ($this).
+ // If the archive ($this) does not exist, the merge becomes a duplicate.
+ // If the $p_archive_to_add archive does not exist, the merge is a success.
+ // Parameters :
+ // $p_archive_to_add : It can be directly the filename of a valid zip archive,
+ // or a PclZip object archive.
+ // Return Values :
+ // 1 on success,
+ // 0 or negative values on error (see below).
+ // --------------------------------------------------------------------------------
+ function merge($p_archive_to_add)
+ {
+ $v_result = 1;
+
+ // ----- Reset the error handler
+ $this->privErrorReset();
+
+ // ----- Check archive
+ if (!$this->privCheckFormat()) {
+ return(0);
+ }
+
+ // ----- Look if the $p_archive_to_add is a PclZip object
+ if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip')) {
+ // ----- Merge the archive
+ $v_result = $this->privMerge($p_archive_to_add);
+ } else if (is_string($p_archive_to_add)) {
+ // ----- Look if the $p_archive_to_add is a string (so a filename)
+ // ----- Create a temporary archive
+ $v_object_archive = new PclZip($p_archive_to_add);
+
+ // ----- Merge the archive
+ $v_result = $this->privMerge($v_object_archive);
+ } else {
+ // ----- Invalid variable
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
+ $v_result = PCLZIP_ERR_INVALID_PARAMETER;
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+
+
+ // --------------------------------------------------------------------------------
+ // Function : errorCode()
+ // Description :
+ // Parameters :
+ // --------------------------------------------------------------------------------
+ function errorCode()
+ {
+ if (PCLZIP_ERROR_EXTERNAL == 1) {
+ return(PclErrorCode());
+ } else {
+ return($this->error_code);
+ }
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : errorName()
+ // Description :
+ // Parameters :
+ // --------------------------------------------------------------------------------
+ function errorName($p_with_code = false)
+ {
+ $v_name = array(
+ PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR',
+ PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL',
+ PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL',
+ PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER',
+ PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE',
+ PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG',
+ PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP',
+ PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE',
+ PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL',
+ PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION',
+ PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT',
+ PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL',
+ PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL',
+ PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM',
+ PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP',
+ PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE',
+ PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE',
+ PCLZIP_ERR_UNSUPPORTED_COMPRESSION => 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION',
+ PCLZIP_ERR_UNSUPPORTED_ENCRYPTION => 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION',
+ PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE => 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE',
+ PCLZIP_ERR_DIRECTORY_RESTRICTION => 'PCLZIP_ERR_DIRECTORY_RESTRICTION',
+ );
+
+ if (isset($v_name[$this->error_code])) {
+ $v_value = $v_name[$this->error_code];
+ } else {
+ $v_value = 'NoName';
+ }
+
+ if ($p_with_code) {
+ return($v_value.' ('.$this->error_code.')');
+ } else {
+ return($v_value);
+ }
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : errorInfo()
+ // Description :
+ // Parameters :
+ // --------------------------------------------------------------------------------
+ function errorInfo($p_full = false)
+ {
+ if (PCLZIP_ERROR_EXTERNAL == 1) {
+ return(PclErrorString());
+ } else {
+ if ($p_full) {
+ return($this->errorName(true)." : ".$this->error_string);
+ } else {
+ return($this->error_string." [code ".$this->error_code."]");
+ }
+ }
+ }
+ // --------------------------------------------------------------------------------
+
+
+ // --------------------------------------------------------------------------------
+ // ***** UNDER THIS LINE ARE DEFINED PRIVATE INTERNAL FUNCTIONS *****
+ // ***** *****
+ // ***** THESES FUNCTIONS MUST NOT BE USED DIRECTLY *****
+ // --------------------------------------------------------------------------------
+
+
+
+ // --------------------------------------------------------------------------------
+ // Function : privCheckFormat()
+ // Description :
+ // This method check that the archive exists and is a valid zip archive.
+ // Several level of check exists. (futur)
+ // Parameters :
+ // $p_level : Level of check. Default 0.
+ // 0 : Check the first bytes (magic codes) (default value))
+ // 1 : 0 + Check the central directory (futur)
+ // 2 : 1 + Check each file header (futur)
+ // Return Values :
+ // true on success,
+ // false on error, the error code is set.
+ // --------------------------------------------------------------------------------
+ function privCheckFormat($p_level = 0)
+ {
+ $v_result = true;
+
+ // ----- Reset the file system cache
+ clearstatcache();
+
+ // ----- Reset the error handler
+ $this->privErrorReset();
+
+ // ----- Look if the file exits
+ if (!is_file($this->zipname)) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'");
+ return(false);
+ }
+
+ // ----- Check that the file is readeable
+ if (!is_readable($this->zipname)) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'");
+ return(false);
+ }
+
+ // ----- Check the magic code
+ // TBC
+
+ // ----- Check the central header
+ // TBC
+
+ // ----- Check each file header
+ // TBC
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privParseOptions()
+ // Description :
+ // This internal methods reads the variable list of arguments ($p_options_list,
+ // $p_size) and generate an array with the options and values ($v_result_list).
+ // $v_requested_options contains the options that can be present and those that
+ // must be present.
+ // $v_requested_options is an array, with the option value as key, and 'optional',
+ // or 'mandatory' as value.
+ // Parameters :
+ // See above.
+ // Return Values :
+ // 1 on success.
+ // 0 on failure.
+ // --------------------------------------------------------------------------------
+ function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options = false)
+ {
+ $v_result=1;
+
+ // ----- Read the options
+ $i=0;
+ while ($i<$p_size) {
+ // ----- Check if the option is supported
+ if (!isset($v_requested_options[$p_options_list[$i]])) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method");
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Look for next option
+ switch ($p_options_list[$i]) {
+ // ----- Look for options that request a path value
+ case PCLZIP_OPT_PATH:
+ case PCLZIP_OPT_REMOVE_PATH:
+ case PCLZIP_OPT_ADD_PATH:
+ // ----- Check the number of parameters
+ if (($i+1) >= $p_size) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Get the value
+ $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], false);
+ $i++;
+ break;
+
+ case PCLZIP_OPT_TEMP_FILE_THRESHOLD:
+ // ----- Check the number of parameters
+ if (($i+1) >= $p_size) {
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
+ return PclZip::errorCode();
+ }
+
+ // ----- Check for incompatible options
+ if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) {
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'");
+ return PclZip::errorCode();
+ }
+
+ // ----- Check the value
+ $v_value = $p_options_list[$i+1];
+ if ((!is_integer($v_value)) || ($v_value<0)) {
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Integer expected for option '".PclZipUtilOptionText($p_options_list[$i])."'");
+ return PclZip::errorCode();
+ }
+
+ // ----- Get the value (and convert it in bytes)
+ $v_result_list[$p_options_list[$i]] = $v_value*1048576;
+ $i++;
+ break;
+
+ case PCLZIP_OPT_TEMP_FILE_ON:
+ // ----- Check for incompatible options
+ if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) {
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'");
+ return PclZip::errorCode();
+ }
+
+ $v_result_list[$p_options_list[$i]] = true;
+ break;
+
+ case PCLZIP_OPT_TEMP_FILE_OFF:
+ // ----- Check for incompatible options
+ if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_ON])) {
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_ON'");
+ return PclZip::errorCode();
+ }
+ // ----- Check for incompatible options
+ if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) {
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_THRESHOLD'");
+ return PclZip::errorCode();
+ }
+ $v_result_list[$p_options_list[$i]] = true;
+ break;
+
+ case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION:
+ // ----- Check the number of parameters
+ if (($i+1) >= $p_size) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Get the value
+ if (is_string($p_options_list[$i+1]) && ($p_options_list[$i+1] != '')) {
+ $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], false);
+ $i++;
+ } else {
+ }
+ break;
+ // ----- Look for options that request an array of string for value
+ case PCLZIP_OPT_BY_NAME:
+ // ----- Check the number of parameters
+ if (($i+1) >= $p_size) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Get the value
+ if (is_string($p_options_list[$i+1])) {
+ $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1];
+ } else if (is_array($p_options_list[$i+1])) {
+ $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
+ } else {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
+ // ----- Return
+ return PclZip::errorCode();
+ }
+ $i++;
+ break;
+ // ----- Look for options that request an EREG or PREG expression
+ case PCLZIP_OPT_BY_EREG:
+ // ereg() is deprecated starting with PHP 5.3. Move PCLZIP_OPT_BY_EREG
+ // to PCLZIP_OPT_BY_PREG
+ $p_options_list[$i] = PCLZIP_OPT_BY_PREG;
+ case PCLZIP_OPT_BY_PREG:
+ //case PCLZIP_OPT_CRYPT :
+ // ----- Check the number of parameters
+ if (($i+1) >= $p_size) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Get the value
+ if (is_string($p_options_list[$i+1])) {
+ $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
+ } else {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
+ // ----- Return
+ return PclZip::errorCode();
+ }
+ $i++;
+ break;
+
+ // ----- Look for options that takes a string
+ case PCLZIP_OPT_COMMENT:
+ case PCLZIP_OPT_ADD_COMMENT:
+ case PCLZIP_OPT_PREPEND_COMMENT:
+ // ----- Check the number of parameters
+ if (($i+1) >= $p_size) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Get the value
+ if (is_string($p_options_list[$i+1])) {
+ $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
+ } else {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '" .PclZipUtilOptionText($p_options_list[$i]) ."'");
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+ $i++;
+ break;
+
+ // ----- Look for options that request an array of index
+ case PCLZIP_OPT_BY_INDEX:
+ // ----- Check the number of parameters
+ if (($i+1) >= $p_size) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Get the value
+ $v_work_list = array();
+ if (is_string($p_options_list[$i+1])) {
+ // ----- Remove spaces
+ $p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', '');
+
+ // ----- Parse items
+ $v_work_list = explode(",", $p_options_list[$i+1]);
+ } else if (is_integer($p_options_list[$i+1])) {
+ $v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1];
+ } else if (is_array($p_options_list[$i+1])) {
+ $v_work_list = $p_options_list[$i+1];
+ } else {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'");
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Reduce the index list
+ // each index item in the list must be a couple with a start and
+ // an end value : [0,3], [5-5], [8-10], ...
+ // ----- Check the format of each item
+ $v_sort_flag=false;
+ $v_sort_value=0;
+ for ($j=0; $j= $p_size) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
+ // ----- Return
+ return PclZip::errorCode();
+ }
+ // ----- Get the value
+ $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
+ $i++;
+ break;
+
+ // ----- Look for options that request a call-back
+ case PCLZIP_CB_PRE_EXTRACT:
+ case PCLZIP_CB_POST_EXTRACT:
+ case PCLZIP_CB_PRE_ADD:
+ case PCLZIP_CB_POST_ADD:
+ /* for futur use
+ case PCLZIP_CB_PRE_DELETE :
+ case PCLZIP_CB_POST_DELETE :
+ case PCLZIP_CB_PRE_LIST :
+ case PCLZIP_CB_POST_LIST :
+ */
+ // ----- Check the number of parameters
+ if (($i+1) >= $p_size) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Get the value
+ $v_function_name = $p_options_list[$i+1];
+
+ // ----- Check that the value is a valid existing function
+ if (!function_exists($v_function_name)) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '".$v_function_name."()' is not an existing function for option '".PclZipUtilOptionText($p_options_list[$i])."'");
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Set the attribute
+ $v_result_list[$p_options_list[$i]] = $v_function_name;
+ $i++;
+ break;
+ default:
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Unknown parameter '" .$p_options_list[$i]."'");
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Next options
+ $i++;
+ }
+
+ // ----- Look for mandatory options
+ if ($v_requested_options !== false) {
+ for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
+ // ----- Look for mandatory option
+ if ($v_requested_options[$key] == 'mandatory') {
+ // ----- Look if present
+ if (!isset($v_result_list[$key])) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+ }
+ }
+ }
+
+ // ----- Look for default values
+ if (!isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) {
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privOptionDefaultThreshold()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privOptionDefaultThreshold(&$p_options)
+ {
+ $v_result=1;
+
+ if (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) || isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) {
+ return $v_result;
+ }
+
+ // ----- Get 'memory_limit' configuration value
+ $v_memory_limit = ini_get('memory_limit');
+ $v_memory_limit = trim($v_memory_limit);
+ $last = strtolower(substr($v_memory_limit, -1));
+
+ if ($last == 'g') {
+ //$v_memory_limit = $v_memory_limit*1024*1024*1024;
+ $v_memory_limit = $v_memory_limit*1073741824;
+ }
+ if ($last == 'm') {
+ //$v_memory_limit = $v_memory_limit*1024*1024;
+ $v_memory_limit = $v_memory_limit*1048576;
+ }
+ if ($last == 'k') {
+ $v_memory_limit = $v_memory_limit*1024;
+ }
+
+ $p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] = floor($v_memory_limit*PCLZIP_TEMPORARY_FILE_RATIO);
+
+ // ----- Sanity check : No threshold if value lower than 1M
+ if ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] < 1048576) {
+ unset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]);
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privFileDescrParseAtt()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // 1 on success.
+ // 0 on failure.
+ // --------------------------------------------------------------------------------
+ function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options = false)
+ {
+ $v_result=1;
+
+ // ----- For each file in the list check the attributes
+ foreach ($p_file_list as $v_key => $v_value) {
+ // ----- Check if the option is supported
+ if (!isset($v_requested_options[$v_key])) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file");
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Look for attribute
+ switch ($v_key) {
+ case PCLZIP_ATT_FILE_NAME:
+ if (!is_string($v_value)) {
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
+ return PclZip::errorCode();
+ }
+
+ $p_filedescr['filename'] = PclZipUtilPathReduction($v_value);
+
+ if ($p_filedescr['filename'] == '') {
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'");
+ return PclZip::errorCode();
+ }
+ break;
+ case PCLZIP_ATT_FILE_NEW_SHORT_NAME:
+ if (!is_string($v_value)) {
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
+ return PclZip::errorCode();
+ }
+
+ $p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value);
+
+ if ($p_filedescr['new_short_name'] == '') {
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'");
+ return PclZip::errorCode();
+ }
+ break;
+ case PCLZIP_ATT_FILE_NEW_FULL_NAME:
+ if (!is_string($v_value)) {
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
+ return PclZip::errorCode();
+ }
+
+ $p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value);
+
+ if ($p_filedescr['new_full_name'] == '') {
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'");
+ return PclZip::errorCode();
+ }
+ break;
+ // ----- Look for options that takes a string
+ case PCLZIP_ATT_FILE_COMMENT:
+ if (!is_string($v_value)) {
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
+ return PclZip::errorCode();
+ }
+ $p_filedescr['comment'] = $v_value;
+ break;
+ case PCLZIP_ATT_FILE_MTIME:
+ if (!is_integer($v_value)) {
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". Integer expected for attribute '".PclZipUtilOptionText($v_key)."'");
+ return PclZip::errorCode();
+ }
+ $p_filedescr['mtime'] = $v_value;
+ break;
+ case PCLZIP_ATT_FILE_CONTENT:
+ $p_filedescr['content'] = $v_value;
+ break;
+ default:
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Unknown parameter '".$v_key."'");
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Look for mandatory options
+ if ($v_requested_options !== false) {
+ for ($key = reset($v_requested_options); $key = key($v_requested_options); $key = next($v_requested_options)) {
+ // ----- Look for mandatory option
+ if ($v_requested_options[$key] == 'mandatory') {
+ // ----- Look if present
+ if (!isset($p_file_list[$key])) {
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
+ return PclZip::errorCode();
+ }
+ }
+ }
+ }
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privFileDescrExpand()
+ // Description :
+ // This method look for each item of the list to see if its a file, a folder
+ // or a string to be added as file. For any other type of files (link, other)
+ // just ignore the item.
+ // Then prepare the information that will be stored for that file.
+ // When its a folder, expand the folder with all the files that are in that
+ // folder (recursively).
+ // Parameters :
+ // Return Values :
+ // 1 on success.
+ // 0 on failure.
+ // --------------------------------------------------------------------------------
+ function privFileDescrExpand(&$p_filedescr_list, &$p_options)
+ {
+ $v_result=1;
+
+ // ----- Create a result list
+ $v_result_list = array();
+
+ // ----- Look each entry
+ for ($i=0; $iprivCalculateStoredFilename($v_descr, $p_options);
+
+ // ----- Add the descriptor in result list
+ $v_result_list[sizeof($v_result_list)] = $v_descr;
+
+ // ----- Look for folder
+ if ($v_descr['type'] == 'folder') {
+ // ----- List of items in folder
+ $v_dirlist_descr = array();
+ $v_dirlist_nb = 0;
+ if ($v_folder_handler = @opendir($v_descr['filename'])) {
+ while (($v_item_handler = @readdir($v_folder_handler)) !== false) {
+ // ----- Skip '.' and '..'
+ if (($v_item_handler == '.') || ($v_item_handler == '..')) {
+ continue;
+ }
+
+ // ----- Compose the full filename
+ $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler;
+
+ // ----- Look for different stored filename
+ // Because the name of the folder was changed, the name of the
+ // files/sub-folders also change
+ if (($v_descr['stored_filename'] != $v_descr['filename'])
+ && (!isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))) {
+ if ($v_descr['stored_filename'] != '') {
+ $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler;
+ } else {
+ $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_item_handler;
+ }
+ }
+ $v_dirlist_nb++;
+ }
+
+ @closedir($v_folder_handler);
+ } else {
+ // TBC : unable to open folder in read mode
+ }
+
+ // ----- Expand each element of the list
+ if ($v_dirlist_nb != 0) {
+ // ----- Expand
+ if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) {
+ return $v_result;
+ }
+
+ // ----- Concat the resulting list
+ $v_result_list = array_merge($v_result_list, $v_dirlist_descr);
+ }
+
+ // ----- Free local array
+ unset($v_dirlist_descr);
+ }
+ }
+
+ // ----- Get the result list
+ $p_filedescr_list = $v_result_list;
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privCreate()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privCreate($p_filedescr_list, &$p_result_list, &$p_options)
+ {
+ $v_result=1;
+ $v_list_detail = array();
+
+ // ----- Magic quotes trick
+ $this->privDisableMagicQuotes();
+
+ // ----- Open the file in write mode
+ if (($v_result = $this->privOpenFd('wb')) != 1) {
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Add the list of files
+ $v_result = $this->privAddList($p_filedescr_list, $p_result_list, $p_options);
+
+ // ----- Close
+ $this->privCloseFd();
+
+ // ----- Magic quotes trick
+ $this->privSwapBackMagicQuotes();
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privAdd()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privAdd($p_filedescr_list, &$p_result_list, &$p_options)
+ {
+ $v_result=1;
+ $v_list_detail = array();
+
+ // ----- Look if the archive exists or is empty
+ if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0)) {
+ // ----- Do a create
+ $v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options);
+
+ // ----- Return
+ return $v_result;
+ }
+ // ----- Magic quotes trick
+ $this->privDisableMagicQuotes();
+
+ // ----- Open the zip file
+ if (($v_result=$this->privOpenFd('rb')) != 1) {
+ // ----- Magic quotes trick
+ $this->privSwapBackMagicQuotes();
+
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Read the central directory informations
+ $v_central_dir = array();
+ if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) {
+ $this->privCloseFd();
+ $this->privSwapBackMagicQuotes();
+ return $v_result;
+ }
+
+ // ----- Go to beginning of File
+ @rewind($this->zip_fd);
+
+ // ----- Creates a temporay file
+ $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
+
+ // ----- Open the temporary file in write mode
+ if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) {
+ $this->privCloseFd();
+ $this->privSwapBackMagicQuotes();
+
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Copy the files from the archive to the temporary file
+ // TBC : Here I should better append the file and go back to erase the central dir
+ $v_size = $v_central_dir['offset'];
+ while ($v_size != 0) {
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
+ $v_buffer = fread($this->zip_fd, $v_read_size);
+ @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
+ $v_size -= $v_read_size;
+ }
+
+ // ----- Swap the file descriptor
+ // Here is a trick : I swap the temporary fd with the zip fd, in order to use
+ // the following methods on the temporary fil and not the real archive
+ $v_swap = $this->zip_fd;
+ $this->zip_fd = $v_zip_temp_fd;
+ $v_zip_temp_fd = $v_swap;
+
+ // ----- Add the files
+ $v_header_list = array();
+ if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1) {
+ fclose($v_zip_temp_fd);
+ $this->privCloseFd();
+ @unlink($v_zip_temp_name);
+ $this->privSwapBackMagicQuotes();
+
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Store the offset of the central dir
+ $v_offset = @ftell($this->zip_fd);
+
+ // ----- Copy the block of file headers from the old archive
+ $v_size = $v_central_dir['size'];
+ while ($v_size != 0) {
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
+ $v_buffer = @fread($v_zip_temp_fd, $v_read_size);
+ @fwrite($this->zip_fd, $v_buffer, $v_read_size);
+ $v_size -= $v_read_size;
+ }
+
+ // ----- Create the Central Dir files header
+ for ($i=0, $v_count=0; $iprivWriteCentralFileHeader($v_header_list[$i])) != 1) {
+ fclose($v_zip_temp_fd);
+ $this->privCloseFd();
+ @unlink($v_zip_temp_name);
+ $this->privSwapBackMagicQuotes();
+
+ // ----- Return
+ return $v_result;
+ }
+ $v_count++;
+ }
+
+ // ----- Transform the header to a 'usable' info
+ $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
+ }
+
+ // ----- Zip file comment
+ $v_comment = $v_central_dir['comment'];
+ if (isset($p_options[PCLZIP_OPT_COMMENT])) {
+ $v_comment = $p_options[PCLZIP_OPT_COMMENT];
+ }
+ if (isset($p_options[PCLZIP_OPT_ADD_COMMENT])) {
+ $v_comment = $v_comment.$p_options[PCLZIP_OPT_ADD_COMMENT];
+ }
+ if (isset($p_options[PCLZIP_OPT_PREPEND_COMMENT])) {
+ $v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT].$v_comment;
+ }
+
+ // ----- Calculate the size of the central header
+ $v_size = @ftell($this->zip_fd)-$v_offset;
+
+ // ----- Create the central dir footer
+ if (($v_result = $this->privWriteCentralHeader($v_count+$v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1) {
+ // ----- Reset the file list
+ unset($v_header_list);
+ $this->privSwapBackMagicQuotes();
+
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Swap back the file descriptor
+ $v_swap = $this->zip_fd;
+ $this->zip_fd = $v_zip_temp_fd;
+ $v_zip_temp_fd = $v_swap;
+
+ // ----- Close
+ $this->privCloseFd();
+
+ // ----- Close the temporary file
+ @fclose($v_zip_temp_fd);
+
+ // ----- Magic quotes trick
+ $this->privSwapBackMagicQuotes();
+
+ // ----- Delete the zip file
+ // TBC : I should test the result ...
+ @unlink($this->zipname);
+
+ // ----- Rename the temporary file
+ // TBC : I should test the result ...
+ //@rename($v_zip_temp_name, $this->zipname);
+ PclZipUtilRename($v_zip_temp_name, $this->zipname);
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privOpenFd()
+ // Description :
+ // Parameters :
+ // --------------------------------------------------------------------------------
+ function privOpenFd($p_mode)
+ {
+ $v_result=1;
+
+ // ----- Look if already open
+ if ($this->zip_fd != 0) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \''.$this->zipname.'\' already open');
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Open the zip file
+ if (($this->zip_fd = @fopen($this->zipname, $p_mode)) == 0) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode');
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privCloseFd()
+ // Description :
+ // Parameters :
+ // --------------------------------------------------------------------------------
+ function privCloseFd()
+ {
+ $v_result=1;
+
+ if ($this->zip_fd != 0) {
+ @fclose($this->zip_fd);
+ }
+ $this->zip_fd = 0;
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privAddList()
+ // Description :
+ // $p_add_dir and $p_remove_dir will give the ability to memorize a path which is
+ // different from the real path of the file. This is usefull if you want to have PclTar
+ // running in any directory, and memorize relative path from an other directory.
+ // Parameters :
+ // $p_list : An array containing the file or directory names to add in the tar
+ // $p_result_list : list of added files with their properties (specially the status field)
+ // $p_add_dir : Path to add in the filename path archived
+ // $p_remove_dir : Path to remove in the filename path archived
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ // function privAddList($p_list, &$p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, &$p_options)
+ function privAddList($p_filedescr_list, &$p_result_list, &$p_options)
+ {
+ $v_result=1;
+
+ // ----- Add the files
+ $v_header_list = array();
+ if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1) {
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Store the offset of the central dir
+ $v_offset = @ftell($this->zip_fd);
+
+ // ----- Create the Central Dir files header
+ for ($i=0, $v_count=0; $iprivWriteCentralFileHeader($v_header_list[$i])) != 1) {
+ // ----- Return
+ return $v_result;
+ }
+ $v_count++;
+ }
+
+ // ----- Transform the header to a 'usable' info
+ $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
+ }
+
+ // ----- Zip file comment
+ $v_comment = '';
+ if (isset($p_options[PCLZIP_OPT_COMMENT])) {
+ $v_comment = $p_options[PCLZIP_OPT_COMMENT];
+ }
+
+ // ----- Calculate the size of the central header
+ $v_size = @ftell($this->zip_fd)-$v_offset;
+
+ // ----- Create the central dir footer
+ if (($v_result = $this->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment)) != 1) {
+ // ----- Reset the file list
+ unset($v_header_list);
+
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privAddFileList()
+ // Description :
+ // Parameters :
+ // $p_filedescr_list : An array containing the file description
+ // or directory names to add in the zip
+ // $p_result_list : list of added files with their properties (specially the status field)
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privAddFileList($p_filedescr_list, &$p_result_list, &$p_options)
+ {
+ $v_result=1;
+ $v_header = array();
+
+ // ----- Recuperate the current number of elt in list
+ $v_nb = sizeof($p_result_list);
+
+ // ----- Loop on the files
+ for ($j=0; ($jprivAddFile($p_filedescr_list[$j], $v_header, $p_options);
+ if ($v_result != 1) {
+ return $v_result;
+ }
+
+ // ----- Store the file infos
+ $p_result_list[$v_nb++] = $v_header;
+ }
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privAddFile()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privAddFile($p_filedescr, &$p_header, &$p_options)
+ {
+ $v_result=1;
+
+ // ----- Working variable
+ $p_filename = $p_filedescr['filename'];
+
+ // TBC : Already done in the fileAtt check ... ?
+ if ($p_filename == "") {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)");
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Look for a stored different filename
+ /* TBC : Removed
+ if (isset($p_filedescr['stored_filename'])) {
+ $v_stored_filename = $p_filedescr['stored_filename'];
+ }
+ else {
+ $v_stored_filename = $p_filedescr['stored_filename'];
+ }
+ */
+
+ // ----- Set the file properties
+ clearstatcache();
+ $p_header['version'] = 20;
+ $p_header['version_extracted'] = 10;
+ $p_header['flag'] = 0;
+ $p_header['compression'] = 0;
+ $p_header['crc'] = 0;
+ $p_header['compressed_size'] = 0;
+ $p_header['filename_len'] = strlen($p_filename);
+ $p_header['extra_len'] = 0;
+ $p_header['disk'] = 0;
+ $p_header['internal'] = 0;
+ $p_header['offset'] = 0;
+ $p_header['filename'] = $p_filename;
+ // TBC : Removed $p_header['stored_filename'] = $v_stored_filename;
+ $p_header['stored_filename'] = $p_filedescr['stored_filename'];
+ $p_header['extra'] = '';
+ $p_header['status'] = 'ok';
+ $p_header['index'] = -1;
+
+ // ----- Look for regular file
+ if ($p_filedescr['type']=='file') {
+ $p_header['external'] = 0x00000000;
+ $p_header['size'] = filesize($p_filename);
+ } else if ($p_filedescr['type']=='folder') {
+ // ----- Look for regular folder
+ $p_header['external'] = 0x00000010;
+ $p_header['mtime'] = filemtime($p_filename);
+ $p_header['size'] = filesize($p_filename);
+ } else if ($p_filedescr['type'] == 'virtual_file') {
+ // ----- Look for virtual file
+ $p_header['external'] = 0x00000000;
+ $p_header['size'] = strlen($p_filedescr['content']);
+ }
+
+ // ----- Look for filetime
+ if (isset($p_filedescr['mtime'])) {
+ $p_header['mtime'] = $p_filedescr['mtime'];
+ } else if ($p_filedescr['type'] == 'virtual_file') {
+ $p_header['mtime'] = time();
+ } else {
+ $p_header['mtime'] = filemtime($p_filename);
+ }
+
+ // ------ Look for file comment
+ if (isset($p_filedescr['comment'])) {
+ $p_header['comment_len'] = strlen($p_filedescr['comment']);
+ $p_header['comment'] = $p_filedescr['comment'];
+ } else {
+ $p_header['comment_len'] = 0;
+ $p_header['comment'] = '';
+ }
+
+ // ----- Look for pre-add callback
+ if (isset($p_options[PCLZIP_CB_PRE_ADD])) {
+ // ----- Generate a local information
+ $v_local_header = array();
+ $this->privConvertHeader2FileInfo($p_header, $v_local_header);
+
+ // ----- Call the callback
+ // Here I do not use call_user_func() because I need to send a reference to the
+ // header.
+ // eval('$v_result = '.$p_options[PCLZIP_CB_PRE_ADD].'(PCLZIP_CB_PRE_ADD, $v_local_header);');
+ $v_result = $p_options[PCLZIP_CB_PRE_ADD](PCLZIP_CB_PRE_ADD, $v_local_header);
+ if ($v_result == 0) {
+ // ----- Change the file status
+ $p_header['status'] = "skipped";
+ $v_result = 1;
+ }
+
+ // ----- Update the informations
+ // Only some fields can be modified
+ if ($p_header['stored_filename'] != $v_local_header['stored_filename']) {
+ $p_header['stored_filename'] = PclZipUtilPathReduction($v_local_header['stored_filename']);
+ }
+ }
+
+ // ----- Look for empty stored filename
+ if ($p_header['stored_filename'] == "") {
+ $p_header['status'] = "filtered";
+ }
+
+ // ----- Check the path length
+ if (strlen($p_header['stored_filename']) > 0xFF) {
+ $p_header['status'] = 'filename_too_long';
+ }
+
+ // ----- Look if no error, or file not skipped
+ if ($p_header['status'] == 'ok') {
+ // ----- Look for a file
+ if ($p_filedescr['type'] == 'file') {
+ // ----- Look for using temporary file to zip
+ if ((!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON]) || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_header['size'])))) {
+ $v_result = $this->privAddFileUsingTempFile($p_filedescr, $p_header, $p_options);
+ if ($v_result < PCLZIP_ERR_NO_ERROR) {
+ return $v_result;
+ }
+ } else {
+ // ----- Use "in memory" zip algo
+ // ----- Open the source file
+ if (($v_file = @fopen($p_filename, "rb")) == 0) {
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
+ return PclZip::errorCode();
+ }
+
+ // ----- Read the file content
+ $v_content = @fread($v_file, $p_header['size']);
+
+ // ----- Close the file
+ @fclose($v_file);
+
+ // ----- Calculate the CRC
+ $p_header['crc'] = @crc32($v_content);
+
+ // ----- Look for no compression
+ if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
+ // ----- Set header parameters
+ $p_header['compressed_size'] = $p_header['size'];
+ $p_header['compression'] = 0;
+ } else {
+ // ----- Look for normal compression
+ // ----- Compress the content
+ $v_content = @gzdeflate($v_content);
+
+ // ----- Set header parameters
+ $p_header['compressed_size'] = strlen($v_content);
+ $p_header['compression'] = 8;
+ }
+
+ // ----- Call the header generation
+ if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
+ @fclose($v_file);
+ return $v_result;
+ }
+
+ // ----- Write the compressed (or not) content
+ @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);
+ }
+ } else if ($p_filedescr['type'] == 'virtual_file') {
+ // ----- Look for a virtual file (a file from string)
+ $v_content = $p_filedescr['content'];
+
+ // ----- Calculate the CRC
+ $p_header['crc'] = @crc32($v_content);
+
+ // ----- Look for no compression
+ if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
+ // ----- Set header parameters
+ $p_header['compressed_size'] = $p_header['size'];
+ $p_header['compression'] = 0;
+ } else {
+ // ----- Look for normal compression
+ // ----- Compress the content
+ $v_content = @gzdeflate($v_content);
+
+ // ----- Set header parameters
+ $p_header['compressed_size'] = strlen($v_content);
+ $p_header['compression'] = 8;
+ }
+
+ // ----- Call the header generation
+ if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
+ @fclose($v_file);
+ return $v_result;
+ }
+
+ // ----- Write the compressed (or not) content
+ @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);
+ } else if ($p_filedescr['type'] == 'folder') {
+ // ----- Look for a directory
+ // ----- Look for directory last '/'
+ if (@substr($p_header['stored_filename'], -1) != '/') {
+ $p_header['stored_filename'] .= '/';
+ }
+
+ // ----- Set the file properties
+ $p_header['size'] = 0;
+ //$p_header['external'] = 0x41FF0010; // Value for a folder : to be checked
+ $p_header['external'] = 0x00000010; // Value for a folder : to be checked
+
+ // ----- Call the header generation
+ if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
+ return $v_result;
+ }
+ }
+ }
+
+ // ----- Look for post-add callback
+ if (isset($p_options[PCLZIP_CB_POST_ADD])) {
+ // ----- Generate a local information
+ $v_local_header = array();
+ $this->privConvertHeader2FileInfo($p_header, $v_local_header);
+
+ // ----- Call the callback
+ // Here I do not use call_user_func() because I need to send a reference to the
+ // header.
+ // eval('$v_result = '.$p_options[PCLZIP_CB_POST_ADD].'(PCLZIP_CB_POST_ADD, $v_local_header);');
+ $v_result = $p_options[PCLZIP_CB_POST_ADD](PCLZIP_CB_POST_ADD, $v_local_header);
+ if ($v_result == 0) {
+ // ----- Ignored
+ $v_result = 1;
+ }
+
+ // ----- Update the informations
+ // Nothing can be modified
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privAddFileUsingTempFile()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privAddFileUsingTempFile($p_filedescr, &$p_header, &$p_options)
+ {
+ $v_result=PCLZIP_ERR_NO_ERROR;
+
+ // ----- Working variable
+ $p_filename = $p_filedescr['filename'];
+
+
+ // ----- Open the source file
+ if (($v_file = @fopen($p_filename, "rb")) == 0) {
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
+ return PclZip::errorCode();
+ }
+
+ // ----- Creates a compressed temporary file
+ $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz';
+ if (($v_file_compressed = @gzopen($v_gzip_temp_name, "wb")) == 0) {
+ fclose($v_file);
+ PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode');
+ return PclZip::errorCode();
+ }
+
+ // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
+ $v_size = filesize($p_filename);
+ while ($v_size != 0) {
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
+ $v_buffer = @fread($v_file, $v_read_size);
+ //$v_binary_data = pack('a'.$v_read_size, $v_buffer);
+ @gzputs($v_file_compressed, $v_buffer, $v_read_size);
+ $v_size -= $v_read_size;
+ }
+
+ // ----- Close the file
+ @fclose($v_file);
+ @gzclose($v_file_compressed);
+
+ // ----- Check the minimum file size
+ if (filesize($v_gzip_temp_name) < 18) {
+ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'gzip temporary file \''.$v_gzip_temp_name.'\' has invalid filesize - should be minimum 18 bytes');
+ return PclZip::errorCode();
+ }
+
+ // ----- Extract the compressed attributes
+ if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) {
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
+ return PclZip::errorCode();
+ }
+
+ // ----- Read the gzip file header
+ $v_binary_data = @fread($v_file_compressed, 10);
+ $v_data_header = unpack('a1id1/a1id2/a1cm/a1flag/Vmtime/a1xfl/a1os', $v_binary_data);
+
+ // ----- Check some parameters
+ $v_data_header['os'] = bin2hex($v_data_header['os']);
+
+ // ----- Read the gzip file footer
+ @fseek($v_file_compressed, filesize($v_gzip_temp_name)-8);
+ $v_binary_data = @fread($v_file_compressed, 8);
+ $v_data_footer = unpack('Vcrc/Vcompressed_size', $v_binary_data);
+
+ // ----- Set the attributes
+ $p_header['compression'] = ord($v_data_header['cm']);
+ //$p_header['mtime'] = $v_data_header['mtime'];
+ $p_header['crc'] = $v_data_footer['crc'];
+ $p_header['compressed_size'] = filesize($v_gzip_temp_name)-18;
+
+ // ----- Close the file
+ @fclose($v_file_compressed);
+
+ // ----- Call the header generation
+ if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
+ return $v_result;
+ }
+
+ // ----- Add the compressed data
+ if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) {
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
+ return PclZip::errorCode();
+ }
+
+ // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
+ fseek($v_file_compressed, 10);
+ $v_size = $p_header['compressed_size'];
+ while ($v_size != 0) {
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
+ $v_buffer = @fread($v_file_compressed, $v_read_size);
+ //$v_binary_data = pack('a'.$v_read_size, $v_buffer);
+ @fwrite($this->zip_fd, $v_buffer, $v_read_size);
+ $v_size -= $v_read_size;
+ }
+
+ // ----- Close the file
+ @fclose($v_file_compressed);
+
+ // ----- Unlink the temporary file
+ @unlink($v_gzip_temp_name);
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privCalculateStoredFilename()
+ // Description :
+ // Based on file descriptor properties and global options, this method
+ // calculate the filename that will be stored in the archive.
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privCalculateStoredFilename(&$p_filedescr, &$p_options)
+ {
+ $v_result=1;
+
+ // ----- Working variables
+ $p_filename = $p_filedescr['filename'];
+ if (isset($p_options[PCLZIP_OPT_ADD_PATH])) {
+ $p_add_dir = $p_options[PCLZIP_OPT_ADD_PATH];
+ } else {
+ $p_add_dir = '';
+ }
+ if (isset($p_options[PCLZIP_OPT_REMOVE_PATH])) {
+ $p_remove_dir = $p_options[PCLZIP_OPT_REMOVE_PATH];
+ } else {
+ $p_remove_dir = '';
+ }
+ if (isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
+ $p_remove_all_dir = $p_options[PCLZIP_OPT_REMOVE_ALL_PATH];
+ } else {
+ $p_remove_all_dir = 0;
+ }
+
+ // ----- Look for full name change
+ if (isset($p_filedescr['new_full_name'])) {
+ // ----- Remove drive letter if any
+ $v_stored_filename = PclZipUtilTranslateWinPath($p_filedescr['new_full_name']);
+ } else {
+ // ----- Look for path and/or short name change
+ // ----- Look for short name change
+ // Its when we cahnge just the filename but not the path
+ if (isset($p_filedescr['new_short_name'])) {
+ $v_path_info = pathinfo($p_filename);
+ $v_dir = '';
+ if ($v_path_info['dirname'] != '') {
+ $v_dir = $v_path_info['dirname'].'/';
+ }
+ $v_stored_filename = $v_dir.$p_filedescr['new_short_name'];
+ } else {
+ // ----- Calculate the stored filename
+ $v_stored_filename = $p_filename;
+ }
+
+ // ----- Look for all path to remove
+ if ($p_remove_all_dir) {
+ $v_stored_filename = basename($p_filename);
+ } else if ($p_remove_dir != "") {
+ // ----- Look for partial path remove
+ if (substr($p_remove_dir, -1) != '/') {
+ $p_remove_dir .= "/";
+ }
+
+ if ((substr($p_filename, 0, 2) == "./") || (substr($p_remove_dir, 0, 2) == "./")) {
+ if ((substr($p_filename, 0, 2) == "./") && (substr($p_remove_dir, 0, 2) != "./")) {
+ $p_remove_dir = "./".$p_remove_dir;
+ }
+ if ((substr($p_filename, 0, 2) != "./") && (substr($p_remove_dir, 0, 2) == "./")) {
+ $p_remove_dir = substr($p_remove_dir, 2);
+ }
+ }
+
+ $v_compare = PclZipUtilPathInclusion($p_remove_dir, $v_stored_filename);
+ if ($v_compare > 0) {
+ if ($v_compare == 2) {
+ $v_stored_filename = "";
+ } else {
+ $v_stored_filename = substr($v_stored_filename, strlen($p_remove_dir));
+ }
+ }
+ }
+
+ // ----- Remove drive letter if any
+ $v_stored_filename = PclZipUtilTranslateWinPath($v_stored_filename);
+
+ // ----- Look for path to add
+ if ($p_add_dir != "") {
+ if (substr($p_add_dir, -1) == "/") {
+ $v_stored_filename = $p_add_dir.$v_stored_filename;
+ } else {
+ $v_stored_filename = $p_add_dir."/".$v_stored_filename;
+ }
+ }
+ }
+
+ // ----- Filename (reduce the path of stored name)
+ $v_stored_filename = PclZipUtilPathReduction($v_stored_filename);
+ $p_filedescr['stored_filename'] = $v_stored_filename;
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privWriteFileHeader()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privWriteFileHeader(&$p_header)
+ {
+ $v_result=1;
+
+ // ----- Store the offset position of the file
+ $p_header['offset'] = ftell($this->zip_fd);
+
+ // ----- Transform UNIX mtime to DOS format mdate/mtime
+ $v_date = getdate($p_header['mtime']);
+ $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;
+ $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];
+
+ // ----- Packed data
+ $v_binary_data = pack("VvvvvvVVVvv", 0x04034b50, $p_header['version_extracted'], $p_header['flag'], $p_header['compression'], $v_mtime, $v_mdate, $p_header['crc'], $p_header['compressed_size'], $p_header['size'], strlen($p_header['stored_filename']), $p_header['extra_len']);
+
+ // ----- Write the first 148 bytes of the header in the archive
+ fputs($this->zip_fd, $v_binary_data, 30);
+
+ // ----- Write the variable fields
+ if (strlen($p_header['stored_filename']) != 0) {
+ fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
+ }
+ if ($p_header['extra_len'] != 0) {
+ fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privWriteCentralFileHeader()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privWriteCentralFileHeader(&$p_header)
+ {
+ $v_result=1;
+
+ // TBC
+ //for(reset($p_header); $key = key($p_header); next($p_header)) {
+ //}
+
+ // ----- Transform UNIX mtime to DOS format mdate/mtime
+ $v_date = getdate($p_header['mtime']);
+ $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;
+ $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];
+
+
+ // ----- Packed data
+ $v_binary_data = pack("VvvvvvvVVVvvvvvVV", 0x02014b50, $p_header['version'], $p_header['version_extracted'], $p_header['flag'], $p_header['compression'], $v_mtime, $v_mdate, $p_header['crc'], $p_header['compressed_size'], $p_header['size'], strlen($p_header['stored_filename']), $p_header['extra_len'], $p_header['comment_len'], $p_header['disk'], $p_header['internal'], $p_header['external'], $p_header['offset']);
+
+ // ----- Write the 42 bytes of the header in the zip file
+ fputs($this->zip_fd, $v_binary_data, 46);
+
+ // ----- Write the variable fields
+ if (strlen($p_header['stored_filename']) != 0) {
+ fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
+ }
+ if ($p_header['extra_len'] != 0) {
+ fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
+ }
+ if ($p_header['comment_len'] != 0) {
+ fputs($this->zip_fd, $p_header['comment'], $p_header['comment_len']);
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privWriteCentralHeader()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privWriteCentralHeader($p_nb_entries, $p_size, $p_offset, $p_comment)
+ {
+ $v_result = 1;
+
+ // ----- Packed data
+ $v_binary_data = pack("VvvvvVVv", 0x06054b50, 0, 0, $p_nb_entries, $p_nb_entries, $p_size, $p_offset, strlen($p_comment));
+
+ // ----- Write the 22 bytes of the header in the zip file
+ fputs($this->zip_fd, $v_binary_data, 22);
+
+ // ----- Write the variable fields
+ if (strlen($p_comment) != 0) {
+ fputs($this->zip_fd, $p_comment, strlen($p_comment));
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privList()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privList(&$p_list)
+ {
+ $v_result = 1;
+
+ // ----- Magic quotes trick
+ $this->privDisableMagicQuotes();
+
+ // ----- Open the zip file
+ if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0) {
+ // ----- Magic quotes trick
+ $this->privSwapBackMagicQuotes();
+
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Read the central directory informations
+ $v_central_dir = array();
+ if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) {
+ $this->privSwapBackMagicQuotes();
+ return $v_result;
+ }
+
+ // ----- Go to beginning of Central Dir
+ @rewind($this->zip_fd);
+ if (@fseek($this->zip_fd, $v_central_dir['offset'])) {
+ $this->privSwapBackMagicQuotes();
+
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Read each entry
+ for ($i=0; $i<$v_central_dir['entries']; $i++) {
+ // ----- Read the file header
+ if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1) {
+ $this->privSwapBackMagicQuotes();
+ return $v_result;
+ }
+ $v_header['index'] = $i;
+
+ // ----- Get the only interesting attributes
+ $this->privConvertHeader2FileInfo($v_header, $p_list[$i]);
+ unset($v_header);
+ }
+
+ // ----- Close the zip file
+ $this->privCloseFd();
+
+ // ----- Magic quotes trick
+ $this->privSwapBackMagicQuotes();
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privConvertHeader2FileInfo()
+ // Description :
+ // This function takes the file informations from the central directory
+ // entries and extract the interesting parameters that will be given back.
+ // The resulting file infos are set in the array $p_info
+ // $p_info['filename'] : Filename with full path. Given by user (add),
+ // extracted in the filesystem (extract).
+ // $p_info['stored_filename'] : Stored filename in the archive.
+ // $p_info['size'] = Size of the file.
+ // $p_info['compressed_size'] = Compressed size of the file.
+ // $p_info['mtime'] = Last modification date of the file.
+ // $p_info['comment'] = Comment associated with the file.
+ // $p_info['folder'] = true/false : indicates if the entry is a folder or not.
+ // $p_info['status'] = status of the action on the file.
+ // $p_info['crc'] = CRC of the file content.
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privConvertHeader2FileInfo($p_header, &$p_info)
+ {
+ $v_result=1;
+
+ // ----- Get the interesting attributes
+ $v_temp_path = PclZipUtilPathReduction($p_header['filename']);
+ $p_info['filename'] = $v_temp_path;
+ $v_temp_path = PclZipUtilPathReduction($p_header['stored_filename']);
+ $p_info['stored_filename'] = $v_temp_path;
+ $p_info['size'] = $p_header['size'];
+ $p_info['compressed_size'] = $p_header['compressed_size'];
+ $p_info['mtime'] = $p_header['mtime'];
+ $p_info['comment'] = $p_header['comment'];
+ $p_info['folder'] = (($p_header['external']&0x00000010)==0x00000010);
+ $p_info['index'] = $p_header['index'];
+ $p_info['status'] = $p_header['status'];
+ $p_info['crc'] = $p_header['crc'];
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privExtractByRule()
+ // Description :
+ // Extract a file or directory depending of rules (by index, by name, ...)
+ // Parameters :
+ // $p_file_list : An array where will be placed the properties of each
+ // extracted file
+ // $p_path : Path to add while writing the extracted files
+ // $p_remove_path : Path to remove (from the file memorized path) while writing the
+ // extracted files. If the path does not match the file path,
+ // the file is extracted with its memorized path.
+ // $p_remove_path does not apply to 'list' mode.
+ // $p_path and $p_remove_path are commulative.
+ // Return Values :
+ // 1 on success,0 or less on error (see error code list)
+ // --------------------------------------------------------------------------------
+ function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
+ {
+ $v_result=1;
+
+ // ----- Magic quotes trick
+ $this->privDisableMagicQuotes();
+
+ // ----- Check the path
+ if (($p_path == "") || ((substr($p_path, 0, 1) != "/") && (substr($p_path, 0, 3) != "../") && (substr($p_path, 1, 2)!=":/"))) {
+ $p_path = "./".$p_path;
+ }
+
+ // ----- Reduce the path last (and duplicated) '/'
+ if (($p_path != "./") && ($p_path != "/")) {
+ // ----- Look for the path end '/'
+ while (substr($p_path, -1) == "/") {
+ $p_path = substr($p_path, 0, strlen($p_path)-1);
+ }
+ }
+
+ // ----- Look for path to remove format (should end by /)
+ if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/')) {
+ $p_remove_path .= '/';
+ }
+ $p_remove_path_size = strlen($p_remove_path);
+
+ // ----- Open the zip file
+ if (($v_result = $this->privOpenFd('rb')) != 1) {
+ $this->privSwapBackMagicQuotes();
+ return $v_result;
+ }
+
+ // ----- Read the central directory informations
+ $v_central_dir = array();
+ if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) {
+ // ----- Close the zip file
+ $this->privCloseFd();
+ $this->privSwapBackMagicQuotes();
+
+ return $v_result;
+ }
+
+ // ----- Start at beginning of Central Dir
+ $v_pos_entry = $v_central_dir['offset'];
+
+ // ----- Read each entry
+ $j_start = 0;
+ for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++) {
+ // ----- Read next Central dir entry
+ @rewind($this->zip_fd);
+ if (@fseek($this->zip_fd, $v_pos_entry)) {
+ // ----- Close the zip file
+ $this->privCloseFd();
+ $this->privSwapBackMagicQuotes();
+
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Read the file header
+ $v_header = array();
+ if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1) {
+ // ----- Close the zip file
+ $this->privCloseFd();
+ $this->privSwapBackMagicQuotes();
+
+ return $v_result;
+ }
+
+ // ----- Store the index
+ $v_header['index'] = $i;
+
+ // ----- Store the file position
+ $v_pos_entry = ftell($this->zip_fd);
+
+ // ----- Look for the specific extract rules
+ $v_extract = false;
+
+ // ----- Look for extract by name rule
+ if ((isset($p_options[PCLZIP_OPT_BY_NAME])) && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
+ // ----- Look if the filename is in the list
+ for ($j=0; ($j strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) && (substr($v_header['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
+ $v_extract = true;
+ }
+ } elseif ($v_header['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
+ // ----- Look for a filename
+ $v_extract = true;
+ }
+ }
+ }else if ((isset($p_options[PCLZIP_OPT_BY_PREG])) && ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
+ // ----- Look for extract by preg rule
+ if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) {
+ $v_extract = true;
+ }
+ } else if ((isset($p_options[PCLZIP_OPT_BY_INDEX])) && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
+ // ----- Look for extract by index rule
+ // ----- Look if the index is in the list
+ for ($j=$j_start; ($j=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
+ $v_extract = true;
+ }
+ if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
+ $j_start = $j+1;
+ }
+
+ if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {
+ break;
+ }
+ }
+ } else {
+ // ----- Look for no rule, which means extract all the archive
+ $v_extract = true;
+ }
+
+ // ----- Check compression method
+ if (($v_extract) && (($v_header['compression'] != 8) && ($v_header['compression'] != 0))) {
+ $v_header['status'] = 'unsupported_compression';
+
+ // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
+ if ((isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) && ($p_options[PCLZIP_OPT_STOP_ON_ERROR] === true)) {
+
+ $this->privSwapBackMagicQuotes();
+
+ PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION, "Filename '".$v_header['stored_filename']."' is compressed by an unsupported compression method (".$v_header['compression'].") ");
+
+ return PclZip::errorCode();
+ }
+ }
+
+ // ----- Check encrypted files
+ if (($v_extract) && (($v_header['flag'] & 1) == 1)) {
+ $v_header['status'] = 'unsupported_encryption';
+ // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
+ if ((isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) && ($p_options[PCLZIP_OPT_STOP_ON_ERROR] === true)) {
+ $this->privSwapBackMagicQuotes();
+
+ PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, "Unsupported encryption for filename '".$v_header['stored_filename']."'");
+
+ return PclZip::errorCode();
+ }
+ }
+
+ // ----- Look for real extraction
+ if (($v_extract) && ($v_header['status'] != 'ok')) {
+ $v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++]);
+ if ($v_result != 1) {
+ $this->privCloseFd();
+ $this->privSwapBackMagicQuotes();
+ return $v_result;
+ }
+
+ $v_extract = false;
+ }
+
+ // ----- Look for real extraction
+ if ($v_extract) {
+ // ----- Go to the file position
+ @rewind($this->zip_fd);
+ if (@fseek($this->zip_fd, $v_header['offset'])) {
+ // ----- Close the zip file
+ $this->privCloseFd();
+
+ $this->privSwapBackMagicQuotes();
+
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Look for extraction as string
+ if ($p_options[PCLZIP_OPT_EXTRACT_AS_STRING]) {
+ $v_string = '';
+
+ // ----- Extracting the file
+ $v_result1 = $this->privExtractFileAsString($v_header, $v_string, $p_options);
+ if ($v_result1 < 1) {
+ $this->privCloseFd();
+ $this->privSwapBackMagicQuotes();
+ return $v_result1;
+ }
+
+ // ----- Get the only interesting attributes
+ if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted])) != 1) {
+ // ----- Close the zip file
+ $this->privCloseFd();
+ $this->privSwapBackMagicQuotes();
+
+ return $v_result;
+ }
+
+ // ----- Set the file content
+ $p_file_list[$v_nb_extracted]['content'] = $v_string;
+
+ // ----- Next extracted file
+ $v_nb_extracted++;
+
+ // ----- Look for user callback abort
+ if ($v_result1 == 2) {
+ break;
+ }
+ }
+ // ----- Look for extraction in standard output
+ elseif ((isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) && ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) {
+ // ----- Extracting the file in standard output
+ $v_result1 = $this->privExtractFileInOutput($v_header, $p_options);
+ if ($v_result1 < 1) {
+ $this->privCloseFd();
+ $this->privSwapBackMagicQuotes();
+ return $v_result1;
+ }
+
+ // ----- Get the only interesting attributes
+ if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) {
+ $this->privCloseFd();
+ $this->privSwapBackMagicQuotes();
+ return $v_result;
+ }
+
+ // ----- Look for user callback abort
+ if ($v_result1 == 2) {
+ break;
+ }
+ } else {
+ // ----- Look for normal extraction
+ // ----- Extracting the file
+ $v_result1 = $this->privExtractFile($v_header, $p_path, $p_remove_path, $p_remove_all_path, $p_options);
+ if ($v_result1 < 1) {
+ $this->privCloseFd();
+ $this->privSwapBackMagicQuotes();
+ return $v_result1;
+ }
+
+ // ----- Get the only interesting attributes
+ if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) {
+ // ----- Close the zip file
+ $this->privCloseFd();
+ $this->privSwapBackMagicQuotes();
+
+ return $v_result;
+ }
+
+ // ----- Look for user callback abort
+ if ($v_result1 == 2) {
+ break;
+ }
+ }
+ }
+ }
+
+ // ----- Close the zip file
+ $this->privCloseFd();
+ $this->privSwapBackMagicQuotes();
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privExtractFile()
+ // Description :
+ // Parameters :
+ // Return Values :
+ //
+ // 1 : ... ?
+ // PCLZIP_ERR_USER_ABORTED(2) : User ask for extraction stop in callback
+ // --------------------------------------------------------------------------------
+ function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
+ {
+ $v_result=1;
+
+ // ----- Read the file header
+ if (($v_result = $this->privReadFileHeader($v_header)) != 1) {
+ // ----- Return
+ return $v_result;
+ }
+
+
+ // ----- Check that the file header is coherent with $p_entry info
+ if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
+ // TBC
+ }
+
+ // ----- Look for all path to remove
+ if ($p_remove_all_path == true) {
+ // ----- Look for folder entry that not need to be extracted
+ if (($p_entry['external']&0x00000010)==0x00000010) {
+ $p_entry['status'] = "filtered";
+
+ return $v_result;
+ }
+
+ // ----- Get the basename of the path
+ $p_entry['filename'] = basename($p_entry['filename']);
+ } else if ($p_remove_path != "") {
+ // ----- Look for path to remove
+ if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2) {
+ // ----- Change the file status
+ $p_entry['status'] = "filtered";
+
+ // ----- Return
+ return $v_result;
+ }
+
+ $p_remove_path_size = strlen($p_remove_path);
+ if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path) {
+ // ----- Remove the path
+ $p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size);
+ }
+ }
+
+ // ----- Add the path
+ if ($p_path != '') {
+ $p_entry['filename'] = $p_path."/".$p_entry['filename'];
+ }
+
+ // ----- Check a base_dir_restriction
+ if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) {
+ $v_inclusion = PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION], $p_entry['filename']);
+ if ($v_inclusion == 0) {
+ PclZip::privErrorLog(PCLZIP_ERR_DIRECTORY_RESTRICTION,"Filename '".$p_entry['filename']."' is outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION");
+
+ return PclZip::errorCode();
+ }
+ }
+
+ // ----- Look for pre-extract callback
+ if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
+ // ----- Generate a local information
+ $v_local_header = array();
+ $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
+
+ // ----- Call the callback
+ // Here I do not use call_user_func() because I need to send a reference to the
+ // header.
+ // eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
+ $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
+ if ($v_result == 0) {
+ // ----- Change the file status
+ $p_entry['status'] = "skipped";
+ $v_result = 1;
+ }
+
+ // ----- Look for abort result
+ if ($v_result == 2) {
+ // ----- This status is internal and will be changed in 'skipped'
+ $p_entry['status'] = "aborted";
+ $v_result = PCLZIP_ERR_USER_ABORTED;
+ }
+
+ // ----- Update the informations
+ // Only some fields can be modified
+ $p_entry['filename'] = $v_local_header['filename'];
+ }
+
+ // ----- Look if extraction should be done
+ if ($p_entry['status'] == 'ok') {
+ // ----- Look for specific actions while the file exist
+ if (file_exists($p_entry['filename'])) {
+ // ----- Look if file is a directory
+ if (is_dir($p_entry['filename'])) {
+
+ // ----- Change the file status
+ $p_entry['status'] = "already_a_directory";
+
+ // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
+ // For historical reason first PclZip implementation does not stop
+ // when this kind of error occurs.
+ if ((isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
+ PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY, "Filename '".$p_entry['filename']."' is already used by an existing directory");
+ return PclZip::errorCode();
+ }
+ } else if (!is_writeable($p_entry['filename'])) {
+ // ----- Look if file is write protected
+ // ----- Change the file status
+ $p_entry['status'] = "write_protected";
+
+ // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
+ // For historical reason first PclZip implementation does not stop
+ // when this kind of error occurs.
+ if ((isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) && ($p_options[PCLZIP_OPT_STOP_ON_ERROR] === true)) {
+ PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, "Filename '".$p_entry['filename']."' exists and is write protected");
+ return PclZip::errorCode();
+ }
+ } else if (filemtime($p_entry['filename']) > $p_entry['mtime']) {
+ // ----- Look if the extracted file is older
+ // ----- Change the file status
+ if ((isset($p_options[PCLZIP_OPT_REPLACE_NEWER])) && ($p_options[PCLZIP_OPT_REPLACE_NEWER] === true)) {
+ } else {
+ $p_entry['status'] = "newer_exist";
+
+ // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
+ // For historical reason first PclZip implementation does not stop
+ // when this kind of error occurs.
+ if ((isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) && ($p_options[PCLZIP_OPT_STOP_ON_ERROR] === true)) {
+ PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, "Newer version of '".$p_entry['filename']."' exists and option PCLZIP_OPT_REPLACE_NEWER is not selected");
+ return PclZip::errorCode();
+ }
+ }
+ } else {
+ }
+ } else {
+ // ----- Check the directory availability and create it if necessary
+ if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/')) {
+ $v_dir_to_check = $p_entry['filename'];
+ }
+ else if (!strstr($p_entry['filename'], "/")) {
+ $v_dir_to_check = "";
+ }
+ else {
+ $v_dir_to_check = dirname($p_entry['filename']);
+ }
+
+ if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) {
+
+ // ----- Change the file status
+ $p_entry['status'] = "path_creation_fail";
+
+ // ----- Return
+ //return $v_result;
+ $v_result = 1;
+ }
+ }
+ }
+
+ // ----- Look if extraction should be done
+ if ($p_entry['status'] == 'ok') {
+ // ----- Do the extraction (if not a folder)
+ if (!(($p_entry['external']&0x00000010) == 0x00000010)) {
+ // ----- Look for not compressed file
+ if ($p_entry['compression'] == 0) {
+ // ----- Opening destination file
+ if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
+ // ----- Change the file status
+ $p_entry['status'] = "write_error";
+
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
+ $v_size = $p_entry['compressed_size'];
+ while ($v_size != 0) {
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
+ $v_buffer = @fread($this->zip_fd, $v_read_size);
+ /* Try to speed up the code
+ $v_binary_data = pack('a'.$v_read_size, $v_buffer);
+ @fwrite($v_dest_file, $v_binary_data, $v_read_size);
+ */
+ @fwrite($v_dest_file, $v_buffer, $v_read_size);
+ $v_size -= $v_read_size;
+ }
+
+ // ----- Closing the destination file
+ fclose($v_dest_file);
+
+ // ----- Change the file mtime
+ touch($p_entry['filename'], $p_entry['mtime']);
+ } else {
+ // ----- TBC
+ // Need to be finished
+ if (($p_entry['flag'] & 1) == 1) {
+ PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, 'File \''.$p_entry['filename'].'\' is encrypted. Encrypted files are not supported.');
+ return PclZip::errorCode();
+ }
+
+ // ----- Look for using temporary file to unzip
+ if ((!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON]) || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_entry['size'])))) {
+ $v_result = $this->privExtractFileUsingTempFile($p_entry, $p_options);
+ if ($v_result < PCLZIP_ERR_NO_ERROR) {
+ return $v_result;
+ }
+ } else {
+ // ----- Look for extract in memory
+ // ----- Read the compressed file in a buffer (one shot)
+ $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
+
+ // ----- Decompress the file
+ $v_file_content = @gzinflate($v_buffer);
+ unset($v_buffer);
+ if ($v_file_content === false) {
+
+ // ----- Change the file status
+ // TBC
+ $p_entry['status'] = "error";
+
+ return $v_result;
+ }
+
+ // ----- Opening destination file
+ if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
+
+ // ----- Change the file status
+ $p_entry['status'] = "write_error";
+
+ return $v_result;
+ }
+
+ // ----- Write the uncompressed data
+ @fwrite($v_dest_file, $v_file_content, $p_entry['size']);
+ unset($v_file_content);
+
+ // ----- Closing the destination file
+ @fclose($v_dest_file);
+ }
+
+ // ----- Change the file mtime
+ @touch($p_entry['filename'], $p_entry['mtime']);
+ }
+
+ // ----- Look for chmod option
+ if (isset($p_options[PCLZIP_OPT_SET_CHMOD])) {
+ // ----- Change the mode of the file
+ @chmod($p_entry['filename'], $p_options[PCLZIP_OPT_SET_CHMOD]);
+ }
+ }
+ }
+
+ // ----- Change abort status
+ if ($p_entry['status'] == "aborted") {
+ $p_entry['status'] = "skipped";
+ } elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
+ // ----- Look for post-extract callback
+ // ----- Generate a local information
+ $v_local_header = array();
+ $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
+
+ // ----- Call the callback
+ // Here I do not use call_user_func() because I need to send a reference to the
+ // header.
+ // eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
+ $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
+
+ // ----- Look for abort result
+ if ($v_result == 2) {
+ $v_result = PCLZIP_ERR_USER_ABORTED;
+ }
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privExtractFileUsingTempFile()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privExtractFileUsingTempFile(&$p_entry, &$p_options)
+ {
+ $v_result=1;
+
+ // ----- Creates a temporary file
+ $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz';
+ if (($v_dest_file = @fopen($v_gzip_temp_name, "wb")) == 0) {
+ fclose($v_file);
+ PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode');
+ return PclZip::errorCode();
+ }
+
+ // ----- Write gz file format header
+ $v_binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($p_entry['compression']), Chr(0x00), time(), Chr(0x00), Chr(3));
+ @fwrite($v_dest_file, $v_binary_data, 10);
+
+ // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
+ $v_size = $p_entry['compressed_size'];
+ while ($v_size != 0) {
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
+ $v_buffer = @fread($this->zip_fd, $v_read_size);
+ //$v_binary_data = pack('a'.$v_read_size, $v_buffer);
+ @fwrite($v_dest_file, $v_buffer, $v_read_size);
+ $v_size -= $v_read_size;
+ }
+
+ // ----- Write gz file format footer
+ $v_binary_data = pack('VV', $p_entry['crc'], $p_entry['size']);
+ @fwrite($v_dest_file, $v_binary_data, 8);
+
+ // ----- Close the temporary file
+ @fclose($v_dest_file);
+
+ // ----- Opening destination file
+ if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
+ $p_entry['status'] = "write_error";
+ return $v_result;
+ }
+
+ // ----- Open the temporary gz file
+ if (($v_src_file = @gzopen($v_gzip_temp_name, 'rb')) == 0) {
+ @fclose($v_dest_file);
+ $p_entry['status'] = "read_error";
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
+ return PclZip::errorCode();
+ }
+
+ // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
+ $v_size = $p_entry['size'];
+ while ($v_size != 0) {
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
+ $v_buffer = @gzread($v_src_file, $v_read_size);
+ //$v_binary_data = pack('a'.$v_read_size, $v_buffer);
+ @fwrite($v_dest_file, $v_buffer, $v_read_size);
+ $v_size -= $v_read_size;
+ }
+ @fclose($v_dest_file);
+ @gzclose($v_src_file);
+
+ // ----- Delete the temporary file
+ @unlink($v_gzip_temp_name);
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privExtractFileInOutput()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privExtractFileInOutput(&$p_entry, &$p_options)
+ {
+ $v_result=1;
+
+ // ----- Read the file header
+ if (($v_result = $this->privReadFileHeader($v_header)) != 1) {
+ return $v_result;
+ }
+
+ // ----- Check that the file header is coherent with $p_entry info
+ if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
+ // TBC
+ }
+
+ // ----- Look for pre-extract callback
+ if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
+ // ----- Generate a local information
+ $v_local_header = array();
+ $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
+
+ // ----- Call the callback
+ // Here I do not use call_user_func() because I need to send a reference to the
+ // header.
+ // eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
+ $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
+ if ($v_result == 0) {
+ // ----- Change the file status
+ $p_entry['status'] = "skipped";
+ $v_result = 1;
+ }
+
+ // ----- Look for abort result
+ if ($v_result == 2) {
+ // ----- This status is internal and will be changed in 'skipped'
+ $p_entry['status'] = "aborted";
+ $v_result = PCLZIP_ERR_USER_ABORTED;
+ }
+
+ // ----- Update the informations
+ // Only some fields can be modified
+ $p_entry['filename'] = $v_local_header['filename'];
+ }
+
+ // ----- Trace
+
+ // ----- Look if extraction should be done
+ if ($p_entry['status'] == 'ok') {
+ // ----- Do the extraction (if not a folder)
+ if (!(($p_entry['external']&0x00000010)==0x00000010)) {
+ // ----- Look for not compressed file
+ if ($p_entry['compressed_size'] == $p_entry['size']) {
+
+ // ----- Read the file in a buffer (one shot)
+ $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
+
+ // ----- Send the file to the output
+ echo $v_buffer;
+ unset($v_buffer);
+ } else {
+
+ // ----- Read the compressed file in a buffer (one shot)
+ $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
+
+ // ----- Decompress the file
+ $v_file_content = gzinflate($v_buffer);
+ unset($v_buffer);
+
+ // ----- Send the file to the output
+ echo $v_file_content;
+ unset($v_file_content);
+ }
+ }
+ }
+
+ // ----- Change abort status
+ if ($p_entry['status'] == "aborted") {
+ $p_entry['status'] = "skipped";
+ } elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
+ // ----- Look for post-extract callback
+
+ // ----- Generate a local information
+ $v_local_header = array();
+ $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
+
+ // ----- Call the callback
+ // Here I do not use call_user_func() because I need to send a reference to the
+ // header.
+ // eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
+ $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
+
+ // ----- Look for abort result
+ if ($v_result == 2) {
+ $v_result = PCLZIP_ERR_USER_ABORTED;
+ }
+ }
+
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privExtractFileAsString()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privExtractFileAsString(&$p_entry, &$p_string, &$p_options)
+ {
+ $v_result=1;
+
+ // ----- Read the file header
+ $v_header = array();
+ if (($v_result = $this->privReadFileHeader($v_header)) != 1) {
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Check that the file header is coherent with $p_entry info
+ if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
+ // TBC
+ }
+
+ // ----- Look for pre-extract callback
+ if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
+ // ----- Generate a local information
+ $v_local_header = array();
+ $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
+
+ // ----- Call the callback
+ // Here I do not use call_user_func() because I need to send a reference to the
+ // header.
+ // eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
+ $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
+ if ($v_result == 0) {
+ // ----- Change the file status
+ $p_entry['status'] = "skipped";
+ $v_result = 1;
+ }
+
+ // ----- Look for abort result
+ if ($v_result == 2) {
+ // ----- This status is internal and will be changed in 'skipped'
+ $p_entry['status'] = "aborted";
+ $v_result = PCLZIP_ERR_USER_ABORTED;
+ }
+
+ // ----- Update the informations
+ // Only some fields can be modified
+ $p_entry['filename'] = $v_local_header['filename'];
+ }
+
+ // ----- Look if extraction should be done
+ if ($p_entry['status'] == 'ok') {
+ // ----- Do the extraction (if not a folder)
+ if (!(($p_entry['external']&0x00000010)==0x00000010)) {
+ // ----- Look for not compressed file
+ // if ($p_entry['compressed_size'] == $p_entry['size'])
+ if ($p_entry['compression'] == 0) {
+
+ // ----- Reading the file
+ $p_string = @fread($this->zip_fd, $p_entry['compressed_size']);
+ } else {
+
+ // ----- Reading the file
+ $v_data = @fread($this->zip_fd, $p_entry['compressed_size']);
+
+ // ----- Decompress the file
+ if (($p_string = @gzinflate($v_data)) === false) {
+ // TBC
+ }
+ }
+ // ----- Trace
+ } else {
+ // TBC : error : can not extract a folder in a string
+ }
+ }
+
+ // ----- Change abort status
+ if ($p_entry['status'] == "aborted") {
+ $p_entry['status'] = "skipped";
+ } elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
+ // ----- Look for post-extract callback
+ // ----- Generate a local information
+ $v_local_header = array();
+ $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
+
+ // ----- Swap the content to header
+ $v_local_header['content'] = $p_string;
+ $p_string = '';
+
+ // ----- Call the callback
+ // Here I do not use call_user_func() because I need to send a reference to the
+ // header.
+ // eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
+ $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
+
+ // ----- Swap back the content to header
+ $p_string = $v_local_header['content'];
+ unset($v_local_header['content']);
+
+ // ----- Look for abort result
+ if ($v_result == 2) {
+ $v_result = PCLZIP_ERR_USER_ABORTED;
+ }
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privReadFileHeader()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privReadFileHeader(&$p_header)
+ {
+ $v_result=1;
+
+ // ----- Read the 4 bytes signature
+ $v_binary_data = @fread($this->zip_fd, 4);
+ $v_data = unpack('Vid', $v_binary_data);
+
+ // ----- Check signature
+ if ($v_data['id'] != 0x04034b50) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Read the first 42 bytes of the header
+ $v_binary_data = fread($this->zip_fd, 26);
+
+ // ----- Look for invalid block size
+ if (strlen($v_binary_data) != 26) {
+ $p_header['filename'] = "";
+ $p_header['status'] = "invalid_header";
+
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Extract the values
+ $v_data = unpack('vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $v_binary_data);
+
+ // ----- Get filename
+ $p_header['filename'] = fread($this->zip_fd, $v_data['filename_len']);
+
+ // ----- Get extra_fields
+ if ($v_data['extra_len'] != 0) {
+ $p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']);
+ } else {
+ $p_header['extra'] = '';
+ }
+
+ // ----- Extract properties
+ $p_header['version_extracted'] = $v_data['version'];
+ $p_header['compression'] = $v_data['compression'];
+ $p_header['size'] = $v_data['size'];
+ $p_header['compressed_size'] = $v_data['compressed_size'];
+ $p_header['crc'] = $v_data['crc'];
+ $p_header['flag'] = $v_data['flag'];
+ $p_header['filename_len'] = $v_data['filename_len'];
+
+ // ----- Recuperate date in UNIX format
+ $p_header['mdate'] = $v_data['mdate'];
+ $p_header['mtime'] = $v_data['mtime'];
+ if ($p_header['mdate'] && $p_header['mtime']) {
+ // ----- Extract time
+ $v_hour = ($p_header['mtime'] & 0xF800) >> 11;
+ $v_minute = ($p_header['mtime'] & 0x07E0) >> 5;
+ $v_seconde = ($p_header['mtime'] & 0x001F)*2;
+
+ // ----- Extract date
+ $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;
+ $v_month = ($p_header['mdate'] & 0x01E0) >> 5;
+ $v_day = $p_header['mdate'] & 0x001F;
+
+ // ----- Get UNIX date format
+ $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
+
+ } else {
+ $p_header['mtime'] = time();
+ }
+
+ // TBC
+ //for(reset($v_data); $key = key($v_data); next($v_data)) {
+ //}
+
+ // ----- Set the stored filename
+ $p_header['stored_filename'] = $p_header['filename'];
+
+ // ----- Set the status field
+ $p_header['status'] = "ok";
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privReadCentralFileHeader()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privReadCentralFileHeader(&$p_header)
+ {
+ $v_result = 1;
+
+ // ----- Read the 4 bytes signature
+ $v_binary_data = @fread($this->zip_fd, 4);
+ $v_data = unpack('Vid', $v_binary_data);
+
+ // ----- Check signature
+ if ($v_data['id'] != 0x02014b50) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Read the first 42 bytes of the header
+ $v_binary_data = fread($this->zip_fd, 42);
+
+ // ----- Look for invalid block size
+ if (strlen($v_binary_data) != 42) {
+ $p_header['filename'] = "";
+ $p_header['status'] = "invalid_header";
+
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Extract the values
+ $p_header = unpack('vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $v_binary_data);
+
+ // ----- Get filename
+ if ($p_header['filename_len'] != 0) {
+ $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']);
+ } else {
+ $p_header['filename'] = '';
+ }
+
+ // ----- Get extra
+ if ($p_header['extra_len'] != 0) {
+ $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']);
+ } else {
+ $p_header['extra'] = '';
+ }
+
+ // ----- Get comment
+ if ($p_header['comment_len'] != 0) {
+ $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']);
+ }
+ else {
+ $p_header['comment'] = '';
+ }
+
+ // ----- Extract properties
+
+ // ----- Recuperate date in UNIX format
+ //if ($p_header['mdate'] && $p_header['mtime'])
+ // TBC : bug : this was ignoring time with 0/0/0
+ if (1) {
+ // ----- Extract time
+ $v_hour = ($p_header['mtime'] & 0xF800) >> 11;
+ $v_minute = ($p_header['mtime'] & 0x07E0) >> 5;
+ $v_seconde = ($p_header['mtime'] & 0x001F)*2;
+
+ // ----- Extract date
+ $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;
+ $v_month = ($p_header['mdate'] & 0x01E0) >> 5;
+ $v_day = $p_header['mdate'] & 0x001F;
+
+ // ----- Get UNIX date format
+ $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
+
+ } else {
+ $p_header['mtime'] = time();
+ }
+
+ // ----- Set the stored filename
+ $p_header['stored_filename'] = $p_header['filename'];
+
+ // ----- Set default status to ok
+ $p_header['status'] = 'ok';
+
+ // ----- Look if it is a directory
+ if (substr($p_header['filename'], -1) == '/') {
+ //$p_header['external'] = 0x41FF0010;
+ $p_header['external'] = 0x00000010;
+ }
+
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privCheckFileHeaders()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // 1 on success,
+ // 0 on error;
+ // --------------------------------------------------------------------------------
+ function privCheckFileHeaders(&$p_local_header, &$p_central_header)
+ {
+ $v_result=1;
+
+ // ----- Check the static values
+ // TBC
+ if ($p_local_header['filename'] != $p_central_header['filename']) {
+ }
+ if ($p_local_header['version_extracted'] != $p_central_header['version_extracted']) {
+ }
+ if ($p_local_header['flag'] != $p_central_header['flag']) {
+ }
+ if ($p_local_header['compression'] != $p_central_header['compression']) {
+ }
+ if ($p_local_header['mtime'] != $p_central_header['mtime']) {
+ }
+ if ($p_local_header['filename_len'] != $p_central_header['filename_len']) {
+ }
+
+ // ----- Look for flag bit 3
+ if (($p_local_header['flag'] & 8) == 8) {
+ $p_local_header['size'] = $p_central_header['size'];
+ $p_local_header['compressed_size'] = $p_central_header['compressed_size'];
+ $p_local_header['crc'] = $p_central_header['crc'];
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privReadEndCentralDir()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privReadEndCentralDir(&$p_central_dir)
+ {
+ $v_result=1;
+
+ // ----- Go to the end of the zip file
+ $v_size = filesize($this->zipname);
+ @fseek($this->zip_fd, $v_size);
+ if (@ftell($this->zip_fd) != $v_size) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\'');
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- First try : look if this is an archive with no commentaries (most of the time)
+ // in this case the end of central dir is at 22 bytes of the file end
+ $v_found = 0;
+ if ($v_size > 26) {
+ @fseek($this->zip_fd, $v_size-22);
+ if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22)) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Read for bytes
+ $v_binary_data = @fread($this->zip_fd, 4);
+ $v_data = @unpack('Vid', $v_binary_data);
+
+ // ----- Check signature
+ if ($v_data['id'] == 0x06054b50) {
+ $v_found = 1;
+ }
+
+ $v_pos = ftell($this->zip_fd);
+ }
+
+ // ----- Go back to the maximum possible size of the Central Dir End Record
+ if (!$v_found) {
+ $v_maximum_size = 65557; // 0xFFFF + 22;
+ if ($v_maximum_size > $v_size)
+ $v_maximum_size = $v_size;
+ @fseek($this->zip_fd, $v_size-$v_maximum_size);
+ if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size)) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Read byte per byte in order to find the signature
+ $v_pos = ftell($this->zip_fd);
+ $v_bytes = 0x00000000;
+ while ($v_pos < $v_size) {
+ // ----- Read a byte
+ $v_byte = @fread($this->zip_fd, 1);
+
+ // ----- Add the byte
+ //$v_bytes = ($v_bytes << 8) | Ord($v_byte);
+ // Note we mask the old value down such that once shifted we can never end up with more than a 32bit number
+ // Otherwise on systems where we have 64bit integers the check below for the magic number will fail.
+ $v_bytes = (($v_bytes & 0xFFFFFF) << 8) | Ord($v_byte);
+
+ // ----- Compare the bytes
+ if ($v_bytes == 0x504b0506)
+ {
+ $v_pos++;
+ break;
+ }
+
+ $v_pos++;
+ }
+
+ // ----- Look if not found end of central dir
+ if ($v_pos == $v_size) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Unable to find End of Central Dir Record signature");
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+ }
+
+ // ----- Read the first 18 bytes of the header
+ $v_binary_data = fread($this->zip_fd, 18);
+
+ // ----- Look for invalid block size
+ if (strlen($v_binary_data) != 18) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data));
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Extract the values
+ $v_data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', $v_binary_data);
+
+ // ----- Check the global size
+ if (($v_pos + $v_data['comment_size'] + 18) != $v_size) {
+ // ----- Removed in release 2.2 see readme file
+ // The check of the file size is a little too strict.
+ // Some bugs where found when a zip is encrypted/decrypted with 'crypt'.
+ // While decrypted, zip has training 0 bytes
+ if (0) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'The central dir is not at the end of the archive. Some trailing bytes exists after the archive.');
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+ }
+
+ // ----- Get comment
+ if ($v_data['comment_size'] != 0) {
+ $p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']);
+ } else {
+ $p_central_dir['comment'] = '';
+ }
+
+ $p_central_dir['entries'] = $v_data['entries'];
+ $p_central_dir['disk_entries'] = $v_data['disk_entries'];
+ $p_central_dir['offset'] = $v_data['offset'];
+ $p_central_dir['size'] = $v_data['size'];
+ $p_central_dir['disk'] = $v_data['disk'];
+ $p_central_dir['disk_start'] = $v_data['disk_start'];
+
+ // TBC
+ //for(reset($p_central_dir); $key = key($p_central_dir); next($p_central_dir)) {
+ //}
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privDeleteByRule()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privDeleteByRule(&$p_result_list, &$p_options)
+ {
+ $v_result=1;
+ $v_list_detail = array();
+
+ // ----- Open the zip file
+ if (($v_result=$this->privOpenFd('rb')) != 1) {
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Read the central directory informations
+ $v_central_dir = array();
+ if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) {
+ $this->privCloseFd();
+ return $v_result;
+ }
+
+ // ----- Go to beginning of File
+ @rewind($this->zip_fd);
+
+ // ----- Scan all the files
+ // ----- Start at beginning of Central Dir
+ $v_pos_entry = $v_central_dir['offset'];
+ @rewind($this->zip_fd);
+ if (@fseek($this->zip_fd, $v_pos_entry)) {
+ // ----- Close the zip file
+ $this->privCloseFd();
+
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Read each entry
+ $v_header_list = array();
+ $j_start = 0;
+ for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++) {
+ // ----- Read the file header
+ $v_header_list[$v_nb_extracted] = array();
+ if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1) {
+ // ----- Close the zip file
+ $this->privCloseFd();
+
+ return $v_result;
+ }
+
+
+ // ----- Store the index
+ $v_header_list[$v_nb_extracted]['index'] = $i;
+
+ // ----- Look for the specific extract rules
+ $v_found = false;
+
+ // ----- Look for extract by name rule
+ if ((isset($p_options[PCLZIP_OPT_BY_NAME])) && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
+ // ----- Look if the filename is in the list
+ for ($j=0; ($j strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) && (substr($v_header_list[$v_nb_extracted]['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
+ $v_found = true;
+ } elseif ((($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */ && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
+ $v_found = true;
+ }
+ }
+ // ----- Look for a filename
+ elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
+ $v_found = true;
+ }
+ }
+ }
+ // ----- Look for extract by ereg rule
+ // ereg() is deprecated with PHP 5.3
+ /*
+ else if ( (isset($p_options[PCLZIP_OPT_BY_EREG]))
+ && ($p_options[PCLZIP_OPT_BY_EREG] != "")) {
+
+ if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
+ $v_found = true;
+ }
+ }
+ */
+ else if ((isset($p_options[PCLZIP_OPT_BY_PREG]))
+ // ----- Look for extract by preg rule
+ && ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
+ if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
+ $v_found = true;
+ }
+ } else if ((isset($p_options[PCLZIP_OPT_BY_INDEX])) && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
+ // ----- Look for extract by index rule
+ // ----- Look if the index is in the list
+ for ($j=$j_start; ($j=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
+ $v_found = true;
+ }
+ if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
+ $j_start = $j+1;
+ }
+
+ if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {
+ break;
+ }
+ }
+ } else {
+ $v_found = true;
+ }
+
+ // ----- Look for deletion
+ if ($v_found) {
+ unset($v_header_list[$v_nb_extracted]);
+ } else {
+ $v_nb_extracted++;
+ }
+ }
+
+ // ----- Look if something need to be deleted
+ if ($v_nb_extracted > 0) {
+ // ----- Creates a temporay file
+ $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
+
+ // ----- Creates a temporary zip archive
+ $v_temp_zip = new PclZip($v_zip_temp_name);
+
+ // ----- Open the temporary zip file in write mode
+ if (($v_result = $v_temp_zip->privOpenFd('wb')) != 1) {
+ $this->privCloseFd();
+
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Look which file need to be kept
+ for ($i=0; $izip_fd);
+ if (@fseek($this->zip_fd, $v_header_list[$i]['offset'])) {
+ // ----- Close the zip file
+ $this->privCloseFd();
+ $v_temp_zip->privCloseFd();
+ @unlink($v_zip_temp_name);
+
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Read the file header
+ $v_local_header = array();
+ if (($v_result = $this->privReadFileHeader($v_local_header)) != 1) {
+ // ----- Close the zip file
+ $this->privCloseFd();
+ $v_temp_zip->privCloseFd();
+ @unlink($v_zip_temp_name);
+
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Check that local file header is same as central file header
+ if ($this->privCheckFileHeaders($v_local_header, $v_header_list[$i]) != 1) {
+ // TBC
+ }
+ unset($v_local_header);
+
+ // ----- Write the file header
+ if (($v_result = $v_temp_zip->privWriteFileHeader($v_header_list[$i])) != 1) {
+ // ----- Close the zip file
+ $this->privCloseFd();
+ $v_temp_zip->privCloseFd();
+ @unlink($v_zip_temp_name);
+
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Read/write the data block
+ if (($v_result = PclZipUtilCopyBlock($this->zip_fd, $v_temp_zip->zip_fd, $v_header_list[$i]['compressed_size'])) != 1) {
+ // ----- Close the zip file
+ $this->privCloseFd();
+ $v_temp_zip->privCloseFd();
+ @unlink($v_zip_temp_name);
+
+ // ----- Return
+ return $v_result;
+ }
+ }
+
+ // ----- Store the offset of the central dir
+ $v_offset = @ftell($v_temp_zip->zip_fd);
+
+ // ----- Re-Create the Central Dir files header
+ for ($i=0; $iprivWriteCentralFileHeader($v_header_list[$i])) != 1) {
+ $v_temp_zip->privCloseFd();
+ $this->privCloseFd();
+ @unlink($v_zip_temp_name);
+
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Transform the header to a 'usable' info
+ $v_temp_zip->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
+ }
+
+
+ // ----- Zip file comment
+ $v_comment = '';
+ if (isset($p_options[PCLZIP_OPT_COMMENT])) {
+ $v_comment = $p_options[PCLZIP_OPT_COMMENT];
+ }
+
+ // ----- Calculate the size of the central header
+ $v_size = @ftell($v_temp_zip->zip_fd)-$v_offset;
+
+ // ----- Create the central dir footer
+ if (($v_result = $v_temp_zip->privWriteCentralHeader(sizeof($v_header_list), $v_size, $v_offset, $v_comment)) != 1) {
+ // ----- Reset the file list
+ unset($v_header_list);
+ $v_temp_zip->privCloseFd();
+ $this->privCloseFd();
+ @unlink($v_zip_temp_name);
+
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Close
+ $v_temp_zip->privCloseFd();
+ $this->privCloseFd();
+
+ // ----- Delete the zip file
+ // TBC : I should test the result ...
+ @unlink($this->zipname);
+
+ // ----- Rename the temporary file
+ // TBC : I should test the result ...
+ //@rename($v_zip_temp_name, $this->zipname);
+ PclZipUtilRename($v_zip_temp_name, $this->zipname);
+
+ // ----- Destroy the temporary archive
+ unset($v_temp_zip);
+ } else if ($v_central_dir['entries'] != 0) {
+ // ----- Remove every files : reset the file
+ $this->privCloseFd();
+
+ if (($v_result = $this->privOpenFd('wb')) != 1) {
+ return $v_result;
+ }
+
+ if (($v_result = $this->privWriteCentralHeader(0, 0, 0, '')) != 1) {
+ return $v_result;
+ }
+
+ $this->privCloseFd();
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privDirCheck()
+ // Description :
+ // Check if a directory exists, if not it creates it and all the parents directory
+ // which may be useful.
+ // Parameters :
+ // $p_dir : Directory path to check.
+ // Return Values :
+ // 1 : OK
+ // -1 : Unable to create directory
+ // --------------------------------------------------------------------------------
+ function privDirCheck($p_dir, $p_is_dir = false)
+ {
+ $v_result = 1;
+
+ // ----- Remove the final '/'
+ if (($p_is_dir) && (substr($p_dir, -1)=='/')) {
+ $p_dir = substr($p_dir, 0, strlen($p_dir)-1);
+ }
+
+ // ----- Check the directory availability
+ if ((is_dir($p_dir)) || ($p_dir == "")) {
+ return 1;
+ }
+
+ // ----- Extract parent directory
+ $p_parent_dir = dirname($p_dir);
+
+ // ----- Just a check
+ if ($p_parent_dir != $p_dir) {
+ // ----- Look for parent directory
+ if ($p_parent_dir != "") {
+ if (($v_result = $this->privDirCheck($p_parent_dir)) != 1) {
+ return $v_result;
+ }
+ }
+ }
+
+ // ----- Create the directory
+ if (!@mkdir($p_dir, 0777)) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL, "Unable to create directory '$p_dir'");
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privMerge()
+ // Description :
+ // If $p_archive_to_add does not exist, the function exit with a success result.
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privMerge(&$p_archive_to_add)
+ {
+ $v_result=1;
+
+ // ----- Look if the archive_to_add exists
+ if (!is_file($p_archive_to_add->zipname)) {
+
+ // ----- Nothing to merge, so merge is a success
+ $v_result = 1;
+
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Look if the archive exists
+ if (!is_file($this->zipname)) {
+
+ // ----- Do a duplicate
+ $v_result = $this->privDuplicate($p_archive_to_add->zipname);
+
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Open the zip file
+ if (($v_result=$this->privOpenFd('rb')) != 1) {
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Read the central directory informations
+ $v_central_dir = array();
+ if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) {
+ $this->privCloseFd();
+ return $v_result;
+ }
+
+ // ----- Go to beginning of File
+ @rewind($this->zip_fd);
+
+ // ----- Open the archive_to_add file
+ if (($v_result=$p_archive_to_add->privOpenFd('rb')) != 1) {
+ $this->privCloseFd();
+
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Read the central directory informations
+ $v_central_dir_to_add = array();
+ if (($v_result = $p_archive_to_add->privReadEndCentralDir($v_central_dir_to_add)) != 1) {
+ $this->privCloseFd();
+ $p_archive_to_add->privCloseFd();
+
+ return $v_result;
+ }
+
+ // ----- Go to beginning of File
+ @rewind($p_archive_to_add->zip_fd);
+
+ // ----- Creates a temporay file
+ $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
+
+ // ----- Open the temporary file in write mode
+ if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) {
+ $this->privCloseFd();
+ $p_archive_to_add->privCloseFd();
+
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Copy the files from the archive to the temporary file
+ // TBC : Here I should better append the file and go back to erase the central dir
+ $v_size = $v_central_dir['offset'];
+ while ($v_size != 0) {
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
+ $v_buffer = fread($this->zip_fd, $v_read_size);
+ @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
+ $v_size -= $v_read_size;
+ }
+
+ // ----- Copy the files from the archive_to_add into the temporary file
+ $v_size = $v_central_dir_to_add['offset'];
+ while ($v_size != 0) {
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
+ $v_buffer = fread($p_archive_to_add->zip_fd, $v_read_size);
+ @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
+ $v_size -= $v_read_size;
+ }
+
+ // ----- Store the offset of the central dir
+ $v_offset = @ftell($v_zip_temp_fd);
+
+ // ----- Copy the block of file headers from the old archive
+ $v_size = $v_central_dir['size'];
+ while ($v_size != 0) {
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
+ $v_buffer = @fread($this->zip_fd, $v_read_size);
+ @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
+ $v_size -= $v_read_size;
+ }
+
+ // ----- Copy the block of file headers from the archive_to_add
+ $v_size = $v_central_dir_to_add['size'];
+ while ($v_size != 0) {
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
+ $v_buffer = @fread($p_archive_to_add->zip_fd, $v_read_size);
+ @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
+ $v_size -= $v_read_size;
+ }
+
+ // ----- Merge the file comments
+ $v_comment = $v_central_dir['comment'].' '.$v_central_dir_to_add['comment'];
+
+ // ----- Calculate the size of the (new) central header
+ $v_size = @ftell($v_zip_temp_fd)-$v_offset;
+
+ // ----- Swap the file descriptor
+ // Here is a trick : I swap the temporary fd with the zip fd, in order to use
+ // the following methods on the temporary fil and not the real archive fd
+ $v_swap = $this->zip_fd;
+ $this->zip_fd = $v_zip_temp_fd;
+ $v_zip_temp_fd = $v_swap;
+
+ // ----- Create the central dir footer
+ if (($v_result = $this->privWriteCentralHeader($v_central_dir['entries']+$v_central_dir_to_add['entries'], $v_size, $v_offset, $v_comment)) != 1) {
+ $this->privCloseFd();
+ $p_archive_to_add->privCloseFd();
+ @fclose($v_zip_temp_fd);
+ $this->zip_fd = null;
+
+ // ----- Reset the file list
+ unset($v_header_list);
+
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Swap back the file descriptor
+ $v_swap = $this->zip_fd;
+ $this->zip_fd = $v_zip_temp_fd;
+ $v_zip_temp_fd = $v_swap;
+
+ // ----- Close
+ $this->privCloseFd();
+ $p_archive_to_add->privCloseFd();
+
+ // ----- Close the temporary file
+ @fclose($v_zip_temp_fd);
+
+ // ----- Delete the zip file
+ // TBC : I should test the result ...
+ @unlink($this->zipname);
+
+ // ----- Rename the temporary file
+ // TBC : I should test the result ...
+ //@rename($v_zip_temp_name, $this->zipname);
+ PclZipUtilRename($v_zip_temp_name, $this->zipname);
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privDuplicate()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privDuplicate($p_archive_filename)
+ {
+ $v_result=1;
+
+ // ----- Look if the $p_archive_filename exists
+ if (!is_file($p_archive_filename)) {
+
+ // ----- Nothing to duplicate, so duplicate is a success.
+ $v_result = 1;
+
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Open the zip file
+ if (($v_result=$this->privOpenFd('wb')) != 1) {
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Open the temporary file in write mode
+ if (($v_zip_temp_fd = @fopen($p_archive_filename, 'rb')) == 0) {
+ $this->privCloseFd();
+
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive file \''.$p_archive_filename.'\' in binary write mode');
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Copy the files from the archive to the temporary file
+ // TBC : Here I should better append the file and go back to erase the central dir
+ $v_size = filesize($p_archive_filename);
+ while ($v_size != 0) {
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
+ $v_buffer = fread($v_zip_temp_fd, $v_read_size);
+ @fwrite($this->zip_fd, $v_buffer, $v_read_size);
+ $v_size -= $v_read_size;
+ }
+
+ // ----- Close
+ $this->privCloseFd();
+
+ // ----- Close the temporary file
+ @fclose($v_zip_temp_fd);
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privErrorLog()
+ // Description :
+ // Parameters :
+ // --------------------------------------------------------------------------------
+ function privErrorLog($p_error_code = 0, $p_error_string = '')
+ {
+ if (PCLZIP_ERROR_EXTERNAL == 1) {
+ PclError($p_error_code, $p_error_string);
+ } else {
+ $this->error_code = $p_error_code;
+ $this->error_string = $p_error_string;
+ }
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privErrorReset()
+ // Description :
+ // Parameters :
+ // --------------------------------------------------------------------------------
+ function privErrorReset()
+ {
+ if (PCLZIP_ERROR_EXTERNAL == 1) {
+ PclErrorReset();
+ } else {
+ $this->error_code = 0;
+ $this->error_string = '';
+ }
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privDisableMagicQuotes()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privDisableMagicQuotes()
+ {
+ $v_result=1;
+
+ // ----- Look if function exists
+ if ((!function_exists("get_magic_quotes_runtime")) || (!function_exists("set_magic_quotes_runtime"))) {
+ return $v_result;
+ }
+
+ // ----- Look if already done
+ if ($this->magic_quotes_status != -1) {
+ return $v_result;
+ }
+
+ // ----- Get and memorize the magic_quote value
+ $this->magic_quotes_status = @get_magic_quotes_runtime();
+
+ // ----- Disable magic_quotes
+ if ($this->magic_quotes_status == 1) {
+ @set_magic_quotes_runtime(0);
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privSwapBackMagicQuotes()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privSwapBackMagicQuotes()
+ {
+ $v_result=1;
+
+ // ----- Look if function exists
+ if ((!function_exists("get_magic_quotes_runtime")) || (!function_exists("set_magic_quotes_runtime"))) {
+ return $v_result;
+ }
+
+ // ----- Look if something to do
+ if ($this->magic_quotes_status != -1) {
+ return $v_result;
+ }
+
+ // ----- Swap back magic_quotes
+ if ($this->magic_quotes_status == 1) {
+ @set_magic_quotes_runtime($this->magic_quotes_status);
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+}
+// End of class
+// --------------------------------------------------------------------------------
+
+// --------------------------------------------------------------------------------
+// Function : PclZipUtilPathReduction()
+// Description :
+// Parameters :
+// Return Values :
+// --------------------------------------------------------------------------------
+function PclZipUtilPathReduction($p_dir)
+{
+ $v_result = "";
+
+ // ----- Look for not empty path
+ if ($p_dir != "") {
+ // ----- Explode path by directory names
+ $v_list = explode("/", $p_dir);
+
+ // ----- Study directories from last to first
+ $v_skip = 0;
+ for ($i=sizeof($v_list)-1; $i>=0; $i--) {
+ // ----- Look for current path
+ if ($v_list[$i] == ".") {
+ // ----- Ignore this directory
+ // Should be the first $i=0, but no check is done
+ } else if ($v_list[$i] == "..") {
+ $v_skip++;
+ } else if ($v_list[$i] == "") {
+ // ----- First '/' i.e. root slash
+ if ($i == 0) {
+ $v_result = "/".$v_result;
+ if ($v_skip > 0) {
+ // ----- It is an invalid path, so the path is not modified
+ // TBC
+ $v_result = $p_dir;
+ $v_skip = 0;
+ }
+ } else if ($i == (sizeof($v_list)-1)) {
+ // ----- Last '/' i.e. indicates a directory
+ $v_result = $v_list[$i];
+ } else {
+ // ----- Double '/' inside the path
+ // ----- Ignore only the double '//' in path,
+ // but not the first and last '/'
+ }
+ } else {
+ // ----- Look for item to skip
+ if ($v_skip > 0) {
+ $v_skip--;
+ }
+ else {
+ $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:"");
+ }
+ }
+ }
+
+ // ----- Look for skip
+ if ($v_skip > 0) {
+ while ($v_skip > 0) {
+ $v_result = '../'.$v_result;
+ $v_skip--;
+ }
+ }
+ }
+
+ // ----- Return
+ return $v_result;
+}
+// --------------------------------------------------------------------------------
+
+// --------------------------------------------------------------------------------
+// Function : PclZipUtilPathInclusion()
+// Description :
+// This function indicates if the path $p_path is under the $p_dir tree. Or,
+// said in an other way, if the file or sub-dir $p_path is inside the dir
+// $p_dir.
+// The function indicates also if the path is exactly the same as the dir.
+// This function supports path with duplicated '/' like '//', but does not
+// support '.' or '..' statements.
+// Parameters :
+// Return Values :
+// 0 if $p_path is not inside directory $p_dir
+// 1 if $p_path is inside directory $p_dir
+// 2 if $p_path is exactly the same as $p_dir
+// --------------------------------------------------------------------------------
+function PclZipUtilPathInclusion($p_dir, $p_path)
+{
+ $v_result = 1;
+
+ // ----- Look for path beginning by ./
+ if (($p_dir == '.') || ((strlen($p_dir) >=2) && (substr($p_dir, 0, 2) == './'))) {
+ $p_dir = PclZipUtilTranslateWinPath(getcwd(), false).'/'.substr($p_dir, 1);
+ }
+ if (($p_path == '.') || ((strlen($p_path) >=2) && (substr($p_path, 0, 2) == './'))) {
+ $p_path = PclZipUtilTranslateWinPath(getcwd(), false).'/'.substr($p_path, 1);
+ }
+
+ // ----- Explode dir and path by directory separator
+ $v_list_dir = explode("/", $p_dir);
+ $v_list_dir_size = sizeof($v_list_dir);
+ $v_list_path = explode("/", $p_path);
+ $v_list_path_size = sizeof($v_list_path);
+
+ // ----- Study directories paths
+ $i = 0;
+ $j = 0;
+ while (($i < $v_list_dir_size) && ($j < $v_list_path_size) && ($v_result)) {
+ // ----- Look for empty dir (path reduction)
+ if ($v_list_dir[$i] == '') {
+ $i++;
+ continue;
+ }
+ if ($v_list_path[$j] == '') {
+ $j++;
+ continue;
+ }
+
+ // ----- Compare the items
+ if (($v_list_dir[$i] != $v_list_path[$j]) && ($v_list_dir[$i] != '') && ($v_list_path[$j] != '')) {
+ $v_result = 0;
+ }
+
+ // ----- Next items
+ $i++;
+ $j++;
+ }
+
+ // ----- Look if everything seems to be the same
+ if ($v_result) {
+ // ----- Skip all the empty items
+ while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) $j++;
+ while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) $i++;
+
+ if (($i >= $v_list_dir_size) && ($j >= $v_list_path_size)) {
+ // ----- There are exactly the same
+ $v_result = 2;
+ } else if ($i < $v_list_dir_size) {
+ // ----- The path is shorter than the dir
+ $v_result = 0;
+ }
+ }
+
+ // ----- Return
+ return $v_result;
+}
+// --------------------------------------------------------------------------------
+
+// --------------------------------------------------------------------------------
+// Function : PclZipUtilCopyBlock()
+// Description :
+// Parameters :
+// $p_mode : read/write compression mode
+// 0 : src & dest normal
+// 1 : src gzip, dest normal
+// 2 : src normal, dest gzip
+// 3 : src & dest gzip
+// Return Values :
+// --------------------------------------------------------------------------------
+function PclZipUtilCopyBlock($p_src, $p_dest, $p_size, $p_mode = 0)
+{
+ $v_result = 1;
+
+ if ($p_mode==0) {
+ while ($p_size != 0) {
+ $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
+ $v_buffer = @fread($p_src, $v_read_size);
+ @fwrite($p_dest, $v_buffer, $v_read_size);
+ $p_size -= $v_read_size;
+ }
+ } else if ($p_mode==1) {
+ while ($p_size != 0) {
+ $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
+ $v_buffer = @gzread($p_src, $v_read_size);
+ @fwrite($p_dest, $v_buffer, $v_read_size);
+ $p_size -= $v_read_size;
+ }
+ } else if ($p_mode==2) {
+ while ($p_size != 0) {
+ $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
+ $v_buffer = @fread($p_src, $v_read_size);
+ @gzwrite($p_dest, $v_buffer, $v_read_size);
+ $p_size -= $v_read_size;
+ }
+ } else if ($p_mode==3) {
+ while ($p_size != 0) {
+ $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
+ $v_buffer = @gzread($p_src, $v_read_size);
+ @gzwrite($p_dest, $v_buffer, $v_read_size);
+ $p_size -= $v_read_size;
+ }
+ }
+
+ // ----- Return
+ return $v_result;
+}
+// --------------------------------------------------------------------------------
+
+// --------------------------------------------------------------------------------
+// Function : PclZipUtilRename()
+// Description :
+// This function tries to do a simple rename() function. If it fails, it
+// tries to copy the $p_src file in a new $p_dest file and then unlink the
+// first one.
+// Parameters :
+// $p_src : Old filename
+// $p_dest : New filename
+// Return Values :
+// 1 on success, 0 on failure.
+// --------------------------------------------------------------------------------
+function PclZipUtilRename($p_src, $p_dest)
+{
+ $v_result = 1;
+
+ // ----- Try to rename the files
+ if (!@rename($p_src, $p_dest)) {
+ // ----- Try to copy & unlink the src
+ if (!@copy($p_src, $p_dest)) {
+ $v_result = 0;
+ } else if (!@unlink($p_src)) {
+ $v_result = 0;
+ }
+ }
+
+ // ----- Return
+ return $v_result;
+}
+// --------------------------------------------------------------------------------
+
+// --------------------------------------------------------------------------------
+// Function : PclZipUtilOptionText()
+// Description :
+// Translate option value in text. Mainly for debug purpose.
+// Parameters :
+// $p_option : the option value.
+// Return Values :
+// The option text value.
+// --------------------------------------------------------------------------------
+function PclZipUtilOptionText($p_option)
+{
+
+ $v_list = get_defined_constants();
+ for (reset($v_list); $v_key = key($v_list); next($v_list)) {
+ $v_prefix = substr($v_key, 0, 10);
+ if ((($v_prefix == 'PCLZIP_OPT') || ($v_prefix == 'PCLZIP_CB_') || ($v_prefix == 'PCLZIP_ATT')) && ($v_list[$v_key] == $p_option)) {
+ return $v_key;
+ }
+ }
+
+ $v_result = 'Unknown';
+
+ return $v_result;
+}
+// --------------------------------------------------------------------------------
+
+// --------------------------------------------------------------------------------
+// Function : PclZipUtilTranslateWinPath()
+// Description :
+// Translate windows path by replacing '\' by '/' and optionally removing
+// drive letter.
+// Parameters :
+// $p_path : path to translate.
+// $p_remove_disk_letter : true | false
+// Return Values :
+// The path translated.
+// --------------------------------------------------------------------------------
+function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter = true)
+{
+ if (stristr(php_uname(), 'windows')) {
+ // ----- Look for potential disk letter
+ if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) {
+ $p_path = substr($p_path, $v_position+1);
+ }
+ // ----- Change potential windows directory separator
+ if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) {
+ $p_path = strtr($p_path, '\\', '/');
+ }
+ }
+ return $p_path;
+}
+// --------------------------------------------------------------------------------
\ No newline at end of file
diff --git a/Classes/PHPExcel/Shared/PasswordHasher.php b/Classes/PHPExcel/Shared/PasswordHasher.php
index 92c8b3f9..946742bf 100644
--- a/Classes/PHPExcel/Shared/PasswordHasher.php
+++ b/Classes/PHPExcel/Shared/PasswordHasher.php
@@ -45,8 +45,9 @@ class PHPExcel_Shared_PasswordHasher
* @param string $pPassword Password to hash
* @return string Hashed password
*/
- public static function hashPassword($pPassword = '') {
- $password = 0x0000;
+ public static function hashPassword($pPassword = '')
+ {
+ $password = 0x0000;
$charPos = 1; // char position
// split the plain text password in its component characters
diff --git a/Classes/PHPExcel/Shared/String.php b/Classes/PHPExcel/Shared/String.php
index 513a1755..c32a3bb8 100644
--- a/Classes/PHPExcel/Shared/String.php
+++ b/Classes/PHPExcel/Shared/String.php
@@ -93,10 +93,11 @@ class PHPExcel_Shared_String
/**
* Build control characters array
*/
- private static function _buildControlCharacters() {
+ private static function _buildControlCharacters()
+ {
for ($i = 0; $i <= 31; ++$i) {
if ($i != 9 && $i != 10 && $i != 13) {
- $find = '_x' . sprintf('%04s' , strtoupper(dechex($i))) . '_';
+ $find = '_x' . sprintf('%04s', strtoupper(dechex($i))) . '_';
$replace = chr($i);
self::$_controlCharacters[$find] = $replace;
}
@@ -316,10 +317,7 @@ class PHPExcel_Shared_String
}
// CUSTOM: IBM AIX iconv() does not work
- if ( defined('PHP_OS') && @stristr(PHP_OS, 'AIX')
- && defined('ICONV_IMPL') && (@strcasecmp(ICONV_IMPL, 'unknown') == 0)
- && defined('ICONV_VERSION') && (@strcasecmp(ICONV_VERSION, 'unknown') == 0) )
- {
+ if (defined('PHP_OS') && @stristr(PHP_OS, 'AIX') && defined('ICONV_IMPL') && (@strcasecmp(ICONV_IMPL, 'unknown') == 0) && defined('ICONV_VERSION') && (@strcasecmp(ICONV_VERSION, 'unknown') == 0)) {
self::$_isIconvEnabled = false;
return false;
}
@@ -329,7 +327,8 @@ class PHPExcel_Shared_String
return true;
}
- public static function buildCharacterSets() {
+ public static function buildCharacterSets()
+ {
if (empty(self::$_controlCharacters)) {
self::_buildControlCharacters();
}
@@ -352,8 +351,9 @@ class PHPExcel_Shared_String
* @param string $value Value to unescape
* @return string
*/
- public static function ControlCharacterOOXML2PHP($value = '') {
- return str_replace( array_keys(self::$_controlCharacters), array_values(self::$_controlCharacters), $value );
+ public static function ControlCharacterOOXML2PHP($value = '')
+ {
+ return str_replace(array_keys(self::$_controlCharacters), array_values(self::$_controlCharacters), $value);
}
/**
@@ -370,8 +370,9 @@ class PHPExcel_Shared_String
* @param string $value Value to escape
* @return string
*/
- public static function ControlCharacterPHP2OOXML($value = '') {
- return str_replace( array_values(self::$_controlCharacters), array_keys(self::$_controlCharacters), $value );
+ public static function ControlCharacterPHP2OOXML($value = '')
+ {
+ return str_replace(array_values(self::$_controlCharacters), array_keys(self::$_controlCharacters), $value);
}
/**
@@ -402,7 +403,8 @@ class PHPExcel_Shared_String
* @param string $value
* @return boolean
*/
- public static function IsUTF8($value = '') {
+ public static function IsUTF8($value = '')
+ {
return $value === '' || preg_match('/^./su', $value) === 1;
}
@@ -413,7 +415,8 @@ class PHPExcel_Shared_String
* @param mixed $value
* @return string
*/
- public static function FormatNumber($value) {
+ public static function FormatNumber($value)
+ {
if (is_float($value)) {
return str_replace(',', '.', $value);
}
@@ -523,17 +526,29 @@ class PHPExcel_Shared_String
* @author Rasmus Andersson {@link http://rasmusandersson.se/}
* @author vadik56
*/
- public static function utf16_decode($str, $bom_be = TRUE) {
- if ( strlen($str) < 2 ) return $str;
+ public static function utf16_decode($str, $bom_be = true)
+ {
+ if (strlen($str) < 2) {
+ return $str;
+ }
$c0 = ord($str{0});
$c1 = ord($str{1});
- if ( $c0 == 0xfe && $c1 == 0xff ) { $str = substr($str,2); }
- elseif ( $c0 == 0xff && $c1 == 0xfe ) { $str = substr($str,2); $bom_be = false; }
+ if ($c0 == 0xfe && $c1 == 0xff) {
+ $str = substr($str, 2);
+ } elseif ($c0 == 0xff && $c1 == 0xfe) {
+ $str = substr($str, 2);
+ $bom_be = false;
+ }
$len = strlen($str);
$newstr = '';
- for($i=0;$i<$len;$i+=2) {
- if ( $bom_be ) { $val = ord($str{$i}) << 4; $val += ord($str{$i+1}); }
- else { $val = ord($str{$i+1}) << 4; $val += ord($str{$i}); }
+ for ($i=0; $i<$len; $i+=2) {
+ if ($bom_be) {
+ $val = ord($str{$i}) << 4;
+ $val += ord($str{$i+1});
+ } else {
+ $val = ord($str{$i+1}) << 4;
+ $val += ord($str{$i});
+ }
$newstr .= ($val == 0x228) ? "\n" : chr($val);
}
return $newstr;
@@ -634,7 +649,7 @@ class PHPExcel_Shared_String
{
# Split at all position not after the start: ^
# and not before the end: $
- return preg_split('/(?getTransitions();
$transitions = array();
foreach ($allTransitions as $key => $transition) {
@@ -114,7 +118,8 @@ class PHPExcel_Shared_TimeZone
* @return integer Number of seconds for timezone adjustment
* @throws PHPExcel_Exception
*/
- public static function getTimeZoneAdjustment($timezone, $timestamp) {
+ public static function getTimeZoneAdjustment($timezone, $timestamp)
+ {
if ($timezone !== null) {
if (!self::_validateTimezone($timezone)) {
throw new PHPExcel_Exception("Invalid timezone " . $timezone);
diff --git a/Classes/PHPExcel/Shared/XMLWriter.php b/Classes/PHPExcel/Shared/XMLWriter.php
index 63d2f400..7b3b5a16 100644
--- a/Classes/PHPExcel/Shared/XMLWriter.php
+++ b/Classes/PHPExcel/Shared/XMLWriter.php
@@ -26,14 +26,13 @@
*/
if (!defined('DATE_W3C')) {
- define('DATE_W3C', 'Y-m-d\TH:i:sP');
+ define('DATE_W3C', 'Y-m-d\TH:i:sP');
}
if (!defined('DEBUGMODE_ENABLED')) {
- define('DEBUGMODE_ENABLED', false);
+ define('DEBUGMODE_ENABLED', false);
}
-
/**
* PHPExcel_Shared_XMLWriter
*
@@ -41,17 +40,18 @@ if (!defined('DEBUGMODE_ENABLED')) {
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
-class PHPExcel_Shared_XMLWriter extends XMLWriter {
+class PHPExcel_Shared_XMLWriter extends XMLWriter
+{
/** Temporary storage method */
const STORAGE_MEMORY = 1;
- const STORAGE_DISK = 2;
+ const STORAGE_DISK = 2;
/**
* Temporary filename
*
* @var string
*/
- private $_tempFileName = '';
+ private $_tempFileName = '';
/**
* Create a new PHPExcel_Shared_XMLWriter instance
@@ -59,14 +59,16 @@ class PHPExcel_Shared_XMLWriter extends XMLWriter {
* @param int $pTemporaryStorage Temporary storage location
* @param string $pTemporaryStorageFolder Temporary storage folder
*/
- public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageFolder = NULL) {
+ public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageFolder = null)
+ {
// Open temporary storage
if ($pTemporaryStorage == self::STORAGE_MEMORY) {
$this->openMemory();
} else {
// Create temporary filename
- if ($pTemporaryStorageFolder === NULL)
+ if ($pTemporaryStorageFolder === null) {
$pTemporaryStorageFolder = PHPExcel_Shared_File::sys_get_temp_dir();
+ }
$this->_tempFileName = @tempnam($pTemporaryStorageFolder, 'xml');
// Open storage
@@ -85,7 +87,8 @@ class PHPExcel_Shared_XMLWriter extends XMLWriter {
/**
* Destructor
*/
- public function __destruct() {
+ public function __destruct()
+ {
// Unlink temporary files
if ($this->_tempFileName != '') {
@unlink($this->_tempFileName);
@@ -97,7 +100,8 @@ class PHPExcel_Shared_XMLWriter extends XMLWriter {
*
* @return $data
*/
- public function getData() {
+ public function getData()
+ {
if ($this->_tempFileName == '') {
return $this->outputMemory(true);
} else {
diff --git a/Classes/PHPExcel/Shared/ZipArchive.php b/Classes/PHPExcel/Shared/ZipArchive.php
index 5fe68297..f795350a 100644
--- a/Classes/PHPExcel/Shared/ZipArchive.php
+++ b/Classes/PHPExcel/Shared/ZipArchive.php
@@ -92,10 +92,7 @@ class PHPExcel_Shared_ZipArchive
fwrite($handle, $contents);
fclose($handle);
- $res = $this->_zip->add($this->_tempDir.'/'.$filenameParts["basename"],
- PCLZIP_OPT_REMOVE_PATH, $this->_tempDir,
- PCLZIP_OPT_ADD_PATH, $filenameParts["dirname"]
- );
+ $res = $this->_zip->add($this->_tempDir.'/'.$filenameParts["basename"], PCLZIP_OPT_REMOVE_PATH, $this->_tempDir, PCLZIP_OPT_ADD_PATH, $filenameParts["dirname"]);
if ($res == 0) {
throw new PHPExcel_Writer_Exception("Error zipping files : " . $this->_zip->errorInfo(true));
}
diff --git a/Classes/PHPExcel/Shared/ZipStreamWrapper.php b/Classes/PHPExcel/Shared/ZipStreamWrapper.php
index 254849df..c96cffe1 100644
--- a/Classes/PHPExcel/Shared/ZipStreamWrapper.php
+++ b/Classes/PHPExcel/Shared/ZipStreamWrapper.php
@@ -25,11 +25,12 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
*/
-class PHPExcel_Shared_ZipStreamWrapper {
+class PHPExcel_Shared_ZipStreamWrapper
+{
/**
* Internal ZipAcrhive
*
- * @var ZipAcrhive
+ * @var ZipArchive
*/
private $_archive;
diff --git a/Classes/PHPExcel/Shared/trend/bestFitClass.php b/Classes/PHPExcel/Shared/trend/bestFitClass.php
index c508fbd4..1e547b2f 100644
--- a/Classes/PHPExcel/Shared/trend/bestFitClass.php
+++ b/Classes/PHPExcel/Shared/trend/bestFitClass.php
@@ -25,7 +25,6 @@
* @version ##VERSION##, ##DATE##
*/
-
/**
* PHPExcel_Best_Fit
*
@@ -40,7 +39,7 @@ class PHPExcel_Best_Fit
*
* @var boolean
**/
- protected $_error = False;
+ protected $_error = false;
/**
* Algorithm type to use for best-fit
@@ -75,7 +74,7 @@ class PHPExcel_Best_Fit
*
* @var boolean
**/
- protected $_adjustToZero = False;
+ protected $_adjustToZero = false;
/**
* Y-value series of best-fit values
@@ -113,205 +112,207 @@ class PHPExcel_Best_Fit
protected $_Yoffset = 0;
- public function getError() {
+ public function getError()
+ {
return $this->_error;
} // function getBestFitType()
- public function getBestFitType() {
+ public function getBestFitType()
+ {
return $this->_bestFitType;
} // function getBestFitType()
-
/**
* Return the Y-Value for a specified value of X
*
* @param float $xValue X-Value
* @return float Y-Value
*/
- public function getValueOfYForX($xValue) {
- return False;
+ public function getValueOfYForX($xValue)
+ {
+ return false;
} // function getValueOfYForX()
-
/**
* Return the X-Value for a specified value of Y
*
* @param float $yValue Y-Value
* @return float X-Value
*/
- public function getValueOfXForY($yValue) {
- return False;
+ public function getValueOfXForY($yValue)
+ {
+ return false;
} // function getValueOfXForY()
-
/**
* Return the original set of X-Values
*
* @return float[] X-Values
*/
- public function getXValues() {
+ public function getXValues()
+ {
return $this->_xValues;
} // function getValueOfXForY()
-
/**
* Return the Equation of the best-fit line
*
* @param int $dp Number of places of decimal precision to display
* @return string
*/
- public function getEquation($dp=0) {
- return False;
+ public function getEquation($dp = 0)
+ {
+ return false;
} // function getEquation()
-
/**
* Return the Slope of the line
*
* @param int $dp Number of places of decimal precision to display
* @return string
*/
- public function getSlope($dp=0) {
+ public function getSlope($dp = 0)
+ {
if ($dp != 0) {
return round($this->_slope, $dp);
}
return $this->_slope;
} // function getSlope()
-
/**
* Return the standard error of the Slope
*
* @param int $dp Number of places of decimal precision to display
* @return string
*/
- public function getSlopeSE($dp=0) {
+ public function getSlopeSE($dp = 0)
+ {
if ($dp != 0) {
return round($this->_slopeSE, $dp);
}
return $this->_slopeSE;
} // function getSlopeSE()
-
/**
* Return the Value of X where it intersects Y = 0
*
* @param int $dp Number of places of decimal precision to display
* @return string
*/
- public function getIntersect($dp=0) {
+ public function getIntersect($dp = 0)
+ {
if ($dp != 0) {
return round($this->_intersect, $dp);
}
return $this->_intersect;
} // function getIntersect()
-
/**
* Return the standard error of the Intersect
*
* @param int $dp Number of places of decimal precision to display
* @return string
*/
- public function getIntersectSE($dp=0) {
+ public function getIntersectSE($dp = 0)
+ {
if ($dp != 0) {
return round($this->_intersectSE, $dp);
}
return $this->_intersectSE;
} // function getIntersectSE()
-
/**
* Return the goodness of fit for this regression
*
* @param int $dp Number of places of decimal precision to return
* @return float
*/
- public function getGoodnessOfFit($dp=0) {
+ public function getGoodnessOfFit($dp = 0)
+ {
if ($dp != 0) {
return round($this->_goodnessOfFit, $dp);
}
return $this->_goodnessOfFit;
} // function getGoodnessOfFit()
-
- public function getGoodnessOfFitPercent($dp=0) {
+ public function getGoodnessOfFitPercent($dp = 0)
+ {
if ($dp != 0) {
return round($this->_goodnessOfFit * 100, $dp);
}
return $this->_goodnessOfFit * 100;
} // function getGoodnessOfFitPercent()
-
/**
* Return the standard deviation of the residuals for this regression
*
* @param int $dp Number of places of decimal precision to return
* @return float
*/
- public function getStdevOfResiduals($dp=0) {
+ public function getStdevOfResiduals($dp = 0)
+ {
if ($dp != 0) {
return round($this->_stdevOfResiduals, $dp);
}
return $this->_stdevOfResiduals;
} // function getStdevOfResiduals()
-
- public function getSSRegression($dp=0) {
+ public function getSSRegression($dp = 0)
+ {
if ($dp != 0) {
return round($this->_SSRegression, $dp);
}
return $this->_SSRegression;
} // function getSSRegression()
-
- public function getSSResiduals($dp=0) {
+ public function getSSResiduals($dp = 0)
+ {
if ($dp != 0) {
return round($this->_SSResiduals, $dp);
}
return $this->_SSResiduals;
} // function getSSResiduals()
-
- public function getDFResiduals($dp=0) {
+ public function getDFResiduals($dp = 0)
+ {
if ($dp != 0) {
return round($this->_DFResiduals, $dp);
}
return $this->_DFResiduals;
} // function getDFResiduals()
-
- public function getF($dp=0) {
+ public function getF($dp = 0)
+ {
if ($dp != 0) {
return round($this->_F, $dp);
}
return $this->_F;
} // function getF()
-
- public function getCovariance($dp=0) {
+ public function getCovariance($dp = 0)
+ {
if ($dp != 0) {
return round($this->_covariance, $dp);
}
return $this->_covariance;
} // function getCovariance()
-
- public function getCorrelation($dp=0) {
+ public function getCorrelation($dp = 0)
+ {
if ($dp != 0) {
return round($this->_correlation, $dp);
}
return $this->_correlation;
} // function getCorrelation()
-
- public function getYBestFitValues() {
+ public function getYBestFitValues()
+ {
return $this->_yBestFitValues;
} // function getYBestFitValues()
-
- protected function _calculateGoodnessOfFit($sumX, $sumY, $sumX2, $sumY2, $sumXY, $meanX, $meanY, $const) {
+ protected function _calculateGoodnessOfFit($sumX, $sumY, $sumX2, $sumY2, $sumXY, $meanX, $meanY, $const)
+ {
$SSres = $SScov = $SScor = $SStot = $SSsex = 0.0;
foreach ($this->_xValues as $xKey => $xValue) {
$bestFitY = $this->_yBestFitValues[$xKey] = $this->getValueOfYForX($xValue);
@@ -346,7 +347,7 @@ class PHPExcel_Best_Fit
$this->_SSRegression = $this->_goodnessOfFit * $SStot;
$this->_covariance = $SScov / $this->_valueCount;
- $this->_correlation = ($this->_valueCount * $sumXY - $sumX * $sumY) / sqrt(($this->_valueCount * $sumX2 - pow($sumX,2)) * ($this->_valueCount * $sumY2 - pow($sumY,2)));
+ $this->_correlation = ($this->_valueCount * $sumXY - $sumX * $sumY) / sqrt(($this->_valueCount * $sumX2 - pow($sumX, 2)) * ($this->_valueCount * $sumY2 - pow($sumY, 2)));
$this->_slopeSE = $this->_stdevOfResiduals / sqrt($SSsex);
$this->_intersectSE = $this->_stdevOfResiduals * sqrt(1 / ($this->_valueCount - ($sumX * $sumX) / $sumX2));
if ($this->_SSResiduals != 0.0) {
@@ -364,15 +365,15 @@ class PHPExcel_Best_Fit
}
} // function _calculateGoodnessOfFit()
-
- protected function _leastSquareFit($yValues, $xValues, $const) {
+ protected function _leastSquareFit($yValues, $xValues, $const)
+ {
// calculate sums
$x_sum = array_sum($xValues);
$y_sum = array_sum($yValues);
$meanX = $x_sum / $this->_valueCount;
$meanY = $y_sum / $this->_valueCount;
$mBase = $mDivisor = $xx_sum = $xy_sum = $yy_sum = 0.0;
- for($i = 0; $i < $this->_valueCount; ++$i) {
+ for ($i = 0; $i < $this->_valueCount; ++$i) {
$xy_sum += $xValues[$i] * $yValues[$i];
$xx_sum += $xValues[$i] * $xValues[$i];
$yy_sum += $yValues[$i] * $yValues[$i];
@@ -401,7 +402,6 @@ class PHPExcel_Best_Fit
$this->_calculateGoodnessOfFit($x_sum, $y_sum, $xx_sum, $yy_sum, $xy_sum, $meanX, $meanY, $const);
} // function _leastSquareFit()
-
/**
* Define the regression
*
@@ -409,7 +409,8 @@ class PHPExcel_Best_Fit
* @param float[] $xValues The set of X-values for this regression
* @param boolean $const
*/
- function __construct($yValues, $xValues=array(), $const=True) {
+ public function __construct($yValues, $xValues = array(), $const = true)
+ {
// Calculate number of points
$nY = count($yValues);
$nX = count($xValues);
@@ -420,13 +421,12 @@ class PHPExcel_Best_Fit
$nX = $nY;
} elseif ($nY != $nX) {
// Ensure both arrays of points are the same size
- $this->_error = True;
- return False;
+ $this->_error = true;
+ return false;
}
$this->_valueCount = $nY;
$this->_xValues = $xValues;
$this->_yValues = $yValues;
} // function __construct()
-
-} // class bestFit
+}
diff --git a/Classes/PHPExcel/Shared/trend/exponentialBestFitClass.php b/Classes/PHPExcel/Shared/trend/exponentialBestFitClass.php
index 54243081..647bd2dc 100644
--- a/Classes/PHPExcel/Shared/trend/exponentialBestFitClass.php
+++ b/Classes/PHPExcel/Shared/trend/exponentialBestFitClass.php
@@ -46,71 +46,70 @@ class PHPExcel_Exponential_Best_Fit extends PHPExcel_Best_Fit
**/
protected $_bestFitType = 'exponential';
-
/**
* Return the Y-Value for a specified value of X
*
* @param float $xValue X-Value
* @return float Y-Value
**/
- public function getValueOfYForX($xValue) {
- return $this->getIntersect() * pow($this->getSlope(),($xValue - $this->_Xoffset));
+ public function getValueOfYForX($xValue)
+ {
+ return $this->getIntersect() * pow($this->getSlope(), ($xValue - $this->_Xoffset));
} // function getValueOfYForX()
-
/**
* Return the X-Value for a specified value of Y
*
* @param float $yValue Y-Value
* @return float X-Value
**/
- public function getValueOfXForY($yValue) {
+ public function getValueOfXForY($yValue)
+ {
return log(($yValue + $this->_Yoffset) / $this->getIntersect()) / log($this->getSlope());
} // function getValueOfXForY()
-
/**
* Return the Equation of the best-fit line
*
* @param int $dp Number of places of decimal precision to display
* @return string
**/
- public function getEquation($dp=0) {
+ public function getEquation($dp = 0)
+ {
$slope = $this->getSlope($dp);
$intersect = $this->getIntersect($dp);
return 'Y = '.$intersect.' * '.$slope.'^X';
} // function getEquation()
-
/**
* Return the Slope of the line
*
* @param int $dp Number of places of decimal precision to display
* @return string
**/
- public function getSlope($dp=0) {
+ public function getSlope($dp = 0)
+ {
if ($dp != 0) {
return round(exp($this->_slope), $dp);
}
return exp($this->_slope);
} // function getSlope()
-
/**
* Return the Value of X where it intersects Y = 0
*
* @param int $dp Number of places of decimal precision to display
* @return string
**/
- public function getIntersect($dp=0) {
+ public function getIntersect($dp = 0)
+ {
if ($dp != 0) {
return round(exp($this->_intersect), $dp);
}
return exp($this->_intersect);
} // function getIntersect()
-
/**
* Execute the regression and calculate the goodness of fit for a set of X and Y data values
*
@@ -118,7 +117,8 @@ class PHPExcel_Exponential_Best_Fit extends PHPExcel_Best_Fit
* @param float[] $xValues The set of X-values for this regression
* @param boolean $const
*/
- private function _exponential_regression($yValues, $xValues, $const) {
+ private function _exponential_regression($yValues, $xValues, $const)
+ {
foreach ($yValues as &$value) {
if ($value < 0.0) {
$value = 0 - log(abs($value));
@@ -131,7 +131,6 @@ class PHPExcel_Exponential_Best_Fit extends PHPExcel_Best_Fit
$this->_leastSquareFit($yValues, $xValues, $const);
} // function _exponential_regression()
-
/**
* Define the regression and calculate the goodness of fit for a set of X and Y data values
*
@@ -139,10 +138,10 @@ class PHPExcel_Exponential_Best_Fit extends PHPExcel_Best_Fit
* @param float[] $xValues The set of X-values for this regression
* @param boolean $const
*/
- function __construct($yValues, $xValues=array(), $const=True) {
- if (parent::__construct($yValues, $xValues) !== False) {
+ function __construct($yValues, $xValues = array(), $const = true)
+ {
+ if (parent::__construct($yValues, $xValues) !== false) {
$this->_exponential_regression($yValues, $xValues, $const);
}
} // function __construct()
-
-} // class exponentialBestFit
\ No newline at end of file
+}
diff --git a/Classes/PHPExcel/Shared/trend/linearBestFitClass.php b/Classes/PHPExcel/Shared/trend/linearBestFitClass.php
index a18d42a9..1689dd60 100644
--- a/Classes/PHPExcel/Shared/trend/linearBestFitClass.php
+++ b/Classes/PHPExcel/Shared/trend/linearBestFitClass.php
@@ -25,10 +25,8 @@
* @version ##VERSION##, ##DATE##
*/
-
require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
-
/**
* PHPExcel_Linear_Best_Fit
*
@@ -46,25 +44,25 @@ class PHPExcel_Linear_Best_Fit extends PHPExcel_Best_Fit
**/
protected $_bestFitType = 'linear';
-
/**
* Return the Y-Value for a specified value of X
*
* @param float $xValue X-Value
* @return float Y-Value
**/
- public function getValueOfYForX($xValue) {
+ public function getValueOfYForX($xValue)
+ {
return $this->getIntersect() + $this->getSlope() * $xValue;
} // function getValueOfYForX()
-
/**
* Return the X-Value for a specified value of Y
*
* @param float $yValue Y-Value
* @return float X-Value
**/
- public function getValueOfXForY($yValue) {
+ public function getValueOfXForY($yValue)
+ {
return ($yValue - $this->getIntersect()) / $this->getSlope();
} // function getValueOfXForY()
@@ -75,14 +73,14 @@ class PHPExcel_Linear_Best_Fit extends PHPExcel_Best_Fit
* @param int $dp Number of places of decimal precision to display
* @return string
**/
- public function getEquation($dp=0) {
+ public function getEquation($dp = 0)
+ {
$slope = $this->getSlope($dp);
$intersect = $this->getIntersect($dp);
return 'Y = '.$intersect.' + '.$slope.' * X';
} // function getEquation()
-
/**
* Execute the regression and calculate the goodness of fit for a set of X and Y data values
*
@@ -90,11 +88,11 @@ class PHPExcel_Linear_Best_Fit extends PHPExcel_Best_Fit
* @param float[] $xValues The set of X-values for this regression
* @param boolean $const
*/
- private function _linear_regression($yValues, $xValues, $const) {
+ private function _linear_regression($yValues, $xValues, $const)
+ {
$this->_leastSquareFit($yValues, $xValues, $const);
} // function _linear_regression()
-
/**
* Define the regression and calculate the goodness of fit for a set of X and Y data values
*
@@ -102,10 +100,10 @@ class PHPExcel_Linear_Best_Fit extends PHPExcel_Best_Fit
* @param float[] $xValues The set of X-values for this regression
* @param boolean $const
*/
- function __construct($yValues, $xValues=array(), $const=True) {
- if (parent::__construct($yValues, $xValues) !== False) {
+ function __construct($yValues, $xValues = array(), $const = true)
+ {
+ if (parent::__construct($yValues, $xValues) !== false) {
$this->_linear_regression($yValues, $xValues, $const);
}
} // function __construct()
-
-} // class linearBestFit
\ No newline at end of file
+}
diff --git a/Classes/PHPExcel/Shared/trend/logarithmicBestFitClass.php b/Classes/PHPExcel/Shared/trend/logarithmicBestFitClass.php
index b0db33e3..fa1a3d26 100644
--- a/Classes/PHPExcel/Shared/trend/logarithmicBestFitClass.php
+++ b/Classes/PHPExcel/Shared/trend/logarithmicBestFitClass.php
@@ -25,10 +25,8 @@
* @version ##VERSION##, ##DATE##
*/
-
require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
-
/**
* PHPExcel_Logarithmic_Best_Fit
*
@@ -46,43 +44,42 @@ class PHPExcel_Logarithmic_Best_Fit extends PHPExcel_Best_Fit
**/
protected $_bestFitType = 'logarithmic';
-
/**
* Return the Y-Value for a specified value of X
*
* @param float $xValue X-Value
* @return float Y-Value
**/
- public function getValueOfYForX($xValue) {
+ public function getValueOfYForX($xValue)
+ {
return $this->getIntersect() + $this->getSlope() * log($xValue - $this->_Xoffset);
} // function getValueOfYForX()
-
/**
* Return the X-Value for a specified value of Y
*
* @param float $yValue Y-Value
* @return float X-Value
**/
- public function getValueOfXForY($yValue) {
+ public function getValueOfXForY($yValue)
+ {
return exp(($yValue - $this->getIntersect()) / $this->getSlope());
} // function getValueOfXForY()
-
/**
* Return the Equation of the best-fit line
*
* @param int $dp Number of places of decimal precision to display
* @return string
**/
- public function getEquation($dp=0) {
+ public function getEquation($dp = 0)
+ {
$slope = $this->getSlope($dp);
$intersect = $this->getIntersect($dp);
return 'Y = '.$intersect.' + '.$slope.' * log(X)';
} // function getEquation()
-
/**
* Execute the regression and calculate the goodness of fit for a set of X and Y data values
*
@@ -90,7 +87,8 @@ class PHPExcel_Logarithmic_Best_Fit extends PHPExcel_Best_Fit
* @param float[] $xValues The set of X-values for this regression
* @param boolean $const
*/
- private function _logarithmic_regression($yValues, $xValues, $const) {
+ private function _logarithmic_regression($yValues, $xValues, $const)
+ {
foreach ($xValues as &$value) {
if ($value < 0.0) {
$value = 0 - log(abs($value));
@@ -103,7 +101,6 @@ class PHPExcel_Logarithmic_Best_Fit extends PHPExcel_Best_Fit
$this->_leastSquareFit($yValues, $xValues, $const);
} // function _logarithmic_regression()
-
/**
* Define the regression and calculate the goodness of fit for a set of X and Y data values
*
@@ -111,10 +108,10 @@ class PHPExcel_Logarithmic_Best_Fit extends PHPExcel_Best_Fit
* @param float[] $xValues The set of X-values for this regression
* @param boolean $const
*/
- function __construct($yValues, $xValues=array(), $const=True) {
- if (parent::__construct($yValues, $xValues) !== False) {
+ function __construct($yValues, $xValues = array(), $const = true)
+ {
+ if (parent::__construct($yValues, $xValues) !== false) {
$this->_logarithmic_regression($yValues, $xValues, $const);
}
} // function __construct()
-
-} // class logarithmicBestFit
\ No newline at end of file
+}
diff --git a/Classes/PHPExcel/Shared/trend/polynomialBestFitClass.php b/Classes/PHPExcel/Shared/trend/polynomialBestFitClass.php
index bd448433..b571f206 100644
--- a/Classes/PHPExcel/Shared/trend/polynomialBestFitClass.php
+++ b/Classes/PHPExcel/Shared/trend/polynomialBestFitClass.php
@@ -61,7 +61,8 @@ class PHPExcel_Polynomial_Best_Fit extends PHPExcel_Best_Fit
*
* @return int
**/
- public function getOrder() {
+ public function getOrder()
+ {
return $this->_order;
} // function getOrder()
@@ -72,7 +73,8 @@ class PHPExcel_Polynomial_Best_Fit extends PHPExcel_Best_Fit
* @param float $xValue X-Value
* @return float Y-Value
**/
- public function getValueOfYForX($xValue) {
+ public function getValueOfYForX($xValue)
+ {
$retVal = $this->getIntersect();
$slope = $this->getSlope();
foreach ($slope as $key => $value) {
@@ -90,7 +92,8 @@ class PHPExcel_Polynomial_Best_Fit extends PHPExcel_Best_Fit
* @param float $yValue Y-Value
* @return float X-Value
**/
- public function getValueOfXForY($yValue) {
+ public function getValueOfXForY($yValue)
+ {
return ($yValue - $this->getIntersect()) / $this->getSlope();
} // function getValueOfXForY()
@@ -101,7 +104,8 @@ class PHPExcel_Polynomial_Best_Fit extends PHPExcel_Best_Fit
* @param int $dp Number of places of decimal precision to display
* @return string
**/
- public function getEquation($dp=0) {
+ public function getEquation($dp = 0)
+ {
$slope = $this->getSlope($dp);
$intersect = $this->getIntersect($dp);
@@ -124,7 +128,8 @@ class PHPExcel_Polynomial_Best_Fit extends PHPExcel_Best_Fit
* @param int $dp Number of places of decimal precision to display
* @return string
**/
- public function getSlope($dp=0) {
+ public function getSlope($dp = 0)
+ {
if ($dp != 0) {
$coefficients = array();
foreach ($this->_slope as $coefficient) {
@@ -136,7 +141,8 @@ class PHPExcel_Polynomial_Best_Fit extends PHPExcel_Best_Fit
} // function getSlope()
- public function getCoefficients($dp=0) {
+ public function getCoefficients($dp = 0)
+ {
return array_merge(array($this->getIntersect($dp)), $this->getSlope($dp));
} // function getCoefficients()
@@ -149,12 +155,13 @@ class PHPExcel_Polynomial_Best_Fit extends PHPExcel_Best_Fit
* @param float[] $xValues The set of X-values for this regression
* @param boolean $const
*/
- private function _polynomial_regression($order, $yValues, $xValues, $const) {
+ private function _polynomial_regression($order, $yValues, $xValues, $const)
+ {
// calculate sums
$x_sum = array_sum($xValues);
$y_sum = array_sum($yValues);
$xx_sum = $xy_sum = 0;
- for($i = 0; $i < $this->_valueCount; ++$i) {
+ for ($i = 0; $i < $this->_valueCount; ++$i) {
$xy_sum += $xValues[$i] * $yValues[$i];
$xx_sum += $xValues[$i] * $xValues[$i];
$yy_sum += $yValues[$i] * $yValues[$i];
@@ -180,7 +187,7 @@ class PHPExcel_Polynomial_Best_Fit extends PHPExcel_Best_Fit
$C = $matrixA->solve($matrixB);
$coefficients = array();
- for($i = 0; $i < $C->m; ++$i) {
+ for ($i = 0; $i < $C->m; ++$i) {
$r = $C->get($i, 0);
if (abs($r) <= pow(10, -9)) {
$r = 0;
@@ -206,19 +213,19 @@ class PHPExcel_Polynomial_Best_Fit extends PHPExcel_Best_Fit
* @param float[] $xValues The set of X-values for this regression
* @param boolean $const
*/
- function __construct($order, $yValues, $xValues=array(), $const=True) {
- if (parent::__construct($yValues, $xValues) !== False) {
+ function __construct($order, $yValues, $xValues = array(), $const = true)
+ {
+ if (parent::__construct($yValues, $xValues) !== false) {
if ($order < $this->_valueCount) {
$this->_bestFitType .= '_'.$order;
$this->_order = $order;
$this->_polynomial_regression($order, $yValues, $xValues, $const);
if (($this->getGoodnessOfFit() < 0.0) || ($this->getGoodnessOfFit() > 1.0)) {
- $this->_error = True;
+ $this->_error = true;
}
} else {
- $this->_error = True;
+ $this->_error = true;
}
}
} // function __construct()
-
-} // class polynomialBestFit
\ No newline at end of file
+}
diff --git a/Classes/PHPExcel/Shared/trend/powerBestFitClass.php b/Classes/PHPExcel/Shared/trend/powerBestFitClass.php
index 4f2a0735..b58d8f5d 100644
--- a/Classes/PHPExcel/Shared/trend/powerBestFitClass.php
+++ b/Classes/PHPExcel/Shared/trend/powerBestFitClass.php
@@ -53,7 +53,8 @@ class PHPExcel_Power_Best_Fit extends PHPExcel_Best_Fit
* @param float $xValue X-Value
* @return float Y-Value
**/
- public function getValueOfYForX($xValue) {
+ public function getValueOfYForX($xValue)
+ {
return $this->getIntersect() * pow(($xValue - $this->_Xoffset), $this->getSlope());
} // function getValueOfYForX()
@@ -64,8 +65,9 @@ class PHPExcel_Power_Best_Fit extends PHPExcel_Best_Fit
* @param float $yValue Y-Value
* @return float X-Value
**/
- public function getValueOfXForY($yValue) {
- return pow((($yValue + $this->_Yoffset) / $this->getIntersect()),(1 / $this->getSlope()));
+ public function getValueOfXForY($yValue)
+ {
+ return pow((($yValue + $this->_Yoffset) / $this->getIntersect()), (1 / $this->getSlope()));
} // function getValueOfXForY()
@@ -75,7 +77,8 @@ class PHPExcel_Power_Best_Fit extends PHPExcel_Best_Fit
* @param int $dp Number of places of decimal precision to display
* @return string
**/
- public function getEquation($dp=0) {
+ public function getEquation($dp = 0)
+ {
$slope = $this->getSlope($dp);
$intersect = $this->getIntersect($dp);
@@ -89,7 +92,8 @@ class PHPExcel_Power_Best_Fit extends PHPExcel_Best_Fit
* @param int $dp Number of places of decimal precision to display
* @return string
**/
- public function getIntersect($dp=0) {
+ public function getIntersect($dp = 0)
+ {
if ($dp != 0) {
return round(exp($this->_intersect), $dp);
}
@@ -104,7 +108,8 @@ class PHPExcel_Power_Best_Fit extends PHPExcel_Best_Fit
* @param float[] $xValues The set of X-values for this regression
* @param boolean $const
*/
- private function _power_regression($yValues, $xValues, $const) {
+ private function _power_regression($yValues, $xValues, $const)
+ {
foreach ($xValues as &$value) {
if ($value < 0.0) {
$value = 0 - log(abs($value));
@@ -133,10 +138,10 @@ class PHPExcel_Power_Best_Fit extends PHPExcel_Best_Fit
* @param float[] $xValues The set of X-values for this regression
* @param boolean $const
*/
- function __construct($yValues, $xValues=array(), $const=True) {
- if (parent::__construct($yValues, $xValues) !== False) {
+ function __construct($yValues, $xValues = array(), $const = true)
+ {
+ if (parent::__construct($yValues, $xValues) !== false) {
$this->_power_regression($yValues, $xValues, $const);
}
- } // function __construct()
-
-} // class powerBestFit
\ No newline at end of file
+ }
+}
diff --git a/Classes/PHPExcel/Shared/trend/trendClass.php b/Classes/PHPExcel/Shared/trend/trendClass.php
index 6d16c7ea..bb1cd1c5 100644
--- a/Classes/PHPExcel/Shared/trend/trendClass.php
+++ b/Classes/PHPExcel/Shared/trend/trendClass.php
@@ -84,7 +84,8 @@ class trendClass
private static $_trendCache = array();
- public static function calculate($trendType=self::TREND_BEST_FIT, $yValues, $xValues=array(), $const=True) {
+ public static function calculate($trendType = self::TREND_BEST_FIT, $yValues, $xValues = array(), $const = true)
+ {
// Calculate number of points in each dataset
$nY = count($yValues);
$nX = count($xValues);
@@ -102,29 +103,29 @@ class trendClass
// Determine which trend method has been requested
switch ($trendType) {
// Instantiate and return the class for the requested trend method
- case self::TREND_LINEAR :
- case self::TREND_LOGARITHMIC :
- case self::TREND_EXPONENTIAL :
- case self::TREND_POWER :
+ case self::TREND_LINEAR:
+ case self::TREND_LOGARITHMIC:
+ case self::TREND_EXPONENTIAL:
+ case self::TREND_POWER:
if (!isset(self::$_trendCache[$key])) {
$className = 'PHPExcel_'.$trendType.'_Best_Fit';
self::$_trendCache[$key] = new $className($yValues, $xValues, $const);
}
return self::$_trendCache[$key];
break;
- case self::TREND_POLYNOMIAL_2 :
- case self::TREND_POLYNOMIAL_3 :
- case self::TREND_POLYNOMIAL_4 :
- case self::TREND_POLYNOMIAL_5 :
- case self::TREND_POLYNOMIAL_6 :
+ case self::TREND_POLYNOMIAL_2:
+ case self::TREND_POLYNOMIAL_3:
+ case self::TREND_POLYNOMIAL_4:
+ case self::TREND_POLYNOMIAL_5:
+ case self::TREND_POLYNOMIAL_6:
if (!isset(self::$_trendCache[$key])) {
- $order = substr($trendType,-1);
+ $order = substr($trendType, -1);
self::$_trendCache[$key] = new PHPExcel_Polynomial_Best_Fit($order, $yValues, $xValues, $const);
}
return self::$_trendCache[$key];
break;
- case self::TREND_BEST_FIT :
- case self::TREND_BEST_FIT_NO_POLY :
+ case self::TREND_BEST_FIT:
+ case self::TREND_BEST_FIT_NO_POLY:
// If the request is to determine the best fit regression, then we test each trend line in turn
// Start by generating an instance of each available trend method
foreach (self::$_trendTypes as $trendMethod) {
@@ -134,7 +135,7 @@ class trendClass
}
if ($trendType != self::TREND_BEST_FIT_NO_POLY) {
foreach (self::$_trendTypePolyOrders as $trendMethod) {
- $order = substr($trendMethod,-1);
+ $order = substr($trendMethod, -1);
$bestFit[$trendMethod] = new PHPExcel_Polynomial_Best_Fit($order, $yValues, $xValues, $const);
if ($bestFit[$trendMethod]->getError()) {
unset($bestFit[$trendMethod]);
@@ -148,9 +149,8 @@ class trendClass
$bestFitType = key($bestFitValue);
return $bestFit[$bestFitType];
break;
- default :
+ default:
return false;
}
} // function calculate()
-
-} // class trendClass
\ No newline at end of file
+} // class trendClass
diff --git a/Classes/PHPExcel/Worksheet.php b/Classes/PHPExcel/Worksheet.php
index 8e2a7d95..5c6d3ed6 100644
--- a/Classes/PHPExcel/Worksheet.php
+++ b/Classes/PHPExcel/Worksheet.php
@@ -196,7 +196,7 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
*
* @var PHPExcel_Worksheet_AutoFilter
*/
- private $_autoFilter = NULL;
+ private $_autoFilter = null;
/**
* Freeze pane
@@ -334,7 +334,7 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
{
// Set parent and title
$this->_parent = $pParent;
- $this->setTitle($pTitle, FALSE);
+ $this->setTitle($pTitle, false);
// setTitle can change $pTitle
$this->setCodeName($this->getTitle());
$this->setSheetState(PHPExcel_Worksheet::SHEETSTATE_VISIBLE);
@@ -363,12 +363,12 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
$this->_protection = new PHPExcel_Worksheet_Protection();
// Default row dimension
- $this->_defaultRowDimension = new PHPExcel_Worksheet_RowDimension(NULL);
+ $this->_defaultRowDimension = new PHPExcel_Worksheet_RowDimension(null);
// Default column dimension
- $this->_defaultColumnDimension = new PHPExcel_Worksheet_ColumnDimension(NULL);
+ $this->_defaultColumnDimension = new PHPExcel_Worksheet_ColumnDimension(null);
- $this->_autoFilter = new PHPExcel_Worksheet_AutoFilter(NULL, $this);
+ $this->_autoFilter = new PHPExcel_Worksheet_AutoFilter(null, $this);
}
@@ -377,10 +377,11 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
* typically so that the worksheet object can be unset
*
*/
- public function disconnectCells() {
- if ( $this->_cellCollection !== NULL) {
+ public function disconnectCells()
+ {
+ if ($this->_cellCollection !== null) {
$this->_cellCollection->unsetWorksheetCells();
- $this->_cellCollection = NULL;
+ $this->_cellCollection = null;
}
// detach ourself from the workbook, so that it can then delete this worksheet successfully
$this->_parent = null;
@@ -390,9 +391,9 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
* Code to execute when this worksheet is unset()
*
*/
- function __destruct() {
- PHPExcel_Calculation::getInstance($this->_parent)
- ->clearCalculationCacheForWorksheet($this->_title);
+ function __destruct()
+ {
+ PHPExcel_Calculation::getInstance($this->_parent)->clearCalculationCacheForWorksheet($this->_title);
$this->disconnectCells();
}
@@ -402,7 +403,8 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
*
* @return PHPExcel_CachedObjectStorage_xxx
*/
- public function getCellCacheController() {
+ public function getCellCacheController()
+ {
return $this->_cellCollection;
} // function getCellCacheController()
@@ -431,17 +433,17 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
throw new PHPExcel_Exception('Sheet code name cannot be empty.');
}
// Some of the printable ASCII characters are invalid: * : / \ ? [ ] and first and last characters cannot be a "'"
- if ((str_replace(self::$_invalidCharacters, '', $pValue) !== $pValue) ||
- (PHPExcel_Shared_String::Substring($pValue,-1,1)=='\'') ||
- (PHPExcel_Shared_String::Substring($pValue,0,1)=='\'')) {
+ if ((str_replace(self::$_invalidCharacters, '', $pValue) !== $pValue) ||
+ (PHPExcel_Shared_String::Substring($pValue, -1, 1)=='\'') ||
+ (PHPExcel_Shared_String::Substring($pValue, 0, 1)=='\'')) {
throw new PHPExcel_Exception('Invalid character found in sheet code name');
}
-
+
// Maximum 31 characters allowed for sheet title
if ($CharCount > 31) {
throw new PHPExcel_Exception('Maximum 31 characters allowed in sheet code name.');
}
-
+
return $pValue;
}
@@ -479,7 +481,7 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
// Re-order cell collection
return $this->sortCellCollection();
}
- if ($this->_cellCollection !== NULL) {
+ if ($this->_cellCollection !== null) {
return $this->_cellCollection->getCellList();
}
return array();
@@ -492,7 +494,7 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
*/
public function sortCellCollection()
{
- if ($this->_cellCollection !== NULL) {
+ if ($this->_cellCollection !== null) {
return $this->_cellCollection->getSortedCellList();
}
return array();
@@ -725,7 +727,6 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
// There is only something to do if there are some auto-size columns
if (!empty($autoSizes)) {
-
// build list of cells references that participate in a merge
$isMergeCell = array();
foreach ($this->getMergeCells() as $cells) {
@@ -762,7 +763,9 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
// adjust column widths
foreach ($autoSizes as $columnIndex => $width) {
- if ($width == -1) $width = $this->getDefaultColumnDimension()->getWidth();
+ if ($width == -1) {
+ $width = $this->getDefaultColumnDimension()->getWidth();
+ }
$this->getColumnDimension($columnIndex)->setWidth($width);
}
}
@@ -775,7 +778,8 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
*
* @return PHPExcel
*/
- public function getParent() {
+ public function getParent()
+ {
return $this->_parent;
}
@@ -785,7 +789,8 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
* @param PHPExcel $parent
* @return PHPExcel_Worksheet
*/
- public function rebindParent(PHPExcel $parent) {
+ public function rebindParent(PHPExcel $parent)
+ {
if ($this->_parent !== null) {
$namedRanges = $this->_parent->getNamedRanges();
foreach ($namedRanges as $namedRange) {
@@ -841,18 +846,18 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
// Use name, but append with lowest possible integer
if (PHPExcel_Shared_String::CountCharacters($pValue) > 29) {
- $pValue = PHPExcel_Shared_String::Substring($pValue,0,29);
+ $pValue = PHPExcel_Shared_String::Substring($pValue, 0, 29);
}
$i = 1;
while ($this->_parent->sheetNameExists($pValue . ' ' . $i)) {
++$i;
if ($i == 10) {
if (PHPExcel_Shared_String::CountCharacters($pValue) > 28) {
- $pValue = PHPExcel_Shared_String::Substring($pValue,0,28);
+ $pValue = PHPExcel_Shared_String::Substring($pValue, 0, 28);
}
} elseif ($i == 100) {
if (PHPExcel_Shared_String::CountCharacters($pValue) > 27) {
- $pValue = PHPExcel_Shared_String::Substring($pValue,0,27);
+ $pValue = PHPExcel_Shared_String::Substring($pValue, 0, 27);
}
}
}
@@ -871,8 +876,9 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
$newTitle = $this->getTitle();
PHPExcel_Calculation::getInstance($this->_parent)
->renameCalculationCacheForWorksheet($oldTitle, $newTitle);
- if ($updateFormulaCellReferences)
+ if ($updateFormulaCellReferences) {
PHPExcel_ReferenceHelper::getInstance()->updateNamedFormulas($this->_parent, $oldTitle, $newTitle);
+ }
}
return $this;
@@ -883,7 +889,8 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
*
* @return string Sheet state (visible, hidden, veryHidden)
*/
- public function getSheetState() {
+ public function getSheetState()
+ {
return $this->_sheetState;
}
@@ -893,7 +900,8 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
* @param string $value Sheet state (visible, hidden, veryHidden)
* @return PHPExcel_Worksheet
*/
- public function setSheetState($value = PHPExcel_Worksheet::SHEETSTATE_VISIBLE) {
+ public function setSheetState($value = PHPExcel_Worksheet::SHEETSTATE_VISIBLE)
+ {
$this->_sheetState = $value;
return $this;
}
@@ -1159,7 +1167,7 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
if ((!preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF.'$/i', $pCoordinate, $matches)) &&
(preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_NAMEDRANGE.'$/i', $pCoordinate, $matches))) {
$namedRange = PHPExcel_NamedRange::resolveRange($pCoordinate, $this);
- if ($namedRange !== NULL) {
+ if ($namedRange !== null) {
$pCoordinate = $namedRange->getRange();
return $namedRange->getWorksheet()->getCell($pCoordinate);
}
@@ -1207,36 +1215,33 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
{
$cell = $this->_cellCollection->addCacheData(
$pCoordinate,
- new PHPExcel_Cell(
- NULL,
- PHPExcel_Cell_DataType::TYPE_NULL,
- $this
- )
+ new PHPExcel_Cell(null, PHPExcel_Cell_DataType::TYPE_NULL, $this)
);
$this->_cellCollectionIsSorted = false;
// Coordinates
$aCoordinates = PHPExcel_Cell::coordinateFromString($pCoordinate);
- if (PHPExcel_Cell::columnIndexFromString($this->_cachedHighestColumn) < PHPExcel_Cell::columnIndexFromString($aCoordinates[0]))
+ if (PHPExcel_Cell::columnIndexFromString($this->_cachedHighestColumn) < PHPExcel_Cell::columnIndexFromString($aCoordinates[0])) {
$this->_cachedHighestColumn = $aCoordinates[0];
+ }
$this->_cachedHighestRow = max($this->_cachedHighestRow, $aCoordinates[1]);
// Cell needs appropriate xfIndex from dimensions records
// but don't create dimension records if they don't already exist
- $rowDimension = $this->getRowDimension($aCoordinates[1], FALSE);
- $columnDimension = $this->getColumnDimension($aCoordinates[0], FALSE);
+ $rowDimension = $this->getRowDimension($aCoordinates[1], false);
+ $columnDimension = $this->getColumnDimension($aCoordinates[0], false);
- if ($rowDimension !== NULL && $rowDimension->getXfIndex() > 0) {
+ if ($rowDimension !== null && $rowDimension->getXfIndex() > 0) {
// then there is a row dimension with explicit style, assign it to the cell
$cell->setXfIndex($rowDimension->getXfIndex());
- } elseif ($columnDimension !== NULL && $columnDimension->getXfIndex() > 0) {
+ } elseif ($columnDimension !== null && $columnDimension->getXfIndex() > 0) {
// then there is a column dimension, assign it to the cell
$cell->setXfIndex($columnDimension->getXfIndex());
}
return $cell;
}
-
+
/**
* Does the cell at a specific coordinate exist?
*
@@ -1256,7 +1261,7 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
if ((!preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF.'$/i', $pCoordinate, $matches)) &&
(preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_NAMEDRANGE.'$/i', $pCoordinate, $matches))) {
$namedRange = PHPExcel_NamedRange::resolveRange($pCoordinate, $this);
- if ($namedRange !== NULL) {
+ if ($namedRange !== null) {
$pCoordinate = $namedRange->getRange();
if ($this->getHashCode() != $namedRange->getWorksheet()->getHashCode()) {
if (!$namedRange->getLocalOnly()) {
@@ -1265,16 +1270,17 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
throw new PHPExcel_Exception('Named range ' . $namedRange->getName() . ' is not accessible from within sheet ' . $this->getTitle());
}
}
+ } else {
+ return false;
}
- else { return false; }
}
// Uppercase coordinate
$pCoordinate = strtoupper($pCoordinate);
- if (strpos($pCoordinate,':') !== false || strpos($pCoordinate,',') !== false) {
+ if (strpos($pCoordinate, ':') !== false || strpos($pCoordinate, ',') !== false) {
throw new PHPExcel_Exception('Cell coordinate can not be a range of cells.');
- } elseif (strpos($pCoordinate,'$') !== false) {
+ } elseif (strpos($pCoordinate, '$') !== false) {
throw new PHPExcel_Exception('Cell coordinate must not be absolute.');
} else {
// Coordinates
@@ -1303,15 +1309,16 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
* @param int $pRow Numeric index of the row
* @return PHPExcel_Worksheet_RowDimension
*/
- public function getRowDimension($pRow = 1, $create = TRUE)
+ public function getRowDimension($pRow = 1, $create = true)
{
// Found
$found = null;
// Get row dimension
if (!isset($this->_rowDimensions[$pRow])) {
- if (!$create)
- return NULL;
+ if (!$create) {
+ return null;
+ }
$this->_rowDimensions[$pRow] = new PHPExcel_Worksheet_RowDimension($pRow);
$this->_cachedHighestRow = max($this->_cachedHighestRow, $pRow);
@@ -1325,19 +1332,21 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
* @param string $pColumn String index of the column
* @return PHPExcel_Worksheet_ColumnDimension
*/
- public function getColumnDimension($pColumn = 'A', $create = TRUE)
+ public function getColumnDimension($pColumn = 'A', $create = true)
{
// Uppercase coordinate
$pColumn = strtoupper($pColumn);
// Fetch dimensions
if (!isset($this->_columnDimensions[$pColumn])) {
- if (!$create)
- return NULL;
+ if (!$create) {
+ return null;
+ }
$this->_columnDimensions[$pColumn] = new PHPExcel_Worksheet_ColumnDimension($pColumn);
- if (PHPExcel_Cell::columnIndexFromString($this->_cachedHighestColumn) < PHPExcel_Cell::columnIndexFromString($pColumn))
+ if (PHPExcel_Cell::columnIndexFromString($this->_cachedHighestColumn) < PHPExcel_Cell::columnIndexFromString($pColumn)) {
$this->_cachedHighestColumn = $pColumn;
+ }
}
return $this->_columnDimensions[$pColumn];
}
@@ -1488,8 +1497,7 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
public function getStyleByColumnAndRow($pColumn = 0, $pRow = 1, $pColumn2 = null, $pRow2 = null)
{
if (!is_null($pColumn2) && !is_null($pRow2)) {
- $cellRange = PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow . ':' .
- PHPExcel_Cell::stringFromColumnIndex($pColumn2) . $pRow2;
+ $cellRange = PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow . ':' . PHPExcel_Cell::stringFromColumnIndex($pColumn2) . $pRow2;
return $this->getStyle($cellRange);
}
@@ -1680,7 +1688,7 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
// Uppercase coordinate
$pRange = strtoupper($pRange);
- if (strpos($pRange,':') !== false) {
+ if (strpos($pRange, ':') !== false) {
$this->_mergeCells[$pRange] = $pRange;
// make sure cells are created
@@ -1699,7 +1707,6 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
for ($i = 1; $i < $count; $i++) {
$this->getCell($aReferences[$i])->setValueExplicit(null, PHPExcel_Cell_DataType::TYPE_NULL);
}
-
} else {
throw new PHPExcel_Exception('Merge must be set on a range of cells.');
}
@@ -1735,7 +1742,7 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
// Uppercase coordinate
$pRange = strtoupper($pRange);
- if (strpos($pRange,':') !== false) {
+ if (strpos($pRange, ':') !== false) {
if (isset($this->_mergeCells[$pRange])) {
unset($this->_mergeCells[$pRange]);
} else {
@@ -1783,7 +1790,6 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
public function setMergeCells($pValue = array())
{
$this->_mergeCells = $pValue;
-
return $this;
}
@@ -1896,7 +1902,6 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
public function setAutoFilter($pValue)
{
$pRange = strtoupper($pValue);
-
if (is_string($pValue)) {
$this->_autoFilter->setRange($pValue);
} elseif (is_object($pValue) && ($pValue instanceof PHPExcel_Worksheet_AutoFilter)) {
@@ -1931,7 +1936,7 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
*/
public function removeAutoFilter()
{
- $this->_autoFilter->setRange(NULL);
+ $this->_autoFilter->setRange(null);
return $this;
}
@@ -1961,8 +1966,7 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
{
// Uppercase coordinate
$pCell = strtoupper($pCell);
-
- if (strpos($pCell,':') === false && strpos($pCell,',') === false) {
+ if (strpos($pCell, ':') === false && strpos($pCell, ',') === false) {
$this->_freezePane = $pCell;
} else {
throw new PHPExcel_Exception('Freeze pane can not be set on a range of cells.');
@@ -2001,7 +2005,8 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
* @throws PHPExcel_Exception
* @return PHPExcel_Worksheet
*/
- public function insertNewRowBefore($pBefore = 1, $pNumRows = 1) {
+ public function insertNewRowBefore($pBefore = 1, $pNumRows = 1)
+ {
if ($pBefore >= 1) {
$objReferenceHelper = PHPExcel_ReferenceHelper::getInstance();
$objReferenceHelper->insertNewBefore('A' . $pBefore, 0, $pNumRows, $this);
@@ -2019,7 +2024,8 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
* @throws PHPExcel_Exception
* @return PHPExcel_Worksheet
*/
- public function insertNewColumnBefore($pBefore = 'A', $pNumCols = 1) {
+ public function insertNewColumnBefore($pBefore = 'A', $pNumCols = 1)
+ {
if (!is_numeric($pBefore)) {
$objReferenceHelper = PHPExcel_ReferenceHelper::getInstance();
$objReferenceHelper->insertNewBefore($pBefore . '1', $pNumCols, 0, $this);
@@ -2037,7 +2043,8 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
* @throws PHPExcel_Exception
* @return PHPExcel_Worksheet
*/
- public function insertNewColumnBeforeByIndex($pBefore = 0, $pNumCols = 1) {
+ public function insertNewColumnBeforeByIndex($pBefore = 0, $pNumCols = 1)
+ {
if ($pBefore >= 0) {
return $this->insertNewColumnBefore(PHPExcel_Cell::stringFromColumnIndex($pBefore), $pNumCols);
} else {
@@ -2053,12 +2060,13 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
* @throws PHPExcel_Exception
* @return PHPExcel_Worksheet
*/
- public function removeRow($pRow = 1, $pNumRows = 1) {
+ public function removeRow($pRow = 1, $pNumRows = 1)
+ {
if ($pRow >= 1) {
$highestRow = $this->getHighestDataRow();
$objReferenceHelper = PHPExcel_ReferenceHelper::getInstance();
$objReferenceHelper->insertNewBefore('A' . ($pRow + $pNumRows), 0, -$pNumRows, $this);
- for($r = 0; $r < $pNumRows; ++$r) {
+ for ($r = 0; $r < $pNumRows; ++$r) {
$this->getCellCacheController()->removeRow($highestRow);
--$highestRow;
}
@@ -2076,13 +2084,14 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
* @throws PHPExcel_Exception
* @return PHPExcel_Worksheet
*/
- public function removeColumn($pColumn = 'A', $pNumCols = 1) {
+ public function removeColumn($pColumn = 'A', $pNumCols = 1)
+ {
if (!is_numeric($pColumn)) {
$highestColumn = $this->getHighestDataColumn();
$pColumn = PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::columnIndexFromString($pColumn) - 1 + $pNumCols);
$objReferenceHelper = PHPExcel_ReferenceHelper::getInstance();
$objReferenceHelper->insertNewBefore($pColumn . '1', -$pNumCols, 0, $this);
- for($c = 0; $c < $pNumCols; ++$c) {
+ for ($c = 0; $c < $pNumCols; ++$c) {
$this->getCellCacheController()->removeColumn($highestColumn);
$highestColumn = PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::columnIndexFromString($highestColumn) - 2);
}
@@ -2100,7 +2109,8 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
* @throws PHPExcel_Exception
* @return PHPExcel_Worksheet
*/
- public function removeColumnByIndex($pColumn = 0, $pNumCols = 1) {
+ public function removeColumnByIndex($pColumn = 0, $pNumCols = 1)
+ {
if ($pColumn >= 0) {
return $this->removeColumn(PHPExcel_Cell::stringFromColumnIndex($pColumn), $pNumCols);
} else {
@@ -2113,7 +2123,8 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
*
* @return boolean
*/
- public function getShowGridlines() {
+ public function getShowGridlines()
+ {
return $this->_showGridlines;
}
@@ -2123,7 +2134,8 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
* @param boolean $pValue Show gridlines (true/false)
* @return PHPExcel_Worksheet
*/
- public function setShowGridlines($pValue = false) {
+ public function setShowGridlines($pValue = false)
+ {
$this->_showGridlines = $pValue;
return $this;
}
@@ -2133,7 +2145,8 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
*
* @return boolean
*/
- public function getPrintGridlines() {
+ public function getPrintGridlines()
+ {
return $this->_printGridlines;
}
@@ -2143,7 +2156,8 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
* @param boolean $pValue Print gridlines (true/false)
* @return PHPExcel_Worksheet
*/
- public function setPrintGridlines($pValue = false) {
+ public function setPrintGridlines($pValue = false)
+ {
$this->_printGridlines = $pValue;
return $this;
}
@@ -2153,7 +2167,8 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
*
* @return boolean
*/
- public function getShowRowColHeaders() {
+ public function getShowRowColHeaders()
+ {
return $this->_showRowColHeaders;
}
@@ -2163,7 +2178,8 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
* @param boolean $pValue Show row and column headers (true/false)
* @return PHPExcel_Worksheet
*/
- public function setShowRowColHeaders($pValue = false) {
+ public function setShowRowColHeaders($pValue = false)
+ {
$this->_showRowColHeaders = $pValue;
return $this;
}
@@ -2173,7 +2189,8 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
*
* @return boolean
*/
- public function getShowSummaryBelow() {
+ public function getShowSummaryBelow()
+ {
return $this->_showSummaryBelow;
}
@@ -2183,7 +2200,8 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
* @param boolean $pValue Show summary below (true/false)
* @return PHPExcel_Worksheet
*/
- public function setShowSummaryBelow($pValue = true) {
+ public function setShowSummaryBelow($pValue = true)
+ {
$this->_showSummaryBelow = $pValue;
return $this;
}
@@ -2193,7 +2211,8 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
*
* @return boolean
*/
- public function getShowSummaryRight() {
+ public function getShowSummaryRight()
+ {
return $this->_showSummaryRight;
}
@@ -2203,7 +2222,8 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
* @param boolean $pValue Show summary right (true/false)
* @return PHPExcel_Worksheet
*/
- public function setShowSummaryRight($pValue = true) {
+ public function setShowSummaryRight($pValue = true)
+ {
$this->_showSummaryRight = $pValue;
return $this;
}
@@ -2243,9 +2263,9 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
// Uppercase coordinate
$pCellCoordinate = strtoupper($pCellCoordinate);
- if (strpos($pCellCoordinate,':') !== false || strpos($pCellCoordinate,',') !== false) {
+ if (strpos($pCellCoordinate, ':') !== false || strpos($pCellCoordinate, ',') !== false) {
throw new PHPExcel_Exception('Cell coordinate string can not be a range of cells.');
- } else if (strpos($pCellCoordinate,'$') !== false) {
+ } else if (strpos($pCellCoordinate, '$') !== false) {
throw new PHPExcel_Exception('Cell coordinate string must not be absolute.');
} else if ($pCellCoordinate == '') {
throw new PHPExcel_Exception('Cell coordinate can not be zero-length string.');
@@ -2340,7 +2360,7 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
// Convert '1:3' to 'A1:XFD3'
$pCoordinate = preg_replace('/^([0-9]+):([0-9]+)$/', 'A${1}:XFD${2}', $pCoordinate);
- if (strpos($pCoordinate,':') !== false || strpos($pCoordinate,',') !== false) {
+ if (strpos($pCoordinate, ':') !== false || strpos($pCoordinate, ',') !== false) {
list($first, ) = PHPExcel_Cell::splitRange($pCoordinate);
$this->_activeCell = $first[0];
} else {
@@ -2368,7 +2388,8 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
*
* @return boolean
*/
- public function getRightToLeft() {
+ public function getRightToLeft()
+ {
return $this->_rightToLeft;
}
@@ -2378,7 +2399,8 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
* @param boolean $value Right-to-left true/false
* @return PHPExcel_Worksheet
*/
- public function setRightToLeft($value = false) {
+ public function setRightToLeft($value = false)
+ {
$this->_rightToLeft = $value;
return $this;
}
@@ -2393,7 +2415,8 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
* @throws PHPExcel_Exception
* @return PHPExcel_Worksheet
*/
- public function fromArray($source = null, $nullValue = null, $startCell = 'A1', $strictNullComparison = false) {
+ public function fromArray($source = null, $nullValue = null, $startCell = 'A1', $strictNullComparison = false)
+ {
if (is_array($source)) {
// Convert a 1-D array to 2-D (for ease of looping)
if (!is_array(end($source))) {
@@ -2439,7 +2462,8 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
* True - Return rows and columns indexed by their actual row and column IDs
* @return array
*/
- public function rangeToArray($pRange = 'A1', $nullValue = null, $calculateFormulas = true, $formatData = true, $returnCellRef = false) {
+ public function rangeToArray($pRange = 'A1', $nullValue = null, $calculateFormulas = true, $formatData = true, $returnCellRef = false)
+ {
// Returnvalue
$returnValue = array();
// Identify the range that we need to extract from the worksheet
@@ -2478,9 +2502,7 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
$style = $this->_parent->getCellXfByIndex($cell->getXfIndex());
$returnValue[$rRef][$cRef] = PHPExcel_Style_NumberFormat::toFormattedString(
$returnValue[$rRef][$cRef],
- ($style && $style->getNumberFormat()) ?
- $style->getNumberFormat()->getFormatCode() :
- PHPExcel_Style_NumberFormat::FORMAT_GENERAL
+ ($style && $style->getNumberFormat()) ? $style->getNumberFormat()->getFormatCode() : PHPExcel_Style_NumberFormat::FORMAT_GENERAL
);
}
} else {
@@ -2511,14 +2533,14 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
* @return array
* @throws PHPExcel_Exception
*/
- public function namedRangeToArray($pNamedRange = '', $nullValue = null, $calculateFormulas = true, $formatData = true, $returnCellRef = false) {
+ public function namedRangeToArray($pNamedRange = '', $nullValue = null, $calculateFormulas = true, $formatData = true, $returnCellRef = false)
+ {
$namedRange = PHPExcel_NamedRange::resolveRange($pNamedRange, $this);
- if ($namedRange !== NULL) {
+ if ($namedRange !== null) {
$pWorkSheet = $namedRange->getWorksheet();
$pCellRange = $namedRange->getRange();
- return $pWorkSheet->rangeToArray( $pCellRange,
- $nullValue, $calculateFormulas, $formatData, $returnCellRef);
+ return $pWorkSheet->rangeToArray($pCellRange, $nullValue, $calculateFormulas, $formatData, $returnCellRef);
}
throw new PHPExcel_Exception('Named Range '.$pNamedRange.' does not exist.');
@@ -2535,7 +2557,8 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
* True - Return rows and columns indexed by their actual row and column IDs
* @return array
*/
- public function toArray($nullValue = null, $calculateFormulas = true, $formatData = true, $returnCellRef = false) {
+ public function toArray($nullValue = null, $calculateFormulas = true, $formatData = true, $returnCellRef = false)
+ {
// Garbage collect...
$this->garbageCollect();
@@ -2543,8 +2566,7 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
$maxCol = $this->getHighestColumn();
$maxRow = $this->getHighestRow();
// Return
- return $this->rangeToArray( 'A1:'.$maxCol.$maxRow,
- $nullValue, $calculateFormulas, $formatData, $returnCellRef);
+ return $this->rangeToArray('A1:'.$maxCol.$maxRow, $nullValue, $calculateFormulas, $formatData, $returnCellRef);
}
/**
@@ -2555,7 +2577,8 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
*
* @return PHPExcel_Worksheet_RowIterator
*/
- public function getRowIterator($startRow = 1, $endRow = null) {
+ public function getRowIterator($startRow = 1, $endRow = null)
+ {
return new PHPExcel_Worksheet_RowIterator($this, $startRow, $endRow);
}
@@ -2567,7 +2590,8 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
*
* @return PHPExcel_Worksheet_ColumnIterator
*/
- public function getColumnIterator($startColumn = 'A', $endColumn = null) {
+ public function getColumnIterator($startColumn = 'A', $endColumn = null)
+ {
return new PHPExcel_Worksheet_ColumnIterator($this, $startColumn, $endColumn);
}
@@ -2576,7 +2600,8 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
*
* @return PHPExcel_Worksheet
*/
- public function garbageCollect() {
+ public function garbageCollect()
+ {
// Flush cache
$this->_cellCollection->getCacheData('A1');
// Build a reference table from images
@@ -2595,7 +2620,7 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
// Loop through column dimensions
foreach ($this->_columnDimensions as $dimension) {
- $highestColumn = max($highestColumn,PHPExcel_Cell::columnIndexFromString($dimension->getColumnIndex()));
+ $highestColumn = max($highestColumn, PHPExcel_Cell::columnIndexFromString($dimension->getColumnIndex()));
}
// Loop through row dimensions
@@ -2620,13 +2645,10 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
*
* @return string Hash code
*/
- public function getHashCode() {
+ public function getHashCode()
+ {
if ($this->_dirty) {
- $this->_hash = md5( $this->_title .
- $this->_autoFilter .
- ($this->_protection->isProtectionEnabled() ? 't' : 'f') .
- __CLASS__
- );
+ $this->_hash = md5($this->_title . $this->_autoFilter . ($this->_protection->isProtectionEnabled() ? 't' : 'f') . __CLASS__);
$this->_dirty = false;
}
return $this->_hash;
@@ -2642,17 +2664,15 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
* @param bool $returnRange Return range? (see example)
* @return mixed
*/
- public static function extractSheetTitle($pRange, $returnRange = false) {
+ public static function extractSheetTitle($pRange, $returnRange = false)
+ {
// Sheet title included?
if (($sep = strpos($pRange, '!')) === false) {
return '';
}
if ($returnRange) {
- return array(
- trim(substr($pRange, 0, $sep),"'"),
- substr($pRange, $sep + 1)
- );
+ return array(trim(substr($pRange, 0, $sep), "'"), substr($pRange, $sep + 1));
}
return substr($pRange, $sep + 1);
@@ -2774,7 +2794,8 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
* @param string $range
* @return string Adjusted range value
*/
- public function shrinkRangeToFit($range) {
+ public function shrinkRangeToFit($range)
+ {
$maxCol = $this->getHighestColumn();
$maxRow = $this->getHighestRow();
$maxCol = PHPExcel_Cell::columnIndexFromString($maxCol);
@@ -2783,10 +2804,18 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
foreach ($rangeBlocks as &$rangeSet) {
$rangeBoundaries = PHPExcel_Cell::getRangeBoundaries($rangeSet);
- if (PHPExcel_Cell::columnIndexFromString($rangeBoundaries[0][0]) > $maxCol) { $rangeBoundaries[0][0] = PHPExcel_Cell::stringFromColumnIndex($maxCol); }
- if ($rangeBoundaries[0][1] > $maxRow) { $rangeBoundaries[0][1] = $maxRow; }
- if (PHPExcel_Cell::columnIndexFromString($rangeBoundaries[1][0]) > $maxCol) { $rangeBoundaries[1][0] = PHPExcel_Cell::stringFromColumnIndex($maxCol); }
- if ($rangeBoundaries[1][1] > $maxRow) { $rangeBoundaries[1][1] = $maxRow; }
+ if (PHPExcel_Cell::columnIndexFromString($rangeBoundaries[0][0]) > $maxCol) {
+ $rangeBoundaries[0][0] = PHPExcel_Cell::stringFromColumnIndex($maxCol);
+ }
+ if ($rangeBoundaries[0][1] > $maxRow) {
+ $rangeBoundaries[0][1] = $maxRow;
+ }
+ if (PHPExcel_Cell::columnIndexFromString($rangeBoundaries[1][0]) > $maxCol) {
+ $rangeBoundaries[1][0] = PHPExcel_Cell::stringFromColumnIndex($maxCol);
+ }
+ if ($rangeBoundaries[1][1] > $maxRow) {
+ $rangeBoundaries[1][1] = $maxRow;
+ }
$rangeSet = $rangeBoundaries[0][0].$rangeBoundaries[0][1].':'.$rangeBoundaries[1][0].$rangeBoundaries[1][1];
}
unset($rangeSet);
@@ -2802,9 +2831,9 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
*/
public function getTabColor()
{
- if ($this->_tabColor === NULL)
+ if ($this->_tabColor === null) {
$this->_tabColor = new PHPExcel_Style_Color();
-
+ }
return $this->_tabColor;
}
@@ -2828,7 +2857,7 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
*/
public function isTabColorSet()
{
- return ($this->_tabColor !== NULL);
+ return ($this->_tabColor !== null);
}
/**
@@ -2836,7 +2865,8 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
*
* @return PHPExcel_Worksheet
*/
- public function copy() {
+ public function copy()
+ {
$copied = clone $this;
return $copied;
@@ -2845,7 +2875,8 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
/**
* Implement PHP __clone to create a deep clone, not just a shallow copy.
*/
- public function __clone() {
+ public function __clone()
+ {
foreach ($this as $key => $val) {
if ($key == '_parent') {
continue;
@@ -2876,7 +2907,8 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
* @return objWorksheet
* @throws PHPExcel_Exception
*/
- public function setCodeName($pValue=null) {
+ public function setCodeName($pValue = null)
+ {
// Is this a 'rename' or not?
if ($this->getCodeName() == $pValue) {
return $this;
@@ -2887,25 +2919,25 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
self::_checkSheetCodeName($pValue);
// We use the same code that setTitle to find a valid codeName else not using a space (Excel don't like) but a '_'
-
+
if ($this->getParent()) {
// Is there already such sheet name?
if ($this->getParent()->sheetCodeNameExists($pValue)) {
// Use name, but append with lowest possible integer
if (PHPExcel_Shared_String::CountCharacters($pValue) > 29) {
- $pValue = PHPExcel_Shared_String::Substring($pValue,0,29);
+ $pValue = PHPExcel_Shared_String::Substring($pValue, 0, 29);
}
$i = 1;
while ($this->getParent()->sheetCodeNameExists($pValue . '_' . $i)) {
++$i;
if ($i == 10) {
if (PHPExcel_Shared_String::CountCharacters($pValue) > 28) {
- $pValue = PHPExcel_Shared_String::Substring($pValue,0,28);
+ $pValue = PHPExcel_Shared_String::Substring($pValue, 0, 28);
}
} elseif ($i == 100) {
if (PHPExcel_Shared_String::CountCharacters($pValue) > 27) {
- $pValue = PHPExcel_Shared_String::Substring($pValue,0,27);
+ $pValue = PHPExcel_Shared_String::Substring($pValue, 0, 27);
}
}
}
@@ -2924,14 +2956,16 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
*
* @return null|string
*/
- public function getCodeName() {
+ public function getCodeName()
+ {
return $this->_codeName;
}
/**
* Sheet has a code name ?
* @return boolean
*/
- public function hasCodeName() {
+ public function hasCodeName()
+ {
return !(is_null($this->_codeName));
}
}
diff --git a/Classes/PHPExcel/Worksheet/AutoFilter.php b/Classes/PHPExcel/Worksheet/AutoFilter.php
index 36407e6e..e86f9783 100644
--- a/Classes/PHPExcel/Worksheet/AutoFilter.php
+++ b/Classes/PHPExcel/Worksheet/AutoFilter.php
@@ -114,7 +114,7 @@ class PHPExcel_Worksheet_AutoFilter
public function setRange($pRange = '')
{
// Uppercase coordinate
- $cellAddress = explode('!',strtoupper($pRange));
+ $cellAddress = explode('!', strtoupper($pRange));
if (count($cellAddress) > 1) {
list($worksheet, $pRange) = $cellAddress;
}
@@ -349,7 +349,7 @@ class PHPExcel_Worksheet_AutoFilter
}
foreach ($dateSet as $dateValue) {
// Use of substr to extract value at the appropriate group level
- if (substr($dtVal,0,strlen($dateValue)) == $dateValue) {
+ if (substr($dtVal, 0, strlen($dateValue)) == $dateValue) {
return true;
}
}
@@ -381,34 +381,34 @@ class PHPExcel_Worksheet_AutoFilter
if (is_numeric($rule['value'])) {
// Numeric values are tested using the appropriate operator
switch ($rule['operator']) {
- case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_EQUAL :
+ case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_EQUAL:
$retVal = ($cellValue == $rule['value']);
break;
- case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_NOTEQUAL :
+ case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_NOTEQUAL:
$retVal = ($cellValue != $rule['value']);
break;
- case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_GREATERTHAN :
+ case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_GREATERTHAN:
$retVal = ($cellValue > $rule['value']);
break;
- case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_GREATERTHANOREQUAL :
+ case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_GREATERTHANOREQUAL:
$retVal = ($cellValue >= $rule['value']);
break;
- case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_LESSTHAN :
+ case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_LESSTHAN:
$retVal = ($cellValue < $rule['value']);
break;
- case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_LESSTHANOREQUAL :
+ case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_LESSTHANOREQUAL:
$retVal = ($cellValue <= $rule['value']);
break;
}
} elseif ($rule['value'] == '') {
switch ($rule['operator']) {
- case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_EQUAL :
+ case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_EQUAL:
$retVal = (($cellValue == '') || ($cellValue === null));
break;
- case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_NOTEQUAL :
+ case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_NOTEQUAL:
$retVal = (($cellValue != '') && ($cellValue !== null));
break;
- default :
+ default:
$retVal = true;
break;
}
@@ -418,7 +418,7 @@ class PHPExcel_Worksheet_AutoFilter
}
// If there are multiple conditions, then we need to test both using the appropriate join operator
switch ($join) {
- case PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_COLUMN_JOIN_OR :
+ case PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_COLUMN_JOIN_OR:
$returnVal = $returnVal || $retVal;
// Break as soon as we have a TRUE match for OR joins,
// to avoid unnecessary additional code execution
@@ -426,7 +426,7 @@ class PHPExcel_Worksheet_AutoFilter
return $returnVal;
}
break;
- case PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_COLUMN_JOIN_AND :
+ case PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_COLUMN_JOIN_AND:
$returnVal = $returnVal && $retVal;
break;
}
@@ -450,7 +450,7 @@ class PHPExcel_Worksheet_AutoFilter
}
if (is_numeric($cellValue)) {
- $dateValue = date('m',PHPExcel_Shared_Date::ExcelToPHP($cellValue));
+ $dateValue = date('m', PHPExcel_Shared_Date::ExcelToPHP($cellValue));
if (in_array($dateValue, $monthSet)) {
return true;
}
@@ -485,69 +485,69 @@ class PHPExcel_Worksheet_AutoFilter
$baseDate = PHPExcel_Calculation_DateTime::DATENOW();
// Calculate start/end dates for the required date range based on current date
switch ($dynamicRuleType) {
- case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_LASTWEEK :
+ case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_LASTWEEK:
$baseDate = strtotime('-7 days', $baseDate);
break;
- case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_NEXTWEEK :
+ case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_NEXTWEEK:
$baseDate = strtotime('-7 days', $baseDate);
break;
- case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_LASTMONTH :
- $baseDate = strtotime('-1 month',gmmktime(0, 0, 0, 1, date('m', $baseDate), date('Y', $baseDate)));
+ case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_LASTMONTH:
+ $baseDate = strtotime('-1 month', gmmktime(0, 0, 0, 1, date('m', $baseDate), date('Y', $baseDate)));
break;
- case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_NEXTMONTH :
- $baseDate = strtotime('+1 month',gmmktime(0, 0, 0, 1, date('m', $baseDate), date('Y', $baseDate)));
+ case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_NEXTMONTH:
+ $baseDate = strtotime('+1 month', gmmktime(0, 0, 0, 1, date('m', $baseDate), date('Y', $baseDate)));
break;
- case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_LASTQUARTER :
- $baseDate = strtotime('-3 month',gmmktime(0, 0, 0, 1, date('m', $baseDate), date('Y', $baseDate)));
+ case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_LASTQUARTER:
+ $baseDate = strtotime('-3 month', gmmktime(0, 0, 0, 1, date('m', $baseDate), date('Y', $baseDate)));
break;
- case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_NEXTQUARTER :
- $baseDate = strtotime('+3 month',gmmktime(0, 0, 0, 1, date('m', $baseDate), date('Y', $baseDate)));
+ case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_NEXTQUARTER:
+ $baseDate = strtotime('+3 month', gmmktime(0, 0, 0, 1, date('m', $baseDate), date('Y', $baseDate)));
break;
- case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_LASTYEAR :
- $baseDate = strtotime('-1 year',gmmktime(0, 0, 0, 1, date('m', $baseDate), date('Y', $baseDate)));
+ case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_LASTYEAR:
+ $baseDate = strtotime('-1 year', gmmktime(0, 0, 0, 1, date('m', $baseDate), date('Y', $baseDate)));
break;
- case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_NEXTYEAR :
- $baseDate = strtotime('+1 year',gmmktime(0, 0, 0, 1, date('m', $baseDate), date('Y', $baseDate)));
+ case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_NEXTYEAR:
+ $baseDate = strtotime('+1 year', gmmktime(0, 0, 0, 1, date('m', $baseDate), date('Y', $baseDate)));
break;
}
switch ($dynamicRuleType) {
- case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_TODAY :
- case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_YESTERDAY :
- case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_TOMORROW :
+ case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_TODAY:
+ case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_YESTERDAY:
+ case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_TOMORROW:
$maxVal = (int) PHPExcel_Shared_Date::PHPtoExcel(strtotime('+1 day', $baseDate));
$val = (int) PHPExcel_Shared_Date::PHPToExcel($baseDate);
break;
- case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_YEARTODATE :
+ case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_YEARTODATE:
$maxVal = (int) PHPExcel_Shared_Date::PHPtoExcel(strtotime('+1 day', $baseDate));
$val = (int) PHPExcel_Shared_Date::PHPToExcel(gmmktime(0, 0, 0, 1, 1, date('Y', $baseDate)));
break;
- case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_THISYEAR :
- case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_LASTYEAR :
- case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_NEXTYEAR :
+ case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_THISYEAR:
+ case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_LASTYEAR:
+ case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_NEXTYEAR:
$maxVal = (int) PHPExcel_Shared_Date::PHPToExcel(gmmktime(0, 0, 0, 31, 12, date('Y', $baseDate)));
++$maxVal;
$val = (int) PHPExcel_Shared_Date::PHPToExcel(gmmktime(0, 0, 0, 1, 1, date('Y', $baseDate)));
break;
- case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_THISQUARTER :
- case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_LASTQUARTER :
- case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_NEXTQUARTER :
+ case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_THISQUARTER:
+ case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_LASTQUARTER:
+ case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_NEXTQUARTER:
$thisMonth = date('m', $baseDate);
$thisQuarter = floor(--$thisMonth / 3);
$maxVal = (int) PHPExcel_Shared_Date::PHPtoExcel(gmmktime(0, 0, 0, date('t', $baseDate), (1+$thisQuarter)*3, date('Y', $baseDate)));
++$maxVal;
$val = (int) PHPExcel_Shared_Date::PHPToExcel(gmmktime(0, 0, 0, 1, 1+$thisQuarter*3, date('Y', $baseDate)));
break;
- case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_THISMONTH :
- case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_LASTMONTH :
- case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_NEXTMONTH :
+ case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_THISMONTH:
+ case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_LASTMONTH:
+ case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_NEXTMONTH:
$maxVal = (int) PHPExcel_Shared_Date::PHPtoExcel(gmmktime(0, 0, 0, date('t', $baseDate), date('m', $baseDate), date('Y', $baseDate)));
++$maxVal;
$val = (int) PHPExcel_Shared_Date::PHPToExcel(gmmktime(0, 0, 0, 1, date('m', $baseDate), date('Y', $baseDate)));
break;
- case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_THISWEEK :
- case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_LASTWEEK :
- case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_NEXTWEEK :
+ case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_THISWEEK:
+ case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_LASTWEEK:
+ case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_NEXTWEEK:
$dayOfWeek = date('w', $baseDate);
$val = (int) PHPExcel_Shared_Date::PHPToExcel($baseDate) - $dayOfWeek;
$maxVal = $val + 7;
@@ -556,11 +556,11 @@ class PHPExcel_Worksheet_AutoFilter
switch ($dynamicRuleType) {
// Adjust Today dates for Yesterday and Tomorrow
- case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_YESTERDAY :
+ case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_YESTERDAY:
--$maxVal;
--$val;
break;
- case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_TOMORROW :
+ case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_TOMORROW:
++$maxVal;
++$val;
break;
@@ -589,7 +589,7 @@ class PHPExcel_Worksheet_AutoFilter
sort($dataValues);
}
- return array_pop(array_slice($dataValues,0, $ruleValue));
+ return array_pop(array_slice($dataValues, 0, $ruleValue));
}
/**
@@ -610,7 +610,7 @@ class PHPExcel_Worksheet_AutoFilter
foreach ($this->_columns as $columnID => $filterColumn) {
$rules = $filterColumn->getRules();
switch ($filterColumn->getFilterType()) {
- case PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_FILTERTYPE_FILTER :
+ case PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_FILTERTYPE_FILTER:
$ruleValues = array();
// Build a list of the filter value selections
foreach ($rules as $rule) {
@@ -620,8 +620,9 @@ class PHPExcel_Worksheet_AutoFilter
// Test if we want to include blanks in our filter criteria
$blanks = false;
$ruleDataSet = array_filter($ruleValues);
- if (count($ruleValues) != count($ruleDataSet))
+ if (count($ruleValues) != count($ruleDataSet)) {
$blanks = true;
+ }
if ($ruleType == PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_FILTER) {
// Filter on absolute values
$columnFilterTests[$columnID] = array(
@@ -638,23 +639,29 @@ class PHPExcel_Worksheet_AutoFilter
foreach ($ruleDataSet as $ruleValue) {
$date = $time = '';
if ((isset($ruleValue[PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DATEGROUP_YEAR])) &&
- ($ruleValue[PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DATEGROUP_YEAR] !== ''))
+ ($ruleValue[PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DATEGROUP_YEAR] !== '')) {
$date .= sprintf('%04d', $ruleValue[PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DATEGROUP_YEAR]);
+ }
if ((isset($ruleValue[PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DATEGROUP_MONTH])) &&
- ($ruleValue[PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DATEGROUP_MONTH] != ''))
+ ($ruleValue[PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DATEGROUP_MONTH] != '')) {
$date .= sprintf('%02d', $ruleValue[PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DATEGROUP_MONTH]);
+ }
if ((isset($ruleValue[PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DATEGROUP_DAY])) &&
- ($ruleValue[PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DATEGROUP_DAY] !== ''))
+ ($ruleValue[PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DATEGROUP_DAY] !== '')) {
$date .= sprintf('%02d', $ruleValue[PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DATEGROUP_DAY]);
+ }
if ((isset($ruleValue[PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DATEGROUP_HOUR])) &&
- ($ruleValue[PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DATEGROUP_HOUR] !== ''))
+ ($ruleValue[PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DATEGROUP_HOUR] !== '')) {
$time .= sprintf('%02d', $ruleValue[PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DATEGROUP_HOUR]);
+ }
if ((isset($ruleValue[PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DATEGROUP_MINUTE])) &&
- ($ruleValue[PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DATEGROUP_MINUTE] !== ''))
+ ($ruleValue[PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DATEGROUP_MINUTE] !== '')) {
$time .= sprintf('%02d', $ruleValue[PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DATEGROUP_MINUTE]);
+ }
if ((isset($ruleValue[PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DATEGROUP_SECOND])) &&
- ($ruleValue[PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DATEGROUP_SECOND] !== ''))
+ ($ruleValue[PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DATEGROUP_SECOND] !== '')) {
$time .= sprintf('%02d', $ruleValue[PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DATEGROUP_SECOND]);
+ }
$dateTime = $date . $time;
$arguments['date'][] = $date;
$arguments['time'][] = $time;
@@ -670,7 +677,7 @@ class PHPExcel_Worksheet_AutoFilter
);
}
break;
- case PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_FILTERTYPE_CUSTOMFILTER :
+ case PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_FILTERTYPE_CUSTOMFILTER:
$customRuleForBlanks = false;
$ruleValues = array();
// Build a list of the filter value selections
@@ -680,7 +687,7 @@ class PHPExcel_Worksheet_AutoFilter
if (!is_numeric($ruleValue)) {
// Convert to a regexp allowing for regexp reserved characters, wildcards and escaped wildcards
$ruleValue = preg_quote($ruleValue);
- $ruleValue = str_replace(self::$_fromReplace,self::$_toReplace, $ruleValue);
+ $ruleValue = str_replace(self::$_fromReplace, self::$_toReplace, $ruleValue);
if (trim($ruleValue) == '') {
$customRuleForBlanks = true;
$ruleValue = trim($ruleValue);
@@ -694,7 +701,7 @@ class PHPExcel_Worksheet_AutoFilter
'arguments' => array('filterRules' => $ruleValues, 'join' => $join, 'customRuleForBlanks' => $customRuleForBlanks)
);
break;
- case PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_FILTERTYPE_DYNAMICFILTER :
+ case PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_FILTERTYPE_DYNAMICFILTER:
$ruleValues = array();
foreach ($rules as $rule) {
// We should only ever have one Dynamic Filter Rule anyway
@@ -704,7 +711,7 @@ class PHPExcel_Worksheet_AutoFilter
// Number (Average) based
// Calculate the average
$averageFormula = '=AVERAGE('.$columnID.($rangeStart[1]+1).':'.$columnID.$rangeEnd[1].')';
- $average = PHPExcel_Calculation::getInstance()->calculateFormula($averageFormula,null, $this->_workSheet->getCell('A1'));
+ $average = PHPExcel_Calculation::getInstance()->calculateFormula($averageFormula, null, $this->_workSheet->getCell('A1'));
// Set above/below rule based on greaterThan or LessTan
$operator = ($dynamicRuleType === PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_ABOVEAVERAGE)
? PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_GREATERTHAN
@@ -720,14 +727,14 @@ class PHPExcel_Worksheet_AutoFilter
// Date based
if ($dynamicRuleType{0} == 'M' || $dynamicRuleType{0} == 'Q') {
// Month or Quarter
- sscanf($dynamicRuleType,'%[A-Z]%d', $periodType, $period);
+ sscanf($dynamicRuleType, '%[A-Z]%d', $periodType, $period);
if ($periodType == 'M') {
$ruleValues = array($period);
} else {
--$period;
$periodEnd = (1+$period)*3;
$periodStart = 1+$period*3;
- $ruleValues = range($periodStart,periodEnd);
+ $ruleValues = range($periodStart, $periodEnd);
}
$columnFilterTests[$columnID] = array(
'method' => '_filterTestInPeriodDateSet',
@@ -742,7 +749,7 @@ class PHPExcel_Worksheet_AutoFilter
}
}
break;
- case PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_FILTERTYPE_TOPTENFILTER :
+ case PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_FILTERTYPE_TOPTENFILTER:
$ruleValues = array();
$dataRowCount = $rangeEnd[1] - $rangeStart[1];
foreach ($rules as $rule) {
@@ -754,8 +761,12 @@ class PHPExcel_Worksheet_AutoFilter
if ($ruleOperator === PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_TOPTEN_PERCENT) {
$ruleValue = floor($ruleValue * ($dataRowCount / 100));
}
- if ($ruleValue < 1) $ruleValue = 1;
- if ($ruleValue > 500) $ruleValue = 500;
+ if ($ruleValue < 1) {
+ $ruleValue = 1;
+ }
+ if ($ruleValue > 500) {
+ $ruleValue = 500;
+ }
$maxVal = $this->_calculateTopTenValue($columnID, $rangeStart[1]+1, $rangeEnd[1], $toptenRuleType, $ruleValue);
@@ -836,7 +847,8 @@ class PHPExcel_Worksheet_AutoFilter
* toString method replicates previous behavior by returning the range if object is
* referenced as a property of its parent.
*/
- public function __toString() {
+ public function __toString()
+ {
return (string) $this->_range;
}
}
diff --git a/Classes/PHPExcel/Worksheet/PageSetup.php b/Classes/PHPExcel/Worksheet/PageSetup.php
index 71649fce..1e9df19e 100644
--- a/Classes/PHPExcel/Worksheet/PageSetup.php
+++ b/Classes/PHPExcel/Worksheet/PageSetup.php
@@ -366,7 +366,8 @@ class PHPExcel_Worksheet_PageSetup
*
* @return boolean
*/
- public function getFitToPage() {
+ public function getFitToPage()
+ {
return $this->_fitToPage;
}