+// Filter for setting CURRENT_DATE, this is required after initialization of extensions
+function FILTER_SET_CURRENT_DATE () {
+ // Set current date
+ setConfigEntry('CURRENT_DATE', generateDateTime(time(), '3'));
+
+ // Epoche time for yesterday, today ... all at 00:00 am
+ setConfigEntry('START_YDAY', makeTime(0, 0, 0, time() - getOneDay()));
+ setConfigEntry('START_TDAY', makeTime(0, 0, 0, time()));
+}
+
+// Filter for marking extension as installed
+function FILTER_EXTENSION_MARK_INSTALLED ($filterData) {
+ // Mark it as installed
+ $GLOBALS['ext_is_installed'][$filterData['ext_name']] = TRUE;
+}
+
+// Filter for generating mails links for 'pool' mails
+function FILTER_GENERATE_POOL_MAIL_LINKS ($filterData) {
+ // Is type 'mid'?
+ if ($filterData['type'] == 'mid') {
+ // Load template
+ $filterData['__output'] .= loadTemplate('admin_links_' . strtolower($filterData['mail_status']) . '_pool_mail', TRUE, $filterData);
+ } // END - if
+
+ // Return data
+ return $filterData;
+}
+
+// Filter to activate exchange
+function FILTER_ACTIVATE_EXCHANGE () {
+ // Is the extension 'user' there?
+ if ((!isExtensionActive('user')) || (getActivateXchange() == '0')) {
+ // Silently abort here
+ return FALSE;
+ } // END - if
+
+ // Check total amount of users
+ if (getTotalConfirmedUser() >= getActivateXchange()) {
+ // Activate System
+ addSql("UPDATE `{?_MYSQL_PREFIX?}_mod_reg` SET `locked`='N',`hidden`='N',`mem_only`='Y' WHERE `module`='order' LIMIT 1");
+ addSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='Y',`locked`='N' WHERE `what`='order' OR `what`='unconfirmed' LIMIT 2");
+
+ // Run SQLs
+ runFilterChain('run_sqls');
+
+ // Update configuration
+ updateConfiguration('activate_xchange' ,0);
+
+ // Rebuild cache
+ rebuildCache('modules', 'modules');
+ } // END - if
+}
+
+// Filter to handle configuration
+function FILTER_HANDLE_HOME_IN_INDEX_SETTING ($filterData) {
+ // Is ext-sql_patches up-to-date?
+ if ((isExtensionInstalledAndNewer('sql_patches', '0.8.3')) && (isDisplayHomeInIndexEnabled())) {
+ // Is 'search' as same as 'index_home'?
+ if ($filterData['search'] == getIndexHome()) {
+ // Then set 'content' to link to index.php
+ $filterData['content'] = $filterData['prefix'] . '<strong><a class="you_are_here" href="{%url=index.php' . $filterData['link_add'] . '%}">' . getTitleFromMenu($filterData['access_level'], $filterData['search'], $filterData['type'], $filterData['add']) . '</a></strong>';
+ } // END - if
+ } // END - if
+
+ // Return data
+ return $filterData;
+}
+
+// Filter to add history entry
+function FILTER_ADD_HISTORY_ENTRY ($filterData) {
+ // Add the entry
+ SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_history` (`history_subject`, `history_userid`, `history_value`) VALUES ('%s',%s,'%s')",
+ $filterData,
+ __FUNCTION__, __LINE__);
+
+ // Remember insert id for other filters
+ $filterData['history_id'] = SQL_INSERTID();
+
+ // Return data
+ return $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());
+ } // END - if
+
+ // Init key
+ setConfigEntry('secret_key', '');
+
+ // Read key from secret file
+ if ((getFileHash() == '') || (getMasterSalt() == '') || (getPassScramble() == '')) {
+ // Maybe need setup of secret key!
+ loadIncludeOnce('inc/gen_sql_patches.php');
+ } // 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?
+ if (isFileReadable($hashFile)) {
+ // Read file
+ setConfigEntry('secret_key', readFromFile($hashFile));
+ } else {
+ // Remove it from database
+ updateConfiguration('file_hash', '');
+
+ // Cannot read secret file!
+ reportBug(__FILE__, __LINE__, 'Cannot read secret file! Please try to reload.');
+ }
+ } // END - if
+
+ // Return data
+ return $filterData;
+}
+
+// Filter to initialize session
+function FILTER_INIT_SESSION ($filterData) {
+ // Determine and set referral id
+ determineReferralId();
+
+ // Return data
+ return $filterData;
+}
+
+// Filter for sending "build mail" to admin
+function FILTER_SEND_BUILD_MAIL ($filterData) {
+ // Was one line updated?
+ if (($filterData['affected'] > 0) || (isDebugBuildMailsEnabled())) {
+ // Then call the proper function
+ call_user_func_array('sendGenericBuildMails', $filterData);
+ } // END - if
+
+ // Return data
+ return $filterData;
+}
+
+// Handles click on referral banner
+function FILTER_HANDLE_REFERRER_BANNER_CLICK ($filterData) {
+ // Check required parameters
+ if ((isGetRequestElementSet('user')) && (isGetRequestElementSet('banner'))) {
+ // Update clicks counter...
+ SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_refbanner` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1",
+ array(bigintval(getRequestElement('banner'))), __FUNCTION__, __LINE__);
+
+ // A line has been updated?
+ if ((!SQL_HASZEROAFFECTED()) && (isGetRequestElementSet('user'))) {
+ // Redirect to the user's referral link
+ redirectToUrl('ref.php?refid=' . bigintval(getRequestElement('user')));
+ } // END - if
+ } // END - if
+
+ // Return filter data
+ return $filterData;
+}
+
+// Filter for handling viewing of a referral banner
+function FILTER_HANDLE_REFERRER_BANNER_VIEW ($filterData) {
+ // Are all required parameters set
+ if ((isGetRequestElementSet('user')) && (isGetRequestElementSet('banner'))) {
+ // For later things... ;-)
+ $result = SQL_QUERY_ESC("SELECT `url` FROM `{?_MYSQL_PREFIX?}_refbanner` WHERE `id`=%s LIMIT 1",
+ array(bigintval(getRequestElement('banner'))), __FUNCTION__, __LINE__);
+
+ // Is there the banner?
+ if (SQL_NUMROWS($result) == 1) {
+ // Load the URL
+ $data = SQL_FETCHARRAY($result);
+
+ // Update counter
+ SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_refbanner` SET `counter`=`counter`+1 WHERE `id`=%s LIMIT 1",
+ array(bigintval(getRequestElement('banner'))), __FUNCTION__, __LINE__);
+
+ // Set header and ...
+ setContentType('image/' . substr($data['url'], -3, 3));
+
+ // Redirect
+ redirectToUrl($data['url'], FALSE);
+ } // END - if
+
+ // @TODO No banner found, output some default banner
+ logDebugMessage(__FUNCTION__, __LINE__, 'Banner ' . bigintval(getRequestElement('banner')) . ' not found.');
+
+ // Free memory
+ SQL_FREERESULT($result);
+ } // END - if
+
+ // Do nothing for now
+ redirectToUrl('modules.php?module=index');
+}
+
+// Filter for redirecting on wrong server name (e.g. bad.your-server.tld will be redirected to your-server.tld)
+function FILTER_REDIRECT_WRONG_SERVER_NAME ($filterData) {
+ // Get URL
+ $url = getUrl();
+
+ // Is the configured URL same as SERVER_NAME?
+ if (extractHostnameFromUrl($url) != detectServerName()) {
+ // Log all attempts
+ logWrongServerNameRedirect();
+
+ // Then redirect to configured URL
+ redirectToRequestUri();
+ } // END - if
+
+ // Return filter data
+ return $filterData;
+}
+
+// Filter for adding hidden session id
+function FILTER_ADD_INPUT_HIDDEN_SESSION_ID ($filterData) {
+ // Is a spider detected?
+ if ((!isSpider()) && (!isSessionValid()) && ($filterData['__form_method'] == 'get')) {
+ // No, then add the hidden field
+ $filterData['__replacer'] .= '<input type="hidden" name="' . session_name() . '" value="' . session_id() . '" />';
+ } // END - if
+
+ // Return filter data
+ return $filterData;
+}
+
+// Filter for purging old SERVER_NAME entries
+function FILTER_SERVER_NAME_EXTRA_AUTOPURGE ($filterData) {
+ // Is purging configured?
+ if ((isApServerNameEnabled()) && (getApServerNameSince() > 0)) {
+ // Then start purging
+ SQL_QUERY('DELETE LOW_PRIORITY FROM
+ `{?_MYSQL_PREFIX?}_server_name_log`
+WHERE
+ (UNIX_TIMESTAMP() - UNIX_TIMESTAMP(`server_name_added`)) >= {?ap_server_name_since?}',
+ __FILE__, __LINE__);
+
+ // Are some entries deleted?
+ if (SQL_AFFECTEDROWS() > 0) {
+ // Okay, then send an email to the admin
+ sendAdminNotification('{--ADMIN_PURGE_USER_SERVER_NAME_LOG_SUBJECT--}', 'admin_purge_user_server_name_log', SQL_AFFECTEDROWS());
+ } // END - if
+ } // END - if
+
+ // Return filter data
+ return $filterData;
+}
+