+ // 'what' not set?
+ if (!isWhatSet()) {
+ // Fix it to default
+ setWhat('welcome');
+ if (getConfig('index_home') != '') setWhatFromConfig('index_home');
+ } // END - if
+
+ // Update last module / online time
+ SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `last_module`='%s', `last_online`=UNIX_TIMESTAMP(), `REMOTE_ADDR`='%s' WHERE `userid`=%s LIMIT 1",
+ array(
+ getWhat(),
+ detectRemoteAddr(),
+ getUserId()
+ ), __FUNCTION__, __LINE__);
+ } else {
+ // Destroy session, we cannot update!
+ destroyUserSession();
+ }
+
+ // Free the result
+ SQL_FREERESULT($result);
+}
+
+// Filter for initializing randomizer
+function FILTER_INIT_RANDOMIZER () {
+ // Only execute this filter if installed
+ if ((!isInstalled()) || (!isExtensionInstalledAndNewer('other', '0.2.5'))) return;
+
+ // Take a prime number which is long (if you know a longer one please try it out!)
+ setConfigEntry('_PRIME', 591623);
+
+ // Calculate "entropy" with the prime number (for code generation)
+ setConfigEntry('_ADD', (getConfig('_PRIME') * getConfig('_PRIME') / (pi() * getConfig('code_length') + 1)));
+
+ // Simply init the randomizer with seed and _ADD value
+ mt_srand(generateSeed() + getConfig('_ADD'));
+}
+
+// Filter for removing updates
+function FILTER_REMOVE_UPDATES ($data) {
+ // 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!
+ removeExtensionUpdateDependency($ext_name);
+ } // END - if
+ } // END - foreach
+ } // END - if
+
+ // Return data
+ return $data;
+}
+
+// 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
+ $result = SQL_QUERY_ESC("SELECT `surname`, `family` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s LIMIT 1",
+ array(getUserId()), __FILE__, __LINE__);
+ if (SQL_NUMROWS($result) == 1) {
+ // Load surname and family's name and build the username
+ $content = SQL_FETCHARRAY($result);
+
+ // 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('<em>{--USERNAME_UNKNOWN--}</em>');
+
+ // Destroy session
+ destroyUserSession();
+
+ // Kill userid
+ setUserId(0);
+ }
+
+ // Free memory
+ SQL_FREERESULT($result);
+ } 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) {
+ // 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]] = getConfig($matches[1][$key]);
+ } elseif (isConfigEntrySet('default_' . strtoupper($matches[1][$key]))) {
+ // Use default value
+ $GLOBALS['compile_config'][$matches[1][$key]] = getConfig('DEFAULT_' . strtoupper($matches[1][$key]));
+ } elseif (isMessageIdValid('DEFAULT_' . strtoupper($matches[1][$key]))) {
+ // No config, try the language system
+ $GLOBALS['compile_config'][$matches[1][$key]] = getMessage('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('<pre>'.htmlentities($code).'</pre>');
+ } // END - foreach
+ } // END - if
+
+ // Return compiled code
+ return $code;
+}
+
+// Filter for compiling extension data
+function FILTER_COMPILE_EXTENSION ($code) {
+ // Compile {%cmd=some_value%} to get extension data
+ // Support cmd is:
+ // - version -> getExtensionVersion() call
+ preg_match_all('/\{%((([a-zA-Z0-9-_]+)=([a-zA-Z0-9-_]+))*)\%\}/', $code, $matches);
+
+ // Some entries found?
+ if ((count($matches) > 0) && (count($matches[3]) > 0)) {
+ // Replace all matches
+ foreach ($matches[3] as $key => $cmd) {
+ // By default we have no extension installed, so 'false' is assumed
+ $replacer = 'false';
+
+ // Is the extension installed?
+ if (isExtensionActive($matches[4][$key])) {
+ // Construct call-back function name
+ $functionName = 'getExtension' . ucfirst(strtolower($cmd));
+
+ // Call the function
+ $replacer = call_user_func_array($functionName, $matches[4][$key]);
+ } // END - if
+
+ // Replace it and insert parameter for GET request
+ $code = str_replace($matches[0][$key], sprintf("&%s=%s&rev=%s", $cmd, $replacer, getConfig('CURR_SVN_REVISION')), $code);
+ } // END - foreach
+ } // END - if
+
+ // Return compiled code
+ return $code;
+}
+
+// Runs some generic filter update steps
+function FILTER_UPDATE_EXTENSION_DATA ($ext_name) {
+ // Create task
+ 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 reset scripts
+function FILTER_RUN_RESET_INCLUDES () {
+ // Is the reset set or old sql_patches?
+ if (((!isResetModeEnabled()) || (!isExtensionInstalledAndOlder('sql_patches', '0.4.5'))) && (getOutputMode() == 0)) {
+ // Then abort here
+ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot run reset! Please report this bug. Thanks');