+ die();
+} // END - if
+
+// Filter for flushing all new filters to the database
+function FILTER_FLUSH_FILTERS () {
+ // Clear all previous SQL queries
+ initSqls();
+
+ // Are we installing?
+ if ((isInstallationPhase())) {
+ // Then silently skip this filter
+ return true;
+ } // END - if
+
+ // Is a database link here and not in installation mode?
+ if ((!SQL_IS_LINK_UP()) && (!isInstalling())) {
+ // Abort here
+ addFatalMessage(__FUNCTION__, __LINE__, '{--FILTER_FLUSH_FAILED_NO_DATABASE--}');
+ return false;
+ } // END - if
+
+ // Is the extension sql_patches updated?
+ if ((!isExtensionInstalled('sql_patches')) || (isExtensionInstalledAndOlder('sql_patches', '0.5.9'))) {
+ // Abort silently here
+ return false;
+ } // END - if
+
+ // Nothing is added/remove by default
+ $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';
+
+ // Write all filters to database
+ foreach ($GLOBALS['cache_array']['filter']['chains'] as $filterName => $filterArray) {
+ // Walk through all filters
+ foreach ($filterArray as $filterFunction => $active) {
+ // Is this filter loaded?
+ //* DEBUG: */ debugOutput('FOUND:'.$filterName.'/'.$filterFunction.'='.$active);
+ if (((!isset($GLOBALS['cache_array']['filter']['loaded'][$filterName][$filterFunction])) && ($active != 'R')) || ($active == 'A')) {
+ // Add this filter (all filters are active by default)
+ //* DEBUG: */ debugOutput('ADD:'.$filterName.'/'.$filterFunction);
+ $insertSQL .= sprintf("('%s','%s','Y'),", $filterName, $filterFunction);
+ $inserted++;
+ } elseif ($active == 'R') {
+ // Remove this filter
+ //* DEBUG: */ debugOutput('REMOVE:'.$filterName.'/'.$filterFunction);
+ $removeSQL .= sprintf(" (`filter_name`='%s' AND `filter_function`='%s') OR", $filterName, $filterFunction);
+ $removed++;
+ }
+ } // END - foreach
+ } // END - foreach
+
+ // Something has been added?
+ if ($inserted > 0) {
+ // Finish SQL command and add it
+ addSql(substr($insertSQL, 0, -1));
+ } // END - if
+
+ // Something has been removed?
+ if ($removed > 0) {
+ // Finish SQL command and add it
+ addSql(substr($removeSQL, 0, -2) . 'LIMIT ' . $removed);
+ } // END - if
+
+ // Shall we update usage counters (ONLY FOR DEBUGGING!)
+ if (isFilterUsageUpdateEnabled()) {
+ // Update all counters
+ foreach ($GLOBALS['cache_array']['filter']['counter'] as $filterName => $filterArray) {
+ // Walk through all filters
+ foreach ($filterArray as $filterFunction => $cnt) {
+ // Construct and add the query
+ addSql(sprintf("UPDATE `{?_MYSQL_PREFIX?}_filters` SET `filter_counter`=%s WHERE `filter_name`='%s' AND `filter_function`='%s' LIMIT 1",
+ bigintval($cnt),
+ $filterName,
+ $filterFunction
+ ));
+ } // END - foreach
+ } // END - foreach
+ } // END - if
+
+ // Run the run_sqls filter in non-dry mode
+ runFilterChain('run_sqls');
+
+ // Should we rebuild cache?
+ if (($inserted > 0) || ($removed > 0)) {
+ // Destroy cache
+ rebuildCache('filter', 'filter');
+ } // END - if
+}
+
+// Filter for calling the handler for login failures
+function FILTER_CALL_HANDLER_LOGIN_FAILTURES ($data) {
+ // Init content
+ $content = $data;
+
+ // Handle failed logins here if not in guest
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "type=".$data['type'].",action=".getAction().",what=".getWhat().",level=".$data['access_level']."<br />");
+ if ((($data['type'] == 'what') || ($data['type'] == 'action') && ((!isWhatSet()) || (getWhat() == 'overview') || (getWhat() == getIndexHome()))) && ($data['access_level'] != 'guest') && ((isExtensionInstalledAndNewer('sql_patches', '0.4.7')) || (isExtensionInstalledAndNewer('admins', '0.7.0')))) {
+ // Handle failure
+ $content['content'] .= handleLoginFailures($data['access_level']);
+ } // END - if
+
+ // Return the content
+ return $content;
+}
+
+// Filter for redirecting to logout if sql_patches has been installed
+function FILTER_REDIRECT_TO_LOGOUT_SQL_PATCHES () {
+ // Remove this filter
+ unregisterFilter(__FUNCTION__, __LINE__, 'shutdown', __FUNCTION__);
+
+ // Is the element set?
+ if (isset($GLOBALS['ext_load_mode'])) {
+ // Redirect here
+ redirectToUrl('modules.php?module=admin&logout=1&' . $GLOBALS['ext_load_mode'] . '=sql_patches');
+ } // END - if
+
+ // This should not happen!
+ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot auto-logout because no extension load-mode has been set.');
+}
+
+// Filter for auto-activation of a extension
+function FILTER_AUTO_ACTIVATE_EXTENSION ($data) {
+ // Debug message
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $data['ext_name'] . ',isExtensionAlwaysActive()=' . intval(isExtensionAlwaysActive()));
+
+ // Is this extension always activated?
+ if (isExtensionAlwaysActive()) {
+ // Then activate the extension
+ doActivateExtension($data['ext_name']);
+ } // END - if
+
+ // Return the data
+ return $data;
+}
+
+// Filter for solving task given task
+function FILTER_SOLVE_TASK ($data) {
+ // Don't solve anything if no admin!
+ if (!isAdmin()) return $data;
+
+ // Is this a direct task id or array element task_id is found?
+ if (is_int($data)) {
+ // Then solve it...
+ adminSolveTask($data);
+ } elseif ((is_array($data)) && (isset($data['task_id']))) {
+ // Solve it...
+ adminSolveTask($data['task_id']);
+ } else {
+ // Not detectable!
+ debug_report_bug(__FUNCTION__, __LINE__, sprintf("Cannot resolve task. data[%s]=<pre>%s</pre>", gettype($data), print_r($data, true)));
+ }
+
+ // Return the data
+ return $data;