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
00086 var $BE_USER = '';
00087 var $observeWorkspaces = FALSE;
00088
00089
00099 function load($modulesArray,$BE_USER='') {
00100
00101 if (is_object($BE_USER)) {
00102 $this->BE_USER = $BE_USER;
00103 } else {
00104 $this->BE_USER = $GLOBALS['BE_USER'];
00105 }
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130 $this->absPathArray = $modulesArray['_PATHS'];
00131 unset($modulesArray['_PATHS']);
00132
00133
00134
00135
00136
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 $theMods = $this->parseModulesArray($modulesArray);
00168
00169
00170
00171
00172
00173
00174
00175
00176 $paths = array();
00177 $paths['defMods'] = PATH_typo3.'mod/';
00178 $paths['userMods'] = PATH_typo3.'../typo3conf/';
00179
00180
00181 foreach($theMods as $mods => $subMod) {
00182 $path = NULL;
00183
00184 $extModRelPath = $this->checkExtensionModule($mods);
00185 if ($extModRelPath) {
00186 $theMainMod = $this->checkMod($mods,PATH_site.$extModRelPath);
00187 if (is_array($theMainMod) || $theMainMod!='notFound') {
00188 $path = 1;
00189 }
00190 } else {
00191
00192 $theMainMod = $this->checkMod($mods,$paths['defMods'].$mods);
00193 if (is_array($theMainMod) || $theMainMod!='notFound') {
00194 $path = $paths['defMods'];
00195 } else {
00196
00197 $theMainMod = $this->checkMod($mods,$paths['userMods'].$mods);
00198 if (is_array($theMainMod) || $theMainMod!='notFound') {
00199 $path = $paths['userMods'];
00200 }
00201 }
00202 }
00203
00204
00205 if ($theMainMod && !is_null($path)) {
00206 $this->modules[$mods] = $theMainMod;
00207
00208
00209 if ($mods!='doc' && is_array($subMod)) {
00210 foreach($subMod as $valsub) {
00211 $extModRelPath = $this->checkExtensionModule($mods.'_'.$valsub);
00212 if ($extModRelPath) {
00213 $theTempSubMod = $this->checkMod($mods.'_'.$valsub,PATH_site.$extModRelPath);
00214 if (is_array($theTempSubMod)) {
00215 $this->modules[$mods]['sub'][$valsub] = $theTempSubMod;
00216 }
00217 } else {
00218
00219
00220 $theTempSubMod = $this->checkMod($mods.'_'.$valsub,$path.$mods.'/'.$valsub);
00221 if (is_array($theTempSubMod)) {
00222 $this->modules[$mods]['sub'][$valsub] = $theTempSubMod;
00223 } elseif ($path == $paths['defMods']) {
00224 $theTempSubMod = $this->checkMod($mods.'_'.$valsub,$paths['userMods'].$mods.'/'.$valsub);
00225 if (is_array($theTempSubMod)) {
00226 $this->modules[$mods]['sub'][$valsub] = $theTempSubMod;
00227 }
00228 }
00229 }
00230 }
00231 }
00232 } else {
00233 if ($mods!='doc' && is_array($subMod)) {
00234 foreach($subMod as $valsub) {
00235
00236 $this->checkMod($mods.'_'.$valsub,$path.$mods.'/'.$valsub);
00237 }
00238 }
00239 }
00240 }
00241
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 #debug($this->modules);
00361 #debug($GLOBALS['LANG']->moduleLabels);
00362 }
00363
00370 function checkExtensionModule($name) {
00371 global $TYPO3_LOADED_EXT;
00372
00373 if (isset($this->absPathArray[$name])) {
00374 return ereg_replace ('\/$', '', substr($this->absPathArray[$name],strlen(PATH_site)));
00375 }
00376 }
00377
00389 function checkMod($name, $fullpath) {
00390 $modconf=Array();
00391 $path = ereg_replace ('/[^/.]+/\.\./', '/', $fullpath);
00392 if (@is_dir($path) && @file_exists($path.'/conf.php')) {
00393 $MCONF = array();
00394 $MLANG = array();
00395 include($path.'/conf.php');
00396 if (!$MCONF['shy'] && $this->checkModAccess($name,$MCONF) && $this->checkModWorkspace($name,$MCONF)) {
00397 $modconf['name']=$name;
00398
00399 if (is_object($GLOBALS['LANG'])) {
00400
00401
00402 if ($MLANG['default']['tabs_images']['tab']) {
00403
00404
00405 $altIconKey = 'MOD:'.$name.'/'.$MLANG['default']['tabs_images']['tab'];
00406 $altIconAbsPath = is_array($GLOBALS['TBE_STYLES']['skinImg'][$altIconKey]) ? t3lib_div::resolveBackPath(PATH_typo3.$GLOBALS['TBE_STYLES']['skinImg'][$altIconKey][0]) : '';
00407
00408
00409 if ($altIconAbsPath && @is_file($altIconAbsPath)) {
00410 $MLANG['default']['tabs_images']['tab']=$this->getRelativePath(PATH_typo3,$altIconAbsPath);
00411 } else {
00412
00413 $MLANG['default']['tabs_images']['tab']=$this->getRelativePath(PATH_typo3,$fullpath.'/'.$MLANG['default']['tabs_images']['tab']);
00414 }
00415
00416
00417 if (substr($MLANG['default']['tabs_images']['tab'],0,3)=='../') {
00418 $MLANG['default']['tabs_images']['tab'] = PATH_site.substr($MLANG['default']['tabs_images']['tab'],3);
00419 } else {
00420 $MLANG['default']['tabs_images']['tab'] = PATH_typo3.$MLANG['default']['tabs_images']['tab'];
00421 }
00422 }
00423
00424
00425 if ($MLANG['default']['ll_ref']) {
00426
00427 $MLANG['default']['labels']['tablabel'] = $GLOBALS['LANG']->sL($MLANG['default']['ll_ref'].':mlang_labels_tablabel');
00428 $MLANG['default']['labels']['tabdescr'] = $GLOBALS['LANG']->sL($MLANG['default']['ll_ref'].':mlang_labels_tabdescr');
00429 $MLANG['default']['tabs']['tab'] = $GLOBALS['LANG']->sL($MLANG['default']['ll_ref'].':mlang_tabs_tab');
00430 $GLOBALS['LANG']->addModuleLabels($MLANG['default'],$name.'_');
00431 } else {
00432 $GLOBALS['LANG']->addModuleLabels($MLANG['default'],$name.'_');
00433 $GLOBALS['LANG']->addModuleLabels($MLANG[$GLOBALS['LANG']->lang],$name.'_');
00434 }
00435 }
00436
00437
00438 if ($MCONF['script']==='_DISPATCH') {
00439 $modconf['script'] = 'mod.php?M='.rawurlencode($name);
00440 } elseif ($MCONF['script'] && @file_exists($path.'/'.$MCONF['script'])) {
00441 $modconf['script'] = $this->getRelativePath(PATH_typo3,$fullpath.'/'.$MCONF['script']);
00442 } else {
00443 $modconf['script'] = 'dummy.php';
00444 }
00445
00446 if ($MCONF['defaultMod']) {
00447 $modconf['defaultMod'] = $MCONF['defaultMod'];
00448 }
00449
00450 if ($MCONF['navFrameScript']) {
00451 $navFrameScript = explode('?', $MCONF['navFrameScript']);
00452 $navFrameScript = $navFrameScript[0];
00453 if (@file_exists($path.'/'.$navFrameScript)) {
00454 $modconf['navFrameScript'] = $this->getRelativePath(PATH_typo3,$fullpath.'/'.$MCONF['navFrameScript']);
00455 }
00456 }
00457
00458 if ($MCONF['navFrameScriptParam']) {
00459 $modconf['navFrameScriptParam'] = $MCONF['navFrameScriptParam'];
00460 }
00461 } else return false;
00462 } else $modconf = 'notFound';
00463 return $modconf;
00464 }
00465
00473 function checkModAccess($name,$MCONF) {
00474 if ($MCONF['access']) {
00475 $access=strtolower($MCONF['access']);
00476
00477 if (strstr($access,'admin')) {
00478 if ($this->BE_USER->isAdmin()) {return true;}
00479 }
00480
00481 if (strstr($access,'user')) { $this->modListUser[]=$name; }
00482 if (strstr($access,'group')) { $this->modListGroup[]=$name; }
00483
00484 if ($this->BE_USER->isAdmin() || $this->BE_USER->check('modules',$name)) {return true;}
00485
00486 } else return true;
00487 }
00488
00497 function checkModWorkspace($name,$MCONF) {
00498 if ($this->observeWorkspaces) {
00499 $status = TRUE;
00500 if ($MCONF['workspaces']) {
00501 $status = FALSE;
00502 if (($this->BE_USER->workspace===0 && t3lib_div::inList($MCONF['workspaces'],'online')) ||
00503 ($this->BE_USER->workspace===-1 && t3lib_div::inList($MCONF['workspaces'],'offline')) ||
00504 ($this->BE_USER->workspace>0 && t3lib_div::inList($MCONF['workspaces'],'custom'))) {
00505 $status = TRUE;
00506 }
00507 } elseif ($this->BE_USER->workspace===-99) {
00508 $status = FALSE;
00509 }
00510 return $status;
00511 } else return TRUE;
00512 }
00513
00521 function parseModulesArray($arr) {
00522 $theMods = Array();
00523 if (is_array($arr)) {
00524 foreach($arr as $mod => $subs) {
00525 $mod = $this->cleanName($mod);
00526 if ($mod) {
00527 if ($subs) {
00528 $subsArr = t3lib_div::trimExplode(',', $subs);
00529 foreach($subsArr as $subMod) {
00530 $subMod = $this->cleanName($subMod);
00531 if ($subMod) {
00532 $theMods[$mod][] = $subMod;
00533 }
00534 }
00535 } else {
00536 $theMods[$mod] = 1;
00537 }
00538 }
00539 }
00540 }
00541 return $theMods;
00542 }
00543
00550 function cleanName ($str) {
00551 return preg_replace('/[^a-z0-9]/i','',$str);
00552 }
00553
00561 function getRelativePath($baseDir,$destDir){
00562
00563
00564 if ($baseDir == $destDir){
00565 return './';
00566 }
00567
00568 $baseDir = ereg_replace ('^/', '', $baseDir);
00569 $destDir = ereg_replace ('^/', '', $destDir);
00570
00571 $found = true;
00572 $slash_pos=0;
00573
00574 do {
00575 $slash_pos = strpos ($destDir, '/');
00576 if (substr($destDir, 0, $slash_pos) == substr($baseDir, 0, $slash_pos)){
00577 $baseDir = substr($baseDir, $slash_pos+1);
00578 $destDir = substr($destDir, $slash_pos+1);
00579 } else {
00580 $found = false;
00581 }
00582 } while($found == true);
00583
00584 $slashes = strlen ($baseDir) - strlen (str_replace('/', '', $baseDir));
00585 for($i=0;$i < $slashes;$i++) {
00586 $destDir = '../'.$destDir;
00587 }
00588 return $destDir;
00589 }
00590 }
00591
00592
00593 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_loadmodules.php']) {
00594 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_loadmodules.php']);
00595 }
00596 ?>