X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Ffilter-functions.php;h=4e19d0980aa78d2ba0a3b655a6eb8f27897c585d;hp=a15900887ca212241ca460c020c74a2ed594b826;hb=f23709a2e9afa25b4bf3b732155fec667fbc1a2a;hpb=84dd2fecd5b013cf6f4c4e7dee8b0d470b6a5f5c diff --git a/inc/filter-functions.php b/inc/filter-functions.php index a15900887c..4e19d0980a 100644 --- a/inc/filter-functions.php +++ b/inc/filter-functions.php @@ -16,7 +16,7 @@ * $Author:: $ * * -------------------------------------------------------------------- * * Copyright (c) 2003 - 2009 by Roland Haeder * - * Copyright (c) 2009 - 2012 by Mailer Developer Team * + * 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 * @@ -55,7 +55,7 @@ function initFilterSystem () { // Mark it as initialized $GLOBALS['filter_init'] = TRUE; - } elseif ((!isInstallationPhase()) && (isExtensionInstalledAndNewer('sql_patches', '0.5.9'))) { + } elseif ((!isInstaller()) && (isExtensionInstalledAndNewer('sql_patches', '0.5.9'))) { // Init add $add = ''; if (isExtensionINstalledAndNewer('sql_patches', '0.6.0')) { @@ -63,7 +63,7 @@ function initFilterSystem () { } // END - if // Load all filters - $result = SQL_QUERY('SELECT + $result = sqlQuery('SELECT `filter_name`, `filter_function`, `filter_active` @@ -74,9 +74,9 @@ ORDER BY `filter_id` ASC', __FUNCTION__, __LINE__); // Are there entries? - if (!SQL_HASZERONUMS($result)) { + 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 +99,7 @@ ORDER BY } // END - if // Free result - SQL_FREERESULT($result); + sqlFreeResult($result); } // Init filters @@ -115,6 +115,7 @@ ORDER BY 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', 'RUN_YEARLY_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); @@ -186,12 +187,12 @@ ORDER BY // Do monthly stuff, keep this entry first in this chain: registerFilter(__FUNCTION__, __LINE__, 'monthly', 'RUN_MONTHLY_INCLUDES'); + // Do yearly stuff, keep this entry first in this chain: + registerFilter(__FUNCTION__, __LINE__, 'yearly', 'RUN_YEARLY_INCLUDES'); + // Remove extension registerFilter(__FUNCTION__, __LINE__, 'extension_remove', 'REMOVE_EXTENSION'); - // Exclude some users - registerFilter(__FUNCTION__, __LINE__, 'exclude_users', 'HTML_INCLUDE_USERS'); - // Handling of fatal errors registerFilter(__FUNCTION__, __LINE__, 'handle_fatal_errors', 'HANDLE_FATAL_ERRORS'); @@ -221,19 +222,19 @@ ORDER BY } // "Registers" a new filter function -function registerFilter ($F, $L, $filterName, $filterFunction, $silentAbort = TRUE, $force = FALSE, $isDryRun = FALSE) { +function registerFilter ($file, $line, $filterName, $filterFunction, $silentAbort = TRUE, $force = FALSE, $isDryRun = FALSE) { // Extend the filter function name $filterFunction = 'FILTER_' . strtoupper($filterFunction); // Debug message with FILTER_ prefix - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ENTRY: filterName=' . $filterName . ',filterFunction=' . $filterFunction . ',force=' . intval($force) . ',isDryRun=' . intval($isDryRun) . ',F=' . basename($F) . ',L=' . $L . ' - ENTERED!'); + //* 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)) { // In installation phase we always want to abort - if (($silentAbort === FALSE) || (isInstallationPhase())) { + if (($silentAbort === FALSE) || (isInstaller())) { // Add fatal message - reportBug(__FUNCTION__, __LINE__, sprintf("Filter chain %s has already filter function %s registered! F=%s,L=%s,force=%d", $filterName, $filterFunction, basename($F), $L, intval($force))); + 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 @@ -245,25 +246,25 @@ function registerFilter ($F, $L, $filterName, $filterFunction, $silentAbort = TR // Is the function there? if (!function_exists($filterFunction)) { // Then abort here - logDebugMessage(__FUNCTION__, __LINE__, sprintf("Filter function %s could not be added to filter chain %s. F=%s,L=%s,force=%d", $filterFunction, $filterName, basename($F), $L, intval($force))); + 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: */ logDebugMessage(__FUNCTION__, __LINE__, 'REGISTER: filterName=' . $filterName . ',filterFunction=' . $filterFunction . ',force=' . intval($force) . ',F=' . basename($F) . ',L=' . $L); + //* 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) . ',F=' . basename($F) . ',L=' . $L . ' - EXIT!'); + //* 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 ($F, $L, $filterName, $filterFunction, $force = FALSE, $isDryRun = FALSE) { - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'F=' . $F . ',L=' . $L . ',filterName=' . $filterName . ',filterFunction=' . $filterFunction . ',force=' . intval($force) . ',isDryRun=' . intval($isDryRun) . ' - ENTERED!'); +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])) { @@ -280,11 +281,11 @@ function unregisterFilter ($F, $L, $filterName, $filterFunction, $force = FALSE, // Shall we remove? (default, not while just showing an extension removal) if (($isDryRun === FALSE) && (isset($GLOBALS['cache_array']['filter']['chains'][$filterName][$filterFunction]))) { // Mark for filter removal - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'F=' . $F . ',L=' . $L . ',filterName=' . $filterName . ',filterFunction=' . $filterFunction . ' - REMOVE!'); + //* 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__, 'F=' . $F . ',L=' . $L . ',filterName=' . $filterName . ',filterFunction=' . $filterFunction . ',force=' . intval($force) . ',isDryRun=' . intval($isDryRun) . ' - EXIT!'); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'file=' . $file . ',line=' . $line . ',filterName=' . $filterName . ',filterFunction=' . $filterFunction . ',force=' . intval($force) . ',isDryRun=' . intval($isDryRun) . ' - EXIT!'); // Worked return TRUE; @@ -310,6 +311,9 @@ function runFilterChain ($filterName, $filterData = NULL) { //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'filterName=' . $filterName . ',count()=' . count($GLOBALS['cache_array']['filter']['chains'][$filterName])); $returnValue = $filterData; + // Remove any existing flag(s) + unset($GLOBALS['filter_chain_aborted']); + // Then run all filters foreach ($GLOBALS['cache_array']['filter']['chains'][$filterName] as $filterFunction => $active) { // Debug message @@ -320,7 +324,7 @@ function runFilterChain ($filterName, $filterData = NULL) { // Is this filter there? if (!function_exists($filterFunction)) { // Should be fixed - reportBug(__FUNCTION__, __LINE__, 'filterName=' . $filterName . ',filterFunction=' . $filterFunction . ' - AUTO-UNREGISTERED!'); + reportBug(__FUNCTION__, __LINE__, 'filterName=' . $filterName . ',filterFunction=' . $filterFunction . ',active=' . $active . ' - AUTO-UNREGISTERED!'); } // END - if // Call the filter chain @@ -333,6 +337,12 @@ function runFilterChain ($filterName, $filterData = NULL) { // Debug message logDebugMessage(__FUNCTION__, __LINE__, 'Skipped: name=' . $filterName . ',func=' . $filterFunction . ',active=' . $active); } + + // Abort loop? + if (isFilterChainAborted()) { + // Yes, then abort here + break; + } // END - if } // END - foreach // Return the filtered content @@ -399,7 +409,7 @@ function loadExtensionFilters ($ext_name) { $GLOBALS[__FUNCTION__][$ext_name] = FALSE; // Construct include file name - $incFileName = sprintf("inc/filter/%s_filter.php", $ext_name); + $incFileName = sprintf('inc/filter/%s_filter.php', $ext_name); // Is the include file readable? if (isIncludeReadable($incFileName)) { @@ -418,5 +428,11 @@ function loadExtensionFilters ($ext_name) { //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',result=' . intval($GLOBALS[__FUNCTION__][$ext_name]) . ' - EXIT!'); } +// Checks whether the filter chain has been aborted +function isFilterChainAborted () { + // Determine it + return ((isset($GLOBALS['filter_chain_aborted'])) && ($GLOBALS['filter_chain_aborted'] === TRUE)); +} + // [EOF] ?>