Login procedure rewritten to filters (internal TODO)
[mailer.git] / inc / filters.php
index 40fb713d99717057726f740728e1541e1455260b..7b6891497d0beeb3d1f3849adcc8b5417f3b9f25 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 12/16/2008 *
- * ===============                              Last change: 12/16/2008 *
+ * Mailer v0.2.1-FINAL                                Start: 12/16/2008 *
+ * ===================                          Last change: 12/16/2008 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : filters.php                                      *
@@ -343,7 +343,7 @@ function FILTER_REMOVE_UPDATES ($data) {
        // Do we need to remove update depency?
        if (countExtensionUpdateDependencies() > 0) {
                // Then find all updates we shall no longer execute
-               foreach (getExtensionUpdateDependencies() as $id=>$ext_name) {
+               foreach (getExtensionUpdateDependencies() as $id => $ext_name) {
                        // Shall we remove this update?
                        if (in_array($ext_name, getExtensionRemovalList())) {
                                // Then remove this extension!
@@ -434,7 +434,9 @@ function FILTER_COMPILE_CONFIG ($code, $compiled = false) {
        // Should we compile it?
        if ($compiled === true) {
                // Run the code
-               eval("\$GLOBALS['compiled_config'][\$uncompiled] = \"" . $GLOBALS['compiled_config'][$uncompiled] . "\";");
+               $eval = "\$GLOBALS['compiled_config'][\$uncompiled] = \"" . $GLOBALS['compiled_config'][$uncompiled] . "\";";
+               //* DEBUG: */ print '<pre>' . str_replace('$', '&#36;', htmlentities($eval)) . '</pre>';
+               eval($eval);
        } // END - if
 
        // Return compiled code
@@ -591,9 +593,12 @@ function FILTER_DETERMINE_WHAT_ACTION () {
                        if (isGetRequestElementSet('module')) {
                                // Set module from request
                                setModule(getRequestElement('module'));
-                       } else {
+                       } elseif (getOutputMode() == '0') {
                                // Set default module 'index'
                                setModule('index');
+                       } else {
+                               // Unknown module
+                               setModule('unknown');
                        }
                } // END - if
 
@@ -845,15 +850,60 @@ function FILTER_DISPLAY_PARSING_TIME () {
 
 // Filter for flushing template cache
 function FILTER_FLUSH_TEMPLATE_CACHE () {
+       // Do not flush when debugging the template cache
+       if (isDebuggingTemplateCache()) return;
+
        // Do we have cached eval() data?
        if ((isset($GLOBALS['template_eval'])) && (count($GLOBALS['template_eval']) > 0)) {
                // Now flush all
-               foreach ($GLOBALS['template_eval'] as $template=>$eval) {
+               foreach ($GLOBALS['template_eval'] as $template => $eval) {
                        // Flush the cache (if not yet found)
-                       //flushTemplateCache($template, $eval);
+                       flushTemplateCache($template, $eval);
                } // END - if
        } // END - if
 }
 
+// Filter for loading user data
+function FILTER_FETCH_USER_DATA ($userid = 0) {
+       // Is the userid not set? Then use member id
+       if (($userid == '0') || (is_null($userid))) $userid = getMemberId();
+
+       // Get user data
+       if (!fetchUserData($userid)) {
+               // Userid is not valid
+               debug_report_bug('User id '.$userid . ' is invalid.');
+       } // END - if
+
+       // Set member id
+       setMemberId($userid);
+}
+
+// Filter for reseting users' last login failure, only available with latest ext-sql_patches
+function FILTER_RESET_USER_LOGIN_FAILURE () {
+       // Is the user data valid?
+       if (!isMember()) {
+               // Do only run for logged in members
+               debug_report_bug('Please only run this filter for logged in users.');
+       } // END - if
+
+       // Remmeber login failures if available
+       if (isExtensionInstalledAndNewer('sql_patches') >= '0.6.1') {
+               // Reset login failures
+               SQL_QUERY_ESC("UPDATE
+       `{?_MYSQL_PREFIX?}_user_data`
+SET
+       `login_failures`=0,
+       `last_failure`='0000-00-00 00:00:00'
+WHERE
+       `userid`=%s
+LIMIT 1",
+                       array(getMemberId()), __FILE__, __LINE__);
+
+               // Store it in session
+               setSession('mxchange_member_failures' , getUserData('login_failures'));
+               setSession('mxchange_member_last_fail', getUserData('last_failure'));
+       } // END - if
+}
+
 // [EOF]
 ?>