00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00079 class t3lib_loadModules {
00080 var $modules = Array();
00081 var $absPathArray = array();
00082
00083 var $modListGroup = Array();
00084 var $modListUser = Array();
00085
00091 var $BE_USER = '';
00092 var $observeWorkspaces = FALSE;
00093
00094
00104 function load($modulesArray,$BE_USER='') {
00105
00106 if (is_object($BE_USER)) {
00107 $this->BE_USER = $BE_USER;
00108 } else {
00109 $this->BE_USER = $GLOBALS['BE_USER'];
00110 }
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 $this->absPathArray = $modulesArray['_PATHS'];
00136 unset($modulesArray['_PATHS']);
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172 $theMods = $this->parseModulesArray($modulesArray);
00173
00174
00175
00176
00177
00178
00179
00180
00181 $paths = array();
00182 $paths['defMods'] = PATH_typo3.'mod/';
00183 $paths['userMods'] = PATH_typo3.'../typo3conf/';
00184
00185
00186 foreach($theMods as $mods => $subMod) {
00187 $path = NULL;
00188
00189 $extModRelPath = $this->checkExtensionModule($mods);
00190 if ($extModRelPath) {
00191 $theMainMod = $this->checkMod($mods,PATH_site.$extModRelPath);
00192 if (is_array($theMainMod) || $theMainMod!='notFound') {
00193 $path = 1;
00194 }
00195 } else {
00196
00197 $theMainMod = $this->checkMod($mods,$paths['defMods'].$mods);
00198 if (is_array($theMainMod) || $theMainMod!='notFound') {
00199 $path = $paths['defMods'];
00200 } else {
00201
00202 $theMainMod = $this->checkMod($mods,$paths['userMods'].$mods);
00203 if (is_array($theMainMod) || $theMainMod!='notFound') {
00204 $path = $paths['userMods'];
00205 }
00206 }
00207 }
00208
00209
00210 if ($theMainMod && !is_null($path)) {
00211 $this->modules[$mods] = $theMainMod;
00212
00213
00214 if ($mods!='doc' && is_array($subMod)) {
00215 foreach($subMod as $valsub) {
00216 $extModRelPath = $this->checkExtensionModule($mods.'_'.$valsub);
00217 if ($extModRelPath) {
00218 $theTempSubMod = $this->checkMod($mods.'_'.$valsub,PATH_site.$extModRelPath);
00219 if (is_array($theTempSubMod)) {
00220 $this->modules[$mods]['sub'][$valsub] = $theTempSubMod;
00221 }
00222 } else {
00223
00224
00225 $theTempSubMod = $this->checkMod($mods.'_'.$valsub,$path.$mods.'/'.$valsub);
00226 if (is_array($theTempSubMod)) {
00227 $this->modules[$mods]['sub'][$valsub] = $theTempSubMod;
00228 } elseif ($path == $paths['defMods']) {
00229 $theTempSubMod = $this->checkMod($mods.'_'.$valsub,$paths['userMods'].$mods.'/'.$valsub);
00230 if (is_array($theTempSubMod)) {
00231 $this->modules[$mods]['sub'][$valsub] = $theTempSubMod;
00232 }
00233 }
00234 }
00235 }
00236 }
00237 } else {
00238 if ($mods!='doc' && is_array($subMod)) {
00239 foreach($subMod as $valsub) {
00240
00241 $this->checkMod($mods.'_'.$valsub,$path.$mods.'/'.$valsub);
00242 }
00243 }
00244 }
00245 }
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365 #debug($this->modules);
00366 #debug($GLOBALS['LANG']->moduleLabels);
00367 }
00368
00375 function checkExtensionModule($name) {
00376 global $TYPO3_LOADED_EXT;
00377
00378 if (isset($this->absPathArray[$name])) {
00379 return ereg_replace ('\/$', '', substr($this->absPathArray[$name],strlen(PATH_site)));
00380 }
00381 }
00382
00394 function checkMod($name, $fullpath) {
00395 $modconf=Array();
00396 $path = ereg_replace ('/[^/.]+/\.\./', '/', $fullpath);
00397 if (@is_dir($path) && @file_exists($path.'/conf.php')) {
00398 $MCONF = array();
00399 $MLANG = array();
00400 include($path.'/conf.php');
00401 if (!$MCONF['shy'] && $this->checkModAccess($name,$MCONF) && $this->checkModWorkspace($name,$MCONF)) {
00402 $modconf['name']=$name;
00403
00404 if (is_object($GLOBALS['LANG'])) {
00405
00406
00407 if ($MLANG['default']['tabs_images']['tab']) {
00408
00409
00410 $altIconKey = 'MOD:'.$name.'/'.$MLANG['default']['tabs_images']['tab'];
00411 $altIconAbsPath = is_array($GLOBALS['TBE_STYLES']['skinImg'][$altIconKey]) ? t3lib_div::resolveBackPath(PATH_typo3.$GLOBALS['TBE_STYLES']['skinImg'][$altIconKey][0]) : '';
00412
00413
00414 if ($altIconAbsPath && @is_file($altIconAbsPath)) {
00415 $MLANG['default']['tabs_images']['tab']=$this->getRelativePath(PATH_typo3,$altIconAbsPath);
00416 } else {
00417
00418 $MLANG['default']['tabs_images']['tab']=$this->getRelativePath(PATH_typo3,$fullpath.'/'.$MLANG['default']['tabs_images']['tab']);
00419 }
00420
00421
00422 if (substr($MLANG['default']['tabs_images']['tab'],0,3)=='../') {
00423 $MLANG['default']['tabs_images']['tab'] = PATH_site.substr($MLANG['default']['tabs_images']['tab'],3);
00424 } else {
00425 $MLANG['default']['tabs_images']['tab'] = PATH_typo3.$MLANG['default']['tabs_images']['tab'];
00426 }
00427 }
00428
00429
00430 if ($MLANG['default']['ll_ref']) {
00431
00432 $MLANG['default']['labels']['tablabel'] = $GLOBALS['LANG']->sL($MLANG['default']['ll_ref'].':mlang_labels_tablabel');
00433 $MLANG['default']['labels']['tabdescr'] = $GLOBALS['LANG']->sL($MLANG['default']['ll_ref'].':mlang_labels_tabdescr');
00434 $MLANG['default']['tabs']['tab'] = $GLOBALS['LANG']->sL($MLANG['default']['ll_ref'].':mlang_tabs_tab');
00435 $GLOBALS['LANG']->addModuleLabels($MLANG['default'],$name.'_');
00436 } else {
00437 $GLOBALS['LANG']->addModuleLabels($MLANG['default'],$name.'_');
00438 $GLOBALS['LANG']->addModuleLabels($MLANG[$GLOBALS['LANG']->lang],$name.'_');
00439 }
00440 }
00441
00442
00443 if ($MCONF['script']==='_DISPATCH') {
00444 $modconf['script'] = 'mod.php?M='.rawurlencode($name);
00445 } elseif ($MCONF['script'] && @file_exists($path.'/'.$MCONF['script'])) {
00446 $modconf['script'] = $this->getRelativePath(PATH_typo3,$fullpath.'/'.$MCONF['script']);
00447 } else {
00448 $modconf['script'] = 'dummy.php';
00449 }
00450
00451 if ($MCONF['defaultMod']) {
00452 $modconf['defaultMod'] = $MCONF['defaultMod'];
00453 }
00454
00455 if ($MCONF['navFrameScript']) {
00456 $navFrameScript = explode('?', $MCONF['navFrameScript']);
00457 $navFrameScript = $navFrameScript[0];
00458 if (@file_exists($path.'/'.$navFrameScript)) {
00459 $modconf['navFrameScript'] = $this->getRelativePath(PATH_typo3,$fullpath.'/'.$MCONF['navFrameScript']);
00460 }
00461 }
00462
00463 if ($MCONF['navFrameScriptParam']) {
00464 $modconf['navFrameScriptParam'] = $MCONF['navFrameScriptParam'];
00465 }
00466 } else return false;
00467 } else $modconf = 'notFound';
00468 return $modconf;
00469 }
00470
00478 function checkModAccess($name,$MCONF) {
00479 if ($MCONF['access']) {
00480 $access=strtolower($MCONF['access']);
00481
00482 if (strstr($access,'admin')) {
00483 if ($this->BE_USER->isAdmin()) {return true;}
00484 }
00485
00486 if (strstr($access,'user')) { $this->modListUser[]=$name; }
00487 if (strstr($access,'group')) { $this->modListGroup[]=$name; }
00488
00489 if ($this->BE_USER->isAdmin() || $this->BE_USER->check('modules',$name)) {return true;}
00490
00491 } else return true;
00492 }
00493
00502 function checkModWorkspace($name,$MCONF) {
00503 if ($this->observeWorkspaces) {
00504 $status = TRUE;
00505 if ($MCONF['workspaces']) {
00506 $status = FALSE;
00507 if (($this->BE_USER->workspace===0 && t3lib_div::inList($MCONF['workspaces'],'online')) ||
00508 ($this->BE_USER->workspace===-1 && t3lib_div::inList($MCONF['workspaces'],'offline')) ||
00509 ($this->BE_USER->workspace>0 && t3lib_div::inList($MCONF['workspaces'],'custom'))) {
00510 $status = TRUE;
00511 }
00512 } elseif ($this->BE_USER->workspace===-99) {
00513 $status = FALSE;
00514 }
00515 return $status;
00516 } else return TRUE;
00517 }
00518
00526 function parseModulesArray($arr) {
00527 $theMods = Array();
00528 if (is_array($arr)) {
00529 foreach($arr as $mod => $subs) {
00530 $mod = $this->cleanName($mod);
00531 if ($mod) {
00532 if ($subs) {
00533 $subsArr = t3lib_div::trimExplode(',', $subs);
00534 foreach($subsArr as $subMod) {
00535 $subMod = $this->cleanName($subMod);
00536 if ($subMod) {
00537 $theMods[$mod][] = $subMod;
00538 }
00539 }
00540 } else {
00541 $theMods[$mod] = 1;
00542 }
00543 }
00544 }
00545 }
00546 return $theMods;
00547 }
00548
00555 function cleanName ($str) {
00556 return preg_replace('/[^a-z0-9]/i','',$str);
00557 }
00558
00566 function getRelativePath($baseDir,$destDir){
00567
00568
00569 if ($baseDir == $destDir){
00570 return './';
00571 }
00572
00573 $baseDir = ereg_replace ('^/', '', $baseDir);
00574 $destDir = ereg_replace ('^/', '', $destDir);
00575
00576 $found = true;
00577 $slash_pos=0;
00578
00579 do {
00580 $slash_pos = strpos ($destDir, '/');
00581 if (substr($destDir, 0, $slash_pos) == substr($baseDir, 0, $slash_pos)){
00582 $baseDir = substr($baseDir, $slash_pos+1);
00583 $destDir = substr($destDir, $slash_pos+1);
00584 } else {
00585 $found = false;
00586 }
00587 } while($found == true);
00588
00589 $slashes = strlen ($baseDir) - strlen (str_replace('/', '', $baseDir));
00590 for($i=0;$i < $slashes;$i++) {
00591 $destDir = '../'.$destDir;
00592 }
00593 return $destDir;
00594 }
00595 }
00596
00597
00598 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_loadmodules.php']) {
00599 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_loadmodules.php']);
00600 }
00601 ?>
This documentation has been generated automatically from TYPO3 source code using
Doxygen and is provided as is by
Cast Iron Coding
as a courtesy to other TYPO3 developers and users. Please consider
Cast Iron Coding — a full-service web development
agency in Portland, Oregon specializing in TYPO3 extension development — for all of your TYPO3 development and consulting needs!