+ destroyMemberSession();
+ }
+}
+
+// Filter for initializing randomizer
+function FILTER_INIT_RANDOMIZER () {
+ // Take a prime number which is long (if you know a longer one please try it out!)
+ setConfigEntry('_PRIME', 591623);
+
+ // Only execute this filter if installed
+ if ((!isInstalled()) || (!isExtensionInstalledAndNewer('other', '0.2.5'))) {
+ // Set missing entry
+ setConfigEntry('_ADD', 0);
+ return;
+ } // END - if
+
+ // Calculate "entropy" with the prime number (for code generation)
+ setConfigEntry('_ADD', (getPrime() * getPrime() / (pi() * getCodeLength() + 1)));
+
+ // Simply init the randomizer with seed and _ADD value
+ mt_srand(generateSeed() + getConfig('_ADD'));
+}
+
+// Filter for removing updates
+function FILTER_REMOVE_UPDATES ($filterData) {
+ // Init removal list
+ initExtensionRemovalList();
+
+ // Add the current extension to it
+ addCurrentExtensionToRemovalList();
+
+ // Simply remove it
+ unsetExtensionSqls();
+
+ // Do we need to remove update depency?
+ if (countExtensionUpdateDependencies() > 0) {
+ // Then find all updates we shall no longer execute
+ foreach (getExtensionUpdateDependencies() as $id => $ext_name) {
+ // Shall we remove this update?
+ if (in_array($ext_name, getExtensionRemovalList())) {
+ // Then remove this extension!
+ removeExtensionDependency($ext_name);
+ } // END - if
+ } // END - foreach
+ } // END - if
+
+ // Return data
+ return $filterData;
+}
+
+// Determines username for current user state
+function FILTER_DETERMINE_USERNAME () {
+ // Check if logged in
+ if (isMember()) {
+ // Is still logged in so we welcome him with his name
+ if (fetchUserData(getMemberId())) {
+ // Load surname and family's name and build the username
+ $content = getUserDataArray();
+
+ // Prepare username
+ setUsername($content['surname'] . ' ' . $content['family']);
+
+ // Additionally admin?
+ if (isAdmin()) {
+ // Add it
+ setUsername(getUsername() . ' ({--USERNAME_ADMIN_SHORT--})');
+ } // END - if
+ } else {
+ // Hmmm, logged in and no valid userid?
+ setUsername('<span class="bad">{--USERNAME_UNKNOWN--}</span>');
+
+ // Destroy session
+ destroyMemberSession();
+ }
+ } elseif (isAdmin()) {
+ // Admin is there
+ setUsername('{--USERNAME_ADMIN--}');
+ } else {
+ // He's a guest, hello there... ;-)
+ setUsername('{--USERNAME_GUEST--}');
+ }
+}
+
+// Filter for compiling config entries
+function FILTER_COMPILE_CONFIG ($code, $compiled = false) {
+ // Save the uncompiled code
+ $uncompiled = $code;
+
+ // Do we have cache?
+ if (!isset($GLOBALS['compiled_config'][$code])) {
+ // Compile {?some_var?} to getConfig('some_var')
+ preg_match_all('/\{\?(([a-zA-Z0-9-_]+)*)\?\}/', $code, $matches);
+
+ // Some entries found?
+ if ((count($matches) > 0) && (count($matches[0]) > 0)) {
+ // Replace all matches
+ foreach ($matches[0] as $key => $match) {
+ // Do we have cache?
+ if (!isset($GLOBALS['compile_config'][$matches[1][$key]])) {
+ // Is the config valid?
+ if (isConfigEntrySet($matches[1][$key])) {
+ // Set it for caching
+ $GLOBALS['compile_config'][$matches[1][$key]] = '{%config=' . $matches[1][$key] . '%}';
+ } elseif (isConfigEntrySet('default_' . strtoupper($matches[1][$key]))) {
+ // Use default value
+ $GLOBALS['compile_config'][$matches[1][$key]] = '{%config=' . 'DEFAULT_' . strtoupper($matches[1][$key]) . '%}';
+ } elseif (isMessageIdValid('DEFAULT_' . strtoupper($matches[1][$key]))) {
+ // No config, try the language system
+ $GLOBALS['compile_config'][$matches[1][$key]] = '{%message,DEFAULT_' . strtoupper($matches[1][$key]) . '%}';
+ } else {
+ // Unhandled!
+ $GLOBALS['compile_config'][$matches[1][$key]] = '!' . $matches[1][$key] . '!';
+ }
+ } // END - if
+
+ // Use this for replacing
+ $code = str_replace($match, $GLOBALS['compile_config'][$matches[1][$key]], $code);
+ //* DEBUG: */ if (($match == '{?URL?}') && (strlen($code) > 10000)) die(__FUNCTION__.'['.__LINE__.']:<pre>'.secureString($code).'</pre>');
+ } // END - foreach
+ } // END - if
+
+ // Add it to cache
+ $GLOBALS['compiled_config'][$uncompiled] = $code;
+ } // END - if
+
+ // Should we compile it?
+ if ($compiled === true) {
+ // Run the code
+ $eval = "\$GLOBALS['compiled_config'][\$uncompiled] = \"" . $GLOBALS['compiled_config'][$uncompiled] . '";';
+ //* DEBUG: */ debugOutput(__FUNCTION__.'['.__LINE__.']:<pre>' . encodeEntities($eval) . '</pre>');
+ eval($eval);
+ } // END - if
+
+ // Return compiled code
+ return $GLOBALS['compiled_config'][$uncompiled];
+}
+
+// Filter for compiling expression code
+function FILTER_COMPILE_EXPRESSION_CODE ($filterData) {
+ // 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})*%\}/', $filterData, $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,
+ 'output_mode' => getScriptOutputMode(),
+ 'code' => $filterData,
+ 'callback' => $callback,
+ 'extra_func' => $extraFunction,
+ 'extra_func2' => $extraFunction2,
+ 'value' => $value
+ );
+
+ // Call it
+ //* DEBUG: */ debugOutput(__FUNCTION__ . '[' . __LINE__ . ']: function=' . $commandFunction);
+ $filterData = 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()) {
+ $filterData = decodeEntities($filterData);
+ } // END - if
+
+ // Return compiled code
+ //* DEBUG: */ debugOutput(__FUNCTION__.'['.__LINE__.']:<pre>'.($filterData).'</pre>');
+ return $filterData;
+}
+
+// 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 dependency
+function FILTER_HTML_INCLUDE_USERS ($mode) {
+ // Exclude no users by default
+ $MORE = '';
+
+ // HTML mail?
+ if ($mode == 'html') {
+ $MORE = " AND `html`='Y'";
+ } // END - if
+
+ 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 (isGetRequestElementSet('module')) {
+ // Set module from request
+ setModule(getRequestElement('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('');