"TYPO3 4.0.1: typo3_src-4.0.1/t3lib/class.t3lib_exec.php Source File", "datetime" => "Sat Dec 2 19:22:17 2006", "date" => "2 Dec 2006", "doxygenversion" => "1.4.6", "projectname" => "TYPO3 4.0.1", "projectnumber" => "4.0.1" ); get_header($doxygen_vars); ?>
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2002-2006 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 ***************************************************************/ 00085 class t3lib_exec { 00086 00095 function checkCommand($cmd, $handler='') { 00096 global $T3_VAR; 00097 00098 if (!t3lib_exec::_init()) { 00099 return false; 00100 } 00101 00102 00103 if ($handler && !t3lib_exec::checkCommand($handler)) { 00104 return -1; 00105 } 00106 // already checked and valid 00107 if ($T3_VAR['t3lib_exec']['apps'][$cmd]['valid']) { 00108 return true; 00109 } 00110 // is set but was (above) not true 00111 if (isset($T3_VAR['t3lib_exec']['apps'][$cmd]['valid'])) { 00112 return false; 00113 } 00114 00115 foreach($T3_VAR['t3lib_exec']['paths'] as $path => $validPath) { 00116 // ignore invalid (false) paths 00117 if ($validPath) { 00118 if (TYPO3_OS=='WIN') { 00119 if (@is_file($path.$cmd)) { 00120 $T3_VAR['t3lib_exec']['apps'][$cmd]['app'] = $cmd; 00121 $T3_VAR['t3lib_exec']['apps'][$cmd]['path'] = $path; 00122 $T3_VAR['t3lib_exec']['apps'][$cmd]['valid'] = true; 00123 return true; 00124 } 00125 if (@is_file($path.$cmd.'.exe')) { 00126 $T3_VAR['t3lib_exec']['apps'][$cmd]['app'] = $cmd.'.exe'; 00127 $T3_VAR['t3lib_exec']['apps'][$cmd]['path'] = $path; 00128 $T3_VAR['t3lib_exec']['apps'][$cmd]['valid'] = true; 00129 return true; 00130 } 00131 } else { // UNIX 00132 if (@is_executable($path.$cmd)) { 00133 $T3_VAR['t3lib_exec']['apps'][$cmd]['app'] = $cmd; 00134 $T3_VAR['t3lib_exec']['apps'][$cmd]['path'] = $path; 00135 $T3_VAR['t3lib_exec']['apps'][$cmd]['valid'] = true; 00136 return true; 00137 } 00138 } 00139 } 00140 } 00141 00142 // try to get the executable with the command 'which'. It do the same like already done, but maybe on other paths?? 00143 if (TYPO3_OS!='WIN') { 00144 $cmd = @exec ('which '.$cmd); 00145 00146 if (@is_executable($cmd)) { 00147 $T3_VAR['t3lib_exec']['apps'][$cmd]['app'] = $cmd; 00148 $T3_VAR['t3lib_exec']['apps'][$cmd]['path'] = dirname($cmd).'/'; 00149 $T3_VAR['t3lib_exec']['apps'][$cmd]['valid'] = true; 00150 return true; 00151 } 00152 } 00153 00154 return false; 00155 } 00156 00157 00166 function getCommand($cmd, $handler='', $handlerOpt='') { 00167 global $T3_VAR; 00168 00169 if (!t3lib_exec::_init()) { 00170 return false; 00171 } 00172 00173 // handler 00174 if ($handler) { 00175 $handler = t3lib_exec::getCommand($handler); 00176 00177 if (!$handler) { 00178 return -1; 00179 } 00180 $handler .= ' '.$handlerOpt.' '; 00181 } 00182 00183 // command 00184 if (!t3lib_exec::checkCommand($cmd)) { 00185 return false; 00186 } 00187 $cmd = $T3_VAR['t3lib_exec']['apps'][$cmd]['path'].$T3_VAR['t3lib_exec']['apps'][$cmd]['app'].' '; 00188 00189 return trim($handler.$cmd); 00190 } 00191 00192 00199 function addPaths($paths) { 00200 t3lib_exec::_initPaths($paths); 00201 } 00202 00203 00204 00211 function getPaths($addInvalid=false) { 00212 global $T3_VAR; 00213 00214 if (!t3lib_exec::_init()) { 00215 return array(); 00216 } 00217 00218 $paths = $T3_VAR['t3lib_exec']['paths']; 00219 if(!$addInvalid) { 00220 00221 foreach($paths as $path => $validPath) { 00222 if(!$validPath) { 00223 unset($paths); 00224 } 00225 } 00226 } 00227 return $paths; 00228 } 00229 00230 00237 function _init() { 00238 global $T3_VAR, $TYPO3_CONF_VARS; 00239 00240 if ($TYPO3_CONF_VARS['BE']['disable_exec_function']) { 00241 return false; 00242 } 00243 if (!$T3_VAR['t3lib_exec']['init']) { 00244 t3lib_exec::_initPaths(); 00245 $T3_VAR['t3lib_exec']['apps'] = t3lib_exec::_getConfiguredApps();; 00246 $T3_VAR['t3lib_exec']['init'] = true; 00247 } 00248 return true; 00249 } 00250 00251 00259 function _initPaths($paths='') { 00260 global $T3_VAR; 00261 00262 $doCeck=false; 00263 00264 // init global paths array if not already done 00265 if (!is_array($T3_VAR['t3lib_exec']['paths'])) { 00266 $T3_VAR['t3lib_exec']['paths'] = t3lib_exec::_getPaths(); 00267 $doCeck=true; 00268 } 00269 // merge the submitted paths array to the global 00270 if ($paths) { 00271 $paths = t3lib_div::trimExplode(',',$paths,1); 00272 if (is_array($paths)) { 00273 foreach($paths as $path) { 00274 // make absolute path of relative 00275 if (!preg_match('#^/#',$path)) { 00276 $path = PATH_site.$path; 00277 } 00278 if (!isset($T3_VAR['t3lib_exec']['paths'][$path])) { 00279 if (@is_dir($path)) { 00280 $T3_VAR['t3lib_exec']['paths'][$path] = $path; 00281 $T3_VAR['t3lib_exec']['allPaths'].=','.$path; 00282 // $doCeck=true; just done 00283 } else { 00284 $T3_VAR['t3lib_exec']['paths'][$path] = false; 00285 } 00286 } 00287 } 00288 } 00289 } 00290 // check if new paths are invalid 00291 if ($doCeck) { 00292 $T3_VAR['t3lib_exec']['allPaths']=''; 00293 foreach($T3_VAR['t3lib_exec']['paths'] as $path => $valid) { 00294 // ignore invalid (false) paths 00295 if ($valid AND !@is_dir($path)) { 00296 $T3_VAR['t3lib_exec']['paths'][$path] = false; 00297 } 00298 if ($path = $T3_VAR['t3lib_exec']['paths'][$path]) { 00299 $T3_VAR['t3lib_exec']['allPaths'].=','.$path; 00300 } 00301 } 00302 } 00303 } 00304 00305 00312 function _getConfiguredApps() { 00313 global $TYPO3_CONF_VARS; 00314 00315 $cmdArr = array(); 00316 00317 if ($TYPO3_CONF_VARS['SYS']['binSetup']) { 00318 $pathSetup = implode("\n", t3lib_div::trimExplode(',',$TYPO3_CONF_VARS['SYS']['binSetup'],1)); 00319 $pathSetup = t3lib_div::trimExplode("\n",$pathSetup,1); 00320 foreach($pathSetup as $val) { 00321 list($cmd, $cmdPath) = t3lib_div::trimExplode('=',$val,1); 00322 00323 $cmdArr[$cmd]['app'] = basename($cmdPath); 00324 $cmdArr[$cmd]['path'] = dirname($cmdPath).'/'; 00325 $cmdArr[$cmd]['valid'] = true; 00326 } 00327 } 00328 00329 return $cmdArr; 00330 } 00331 00332 00339 function _getPaths() { 00340 global $T3_VAR, $TYPO3_CONF_VARS; 00341 00342 $pathsArr = array(); 00343 $sysPathArr = array(); 00344 00345 // image magick paths first 00346 // im_path_lzw take precedence over im_path 00347 if ($imPath = ($TYPO3_CONF_VARS['GFX']['im_path_lzw'] ? $TYPO3_CONF_VARS['GFX']['im_path_lzw'] : $TYPO3_CONF_VARS['GFX']['im_path'])) { 00348 $imPath = t3lib_exec::_fixPath($imPath); 00349 $pathsArr[$imPath] = $imPath; 00350 } 00351 00352 // add configured paths 00353 if ($TYPO3_CONF_VARS['SYS']['binPath']) { 00354 $sysPath = t3lib_div::trimExplode(',',$TYPO3_CONF_VARS['SYS']['binPath'],1); 00355 foreach($sysPath as $val) { 00356 $val = t3lib_exec::_fixPath($val); 00357 $sysPathArr[$val]=$val; 00358 } 00359 } 00360 00361 00362 // add path from environment 00363 // TODO: how does this work for WIN 00364 if ($GLOBALS['_SERVER']['PATH']) { 00365 $sep = (TYPO3_OS=='WIN') ? ';' : ':'; 00366 $envPath = t3lib_div::trimExplode($sep,$GLOBALS['_SERVER']['PATH'],1); 00367 foreach($envPath as $val) { 00368 $val = t3lib_exec::_fixPath($val); 00369 $sysPathArr[$val]=$val; 00370 } 00371 } 00372 00373 if (TYPO3_OS=='WIN') { 00374 // TODO: add the most common paths for WIN 00375 $sysPathArr = array_merge($sysPathArr, array ( 00376 '/usr/bin/' => '/usr/bin/', 00377 '/perl/bin/' => '/perl/bin/', 00378 )); 00379 } else { // UNIX 00380 $sysPathArr = array_merge($sysPathArr, array ( 00381 '/usr/bin/' => '/usr/bin/', 00382 '/usr/local/bin/' => '/usr/local/bin/', 00383 )); 00384 } 00385 00386 00387 $pathsArr = array_merge($pathsArr, $sysPathArr); 00388 00389 return $pathsArr; 00390 } 00391 00392 00400 function _fixPath($path) { 00401 return str_replace ('//','/',$path.'/'); 00402 } 00403 } 00404 00405 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_exec.php']) { 00406 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_exec.php']); 00407 } 00408 ?>