Project

General

Profile

Bug #22410 » 14050_cleaning_t3lib_svbase.patch

Administrator Admin, 2010-11-24 16:43

View differences:

t3lib/class.t3lib_svbase.php (revision )
<?php
/***************************************************************
* Copyright notice
*
* (c) 1999-2010 Kasper Sk?rh?j (kasperYYYY@typo3.com)
* All rights reserved
*
* This script is part of the Typo3 project. The Typo3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
* Copyright notice
*
* (c) 1999-2010 Kasper Sk?rh?j (kasperYYYY@typo3.com)
* All rights reserved
*
* This script is part of the Typo3 project. The Typo3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Parent class for "Services" classes
*
......
*
* 125: class t3lib_svbase
*
* SECTION: Get service meta information
* SECTION: Get service meta information
* 191: function getServiceInfo()
* 191: function getServiceInfo()
* 201: function getServiceKey()
* 201: function getServiceKey()
* 211: function getServiceTitle()
* 211: function getServiceTitle()
* 224: function getServiceOption($optionName, $defaultValue='', $includeDefaultConfig=TRUE)
* 224: function getServiceOption($optionName, $defaultValue='', $includeDefaultConfig=TRUE)
*
* SECTION: Error handling
* SECTION: Error handling
* 259: function devLog($msg, $severity=0, $dataVar=FALSE)
* 259: function devLog($msg, $severity=0, $dataVar=FALSE)
* 273: function errorPush($errNum=T3_ERR_SV_GENERAL, $errMsg='Unspecified error occured')
* 273: function errorPush($errNum=T3_ERR_SV_GENERAL, $errMsg='Unspecified error occured')
* 288: function errorPull()
* 288: function errorPull()
* 300: function getLastError()
* 300: function getLastError()
* 315: function getLastErrorMsg()
* 315: function getLastErrorMsg()
* 330: function getErrorMsgArray()
* 330: function getErrorMsgArray()
* 348: function getLastErrorArray()
* 348: function getLastErrorArray()
* 357: function resetErrors()
* 357: function resetErrors()
*
* SECTION: General service functions
* SECTION: General service functions
* 377: function checkExec($progList)
* 377: function checkExec($progList)
* 401: function deactivateService()
* 401: function deactivateService()
*
* SECTION: IO tools
* SECTION: IO tools
* 427: function checkInputFile ($absFile)
* 427: function checkInputFile ($absFile)
* 448: function readFile ($absFile, $length=0)
* 448: function readFile ($absFile, $length=0)
* 473: function writeFile ($content, $absFile='')
* 473: function writeFile ($content, $absFile='')
* 499: function tempFile ($filePrefix)
* 499: function tempFile ($filePrefix)
* 517: function registerTempFile ($absFile)
* 517: function registerTempFile ($absFile)
* 527: function unlinkTempFiles ()
* 527: function unlinkTempFiles ()
*
* SECTION: IO input
* SECTION: IO input
* 549: function setInput ($content, $type='')
* 549: function setInput ($content, $type='')
* 563: function setInputFile ($absFile, $type='')
* 563: function setInputFile ($absFile, $type='')
* 576: function getInput ()
* 576: function getInput ()
* 591: function getInputFile ($createFile='')
* 591: function getInputFile ($createFile='')
*
* SECTION: IO output
* SECTION: IO output
* 616: function setOutputFile ($absFile)
* 616: function setOutputFile ($absFile)
* 626: function getOutput ()
* 626: function getOutput ()
* 640: function getOutputFile ($absFile='')
* 640: function getOutputFile ($absFile='')
*
* SECTION: Service implementation
* SECTION: Service implementation
* 664: function init()
* 664: function init()
* 688: function reset()
* 688: function reset()
* 703: function __destruct()
* 703: function __destruct()
*
* TOTAL FUNCTIONS: 30
* (This index is automatically created/updated by the extension "extdeveval")
......
*/
define ('T3_ERR_SV_GENERAL', -1); // General error - something went wrong
define ('T3_ERR_SV_NOT_AVAIL', -2); // During execution it showed that the service is not available and should be ignored. The service itself should call $this->setNonAvailable()
define ('T3_ERR_SV_WRONG_SUBTYPE', -3); // passed subtype is not possible with this service
......
// define ('T3_ERR_SV_serviceType_myerr, -100); // All errors with prefix T3_ERR_SV_[serviceType]_ and lower than -99 are service type dependent error
/**
* Parent class for "Services" classes
*
......
/**
* service description array
*/
var $info=array();
var $info = array();
/**
* error stack
*/
var $error=array();
var $error = array();
/**
* Defines if debug messages should be written with t3lib_div::devLog
*/
var $writeDevLog = false;
var $writeDevLog = FALSE;
/**
......
var $tempFiles = array();
/***************************************
*
* Get service meta information
......
* @param [type] $includeDefaultConfig: ...
* @return mixed configuration value for the service
*/
function getServiceOption($optionName, $defaultValue='', $includeDefaultConfig=TRUE) {
function getServiceOption($optionName, $defaultValue = '', $includeDefaultConfig = TRUE) {
$config = NULL;
$svOptions = $GLOBALS['TYPO3_CONF_VARS']['SVCONF'][$this->info['serviceType']];
if(isset($svOptions[$this->info['serviceKey']][$optionName])) {
if (isset($svOptions[$this->info['serviceKey']][$optionName])) {
$config = $svOptions[$this->info['serviceKey']][$optionName];
} elseif($includeDefaultConfig AND isset($svOptions['default'][$optionName])) {
} elseif ($includeDefaultConfig && isset($svOptions['default'][$optionName])) {
$config = $svOptions['default'][$optionName];
}
if(!isset($config)) {
if (!isset($config)) {
$config = $defaultValue;
}
return $config;
}
/***************************************
*
* Error handling
......
* @param array Additional data you want to pass to the logger.
* @return void
*/
function devLog($msg, $severity=0, $dataVar=FALSE) {
function devLog($msg, $severity = 0, $dataVar = FALSE) {
if($this->writeDevLog) {
if ($this->writeDevLog) {
t3lib_div::devLog($msg, $this->info['serviceKey'], $severity, $dataVar);
}
}
......
* @param string error number (see T3_ERR_SV_* constants)
* @return void
*/
function errorPush($errNum=T3_ERR_SV_GENERAL, $errMsg='Unspecified error occured') {
function errorPush($errNum = T3_ERR_SV_GENERAL, $errMsg = 'Unspecified error occured') {
array_push($this->error, array('nr'=>$errNum, 'msg'=>$errMsg));
array_push($this->error, array('nr' => $errNum, 'msg' => $errMsg));
if (is_object($GLOBALS['TT'])) {
$GLOBALS['TT']->setTSlogMessage($errMsg,2);
$GLOBALS['TT']->setTSlogMessage($errMsg, 2);
}
}
......
* @return string error number
*/
function getLastError() {
if(count($this->error)) {
if (count($this->error)) {
$error = end($this->error);
return $error['nr'];
} else {
......
* @return string error message
*/
function getLastErrorMsg() {
if(count($this->error)) {
if (count($this->error)) {
$error = end($this->error);
return $error['msg'];
} else {
......
function getErrorMsgArray() {
$errArr = array();
if(count($this->error)) {
if (count($this->error)) {
reset($this->error);
foreach($this->error as $error) {
foreach ($this->error as $error) {
$errArr[] = $error['msg'];
}
}
......
* @return void
*/
function resetErrors() {
$this->error=array();
$this->error = array();
}
/***************************************
*
* General service functions
......
***************************************/
/**
* check the availability of external programs
*
......
$ret = TRUE;
$progList = t3lib_div::trimExplode(',', $progList, 1);
foreach($progList as $prog) {
foreach ($progList as $prog) {
if (!t3lib_exec::checkCommand($prog)) {
// program not found
$this->errorPush('External program not found: '.$prog, T3_ERR_SV_PROG_NOT_FOUND);
$this->errorPush('External program not found: ' . $prog, T3_ERR_SV_PROG_NOT_FOUND);
$ret = FALSE;
}
}
......
}
/***************************************
*
* IO tools
......
***************************************/
/**
* Check if a file exists and is readable.
*
* @param string File name with absolute path.
* @return string File name or FALSE.
*/
function checkInputFile ($absFile) {
function checkInputFile($absFile) {
if(t3lib_div::isAllowedAbsPath($absFile) && @is_file($absFile)) {
if (t3lib_div::isAllowedAbsPath($absFile) && @is_file($absFile)) {
if(@is_readable($absFile)) {
if (@is_readable($absFile)) {
return $absFile;
} else {
$this->errorPush(T3_ERR_SV_FILE_READ, 'File is not readable: '.$absFile);
$this->errorPush(T3_ERR_SV_FILE_READ, 'File is not readable: ' . $absFile);
}
} else {
$this->errorPush(T3_ERR_SV_FILE_NOT_FOUND, 'File not found: '.$absFile);
$this->errorPush(T3_ERR_SV_FILE_NOT_FOUND, 'File not found: ' . $absFile);
}
return FALSE;
}
......
* @param integer Maximum length to read. If empty the whole file will be read.
* @return string $content or FALSE
*/
function readFile ($absFile, $length=0) {
function readFile($absFile, $length = 0) {
$out = FALSE;
if ($this->checkInputFile($absFile)) {
$out = file_get_contents($absFile);
if ($out===FALSE) {
if ($out === FALSE) {
$this->errorPush(T3_ERR_SV_FILE_READ, 'Can not read from file: '.$absFile);
$this->errorPush(T3_ERR_SV_FILE_READ, 'Can not read from file: ' . $absFile);
}
}
return $out;
......
* @param string File name to write into. If empty a temp file will be created.
* @return string File name or FALSE
*/
function writeFile ($content, $absFile='') {
function writeFile($content, $absFile = '') {
$ret = TRUE;
if (!$absFile) {
$absFile = $this->tempFile($this->prefixId);
}
if($absFile && t3lib_div::isAllowedAbsPath($absFile)) {
if ($absFile && t3lib_div::isAllowedAbsPath($absFile)) {
if ($fd = @fopen($absFile,'wb')) {
if ($fd = @fopen($absFile, 'wb')) {
@fwrite($fd, $content);
@fclose($fd);
} else {
$this->errorPush(T3_ERR_SV_FILE_WRITE, 'Can not write to file: '.$absFile);
$this->errorPush(T3_ERR_SV_FILE_WRITE, 'Can not write to file: ' . $absFile);
$absFile = FALSE;
}
}
......
* @param string File prefix.
* @return string File name or FALSE
*/
function tempFile ($filePrefix) {
function tempFile($filePrefix) {
$absFile = t3lib_div::tempnam($filePrefix);
if($absFile) {
if ($absFile) {
$ret = TRUE;
$this->registerTempFile ($absFile);
$this->registerTempFile($absFile);
} else {
$ret = FALSE;
$this->errorPush(T3_ERR_SV_FILE_WRITE, 'Can not create temp file.');
......
* @param string File name with absolute path.
* @return void
*/
function registerTempFile ($absFile) {
function registerTempFile($absFile) {
$this->tempFiles[] = $absFile;
}
......
* @param string File name with absolute path.
* @return void
*/
function unlinkTempFiles () {
function unlinkTempFiles() {
foreach ($this->tempFiles as $absFile) {
t3lib_div::unlink_tempfile($absFile);
}
......
* @param string The type of the input content (or file). Might be the same as the service subtypes.
* @return void
*/
function setInput ($content, $type='') {
function setInput($content, $type = '') {
$this->inputContent = $content;
$this->inputFile = '';
$this->inputType = $type;
......
* @param string The type of the input content (or file). Might be the same as the service subtypes.
* @return void
*/
function setInputFile ($absFile, $type='') {
function setInputFile($absFile, $type = '') {
$this->inputContent = '';
$this->inputFile = $absFile;
$this->inputType = $type;
......
*
* @return mixed
*/
function getInput () {
function getInput() {
if ($this->inputContent=='') {
if ($this->inputContent == '') {
$this->inputContent = $this->readFile($this->inputFile);
}
return $this->inputContent;
......
* @param string File name. If empty a temp file will be created.
* @return string File name or FALSE if no input or file error.
*/
function getInputFile ($createFile='') {
function getInputFile($createFile = '') {
if($this->inputFile) {
if ($this->inputFile) {
$this->inputFile = $this->checkInputFile($this->inputFile);
} elseif ($this->inputContent) {
$this->inputFile = $this->writeFile($this->inputContent, $createFile);
......
}
/***************************************
*
* IO output
......
* @param string file name
* @return void
*/
function setOutputFile ($absFile) {
function setOutputFile($absFile) {
$this->outputFile = $absFile;
}
......
*
* @return mixed
*/
function getOutput () {
function getOutput() {
if ($this->outputFile) {
$this->out = $this->readFile($this->outputFile);
}
......
* @param string Absolute filename to write to
* @return mixed
*/
function getOutputFile ($absFile='') {
function getOutputFile($absFile = '') {
if (!$this->outputFile) {
$this->outputFile = $this->writeFile($this->out, $absFile);
}
......
}
/***************************************
*
* Service implementation
......
*
* @return boolean TRUE if the service is available
*/
function init() {
function init() {
// do not work :-( but will not hurt
// do not work :-( but will not hurt
register_shutdown_function(array(&$this, '__destruct'));
// look in makeInstanceService()
// look in makeInstanceService()
$this->reset();
......
}
}
return ($this->getLastError() === true);
return ($this->getLastError() === TRUE);
}
......
*
* @return void
*/
function reset() {
function reset() {
$this->unlinkTempFiles();
$this->resetErrors();
$this->out = '';
......
}
/**
// Does not make sense, because this class is always extended by the service classes..
// Does not make sense, because this class is always extended by the service classes..
if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["t3lib/class.t3lib_svbase.php"]) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["t3lib/class.t3lib_svbase.php"]);
include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["t3lib/class.t3lib_svbase.php"]);
}
*/
*/
?>
(58-58/93)