]> git.mxchange.org Git - mailer.git/blobdiff - inc/module-functions.php
Extension ext-earning introduced (unfinished), renamings:
[mailer.git] / inc / module-functions.php
index d0f00c8fa60c1f2602cd434fd4c4741d4f6ae60b..e4ef7dff421e03d721e0b16fc861a8e340e74f7a 100644 (file)
@@ -6,9 +6,9 @@
  * -------------------------------------------------------------------- *
  * File              : module-functions.php                             *
  * -------------------------------------------------------------------- *
- * Short description : All MySQL-related functions                      *
+ * Short description : Module functions                                 *
  * -------------------------------------------------------------------- *
- * Kurzbeschreibung  : Alle MySQL-Relevanten Funktionen                 *
+ * Kurzbeschreibung  : Modulfunktionen                                  *
  * -------------------------------------------------------------------- *
  * $Revision::                                                        $ *
  * $Date::                                                            $ *
@@ -16,7 +16,7 @@
  * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
- * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
+ * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
  * For more information visit: http://www.mxchange.org                  *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
@@ -61,7 +61,7 @@ function getModuleTitle ($module) {
                                array($module), __FUNCTION__, __LINE__);
 
                        // Is the entry there?
-                       if (SQL_NUMROWS($result)) {
+                       if (SQL_NUMROWS($result) == 1) {
                                // Get the title from database
                                $data = SQL_FETCHARRAY($result);
                        } // END - if
@@ -79,13 +79,13 @@ function getModuleTitle ($module) {
                // Is it 'error'?
                if ($module == 'error') {
                        // Error (real module was not found)
-                       $data['title'] = getMessage('MODULE_ERROR_404');
+                       $data['title'] = '{--MODULE_ERROR_404--}';
                }  else {
                        // No name found
-                       $data['title'] = getMaskedMessage('UNKNOWN_MODULE_DETECTED', $module);
+                       $data['title'] = '{%message,UNKNOWN_MODULE_DETECTED_TITLE=' . $module . '%}';
                        if ((is_resource($result)) && (SQL_HASZERONUMS($result))) {
-                               // Add module to database
-                               $dummy = checkModulePermissions($module);
+                               // Add module to database and ignore return value
+                               checkModulePermissions($module);
                        } // END - if
                }
        } // END - if
@@ -139,7 +139,7 @@ function isModuleRegistered ($module) {
        } 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",
+               $result = SQL_QUERY_ESC("SELECT `locked`,`hidden`,`admin_only`,`mem_only` FROM `{?_MYSQL_PREFIX?}_mod_reg` WHERE `module`='%s' LIMIT 1",
                        array($module), __FUNCTION__, __LINE__);
                if (SQL_NUMROWS($result) == 1) {
                        // Read data
@@ -154,7 +154,7 @@ function isModuleRegistered ($module) {
                        $found = true;
                } elseif (isDebugModeEnabled()) {
                        // Debug message only in debug-mode...
-                       logDebugMessage(__FUNCTION__, __LINE__, 'Module ' . $module . ' not found!');
+                       logDebugMessage(__FUNCTION__, __LINE__, 'Module ' . $module . ' not found.');
                }
 
                // Free result
@@ -286,13 +286,13 @@ function checkModulePermissions ($module = '') {
                                 * 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`)
+(`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`)
+(`module`,`locked`,`hidden`,`mem_only`,`admin_only`)
 VALUES
 ('%s','Y','N','N','N')", array($module_chk), __FUNCTION__, __LINE__);
                        }
@@ -322,7 +322,7 @@ VALUES
                rebuildCache('modules', 'modules');
        } elseif ($found === false) {
                // Problem with module detected
-               logDebugMessage(__FUNCTION__, __LINE__, sprintf("Problem in module %s detected. ret=%s,locked=%d,hidden=%d,mem=%d,admin=%d,output_mode=%s",
+               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)),
@@ -334,7 +334,7 @@ VALUES
        }
 
        // Debug log
-       logDebugMessage(__FUNCTION__, __LINE__, sprintf("module=%s, status=%s", $module_chk, getModuleStatus($module_chk)));
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("module=%s, status=%s", $module_chk, getModuleStatus($module_chk)));
 
        // Return the value
        return getModuleStatus($module_chk);
@@ -396,7 +396,7 @@ 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 . "')");
+               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",
@@ -409,5 +409,111 @@ function addModuleSql ($module, $locked, $hidden, $adminOnly, $memOnly) {
        }
 }
 
+// Load the currently set module
+function loadModule () {
+       // By default all modules are invalid
+       $isModuleValid = false;
+
+       // Init module state as 'failed' (always failed first)
+       $moduleState = 'failed';
+
+       // 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_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');
+
+       // The header file
+       loadIncludeOnce('inc/header.php');
+
+       // 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 ((SQL_IS_LINK_UP()) && (!ifFatalErrorsDetected())) {
+               // Do the small "load module" call
+               $isModuleValid = loadModule();
+       } elseif (!ifFatalErrorsDetected()) {
+               // SQL problems detected
+               addFatalMessage(__FUNCTION__, __LINE__, '{--MYSQL_ERRORS--}');
+       }
+
+       if (($isModuleValid === true) && (!is_null($GLOBALS['module_inc']))) {
+               // Everything is okay so we can load the module
+               loadIncludeOnce($GLOBALS['module_inc']);
+       } // END - if
+
+       // Add the footer (this will call shutdown())
+       loadIncludeOnce('inc/footer.php');
+}
+
 // [EOF]
 ?>