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
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 class t3lib_loadModules {
00080 var $modules = Array();
00081 var $absPathArray = array();
00082
00083 var $modListGroup = Array();
00084 var $modListUser = Array();
00085
00086
00087
00088
00089
00090
00091 var $BE_USER = '';
00092 var $observeWorkspaces = FALSE;
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
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 $this->absPathArray = $modulesArray['_PATHS'];
00135 unset($modulesArray['_PATHS']);
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
00168
00169
00170 $theMods = $this->parseModulesArray($modulesArray);
00171
00172
00173
00174
00175
00176
00177
00178
00179 $paths = array();
00180 $paths['defMods'] = PATH_typo3.'mod/';
00181 $paths['userMods'] = PATH_typo3.'../typo3conf/';
00182
00183
00184 foreach($theMods as $mods => $subMod) {
00185 $path = NULL;
00186
00187 $extModRelPath = $this->checkExtensionModule($mods);
00188 if ($extModRelPath) {
00189 $theMainMod = $this->checkMod($mods,PATH_site.$extModRelPath);
00190 if (is_array($theMainMod) || $theMainMod!='notFound') {
00191 $path = 1;
00192 }
00193 } else {
00194
00195 $theMainMod = $this->checkMod($mods,$paths['defMods'].$mods);
00196 if (is_array($theMainMod) || $theMainMod!='notFound') {
00197 $path = $paths['defMods'];
00198 } else {
00199
00200 $theMainMod = $this->checkMod($mods,$paths['userMods'].$mods);
00201 if (is_array($theMainMod) || $theMainMod!='notFound') {
00202 $path = $paths['userMods'];
00203 }
00204 }
00205 }
00206
00207
00208 if ($theMainMod && !is_null($path)) {
00209 $this->modules[$mods] = $theMainMod;
00210
00211
00212 if (is_array($subMod)) {
00213 foreach($subMod as $valsub) {
00214 $extModRelPath = $this->checkExtensionModule($mods.'_'.$valsub);
00215 if ($extModRelPath) {
00216 $theTempSubMod = $this->checkMod($mods.'_'.$valsub,PATH_site.$extModRelPath);
00217 if (is_array($theTempSubMod)) {
00218 $this->modules[$mods]['sub'][$valsub] = $theTempSubMod;
00219 }
00220 } else {
00221
00222
00223 $theTempSubMod = $this->checkMod($mods.'_'.$valsub,$path.$mods.'/'.$valsub);
00224 if (is_array($theTempSubMod)) {
00225 $this->modules[$mods]['sub'][$valsub] = $theTempSubMod;
00226 } elseif ($path == $paths['defMods']) {
00227 $theTempSubMod = $this->checkMod($mods.'_'.$valsub,$paths['userMods'].$mods.'/'.$valsub);
00228 if (is_array($theTempSubMod)) {
00229 $this->modules[$mods]['sub'][$valsub] = $theTempSubMod;
00230 }
00231 }
00232 }
00233 }
00234 }
00235 } else {
00236 if (is_array($subMod)) {
00237 foreach($subMod as $valsub) {
00238
00239 $this->checkMod($mods.'_'.$valsub,$path.$mods.'/'.$valsub);
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 #debug($this->modules);
00358 #debug($GLOBALS['LANG']->moduleLabels);
00359 }
00360
00361
00362
00363
00364
00365
00366
00367 function checkExtensionModule($name) {
00368 global $TYPO3_LOADED_EXT;
00369
00370 if (isset($this->absPathArray[$name])) {
00371 return ereg_replace ('\/$', '', substr($this->absPathArray[$name],strlen(PATH_site)));
00372 }
00373 }
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386 function checkMod($name, $fullpath) {
00387 $modconf=Array();
00388 $path = ereg_replace ('/[^/.]+/\.\./', '/', $fullpath);
00389 if (@is_dir($path) && file_exists($path.'/conf.php')) {
00390 $MCONF = array();
00391 $MLANG = array();
00392 include($path.'/conf.php');
00393 if (!$MCONF['shy'] && $this->checkModAccess($name,$MCONF) && $this->checkModWorkspace($name,$MCONF)) {
00394 $modconf['name']=$name;
00395
00396 if (is_object($GLOBALS['LANG'])) {
00397
00398
00399 if ($MLANG['default']['tabs_images']['tab']) {
00400
00401
00402 $altIconKey = 'MOD:'.$name.'/'.$MLANG['default']['tabs_images']['tab'];
00403 $altIconAbsPath = is_array($GLOBALS['TBE_STYLES']['skinImg'][$altIconKey]) ? t3lib_div::resolveBackPath(PATH_typo3.$GLOBALS['TBE_STYLES']['skinImg'][$altIconKey][0]) : '';
00404
00405
00406 if ($altIconAbsPath && @is_file($altIconAbsPath)) {
00407 $MLANG['default']['tabs_images']['tab']=$this->getRelativePath(PATH_typo3,$altIconAbsPath);
00408 } else {
00409
00410 $MLANG['default']['tabs_images']['tab']=$this->getRelativePath(PATH_typo3,$fullpath.'/'.$MLANG['default']['tabs_images']['tab']);
00411 }
00412
00413
00414 if (substr($MLANG['default']['tabs_images']['tab'],0,3)=='../') {
00415 $MLANG['default']['tabs_images']['tab'] = PATH_site.substr($MLANG['default']['tabs_images']['tab'],3);
00416 } else {
00417 $MLANG['default']['tabs_images']['tab'] = PATH_typo3.$MLANG['default']['tabs_images']['tab'];
00418 }
00419 }
00420
00421
00422 if ($MLANG['default']['ll_ref']) {
00423
00424 $MLANG['default']['labels']['tablabel'] = $GLOBALS['LANG']->sL($MLANG['default']['ll_ref'].':mlang_labels_tablabel');
00425 $MLANG['default']['labels']['tabdescr'] = $GLOBALS['LANG']->sL($MLANG['default']['ll_ref'].':mlang_labels_tabdescr');
00426 $MLANG['default']['tabs']['tab'] = $GLOBALS['LANG']->sL($MLANG['default']['ll_ref'].':mlang_tabs_tab');
00427 $GLOBALS['LANG']->addModuleLabels($MLANG['default'],$name.'_');
00428 } else {
00429 $GLOBALS['LANG']->addModuleLabels($MLANG['default'],$name.'_');
00430 $GLOBALS['LANG']->addModuleLabels($MLANG[$GLOBALS['LANG']->lang],$name.'_');
00431 }
00432 }
00433
00434
00435 if ($MCONF['script']==='_DISPATCH') {
00436 $modconf['script'] = 'mod.php?M='.rawurlencode($name);
00437 } elseif ($MCONF['script'] && file_exists($path.'/'.$MCONF['script'])) {
00438 $modconf['script'] = $this->getRelativePath(PATH_typo3,$fullpath.'/'.$MCONF['script']);
00439 } else {
00440 $modconf['script'] = 'dummy.php';
00441 }
00442
00443 if ($MCONF['defaultMod']) {
00444 $modconf['defaultMod'] = $MCONF['defaultMod'];
00445 }
00446
00447 if ($MCONF['navFrameScript']) {
00448 $navFrameScript = explode('?', $MCONF['navFrameScript']);
00449 $navFrameScript = $navFrameScript[0];
00450 if (file_exists($path.'/'.$navFrameScript)) {
00451 $modconf['navFrameScript'] = $this->getRelativePath(PATH_typo3,$fullpath.'/'.$MCONF['navFrameScript']);
00452 }
00453 }
00454
00455 if ($MCONF['navFrameScriptParam']) {
00456 $modconf['navFrameScriptParam'] = $MCONF['navFrameScriptParam'];
00457 }
00458 } else return false;
00459 } else $modconf = 'notFound';
00460 return $modconf;
00461 }
00462
00463
00464
00465
00466
00467
00468
00469
00470 function checkModAccess($name,$MCONF) {
00471 if ($MCONF['access']) {
00472 $access=strtolower($MCONF['access']);
00473
00474 if (strstr($access,'admin')) {
00475 if ($this->BE_USER->isAdmin()) {return true;}
00476 }
00477
00478 if (strstr($access,'user')) { $this->modListUser[]=$name; }
00479 if (strstr($access,'group')) { $this->modListGroup[]=$name; }
00480
00481 if ($this->BE_USER->isAdmin() || $this->BE_USER->check('modules',$name)) {return true;}
00482
00483 } else return true;
00484 }
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494 function checkModWorkspace($name,$MCONF) {
00495 if ($this->observeWorkspaces) {
00496 $status = TRUE;
00497 if ($MCONF['workspaces']) {
00498 $status = FALSE;
00499 if (($this->BE_USER->workspace===0 && t3lib_div::inList($MCONF['workspaces'],'online')) ||
00500 ($this->BE_USER->workspace===-1 && t3lib_div::inList($MCONF['workspaces'],'offline')) ||
00501 ($this->BE_USER->workspace>0 && t3lib_div::inList($MCONF['workspaces'],'custom'))) {
00502 $status = TRUE;
00503 }
00504 } elseif ($this->BE_USER->workspace===-99) {
00505 $status = FALSE;
00506 }
00507 return $status;
00508 } else return TRUE;
00509 }
00510
00511
00512
00513
00514
00515
00516
00517
00518 function parseModulesArray($arr) {
00519 $theMods = Array();
00520 if (is_array($arr)) {
00521 foreach($arr as $mod => $subs) {
00522 $mod = $this->cleanName($mod);
00523 if ($mod) {
00524 if ($subs) {
00525 $subsArr = t3lib_div::trimExplode(',', $subs);
00526 foreach($subsArr as $subMod) {
00527 $subMod = $this->cleanName($subMod);
00528 if ($subMod) {
00529 $theMods[$mod][] = $subMod;
00530 }
00531 }
00532 } else {
00533 $theMods[$mod] = 1;
00534 }
00535 }
00536 }
00537 }
00538 return $theMods;
00539 }
00540
00541
00542
00543
00544
00545
00546
00547 function cleanName ($str) {
00548 return preg_replace('/[^a-z0-9]/i','',$str);
00549 }
00550
00551
00552
00553
00554
00555
00556
00557
00558 function getRelativePath($baseDir,$destDir){
00559
00560
00561 if ($baseDir == $destDir){
00562 return './';
00563 }
00564
00565 $baseDir = ereg_replace ('^/', '', $baseDir);
00566 $destDir = ereg_replace ('^/', '', $destDir);
00567
00568 $found = true;
00569 $slash_pos=0;
00570
00571 do {
00572 $slash_pos = strpos ($destDir, '/');
00573 if (substr($destDir, 0, $slash_pos) == substr($baseDir, 0, $slash_pos)){
00574 $baseDir = substr($baseDir, $slash_pos+1);
00575 $destDir = substr($destDir, $slash_pos+1);
00576 } else {
00577 $found = false;
00578 }
00579 } while($found == true);
00580
00581 $slashes = strlen ($baseDir) - strlen (str_replace('/', '', $baseDir));
00582 for($i=0;$i < $slashes;$i++) {
00583 $destDir = '../'.$destDir;
00584 }
00585 return $destDir;
00586 }
00587 }
00588
00589
00590 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_loadmodules.php']) {
00591 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_loadmodules.php']);
00592 }
00593
00594 ?>