Documentation TYPO3 par Ameos

class.t3lib_exec.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2002-2004 René Fritz (r.fritz@colorcube.de)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the Typo3 project. The Typo3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *
00017 *  This script is distributed in the hope that it will be useful,
00018 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 *  GNU General Public License for more details.
00021 *
00022 *  This copyright notice MUST APPEAR in all copies of the script!
00023 ***************************************************************/
00081 class t3lib_exec {
00082 
00091         function checkCommand($cmd, $handler='')        {
00092 
00093                 t3lib_exec::_init();
00094                 $osType = t3lib_exec::_getOS();
00095 
00096 
00097 #debug($GLOBALS['t3lib_exec'], 't3lib_exec', __LINE__, __FILE__);
00098 
00099                 if ($handler && !t3lib_exec::checkCommand($handler)) {
00100                         return -1;
00101                 }
00102                         // already checked and valid
00103                 if ($GLOBALS['t3lib_exec']['apps'][$cmd]['valid']) {
00104                         return true;
00105                 }
00106                         // is set but was (above) not true
00107                 if (isset($GLOBALS['t3lib_exec']['apps'][$cmd]['valid'])) {
00108                         return false;
00109                 }
00110 
00111                 reset($GLOBALS['t3lib_exec']['paths']);
00112                 foreach($GLOBALS['t3lib_exec']['paths'] as $path => $validPath) {
00113                                 // ignore invalid (false) paths
00114                         if ($validPath) {
00115                                 if ($osType=='WIN') {
00116                                         if (@is_file($path.$cmd)) {
00117                                                 $GLOBALS['t3lib_exec']['apps'][$cmd]['app'] = $cmd;
00118                                                 $GLOBALS['t3lib_exec']['apps'][$cmd]['path'] = $path;
00119                                                 $GLOBALS['t3lib_exec']['apps'][$cmd]['valid'] = true;
00120                                                 return true;
00121                                         }
00122                                         if (@is_file($path.$cmd.'.exe')) {
00123                                                 $GLOBALS['t3lib_exec']['apps'][$cmd]['app'] = $cmd.'.exe';
00124                                                 $GLOBALS['t3lib_exec']['apps'][$cmd]['path'] = $path;
00125                                                 $GLOBALS['t3lib_exec']['apps'][$cmd]['valid'] = true;
00126                                                 return true;
00127                                         }
00128                                 } else { // UNIX
00129                                         if (@is_executable($path.$cmd)) {
00130                                                 $GLOBALS['t3lib_exec']['apps'][$cmd]['app'] = $cmd;
00131                                                 $GLOBALS['t3lib_exec']['apps'][$cmd]['path'] = $path;
00132                                                 $GLOBALS['t3lib_exec']['apps'][$cmd]['valid'] = true;
00133                                                 return true;
00134                                         }
00135                                 }
00136                         }
00137                 }
00138 
00139                         // try to get the executable with the command 'which'. It do the same like already done, but maybe on other paths??
00140                 if ($osType=='UNIX') {
00141                         $cmd = @exec ('which '.$val['cmd']);
00142 
00143                         if (@is_executable($cmd)) {
00144                                 $GLOBALS['t3lib_exec']['apps'][$cmd]['app'] = $cmd;
00145                                 $GLOBALS['t3lib_exec']['apps'][$cmd]['path'] = dirname($cmd).'/';
00146                                 $GLOBALS['t3lib_exec']['apps'][$cmd]['valid'] = true;
00147                                 return true;
00148                         }
00149                 }
00150 
00151                 return false;
00152         }
00153 
00162         function getCommand($cmd, $handler='', $handlerOpt='')  {
00163 
00164                 t3lib_exec::_init();
00165 
00166                         // handler
00167                 if ($handler) {
00168                         $handler = t3lib_exec::getCommand($handler);
00169 
00170                         if (!$handler) {
00171                                 return -1;
00172                         }
00173                         $handler .= ' '.$handlerOpt.' ';
00174                 }
00175 
00176                         // command
00177                 if (!t3lib_exec::checkCommand($cmd)) {
00178                         return false;
00179                 }
00180                 $cmd = $GLOBALS['t3lib_exec']['apps'][$cmd]['path'].$GLOBALS['t3lib_exec']['apps'][$cmd]['app'].' ';
00181 
00182                 return $handler.$cmd;
00183         }
00184 
00191         function addPaths($paths)       {
00192                 t3lib_exec::_initPaths($paths);
00193         }
00194 
00201         function _getPaths()    {
00202                 global $TYPO3_CONF_VARS;
00203 
00204                 $pathsArr = array();
00205                 $sysPathArr = array();
00206                 $osType = t3lib_exec::_getOS();
00207 
00208                         // image magick paths first
00209                         // im_path_lzw take precedence over im_path
00210                 if ($imPath = ($TYPO3_CONF_VARS['GFX']['im_path_lzw'] ? $TYPO3_CONF_VARS['GFX']['im_path_lzw'] : $TYPO3_CONF_VARS['GFX']['im_path'])) {
00211                         $imPath = t3lib_exec::_fixPath($imPath);
00212                         $pathsArr[$imPath] = $imPath;
00213                 }
00214 
00215                         // add configured paths
00216                 if ($TYPO3_CONF_VARS['SYS']['binPath']) {
00217                         $sysPath = t3lib_div::trimExplode(',',$TYPO3_CONF_VARS['SYS']['binPath'],1);
00218                         reset($sysPath);
00219                         while(list(,$val)=each($sysPath)) {
00220                                 $val = t3lib_exec::_fixPath($val);
00221                                 $sysPathArr[$val]=$val;
00222                         }
00223                 }
00224 
00225 
00226 
00227 
00228 # ???? t3lib_div::getIndpEnv('REQUEST_URI');
00229 
00230 
00231                         // add path from environment
00232 #TODO: how does this work for WIN
00233                 if ($GLOBALS['_SERVER']['PATH']) {
00234                         $sep = ($osType=='WIN') ? ';' : ':';
00235                         $envPath = t3lib_div::trimExplode($sep,$GLOBALS['_SERVER']['PATH'],1);
00236                         reset($envPath);
00237                         while(list(,$val)=each($envPath)) {
00238                                 $val = t3lib_exec::_fixPath($val);
00239                                 $sysPathArr[$val]=$val;
00240                         }
00241                 }
00242 
00243                 if ($osType=='WIN') {
00244 #TODO: add the most common paths for WIN
00245                         $sysPathArr = array_merge($sysPathArr, array (
00246                                 '/usr/bin/' => '/usr/bin/',
00247                                 '/perl/bin/' => '/perl/bin/',
00248                         ));
00249                 } else { // UNIX
00250                         $sysPathArr = array_merge($sysPathArr, array (
00251                                 '/usr/bin/' => '/usr/bin/',
00252                                 '/usr/local/bin/' => '/usr/local/bin/',
00253                         ));
00254                 }
00255 
00256 #debug($pathsArr, '$pathsArr', __LINE__, __FILE__);
00257 #debug($GLOBALS['_SERVER']['PATH'], 'PATH', __LINE__, __FILE__);
00258 
00259                 $pathsArr = array_merge($pathsArr, $sysPathArr);
00260                 return $pathsArr;
00261         }
00262 
00269         function _init()        {
00270                 if (!$GLOBALS['t3lib_exec']['init']) {
00271 
00272                         t3lib_exec::_initPaths();
00273                         $GLOBALS['t3lib_exec']['apps'] = array();
00274                         $GLOBALS['t3lib_exec']['init'] = true;
00275                 }
00276         }
00277 
00285         function _initPaths($paths='')  {
00286                 $doCeck=false;
00287 
00288                         // init global paths array if not already done
00289                 if (!is_array($GLOBALS['t3lib_exec']['paths'])) {
00290                         $GLOBALS['t3lib_exec']['paths'] = t3lib_exec::_getPaths();
00291                         $doCeck=true;
00292                 }
00293                         // merge the submitted paths array to the global
00294                 if ($paths) {
00295                         $paths = t3lib_div::trimExplode(',',$paths,1);
00296                         if (is_array($paths)) {
00297                                 reset($paths);
00298                                 while(list(,$path)=each($paths)) {
00299                                                 // make absolute path of relative
00300                                         if (!preg_match('#^/#',$path)) {
00301                                                 $path = PATH_site.$path;
00302                                         }
00303                                         if (!isset($GLOBALS['t3lib_exec']['paths'][$path])) {
00304                                                 if (@is_dir($path)) {
00305                                                         $GLOBALS['t3lib_exec']['paths'][$path] = $path;
00306                                                         $GLOBALS['t3lib_exec']['allPaths'].=','.$path;
00307                                                         // $doCeck=true; just done
00308                                                 } else {
00309                                                         $GLOBALS['t3lib_exec']['paths'][$path] = false;
00310                                                 }
00311                                         }
00312                                 }
00313                         }
00314                 }
00315                         // check if new paths are invalid
00316                 if ($doCeck) {
00317                         $GLOBALS['t3lib_exec']['allPaths']='';
00318                         reset($GLOBALS['t3lib_exec']['paths']);
00319                         while(list($path,$valid)=each($GLOBALS['t3lib_exec']['paths'])) {
00320                                         // ignore invalid (false) paths
00321 #TODO: what's the idea not to remove invalid paths?
00322                                 if ($valid) {
00323                                         if (!@is_dir($path)) {
00324                                                 $GLOBALS['t3lib_exec']['paths'][$path] = false;
00325                                         }
00326                                 }
00327                                 if ($path = $GLOBALS['t3lib_exec']['paths'][$path]) {
00328                                         $GLOBALS['t3lib_exec']['allPaths'].=','.$path;
00329                                 }
00330                         }
00331                 }
00332         }
00333 
00340         function _getOS()       {
00341                 return stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':'UNIX';
00342         }
00343 
00351         function _fixPath($path)        {
00352                 return str_replace ('//',"/",$path.'/');
00353         }
00354 }
00355 
00356 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_exec.php'])      {
00357         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_exec.php']);
00358 }
00359 ?>


Généré par Les spécialistes TYPO3 avec  doxygen 1.4.6