Rewrote reset and some extensions:
[mailer.git] / inc / filters.php
index bd34939676611f5f3afaca6767b2a9377c70923c..e1784f4691065f5af74fff932051b5538f47d158 100644 (file)
@@ -583,67 +583,97 @@ function FILTER_RUN_HOURLY_INCLUDES () {
        // Is the reset set or old sql_patches?
        if (((!isHourlyResetEnabled()) || (!isExtensionInstalledAndNewer('sql_patches', '0.7.5'))) && (isHtmlOutputMode())) {
                // Then abort here
-               reportBug(__FUNCTION__, __LINE__, 'Cannot run reset! enabled='.intval(isHourlyResetEnabled()).',ext_newer[sql_patches:0.7.5]='.intval(isExtensionInstalledAndNewer('sql_patches', '0.7.5')).' Please report this bug. Thanks');
+               reportBug(__FUNCTION__, __LINE__, 'Cannot run hourly reset! enabled='.intval(isHourlyResetEnabled()).',ext='.intval(isExtensionInstalledAndNewer('sql_patches', '0.9.8')).' Please report this bug. Thanks');
        } // END - if
 
-       // Get more hourly reset scripts
-       setIncludePool('hourly', getArrayFromDirectory('inc/hourly/', 'hourly_'));
+       // Is the config entry set?
+       if (isExtensionInstalledAndNewer('sql_patches', '0.7.5')) {
+               // Get more hourly reset scripts
+               setIncludePool('hourly', getArrayFromDirectory('inc/hourly/', 'hourly_'));
 
-       // Update database
-       if ((!isConfigEntrySet('DEBUG_HOURLY')) || (!isDebugHourlyEnabled())) {
-               updateConfiguration('last_hour', getHour());
-       } // END - if
+               // Update database
+               if ((!isConfigEntrySet('DEBUG_HOURLY')) || (!isDebugHourlyEnabled())) {
+                       updateConfiguration('last_hourly', getHour());
+               } // END - if
 
-       // Run the filter
-       runFilterChain('load_includes', 'hourly');
+               // Run the filter
+               runFilterChain('load_includes', 'hourly');
+       } // END - if
 }
 
-// Load more reset scripts
-function FILTER_RUN_RESET_INCLUDES () {
+// Load more daily scripts
+function FILTER_RUN_DAILY_INCLUDES () {
        // Is the reset set or old sql_patches?
-       if (((!isResetModeEnabled()) || (!isExtensionInstalled('sql_patches'))) && (isHtmlOutputMode())) {
+       if (((!isDailyResetEnabled()) || (!isExtensionInstalledAndNewer('sql_patches', '0.9.8'))) && (isHtmlOutputMode())) {
                // Then abort here
-               reportBug(__FUNCTION__, __LINE__, 'Cannot run reset! enabled='.intval(isResetModeEnabled()).',ext='.intval(isExtensionInstalled('sql_patches')).' Please report this bug. Thanks');
+               reportBug(__FUNCTION__, __LINE__, 'Cannot run daily reset! enabled='.intval(isDailyResetEnabled()).',ext='.intval(isExtensionInstalledAndNewer('sql_patches', '0.9.8')).' Please report this bug. Thanks');
        } // END - if
 
        // Get more daily reset scripts
-       setIncludePool('reset', getArrayFromDirectory('inc/daily/', 'daily_'));
+       setIncludePool('daily', getArrayFromDirectory('inc/daily/', 'daily_'));
 
        // Update configuration if this reset is not being debugged
-       if (!isDebugResetEnabled()) {
-               updateConfiguration('last_update', 'UNIX_TIMESTAMP()');
+       if (!isDebugDailyEnabled()) {
+               updateConfiguration('last_daily', getDay());
+       } // END - if
+
+       // Run the filter
+       runFilterChain('load_includes', 'daily');
+}
+
+// Load more weeklt scripts
+function FILTER_RUN_WEEKLY_INCLUDES () {
+       // Is the reset set or old sql_patches?
+       if (((!isWeeklyResetDebugEnabled()) || (!isExtensionInstalledAndNewer('sql_patches', '0.9.8'))) && (isHtmlOutputMode())) {
+               // Then abort here
+               reportBug(__FUNCTION__, __LINE__, 'Cannot run weekly reset! enabled='.intval(isWeeklyResetDebugEnabled()).',ext='.intval(isExtensionInstalledAndNewer('sql_patches', '0.9.8')).' Please report this bug. Thanks');
        } // END - if
 
        // Is the config entry set?
        if (isExtensionInstalledAndNewer('sql_patches', '0.4.2')) {
                // Has it changed?
-               if (((isConfigEntrySet('last_week')) && (getConfig('last_week') != getWeek())) || (isWeeklyResetDebugEnabled())) {
+               if (((isConfigEntrySet('last_weekly')) && (getLastWeekly() != getWeek())) || (isWeeklyResetDebugEnabled())) {
                        // Include weekly reset scripts
-                       mergeIncludePool('reset', getArrayFromDirectory('inc/weekly/', 'weekly_'));
+                       setIncludePool('weekly', getArrayFromDirectory('inc/weekly/', 'weekly_'));
 
                        // Update configuration if this reset is not being debugged
                        if (!isWeeklyResetDebugEnabled()) {
-                               updateConfiguration('last_week', getWeek());
+                               updateConfiguration('last_weekly', getWeek());
                        } // END - if
                } // END - if
 
+               // Run the filter
+               runFilterChain('load_includes', 'weekly');
+       } // END - if
+}
+
+// Load more monthly scripts
+function FILTER_RUN_MONTHLY_INCLUDES () {
+       // Is the reset set or old sql_patches?
+       if (((!isMonthlyResetDebugEnabled()) || (!isExtensionInstalledAndNewer('sql_patches', '0.9.8'))) && (isHtmlOutputMode())) {
+               // Then abort here
+               reportBug(__FUNCTION__, __LINE__, 'Cannot run monthly reset! enabled='.intval(isMonthlyResetDebugEnabled()).',ext='.intval(isExtensionInstalledAndNewer('sql_patches', '0.9.8')).' Please report this bug. Thanks');
+       } // END - if
+
+       // Is the config entry set?
+       if (isExtensionInstalledAndNewer('sql_patches', '0.4.2')) {
                // Create current month mark
                $currMonth = getMonth();
 
                // Has it changed?
-               if ((getLastMonth() != $currMonth) || (isMonthlyResetDebugEnabled())) {
+               if ((getLastMonthly() != $currMonth) || (isMonthlyResetDebugEnabled())) {
                        // Include monthly reset scripts
-                       mergeIncludePool('reset', getArrayFromDirectory('inc/monthly/', 'monthly_'));
+                       setIncludePool('monthly', getArrayFromDirectory('inc/monthly/', 'monthly_'));
 
                        // Update configuration if this reset is not being debugged
                        if (!isMonthlyResetDebugEnabled()) {
-                               updateConfiguration('last_month', $currMonth);
+                               updateConfiguration('last_monthly', $currMonth);
                        } // END - if
                } // END - if
        } // END - if
 
        // Run the filter
-       runFilterChain('load_includes', 'reset');
+       runFilterChain('load_includes', 'monthly');
 }
 
 // Filter for removing the given extension
@@ -792,7 +822,9 @@ function FILTER_TRIGGER_SENDING_POOL () {
 // Filter for checking and updating SVN revision
 function FILTER_CHECK_REPOSITORY_REVISION () {
        // Only execute this filter if installed and all config entries are there
-       if ((!isInstalled()) || (!isConfigEntrySet('patch_level'))) return;
+       if ((!isInstalled()) || (!isConfigEntrySet('patch_level'))) {
+               return;
+       } // END - if
 
        // Check for patch level differences between database and current hard-coded
        if ((getCurrentRepositoryRevision() > getConfig('patch_level')) || (getConfig('patch_level') == 'CURRENT_REPOSITORY_REVISION') || (getConfig('patch_ctime') == 'UNIX_TIMES')) {
@@ -803,31 +835,59 @@ function FILTER_CHECK_REPOSITORY_REVISION () {
        } // END - if
 }
 
+// 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'))) {
+               return;
+       } // END - if
+
+       // Shall we run the reset scripts? If a day has changed, maybe also a week/month has changed... Simple! :D
+       if (((getLastHourly() != getHour()) || (isDebugHourlyEnabled())) && (!isInstallationPhase()) && (isAdminRegistered()) && (!isGetRequestElementSet('setup')) && (!isCssOutputMode())) {
+               // Tell every module we are in reset-mode!
+               doHourly();
+       } // END - if
+}
+
 // Filter for running daily reset
 function FILTER_RUN_DAILY_RESET () {
        // Only execute this filter if installed
-       if ((isInstallationPhase()) || (!isInstalled()) || (!isAdminRegistered()) || (!isExtensionInstalled('sql_patches'))) {
+       if ((isInstallationPhase()) || (!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
-       if (((getDay(getConfig('last_update')) != getDay()) || (isDebugResetEnabled())) && (!isInstallationPhase()) && (isAdminRegistered()) && (!isGetRequestElementSet('setup')) && (!isCssOutputMode())) {
+       if (((getLastDaily() != getDay()) || (isDebugDailyEnabled())) && (!isInstallationPhase()) && (isAdminRegistered()) && (!isGetRequestElementSet('setup')) && (!isCssOutputMode())) {
                // Tell every module we are in reset-mode!
-               doReset();
+               doDaily();
        } // END - if
 }
 
-// Filter for running hourly reset
-function FILTER_RUN_HOURLY_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.7.5'))) {
+       if ((isInstallationPhase()) || (!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
-       if ((((isConfigEntrySet('last_hour')) && (getConfig('last_hour') != getHour())) || (isDebugHourlyEnabled())) && (!isInstallationPhase()) && (isAdminRegistered()) && (!isGetRequestElementSet('setup')) && (!isCssOutputMode())) {
+       if (((getLastWeekly() != getWeek()) || (isDebugWeeklyEnabled())) && (!isInstallationPhase()) && (isAdminRegistered()) && (!isGetRequestElementSet('setup')) && (!isCssOutputMode())) {
                // Tell every module we are in reset-mode!
-               doHourly();
+               doWeekly();
+       } // END - if
+}
+
+// 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'))) {
+               return;
+       } // END - if
+
+       // Shall we run the reset scripts? If a day has changed, maybe also a week/month has changed... Simple! :D
+       if (((getLastMonthly() != getMonth()) || (isDebugMonthlyEnabled())) && (!isInstallationPhase()) && (isAdminRegistered()) && (!isGetRequestElementSet('setup')) && (!isCssOutputMode())) {
+               // Tell every module we are in reset-mode!
+               doMonthly();
        } // END - if
 }
 
@@ -885,14 +945,14 @@ function FILTER_INIT_RANDOM_NUMBER () {
 
 // Update module counter
 function FILTER_COUNT_MODULE () {
-       // Is installation phase?
-       if (isInstallationPhase()) {
+       // Is installation phase or no admin registered?
+       if ((isInstallationPhase()) || (!isInstalled()) || (!isAdminRegistered())) {
                // Then don't count any modules
                return;
        } // END - if
 
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getModule()=' . getModule() . ' - ENTERED!');
-       // Do count all other modules but not accesses on CSS file css.php!
+       // Count module click
        SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_mod_reg` SET `clicks`=`clicks`+1 WHERE `module`='%s' LIMIT 1",
                array(getModule()), __FUNCTION__, __LINE__);
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getModule()=' . getModule() . ',SQL_AFFECTEDROWS()=' . SQL_AFFECTEDROWS() . ' - EXIT!');