$active) { // Debug message //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Running: name=' . $filterName . ',func=' . $filterFunction . ',active=' . $active); // 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)) { // Should be fixed reportBug(__FUNCTION__, __LINE__, 'filterName=' . $filterName . ',filterFunction=' . $filterFunction . ',active=' . $active . ' - AUTO-UNREGISTERED!'); } // END - if // Call the filter chain //* 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); } // Abort loop? if (isFilterChainAborted()) { // Yes, then abort here break; } // END - if } // END - foreach // Return the filtered content //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'filterName=' . $filterName . ',filterData[]=' . gettype($filterData) . ',returnValue[]=' . gettype($returnValue) . ' - EXIT!'); 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; } } // 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!'); } // Checks whether the filter chain has been aborted function isFilterChainAborted () { // Determine it return ((isset($GLOBALS['filter_chain_interrupted'])) && ($GLOBALS['filter_chain_interrupted'] === TRUE)); } // Interrupts the filter chain by enabling flag 'filter_chain_aborted' function interruptFilterChain () { // Set it $GLOBALS['filter_chain_interrupted'] = TRUE; } // Continues the filter chain by disabling flag 'filter_chain_aborted' function continueFilterChain () { // Set it $GLOBALS['filter_chain_interrupted'] = FALSE; } // [EOF] ?>