Documentation TYPO3 par Ameos

class.t3lib_exec.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2002-2005 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                 global $T3_VAR;
00093 
00094                 if (!t3lib_exec::_init()) {
00095                         return false;
00096                 }
00097 
00098                 $osType = t3lib_exec::_getOS();
00099 
00100 
00101                 if ($handler && !t3lib_exec::checkCommand($handler)) {
00102                         return -1;
00103                 }
00104                         // already checked and valid
00105                 if ($T3_VAR['t3lib_exec']['apps'][$cmd]['valid']) {
00106                         return true;
00107                 }
00108                         // is set but was (above) not true
00109                 if (isset($T3_VAR['t3lib_exec']['apps'][$cmd]['valid'])) {
00110                         return false;
00111                 }
00112 
00113                 foreach($T3_VAR['t3lib_exec']['paths'] as $path => $validPath) {
00114                                 // ignore invalid (false) paths
00115                         if ($validPath) {
00116                                 if ($osType=='WIN') {
00117                                         if (@is_file($path.$cmd)) {
00118                                                 $T3_VAR['t3lib_exec']['apps'][$cmd]['app'] = $cmd;
00119                                                 $T3_VAR['t3lib_exec']['apps'][$cmd]['path'] = $path;
00120                                                 $T3_VAR['t3lib_exec']['apps'][$cmd]['valid'] = true;
00121                                                 return true;
00122                                         }
00123                                         if (@is_file($path.$cmd.'.exe')) {
00124                                                 $T3_VAR['t3lib_exec']['apps'][$cmd]['app'] = $cmd.'.exe';
00125                                                 $T3_VAR['t3lib_exec']['apps'][$cmd]['path'] = $path;
00126                                                 $T3_VAR['t3lib_exec']['apps'][$cmd]['valid'] = true;
00127                                                 return true;
00128                                         }
00129                                 } else { // UNIX
00130                                         if (@is_executable($path.$cmd)) {
00131                                                 $T3_VAR['t3lib_exec']['apps'][$cmd]['app'] = $cmd;
00132                                                 $T3_VAR['t3lib_exec']['apps'][$cmd]['path'] = $path;
00133                                                 $T3_VAR['t3lib_exec']['apps'][$cmd]['valid'] = true;
00134                                                 return true;
00135                                         }
00136                                 }
00137                         }
00138                 }
00139 
00140                         // try to get the executable with the command 'which'. It do the same like already done, but maybe on other paths??
00141                 if ($osType=='UNIX') {
00142                         $cmd = @exec ('which '.$val['cmd']);
00143 
00144                         if (@is_executable($cmd)) {
00145                                 $T3_VAR['t3lib_exec']['apps'][$cmd]['app'] = $cmd;
00146                                 $T3_VAR['t3lib_exec']['apps'][$cmd]['path'] = dirname($cmd).'/';
00147                                 $T3_VAR['t3lib_exec']['apps'][$cmd]['valid'] = true;
00148                                 return true;
00149                         }
00150                 }
00151 
00152                 return false;
00153         }
00154 
00155 
00164         function getCommand($cmd, $handler='', $handlerOpt='')  {
00165                 global $T3_VAR;
00166 
00167                 if (!t3lib_exec::_init()) {
00168                         return false;
00169                 }
00170 
00171                         // handler
00172                 if ($handler) {
00173                         $handler = t3lib_exec::getCommand($handler);
00174 
00175                         if (!$handler) {
00176                                 return -1;
00177                         }
00178                         $handler .= ' '.$handlerOpt.' ';
00179                 }
00180 
00181                         // command
00182                 if (!t3lib_exec::checkCommand($cmd)) {
00183                         return false;
00184                 }
00185                 $cmd = $T3_VAR['t3lib_exec']['apps'][$cmd]['path'].$T3_VAR['t3lib_exec']['apps'][$cmd]['app'].' ';
00186 
00187                 return $handler.$cmd;
00188         }
00189 
00190 
00197         function addPaths($paths)       {
00198                 t3lib_exec::_initPaths($paths);
00199         }
00200 
00201 
00202 
00209         function getPaths($addInvalid=false)    {
00210                 global $T3_VAR;
00211 
00212                 if (!t3lib_exec::_init()) {
00213                         return array();
00214                 }
00215 
00216                 $paths = $T3_VAR['t3lib_exec']['paths'];
00217                 if(!$addInvalid) {
00218 
00219                         foreach($paths as $path => $validPath) {
00220                                 if(!$validPath) {
00221                                         unset($paths);
00222                                 }
00223                         }
00224                 }
00225                 return $paths;
00226         }
00227 
00228 
00235         function _getPaths()    {
00236                 global $T3_VAR, $TYPO3_CONF_VARS;
00237 
00238                 $pathsArr = array();
00239                 $sysPathArr = array();
00240                 $osType = t3lib_exec::_getOS();
00241 
00242                         // image magick paths first
00243                         // im_path_lzw take precedence over im_path
00244                 if ($imPath = ($TYPO3_CONF_VARS['GFX']['im_path_lzw'] ? $TYPO3_CONF_VARS['GFX']['im_path_lzw'] : $TYPO3_CONF_VARS['GFX']['im_path'])) {
00245                         $imPath = t3lib_exec::_fixPath($imPath);
00246                         $pathsArr[$imPath] = $imPath;
00247                 }
00248 
00249                         // add configured paths
00250                 if ($TYPO3_CONF_VARS['SYS']['binPath']) {
00251                         $sysPath = t3lib_div::trimExplode(',',$TYPO3_CONF_VARS['SYS']['binPath'],1);
00252                         foreach($sysPath as $val) {
00253                                 $val = t3lib_exec::_fixPath($val);
00254                                 $sysPathArr[$val]=$val;
00255                         }
00256                 }
00257 
00258 
00259                         // add path from environment
00260 #TODO: how does this work for WIN
00261                 if ($GLOBALS['_SERVER']['PATH']) {
00262                         $sep = ($osType=='WIN') ? ';' : ':';
00263                         $envPath = t3lib_div::trimExplode($sep,$GLOBALS['_SERVER']['PATH'],1);
00264                         foreach($envPath as $val) {
00265                                 $val = t3lib_exec::_fixPath($val);
00266                                 $sysPathArr[$val]=$val;
00267                         }
00268                 }
00269 
00270                 if ($osType=='WIN') {
00271 #TODO: add the most common paths for WIN
00272                         $sysPathArr = array_merge($sysPathArr, array (
00273                                 '/usr/bin/' => '/usr/bin/',
00274                                 '/perl/bin/' => '/perl/bin/',
00275                         ));
00276                 } else { // UNIX
00277                         $sysPathArr = array_merge($sysPathArr, array (
00278                                 '/usr/bin/' => '/usr/bin/',
00279                                 '/usr/local/bin/' => '/usr/local/bin/',
00280                         ));
00281                 }
00282 
00283 
00284                 $pathsArr = array_merge($pathsArr, $sysPathArr);
00285 
00286                 return $pathsArr;
00287         }
00288 
00289 
00296         function _init()        {
00297                 global $T3_VAR, $TYPO3_CONF_VARS;
00298 
00299                 if ($TYPO3_CONF_VARS['BE']['disable_exec_function']) {
00300                         return false;
00301                 }
00302                 if (!$T3_VAR['t3lib_exec']['init']) {
00303                         t3lib_exec::_initPaths();
00304                         $T3_VAR['t3lib_exec']['apps'] = array();
00305                         $T3_VAR['t3lib_exec']['init'] = true;
00306                 }
00307                 return true;
00308         }
00309 
00310 
00318         function _initPaths($paths='')  {
00319                 global $T3_VAR;
00320 
00321                 $doCeck=false;
00322 
00323                         // init global paths array if not already done
00324                 if (!is_array($T3_VAR['t3lib_exec']['paths'])) {
00325                         $T3_VAR['t3lib_exec']['paths'] = t3lib_exec::_getPaths();
00326                         $doCeck=true;
00327                 }
00328                         // merge the submitted paths array to the global
00329                 if ($paths) {
00330                         $paths = t3lib_div::trimExplode(',',$paths,1);
00331                         if (is_array($paths)) {
00332                                 foreach($paths as $path) {
00333                                                 // make absolute path of relative
00334                                         if (!preg_match('#^/#',$path)) {
00335                                                 $path = PATH_site.$path;
00336                                         }
00337                                         if (!isset($T3_VAR['t3lib_exec']['paths'][$path])) {
00338                                                 if (@is_dir($path)) {
00339                                                         $T3_VAR['t3lib_exec']['paths'][$path] = $path;
00340                                                         $T3_VAR['t3lib_exec']['allPaths'].=','.$path;
00341                                                         // $doCeck=true; just done
00342                                                 } else {
00343                                                         $T3_VAR['t3lib_exec']['paths'][$path] = false;
00344                                                 }
00345                                         }
00346                                 }
00347                         }
00348                 }
00349                         // check if new paths are invalid
00350                 if ($doCeck) {
00351                         $T3_VAR['t3lib_exec']['allPaths']='';
00352                         foreach($T3_VAR['t3lib_exec']['paths'] as $path => $valid) {
00353                                         // ignore invalid (false) paths
00354                                 if ($valid AND !@is_dir($path)) {
00355                                         $T3_VAR['t3lib_exec']['paths'][$path] = false;
00356                                 }
00357                                 if ($path = $T3_VAR['t3lib_exec']['paths'][$path]) {
00358                                         $T3_VAR['t3lib_exec']['allPaths'].=','.$path;
00359                                 }
00360                         }
00361                 }
00362         }
00363 
00364 
00371         function _getOS()       {
00372                 return stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':'UNIX';
00373         }
00374 
00375 
00383         function _fixPath($path)        {
00384                 return str_replace ('//','/',$path.'/');
00385         }
00386 }
00387 
00388 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_exec.php'])      {
00389         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_exec.php']);
00390 }
00391 ?>


Généré par TYPO3 Ameos avec  doxygen 1.4.6