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
00078 class t3lib_loadModules {
00079 var $modules = Array();
00080 var $absPathArray = array();
00081
00082 var $modListGroup = Array();
00083 var $modListUser = Array();
00084
00085 var $BE_USER = '';
00086
00087
00097 function load($modulesArray,$BE_USER='') {
00098
00099 if (is_object($BE_USER)) {
00100 $this->BE_USER = $BE_USER;
00101 } else {
00102 $this->BE_USER = $GLOBALS['BE_USER'];
00103 }
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 $this->absPathArray = $modulesArray['_PATHS'];
00129 unset($modulesArray['_PATHS']);
00130
00131
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 $theMods = $this->parseModulesArray($modulesArray);
00166
00167
00168
00169
00170
00171
00172
00173
00174 $paths = array();
00175 $paths['defMods'] = PATH_typo3.'mod/';
00176 $paths['userMods'] = PATH_typo3.'../typo3conf/';
00177
00178
00179 foreach($theMods as $mods => $subMod) {
00180 unset ($path);
00181
00182 $extModRelPath = $this->checkExtensionModule($mods);
00183 if ($extModRelPath) {
00184 $theMainMod = $this->checkMod($mods,PATH_site.$extModRelPath);
00185 if (is_array($theMainMod) || $theMainMod!='notFound') {
00186 $path = 1;
00187 }
00188 } else {
00189
00190 $theMainMod = $this->checkMod($mods,$paths['defMods'].$mods);
00191 if (is_array($theMainMod) || $theMainMod!='notFound') {
00192 $path = $paths['defMods'];
00193 } else {
00194
00195 $theMainMod = $this->checkMod($mods,$paths['userMods'].$mods);
00196 if (is_array($theMainMod) || $theMainMod!='notFound') {
00197 $path = $paths['userMods'];
00198 }
00199 }
00200 }
00201
00202
00203 if ($theMainMod && isset($path)) {
00204 $this->modules[$mods] = $theMainMod;
00205
00206
00207 if ($mods!='doc' && is_array($subMod)) {
00208 foreach($subMod as $valsub) {
00209 $extModRelPath = $this->checkExtensionModule($mods.'_'.$valsub);
00210 if ($extModRelPath) {
00211 $theTempSubMod = $this->checkMod($mods.'_'.$valsub,PATH_site.$extModRelPath);
00212 if (is_array($theTempSubMod)) {
00213 $this->modules[$mods]['sub'][$valsub] = $theTempSubMod;
00214 }
00215 } else {
00216
00217 $theTempSubMod = $this->checkMod($mods.'_'.$valsub,$path.$mods.'/'.$valsub);
00218 if (is_array($theTempSubMod)) {
00219 $this->modules[$mods]['sub'][$valsub] = $theTempSubMod;
00220 } elseif ($path == $paths['defMods']) {
00221 $theTempSubMod = $this->checkMod($mods.'_'.$valsub,$paths['userMods'].$mods.'/'.$valsub);
00222 if (is_array($theTempSubMod)) {
00223 $this->modules[$mods]['sub'][$valsub] = $theTempSubMod;
00224 }
00225 }
00226 }
00227 }
00228 }
00229 } else {
00230 if ($mods!='doc' && is_array($subMod)) {
00231 foreach($subMod as $valsub) {
00232 $this->checkMod($mods.'_'.$valsub,$path.$mods.'/'.$valsub);
00233 }
00234 }
00235 }
00236 }
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 #debug($this->modules);
00357 #debug($GLOBALS['LANG']->moduleLabels);
00358 }
00359
00366 function checkExtensionModule($name) {
00367 global $TYPO3_LOADED_EXT;
00368
00369 if (isset($this->absPathArray[$name])) {
00370 return ereg_replace ('\/$', '', substr($this->absPathArray[$name],strlen(PATH_site)));
00371 }
00372 }
00373
00385 function checkMod($name, $fullpath) {
00386 $modconf=Array();
00387 $path = ereg_replace ('/[^/.]+/\.\./', '/', $fullpath);
00388 if (@is_dir($path) && @file_exists($path.'/conf.php')) {
00389 include($path.'/conf.php');
00390 if (!$MCONF['shy'] && $this->checkModAccess($name,$MCONF)) {
00391 $modconf['name']=$name;
00392
00393 if (is_object($GLOBALS['LANG'])) {
00394
00395
00396 if ($MLANG['default']['tabs_images']['tab']) {
00397
00398
00399 $altIconKey = 'MOD:'.$name.'/'.$MLANG['default']['tabs_images']['tab'];
00400 $altIconAbsPath = is_array($GLOBALS['TBE_STYLES']['skinImg'][$altIconKey]) ? t3lib_div::resolveBackPath(PATH_typo3.$GLOBALS['TBE_STYLES']['skinImg'][$altIconKey][0]) : '';
00401
00402
00403 if ($altIconAbsPath && @is_file($altIconAbsPath)) {
00404 $MLANG['default']['tabs_images']['tab']=$this->getRelativePath(PATH_typo3,$altIconAbsPath);
00405 } else {
00406
00407 $MLANG['default']['tabs_images']['tab']=$this->getRelativePath(PATH_typo3,$fullpath.'/'.$MLANG['default']['tabs_images']['tab']);
00408 }
00409
00410
00411 if (substr($MLANG['default']['tabs_images']['tab'],0,3)=='../') {
00412 $MLANG['default']['tabs_images']['tab'] = PATH_site.substr($MLANG['default']['tabs_images']['tab'],3);
00413 } else {
00414 $MLANG['default']['tabs_images']['tab'] = PATH_typo3.$MLANG['default']['tabs_images']['tab'];
00415 }
00416 }
00417
00418
00419 if ($MLANG['default']['ll_ref']) {
00420
00421 $MLANG['default']['labels']['tablabel'] = $GLOBALS['LANG']->sL($MLANG['default']['ll_ref'].':mlang_labels_tablabel');
00422 $MLANG['default']['labels']['tabdescr'] = $GLOBALS['LANG']->sL($MLANG['default']['ll_ref'].':mlang_labels_tabdescr');
00423 $MLANG['default']['tabs']['tab'] = $GLOBALS['LANG']->sL($MLANG['default']['ll_ref'].':mlang_tabs_tab');
00424 $GLOBALS['LANG']->addModuleLabels($MLANG['default'],$name.'_');
00425 } else {
00426 $GLOBALS['LANG']->addModuleLabels($MLANG['default'],$name.'_');
00427 $GLOBALS['LANG']->addModuleLabels($MLANG[$GLOBALS['LANG']->lang],$name.'_');
00428 }
00429 }
00430
00431
00432 if ($MCONF['script'] && @file_exists($path.'/'.$MCONF['script'])) {
00433 $modconf['script'] = $this->getRelativePath(PATH_typo3,$fullpath.'/'.$MCONF['script']);
00434 } else {
00435 $modconf['script'] = 'dummy.php';
00436 }
00437
00438 if ($MCONF['defaultMod']) {
00439 $modconf['defaultMod'] = $MCONF['defaultMod'];
00440 }
00441
00442 if ($MCONF['navFrameScript']) {
00443 $navFrameScript = explode('?', $MCONF['navFrameScript']);
00444 $navFrameScript = $navFrameScript[0];
00445 if (@file_exists($path.'/'.$navFrameScript)) {
00446 $modconf['navFrameScript'] = $this->getRelativePath(PATH_typo3,$fullpath.'/'.$MCONF['navFrameScript']);
00447 }
00448 }
00449
00450 if ($MCONF['navFrameScriptParam']) {
00451 $modconf['navFrameScriptParam'] = $MCONF['navFrameScriptParam'];
00452 }
00453 } else return false;
00454 } else $modconf = 'notFound';
00455 return $modconf;
00456 }
00457
00465 function checkModAccess($name,$MCONF) {
00466 if ($MCONF['access']) {
00467 $access=strtolower($MCONF['access']);
00468
00469 if (strstr($access,'admin')) {
00470 if ($this->BE_USER->isAdmin()) {return true;}
00471 }
00472
00473 if (strstr($access,'user')) { $this->modListUser[]=$name; }
00474 if (strstr($access,'group')) { $this->modListGroup[]=$name; }
00475
00476 if ($this->BE_USER->isAdmin() || $this->BE_USER->check('modules',$name)) {return true;}
00477
00478 } else return true;
00479 }
00480
00488 function parseModulesArray($arr) {
00489 $theMods = Array();
00490 if (is_array($arr)) {
00491 foreach($arr as $mod => $subs) {
00492 $mod = $this->cleanName($mod);
00493 if ($mod) {
00494 if ($subs) {
00495 $subsArr = t3lib_div::trimExplode(',', $subs);
00496 foreach($subsArr as $subMod) {
00497 $subMod = $this->cleanName($subMod);
00498 if ($subMod) {
00499 $theMods[$mod][] = $subMod;
00500 }
00501 }
00502 } else {
00503 $theMods[$mod] = 1;
00504 }
00505 }
00506 }
00507 }
00508 return $theMods;
00509 }
00510
00517 function cleanName ($str) {
00518 return ereg_replace('[^A-Za-z0-9]*','',$str);
00519 }
00520
00528 function getRelativePath($baseDir,$destDir){
00529
00530
00531 if ($baseDir == $destDir){
00532 return './';
00533 }
00534
00535 $baseDir = ereg_replace ('^/', '', $baseDir);
00536 $destDir = ereg_replace ('^/', '', $destDir);
00537
00538 $found = true;
00539 $slash_pos=0;
00540
00541 do {
00542 $slash_pos = strpos ($destDir, '/');
00543 if (substr($destDir, 0, $slash_pos) == substr($baseDir, 0, $slash_pos)){
00544 $baseDir = substr($baseDir, $slash_pos+1);
00545 $destDir = substr($destDir, $slash_pos+1);
00546 } else {
00547 $found = false;
00548 }
00549 } while($found == true);
00550
00551 $slashes = strlen ($baseDir) - strlen (str_replace('/', '', $baseDir));
00552 for($i=0;$i < $slashes;$i++) {
00553 $destDir = '../'.$destDir;
00554 }
00555 return $destDir;
00556 }
00557 }
00558
00559
00560 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_loadmodules.php']) {
00561 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_loadmodules.php']);
00562 }
00563 ?>