'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); // Is the module found? 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())))) { // If you are admin you are welcome for everything! $ret = 'done'; } elseif ($data['locked'] == 'Y') { // Module is locked $ret = 'locked'; } elseif (($data['mem_only'] == 'Y') && (!isMember())) { // You have to login first! $ret = 'mem_only'; } elseif (($data['admin_only'] == 'Y') && (!isAdmin())) { // Only the Admin is allowed to enter this module! $ret = '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'] )); } } // 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)))) { // 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 ('%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 ('%s','Y','N','N','N')", array($module_chk), __FUNCTION__, __LINE__); } // Everthing is fine? if (SQL_AFFECTEDROWS() < 1) { // Something bad happend! return 'major'; } // END - if // Destroy cache here // @TODO Rewrite this to a filter if ((isHtmlOutputMode()) || (isRawOutputMode())) rebuildCache('modules', 'modules'); // And reload data unset($GLOBALS['module_status'][$module]); $ret = checkModulePermissions($module_chk); } else { // Module not found we don't add it to the database $ret = '404'; } } elseif (($ret == 'cache_miss') && (isHtmlOutputMode())) { // Rebuild the cache files rebuildCache('modules', 'modules'); } 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'], getScriptOutputMode() )); } // Return the value //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret=' . $ret); $GLOBALS['module_status'][$module] = $ret; return $ret; } // Checks if the module has a menu function ifModuleHasMenu ($mod, $forceDb = false) { // All is false by default $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])) { // Check module cache and count hit $ret = ($GLOBALS['cache_array']['modules']['has_menu'][$mod] == 'Y'); incrementStatsEntry('cache_hits'); } elseif (isset($GLOBALS['cache_array']['extension']['ext_menu'][$mod])) { // Check cache and count hit $ret = ($GLOBALS['cache_array']['extension']['ext_menu'][$mod] == 'Y'); incrementStatsEntry('cache_hits'); } else { // Admin/guest/member/sponsor modules have always a menu! $ret = in_array($mod, array('admin', 'index', 'login', 'sponsor')); } } 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__); // Entry found? if (SQL_NUMROWS($result) == 1) { // Load "has_menu" column $data = SQL_FETCHARRAY($result); // Fake cache... ;-) $GLOBALS['cache_array']['extension']['ext_menu'][$mod] = $data['has_menu']; // Does it have a menu? $ret = ($data['has_menu'] == 'Y'); } // END - if // Free memory SQL_FREERESULT($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.'); } // Return status return $ret; } // [EOF] ?>