2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 12/16/2008 *
4 * =================== Last change: 12/16/2008 *
6 * -------------------------------------------------------------------- *
8 * -------------------------------------------------------------------- *
9 * Short description : Generic filters *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Allgemeine Filter *
12 * -------------------------------------------------------------------- *
13 * Copyright (c) 2003 - 2009 by Roland Haeder *
14 * Copyright (c) 2009 - 2013 by Mailer Developer Team *
15 * For more information visit: http://mxchange.org *
17 * This program is free software; you can redistribute it and/or modify *
18 * it under the terms of the GNU General Public License as published by *
19 * the Free Software Foundation; either version 2 of the License, or *
20 * (at your option) any later version. *
22 * This program is distributed in the hope that it will be useful, *
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
25 * GNU General Public License for more details. *
27 * You should have received a copy of the GNU General Public License *
28 * along with this program; if not, write to the Free Software *
29 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
31 ************************************************************************/
33 // Some security stuff...
34 if (!defined('__SECURITY')) {
38 // Filter for flushing all new filters to the database
39 function FILTER_FLUSH_FILTERS () {
40 // Clear all previous SQL queries
43 // Is a database link here and not in installation mode?
44 if ((!isSqlLinkUp()) && (!isInstaller())) {
46 reportBug(__FUNCTION__, __LINE__, 'No database link is up. Cannot flush filters.');
47 } elseif ((isInstaller()) && (!isSqlLinkUp())) {
48 // If the link is not up in installation phase, skip flushing filters
49 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot flush filters: No link is up.');
53 // Is the extension ext-sql_patches updated?
54 if (((!isExtensionInstalled('sql_patches')) || (isExtensionInstalledAndOlder('sql_patches', '0.5.9'))) && (!isInstaller())) {
55 // Log only in debug mode
56 if (isDebugModeEnabled()) {
57 logDebugMessage(__FUNCTION__, __LINE__, 'Cannot flush filters, ext-sql_patches might be missing. isExtensionInstalled()=' . intval(isExtensionInstalled('sql_patches')) . ',isExtensionInstalledAndOlder()=' . intval(isExtensionInstalledAndOlder('sql_patches', '0.5.9')));
60 // Abort silently here
64 // Nothing is added/remove by default
68 // Prepare SQL queries
69 $insertSQL = 'INSERT INTO `{?_MYSQL_PREFIX?}_filters` (`filter_name`, `filter_function`, `filter_active`) VALUES';
70 $removeSQL = 'DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_filters` WHERE';
72 // Write all filters to database
73 foreach ($GLOBALS['cache_array']['filter']['chains'] as $filterName => $filterArray) {
74 // Walk through all filters
75 foreach ($filterArray as $filterFunction => $active) {
76 // Is this filter loaded?
77 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'FOUND:'.$filterName.'/'.$filterFunction.'='.$active);
78 if (((!isset($GLOBALS['cache_array']['filter']['loaded'][$filterName][$filterFunction])) && ($active != 'R')) || ($active == 'A')) {
79 // Is this filter already in database?
80 if (countSumTotalData($filterFunction, 'filters', 'filter_name', 'filter_function', TRUE, sprintf(" AND `filter_name`='%s'", sqlEscapeString($filterName))) == 0) {
81 // Add this filter (all filters are active by default)
82 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ADD:'.$filterName.'/'.$filterFunction);
83 $insertSQL .= sprintf("('%s','%s','Y'),", $filterName, $filterFunction);
85 } elseif (isDebugModeEnabled()) {
86 // Log already registered filters
87 logDebugMessage(__FUNCTION__, __LINE__, 'Already registered: filterName=' . $filterName . ',filterFunction=' . $filterFunction . ',active=' . $active);
89 } elseif ($active == 'R') {
91 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'REMOVE:'.$filterName.'/'.$filterFunction);
92 $removeSQL .= sprintf(" (`filter_name`='%s' AND `filter_function`='%s') OR", $filterName, $filterFunction);
99 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'inserted=' . $inserted . ',removed=' . $removed . ' - AFTER COLLECTION');
101 // Something has been added?
103 // Finish SQL command and add it
104 addSql(substr($insertSQL, 0, -1));
107 // Something has been removed?
109 // Finish SQL command and add it
110 addSql(substr($removeSQL, 0, -2) . 'LIMIT ' . $removed);
113 // Shall we update usage counters (ONLY FOR DEBUGGING!)
114 if (isFilterUsageUpdateEnabled()) {
115 // Update all counters
116 foreach ($GLOBALS['cache_array']['filter']['counter'] as $filterName => $filterArray) {
117 // Walk through all filters
118 foreach ($filterArray as $filterFunction => $count) {
119 // Construct and add the query
120 addSql(sprintf("UPDATE `{?_MYSQL_PREFIX?}_filters` SET `filter_counter`=%s WHERE `filter_name`='%s' AND `filter_function`='%s' LIMIT 1",
129 // Run the run_sqls filter in non-dry mode
130 runFilterChain('run_sqls');
132 // Should we rebuild cache?
133 if (($inserted > 0) || ($removed > 0)) {
135 rebuildCache('filter', 'filter');
139 // Filter for calling the handler for login failures
140 function FILTER_CALL_HANDLER_LOGIN_FAILTURES ($filterData) {
142 $content = $filterData;
144 // Handle failed logins here if not in guest
145 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'type=' . $filterData['type'] . ',action=' . getAction() . ',what=' . getWhat() . ',level=' . $filterData['access_level']);
146 if ((($filterData['type'] == 'what') || ($filterData['type'] == 'action') && ((!isWhatSet()) || (getWhat() == 'welcome') || (getWhat() == getIndexHome()))) && ($filterData['access_level'] != 'guest') && ((isExtensionInstalledAndNewer('sql_patches', '0.4.7')) || (isExtensionInstalledAndNewer('admins', '0.7.6')))) {
148 $content['content'] .= handleLoginFailures($filterData['access_level']);
151 // Return the content
155 // Filter for auto-activation of a extension
156 function FILTER_AUTO_ACTIVATE_EXTENSION ($filterData) {
158 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $filterData['ext_name'] . ',isThisExtensionAlwaysActive()=' . intval(isThisExtensionAlwaysActive()));
160 // Is this extension always activated?
161 if (isThisExtensionAlwaysActive()) {
162 // Then activate the extension
163 doActivateExtension($filterData['ext_name']);
170 // Filter for solving task given task
171 function FILTER_SOLVE_TASK ($filterData) {
172 // Don't solve anything if no admin!
177 // Is this a direct task id or array element task_id is found?
178 if (is_int($filterData)) {
180 adminSolveTask($filterData);
181 } elseif ((is_array($filterData)) && (isset($filterData['task_id']))) {
183 adminSolveTask($filterData['task_id']);
186 reportBug(__FUNCTION__, __LINE__, sprintf('Cannot resolve task. data[%s]=<pre>%s</pre>', gettype($filterData), print_r($filterData, TRUE)));
193 // Filter to load include files
194 function FILTER_LOAD_INCLUDES ($filterData) {
196 if (is_null($filterData)) {
197 // This should not happen!
198 reportBug(__FUNCTION__, __LINE__, 'pool is null.');
201 // Is the pool an array and 'pool' set?
202 if ((is_array($filterData)) && (isset($filterData['pool']))) {
203 // Then use it as pool
204 $realPool = $filterData['pool'];
206 // Default is $data as inclusion list
207 $realPool = $filterData;
211 $data = getIncludePool($realPool);
214 if ((!isset($data)) || (!is_array($data))) {
216 reportBug(__FUNCTION__, __LINE__, sprintf('INC_POOL is no array! Type: %s', gettype($data)));
217 } elseif (isset($data['inc_pool'])) {
218 // Use this as new inclusion pool!
219 setIncludePool($realPool, $data['inc_pool']);
222 // Check for added include files
223 if (countIncludePool($realPool) > 0) {
224 // Loads every include file
225 loadIncludePool($realPool);
228 initIncludePool($realPool);
231 // Continue with processing
235 // Filter for running SQL commands
236 function FILTER_RUN_SQLS ($filterData) {
241 //* DEBUG: */ die('getSqls()=<pre>'.print_r(getSqls(), TRUE).'</pre>ext_update_depends=<pre>'.print_r($GLOBALS['ext_update_depends'], TRUE).'</pre>');
242 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '- Entered!');
244 // Is the array there?
245 if ((ifSqlsRegistered()) && ((!isset($filterData['dry_run'])) || ($filterData['dry_run'] == FALSE))) {
247 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '- Found ' . countSqls() . ' queries to run.');
248 foreach (getSqls() as $mode => $sqls) {
250 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'mode=' . $mode . ',count()=' . count($sqls));
252 // New cache format...
253 foreach ($sqls as $sql) {
257 // Is 'enable_codes' not set? Then set it to true
258 if (!isset($filterData['enable_codes'])) {
259 $filterData['enable_codes'] = TRUE;
262 // Is there still a query left?
264 // Is there an "ALTER TABLE" command? Exclude installation phase here as it would cause this query to fail
265 if ((substr(strtolower($sql), 0, 11) == 'alter table') && (!isset($filterData['ext_installing']))) {
266 // Analyse the alteration command
267 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Alterting table: ' . $sql . ',enable_codes=' . intval($filterData['enable_codes']));
268 sqlQueryAlterTable($sql, __FUNCTION__, __LINE__, $filterData['enable_codes']);
270 // Run regular SQL command
271 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Running regular query: ' . $sql . ',enable_codes=' . intval($filterData['enable_codes']));
272 sqlQuery($sql, __FUNCTION__, __LINE__, $filterData['enable_codes']);
275 // Has a line changed?
276 if (!ifSqlHasZeroAffectedRows()) {
277 // Add it to total account
278 $count += sqlAffectedRows();
286 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '- Left!');
292 // Filter for updating/validating login data
293 function FILTER_UPDATE_LOGIN_DATA () {
295 if ((!isset($GLOBALS['last_online'])) || (!is_array($GLOBALS['last_online']))) {
296 $GLOBALS['last_online'] = array();
299 // Recheck if logged in
300 if ((!isMember()) || ((isAdmin()) && (!isDebugModeEnabled()))) {
305 setMemberId(getSession('userid'));
308 if (fetchUserData(getMemberId())) {
309 // Load last module and online time
310 $content = getUserDataArray();
312 // Maybe first login time?
313 if (empty($content[getUserLastWhatName()])) {
314 $content[getUserLastWhatName()] = 'login';
317 // This will be displayed on welcome page! :-)
318 if (empty($GLOBALS['last_online']['module'])) {
319 $GLOBALS['last_online']['module'] = $content[getUserLastWhatName()];
320 $GLOBALS['last_online']['online'] = $content['last_online'];
327 if (getIndexHome() != '') {
328 setWhatFromConfig('index_home');
332 // Update last module / online time
333 updateLastActivity(getMemberId());
335 // Destroy session, we cannot update!
336 destroyMemberSession();
340 // Filter for initializing randomizer
341 function FILTER_INIT_RANDOMIZER () {
342 // Take a prime number which is long (if you know a longer one please try it out!)
343 setConfigEntry('_PRIME', 591623);
345 // Initialize array with all allowed chars
346 $GLOBALS['_abc'] = explode(',', 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,1,2,3,4,6,7,8,9,-,+,_,/,.');
348 // Only execute this filter if installed
349 if ((!isInstalled()) || (!isExtensionInstalledAndNewer('other', '0.2.5'))) {
351 setConfigEntry('_ADD', 0);
355 // Calculate "entropy" with the prime number (for code generation)
356 setConfigEntry('_ADD', (getPrime() * getPrime() / (pi() * getCodeLength() + 1)));
358 // Simply init the randomizer with seed and _ADD value
359 mt_srand(generateSeed() + getConfig('_ADD'));
362 // Filter for removing updates
363 function FILTER_REMOVE_UPDATES ($filterData) {
365 initExtensionRemovalList();
367 // Add the current extension to it
368 addCurrentExtensionToRemovalList();
371 unsetExtensionSqls();
373 // Are there update dependencies to remove?
374 if (countExtensionUpdateDependencies() > 0) {
375 // Then find all updates we shall no longer execute
376 foreach (getExtensionUpdateDependencies() as $id => $ext_name) {
377 // Shall we remove this update?
378 if (in_array($ext_name, getExtensionRemovalList())) {
379 // Then remove this extension!
380 removeExtensionDependency($ext_name);
389 // Determines username for current user state
390 function FILTER_DETERMINE_USERNAME () {
391 // Check if logged in
393 // Is still logged in so we welcome him with his name
394 if (fetchUserData(getMemberId())) {
395 // Load surname and family's name and build the username
396 $content = getUserDataArray();
399 setUsername($content['surname'] . ' ' . $content['family']);
401 // Additionally admin?
404 setUsername(getUsername() . ' ({--USERNAME_ADMIN_SHORT--})');
407 // Hmmm, logged in and no valid userid?
408 setUsername('<span class="bad">{--USERNAME_UNKNOWN--}</span>');
411 destroyMemberSession();
413 } elseif (isAdmin()) {
415 setUsername('{--USERNAME_ADMIN--}');
417 // He's a guest, hello there... ;-)
418 setUsername('{--USERNAME_GUEST--}');
422 // Filter for compiling config entries
423 function FILTER_COMPILE_CONFIG ($code, $compiled = FALSE) {
424 // Save the uncompiled code
428 if (!isset($GLOBALS['compiled_config'][$code])) {
429 // Compile {?some_var?} to getConfig('some_var')
430 preg_match_all('/\{\?(([a-zA-Z0-9-_]+)*)\?\}/', $code, $matches);
432 // Some entries found?
433 if ((isFilledArray($matches)) && (isFilledArray($matches[0]))) {
434 // Replace all matches
435 foreach ($matches[0] as $key => $match) {
437 if (!isset($GLOBALS['compile_config'][$matches[1][$key]])) {
438 // Is the config valid?
439 if (isConfigEntrySet($matches[1][$key])) {
440 // Set it for caching
441 $GLOBALS['compile_config'][$matches[1][$key]] = '{%config=' . $matches[1][$key] . '%}';
442 } elseif (isConfigEntrySet('default_' . strtoupper($matches[1][$key]))) {
444 $GLOBALS['compile_config'][$matches[1][$key]] = '{%config=' . 'DEFAULT_' . strtoupper($matches[1][$key]) . '%}';
445 } elseif (isMessageIdValid('DEFAULT_' . strtoupper($matches[1][$key]))) {
446 // No config, try the language system
447 $GLOBALS['compile_config'][$matches[1][$key]] = '{%message,DEFAULT_' . strtoupper($matches[1][$key]) . '%}';
450 $GLOBALS['compile_config'][$matches[1][$key]] = '!' . $matches[1][$key] . '!';
454 // Use this for replacing
455 $code = str_replace($match, $GLOBALS['compile_config'][$matches[1][$key]], $code);
456 //* DEBUG: */ if (($match == '{?URL?}') && (strlen($code) > 10000)) die(__FUNCTION__.'['.__LINE__.']:<pre>'.secureString($code).'</pre>');
461 $GLOBALS['compiled_config'][$uncompiled] = $code;
464 // Should we compile it?
465 if ($compiled === TRUE) {
467 $eval = "\$GLOBALS['compiled_config'][\$uncompiled] = \"" . $GLOBALS['compiled_config'][$uncompiled] . '";';
468 //* DEBUG: */ debugOutput(__FUNCTION__.'['.__LINE__.']:<pre>' . encodeEntities($eval) . '</pre>');
472 // Return compiled code
473 return $GLOBALS['compiled_config'][$uncompiled];
476 // Filter for compiling expression code
477 function FILTER_COMPILE_EXPRESSION_CODE ($filterData) {
478 // Compile {%cmd,callback,extraFunction=some_value%} to get expression code snippets
479 // See switch() command below for supported commands
480 preg_match_all('/\{%(([a-zA-Z0-9-_,]+)(=([^\}]+)){0,1})*%\}/', $filterData, $matches);
481 //* DEBUG: */ debugOutput(__FUNCTION__.'['.__LINE__.']:<pre>'.print_r($matches, TRUE).'</pre>');
483 // Default is from outputHtml()
484 $outputMode = getScriptOutputMode();
486 // Some entries found?
487 if ((isFilledArray($matches)) && (isFilledArray($matches[3]))) {
488 // Replace all matches
489 foreach ($matches[2] as $key => $eti) {
490 // Init replacer/call-back variable
494 $extraFunction2 = '';
497 // Extract command and call-back
498 $etiArray = explode(',', $eti);
501 // Detect call-back function
502 if (isset($etiArray[1])) {
503 // Call-back function detected
504 $callback = $etiArray[1];
507 // Detect extra function
508 if (isset($etiArray[2])) {
510 $extraFunction = $etiArray[2];
513 // Detect extra function 2
514 if (isset($etiArray[3])) {
516 $extraFunction2 = $etiArray[3];
520 if (isset($matches[4][$key])) {
522 $value = $matches[4][$key];
525 // Construct call-back function name for the command
526 $etiFunction = 'doExpression' . capitalizeUnderscoreString($eti);
528 // Is this function there?
529 if (function_exists($etiFunction)) {
530 // Prepare $matches, $key, $outputMode, etc.
532 'matches' => $matches,
534 'output_mode' => getScriptOutputMode(),
535 'code' => $filterData,
536 'callback' => $callback,
537 'extra_func' => $extraFunction,
538 'extra_func2' => $extraFunction2,
543 //* DEBUG: */ debugOutput(__FUNCTION__ . '[' . __LINE__ . ']: etiFunction=' . $etiFunction);
544 $filterData = call_user_func($etiFunction, $data);
546 // Unsupported command detected
547 logDebugMessage(__FUNCTION__, __LINE__, 'eti=' . $eti . ',etiFunction=' . $etiFunction . ',callback=' . $callback . ',extraFunction=' . $extraFunction . ',extraFunction2=' . $extraFunction2 . ' - UNSUPPORTED');
552 // Is there non-HTML/AJAX mode?
553 if ((!isHtmlOutputMode()) && (!isAjaxOutputMode())) {
554 $filterData = decodeEntities($filterData);
557 // Return compiled code
558 //* DEBUG: */ debugOutput(__FUNCTION__.'['.__LINE__.']:<pre>'.($filterData).'</pre>');
562 // Runs some generic filter update steps
563 function FILTER_UPDATE_EXTENSION_DATA ($ext_name) {
564 // Create task (we ignore the task id here)
565 createExtensionUpdateTask(getCurrentAdminId(), $ext_name, $GLOBALS['update_ver'][$ext_name], sqlEscapeString(getExtensionNotes(getExtensionNotes())));
567 // Update extension's version
568 sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_version`='%s' WHERE `ext_name`='%s' LIMIT 1",
569 array($GLOBALS['update_ver'][$ext_name], $ext_name), __FUNCTION__, __LINE__);
573 unset($GLOBALS['update_ver'][$ext_name]);
576 // Load more hourly reset scripts
577 function FILTER_RUN_HOURLY_INCLUDES () {
578 // Is the reset set or old sql_patches?
579 if (((!isHourlyResetEnabled()) || (!isExtensionInstalledAndNewer('sql_patches', '0.9.8'))) && (isHtmlOutputMode())) {
581 reportBug(__FUNCTION__, __LINE__, 'Cannot run hourly reset! enabled='.intval(isHourlyResetEnabled()).',isExtensionInstalledAndNewer='.intval(isExtensionInstalledAndNewer('sql_patches', '0.9.8')).' Please report this bug. Thanks');
584 // Is ext-sql_patches at least 0.9.8?
585 if (isExtensionInstalledAndNewer('sql_patches', '0.9.8')) {
587 if ((getLastHourly() != getHour()) || (isDebugHourlyEnabled())) {
588 // Get more hourly reset scripts
589 setIncludePool('hourly', getArrayFromDirectory('inc/hourly/', 'hourly_'));
592 runFilterChain('load_includes', 'hourly');
597 // Load more daily scripts
598 function FILTER_RUN_DAILY_INCLUDES () {
599 // Is the reset set or old sql_patches?
600 if (((!isDailyResetEnabled()) || (!isExtensionInstalledAndNewer('sql_patches', '0.9.8'))) && (isHtmlOutputMode())) {
602 reportBug(__FUNCTION__, __LINE__, 'Cannot run daily reset! enabled='.intval(isDailyResetEnabled()).',isExtensionInstalledAndNewer='.intval(isExtensionInstalledAndNewer('sql_patches', '0.9.8')).' Please report this bug. Thanks');
605 // Is ext-sql_patches at least 0.9.8?
606 if (isExtensionInstalledAndNewer('sql_patches', '0.9.8')) {
608 if ((getLastDaily() != getDay()) || (isDebugDailyEnabled())) {
609 // Get more daily reset scripts
610 setIncludePool('daily', getArrayFromDirectory('inc/daily/', 'daily_'));
613 runFilterChain('load_includes', 'daily');
618 // Load more weeklt scripts
619 function FILTER_RUN_WEEKLY_INCLUDES () {
620 // Is the reset set or old sql_patches?
621 if (((!isWeeklyResetEnabled()) || (!isExtensionInstalledAndNewer('sql_patches', '0.9.8'))) && (isHtmlOutputMode())) {
623 reportBug(__FUNCTION__, __LINE__, 'Cannot run weekly reset! enabled='.intval(isWeeklyResetEnabled()).',isExtensionInstalledAndNewer()='.intval(isExtensionInstalledAndNewer('sql_patches', '0.9.8')).' Please report this bug. Thanks');
626 // Is ext-sql_patches at least 0.9.8?
627 if (isExtensionInstalledAndNewer('sql_patches', '0.9.8')) {
629 if ((getLastWeekly() != getWeek()) || (isDebugWeeklyEnabled())) {
630 // Include weekly reset scripts
631 setIncludePool('weekly', getArrayFromDirectory('inc/weekly/', 'weekly_'));
634 runFilterChain('load_includes', 'weekly');
639 // Load more monthly scripts
640 function FILTER_RUN_MONTHLY_INCLUDES () {
641 // Is the reset set or old sql_patches?
642 if (((!isMonthlyResetEnabled()) || (!isExtensionInstalledAndNewer('sql_patches', '0.9.8'))) && (isHtmlOutputMode())) {
644 reportBug(__FUNCTION__, __LINE__, 'Cannot run monthly reset! enabled='.intval(isMonthlyResetEnabled()).',isExtensionInstalledAndNewer='.intval(isExtensionInstalledAndNewer('sql_patches', '0.9.8')).' Please report this bug. Thanks');
647 // Is ext-sql_patches at least 0.9.8?
648 if (isExtensionInstalledAndNewer('sql_patches', '0.9.8')) {
650 if ((getLastMonthly() != getMonth()) || (isDebugMonthlyEnabled())) {
651 // Include monthly reset scripts
652 setIncludePool('monthly', getArrayFromDirectory('inc/monthly/', 'monthly_'));
655 runFilterChain('load_includes', 'monthly');
660 // Load more yearly scripts
661 function FILTER_RUN_YEARLY_INCLUDES () {
662 // Is the reset set or old sql_patches?
663 if (((!isYearlyResetEnabled()) || (!isExtensionInstalledAndNewer('sql_patches', '0.9.8'))) && (isHtmlOutputMode())) {
665 reportBug(__FUNCTION__, __LINE__, 'Cannot run yearly reset! enabled='.intval(isYearlyResetEnabled()).',isExtensionInstalledAndNewer='.intval(isExtensionInstalledAndNewer('sql_patches', '0.9.8')).' Please report this bug. Thanks');
668 // Is ext-sql_patches at least 0.9.8?
669 if (isExtensionInstalledAndNewer('sql_patches', '0.9.8')) {
671 if ((getLastYearly() != getYear()) || (isDebugYearlyEnabled())) {
672 // Include yearly reset scripts
673 setIncludePool('yearly', getArrayFromDirectory('inc/yearly/', 'yearly_'));
676 runFilterChain('load_includes', 'yearly');
681 // Filter for removing the given extension
682 function FILTER_REMOVE_EXTENSION () {
683 // Delete this extension (remember to remove it from your server *before* you click on welcome!
684 sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
685 array(getCurrentExtensionName()), __FUNCTION__, __LINE__);
687 // Remove the extension from cache array as well
688 removeExtensionFromArray();
691 rebuildCache('extension', 'extension');
694 // Filter for flushing the output
695 function FILTER_FLUSH_OUTPUT () {
696 // Is this filter called?
697 if (isset($GLOBALS[__FUNCTION__])) {
699 reportBug(__FUNCTION__, __LINE__, 'Double call of ' . __FUNCTION__ . ' causes problems with sent headers.');
702 // Mark this filter as called
703 $GLOBALS[__FUNCTION__] = TRUE;
709 // Filter for determining what/action/module
710 function FILTER_DETERMINE_WHAT_ACTION () {
711 // In installation phase we don't have what/action
722 if ((!isCssOutputMode()) && (!isRawOutputMode())) {
724 if (!isModuleSet()) {
725 // Is the module registered?
726 if (!isModuleRegistered(getRequestElement('module'))) {
727 // Is not a valid module
728 redirectToUrl('modules.php?module=index');
731 // Is the request element set?
732 if (isGetRequestElementSet('module')) {
733 // Set module from request
734 setModule(getRequestElement('module'));
735 } elseif (isHtmlOutputMode()) {
736 // Set default module 'index'
740 setModule('unknown');
744 // Fix 'what' if not yet set
746 setWhat(getWhatFromModule(getModule()));
749 // Fix 'action' if not yet set
750 if (!isActionSet()) {
754 setAction(getActionFromModuleWhat(getModule(), getWhat()));
756 // Set action/what to empty
762 // Set action/what to empty
767 // Set default 'what' value
768 //* DEBUG: */ debugOutput('-' . getModule() . '/' . getWhat() . '-');
769 if ((!isWhatSet()) && (!isActionSet()) && (!isCssOutputMode()) && (!isRawOutputMode())) {
770 if (getModule() == 'admin') {
771 // Set 'action' value to 'login' in admin menu
772 setAction(getActionFromModuleWhat(getModule(), getWhat()));
773 } elseif ((getModule() == 'index') || (getModule() == 'login')) {
774 // Set 'what' value to 'welcome' in guest and member menu
775 setWhatFromConfig('index_home');
777 // Anything else like begging link
783 // Sends out pooled mails
784 function FILTER_TRIGGER_SENDING_POOL () {
785 // Are we in normal output mode?
786 if (!isHtmlOutputMode()) {
787 // Only in normal output mode to prevent race-conditons!
792 $GLOBALS['pool_cnt'] = '0';
794 // Init & set the include pool
795 initIncludePool('pool');
796 setIncludePool('pool', getArrayFromDirectory('inc/pool/', 'pool-'));
799 runFilterChain('load_includes', 'pool');
801 // Remove the counter
802 unset($GLOBALS['pool_cnt']);
805 // Filter for running hourly reset
806 function FILTER_RUN_HOURLY_RESET () {
807 // Only execute this filter if installed
808 if ((isInstaller()) || (!isInstalled()) || (!isAdminRegistered()) || (!isExtensionInstalledAndNewer('sql_patches', '0.9.8'))) {
812 // Shall we run the reset scripts? If a day has changed, maybe also a week/month has changed... Simple! :D
813 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getLastHourly()=' . getLastHourly() . ',getHour()=' . getHour());
814 if (((getLastHourly() != getHour()) || (isDebugHourlyEnabled())) && (!isInstaller()) && (isAdminRegistered()) && (!isGetRequestElementSet('setup')) && (!isCssOutputMode())) {
815 // Tell every module we are in reset-mode!
820 // Filter for running daily reset
821 function FILTER_RUN_DAILY_RESET () {
822 // Only execute this filter if installed
823 if ((isInstaller()) || (!isInstalled()) || (!isAdminRegistered()) || (!isExtensionInstalledAndNewer('sql_patches', '0.9.8'))) {
827 // Shall we run the reset scripts? If a day has changed, maybe also a week/month has changed... Simple! :D
828 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getLastDaily()=' . getLastDaily() . ',getDay()=' . getDay());
829 if (((getLastDaily() != getDay()) || (isDebugDailyEnabled())) && (!isInstaller()) && (isAdminRegistered()) && (!isGetRequestElementSet('setup')) && (!isCssOutputMode())) {
830 // Tell every module we are in reset-mode!
835 // Filter for running weekly reset
836 function FILTER_RUN_WEEKLY_RESET () {
837 // Only execute this filter if installed
838 if ((isInstaller()) || (!isInstalled()) || (!isAdminRegistered()) || (!isExtensionInstalledAndNewer('sql_patches', '0.9.8'))) {
842 // Shall we run the reset scripts? If a day has changed, maybe also a week/month has changed... Simple! :D
843 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getLastWeekly()=' . getLastWeekly() . ',getWeek()=' . getWeek());
844 if (((getLastWeekly() != getWeek()) || (isDebugWeeklyEnabled())) && (!isInstaller()) && (isAdminRegistered()) && (!isGetRequestElementSet('setup')) && (!isCssOutputMode())) {
845 // Tell every module we are in reset-mode!
850 // Filter for running monthly reset
851 function FILTER_RUN_MONTHLY_RESET () {
852 // Only execute this filter if installed
853 if ((isInstaller()) || (!isInstalled()) || (!isAdminRegistered()) || (!isExtensionInstalledAndNewer('sql_patches', '0.9.8'))) {
857 // Shall we run the reset scripts? If a day has changed, maybe also a week/month has changed... Simple! :D
858 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getLastMonthly()=' . getLastMonthly() . ',getMonth()=' . getMonth());
859 if (((getLastMonthly() != getMonth()) || (isDebugMonthlyEnabled())) && (!isInstaller()) && (isAdminRegistered()) && (!isGetRequestElementSet('setup')) && (!isCssOutputMode())) {
860 // Tell every module we are in reset-mode!
865 // Filter for running yearly reset
866 function FILTER_RUN_YEARLY_RESET () {
867 // Only execute this filter if installed
868 if ((isInstaller()) || (!isInstalled()) || (!isAdminRegistered()) || (!isExtensionInstalledAndNewer('sql_patches', '0.9.8'))) {
872 // Shall we run the reset scripts? If a day has changed, maybe also a week/month has changed... Simple! :D
873 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getLastYearly()=' . getLastYearly() . ',getYear()=' . getYear());
874 if (((getLastYearly() != getYear()) || (isDebugYearlyEnabled())) && (!isInstaller()) && (isAdminRegistered()) && (!isGetRequestElementSet('setup')) && (!isCssOutputMode())) {
875 // Tell every module we are in reset-mode!
880 // Filter for loading more runtime includes (not for installation)
881 function FILTER_LOAD_RUNTIME_INCLUDES () {
882 // Load more includes
883 foreach (array('databases', 'session') as $inc) {
885 loadIncludeOnce('inc/' . $inc . '.php');
889 // Filter for checking admin ACL
890 function FILTER_CHECK_ADMIN_ACL () {
891 // Extension not installed so it's always allowed to access everywhere!
894 // Ok, Cookie-Update done
895 if ((isExtensionInstalledAndNewer('admins', '0.3.0')) && (isExtensionActive('admins'))) {
896 // Check if action GET variable was set
897 $action = getAction();
899 // Get action value by what-value
900 $action = getActionFromModuleWhat('admin', getWhat());
903 // Check for access control line of current menu entry
904 $ret = isAdminsAllowedByAcl($action, getWhat());
908 $GLOBALS['acl_allow'] = $ret;
911 // Init random number/cache buster
912 function FILTER_INIT_RANDOM_NUMBER () {
913 // Is the extension ext-sql_patches installed and at least 0.3.6?
914 if (isSessionVariableSet('random_number')) {
916 setConfigEntry('RAND_NUMBER', getSession('random_number'));
917 } elseif ((isExtensionInstalledAndNewer('sql_patches', '0.3.6')) && (isExtensionInstalledAndNewer('other', '0.2.5'))) {
918 // Generate random number
919 setConfigEntry('RAND_NUMBER', generateRandomCode(10, mt_rand(10000, 99999), getMemberId(), ''));
921 // Generate *WEAK* code
922 setConfigEntry('RAND_NUMBER', mt_rand(1000000, 9999999));
925 // Set it in session for faster script execusion
926 setSession('random_number', getConfig('RAND_NUMBER'));
928 // Copy it to CACHE_BUSTER
929 setConfigEntry('CACHE_BUSTER', getConfig('RAND_NUMBER'));
932 // Update module counter
933 function FILTER_COUNT_MODULE () {
934 // Is installation phase or no admin registered?
935 if ((isInstaller()) || (!isInstalled()) || (!isAdminRegistered())) {
936 // Then don't count any modules
940 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getModule()=' . getModule() . ' - ENTERED!');
941 // Count module click
942 sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_mod_reg` SET `clicks`=`clicks`+1 WHERE `module`='%s' LIMIT 1",
943 array(getModule()), __FUNCTION__, __LINE__);
944 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getModule()=' . getModule() . ',sqlAffectedRows()=' . sqlAffectedRows() . ' - EXIT!');
947 // Handles fatal errors
948 function FILTER_HANDLE_FATAL_ERRORS () {
949 // Is there errors to handle and right output mode?
950 if ((!ifFatalErrorsDetected()) || (!isHtmlOutputMode())) {
951 // Abort executing here
956 setContentType('text/html');
959 loadIncludeOnce('inc/load_config.php');
961 // Default content is none
964 // Installation phase or regular mode?
965 if ((isInstaller())) {
966 // While we are installing ouput other header than while it is installed... :-)
968 foreach (getFatalArray() as $key => $value) {
969 // Prepare content for the template
976 $OUT .= loadTemplate('install_fatal_row', TRUE, $content);
979 // Load main template
980 $content = loadTemplate('install_fatal_table', TRUE, $OUT);
981 } elseif (isInstalled()) {
982 // Display all runtime fatal errors
984 foreach (getFatalArray() as $key => $value) {
985 // Prepare content for the template
992 $OUT .= loadTemplate('runtime_fatal_row', TRUE, $content);
995 // Load main template
996 $content = loadTemplate('runtime_fatal_table', TRUE, $OUT);
999 // Message to regular users (non-admin)
1000 $CORR = '{--FATAL_REPORT_ERRORS--}';
1002 // Maybe the admin wants to take a look?
1004 $CORR = '{--FATAL_CORRECT_ERRORS--}';
1007 // Remember all in array
1016 // Load main template
1017 loadTemplate('fatal_errors', FALSE, $content);
1019 // Delete all to prevent double-display
1020 initFatalMessages();
1029 // Filter for displaying copyright line
1030 function FILTER_DISPLAY_COPYRIGHT () {
1031 // Shall we display the copyright notice?
1032 if ((isFullPage()) && ((getWriteFooter() == 'Y') || (isInstalling())) && ($GLOBALS['__header_sent'] == 2) && (ifCopyrightFooterEnabled())) {
1033 // Backlink enabled?
1034 if (((isConfigEntrySet('ENABLE_BACKLINK')) && (getConfig('ENABLE_BACKLINK') == 'Y')) || (isInstalling())) {
1035 // Copyright with backlink, thanks! :-)
1036 $GLOBALS['__page_footer'] .= loadTemplate('copyright_backlink', TRUE);
1038 // No backlink in Copyright note
1039 $GLOBALS['__page_footer'] .= loadTemplate('copyright', TRUE);
1044 // Filter for displaying parsing time
1045 function FILTER_DISPLAY_PARSING_TIME () {
1046 // Shall we display the parsing time and number of queries?
1047 // 1234 5 54 4 554 4 5543 3 4432 2 332 2 21
1048 if ((((isExtensionInstalledAndNewer('sql_patches', '0.4.1')) && (isShowTimingsEnabled()) && (isFullPage())) && (!isInstaller())) && (isHtmlOutputMode()) && ($GLOBALS['__header_sent'] == 2)) {
1049 // Then display it here
1050 displayParsingTime();
1054 // Filter for flushing template cache
1055 function FILTER_FLUSH_TEMPLATE_CACHE () {
1056 // Do not flush when debugging the template cache
1057 if (isDebugTemplateCacheEnabled()) {
1058 // Do not flush templates in debug-mode
1062 // Is there cached eval() data?
1063 if ((isset($GLOBALS['template_eval'])) && (isFilledArray($GLOBALS['template_eval']))) {
1065 foreach ($GLOBALS['template_eval'] as $prefix => $templateArray) {
1066 foreach ($templateArray as $template => $eval) {
1067 // Flush the cache (if not yet found)
1068 flushTemplateCache($prefix, $template, $eval);
1074 // Filter for loading user data
1075 function FILTER_FETCH_USER_DATA ($userid = NULL) {
1076 // Is the userid not set?
1077 if (!isValidId($userid)) {
1078 // Then use member id
1079 $userid = getMemberId();
1083 if (!fetchUserData($userid)) {
1084 // Userid is not valid
1085 reportBug(__FUNCTION__, __LINE__, 'User id ' . $userid . ' is invalid.');
1089 setMemberId($userid);
1091 // Continue with next filter
1095 // Filter for reseting users' last login failure, only available with latest ext-sql_patches
1096 function FILTER_RESET_USER_LOGIN_FAILURE () {
1097 // Is the user data valid?
1099 // Do only run for logged in members
1100 reportBug(__FUNCTION__, __LINE__, 'Please only run this filter for logged in users.');
1103 // Remmeber login failures if available
1104 if (isExtensionInstalledAndNewer('user', '0.3.7')) {
1105 // Reset login failures
1106 sqlQueryEscaped("UPDATE
1107 `{?_MYSQL_PREFIX?}_user_data`
1114 array(getMemberId()), __FUNCTION__, __LINE__);
1116 // Store it in session
1117 setSession('mailer_member_failures' , getUserData('login_failures'));
1118 setSession('mailer_member_last_failure', getUserData('last_failure'));
1122 // Try to login the admin by setting some session/cookie variables
1123 function FILTER_DO_LOGIN_ADMIN ($filterData) {
1124 // Now set all session variables and store the result for later processing
1125 $GLOBALS['admin_login_success'] = ((
1126 setAdminMd5(encodeHashForCookie($filterData['pass_hash']))
1128 setAdminId($filterData['id'])
1130 setAdminLast(time())
1133 // Return the data for further processing
1137 // Filter for loading page header, this should be ran first!
1138 function FILTER_LOAD_PAGE_HEADER () {
1139 // Output page header code
1140 $GLOBALS['__page_header'] = loadTemplate('page_header', TRUE);
1142 // Include meta data in 'guest' module
1143 if (isModuleSet()) {
1144 // Load meta data template
1145 $GLOBALS['__page_header'] .= loadTemplate(getMenuModeFromModule() . '_metadata', TRUE);
1147 // Add meta description to header
1148 if ((isInstalled()) && (isAdminRegistered()) && (isSqlLinkUp()) && (getModule() == 'index')) {
1149 // Add meta description not in admin and login module and when the script is installed
1150 generateMetaDescriptionCode();
1155 // Filter for adding style sheet, closing page header
1156 function FILTER_FINISH_PAGE_HEADER () {
1157 // Include stylesheet
1158 loadIncludeOnce('inc/stylesheet.php');
1161 $GLOBALS['__page_header'] .= '</head>';
1164 // Cleans up the DNS cache if ext-sql_patches is at least 0.7.0
1165 function FILTER_CLEANUP_DNS_CACHE () {
1166 // Is the latest version installed?
1167 if (isExtensionInstalledAndNewer('sql_patches', '0.7.0')) {
1169 loadIncludeOnce('inc/classes/resolver.class.php');
1171 // Instance the resolver
1172 $resolver = new HostnameResolver();
1175 $resolver->purgeEntries();
1177 // Cute, isn't it? ;-)
1181 // Filter for setting CURRENT_DATE, this is required after initialization of extensions
1182 function FILTER_SET_CURRENT_DATE () {
1184 setConfigEntry('CURRENT_DATE', generateDateTime(time(), '3'));
1186 // Epoche time for yesterday, today ... all at 00:00 am
1187 setConfigEntry('START_YDAY', makeTime(0, 0, 0, time() - getOneDay()));
1188 setConfigEntry('START_TDAY', makeTime(0, 0, 0, time()));
1191 // Filter for marking extension as installed
1192 function FILTER_EXTENSION_MARK_INSTALLED ($filterData) {
1193 // Mark it as installed
1194 $GLOBALS['ext_is_installed'][$filterData['ext_name']] = TRUE;
1197 // Filter for generating mails links for 'pool' mails
1198 function FILTER_GENERATE_POOL_MAIL_LINKS ($filterData) {
1199 // Is type 'normal'?
1200 if ($filterData['type'] == 'normal') {
1202 $filterData['__output'] .= loadTemplate('admin_links_' . strtolower($filterData['mail_status']) . '_pool_mail', TRUE, $filterData);
1209 // Filter to activate exchange
1210 function FILTER_ACTIVATE_EXCHANGE () {
1211 // Are the extension ext-user/other there?
1212 if ((!isExtensionActive('user')) || (!isExtensionInstalled('other')) || (isAjaxOutputMode()) || (getActivateXchange() == '0')) {
1213 // Silently abort here
1217 // Check total amount of users
1218 if (getTotalConfirmedUser() >= getActivateXchange()) {
1220 addSql("UPDATE `{?_MYSQL_PREFIX?}_mod_reg` SET `locked`='N',`hidden`='N',`mem_only`='Y' WHERE `module`='order' LIMIT 1");
1221 addSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='Y',`locked`='N' WHERE `what`='order' OR `what`='unconfirmed' LIMIT 2");
1224 runFilterChain('run_sqls');
1226 // Update configuration
1227 updateConfiguration('activate_xchange' ,0);
1230 rebuildCache('modules', 'modules');
1234 // Filter to handle configuration
1235 function FILTER_HANDLE_HOME_IN_INDEX_SETTING ($filterData) {
1236 // Is ext-sql_patches up-to-date?
1237 if ((isExtensionInstalledAndNewer('sql_patches', '0.8.3')) && (isDisplayHomeInIndexEnabled())) {
1238 // Is 'search' as same as 'index_home'?
1239 if ($filterData['search'] == getIndexHome()) {
1240 // Then set 'content' to link to index.php
1241 $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>';
1249 // Filter to add history entry
1250 function FILTER_ADD_HISTORY_ENTRY ($filterData) {
1252 sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_history` (`history_subject`, `history_userid`, `history_value`) VALUES ('%s',%s,'%s')",
1254 __FUNCTION__, __LINE__);
1256 // Remember insert id for other filters
1257 $filterData['history_id'] = getSqlInsertId();
1263 // Filter for initializing ext-sql_patches
1264 function FILTER_GENERATE_FILE_SECRET_HASH ($filterData) {
1265 // Is ext-sql_patches installed and transfer POINTS word?
1266 if ((!isExtensionInstalled('sql_patches')) || (!isExtensionInstalledAndNewer('sql_patches', '0.9.0'))) {
1267 // Extension ext-sql_patches is missing, so better abort here
1271 // Okay, recent enough, so transfer the word for POINTS
1272 setConfigEntry('POINTS', getPointsWord());
1275 setConfigEntry('secret_key', '');
1277 // File hash was generated so we can also file the secret file... hopefully.
1278 $hashFile = getGenericHashFileName();
1280 // Read key from secret file
1281 if ((getFileHash() == '') || (getMasterSalt() == '') || (getPassScramble() == '') || (!isFileReadable($hashFile))) {
1282 // Maybe need setup of secret key!
1283 loadIncludeOnce('inc/gen_sql_patches.php');
1285 // Generate file name again
1286 $hashFile = getGenericHashFileName();
1290 if ((getFileHash() != '') && (getMasterSalt() != '') && (getPassScramble() != '')) {
1291 // Is the secret key file readable?
1292 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'hashFile=' . $hashFile);
1293 if (isFileReadable($hashFile)) {
1295 setConfigEntry('secret_key', readFromFile($hashFile));
1297 // Remove it from database
1298 updateConfiguration('file_hash', '', '', '0', TRUE);
1300 // Cannot read secret file!
1301 reportBug(__FILE__, __LINE__, 'Cannot read secret file! Please try to reload.');
1309 // Filter to initialize session
1310 function FILTER_INIT_SESSION ($filterData) {
1311 // Determine and set referral id
1312 determineReferralId();
1318 // Filter for sending "build mail" to admin
1319 function FILTER_SEND_BUILD_MAIL ($filterData) {
1320 // Was one line updated?
1321 if (($filterData['affected'] > 0) || (isDebugBuildMailsEnabled())) {
1322 // Then call the proper function
1323 call_user_func_array('sendGenericBuildMails', $filterData);
1330 // Handles click on referral banner
1331 function FILTER_HANDLE_REFERRER_BANNER_CLICK ($filterData) {
1332 // Check required parameters
1333 if ((isGetRequestElementSet('user')) && (isGetRequestElementSet('banner'))) {
1334 // Update clicks counter...
1335 sqlQueryEscaped('UPDATE `{?_MYSQL_PREFIX?}_refbanner` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1',
1336 array(bigintval(getRequestElement('banner'))), __FUNCTION__, __LINE__);
1338 // A line has been updated?
1339 if ((!ifSqlHasZeroAffectedRows()) && (isGetRequestElementSet('user'))) {
1340 // Redirect to the user's referral link
1341 redirectToUrl('ref.php?refid=' . bigintval(getRequestElement('user')));
1345 // Return filter data
1349 // Filter for handling viewing of a referral banner
1350 function FILTER_HANDLE_REFERRER_BANNER_VIEW ($filterData) {
1351 // Are all required parameters set
1352 if ((isGetRequestElementSet('user')) && (isGetRequestElementSet('banner'))) {
1353 // For later things... ;-)
1354 $result = sqlQueryEscaped('SELECT `url` FROM `{?_MYSQL_PREFIX?}_refbanner` WHERE `id`=%s LIMIT 1',
1355 array(bigintval(getRequestElement('banner'))), __FUNCTION__, __LINE__);
1357 // Is there the banner?
1358 if (sqlNumRows($result) == 1) {
1360 $data = sqlFetchArray($result);
1363 sqlQueryEscaped('UPDATE `{?_MYSQL_PREFIX?}_refbanner` SET `counter`=`counter`+1 WHERE `id`=%s LIMIT 1',
1364 array(bigintval(getRequestElement('banner'))), __FUNCTION__, __LINE__);
1366 // Set header and ...
1367 setContentType('image/' . substr($data['url'], -3, 3));
1370 redirectToUrl($data['url'], FALSE);
1373 // @TODO No banner found, output some default banner
1374 logDebugMessage(__FUNCTION__, __LINE__, 'Banner ' . bigintval(getRequestElement('banner')) . ' not found.');
1377 sqlFreeResult($result);
1380 // Do nothing for now
1381 redirectToUrl('modules.php?module=index');
1384 // Filter for redirecting on wrong server name (e.g. bad.your-server.tld will be redirected to your-server.tld)
1385 function FILTER_REDIRECT_WRONG_SERVER_NAME ($filterData) {
1389 // Is the configured URL same as SERVER_NAME?
1390 if (extractHostnameFromUrl($url) != detectServerName()) {
1392 logWrongServerNameRedirect();
1394 // Then redirect to configured URL
1395 redirectToRequestUri();
1398 // Return filter data
1402 // Filter for adding hidden session id
1403 function FILTER_ADD_INPUT_HIDDEN_SESSION_ID ($filterData) {
1404 // Is a spider detected?
1405 if ((!isSpider()) && (!isValidSession()) && ($filterData['__form_method'] == 'get')) {
1406 // No, then add the hidden field
1407 $filterData['__replacer'] .= '<input type="hidden" name="' . session_name() . '" value="' . session_id() . '" />';
1410 // Return filter data
1414 // Filter for purging old SERVER_NAME entries
1415 function FILTER_SERVER_NAME_EXTRA_AUTOPURGE ($filterData) {
1416 // Is purging configured?
1417 if ((isApServerNameEnabled()) && (getApServerNameSince() > 0)) {
1418 // Then start purging
1419 sqlQuery('DELETE LOW_PRIORITY FROM
1420 `{?_MYSQL_PREFIX?}_server_name_log`
1422 (UNIX_TIMESTAMP() - UNIX_TIMESTAMP(`server_name_added`)) >= {?ap_server_name_since?}',
1423 __FILE__, __LINE__);
1425 // Are some entries deleted?
1426 if (sqlAffectedRows() > 0) {
1427 // Okay, then send an email to the admin
1428 sendAdminNotification('{--ADMIN_PURGE_USER_SERVER_NAME_LOG_SUBJECT--}', 'admin_purge_user_server_name_log', sqlAffectedRows());
1432 // Return filter data
1436 // Filter for detecting menu mode
1437 function FILTER_DETERMINE_MENU_MODE_GENERIC ($filterData) {
1439 switch (getModule()) {
1440 case 'chk_login': // Is also faked
1441 case 'confirm': // Login script is 'member'
1442 case 'loader': // Is faked to 'member' to avoid indexing by search engines
1443 case 'mailid': // Mail confirmation is 'member'
1444 $filterData = 'member';
1448 // Return filter data
1452 // Filter to exclude default referral id
1453 function FILTER_EXCLUDE_DEFAULT_REFID ($filterData = array()) {
1455 if (isValidId(getDefRefid())) {
1457 array_push($filterData, '{?def_refid?}');