]> git.mxchange.org Git - mailer.git/blobdiff - inc/filters.php
Fixes for various bugs (e.g.: 'secret file could not be read', SQL error and more)
[mailer.git] / inc / filters.php
index bbac2082ad12bd014289735b4f25a857a254a847..ceaf0e0ac9c47e6332df05342cf8a914989f7848 100644 (file)
@@ -46,17 +46,17 @@ function FILTER_FLUSH_FILTERS () {
        initSqls();
 
        // Is a database link here and not in installation mode?
-       if ((!isSqlLinkUp()) && (!isInstallationPhase())) {
+       if ((!isSqlLinkUp()) && (!isInstaller())) {
                // Abort here
                reportBug(__FUNCTION__, __LINE__, 'No database link is up. Cannot flush filters.');
-       } elseif ((isInstallationPhase()) && (!isSqlLinkUp())) {
+       } elseif ((isInstaller()) && (!isSqlLinkUp())) {
                // 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?
-       if (((!isExtensionInstalled('sql_patches')) || (isExtensionInstalledAndOlder('sql_patches', '0.5.9'))) && (!isInstallationPhase())) {
+       if (((!isExtensionInstalled('sql_patches')) || (isExtensionInstalledAndOlder('sql_patches', '0.5.9'))) && (!isInstaller())) {
                // 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')));
@@ -188,7 +188,7 @@ function FILTER_SOLVE_TASK ($filterData) {
                adminSolveTask($filterData['task_id']);
        } else {
                // Not detectable!
-               reportBug(__FUNCTION__, __LINE__, sprintf("Cannot resolve task. data[%s]=<pre>%s</pre>", gettype($filterData), print_r($filterData, TRUE)));
+               reportBug(__FUNCTION__, __LINE__, sprintf('Cannot resolve task. data[%s]=<pre>%s</pre>', gettype($filterData), print_r($filterData, TRUE)));
        }
 
        // Return the data
@@ -218,7 +218,7 @@ function FILTER_LOAD_INCLUDES ($filterData) {
        // Is it an array?
        if ((!isset($data)) || (!is_array($data))) {
                // Then abort here
-               reportBug(__FUNCTION__, __LINE__, sprintf("INC_POOL is no array! Type: %s", gettype($data)));
+               reportBug(__FUNCTION__, __LINE__, sprintf('INC_POOL is no array! Type: %s', gettype($data)));
        } elseif (isset($data['inc_pool'])) {
                // Use this as new inclusion pool!
                setIncludePool($realPool, $data['inc_pool']);
@@ -435,7 +435,7 @@ function FILTER_COMPILE_CONFIG ($code, $compiled = FALSE) {
                preg_match_all('/\{\?(([a-zA-Z0-9-_]+)*)\?\}/', $code, $matches);
 
                // Some entries found?
-               if ((count($matches) > 0) && (count($matches[0]) > 0)) {
+               if ((isFilledArray($matches)) && (isFilledArray($matches[0]))) {
                        // Replace all matches
                        foreach ($matches[0] as $key => $match) {
                                // Is there cache?
@@ -489,7 +489,7 @@ function FILTER_COMPILE_EXPRESSION_CODE ($filterData) {
        $outputMode = getScriptOutputMode();
 
        // Some entries found?
-       if ((count($matches) > 0) && (count($matches[3]) > 0)) {
+       if ((isFilledArray($matches)) && (isFilledArray($matches[3]))) {
                // Replace all matches
                foreach ($matches[2] as $key => $eti) {
                        // Init replacer/call-back variable
@@ -662,6 +662,27 @@ function FILTER_RUN_MONTHLY_INCLUDES () {
        } // END - if
 }
 
+// Load more yearly scripts
+function FILTER_RUN_YEARLY_INCLUDES () {
+       // Is the reset set or old sql_patches?
+       if (((!isYearlyResetEnabled()) || (!isExtensionInstalledAndNewer('sql_patches', '0.9.8'))) && (isHtmlOutputMode())) {
+               // Then abort here
+               reportBug(__FUNCTION__, __LINE__, 'Cannot run yearly reset! enabled='.intval(isYearlyResetEnabled()).',isExtensionInstalledAndNewer='.intval(isExtensionInstalledAndNewer('sql_patches', '0.9.8')).' Please report this bug. Thanks');
+       } // END - if
+
+       // Is ext-sql_patches at least 0.9.8?
+       if (isExtensionInstalledAndNewer('sql_patches', '0.9.8')) {
+               // Has it changed?
+               if ((getLastYearly() != getYear()) || (isDebugYearlyEnabled())) {
+                       // Include yearly reset scripts
+                       setIncludePool('yearly', getArrayFromDirectory('inc/yearly/', 'yearly_'));
+
+                       // Run the filter
+                       runFilterChain('load_includes', 'yearly');
+               } // END - if
+       } // END - if
+}
+
 // Filter for removing the given extension
 function FILTER_REMOVE_EXTENSION () {
        // Delete this extension (remember to remove it from your server *before* you click on welcome!
@@ -712,7 +733,7 @@ function FILTER_HTML_INCLUDE_USERS ($mode) {
 // Filter for determining what/action/module
 function FILTER_DETERMINE_WHAT_ACTION () {
        // In installation phase we don't have what/action
-       if (isInstallationPhase()) {
+       if (isInstaller()) {
                // Set both to empty
                setAction('');
                setWhat('');
@@ -824,13 +845,13 @@ function FILTER_CHECK_REPOSITORY_REVISION () {
 // Filter for running hourly reset
 function FILTER_RUN_HOURLY_RESET () {
        // Only execute this filter if installed
-       if ((isInstallationPhase()) || (!isInstalled()) || (!isAdminRegistered()) || (!isExtensionInstalledAndNewer('sql_patches', '0.9.8'))) {
+       if ((isInstaller()) || (!isInstalled()) || (!isAdminRegistered()) || (!isExtensionInstalledAndNewer('sql_patches', '0.9.8'))) {
                return;
        } // END - if
 
        // Shall we run the reset scripts? If a day has changed, maybe also a week/month has changed... Simple! :D
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getLastHourly()=' . getLastHourly() . ',getHour()=' . getHour());
-       if (((getLastHourly() != getHour()) || (isDebugHourlyEnabled())) && (!isInstallationPhase()) && (isAdminRegistered()) && (!isGetRequestElementSet('setup')) && (!isCssOutputMode())) {
+       if (((getLastHourly() != getHour()) || (isDebugHourlyEnabled())) && (!isInstaller()) && (isAdminRegistered()) && (!isGetRequestElementSet('setup')) && (!isCssOutputMode())) {
                // Tell every module we are in reset-mode!
                doHourly();
        } // END - if
@@ -839,13 +860,13 @@ function FILTER_RUN_HOURLY_RESET () {
 // Filter for running daily reset
 function FILTER_RUN_DAILY_RESET () {
        // Only execute this filter if installed
-       if ((isInstallationPhase()) || (!isInstalled()) || (!isAdminRegistered()) || (!isExtensionInstalledAndNewer('sql_patches', '0.9.8'))) {
+       if ((isInstaller()) || (!isInstalled()) || (!isAdminRegistered()) || (!isExtensionInstalledAndNewer('sql_patches', '0.9.8'))) {
                return;
        } // END - if
 
        // Shall we run the reset scripts? If a day has changed, maybe also a week/month has changed... Simple! :D
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getLastDaily()=' . getLastDaily() . ',getDay()=' . getDay());
-       if (((getLastDaily() != getDay()) || (isDebugDailyEnabled())) && (!isInstallationPhase()) && (isAdminRegistered()) && (!isGetRequestElementSet('setup')) && (!isCssOutputMode())) {
+       if (((getLastDaily() != getDay()) || (isDebugDailyEnabled())) && (!isInstaller()) && (isAdminRegistered()) && (!isGetRequestElementSet('setup')) && (!isCssOutputMode())) {
                // Tell every module we are in reset-mode!
                doDaily();
        } // END - if
@@ -854,13 +875,13 @@ function FILTER_RUN_DAILY_RESET () {
 // Filter for running weekly reset
 function FILTER_RUN_WEEKLY_RESET () {
        // Only execute this filter if installed
-       if ((isInstallationPhase()) || (!isInstalled()) || (!isAdminRegistered()) || (!isExtensionInstalledAndNewer('sql_patches', '0.9.8'))) {
+       if ((isInstaller()) || (!isInstalled()) || (!isAdminRegistered()) || (!isExtensionInstalledAndNewer('sql_patches', '0.9.8'))) {
                return;
        } // END - if
 
        // Shall we run the reset scripts? If a day has changed, maybe also a week/month has changed... Simple! :D
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getLastWeekly()=' . getLastWeekly() . ',getWeek()=' . getWeek());
-       if (((getLastWeekly() != getWeek()) || (isDebugWeeklyEnabled())) && (!isInstallationPhase()) && (isAdminRegistered()) && (!isGetRequestElementSet('setup')) && (!isCssOutputMode())) {
+       if (((getLastWeekly() != getWeek()) || (isDebugWeeklyEnabled())) && (!isInstaller()) && (isAdminRegistered()) && (!isGetRequestElementSet('setup')) && (!isCssOutputMode())) {
                // Tell every module we are in reset-mode!
                doWeekly();
        } // END - if
@@ -869,18 +890,33 @@ function FILTER_RUN_WEEKLY_RESET () {
 // Filter for running monthly reset
 function FILTER_RUN_MONTHLY_RESET () {
        // Only execute this filter if installed
-       if ((isInstallationPhase()) || (!isInstalled()) || (!isAdminRegistered()) || (!isExtensionInstalledAndNewer('sql_patches', '0.9.8'))) {
+       if ((isInstaller()) || (!isInstalled()) || (!isAdminRegistered()) || (!isExtensionInstalledAndNewer('sql_patches', '0.9.8'))) {
                return;
        } // END - if
 
        // Shall we run the reset scripts? If a day has changed, maybe also a week/month has changed... Simple! :D
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getLastMonthly()=' . getLastMonthly() . ',getMonth()=' . getMonth());
-       if (((getLastMonthly() != getMonth()) || (isDebugMonthlyEnabled())) && (!isInstallationPhase()) && (isAdminRegistered()) && (!isGetRequestElementSet('setup')) && (!isCssOutputMode())) {
+       if (((getLastMonthly() != getMonth()) || (isDebugMonthlyEnabled())) && (!isInstaller()) && (isAdminRegistered()) && (!isGetRequestElementSet('setup')) && (!isCssOutputMode())) {
                // Tell every module we are in reset-mode!
                doMonthly();
        } // END - if
 }
 
+// Filter for running yearly reset
+function FILTER_RUN_YEARLY_RESET () {
+       // Only execute this filter if installed
+       if ((isInstaller()) || (!isInstalled()) || (!isAdminRegistered()) || (!isExtensionInstalledAndNewer('sql_patches', '0.9.8'))) {
+               return;
+       } // END - if
+
+       // Shall we run the reset scripts? If a day has changed, maybe also a week/month has changed... Simple! :D
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getLastYearly()=' . getLastYearly() . ',getYear()=' . getYear());
+       if (((getLastYearly() != getYear()) || (isDebugYearlyEnabled())) && (!isInstaller()) && (isAdminRegistered()) && (!isGetRequestElementSet('setup')) && (!isCssOutputMode())) {
+               // Tell every module we are in reset-mode!
+               doYearly();
+       } // END - if
+}
+
 // Filter for loading more runtime includes (not for installation)
 function FILTER_LOAD_RUNTIME_INCLUDES () {
        // Load more includes
@@ -936,7 +972,7 @@ function FILTER_INIT_RANDOM_NUMBER () {
 // Update module counter
 function FILTER_COUNT_MODULE () {
        // Is installation phase or no admin registered?
-       if ((isInstallationPhase()) || (!isInstalled()) || (!isAdminRegistered())) {
+       if ((isInstaller()) || (!isInstalled()) || (!isAdminRegistered())) {
                // Then don't count any modules
                return;
        } // END - if
@@ -966,7 +1002,7 @@ function FILTER_HANDLE_FATAL_ERRORS () {
        $content = '';
 
        // Installation phase or regular mode?
-       if ((isInstallationPhase())) {
+       if ((isInstaller())) {
                // While we are installing ouput other header than while it is installed... :-)
                $OUT = '';
                foreach (getFatalArray() as $key => $value) {
@@ -1049,7 +1085,7 @@ function FILTER_DISPLAY_COPYRIGHT () {
 function FILTER_DISPLAY_PARSING_TIME () {
        // Shall we display the parsing time and number of queries?
        // 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)) {
+       if ((((isExtensionInstalledAndNewer('sql_patches', '0.4.1')) && (isShowTimingsEnabled()) && (isFullPage())) && (!isInstaller())) && (isHtmlOutputMode()) && ($GLOBALS['__header_sent'] == 2)) {
                // Then display it here
                displayParsingTime();
        } // END - if
@@ -1064,7 +1100,7 @@ function FILTER_FLUSH_TEMPLATE_CACHE () {
        } // END - if
 
        // Is there cached eval() data?
-       if ((isset($GLOBALS['template_eval'])) && (count($GLOBALS['template_eval']) > 0)) {
+       if ((isset($GLOBALS['template_eval'])) && (isFilledArray($GLOBALS['template_eval']))) {
                // Flush all
                foreach ($GLOBALS['template_eval'] as $prefix => $templateArray) {
                        foreach ($templateArray as $template => $eval) {
@@ -1213,7 +1249,7 @@ function FILTER_GENERATE_POOL_MAIL_LINKS ($filterData) {
 // Filter to activate exchange
 function FILTER_ACTIVATE_EXCHANGE () {
        // Are the extension ext-user/other there?
-       if ((!isExtensionActive('user')) || (!isExtensionActive('other')) || (getActivateXchange() == '0')) {
+       if ((!isExtensionActive('user')) || (!isExtensionInstalled('other')) || (isAjaxOutputMode()) || (getActivateXchange() == '0')) {
                // Silently abort here
                return FALSE;
        } // END - if
@@ -1266,33 +1302,40 @@ function FILTER_ADD_HISTORY_ENTRY ($filterData) {
 
 // Filter for initializing ext-sql_patches
 function FILTER_GENERATE_FILE_SECRET_HASH ($filterData) {
-       // Transfer POINTS word
-       if (isExtensionInstalledAndNewer('sql_patches', '0.0.3')) {
-               // Okay, recent enough, so transfer the word for POINTS
-               setConfigEntry('POINTS', getPointsWord());
+       // Is ext-sql_patches installed and transfer POINTS word?
+       if ((!isExtensionInstalled('sql_patches')) || (!isExtensionInstalledAndNewer('sql_patches', '0.9.0'))) {
+               // Extension ext-sql_patches is missing, so better abort here
+               return;
        } // END - if
 
+       // Okay, recent enough, so transfer the word for POINTS
+       setConfigEntry('POINTS', getPointsWord());
+
        // Init key
        setConfigEntry('secret_key', '');
 
+       // File hash was generated so we can also file the secret file... hopefully.
+       $hashFile = sprintf('%s%s.%s.cache', getPath(), getCachePath(), getFileHash());
+
        // Read key from secret file
-       if ((getFileHash() == '') || (getMasterSalt() == '') || (getPassScramble() == '')) {
+       if ((getFileHash() == '') || (getMasterSalt() == '') || (getPassScramble() == '') || (!isFileReadable($hashFile))) {
                // Maybe need setup of secret key!
                loadIncludeOnce('inc/gen_sql_patches.php');
+
+               // Generate file name again
+               $hashFile = sprintf('%s%s.%s.cache', getPath(), getCachePath(), getFileHash());
        } // END - if
 
        // Test again
        if ((getFileHash() != '') && (getMasterSalt() != '') && (getPassScramble() != '')) {
-               // File hash fas generated so we can also file the secret file... hopefully.
-               $hashFile = sprintf("%s%s.%s.cache", getPath(), getCachePath(), getFileHash());
-
                // Is the secret key file readable?
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'hashFile=' . $hashFile);
                if (isFileReadable($hashFile)) {
                        // Read file
                        setConfigEntry('secret_key', readFromFile($hashFile));
                } else {
                        // Remove it from database
-                       updateConfiguration('file_hash', '');
+                       updateConfiguration('file_hash', '', '', '0', TRUE);
 
                        // Cannot read secret file!
                        reportBug(__FILE__, __LINE__, 'Cannot read secret file! Please try to reload.');
@@ -1329,7 +1372,7 @@ function FILTER_HANDLE_REFERRER_BANNER_CLICK ($filterData) {
        // Check required parameters
        if ((isGetRequestElementSet('user')) && (isGetRequestElementSet('banner'))) {
                // Update clicks counter...
-               sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_refbanner` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1",
+               sqlQueryEscaped('UPDATE `{?_MYSQL_PREFIX?}_refbanner` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1',
                        array(bigintval(getRequestElement('banner'))), __FUNCTION__, __LINE__);
 
                // A line has been updated?
@@ -1348,7 +1391,7 @@ function FILTER_HANDLE_REFERRER_BANNER_VIEW ($filterData) {
        // Are all required parameters set
        if ((isGetRequestElementSet('user')) && (isGetRequestElementSet('banner'))) {
                // For later things... ;-)
-               $result = sqlQueryEscaped("SELECT `url` FROM `{?_MYSQL_PREFIX?}_refbanner` WHERE `id`=%s LIMIT 1",
+               $result = sqlQueryEscaped('SELECT `url` FROM `{?_MYSQL_PREFIX?}_refbanner` WHERE `id`=%s LIMIT 1',
                        array(bigintval(getRequestElement('banner'))), __FUNCTION__, __LINE__);
 
                // Is there the banner?
@@ -1357,7 +1400,7 @@ function FILTER_HANDLE_REFERRER_BANNER_VIEW ($filterData) {
                        $data = sqlFetchArray($result);
 
                        // Update counter
-                       sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_refbanner` SET `counter`=`counter`+1 WHERE `id`=%s LIMIT 1",
+                       sqlQueryEscaped('UPDATE `{?_MYSQL_PREFIX?}_refbanner` SET `counter`=`counter`+1 WHERE `id`=%s LIMIT 1',
                                array(bigintval(getRequestElement('banner'))), __FUNCTION__, __LINE__);
 
                        // Set header and ...
@@ -1434,7 +1477,10 @@ WHERE
 function FILTER_DETERMINE_MENU_MODE_GENERIC ($filterData) {
        // "Detect" it
        switch (getModule()) {
+               case 'chk_login': // Is also faked
                case 'confirm': // Login script is 'member'
+               case 'loader': // Is faked to 'member' to avoid indexing by search engines
+               case 'mailid': // Mail confirmation is 'member'
                        $filterData = 'member';
                        break;
        } // END - switch