* -------------------------------------------------------------------- *
* File : module-functions.php *
* -------------------------------------------------------------------- *
- * Short description : All MySQL-related functions *
+ * Short description : Module functions *
* -------------------------------------------------------------------- *
- * Kurzbeschreibung : Alle MySQL-Relevanten Funktionen *
- * -------------------------------------------------------------------- *
- * $Revision:: 1910 $ *
- * $Date:: 2010-06-29 06:00:23 +0200 (Tue, 29 Jun 2010) $ *
- * $Tag:: 0.2.1-FINAL $ *
- * $Author:: quix0r $ *
- * Needs to be in all Files and every File needs "svn propset *
- * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
+ * Kurzbeschreibung : Modulfunktionen *
* -------------------------------------------------------------------- *
* Copyright (c) 2003 - 2009 by Roland Haeder *
- * Copyright (c) 2009, 2010 by Mailer Developer Team *
- * For more information visit: http://www.mxchange.org *
+ * Copyright (c) 2009 - 2013 by Mailer Developer Team *
+ * For more information visit: http://mxchange.org *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
// "Getter" for module title
function getModuleTitle ($module) {
- // Init variables
- $data['title'] = '';
- $result = false;
+ // Is there cache?
+ if (!isset($GLOBALS[__FUNCTION__][$module])) {
+ // Init variables
+ $data['title'] = '';
+ $result = FALSE;
+
+ // Is the script installed?
+ if ((isInstalled()) && ($module != 'error')) {
+ // Check if cache is valid
+ if ((isExtensionInstalledAndNewer('cache', '0.1.2')) && (isset($GLOBALS['cache_array']['modules']['module'])) && (in_array($module, $GLOBALS['cache_array']['modules']['module']))) {
+ // Load from cache
+ $data['title'] = $GLOBALS['cache_array']['modules']['title'][$module];
+
+ // Update cache hits
+ incrementStatsEntry('cache_hits');
+ } elseif (!isExtensionActive('cache')) {
+ // Load from database
+ $result = sqlQueryEscaped("SELECT `title` FROM `{?_MYSQL_PREFIX?}_mod_reg` WHERE `module`='%s' LIMIT 1",
+ array($module), __FUNCTION__, __LINE__);
+
+ // Is the entry there?
+ if (sqlNumRows($result) == 1) {
+ // Get the title from database
+ $data = sqlFetchArray($result);
+ } // END - if
+
+ // Free the result
+ sqlFreeResult($result);
+ }
+ } // END - if
+
+ // Trim name
+ $data['title'] = trim($data['title']);
+
+ // Still no luck or empty title?
+ if (empty($data['title'])) {
+ // Is it 'error'?
+ if ($module == 'error') {
+ // Error (real module was not found)
+ $data['title'] = '{--MODULE_ERROR_404_TITLE--}';
+ } else {
+ // No name found
+ $data['title'] = '{%message,UNKNOWN_MODULE_DETECTED_TITLE=' . $module . '%}';
+ if ((is_resource($result)) && (ifSqlHasZeroNums($result))) {
+ // Add module to database and ignore return value
+ checkModulePermissions($module);
+ } // END - if
+ }
+ } // END - if
+
+ // Store in cache
+ $GLOBALS[__FUNCTION__][$module] = $data['title'];
+ } // END - if
- // Is the script installed?
- if ((isInstalled()) && ($module != 'error')) {
- // Check if cache is valid
- if ((isExtensionInstalledAndNewer('cache', '0.1.2')) && (isset($GLOBALS['cache_array']['modules']['module'])) && (in_array($module, $GLOBALS['cache_array']['modules']['module']))) {
- // Load from cache
- $data['title'] = $GLOBALS['cache_array']['modules']['title'][$module];
+ // Return it
+ return $GLOBALS[__FUNCTION__][$module];
+}
+
+// Checks if module_status entry is there
+function isModuleStatusSet ($module) {
+ // Check it
+ return (isset($GLOBALS['module_status'][$module]));
+}
+
+// Setter module status
+function setModuleStatus ($module, $status) {
+ $GLOBALS['module_status'][$module] = $status;
+}
+
+// Getter for module status
+function getModuleStatus ($module) {
+ // Is the module_status entry there?
+ if (!isModuleStatusSet($module)) {
+ // Abort
+ reportBug(__FUNCTION__, __LINE__, 'Module status not set. module=' . $module);
+ } // END - if
+ // Return it
+ return $GLOBALS['module_status'][$module];
+}
+
+// Checks whether the given module is registered
+function isModuleRegistered ($module) {
+ // By default nothing is found
+ $found = FALSE;
+
+ // Check if cache is latest version
+ if (isExtensionInstalledAndNewer('cache', '0.1.2')) {
+ // Is the cache there?
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Using cache.');
+ if (isset($GLOBALS['cache_array']['modules']['locked'][$module])) {
// Update cache hits
incrementStatsEntry('cache_hits');
- } elseif (!isExtensionActive('cache')) {
- // Load from database
- $result = SQL_QUERY_ESC("SELECT `title` FROM `{?_MYSQL_PREFIX?}_mod_reg` WHERE `module`='%s' LIMIT 1",
- array($module), __FUNCTION__, __LINE__);
-
- // Is the entry there?
- if (SQL_NUMROWS($result)) {
- // Get the title from database
- $data = SQL_FETCHARRAY($result);
- } // END - if
- // Free the result
- SQL_FREERESULT($result);
+ // Is found
+ $found = TRUE;
+ } else {
+ // No, then we have to update it!
+ setModuleStatus($module, 'cache_miss');
}
- } // END - if
+ } elseif (!isExtensionActive('cache')) {
+ // Check for module in database
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Using database.');
+ $result = sqlQueryEscaped("SELECT `locked`, `hidden`, `admin_only`, `mem_only` FROM `{?_MYSQL_PREFIX?}_mod_reg` WHERE `module`='%s' LIMIT 1",
+ array($module), __FUNCTION__, __LINE__);
+ if (sqlNumRows($result) == 1) {
+ // Read data
+ $data = sqlFetchArray($result);
- // Trim name
- $data['title'] = trim($data['title']);
-
- // Still no luck or empty title?
- if (empty($data['title'])) {
- // Is it 'error'?
- if ($module == 'error') {
- // Error (real module was not found)
- $data['title'] = getMessage('MODULE_ERROR_404');
- } else {
- // No name found
- $data['title'] = getMaskedMessage('UNKNOWN_MODULE_DETECTED', $module);
- if ((is_resource($result)) && (SQL_HASZERONUMS($result))) {
- // Add module to database
- $dummy = checkModulePermissions($module);
- } // END - if
+ // Set all entries
+ foreach ($data as $key => $value) {
+ $GLOBALS['cache_array']['modules'][$key][$module] = $value;
+ } // END - foreach
+
+ // Mark as found
+ $found = TRUE;
+ } elseif (isDebugModeEnabled()) {
+ // Debug message only in debug-mode...
+ logDebugMessage(__FUNCTION__, __LINE__, 'Module ' . $module . ' not found.');
}
- } // END - if
- // Return name
- return $data['title'];
+ // Free result
+ sqlFreeResult($result);
+ }
+
+ // Return status
+ return $found;
+}
+
+// Checks whether the given module is locked by just checking the cache
+function isModuleLocked ($module) {
+ // Determine if there a cache entry and is it set
+ $return = ((isset($GLOBALS['cache_array']['modules']['locked'][$module])) && ($GLOBALS['cache_array']['modules']['locked'][$module] == 'Y'));
+
+ // Return determined value
+ return $return;
+}
+
+// Checks whether the given module is hidden by just checking the cache
+function isModuleHidden ($module) {
+ // Determine if there a cache entry and is it set
+ $return = ((isset($GLOBALS['cache_array']['modules']['hidden'][$module])) && ($GLOBALS['cache_array']['modules']['hidden'][$module] == 'Y'));
+
+ // Return determined value
+ return $return;
+}
+
+// Checks whether the given module is mem_only by just checking the cache
+function isModuleMemberOnly ($module) {
+ // Determine if there a cache entry and is it set
+ $return = ((isset($GLOBALS['cache_array']['modules']['mem_only'][$module])) && ($GLOBALS['cache_array']['modules']['mem_only'][$module] == 'Y'));
+
+ // Return determined value
+ return $return;
+}
+
+// Checks whether the given module is admin_only by just checking the cache
+function isModuleAdminOnly ($module) {
+ // Determine if there a cache entry and is it set
+ $return = ((isset($GLOBALS['cache_array']['modules']['admin_only'][$module])) && ($GLOBALS['cache_array']['modules']['admin_only'][$module] == 'Y'));
+
+ // Return determined value
+ return $return;
}
// Check validity of a given module name (no file extension)
function checkModulePermissions ($module = '') {
// Is it empty (default), then take the current one
- if (empty($module)) $module = getModule();
+ if (empty($module)) {
+ // Use current module
+ $module = getModule();
+ } // END - if
- // Do we have cache?
- if (isset($GLOBALS['module_status'][$module])) {
+ // Is there cache?
+ if (isModuleStatusSet($module)) {
// Then use it
- return $GLOBALS['module_status'][$module];
+ return getModuleStatus($module);
} // END - if
// Filter module name (names with low chars and underlines are fine!)
$extension = ''; $module_chk = $module;
//* DEBUG: */ debugOutput(__LINE__.'*'.count($modSplit).'/'.$module.'*');
if (count($modSplit) == 2) {
- // Okay, there is a seperator (_) in the name so is the first part a module?
+ // Okay, there is a separator (_) in the name so is the first part a module?
//* DEBUG: */ debugOutput(__LINE__.'*'.$modSplit[0].'*');
if (isExtensionActive($modSplit[0])) {
// The prefix is an extension's name, so let's set it
} // END - if
// Major error in module registry is the default
- $ret = 'major';
+ setModuleStatus($module_chk, 'major');
// Check if script is installed if not return a 'done' to prevent some errors
- if ((isInstallationPhase()) || (!isAdminRegistered())) {
+ if ((isInstaller()) || (!isAdminRegistered())) {
// Not installed or no admin registered or in installation phase
+ setModuleStatus($module_chk, 'done');
+
+ // Return status
return 'done';
} // END - if
- // Init data array
- $data = array(
- 'locked' => 'Y',
- 'hidden' => 'N',
- 'admin_only' => 'N',
- 'mem_only' => 'N'
- );
-
- // By default nothing is found
- $found = false;
-
- // Check if cache is latest version
- if (isExtensionInstalledAndNewer('cache', '0.1.2')) {
- // Is the cache there?
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Using cache.');
- if (isset($GLOBALS['cache_array']['modules']['locked'][$module_chk])) {
- // Check cache
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cache found.');
- $data['locked'] = $GLOBALS['cache_array']['modules']['locked'][$module_chk];
- $data['hidden'] = $GLOBALS['cache_array']['modules']['hidden'][$module_chk];
- $data['admin_only'] = $GLOBALS['cache_array']['modules']['admin_only'][$module_chk];
- $data['mem_only'] = $GLOBALS['cache_array']['modules']['mem_only'][$module_chk];
-
- // Update cache hits
- incrementStatsEntry('cache_hits');
- $found = true;
- } else {
- // No, then we have to update it!
- $ret = 'cache_miss';
- }
- } elseif (!isExtensionActive('cache')) {
- // Check for module in database
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Using database.');
- $result = SQL_QUERY_ESC("SELECT `locked`, `hidden`, `admin_only`, `mem_only` FROM `{?_MYSQL_PREFIX?}_mod_reg` WHERE `module`='%s' LIMIT 1",
- array($module_chk), __FUNCTION__, __LINE__);
- if (SQL_NUMROWS($result) == 1) {
- // Read data
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Entry found.');
- $data = SQL_FETCHARRAY($result);
- $found = true;
- } elseif (isDebugModeEnabled()) {
- // Debug message only in debug-mode...
- logDebugMessage(__FUNCTION__, __LINE__, 'Module ' . $module_chk . ' not found!');
- }
-
- // Free result
- SQL_FREERESULT($result);
- }
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret=' . $ret);
+ // Check if the module is registered
+ $found = isModuleRegistered($module_chk);
// Is the module found?
- if ($found === true) {
+ if ($found === TRUE) {
// Check returned values against current access permissions
//
- // Admin access ----- Guest access ----- --- Guest or member? ---
- if ((isAdmin()) || (($data['locked'] != 'Y') && ($data['admin_only'] != 'Y') && (($data['mem_only'] != 'Y') || (isMember())))) {
+ // Admin access ----- Guest access ----- --- Guest or member? ---
+ if ((isAdmin()) || ((!isModuleLocked($module_chk)) && (!isModuleAdminOnly($module_chk)) && ((!isModuleMemberOnly($module_chk)) || (isMember())))) {
// If you are admin you are welcome for everything!
- $ret = 'done';
- } elseif ($data['locked'] == 'Y') {
+ setModuleStatus($module_chk, 'done');
+ } elseif (isModuleLocked($module_chk)) {
// Module is locked
- $ret = 'locked';
- } elseif (($data['mem_only'] == 'Y') && (!isMember())) {
+ setModuleStatus($module_chk, 'locked');
+ } elseif ((isModuleMemberOnly($module_chk)) && (!isMember())) {
// You have to login first!
- $ret = 'mem_only';
- } elseif (($data['admin_only'] == 'Y') && (!isAdmin())) {
+ setModuleStatus($module_chk, 'mem_only');
+ } elseif ((isModuleAdminOnly($module_chk)) && (!isAdmin())) {
// Only the Admin is allowed to enter this module!
- $ret = 'admin_only';
+ setModuleStatus($module_chk, 'admin_only');
} else {
// @TODO Nothing helped???
- logDebugMessage(__FUNCTION__, __LINE__, sprintf("ret=%s,locked=%s,admin=%s,mem=%s",
- $ret,
- $data['locked'],
- $data['admin_only'],
- $data['mem_only']
+ logDebugMessage(__FUNCTION__, __LINE__, sprintf('ret=%s,locked=%d,hidden=%d,mem=%d,admin=%d',
+ getModuleStatus($module_chk),
+ intval(isModuleLocked($module_chk)),
+ intval(isModuleHidden($module_chk)),
+ intval(isModuleMemberOnly($module_chk)),
+ intval(isModuleAdminOnly($module_chk))
));
}
} // END - if
// Still no luck or not found?
- if (($found === false) && (!isExtensionActive('cache')) && ($ret != 'done')) {
- // ----- Legacy module ----- ---- Module in base folder ---- --- Module with extension's name ---
- if ((isIncludeReadable(sprintf("inc/modules/%s.php", $module))) || (isIncludeReadable(sprintf("%s.php", $module))) || (isIncludeReadable(sprintf("%s/%s.php", $extension, $module)))) {
+ if (($found === FALSE) && (!isExtensionActive('cache')) && (getModuleStatus($module_chk) != 'done')) {
+ // ----- Default module ----- ---- Module in base folder ---- --- Module with extension's name ---
+ if ((isIncludeReadable(sprintf('inc/modules/%s.php', $module))) || (isIncludeReadable($module . '.php')) || (isIncludeReadable(sprintf('%s/%s.php', $extension, $module)))) {
// Data is missing so we add it
if (isExtensionInstalledAndNewer('sql_patches', '0.3.6')) {
- // Since 0.3.6 we have a has_menu column, this took me a half hour
- // to find a loop here... *sigh*
- SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_mod_reg`
-(`module`, `locked`, `hidden`, `mem_only`, `admin_only`, `has_menu`) VALUES
+ /*
+ * Since 0.3.6 there is a has_menu column, this took me a half
+ * hour to find a loop here... *sigh*
+ */
+ sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_mod_reg`
+(`module`, `locked`, `hidden`, `mem_only`, `admin_only`, `has_menu`)
+VALUES
('%s','Y','N','N','N','N')", array($module_chk), __FUNCTION__, __LINE__);
} else {
// Wrong/missing sql_patches!
- SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_mod_reg`
-(`module`, `locked`, `hidden`, `mem_only`, `admin_only`) VALUES
+ sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_mod_reg`
+(`module`, `locked`, `hidden`, `mem_only`, `admin_only`)
+VALUES
('%s','Y','N','N','N')", array($module_chk), __FUNCTION__, __LINE__);
}
// Everthing is fine?
- if (SQL_AFFECTEDROWS() < 1) {
+ if (ifSqlHasZeroAffectedRows()) {
// Something bad happend!
+ setModuleStatus($module_chk, 'major');
return 'major';
} // END - if
// Destroy cache here
// @TODO Rewrite this to a filter
- if ((getScriptOutputMode() == '0') || (getScriptOutputMode() == -1)) rebuildCache('modules', 'modules');
+ if ((isHtmlOutputMode()) || (isRawOutputMode())) {
+ rebuildCache('modules', 'modules');
+ } // END - if
// And reload data
- unset($GLOBALS['module_status'][$module]);
- $ret = checkModulePermissions($module_chk);
+ unset($GLOBALS['module_status'][$module_chk]);
+ return checkModulePermissions($module_chk);
} else {
// Module not found we don't add it to the database
- $ret = '404';
+ setModuleStatus($module_chk, '404');
}
- } elseif (($ret == 'cache_miss') && (getScriptOutputMode() == '0')) {
+ } elseif ((getModuleStatus($module_chk) == 'cache_miss') && (isHtmlOutputMode())) {
// Rebuild the cache files
rebuildCache('modules', 'modules');
- } elseif ($found === false) {
+ } elseif ($found === FALSE) {
// Problem with module detected
- logDebugMessage(__FUNCTION__, __LINE__, sprintf("Problem in module %s detected. ret=%s, locked=%s, hidden=%s, mem=%s, admin=%s, output_mode=%s",
- $module,
- $ret,
- $data['locked'],
- $data['hidden'],
- $data['mem_only'],
- $data['admin_only'],
+ logDebugMessage(__FUNCTION__, __LINE__, sprintf('Problem in module %s detected. getModuleStatus()=%s,locked=%d,hidden=%d,mem=%d,admin=%d,output_mode=%s',
+ $module_chk,
+ getModuleStatus($module_chk),
+ intval(isModuleLocked($module_chk)),
+ intval(isModuleHidden($module_chk)),
+ intval(isModuleMemberOnly($module_chk)),
+ intval(isModuleAdminOnly($module_chk)),
getScriptOutputMode()
));
}
+ // Debug log
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf('module=%s, status=%s', $module_chk, getModuleStatus($module_chk)));
+
// Return the value
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret=' . $ret);
- $GLOBALS['module_status'][$module] = $ret;
- return $ret;
+ return getModuleStatus($module_chk);
}
// Checks if the module has a menu
-function ifModuleHasMenu ($mod, $forceDb = false) {
+function ifModuleHasMenu ($module, $forceDb = FALSE) {
// All is false by default
- $ret = false;
+ $ret = FALSE;
// Extension installed and newer than or has version 0.1.2?
if (isExtensionInstalledAndNewer('cache', '0.1.2')) {
// Cache version is okay, so let's check the cache!
- if (isset($GLOBALS['cache_array']['modules']['has_menu'][$mod])) {
+ if (isset($GLOBALS['cache_array']['modules']['has_menu'][$module])) {
// Check module cache and count hit
- $ret = ($GLOBALS['cache_array']['modules']['has_menu'][$mod] == 'Y');
+ $ret = ($GLOBALS['cache_array']['modules']['has_menu'][$module] == 'Y');
incrementStatsEntry('cache_hits');
- } elseif (isset($GLOBALS['cache_array']['extension']['ext_menu'][$mod])) {
+ } elseif (isset($GLOBALS['cache_array']['extension']['ext_menu'][$module])) {
// Check cache and count hit
- $ret = ($GLOBALS['cache_array']['extension']['ext_menu'][$mod] == 'Y');
+ $ret = ($GLOBALS['cache_array']['extension']['ext_menu'][$module] == 'Y');
incrementStatsEntry('cache_hits');
} else {
// Admin/guest/member/sponsor modules have always a menu!
- $ret = in_array($mod, array('admin', 'index', 'login', 'sponsor'));
+ $ret = in_array($module, array('admin', 'index', 'login', 'sponsor'));
}
- } elseif ((isExtensionInstalledAndNewer('sql_patches', '0.3.6')) && ((!isExtensionActive('cache')) || ($forceDb === true))) {
+ } elseif ((isExtensionInstalledAndNewer('sql_patches', '0.3.6')) && ((!isExtensionActive('cache')) || ($forceDb === TRUE))) {
// Check database for entry
- $result = SQL_QUERY_ESC("SELECT `has_menu` FROM `{?_MYSQL_PREFIX?}_mod_reg` WHERE `module`='%s' LIMIT 1",
- array($mod), __FUNCTION__, __LINE__);
+ $result = sqlQueryEscaped("SELECT `has_menu` FROM `{?_MYSQL_PREFIX?}_mod_reg` WHERE `module`='%s' LIMIT 1",
+ array($module), __FUNCTION__, __LINE__);
// Entry found?
- if (SQL_NUMROWS($result) == 1) {
+ if (sqlNumRows($result) == 1) {
// Load "has_menu" column
- $data = SQL_FETCHARRAY($result);
+ $data = sqlFetchArray($result);
// Fake cache... ;-)
- $GLOBALS['cache_array']['extension']['ext_menu'][$mod] = $data['has_menu'];
+ $GLOBALS['cache_array']['extension']['ext_menu'][$module] = $data['has_menu'];
// Does it have a menu?
$ret = ($data['has_menu'] == 'Y');
} // END - if
// Free memory
- SQL_FREERESULT($result);
+ sqlFreeResult($result);
} elseif (!isExtensionInstalled('sql_patches')) {
- // No sql_patches installed, so maybe in admin/guest/member/sponsor area or no admin registered?
- $ret = in_array($mod, array('admin', 'index', 'login', 'sponsor')); // Then there is a menu!
- } else {
- // Unsupported state!
- logDebugMessage(__FUNCTION__, __LINE__, 'This should never be reached.');
+ // No ext-sql_patches installed, so maybe in admin/guest/member/sponsor area or no admin registered?
+ $ret = in_array($module, array('admin', 'index', 'login', 'sponsor')); // Then there is a menu!
+ } elseif (!isInstaller()) {
+ // Unsupported state, but ignored in installation phase
+ logDebugMessage(__FUNCTION__, __LINE__, 'This should never be reached, module[' . gettype($module) . ']=' . $module . ',forceDb=' . intval($forceDb));
}
// Return status
return $ret;
}
+// Adds a SQL for given module
+function addModuleSql ($module, $title, $locked, $hidden, $adminOnly, $memOnly) {
+ // Is the module already registered?
+ if (!isModuleRegistered($module)) {
+ // Add it
+ addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_mod_reg` (`module`, `title`, `locked`, `hidden`, `admin_only`, `mem_only`) VALUES ('" . $module . "', '" . $title . "', '" . $locked . "', '" . $hidden . "', '" . $adminOnly . "', '" . $memOnly . "')");
+ } else {
+ // Already registered
+ logDebugMessage(__FUNCTION__, __LINE__, sprintf('Already registered: module=%s,locked=%s,hidden=%s,admin=%s,mem=%s',
+ $module,
+ $locked,
+ $hidden,
+ $adminOnly,
+ $memOnly
+ ));
+ }
+}
+
+// Load the currently set module
+function loadModule () {
+ // By default all modules are invalid
+ $isModuleValid = FALSE;
+
+ // Construct module name
+ $GLOBALS['module_inc'] = sprintf('inc/modules/%s.php', getModule());
+
+ // Check module permission (again)
+ $moduleState = checkModulePermissions();
+
+ // Which permission/error state do we have?
+ switch ($moduleState) {
+ case 'cache_miss': // The cache is gone
+ case 'admin_only': // Admin-only access
+ case 'mem_only': // Member-only access
+ case 'done': // All fine!
+ // Does the module exists on local file system?
+ if ((isIncludeReadable($GLOBALS['module_inc'])) && (!ifFatalErrorsDetected())) {
+ // Module is valid, active and located on the local disk...
+ $isModuleValid = TRUE;
+ } elseif (!ifFatalErrorsDetected()) {
+ // Set HTTP status
+ setHttpStatus('404');
+
+ // Module not found
+ addFatalMessage(__FUNCTION__, __LINE__, '{--MODULE_REGISTRY_404--}');
+
+ // Set module to error module (non-existent!)
+ setModule('error');
+ }
+ break;
+
+ case '404':
+ // Set HTTP status
+ setHttpStatus('404');
+
+ // Add fatal message
+ addFatalMessage(__FUNCTION__, __LINE__, '{--MODULE_REGISTRY_404--}');
+ break;
+
+ case 'locked':
+ // Set HTTP status
+ setHttpStatus('403 Forbidden');
+
+ if (!isIncludeReadable($GLOBALS['module_inc'])) {
+ // Set HTTP status again
+ setHttpStatus('404 Not Found');
+
+ // Module does addionally not exists
+ addFatalMessage(__FUNCTION__, __LINE__, '{--MODULE_REGISTRY_LOCKED_404--}');
+ } // END - if
+
+ // Add fatal message
+ addFatalMessage(__FUNCTION__, __LINE__, '{--MODULE_REGISTRY_IS_LOCKED--}');
+ break;
+
+ default:
+ // Unknown module status
+ logDebugMessage(__FUNCTION__, __LINE__, sprintf('Unknown status %s return from module check. Module=%s', $moduleState, getModule()));
+ addFatalMessage(__FUNCTION__, __LINE__, '{%message,UNKNOWN_MODULE_STATUS=' . $moduleState . '%}');
+ break;
+ } // END - switch
+
+ // Return status
+ return $isModuleValid;
+}
+
+// Include module
+function doIncludeModule () {
+ // Set content type
+ setContentType('text/html');
+
+ // Load page header
+ loadPageHeader();
+
+ // Modules are by default not valid!
+ $isModuleValid = FALSE;
+
+ // By default NULL is used
+ $GLOBALS['module_inc'] = NULL;
+
+ // Is the maintenance mode active or goes all well?
+ if ((isExtensionActive('maintenance')) && (isMaintenanceEnabled()) && (!isAdmin()) && (getModule() != 'admin')) {
+ // Maintain mode is active and you are no admin
+ addFatalMessage(__FUNCTION__, __LINE__, '{--MAILER_DOWN_FOR_MAINTENANCE--}');
+ } elseif ((isSqlLinkUp()) && (!ifFatalErrorsDetected())) {
+ // Do the small "load module" call
+ $isModuleValid = loadModule();
+ } elseif (!ifFatalErrorsDetected()) {
+ // SQL problems detected
+ addFatalMessage(__FUNCTION__, __LINE__, '{--MYSQL_ERRORS--}');
+ }
+
+ // Is the module valid?
+ if (($isModuleValid === TRUE) && (!is_null($GLOBALS['module_inc']))) {
+ // Run pre-filter
+ runFilterChain('pre_module_load');
+
+ // Everything is okay so we can load the module
+ loadIncludeOnce($GLOBALS['module_inc']);
+
+ // Run post-filter
+ runFilterChain('post_module_load');
+ } // END - if
+
+ // Add the footer (this will call doShutdown())
+ loadPageFooter();
+}
+
+// "Getter" for menu mode from given module
+function getMenuModeFromModule () {
+ // Is cache set?
+ if (!isset($GLOBALS[__FUNCTION__])) {
+ // Default is 'noindex' which is invalid for SQL tables but okay for meta data template
+ $GLOBALS[__FUNCTION__] = 'noindex';
+
+ // Determine it hard-coded
+ if (getModule() == 'login') {
+ // Is member area
+ $GLOBALS[__FUNCTION__] = 'member';
+ } elseif (getModule() == 'index') {
+ // Is guest area
+ $GLOBALS[__FUNCTION__] = 'guest';
+ } elseif (getModule() == 'admin') {
+ // Is admin area
+ $GLOBALS[__FUNCTION__] = 'admin';
+ } elseif (isInstaller()) {
+ // Is installation phase
+ $GLOBALS[__FUNCTION__] = 'install';
+ } else {
+ // Get it from filter
+ $GLOBALS[__FUNCTION__] = runFilterChain('determine_menu_mode');
+ }
+ } // END - if
+
+ // Return it
+ return $GLOBALS[__FUNCTION__];
+}
+
// [EOF]
?>