]> git.mxchange.org Git - mailer.git/commitdiff
Encapsulated access on many ['cache_array']['modules']['foo'] entries
authorRoland Häder <roland@mxchange.org>
Sun, 26 Sep 2010 01:26:41 +0000 (01:26 +0000)
committerRoland Häder <roland@mxchange.org>
Sun, 26 Sep 2010 01:26:41 +0000 (01:26 +0000)
inc/module-functions.php

index 58ae31fc548476a4ffe9733e8ff086ddef1c544d..445c8505d453d7944c22afd555d79fb238806b2f 100644 (file)
@@ -165,6 +165,42 @@ function isModuleRegistered ($module) {
        return $found;
 }
 
        return $found;
 }
 
+// Checks wether 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 wether 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 wether 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 wether 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
 // Check validity of a given module name (no file extension)
 function checkModulePermissions ($module = '') {
        // Is it empty (default), then take the current one
@@ -215,26 +251,26 @@ function checkModulePermissions ($module = '') {
                // Check returned values against current access permissions
                //
                // Admin access                                                              ----- Guest access -----                                                                                                                         --- Guest   or   member? ---
                // 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 ((isAdmin()) || ((!isModuleLocked($module_chk)) && (!isModuleAdminOnly($module_chk)) && ((!isModuleMemberOnly($module_chk)) || (isMember())))) {
                        // If you are admin you are welcome for everything!
                        setModuleStatus($module_chk, 'done');
                        // If you are admin you are welcome for everything!
                        setModuleStatus($module_chk, 'done');
-               } elseif ($GLOBALS['cache_array']['modules']['locked'][$module_chk] == 'Y') {
+               } elseif (isModuleLocked($module_chk)) {
                        // Module is locked
                        setModuleStatus($module_chk, 'locked');
                        // Module is locked
                        setModuleStatus($module_chk, 'locked');
-               } elseif (($GLOBALS['cache_array']['modules']['mem_only'][$module_chk] == 'Y') && (!isMember())) {
+               } elseif ((isModuleMemberOnly($module_chk)) && (!isMember())) {
                        // You have to login first!
                        setModuleStatus($module_chk, 'mem_only');
                        // You have to login first!
                        setModuleStatus($module_chk, 'mem_only');
-               } elseif (($GLOBALS['cache_array']['modules']['admin_only'][$module_chk] == 'Y') && (!isAdmin())) {
+               } elseif ((isModuleAdminOnly($module_chk)) && (!isAdmin())) {
                        // Only the Admin is allowed to enter this module!
                        setModuleStatus($module_chk, 'admin_only');
                } else {
                        // @TODO Nothing helped???
                        // 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",
+                       logDebugMessage(__FUNCTION__, __LINE__, sprintf("ret=%s,locked=%d,hidden=%d,mem=%d,admin=%d",
                                getModuleStatus($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]
+                               intval(isModuleLocked($module_chk)),
+                               intval(isModuleHidden($module_chk)),
+                               intval(isModuleMemberOnly($module_chk)),
+                               intval(isModuleAdminOnly($module_chk))
                        ));
                }
        } // END - if
                        ));
                }
        } // END - if
@@ -286,13 +322,13 @@ VALUES
                rebuildCache('modules', 'modules');
        } elseif ($found === false) {
                // Problem with module detected
                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",
+               logDebugMessage(__FUNCTION__, __LINE__, sprintf("Problem in module %s detected. ret=%s,locked=%d,hidden=%d,mem=%d,admin=%d,output_mode=%s",
                        $module_chk,
                        getModuleStatus($module_chk),
                        $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],
+                       intval(isModuleLocked($module_chk)),
+                       intval(isModuleHidden($module_chk)),
+                       intval(isModuleMemberOnly($module_chk)),
+                       intval(isModuleAdminOnly($module_chk)),
                        getScriptOutputMode()
                ));
        }
                        getScriptOutputMode()
                ));
        }