Heacy rewrite/cleanup:
[mailer.git] / inc / filter-functions.php
index 50a4a650459c432c5bc6886650726fc2733613b1..e217428394c3dbff7dbf7b47bc02d19f1bd35640 100644 (file)
@@ -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')) {
@@ -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,6 +187,9 @@ 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');
 
@@ -231,7 +235,7 @@ function registerFilter ($file, $line, $filterName, $filterFunction, $silentAbor
        // 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! file=%s,L=%s,force=%d", $filterName, $filterFunction, basename($file), $line, intval($force)));
                } // END - if
@@ -310,6 +314,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 +327,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 +340,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 +412,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 +431,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]
 ?>