]> git.mxchange.org Git - mailer.git/blobdiff - inc/filters.php
More queries and language constants rewritten
[mailer.git] / inc / filters.php
index c0b3702d2eb191ac615e61dbe32cfccedb6f7f63..f479861e71529c60c960fe529a2e7fd4aad5e798 100644 (file)
@@ -38,13 +38,13 @@ if (!defined('__SECURITY')) {
 }
 
 // Init "generic filter system"
-function INIT_FILTER_SYSTEM() {
+function INIT_FILTER_SYSTEM () {
        global $filters, $loadedFilters, $counter;
 
        // Is the filter already initialized?
        if ((isset($filters)) && (is_array($filters))) {
                // Then abort here
-               ADD_FATAL(FILTER_FAILED_ALREADY_INIT);
+               addFatalMessage(getMessage('FILTER_FAILED_ALREADY_INIT'));
                return false;
        } // END - if
 
@@ -70,7 +70,7 @@ function INIT_FILTER_SYSTEM() {
 
                // Load all active filers
                $result = SQL_QUERY("SELECT `filter_name`, `filter_function`, `filter_active`".$ADD."
-FROM `"._MYSQL_PREFIX."_filters`
+FROM `{!_MYSQL_PREFIX!}_filters`
 ORDER BY `filter_id` ASC", __FILE__, __LINE__);
 
                // Are there entries?
@@ -102,7 +102,11 @@ ORDER BY `filter_id` ASC", __FILE__, __LINE__);
                SQL_FREERESULT($result);
        } // END - if
 
-       // Login failtures handler
+       // Init filters
+       REGISTER_FILTER('init', 'UPDATE_LOGIN_DATA');
+       REGISTER_FILTER('init', 'INIT_RANDOMIZER');
+
+       // Login failures handler
        REGISTER_FILTER('post_youhere_line', 'CALL_HANDLER_LOGIN_FAILTURES');
 
        // Filters for pre-extension-registration
@@ -122,12 +126,15 @@ ORDER BY `filter_id` ASC", __FILE__, __LINE__);
        // Run SQLs
        REGISTER_FILTER('run_sqls', 'RUN_SQLS');
 
+       // Admin ACL check
+       REGISTER_FILTER('check_admin_acl', 'CHECK_ADMIN_ACL');
+
        // Register shutdown filters
        REGISTER_FILTER('shutdown', 'FLUSH_FILTERS');
 }
 
 // "Registers" a new filter function
-function REGISTER_FILTER ($filterName, $filterFunction, $silentAbort = true, $force = false, $add = true) {
+function REGISTER_FILTER ($filterName, $filterFunction, $silentAbort = true, $force = false, $dry_run = false) {
        global $filters, $counter;
 
        // Extend the filter function name
@@ -137,7 +144,7 @@ function REGISTER_FILTER ($filterName, $filterFunction, $silentAbort = true, $fo
        if ((isset($filters[$filterName][$filterFunction])) && (!$force)) {
                // Then abort here
                if (!$silentAbort) {
-                       ADD_FATAL(sprintf(FILTER_FAILED_ALREADY_ADDED, $filterFunction, $filterName));
+                       addFatalMessage(sprintf(getMessage('FILTER_FAILED_ALREADY_ADDED'), $filterFunction, $filterName));
                } // END - if
 
                // Abort here
@@ -147,12 +154,12 @@ function REGISTER_FILTER ($filterName, $filterFunction, $silentAbort = true, $fo
        // Is the function there?
        if (!function_exists($filterFunction)) {
                // Then abort here
-               ADD_FATAL(sprintf(FILTER_FAILED_NOT_FOUND, $filterFunction, $filterName));
+               addFatalMessage(sprintf(getMessage('FILTER_FAILED_NOT_FOUND'), $filterFunction, $filterName));
                return false;
        } // END - if
 
        // Shall we add it?
-       if ($add) {
+       if (!$dry_run) {
                // Simply add it to the array
                $filters[$filterName][$filterFunction] = "Y";
                $counter[$filterName][$filterFunction] = 0;
@@ -160,21 +167,23 @@ function REGISTER_FILTER ($filterName, $filterFunction, $silentAbort = true, $fo
 }
 
 // "Unregisters" a filter from the given chain
-function UNREGISTER_FILTER ($filterName, $filterFunction, $force = false, $remove = true) {
-       global $filters, $counter;
+function UNREGISTER_FILTER ($filterName, $filterFunction, $force = false, $dry_run = false) {
+       global $filters, $counter, $loadedFilters;
 
-       // Extend the filter function name
-       $filterFunction = sprintf("FILTER_%s", strtoupper($filterFunction));
+       // Extend the filter function name only if not loaded from database
+       if (!isset($loadedFilters[$filterName][$filterFunction])) {
+               $filterFunction = sprintf("FILTER_%s", strtoupper($filterFunction));
+       } // END - if
 
        // Is that filter there?
        if ((!isset($filters[$filterName][$filterFunction])) && (!$force)) {
                // Not found, so abort here
-               ADD_FATAL(sprintf(FILTER_FAILED_NOT_REMOVED, $filterFunction, $filterName));
+               addFatalMessage(sprintf(getMessage('FILTER_FAILED_NOT_REMOVED'), $filterFunction, $filterName));
                return false;
        } // END - if
 
        // Shall we remove? (default, not while just showing an extension removal)
-       if ($remove) {
+       if (!$dry_run) {
                // Mark for filter removal
                $filters[$filterName][$filterFunction] = "R";
                unset($counter[$filterName][$filterFunction]);
@@ -190,7 +199,7 @@ function RUN_FILTER ($filterName, $data = null, $silentAbort = true) {
                // Then abort here (quick'N'dirty hack)
                if ((!$silentAbort) && (defined('FILTER_FAILED_NO_FILTER_FOUND'))) {
                        // Add fatal message
-                       ADD_FATAL(sprintf(FILTER_FAILED_NO_FILTER_FOUND, $filterName));
+                       addFatalMessage(sprintf(getMessage('FILTER_FAILED_NO_FILTER_FOUND'), $filterName));
                } // END - if
 
                // Abort here
@@ -203,7 +212,7 @@ function RUN_FILTER ($filterName, $data = null, $silentAbort = true) {
        // Then run all filters
        foreach ($filters[$filterName] as $filterFunction=>$active) {
                // Debug message
-               //* DEBUG: */ echo __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): name={$filterName}, func={$filterFunction}, active={$active}<br />\n";
+               //* DEBUG: */ echo __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): name={$filterName},func={$filterFunction},active={$active}<br />\n";
 
                // Is the filter active?
                if ($active == "Y") {
@@ -242,7 +251,7 @@ function FILTER_FLUSH_FILTERS () {
        // Is a database link here and not in installation mode?
        if ((!is_resource($link)) && (!isBooleanConstantAndTrue('mxchange_installing'))) {
                // Abort here
-               ADD_FATAL(sprintf(FILTER_FLUSH_FAILED_NO_DATABASE, $filterFunction, $filterName));
+               addFatalMessage(sprintf(getMessage('FILTER_FLUSH_FAILED_NO_DATABASE'), $filterFunction, $filterName));
                return false;
        } // END - if
 
@@ -256,8 +265,8 @@ function FILTER_FLUSH_FILTERS () {
        $inserted = 0; $removed = 0;
 
        // Prepare SQL queries
-       $insertSQL = "INSERT INTO `"._MYSQL_PREFIX."_filters` (`filter_name`,`filter_function`,`filter_active`) VALUES";
-       $removeSQL = "DELETE LOW_PRIORITY FROM `"._MYSQL_PREFIX."_filters` WHERE";
+       $insertSQL = "INSERT INTO `{!_MYSQL_PREFIX!}_filters` (`filter_name`,`filter_function`,`filter_active`) VALUES";
+       $removeSQL = "DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_filters` WHERE";
 
        // Write all filters to database
        foreach ($filters as $filterName => $filterArray) {
@@ -291,7 +300,7 @@ function FILTER_FLUSH_FILTERS () {
                $removeSQL = substr($removeSQL, 0, -2) . "LIMIT ".$removed;
 
                // And run it
-               $removeSQL;
+               $SQLs[] = $removeSQL;
        } // END - if
 
        // Shall we update usage counters (ONLY FOR DEBUGGING!)
@@ -301,7 +310,7 @@ function FILTER_FLUSH_FILTERS () {
                        // Walk through all filters
                        foreach ($filterArray as $filterFunction => $cnt) {
                                // Construct and add the query
-                               $SQLs[] = sprintf("UPDATE `"._MYSQL_PREFIX."_filters` SET `filter_counter`=%s WHERE `filter_name`='%s' AND `filter_function`='%s' LIMIT 1",
+                               $SQLs[] = sprintf("UPDATE `{!_MYSQL_PREFIX!}_filters` SET `filter_counter`=%s WHERE `filter_name`='%s' AND `filter_function`='%s' LIMIT 1",
                                        bigintval($cnt),
                                        $filterName,
                                        $filterFunction
@@ -311,10 +320,10 @@ function FILTER_FLUSH_FILTERS () {
        } // END - if
 
        // Run the run_sqls filter in non-dry mode
-       RUN_FILTER('run_sqls', false);
+       RUN_FILTER('run_sqls', array('dry_run' => false, 'sqls' => $SQLs));
 }
 
-// Filter for calling the handler for login failtures
+// Filter for calling the handler for login failures
 function FILTER_CALL_HANDLER_LOGIN_FAILTURES ($data) {
        // Init content
        $content = $data;
@@ -322,7 +331,7 @@ function FILTER_CALL_HANDLER_LOGIN_FAILTURES ($data) {
        // Handle failed logins here if not in guest
        //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):type={$data['type']},action={$GLOBALS['action']},what={$GLOBALS['what']},lvl={$data['access_level']}<br />\n";
        if ((($data['type'] == "what") || ($data['type'] == "action") && ((!isset($GLOBALS['what'])) || ($GLOBALS['what'] == "overview") || ($GLOBALS['what'] == getConfig('index_home')))) && ($data['access_level'] != "guest") && ((GET_EXT_VERSION("sql_patches") >= "0.4.7") || (GET_EXT_VERSION("admins") >= "0.7.0"))) {
-               // Handle failture
+               // Handle failure
                $content['content'] .= HANDLE_LOGIN_FAILTURES($data['access_level']);
        } // END - if
 
@@ -338,7 +347,7 @@ function FILTER_REDIRECT_TO_LOGOUT_SQL_PATCHES () {
        // Is the element set?
        if (isset($GLOBALS['ext_load_mode'])) {
                // Redirect here
-               LOAD_URL("modules.php?module=admin&logout=1&".$GLOBALS['ext_load_mode']."=sql_patches");
+               LOAD_URL("modules.php?module=admin&amp;logout=1&amp;".$GLOBALS['ext_load_mode']."=sql_patches");
        } // END - if
 
        // This should not happen!
@@ -380,38 +389,42 @@ function FILTER_SOLVE_TASK ($data) {
 
 // Filter to load include files
 function FILTER_LOAD_INCLUDES ($data) {
-       global $INC_POOL;
+       global $CSS;
+
+       // Default is $data as inclusion list
+       $INC_POOL = $data;
 
        // Is it an array?
-       if ((!isset($INC_POOL)) || (!is_array($INC_POOL))) {
+       if ((!isset($data)) || (!is_array($data))) {
                // Then abort here
                DEBUG_LOG(__FILE__, __LINE__, "INC_POOL is no array!");
                return $data;
-       } // END - if
+       } elseif (isset($data['inc_pool'])) {
+               // Use this as new inclusion pool!
+               $INC_POOL = $data['inc_pool'];
+       }
 
        // Check for added include files
        if (count($INC_POOL) > 0) {
                // Loads every include file
-               foreach ($INC_POOL as $fqfn) {
-                       require_once($fqfn);
+               foreach ($INC_POOL as $FQFN) {
+                       LOAD_INC_ONCE($FQFN);
                } // END - foreach
 
-               // Remove array
-               unset($INC_POOL);
+               // Reset array
+               if (isset($data['inc_pool'])) $data['inc_pool'] = array();
        } // END - if
 
-       // Return $data
+       // Continue with processing
        return $data;
 }
 
 // Filter for running SQL commands
-function FILTER_RUN_SQLS ($dry_run) {
-       global $SQLs;
-
+function FILTER_RUN_SQLS ($data) {
        // Is the array there?
-       if ((is_array($SQLs)) && (!$dry_run)) {
+       if ((isset($data['sqls'])) && ((!isset($data['dry_run'])) || ($data['dry_run'] == false))) {
                // Run SQL commands
-               foreach ($SQLs as $sql) {
+               foreach ($data['sqls'] as $sql) {
                        $sql = trim($sql);
                        if (!empty($sql)) {
                                // Do we have an "ALTER TABLE" command?
@@ -424,10 +437,82 @@ function FILTER_RUN_SQLS ($dry_run) {
                                }
                        } // END - if
                } // END - foreach
-       } elseif (GET_EXT_VERSION("sql_patches") == "") {
-               // Remove SQLs if extension is not installed
-               $SQLs = array();
+       } // END - if
+}
+
+// Filter for updating/validating login data
+function FILTER_UPDATE_LOGIN_DATA () {
+       global $LAST;
+       if (!is_array($LAST)) $LAST = array();
+
+       // Recheck if logged in
+       if (!IS_MEMBER()) return false;
+
+       // Secure user ID
+       $GLOBALS['userid'] = bigintval(get_session('userid'));
+
+       // Load last module and last online time
+       $result = SQL_QUERY_ESC("SELECT last_module, last_online FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
+               array($GLOBALS['userid']), __FILE__, __LINE__);
+
+       // Entry found?
+       if (SQL_NUMROWS($result) == 1) {
+               // Load last module and online time
+               list($mod, $onl) = SQL_FETCHROW($result);
+
+               // Maybe first login time?
+               if (empty($mod)) $mod = "login";
+
+               // This will be displayed on welcome page! :-)
+               if (empty($LAST['module'])) {
+                       $LAST['module'] = $mod; $LAST['online'] = $onl;
+               } // END - if
+
+               // "what" not set?
+               if (empty($GLOBALS['what'])) {
+                       // Fix it to default
+                       $GLOBALS['what'] = "welcome";
+                       if (getConfig('index_home') != "") $GLOBALS['what'] = getConfig('index_home');
+               } // END - if
+
+               // Update last module / online time
+               SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET last_module='%s', last_online=UNIX_TIMESTAMP(), REMOTE_ADDR='%s' WHERE userid=%s LIMIT 1",
+                       array($GLOBALS['what'], GET_REMOTE_ADDR(), $GLOBALS['userid']), __FILE__, __LINE__);
+       }  else {
+               // Destroy session, we cannot update!
+               destroy_user_session();
        }
+
+       // Free the result
+       SQL_FREERESULT($result);
+}
+
+// Filter for checking admin ACL
+function FILTER_CHECK_ADMIN_ACL () {
+       // Extension not installed so it's always allowed to access everywhere!
+       $ret = true;
+
+       // Ok, Cookie-Update done
+       if (GET_EXT_VERSION("admins") >= "0.3") {
+               // Check if action GET variable was set
+               $action = SQL_ESCAPE($GLOBALS['action']);
+               if (!empty($GLOBALS['what'])) {
+                       // Get action value by what-value
+                       $action = GET_ACTION("admin", $GLOBALS['what']);
+               } // END - if
+
+               // Check for access control line of current menu entry
+               $ret = ADMINS_CHECK_ACL($action, $GLOBALS['what']);
+       } // END - if
+
+       // Return result
+       return $ret;
+}
+
+// Filter for initializing randomizer
+function FILTER_INIT_RANDOMIZER () {
+       // Simply init the randomizer with seed and _ADD value
+       mt_srand(generateSeed() + constant('_ADD'));
 }
 
 //