$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!'); } // Free result SQL_FREERESULT($result); } // Return status return $found; } // 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)) { // Use current module $module = getModule(); } // END - if // Do we have cache? if (isModuleStatusSet($module)) { // Then use it return getModuleStatus($module); } // END - if // Filter module name (names with low chars and underlines are fine!) $module = preg_replace('/[^a-z_]/', '', $module); // Check for prefix is a extension... $modSplit = explode('_', $module); $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? //* DEBUG: */ debugOutput(__LINE__.'*'.$modSplit[0].'*'); if (isExtensionActive($modSplit[0])) { // The prefix is an extension's name, so let's set it $extension = $modSplit[0]; $module = $modSplit[1]; } // END - if } // END - if // Major error in module registry is the default setModuleStatus($module_chk, 'major'); // Check if script is installed if not return a 'done' to prevent some errors if ((isInstallationPhase()) || (!isAdminRegistered())) { // Not installed or no admin registered or in installation phase setModuleStatus($module_chk, 'done'); // Return status return 'done'; } // END - if // Check if the module is registered $found = isModuleRegistered($module_chk); // Is the module found? if ($found === true) { // Check returned values against current access permissions // // Admin access ----- Guest access ----- --- Guest or member? --- if ((isAdmin()) || (($GLOBALS['cache_array']['modules']['locked'][$module_chk] != 'Y') && ($GLOBALS['cache_array']['modules']['admin_only'][$module_chk] != 'Y') && (($GLOBALS['cache_array']['modules']['mem_only'][$module_chk] != 'Y') || (isMember())))) { // If you are admin you are welcome for everything! setModuleStatus($module_chk, 'done'); } elseif ($GLOBALS['cache_array']['modules']['locked'][$module_chk] == 'Y') { // Module is locked setModuleStatus($module_chk, 'locked'); } elseif (($GLOBALS['cache_array']['modules']['mem_only'][$module_chk] == 'Y') && (!isMember())) { // You have to login first! setModuleStatus($module_chk, 'mem_only'); } elseif (($GLOBALS['cache_array']['modules']['admin_only'][$module_chk] == 'Y') && (!isAdmin())) { // Only the Admin is allowed to enter this module! setModuleStatus($module_chk, 'admin_only'); } else { // @TODO Nothing helped??? logDebugMessage(__FUNCTION__, __LINE__, sprintf("ret=%s,locked=%s,hidden=%s,mem=%s,admin=%s", getModuleStatus($module_chk), $GLOBALS['cache_array']['modules']['locked'][$module_chk], $GLOBALS['cache_array']['modules']['hidden'][$module_chk], $GLOBALS['cache_array']['modules']['mem_only'][$module_chk], $GLOBALS['cache_array']['modules']['admin_only'][$module_chk] )); } } // END - if // Still no luck or not found? 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(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! setModuleStatus($module_chk, 'major'); return 'major'; } // END - if // Destroy cache here // @TODO Rewrite this to a filter if ((isHtmlOutputMode()) || (isRawOutputMode())) { rebuildCache('modules', 'modules'); } // END - if // And reload data unset($GLOBALS['module_status'][$module_chk]); return checkModulePermissions($module_chk); } else { // Module not found we don't add it to the database setModuleStatus($module_chk, '404'); } } elseif ((getModuleStatus($module_chk) == '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_chk, getModuleStatus($module_chk), $GLOBALS['cache_array']['modules']['locked'][$module_chk], $GLOBALS['cache_array']['modules']['hidden'][$module_chk], $GLOBALS['cache_array']['modules']['mem_only'][$module_chk], $GLOBALS['cache_array']['modules']['admin_only'][$module_chk], getScriptOutputMode() )); } // Debug log logDebugMessage(__FUNCTION__, __LINE__, sprintf("module=%s, status=%s", $module_chk, getModuleStatus($module_chk))); // Return the value return getModuleStatus($module_chk); } // Checks if the module has a menu function ifModuleHasMenu ($module, $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'][$module])) { // Check module cache and count hit $ret = ($GLOBALS['cache_array']['modules']['has_menu'][$module] == 'Y'); incrementStatsEntry('cache_hits'); } elseif (isset($GLOBALS['cache_array']['extension']['ext_menu'][$module])) { // Check cache and count hit $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($module, 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($module), __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'][$module] = $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($module, 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; } // Adds a SQL for given module function addModuleSql ($module, $locked, $hidden, $adminOnly, $memOnly) { // Is the module already registered? if (!isModuleRegistered($module)) { // Add it addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_mod_reg` (`module`,`locked`,`hidden`,`admin_only`,`mem_only`) VALUES('" . $module . "','" . $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 )); } } // [EOF] ?>