- $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php";
- require($INC);
-}
-
-// Init "generic filter system"
-function INIT_FILTER_SYSTEM () {
- // Is the filter already initialized?
- if ((isset($GLOBALS['filters']['chains'])) && (is_array($GLOBALS['filters']['chains']))) {
- // Then abort here
- addFatalMessage(getMessage('FILTER_FAILED_ALREADY_INIT'));
- return false;
- } // END - if
-
- // Init the filter system (just some ideas)
- $GLOBALS['filters']['chains'] = array(
- // Filters for pre-init phase
- 'preinit' => array(),
- // Filters for post-init phase
- 'postinit' => array(),
- // Filters for shutdown phase
- 'shutdown' => array()
- );
-
- // Init loaded filters and counter
- $GLOBALS['filters']['loaded'] = array();
- $GLOBALS['filters']['counter'] = array();
-
- // Load all saved filers if sql_patches is updated
- if (GET_EXT_VERSION("sql_patches") >= "0.5.9") {
- // Init add
- $ADD = "";
- if (GET_EXT_VERSION("sql_patches") >= "0.6.0") $ADD = ", `filter_counter`";
-
- // Load all active filers
- $result = SQL_QUERY("SELECT `filter_name`, `filter_function`, `filter_active`".$ADD."
-FROM `{!_MYSQL_PREFIX!}_filters`
-ORDER BY `filter_id` ASC", __FILE__, __LINE__);
-
- // Are there entries?
- if (SQL_NUMROWS($result) > 0) {
- // Load all filters
- while ($filterArray = SQL_FETCHARRAY($result)) {
- // Get filter name and function
- $filterName = $filterArray['filter_name'];
- $filterFunction = $filterArray['filter_function'];
-
- // Set counter to default
- $GLOBALS['filters']['counter'][$filterName][$filterFunction] = 0;
-
- // Mark this filter as loaded (from database)
- $GLOBALS['filters']['loaded'][$filterName][$filterFunction] = true;
-
- // Set this filter
- $GLOBALS['filters']['chains'][$filterName][$filterFunction] = $filterArray['filter_active'];
-
- // Is the array element for counter there?
- if (isset($filterArray['filter_counter'])) {
- // Then use this value!
- $GLOBALS['filters']['counter'][$filterName][$filterFunction] = $filterArray['filter_counter'];
- } // END - if
- } // END - while
- } // END - if
-
- // Free result
- SQL_FREERESULT($result);
- } // END - if
-
- // 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
- REGISTER_FILTER('pre_extension_installed', 'RUN_SQLS');
-
- // Filters for post-extension-registration
- REGISTER_FILTER('post_extension_installed', 'AUTO_ACTIVATE_EXTENSION');
- REGISTER_FILTER('post_extension_installed', 'SOLVE_TASK');
- REGISTER_FILTER('post_extension_installed', 'LOAD_INCLUDES');
-
- // Solving tasks
- REGISTER_FILTER('solve_task', 'SOLVE_TASK');
-
- // Loading includes in general
- REGISTER_FILTER('load_includes', 'LOAD_INCLUDES');
-
- // 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, $dry_run = false) {
- // Extend the filter function name
- $filterFunction = sprintf("FILTER_%s", strtoupper($filterFunction));
-
- // Is that filter already there?
- if ((isset($GLOBALS['filters']['chains'][$filterName][$filterFunction])) && (!$force)) {
- // Then abort here
- if (!$silentAbort) {
- addFatalMessage(getMessage('FILTER_FAILED_ALREADY_ADDED'), array($filterFunction, $filterName));
- } // END - if
-
- // Abort here
- return false;
- } // END - if
-
- // Is the function there?
- if (!function_exists($filterFunction)) {
- // Then abort here
- addFatalMessage(getMessage('FILTER_FAILED_NOT_FOUND'), array($filterFunction, $filterName));
- return false;
- } // END - if
-
- // Shall we add it?
- if (!$dry_run) {
- // Simply add it to the array
- $GLOBALS['filters']['chains'][$filterName][$filterFunction] = "Y";
- $GLOBALS['filters']['counter'][$filterName][$filterFunction] = 0;
- } // END - if
-}
-
-// "Unregisters" a filter from the given chain
-function UNREGISTER_FILTER ($filterName, $filterFunction, $force = false, $dry_run = false) {
- // Extend the filter function name only if not loaded from database
- if (!isset($GLOBALS['filters']['loaded'][$filterName][$filterFunction])) {
- $filterFunction = sprintf("FILTER_%s", strtoupper($filterFunction));
- } // END - if
-
- // Is that filter there?
- if ((!isset($GLOBALS['filters']['chains'][$filterName][$filterFunction])) && (!$force)) {
- // Not found, so abort here
- addFatalMessage(getMessage('FILTER_FAILED_NOT_REMOVED'), array($filterFunction, $filterName));
- return false;
- } // END - if
-
- // Shall we remove? (default, not while just showing an extension removal)
- if (!$dry_run) {
- // Mark for filter removal
- $GLOBALS['filters']['chains'][$filterName][$filterFunction] = "R";
- unset($GLOBALS['filters']['counter'][$filterName][$filterFunction]);
- } // END - if
-}
-
-// "Runs" the given filters, data is optional and can be any type of data
-function RUN_FILTER ($filterName, $data = null, $silentAbort = true) {
- // Is that filter chain there?
- if (!isset($GLOBALS['filters']['chains'][$filterName])) {
- // Then abort here (quick'N'dirty hack)
- if ((!$silentAbort) && (defined('FILTER_FAILED_NO_FILTER_FOUND'))) {
- // Add fatal message
- addFatalMessage(getMessage('FILTER_FAILED_NO_FILTER_FOUND'), $filterName);
- } // END - if
-
- // Abort here
- return false;
- } // END - if
-
- // Default return value
- $returnValue = $data;
-
- // Then run all filters
- foreach ($GLOBALS['filters']['chains'][$filterName] as $filterFunction=>$active) {
- // Debug message
- //* DEBUG: */ echo __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): name={$filterName},func={$filterFunction},active={$active}<br />\n";
-
- // Is the filter active?
- if ($active == "Y") {
- // Is this filter there?
- if (!function_exists($filterFunction)) {
- // Unregister it
- UNREGISTER_FILTER($filterName, $filterFunction);
-
- // Skip this entry
- continue;
- } // END - if
-
- // Call the filter chain
- $returnValue = call_user_func_array($filterFunction, array($returnValue));
-
- // Update usage counter
- $GLOBALS['filters']['counter'][$filterName][$filterFunction]++;
- } // END - if
- } // END - foreach
-
- // Return the filtered content
- return $returnValue;
-}
-
-// -----------------------------------------------------------------------------
-// Generic filter functions we always need
-// -----------------------------------------------------------------------------