X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Ffilter-functions.php;h=50a4a650459c432c5bc6886650726fc2733613b1;hp=38a1262175cebe9c8064ddffc2b91d31cce25815;hb=f2b603aed42bfdf7a94611d7bae71fe3a1048890;hpb=263a089d8a499e0e26d0af9e7aa7639f88b8ca60 diff --git a/inc/filter-functions.php b/inc/filter-functions.php index 38a1262175..50a4a65045 100644 --- a/inc/filter-functions.php +++ b/inc/filter-functions.php @@ -10,15 +10,14 @@ * -------------------------------------------------------------------- * * Kurzbeschreibung : Funktionen fuer Filter-System * * -------------------------------------------------------------------- * - * $Revision:: 1185 $ * - * $Date:: 2009-10-11 04:16:39 +0200 (Sun, 11 Oct 2009) $ * + * $Revision:: $ * + * $Date:: $ * * $Tag:: 0.2.1-FINAL $ * - * $Author:: quix0r $ * - * Needs to be in all Files and every File needs "svn propset * - * svn:keywords Date Revision" (autoprobset!) at least!!!!!! * + * $Author:: $ * * -------------------------------------------------------------------- * * Copyright (c) 2003 - 2009 by Roland Haeder * - * For more information visit: http://www.mxchange.org * + * Copyright (c) 2009 - 2013 by Mailer Developer Team * + * For more information visit: http://mxchange.org * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -46,51 +45,38 @@ function initFilterSystem () { // Is the filter already initialized? if (isset($GLOBALS['filter_init'])) { // Then abort here - debug_report_bug('Filter system already initialized.'); + reportBug(__FUNCTION__, __LINE__, 'Filter system already initialized.'); } // END - if - // Load all saved filers if sql_patches is updated - if (isset($GLOBALS['cache_array']['filter']['filter_name'])) { - // Init dummy array - $filterArray = array( - 'chains' => 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 + // Load all saved filers if ext-sql_patches is updated + if ((isset($GLOBALS['cache_array']['filter']['filter_name'])) && (!isset($GLOBALS['cache_array']['filter']['chains']))) { + // Prepare filter array + prepareFilterArray(); // Mark it as initialized - $GLOBALS['filter_init'] = true; - - // Remove the cache - $GLOBALS['cache_array']['filter'] = $filterArray; + $GLOBALS['filter_init'] = TRUE; } elseif ((!isInstallationPhase()) && (isExtensionInstalledAndNewer('sql_patches', '0.5.9'))) { // Init add $add = ''; - if (getExtensionVersion('sql_patches') >= '0.6.0') $add = ", `filter_counter`"; + if (isExtensionINstalledAndNewer('sql_patches', '0.6.0')) { + $add = ',`filter_counter`'; + } // END - if - // Load all active filers - $result = SQL_QUERY("SELECT - `filter_name`,`filter_function`,`filter_active`".$add." + // Load all filters + $result = sqlQuery('SELECT + `filter_name`, + `filter_function`, + `filter_active` + ' . $add . ' FROM `{?_MYSQL_PREFIX?}_filters` ORDER BY - `filter_id` ASC", __FUNCTION__, __LINE__); + `filter_id` ASC', __FUNCTION__, __LINE__); // Are there entries? - if (SQL_NUMROWS($result) > 0) { + if (!ifSqlHasZeroNums($result)) { // Load all filters - while ($filterArray = SQL_FETCHARRAY($result)) { + while ($filterArray = sqlFetchArray($result)) { // Get filter name and function $filterName = $filterArray['filter_name']; $filterFunction = $filterArray['filter_function']; @@ -99,7 +85,7 @@ ORDER BY $GLOBALS['cache_array']['filter']['counter'][$filterName][$filterFunction] = '0'; // Mark this filter as loaded (from database) - $GLOBALS['cache_array']['filter']['loaded'][$filterName][$filterFunction] = true; + $GLOBALS['cache_array']['filter']['loaded'][$filterName][$filterFunction] = TRUE; // Set this filter $GLOBALS['cache_array']['filter']['chains'][$filterName][$filterFunction] = $filterArray['filter_active']; @@ -113,180 +99,244 @@ ORDER BY } // END - if // Free result - SQL_FREERESULT($result); + sqlFreeResult($result); } // Init filters - registerFilter('init', 'LOAD_CONFIGURATION'); - registerFilter('init', 'INIT_EXTENSIONS'); - registerFilter('init', 'INIT_RANDOMIZER'); - registerFilter('init', 'LOAD_RUNTIME_INCLUDES'); - registerFilter('init', 'INIT_RANDOM_NUMBER'); - registerFilter('init', 'CHECK_SVN_REVISION'); - registerFilter('init', 'RUN_DAILY_RESET'); - 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'); + registerFilter(__FUNCTION__, __LINE__, 'init', 'LOAD_CONFIGURATION'); + registerFilter(__FUNCTION__, __LINE__, 'init', 'INIT_RANDOMIZER'); + registerFilter(__FUNCTION__, __LINE__, 'init', 'LOAD_RUNTIME_INCLUDES'); + registerFilter(__FUNCTION__, __LINE__, 'init', 'INIT_EXTENSIONS'); + registerFilter(__FUNCTION__, __LINE__, 'init', 'INIT_SESSION'); + registerFilter(__FUNCTION__, __LINE__, 'init', 'SET_CURRENT_DATE'); + registerFilter(__FUNCTION__, __LINE__, 'init', 'INIT_RANDOM_NUMBER'); + registerFilter(__FUNCTION__, __LINE__, 'init', 'CHECK_REPOSITORY_REVISION'); + registerFilter(__FUNCTION__, __LINE__, 'init', 'RUN_HOURLY_RESET'); + registerFilter(__FUNCTION__, __LINE__, 'init', 'RUN_DAILY_RESET'); + registerFilter(__FUNCTION__, __LINE__, 'init', 'RUN_WEEKLY_RESET'); + registerFilter(__FUNCTION__, __LINE__, 'init', 'RUN_MONTHLY_RESET'); + registerFilter(__FUNCTION__, __LINE__, 'init', 'TRIGGER_SENDING_POOL'); + // @TODO Remove this forced removal after a year or so + unregisterFilter(__FUNCTION__, __LINE__, 'init', 'DETERMINE_USERNAME', TRUE); + registerFilter(__FUNCTION__, __LINE__, 'init', 'DETERMINE_WHAT_ACTION'); + registerFilter(__FUNCTION__, __LINE__, 'init', 'COUNT_MODULE'); + registerFilter(__FUNCTION__, __LINE__, 'init', 'UPDATE_LOGIN_DATA'); + registerFilter(__FUNCTION__, __LINE__, 'init', 'ACTIVATE_EXCHANGE'); + registerFilter(__FUNCTION__, __LINE__, 'init', 'REDIRECT_WRONG_SERVER_NAME'); + + // Post-initialization + registerFilter(__FUNCTION__, __LINE__, 'post_init', 'DETERMINE_USERNAME'); + + // Page headers - pre-filter (normally, you want to register here) + registerFilter(__FUNCTION__, __LINE__, 'pre_page_header', 'LOAD_PAGE_HEADER'); + + // Page headers - post-filter (normally, you don't want to register here) + //-------------------- LAST FILTER FOR THIS CHAIN! ------------------------ + registerFilter(__FUNCTION__, __LINE__, 'post_page_header', 'FINISH_PAGE_HEADER'); + //-------------------- LAST FILTER FOR THIS CHAIN! ------------------------ + + // 'You are here' navigation - post filter + registerFilter(__FUNCTION__, __LINE__, 'post_youhere_line', 'CALL_HANDLER_LOGIN_FAILTURES'); + registerFilter(__FUNCTION__, __LINE__, 'post_youhere_line', 'HANDLE_HOME_IN_INDEX_SETTING'); // Filters for pre-extension-registration - registerFilter('pre_extension_installed', 'RUN_SQLS'); + registerFilter(__FUNCTION__, __LINE__, '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'); + registerFilter(__FUNCTION__, __LINE__, 'post_extension_installed', 'AUTO_ACTIVATE_EXTENSION'); + registerFilter(__FUNCTION__, __LINE__, 'post_extension_installed', 'SOLVE_TASK'); + registerFilter(__FUNCTION__, __LINE__, 'post_extension_installed', 'LOAD_INCLUDES'); + registerFilter(__FUNCTION__, __LINE__, 'post_extension_installed', 'REMOVE_UPDATES'); + registerFilter(__FUNCTION__, __LINE__, 'post_extension_installed', 'EXTENSION_MARK_INSTALLED'); // Solving tasks - registerFilter('solve_task', 'SOLVE_TASK'); + registerFilter(__FUNCTION__, __LINE__, 'solve_task', 'SOLVE_TASK'); // Loading includes in general - registerFilter('load_includes', 'LOAD_INCLUDES'); + registerFilter(__FUNCTION__, __LINE__, 'load_includes', 'LOAD_INCLUDES'); // Run SQLs - registerFilter('run_sqls', 'RUN_SQLS'); + registerFilter(__FUNCTION__, __LINE__, 'run_sqls', 'RUN_SQLS'); // Admin ACL check - registerFilter('check_admin_acl', 'CHECK_ADMIN_ACL'); + registerFilter(__FUNCTION__, __LINE__, 'check_admin_acl', 'CHECK_ADMIN_ACL'); // Register shutdown filters - registerFilter('shutdown', 'FLUSH_FILTERS'); - registerFilter('shutdown', 'FLUSH_STATS'); - registerFilter('shutdown', 'FLUSH_TEMPLATE_CACHE'); - registerFilter('shutdown', 'FLUSH_OUTPUT'); + registerFilter(__FUNCTION__, __LINE__, 'shutdown', 'FLUSH_FILTERS'); + registerFilter(__FUNCTION__, __LINE__, 'shutdown', 'FLUSH_STATS'); + registerFilter(__FUNCTION__, __LINE__, 'shutdown', 'FLUSH_TEMPLATE_CACHE'); + registerFilter(__FUNCTION__, __LINE__, 'shutdown', 'FLUSH_OUTPUT'); // Compiling code - registerFilter('compile_code', 'COMPILE_CONFIG'); - registerFilter('compile_code', 'COMPILE_EXTENSION'); + registerFilter(__FUNCTION__, __LINE__, 'compile_code', 'COMPILE_CONFIG'); + registerFilter(__FUNCTION__, __LINE__, 'compile_code', 'COMPILE_EXPRESSION_CODE'); // Generic extension update filters - registerFilter('extension_update', 'UPDATE_EXTENSION_DATA'); + registerFilter(__FUNCTION__, __LINE__, 'extension_update', 'UPDATE_EXTENSION_DATA'); + + // Do hourly reset stuff, keep this entry first in this chain: + registerFilter(__FUNCTION__, __LINE__, 'hourly', 'RUN_HOURLY_INCLUDES'); + + // Do daily stuff, keep this entry first in this chain: + registerFilter(__FUNCTION__, __LINE__, 'daily', 'RUN_DAILY_INCLUDES'); + + // Do weekly stuff, keep this entry first in this chain: + registerFilter(__FUNCTION__, __LINE__, 'weekly', 'RUN_WEEKLY_INCLUDES'); - // Do reset stuff, keep this entry first in this chain: - registerFilter('reset', 'RUN_RESET_INCLUDES'); + // Do monthly stuff, keep this entry first in this chain: + registerFilter(__FUNCTION__, __LINE__, 'monthly', 'RUN_MONTHLY_INCLUDES'); // Remove extension - registerFilter('extension_remove', 'REMOVE_EXTENSION'); + registerFilter(__FUNCTION__, __LINE__, 'extension_remove', 'REMOVE_EXTENSION'); // Exclude some users - registerFilter('exclude_users', 'HTML_INCLUDE_USERS'); + registerFilter(__FUNCTION__, __LINE__, 'exclude_users', 'HTML_INCLUDE_USERS'); // Handling of fatal errors - registerFilter('handle_fatal_errors', 'HANDLE_FATAL_ERRORS'); + registerFilter(__FUNCTION__, __LINE__, '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'); + registerFilter(__FUNCTION__, __LINE__, 'page_footer', 'HANDLE_FATAL_ERRORS'); + registerFilter(__FUNCTION__, __LINE__, 'page_footer', 'DISPLAY_COPYRIGHT'); + registerFilter(__FUNCTION__, __LINE__, 'page_footer', 'DISPLAY_PARSING_TIME'); + + // Member login check. Always keep FETCH_USER_DATA as first entry! + registerFilter(__FUNCTION__, __LINE__, 'member_login_check', 'FETCH_USER_DATA'); + + // Admin login + registerFilter(__FUNCTION__, __LINE__, 'do_admin_login_done', 'DO_LOGIN_ADMIN'); + + // Admin mail links + registerFilter(__FUNCTION__, __LINE__, 'generate_admin_mail_links', 'GENERATE_POOL_MAIL_LINKS'); + + // Build mails + registerFilter(__FUNCTION__, __LINE__, 'send_build_mail', 'SEND_BUILD_MAIL'); + + // Handle referral banner click/view + registerFilter(__FUNCTION__, __LINE__, 'handle_click_php', 'HANDLE_REFERRER_BANNER_CLICK'); + registerFilter(__FUNCTION__, __LINE__, 'handle_view_php', 'HANDLE_REFERRER_BANNER_VIEW'); + + // Generic filter to add hidden fields to formulars + registerFilter(__FUNCTION__, __LINE__, 'open_form_fields', 'ADD_INPUT_HIDDEN_SESSION_ID'); } // "Registers" a new filter function -function registerFilter ($filterName, $filterFunction, $silentAbort = true, $force = false, $dry_run = false) { +function registerFilter ($file, $line, $filterName, $filterFunction, $silentAbort = TRUE, $force = FALSE, $isDryRun = FALSE) { // Extend the filter function name - $filterFunction = sprintf("FILTER_%s", strtoupper($filterFunction)); + $filterFunction = 'FILTER_' . strtoupper($filterFunction); + + // Debug message with FILTER_ prefix + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ENTRY: filterName=' . $filterName . ',filterFunction=' . $filterFunction . ',force=' . intval($force) . ',isDryRun=' . intval($isDryRun) . ',file=' . basename($file) . ',line=' . $line . ' - ENTERED!'); // Is that filter already there? - if ((isset($GLOBALS['cache_array']['filter']['chains'][$filterName][$filterFunction])) && ($force === false)) { - // Then abort here - if ($silentAbort === false) { + if ((isset($GLOBALS['cache_array']['filter']['chains'][$filterName][$filterFunction])) && ($force === FALSE)) { + // In installation phase we always want to abort + if (($silentAbort === FALSE) || (isInstallationPhase())) { // Add fatal message - addFatalMessage(__FUNCTION__, __LINE__, sprintf("Filter chain %s has already filter function %s registered!", $filterName, $filterFunction)); + reportBug(__FUNCTION__, __LINE__, sprintf("Filter chain %s has already filter function %s registered! file=%s,L=%s,force=%d", $filterName, $filterFunction, basename($file), $line, intval($force))); } // END - if // Abort here - return false; + return FALSE; } // END - if // Shall we add it? - if ($dry_run === false) { + if ($isDryRun === 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; + logDebugMessage(__FUNCTION__, __LINE__, sprintf("Filter function %s could not be added to filter chain %s. file=%s,L=%s,force=%d", $filterFunction, $filterName, basename($file), $line, intval($force))); + return FALSE; } // END - if // Simply add it to the array - //* DEBUG: */ print __FUNCTION__.': filterName='.$filterName.',filterFunction='.$filterFunction.'
'; + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'REGISTER: filterName=' . $filterName . ',filterFunction=' . $filterFunction . ',force=' . intval($force) . ',file=' . basename($file) . ',line=' . $line); $GLOBALS['cache_array']['filter']['chains'][$filterName][$filterFunction] = 'A'; $GLOBALS['cache_array']['filter']['counter'][$filterName][$filterFunction] = '0'; } // END - if + + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ENTRY: filterName=' . $filterName . ',filterFunction=' . $filterFunction . ',force=' . intval($force) . ',isDryRun=' . intval($isDryRun) . ',file=' . basename($file) . ',line=' . $line . ' - EXIT!'); + + // Worked + return TRUE; } // "Unregisters" a filter from the given chain -function unregisterFilter ($filterName, $filterFunction, $force = false, $dry_run = false) { +function unregisterFilter ($file, $line, $filterName, $filterFunction, $force = FALSE, $isDryRun = FALSE) { + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'file=' . $file . ',line=' . $line . ',filterName=' . $filterName . ',filterFunction=' . $filterFunction . ',force=' . intval($force) . ',isDryRun=' . intval($isDryRun) . ' - ENTERED!'); + // 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)); + $filterFunction = 'FILTER_' . strtoupper($filterFunction); } // END - if // Is that filter there? - if ((!isset($GLOBALS['cache_array']['filter']['chains'][$filterName][$filterFunction])) && ($force === false)) { + 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; + logDebugMessage(__FUNCTION__, __LINE__, sprintf('Filter function %s cannot be unregistered from filter %s.', $filterFunction, $filterName)); + return FALSE; } // END - if // Shall we remove? (default, not while just showing an extension removal) - if ($dry_run === false) { + if (($isDryRun === FALSE) && (isset($GLOBALS['cache_array']['filter']['chains'][$filterName][$filterFunction]))) { // Mark for filter removal - //* DEBUG: */ print __FUNCTION__.': filterName='.$filterName.',filterFunction='.$filterFunction.'
'; + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'file=' . $file . ',line=' . $line . ',filterName=' . $filterName . ',filterFunction=' . $filterFunction . ' - REMOVE!'); $GLOBALS['cache_array']['filter']['chains'][$filterName][$filterFunction] = 'R'; } // END - if + + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'file=' . $file . ',line=' . $line . ',filterName=' . $filterName . ',filterFunction=' . $filterFunction . ',force=' . intval($force) . ',isDryRun=' . intval($isDryRun) . ' - EXIT!'); + + // Worked + return TRUE; } -// "Runs" the given filters, data is optional and can be any type of data -function runFilterChain ($filterName, $data = null) { +// "Runs" the given filters, filterData is optional and can be any type of data +function runFilterChain ($filterName, $filterData = NULL) { + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'filterName=' . $filterName . ',filterData[]=' . gettype($filterData) . ' - ENTERED!'); + // 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!'); + // Log not found filters in debug-mode + if (isDebugModeEnabled()) { + // Log it away... + logDebugMessage(__FUNCTION__, __LINE__, 'Filter chain ' . $filterName . ' does not exist.'); + } // END - if // Abort here and return content - return $data; + return $filterData; } // END - if // Default return value - $returnValue = $data; + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'filterName=' . $filterName . ',count()=' . count($GLOBALS['cache_array']['filter']['chains'][$filterName])); + $returnValue = $filterData; // 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}"); + //* 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 the filter active or newly added?? + 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; + // Should be fixed + reportBug(__FUNCTION__, __LINE__, 'filterName=' . $filterName . ',filterFunction=' . $filterFunction . ' - AUTO-UNREGISTERED!'); } // END - if // Call the filter chain - //* DEBUG: */ print $filterName.'/'.$filterFunction.',[]='.gettype($returnValue).'
'; + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $filterName . '/' . $filterFunction . ',[]=' . gettype($returnValue) . ' - CALLING!'); $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}"); + logDebugMessage(__FUNCTION__, __LINE__, 'Skipped: name=' . $filterName . ',func=' . $filterFunction . ',active=' . $active); } } // END - foreach // Return the filtered content + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'filterName=' . $filterName . ',filterData[]=' . gettype($filterData) . ',returnValue[]=' . gettype($returnValue) . ' - EXIT!'); return $returnValue; } @@ -302,5 +352,71 @@ function countFilterUsage ($filterName, $filterFunction) { } } +// Prepares the filter array for usage +function prepareFilterArray () { + // Abort here if array is absend (e.g. not cached) + if (!isset($GLOBALS['cache_array']['filter']['filter_name'])) { + // Abort silently + return FALSE; + } // END - if + + // Init dummy array + $filterArray = array( + 'chains' => 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 + + // Remove the cache + $GLOBALS['cache_array']['filter'] = $filterArray; +} + +/** + * Loads filter for given extension if present. This function will silently + * ignore absent filter files. + * + * @param $ext_name Name of extension + * @return void + */ +function loadExtensionFilters ($ext_name) { + // Debug message + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - ENTERED!'); + + // Is there a cache entry? + if (!isset($GLOBALS[__FUNCTION__][$ext_name])) { + // Default is not found + $GLOBALS[__FUNCTION__][$ext_name] = FALSE; + + // Construct include file name + $incFileName = sprintf("inc/filter/%s_filter.php", $ext_name); + + // Is the include file readable? + if (isIncludeReadable($incFileName)) { + // Load the include file + loadIncludeOnce($incFileName); + + // Mark the file as loaded + $GLOBALS[__FUNCTION__][$ext_name] = TRUE; + } elseif (isDebugModeEnabled()) { + // Log missing file + //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Filter include file ' . $incFileName . ' for extension ' . $ext_name . ' is missing.'); + } + } // END - if + + // Debug message + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',result=' . intval($GLOBALS[__FUNCTION__][$ext_name]) . ' - EXIT!'); +} + // [EOF] ?>