+ // Return compiled code
+ return $GLOBALS['compiled_config'][$uncompiled];
+}
+
+// Filter for compiling expression code
+function FILTER_COMPILE_EXPRESSION_CODE ($code) {
+ // Compile {%cmd,callback,extraFunction=some_value%} to get expression code snippets
+ // See switch() command below for supported commands
+ preg_match_all('/\{%(([a-zA-Z0-9-_,]+)(=([^\}]+)){0,1})*%\}/', $code, $matches);
+ //* DEBUG: */ debugOutput(__FUNCTION__.'['.__LINE__.']:<pre>'.print_r($matches, true).'</pre>');
+
+ // Default is from outputHtml()
+ $outputMode = getScriptOutputMode();
+
+ // Some entries found?
+ if ((count($matches) > 0) && (count($matches[3]) > 0)) {
+ // Replace all matches
+ foreach ($matches[2] as $key => $cmd) {
+ // Init replacer/call-back variable
+ $replacer = '';
+ $callback = '';
+ $extraFunction = '';
+ $extraFunction2 = '';
+ $value = null;
+
+ // Extract command and call-back
+ $cmdArray = explode(',', $cmd);
+ $cmd = $cmdArray[0];
+
+ // Detect call-back function
+ if (isset($cmdArray[1])) {
+ // Call-back function detected
+ $callback = $cmdArray[1];
+ } // END - if
+
+ // Detect extra function
+ if (isset($cmdArray[2])) {
+ // Also detected
+ $extraFunction = $cmdArray[2];
+ } // END - if
+
+ // Detect extra function 2
+ if (isset($cmdArray[3])) {
+ // Also detected
+ $extraFunction2 = $cmdArray[3];
+ } // END - if
+
+ // And value
+ if (isset($matches[4][$key])) {
+ // Use this as value
+ $value = $matches[4][$key];
+ } // END - if
+
+ // Construct call-back function name for the command
+ $commandFunction = 'doExpression' . capitalizeUnderscoreString($cmd);
+
+ // Is this function there?
+ if (function_exists($commandFunction)) {
+ // Prepare $matches, $key, $outputMode, etc.
+ $data = array(
+ 'matches' => $matches,
+ 'key' => $key,
+ 'mode' => getScriptOutputMode(),
+ 'code' => $code,
+ 'callback' => $callback,
+ 'extra_func' => $extraFunction,
+ 'extra_func2' => $extraFunction2,
+ 'value' => $value
+ );
+
+ // Call it
+ //* DEBUG: */ debugOutput(__FUNCTION__ . '[' . __LINE__ . ']: function=' . $commandFunction);
+ $code = call_user_func($commandFunction, $data);
+ } else {
+ // Unsupported command detected
+ logDebugMessage(__FUNCTION__, __LINE__, 'Command cmd=' . $cmd . ', callback=' . $callback . ', extra=' . $extraFunction . ' is unsupported.');
+ }
+ } // END - foreach
+ } // END - if
+
+ // Do we have non-HTML mode?
+ if (!isHtmlOutputMode()) {
+ $code = decodeEntities($code);
+ } // END - if
+
+ // Return compiled code
+ //* DEBUG: */ debugOutput(__FUNCTION__.'['.__LINE__.']:<pre>'.($code).'</pre>');
+ return $code;
+}
+
+// Runs some generic filter update steps
+function FILTER_UPDATE_EXTENSION_DATA ($ext_name) {
+ // Create task (we ignore the task id here)
+ createExtensionUpdateTask(getCurrentAdminId(), $ext_name, $GLOBALS['update_ver'][$ext_name], SQL_ESCAPE(getExtensionNotes(getExtensionNotes())));
+
+ // Update extension's version
+ SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_version`='%s' WHERE `ext_name`='%s' LIMIT 1",
+ array($GLOBALS['update_ver'][$ext_name], $ext_name), __FUNCTION__, __LINE__);
+
+ // Remove arrays
+ unsetSqls();
+ unset($GLOBALS['update_ver'][$ext_name]);
+}
+
+// Load more hourly reset scripts
+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
+ debug_report_bug(__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');
+ } // END - if
+
+ // Get more hourly reset scripts
+ setIncludePool('hourly', getArrayFromDirectory('inc/hourly/', 'hourly_'));
+
+ // Update database
+ if ((!isConfigEntrySet('DEBUG_RESET')) || (!isDebugResetEnabled())) {
+ updateConfiguration('last_hour', getHour());
+ } // END - if
+
+ // Run the filter
+ runFilterChain('load_includes', 'hourly');
+}
+
+// Load more reset scripts
+function FILTER_RUN_RESET_INCLUDES () {
+ // Is the reset set or old sql_patches?
+ if (((!isResetModeEnabled()) || (!isExtensionInstalled('sql_patches'))) && (isHtmlOutputMode())) {
+ // Then abort here
+ debug_report_bug(__FUNCTION__, __LINE__, 'Cannot run reset! enabled='.intval(isResetModeEnabled()).',ext='.intval(isExtensionInstalled('sql_patches')).' Please report this bug. Thanks');
+ } // END - if
+
+ // Get more daily reset scripts
+ setIncludePool('reset', getArrayFromDirectory('inc/daily/', 'daily_'));
+
+ // Update database
+ if ((!isConfigEntrySet('DEBUG_RESET')) || (!isDebugResetEnabled())) {
+ updateConfiguration('last_update', 'UNIX_TIMESTAMP()');
+ } // 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())) {
+ // Include weekly reset scripts
+ mergeIncludePool('reset', getArrayFromDirectory('inc/weekly/', 'weekly_'));
+
+ // Update config if not in debug mode
+ if (!isWeeklyResetDebugEnabled()) {
+ updateConfiguration('last_week', getWeek());
+ } // END - if
+ } // END - if
+
+ // Create current month mark
+ $currMonth = getMonth();
+
+ // Has it changed?
+ if ((getLastMonth() != $currMonth) || (isMonthlyResetDebugEnabled())) {
+ // Include monthly reset scripts
+ mergeIncludePool('reset', getArrayFromDirectory('inc/monthly/', 'monthly_'));
+
+ // Update config
+ if (!isMonthlyResetDebugEnabled()) {
+ updateConfiguration('last_month', $currMonth);
+ } // END - if
+ } // END - if
+ } // END - if
+
+ // Run the filter
+ runFilterChain('load_includes', 'reset');
+}
+
+// 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!
+ SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
+ array(getCurrentExtensionName()), __FUNCTION__, __LINE__);
+
+ // Remove the extension from cache array as well
+ removeExtensionFromArray();
+
+ // Remove the cache
+ rebuildCache('extension', 'extension');
+}
+
+// Filter for flushing the output
+function FILTER_FLUSH_OUTPUT () {
+ // Simple, he?
+ outputHtml('');
+}
+
+// Prepares an SQL statement part for HTML mail and/or holiday depency
+function FILTER_HTML_INCLUDE_USERS ($mode) {
+ // Exclude no users by default
+ $MORE = '';
+
+ // HTML mail?
+ if ($mode == 'html') $MORE = " AND `html`='Y'";
+ if (isExtensionInstalledAndNewer('holiday', '0.1.3')) {
+ // Add something for the holiday extension
+ $MORE .= " AND `holiday_active`='N'";
+ } // END - if
+
+ // Return result
+ return $MORE;
+}
+
+// Filter for determining what/action/module
+function FILTER_DETERMINE_WHAT_ACTION () {
+ // In installation phase we don't have what/action
+ if (isInstallationPhase()) {
+ // Set both to empty
+ setAction('');
+ setWhat('');
+
+ // Abort here
+ return;
+ } // END - if
+
+ // Get all values
+ if ((!isCssOutputMode()) && (!isRawOutputMode())) {
+ // Fix module
+ if (!isModuleSet()) {
+ // Is the request element set?
+ if (isGetRequestParameterSet('module')) {
+ // Set module from request
+ setModule(getRequestParameter('module'));
+ } elseif (isHtmlOutputMode()) {
+ // Set default module 'index'
+ setModule('index');
+ } else {
+ // Unknown module
+ setModule('unknown');
+ }
+ } // END - if
+
+ // Fix 'what' if not yet set
+ if (!isWhatSet()) {
+ setWhat(getWhatFromModule(getModule()));
+ } // END - if
+
+ // Fix 'action' if not yet set
+ if (!isActionSet()) {
+ setAction(getActionFromModuleWhat(getModule(), getWhat()));
+ } // END - if
+ } else {
+ // Set action/what to empty
+ setAction('');
+ setWhat('');
+ }
+
+ // Set default 'what' value
+ //* DEBUG: */ debugOutput('-' . getModule() . '/' . getWhat() . '-');
+ if ((!isWhatSet()) && (!isActionSet()) && (!isCssOutputMode()) && (!isRawOutputMode())) {
+ if (getModule() == 'admin') {
+ // Set 'action' value to 'login' in admin menu
+ setAction(getActionFromModuleWhat(getModule(), getWhat()));
+ } elseif ((getModule() == 'index') || (getModule() == 'login')) {
+ // Set 'what' value to 'welcome' in guest and member menu
+ setWhatFromConfig('index_home');
+ } else {
+ // Anything else like begging link
+ setWhat('');
+ }
+ } // END - if
+}
+
+// Sends out pooled mails
+function FILTER_TRIGGER_SENDING_POOL () {
+ // Are we in normal output mode?
+ if (!isHtmlOutputMode()) {
+ // Only in normal output mode to prevent race-conditons!
+ } // END - if
+
+ // Init counter
+ $GLOBALS['pool_cnt'] = '0';
+
+ // Init & set the include pool
+ initIncludePool('pool');
+ setIncludePool('pool', getArrayFromDirectory('inc/pool/', 'pool-'));
+
+ // Run the filter
+ runFilterChain('load_includes', 'pool');
+
+ // Remove the counter
+ unset($GLOBALS['pool_cnt']);
+}
+
+// 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;
+
+ // 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')) {
+ // Update database and CONFIG array
+ updateConfiguration(array('patch_level', 'patch_ctime'), array(getCurrentRepositoryRevision(), 'UNIX_TIMESTAMP()'));
+ setConfigEntry('patch_level', getCurrentRepositoryRevision());
+ setConfigEntry('patch_ctime', time());
+ } // 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'))) {
+ 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()) && (!isGetRequestParameterSet('register')) && (!isCssOutputMode())) {
+ // Tell every module we are in reset-mode!
+ doReset();
+ } // 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.7.5'))) {
+ 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())) || (isDebugResetEnabled())) && (!isInstallationPhase()) && (isAdminRegistered()) && (!isGetRequestParameterSet('register')) && (!isCssOutputMode())) {
+ // Tell every module we are in reset-mode!
+ doHourly();
+ } // END - if
+}
+
+// Filter for loading more runtime includes (not for installation)
+function FILTER_LOAD_RUNTIME_INCLUDES () {
+ // Load more includes
+ foreach (array('databases', 'session', 'versions') as $inc) {
+ // Load the include
+ loadIncludeOnce('inc/' . $inc . '.php');
+ } // END - foreach