- $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
- require($INC);
-}
-
-//
-function ADD_MODULE_TITLE($mod) {
- global $cacheArray, $_CONFIG;
- $name = ""; $result = false;
-
- // Is the script installed?
- if (isBooleanConstantAndTrue('mxchange_installed')) {
- // Check if cache is valid
- if ((GET_EXT_VERSION("cache") >= "0.1.2") && (isset($cacheArray['modules']['module'])) && (in_array($mod, $cacheArray['modules']['module']))) {
- // Load from cache
- $name = $cacheArray['modules']['title'][$mod];
-
- // Update cache hits
- if (isset($_CONFIG['cache_hits'])) { $_CONFIG['cache_hits']++; } else { $_CONFIG['cache_hits'] = 1; }
- } elseif (!EXT_IS_ACTIVE("cache")) {
- // Load from database
- $result = SQL_QUERY_ESC("SELECT title FROM "._MYSQL_PREFIX."_mod_reg WHERE module='%s' LIMIT 1", array($mod), __FILE__, __LINE__);
- list($name) = SQL_FETCHROW($result);
- SQL_FREERESULT($result);
- }
- } // END - if
-
- // Trim name
- $name = trim($name);
-
- // Still no luck or empty title?
- if (empty($name)) {
- // No name found
- $name = sprintf("%s (%s)", LANG_UNKNOWN_MODULE, $mod);
- if (SQL_NUMROWS($result) == 0) {
- // Add module to database
- $dummy = CHECK_MODULE($mod);
- } // END - if
- } // END - if
-
- // Return name
- return $name;
-}
-
-// Check validity of a given module name (no file extension)
-function CHECK_MODULE ($mod) {
- // We need them now here...
- global $cacheArray, $_CONFIG, $cacheInstance;
-
- // Filter module name (names with low chars and underlines are fine!)
- $mod = preg_replace("/[^a-z_]/", "", $mod);
-
- // Check for prefix is a extension...
- $modSplit = explode("_", $mod);
- $extension = ""; $mod_chk = $mod;
- //* DEBUG: */ echo __LINE__."*".count($modSplit)."*/".$mod."*<br />";
- if (count($modSplit) == 2) {
- // Okay, there is a seperator (_) in the name so is the first part a module?
- //* DEBUG: */ echo __LINE__."*".$modSplit[0]."*<br />";
- if (EXT_IS_ACTIVE($modSplit[0])) {
- // The prefix is an extension's name, so let's set it
- $extension = $modSplit[0]; $mod = $modSplit[1];
- }
- }
-
- // Major error in module registry is the default
- $ret = "major";
-
- // Check if script is installed if not return a "done" to prevent some errors
- if ((!isBooleanConstantAndTrue('mxchange_installed')) || (isBooleanConstantAndTrue('mxchange_installing')) || (!isBooleanConstantAndTrue('admin_registered'))) return "done";
-
- // Check if cache is latest version
- $locked = "Y"; $hidden = "N"; $admin = "N"; $mem = "N"; $found = false;
- if ((GET_EXT_VERSION("cache") >= "0.1.2") && (isset($cacheArray['modules']['module'])) && (is_array($cacheArray['modules']['module']))) {
- // Is the module cached?
- if (isset($cacheArray['modules']['locked'][$mod_chk])) {
- // Check cache
- $locked = $cacheArray['modules']['locked'][$mod_chk];
- $hidden = $cacheArray['modules']['hidden'][$mod_chk];
- $admin = $cacheArray['modules']['admin_only'][$mod_chk];
- $mem = $cacheArray['modules']['mem_only'][$mod_chk];
-
- // Update cache hits
- if (isset($_CONFIG['cache_hits'])) { $_CONFIG['cache_hits']++; } else { $_CONFIG['cache_hits'] = 1; }
- $found = true;
- } else {
- // No, then we have to update it!
- $ret = "cache_miss";
- }
- } elseif (!EXT_IS_ACTIVE("cache")) {
- // Check for module in database
- $result = SQL_QUERY_ESC("SELECT locked, hidden, admin_only, mem_only FROM "._MYSQL_PREFIX."_mod_reg WHERE module='%s' LIMIT 1", array($mod_chk), __FILE__, __LINE__);
- if (SQL_NUMROWS($result) == 1) {
- // Read data
- list($locked, $hidden, $admin, $mem) = SQL_FETCHROW($result);
- SQL_FREERESULT($result);
- $found = true;
- }
- }
-
- // Check returned values against current access permissions
- //
- // Admin access ----- Guest access ----- --- Guest or member? ---
- if ((IS_ADMIN()) || (($locked == "N") && ($admin == "N") && (($mem == "N") || (IS_MEMBER())))) {
- // If you are admin you are welcome for everything!
- $ret = "done";
- } elseif ($locked == "Y") {
- // Module is locked
- $ret = "locked";
- } elseif (($mem == "Y") && (!IS_MEMBER())) {
- // You have to login first!
- $ret = "mem_only";
- } elseif (($admin == "Y") && (!IS_ADMIN())) {
- // Only the Admin is allowed to enter this module!
- $ret = "admin_only";