]> git.mxchange.org Git - mailer.git/blobdiff - inc/filters.php
Mailer project rwritten:
[mailer.git] / inc / filters.php
index 38193a20596f899e1c675581fb71d02c1c7540d3..9a4870c3c5c8cef55537d50ea45001247e43ebf1 100644 (file)
@@ -51,11 +51,12 @@ function FILTER_FLUSH_FILTERS () {
                reportBug(__FUNCTION__, __LINE__, 'No database link is up. Cannot flush filters.');
        } elseif ((isInstallationPhase()) && (!SQL_IS_LINK_UP())) {
                // If the link is not up in installation phase, skip flushing filters
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot flush filters: No link is up.');
                return;
        }
 
-       // Is the extension ext-sql_patches updated and not in installation phase?
-       if ((!isInstallationPhase()) && ((!isExtensionInstalled('sql_patches')) || (isExtensionInstalledAndOlder('sql_patches', '0.5.9')))) {
+       // Is the extension ext-sql_patches updated?
+       if (((!isExtensionInstalled('sql_patches')) || (isExtensionInstalledAndOlder('sql_patches', '0.5.9'))) && (!isInstallationPhase())) {
                // Log only in debug mode
                if (isDebugModeEnabled()) {
                        logDebugMessage(__FUNCTION__, __LINE__, 'Cannot flush filters, ext-sql_patches might be missing. isExtensionInstalled()=' . intval(isExtensionInstalled('sql_patches')) . ',isExtensionInstalledAndOlder()=' . intval(isExtensionInstalledAndOlder('sql_patches', '0.5.9')));
@@ -78,21 +79,30 @@ function FILTER_FLUSH_FILTERS () {
                // Walk through all filters
                foreach ($filterArray as $filterFunction => $active) {
                        // Is this filter loaded?
-                       //* DEBUG: */ debugOutput('FOUND:'.$filterName.'/'.$filterFunction.'='.$active);
+                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'FOUND:'.$filterName.'/'.$filterFunction.'='.$active);
                        if (((!isset($GLOBALS['cache_array']['filter']['loaded'][$filterName][$filterFunction])) && ($active != 'R')) || ($active == 'A')) {
-                               // Add this filter (all filters are active by default)
-                               //* DEBUG: */ debugOutput('ADD:'.$filterName.'/'.$filterFunction);
-                               $insertSQL .= sprintf("('%s','%s','Y'),", $filterName, $filterFunction);
-                               $inserted++;
+                               // Is this filter already in database?
+                               if (countSumTotalData($filterFunction, 'filters', 'filter_name', 'filter_function', TRUE, sprintf(" AND `filter_name`='%s'", SQL_ESCAPE($filterName))) == 0) {
+                                       // Add this filter (all filters are active by default)
+                                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ADD:'.$filterName.'/'.$filterFunction);
+                                       $insertSQL .= sprintf("('%s','%s','Y'),", $filterName, $filterFunction);
+                                       $inserted++;
+                               } elseif (isDebugModeEnabled()) {
+                                       // Log already registered filters
+                                       logDebugMessage(__FUNCTION__, __LINE__, 'Already registered: filterName=' . $filterName . ',filterFunction=' . $filterFunction . ',active=' . $active);
+                               }
                        } elseif ($active == 'R') {
                                // Remove this filter
-                               //* DEBUG: */ debugOutput('REMOVE:'.$filterName.'/'.$filterFunction);
+                               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'REMOVE:'.$filterName.'/'.$filterFunction);
                                $removeSQL .= sprintf(" (`filter_name`='%s' AND `filter_function`='%s') OR", $filterName, $filterFunction);
                                $removed++;
                        }
                } // END - foreach
        } // END - foreach
 
+       // Debug message
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'inserted=' . $inserted . ',removed=' . $removed . ' - AFTER COLLECTION');
+
        // Something has been added?
        if ($inserted > 0) {
                // Finish SQL command and add it
@@ -147,21 +157,6 @@ function FILTER_CALL_HANDLER_LOGIN_FAILTURES ($filterData) {
        return $content;
 }
 
-// Filter for redirecting to logout if ext-sql_patches has been installed
-function FILTER_REDIRECT_TO_LOGOUT_SQL_PATCHES () {
-       // Remove this filter
-       unregisterFilter(__FUNCTION__, __LINE__, 'shutdown', __FUNCTION__);
-
-       // Is the element set?
-       if (isset($GLOBALS['ext_load_mode'])) {
-               // Redirect here
-               redirectToUrl('modules.php?module=admin&logout=1&' . $GLOBALS['ext_load_mode'] . '=sql_patches');
-       } // END - if
-
-       // This should not happen!
-       logDebugMessage(__FUNCTION__, __LINE__, 'Cannot auto-logout because no extension load-mode has been set.');
-}
-
 // Filter for auto-activation of a extension
 function FILTER_AUTO_ACTIVATE_EXTENSION ($filterData) {
        // Debug message
@@ -271,8 +266,8 @@ function FILTER_RUN_SQLS ($filterData) {
 
                                // Is there still a query left?
                                if (!empty($sql)) {
-                                       // Is there an "ALTER TABLE" command?
-                                       if (substr(strtolower($sql), 0, 11) == 'alter table') {
+                                       // Is there an "ALTER TABLE" command? Exclude installation phase here as it would cause this query to fail
+                                       if ((substr(strtolower($sql), 0, 11) == 'alter table') && (!isset($filterData['ext_installing']))) {
                                                // Analyse the alteration command
                                                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Alterting table: ' . $sql . ',enable_codes=' . intval($filterData['enable_codes']));
                                                SQL_ALTER_TABLE($sql, __FUNCTION__, __LINE__, $filterData['enable_codes']);
@@ -295,9 +290,6 @@ function FILTER_RUN_SQLS ($filterData) {
        // Debug message
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '- Left!');
 
-       // Clear any SQL queries
-       //initSqls();
-
        // Return counter
        return $count;
 }
@@ -355,6 +347,9 @@ function FILTER_INIT_RANDOMIZER () {
        // Take a prime number which is long (if you know a longer one please try it out!)
        setConfigEntry('_PRIME', 591623);
 
+       // Initialize array with all allowed chars
+       $GLOBALS['_abc'] = explode(',', 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,1,2,3,4,6,7,8,9,-,+,_,/,.');
+
        // Only execute this filter if installed
        if ((!isInstalled()) || (!isExtensionInstalledAndNewer('other', '0.2.5'))) {
                // Set missing entry
@@ -367,9 +362,6 @@ function FILTER_INIT_RANDOMIZER () {
 
        // Simply init the randomizer with seed and _ADD value
        mt_srand(generateSeed() + getConfig('_ADD'));
-
-       // Initialize array with all allowed chars
-       $GLOBALS['_abc'] = explode(',', 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,1,2,3,4,6,7,8,9,-,+,_,/,.');
 }
 
 // Filter for removing updates
@@ -562,8 +554,8 @@ function FILTER_COMPILE_EXPRESSION_CODE ($filterData) {
                } // END - foreach
        } // END - if
 
-       // Is there non-HTML mode?
-       if (!isHtmlOutputMode()) {
+       // Is there non-HTML/AJAX mode?
+       if ((!isHtmlOutputMode()) && (!isAjaxOutputMode())) {
                $filterData = decodeEntities($filterData);
        } // END - if
 
@@ -669,8 +661,17 @@ function FILTER_REMOVE_EXTENSION () {
 
 // Filter for flushing the output
 function FILTER_FLUSH_OUTPUT () {
+       // Is this filter called?
+       if (isset($GLOBALS[__FUNCTION__])) {
+               // Abort here
+               reportBug(__FUNCTION__, __LINE__, 'Double call of ' . __FUNCTION__ . ' causes problems with sent headers.');
+       } // END - if
+
+       // Mark this filter as called
+       $GLOBALS[__FUNCTION__] = TRUE;
+
        // Simple, he?
-       outputHtml('');
+       outputHtml();
 }
 
 // Prepares an SQL statement part for HTML mail and/or holiday dependency
@@ -981,7 +982,7 @@ function FILTER_HANDLE_FATAL_ERRORS () {
 // Filter for displaying copyright line
 function FILTER_DISPLAY_COPYRIGHT () {
        // Shall we display the copyright notice?
-       if ((isFullPage()) && ((getConfig('WRITE_FOOTER') == 'Y') || (isInstalling())) && ($GLOBALS['__header_sent'] == 2) && (ifCopyrightFooterEnabled())) {
+       if ((isFullPage()) && ((getWriteFooter() == 'Y') || (isInstalling())) && ($GLOBALS['__header_sent'] == 2) && (ifCopyrightFooterEnabled())) {
                // Backlink enabled?
                if (((isConfigEntrySet('ENABLE_BACKLINK')) && (getConfig('ENABLE_BACKLINK') == 'Y')) || (isInstalling())) {
                        // Copyright with backlink, thanks! :-)
@@ -996,8 +997,8 @@ function FILTER_DISPLAY_COPYRIGHT () {
 // Filter for displaying parsing time
 function FILTER_DISPLAY_PARSING_TIME () {
        // Shall we display the parsing time and number of queries?
-       // 1234                            5                      54    4         5              5       4    4          5543    3                    4432    2                332    2                              21
-       if ((((isExtensionInstalledAndNewer('sql_patches', '0.4.1')) && (getConfig('show_timings') == 'Y') && (isFullPage())) && (!isInstallationPhase())) && (isHtmlOutputMode()) && ($GLOBALS['__header_sent'] == 2)) {
+       // 1234                            5                      54    4                    554    4          5543    3                    4432    2                332    2                              21
+       if ((((isExtensionInstalledAndNewer('sql_patches', '0.4.1')) && (isShowTimingsEnabled()) && (isFullPage())) && (!isInstallationPhase())) && (isHtmlOutputMode()) && ($GLOBALS['__header_sent'] == 2)) {
                // Then display it here
                displayParsingTime();
        } // END - if
@@ -1006,14 +1007,14 @@ function FILTER_DISPLAY_PARSING_TIME () {
 // Filter for flushing template cache
 function FILTER_FLUSH_TEMPLATE_CACHE () {
        // Do not flush when debugging the template cache
-       if (isDebuggingTemplateCache()) {
+       if (isDebugTemplateCacheEnabled()) {
                // Do not flush templates in debug-mode
                return;
        } // END - if
 
        // Is there cached eval() data?
        if ((isset($GLOBALS['template_eval'])) && (count($GLOBALS['template_eval']) > 0)) {
-               // Now flush all
+               // Flush all
                foreach ($GLOBALS['template_eval'] as $prefix => $templateArray) {
                        foreach ($templateArray as $template => $eval) {
                                // Flush the cache (if not yet found)
@@ -1025,19 +1026,23 @@ function FILTER_FLUSH_TEMPLATE_CACHE () {
 
 // Filter for loading user data
 function FILTER_FETCH_USER_DATA ($userid = NULL) {
-       // Is the userid not set? Then use member id
-       if (!isValidUserId($userid)) {
+       // Is the userid not set?
+       if (!isValidId($userid)) {
+               // Then use member id
                $userid = getMemberId();
        } // END - if
 
        // Get user data
        if (!fetchUserData($userid)) {
                // Userid is not valid
-               reportBug(__FUNCTION__, __LINE__, 'User id '.$userid . ' is invalid.');
+               reportBug(__FUNCTION__, __LINE__, 'User id ' . $userid . ' is invalid.');
        } // END - if
 
        // Set member id
        setMemberId($userid);
+
+       // Continue with next filter
+       return $userid;
 }
 
 // Filter for reseting users' last login failure, only available with latest ext-sql_patches
@@ -1088,12 +1093,12 @@ function FILTER_LOAD_PAGE_HEADER () {
        $GLOBALS['__page_header'] = loadTemplate('page_header', TRUE);
 
        // Include meta data in 'guest' module
-       if ((isModuleSet()) && (getModule() == 'index')) {
+       if (isModuleSet()) {
                // Load meta data template
-               $GLOBALS['__page_header'] .= loadTemplate('metadata', TRUE);
+               $GLOBALS['__page_header'] .= loadTemplate(getMenuModeFromModule() . '_metadata', TRUE);
 
                // Add meta description to header
-               if ((isInstalled()) && (isAdminRegistered()) && (SQL_IS_LINK_UP())) {
+               if ((isInstalled()) && (isAdminRegistered()) && (SQL_IS_LINK_UP()) && (getModule() == 'index')) {
                        // Add meta description not in admin and login module and when the script is installed
                        generateMetaDescriptionCode();
                } // END - if
@@ -1309,17 +1314,17 @@ function FILTER_HANDLE_REFERRER_BANNER_VIEW ($filterData) {
 
                        // Redirect
                        redirectToUrl($data['url'], FALSE);
-               } else {
-                       // @TODO No banner found, output some default banner
-                       logDebugMessage(__FUNCTION__, __LINE__, 'Banner ' . bigintval(getRequestElement('banner')) . ' not dound.');
-               }
+               } // END - if
+
+               // @TODO No banner found, output some default banner
+               logDebugMessage(__FUNCTION__, __LINE__, 'Banner ' . bigintval(getRequestElement('banner')) . ' not found.');
 
                // Free memory
                SQL_FREERESULT($result);
-       } else {
-               // Do nothing for now
-               redirectToUrl('modules.php?module=index');
-       }
+       } // END - if
+
+       // Do nothing for now
+       redirectToUrl('modules.php?module=index');
 }
 
 // Filter for redirecting on wrong server name (e.g. bad.your-server.tld will be redirected to your-server.tld)
@@ -1374,5 +1379,18 @@ WHERE
        return $filterData;
 }
 
+// Filter for detecting menu mode
+function FILTER_DETERMINE_MENU_MODE_GENERIC ($filterData) {
+       // "Detect" it
+       switch (getModule()) {
+               case 'confirm': // Login script is 'member'
+                       $filterData = 'member';
+                       break;
+       } // END - switch
+
+       // Return filter data
+       return $filterData;
+}
+
 // [EOF]
 ?>