array(),
'loaded' => array(),
'counter' => array()
);
// Found in cache so rewrite the array
foreach ($GLOBALS['cache_array']['filter']['filter_name'] as $idx => $filterName) {
// Get filter function
$filterFunction = $GLOBALS['cache_array']['filter']['filter_function'][$idx];
// Add the element with mapped index
$filterArray['counter'][$filterName][$filterFunction] = $GLOBALS['cache_array']['filter']['filter_counter'][$idx];
$filterArray['loaded'][$filterName][$filterFunction] = true;
$filterArray['chains'][$filterName][$filterFunction] = $GLOBALS['cache_array']['filter']['filter_active'][$idx];
} // END - foreach
// Mark it as initialized
$GLOBALS['filter_init'] = true;
// Remove the cache
$GLOBALS['cache_array']['filter'] = $filterArray;
} elseif ((!isInstallationPhase()) && (isExtensionInstalledAndNewer('sql_patches', '0.5.9'))) {
// Init add
$add = '';
if (getExtensionVersion('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", __FUNCTION__, __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['cache_array']['filter']['counter'][$filterName][$filterFunction] = 0;
// Mark this filter as loaded (from database)
$GLOBALS['cache_array']['filter']['loaded'][$filterName][$filterFunction] = true;
// Set this filter
$GLOBALS['cache_array']['filter']['chains'][$filterName][$filterFunction] = $filterArray['filter_active'];
// Is the array element for counter there?
if (isset($filterArray['filter_counter'])) {
// Then use this value!
$GLOBALS['cache_array']['filter']['counter'][$filterName][$filterFunction] = $filterArray['filter_counter'];
} // END - if
} // END - while
} // END - if
// Free result
SQL_FREERESULT($result);
}
// Init filters
registerFilter('init', 'LOAD_CONFIGURATION');
registerFilter('init', 'INIT_EXTENSIONS');
registerFilter('init', 'LOAD_RUNTIME_INCLUDES');
registerFilter('init', 'CHECK_SVN_REVISION');
registerFilter('init', 'RUN_DAILY_RESET');
registerFilter('init', 'INIT_RANDOMIZER');
registerFilter('init', 'INIT_RANDOM_NUMBER');
registerFilter('init', 'TRIGGER_SENDING_POOL');
registerFilter('init', 'DETERMINE_USERNAME');
registerFilter('init', 'DETERMINE_WHAT_ACTION');
registerFilter('init', 'COUNT_MODULE');
registerFilter('init', 'UPDATE_LOGIN_DATA');
registerFilter('init', 'ACTIVATE_EXCHANGE');
// Login failures handler
registerFilter('post_youhere_line', 'CALL_HANDLER_LOGIN_FAILTURES');
// Filters for pre-extension-registration
registerFilter('pre_extension_installed', 'RUN_SQLS');
// Filters for post-extension-registration
registerFilter('post_extension_installed', 'AUTO_ACTIVATE_EXTENSION');
registerFilter('post_extension_installed', 'SOLVE_TASK');
registerFilter('post_extension_installed', 'LOAD_INCLUDES');
registerFilter('post_extension_installed', 'REMOVE_UPDATES');
// Solving tasks
registerFilter('solve_task', 'SOLVE_TASK');
// Loading includes in general
registerFilter('load_includes', 'LOAD_INCLUDES');
// Run SQLs
registerFilter('run_sqls', 'RUN_SQLS');
// Admin ACL check
registerFilter('check_admin_acl', 'CHECK_ADMIN_ACL');
// Register shutdown filters
registerFilter('shutdown', 'FLUSH_FILTERS');
registerFilter('shutdown', 'FLUSH_STATS');
registerFilter('shutdown', 'FLUSH_OUTPUT');
// Compiling code
registerFilter('compile_code', 'COMPILE_CONFIG');
registerFilter('compile_code', 'COMPILE_EXTENSION');
// Generic extension update filters
registerFilter('extension_update', 'UPDATE_EXTENSION_DATA');
// Do reset stuff, keep this entry first in this chain:
registerFilter('reset', 'RUN_RESET_INCLUDES');
// Remove extension
registerFilter('extension_remove', 'REMOVE_EXTENSION');
// Exclude some users
registerFilter('exclude_users', 'HTML_INCLUDE_USERS');
// Handling of fatal errors
registerFilter('handle_fatal_errors', 'HANDLE_FATAL_ERRORS');
// Page footer filters
registerFilter('page_footer', 'HANDLE_FATAL_ERRORS');
registerFilter('page_footer', 'DISPLAY_COPYRIGHT');
registerFilter('page_footer', 'DISPLAY_PARSING_TIME');
}
// "Registers" a new filter function
function registerFilter ($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['cache_array']['filter']['chains'][$filterName][$filterFunction])) && ($force === false)) {
// Then abort here
if ($silentAbort === false) {
// Add fatal message
addFatalMessage(__FUNCTION__, __LINE__, sprintf("Filter chain %s has already filter function %s registered!", $filterName, $filterFunction));
} // END - if
// Abort here
return false;
} // END - if
// Shall we add it?
if ($dry_run === false) {
// Is the function there?
if (!function_exists($filterFunction)) {
// Then abort here
addFatalMessage(__FUNCTION__, __LINE__, sprintf("Filter function %s could not be added to filter chain %s.", $filterFunction, $filterName));
return false;
} // END - if
// Simply add it to the array
//* DEBUG: */ print __FUNCTION__.': filterName='.$filterName.',filterFunction='.$filterFunction.'
';
$GLOBALS['cache_array']['filter']['chains'][$filterName][$filterFunction] = 'A';
$GLOBALS['cache_array']['filter']['counter'][$filterName][$filterFunction] = 0;
} // END - if
}
// "Unregisters" a filter from the given chain
function unregisterFilter ($filterName, $filterFunction, $force = false, $dry_run = false) {
// Extend the filter function name only if not loaded from database
if (!isset($GLOBALS['cache_array']['filter']['loaded'][$filterName][$filterFunction])) {
$filterFunction = sprintf("FILTER_%s", strtoupper($filterFunction));
} // END - if
// Is that filter there?
if ((!isset($GLOBALS['cache_array']['filter']['chains'][$filterName][$filterFunction])) && ($force === false)) {
// Not found, so abort here
addFatalMessage(__FUNCTION__, __LINE__, 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 === false) {
// Mark for filter removal
//* DEBUG: */ print __FUNCTION__.': filterName='.$filterName.',filterFunction='.$filterFunction.'
';
$GLOBALS['cache_array']['filter']['chains'][$filterName][$filterFunction] = 'R';
} // END - if
}
// "Runs" the given filters, data is optional and can be any type of data
function runFilterChain ($filterName, $data = null) {
// Is that filter chain there?
if (!isset($GLOBALS['cache_array']['filter']['chains'][$filterName])) {
// We should find all these non-existing filter chains
//* Only for tracking: */ if ($filterName != 'sql_admin_extra_data') {
//* Only for tracking: */ debug_report_bug('Filter chain ' . $filterName . ' not found!');
//* Only for tracking: */ }
/* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Filter chain ' . $filterName . ' not found!');
// Abort here and return content
return $data;
} // END - if
// Default return value
$returnValue = $data;
// Then run all filters
foreach ($GLOBALS['cache_array']['filter']['chains'][$filterName] as $filterFunction => $active) {
// Debug message
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "Running: name={$filterName},func={$filterFunction},active={$active}");
// Is the filter active?
if (($active == 'Y') || ($active == 'A') || ((in_array($filterName, array('shutdown','extension_remove','post_extension_run_sql'))) && ($active == 'R'))) {
// Is this filter there?
if (!function_exists($filterFunction)) {
// Unregister it
unregisterFilter($filterName, $filterFunction);
// Skip this entry
continue;
} // END - if
// Call the filter chain
//* DEBUG: */ print $filterName.'/'.$filterFunction.',[]='.gettype($returnValue).'
';
$returnValue = call_user_func_array($filterFunction, array($returnValue));
// Update usage counter
countFilterUsage($filterName, $filterFunction);
} elseif (isDebugModeEnabled()) {
// Debug message
logDebugMessage(__FUNCTION__, __LINE__, "Skipped: name={$filterName},func={$filterFunction},active={$active}");
}
} // END - foreach
// Return the filtered content
return $returnValue;
}
// Count the filter usage
function countFilterUsage ($filterName, $filterFunction) {
// Is it there?
if (isset($GLOBALS['cache_array']['filter']['counter'][$filterName][$filterFunction])) {
// Yes, then increase
$GLOBALS['cache_array']['filter']['counter'][$filterName][$filterFunction]++;
} else {
// No, then create
$GLOBALS['cache_array']['filter']['counter'][$filterName][$filterFunction] = 1;
}
}
// [EOF]
?>