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 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * Needs to be in all Files and every File needs "svn propset *
18 * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
19 * -------------------------------------------------------------------- *
20 * Copyright (c) 2003 - 2009 by Roland Haeder *
21 * For more information visit: http://www.mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
44 // Filter for flushing all new filters to the database
45 function FILTER_FLUSH_FILTERS () {
46 // Clear all previous SQL queries
50 if ((isInstallationPhase())) {
51 // Then silently skip this filter
55 // Is a database link here and not in installation mode?
56 if ((!SQL_IS_LINK_UP()) && (!isInstalling())) {
58 addFatalMessage(__FUNCTION__, __LINE__, getMessage('FILTER_FLUSH_FAILED_NO_DATABASE'));
62 // Is the extension sql_patches updated?
63 if ((!isExtensionInstalled('sql_patches')) || (isExtensionInstalledAndOlder('sql_patches', '0.5.9'))) {
64 // Abort silently here
68 // Nothing is added/remove by default
72 // Prepare SQL queries
73 $insertSQL = "INSERT INTO `{?_MYSQL_PREFIX?}_filters` (`filter_name`,`filter_function`,`filter_active`) VALUES";
74 $removeSQL = "DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_filters` WHERE";
76 // Write all filters to database
77 foreach ($GLOBALS['cache_array']['filter']['chains'] as $filterName => $filterArray) {
78 // Walk through all filters
79 foreach ($filterArray as $filterFunction => $active) {
80 // Is this filter loaded?
81 //* DEBUG: */ print 'FOUND:'.$filterName.'/'.$filterFunction.'='.$active.'<br />';
82 if (((!isset($GLOBALS['cache_array']['filter']['loaded'][$filterName][$filterFunction])) && ($active != 'R')) || ($active == 'A')) {
83 // Add this filter (all filters are active by default)
84 //* DEBUG: */ print 'ADD:'.$filterName.'/'.$filterFunction.'<br />';
85 $insertSQL .= sprintf("('%s','%s','Y'),", $filterName, $filterFunction);
87 } elseif ($active == 'R') {
89 //* DEBUG: */ print 'REMOVE:'.$filterName.'/'.$filterFunction.'<br />';
90 $removeSQL .= sprintf(" (`filter_name`='%s' AND `filter_function`='%s') OR", $filterName, $filterFunction);
96 // Something has been added?
98 // Finish SQL command and add it
99 addSql(substr($insertSQL, 0, -1));
102 // Something has been removed?
104 // Finish SQL command and add it
105 addSql(substr($removeSQL, 0, -2) . 'LIMIT ' . $removed);
108 // Shall we update usage counters (ONLY FOR DEBUGGING!)
109 if (getConfig('update_filter_usage') == 'Y') {
110 // Update all counters
111 foreach ($GLOBALS['cache_array']['filter']['counter'] as $filterName => $filterArray) {
112 // Walk through all filters
113 foreach ($filterArray as $filterFunction => $cnt) {
114 // Construct and add the query
115 addSql(sprintf("UPDATE `{?_MYSQL_PREFIX?}_filters` SET `filter_counter`=%s WHERE `filter_name`='%s' AND `filter_function`='%s' LIMIT 1",
124 // Run the run_sqls filter in non-dry mode
125 runFilterChain('run_sqls');
127 // Should we rebuild cache?
128 if (($inserted > 0) || ($removed > 0)) {
130 rebuildCacheFile('filter', 'filter');
134 // Filter for calling the handler for login failures
135 function FILTER_CALL_HANDLER_LOGIN_FAILTURES ($data) {
139 // Handle failed logins here if not in guest
140 //* DEBUG: */ outputHtml(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):type={$data['type']},action={getAction()},what={getWhat()},level={$data['access_level']}<br />");
141 if ((($data['type'] == 'what') || ($data['type'] == 'action') && ((!isWhatSet()) || (getWhat() == 'overview') || (getWhat() == getConfig('index_home')))) && ($data['access_level'] != 'guest') && ((isExtensionInstalledAndNewer('sql_patches', '0.4.7')) || (isExtensionInstalledAndNewer('admins', '0.7.0')))) {
143 $content['content'] .= handleLoginFailtures($data['access_level']);
146 // Return the content
150 // Filter for redirecting to logout if sql_patches has been installed
151 function FILTER_REDIRECT_TO_LOGOUT_SQL_PATCHES () {
152 // Remove this filter
153 unregisterFilter('shutdown', __FUNCTION__);
155 // Is the element set?
156 if (isset($GLOBALS['ext_load_mode'])) {
158 redirectToUrl('modules.php?module=admin&logout=1&' . $GLOBALS['ext_load_mode'] . '=sql_patches');
161 // This should not happen!
162 logDebugMessage(__FUNCTION__, __LINE__, 'Cannot auto-logout because no extension load-mode has been set.');
165 // Filter for auto-activation of a extension
166 function FILTER_AUTO_ACTIVATE_EXTENSION ($data) {
167 // Is this extension always activated?
168 if (getExtensionAlwaysActive() == 'Y') {
169 // Then activate the extension
170 //* DEBUG: */ outputHtml(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): ext_name={$data['ext_name']}<br />");
171 doActivateExtension($data['ext_name']);
178 // Filter for solving task given task
179 function FILTER_SOLVE_TASK ($data) {
180 // Don't solve anything if no admin!
181 if (!isAdmin()) return $data;
183 // Is this a direct task id or array element task_id is found?
186 adminSolveTask($data);
187 } elseif ((is_array($data)) && (isset($data['task_id']))) {
189 adminSolveTask($data['task_id']);
192 debug_report_bug(sprintf("Cannot resolve task. data[%s]=<pre>%s</pre>", gettype($data), print_r($data, true)));
199 // Filter to load include files
200 function FILTER_LOAD_INCLUDES ($pool) {
202 if (is_null($pool)) {
203 // This should not happen!
204 debug_report_bug('pool is null.');
207 // Is the pool an array and 'pool' set?
208 if ((is_array($pool)) && (isset($pool['pool']))) {
209 // Then use it as pool
210 $realPool = $pool['pool'];
212 // Default is $data as inclusion list
217 $data = getIncludePool($realPool);
220 if ((!isset($data)) || (!is_array($data))) {
222 debug_report_bug(sprintf("INC_POOL is no array! Type: %s", gettype($data)));
223 } elseif (isset($data['inc_pool'])) {
224 // Use this as new inclusion pool!
225 setIncludePool($realPool, $data['inc_pool']);
228 // Check for added include files
229 if (countIncludePool($realPool) > 0) {
230 // Loads every include file
231 loadIncludePool($realPool);
234 initIncludePool($realPool);
237 // Continue with processing
241 // Filter for running SQL commands
242 function FILTER_RUN_SQLS ($data) {
244 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "- Entered!");
246 // Is the array there?
247 if ((isSqlsValid()) && ((!isset($data['dry_run'])) || ($data['dry_run'] == false))) {
249 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "- Found ".countSqls()." queries to run.");
250 foreach (getSqls() as $sqls) {
251 // New cache format...
252 foreach ($sqls as $sql) {
256 // Is there still a query left?
258 // Do we have an "ALTER TABLE" command?
259 if (substr(strtolower($sql), 0, 11) == 'alter table') {
260 // Analyse the alteration command
261 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "Alterting table: {$sql}");
262 SQL_ALTER_TABLE($sql, __FUNCTION__, __LINE__);
264 // Run regular SQL command
265 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "Running regular query: {$sql}");
266 SQL_QUERY($sql, __FUNCTION__, __LINE__, false);
274 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "- Left!");
277 // Filter for updating/validating login data
278 function FILTER_UPDATE_LOGIN_DATA () {
280 if ((!isset($GLOBALS['last_online'])) || (!is_array($GLOBALS['last_online']))) $GLOBALS['last_online'] = array();
282 // Recheck if logged in
283 if (!isMember()) return false;
286 setMemberId(getSession('userid'));
289 if (fetchUserData(getMemberId())) {
290 // Load last module and online time
291 $content = getUserDataArray();
293 // Maybe first login time?
294 if (empty($content['last_module'])) $content['last_module'] = 'login';
296 // This will be displayed on welcome page! :-)
297 if (empty($GLOBALS['last_online']['module'])) {
298 $GLOBALS['last_online']['module'] = $content['last_module'];
299 $GLOBALS['last_online']['online'] = $content['last_online'];
306 if (getConfig('index_home') != '') setWhatFromConfig('index_home');
309 // Update last module / online time
310 updateLastActivity(getMemberId());
312 // Destroy session, we cannot update!
313 destroyMemberSession();
317 // Filter for initializing randomizer
318 function FILTER_INIT_RANDOMIZER () {
319 // Only execute this filter if installed
320 if ((!isInstalled()) || (!isExtensionInstalledAndNewer('other', '0.2.5'))) return;
322 // Take a prime number which is long (if you know a longer one please try it out!)
323 setConfigEntry('_PRIME', 591623);
325 // Calculate "entropy" with the prime number (for code generation)
326 setConfigEntry('_ADD', (getConfig('_PRIME') * getConfig('_PRIME') / (pi() * getConfig('code_length') + 1)));
328 // Simply init the randomizer with seed and _ADD value
329 mt_srand(generateSeed() + getConfig('_ADD'));
332 // Filter for removing updates
333 function FILTER_REMOVE_UPDATES ($data) {
335 initExtensionRemovalList();
337 // Add the current extension to it
338 addCurrentExtensionToRemovalList();
341 unsetExtensionSqls();
343 // Do we need to remove update depency?
344 if (countExtensionUpdateDependencies() > 0) {
345 // Then find all updates we shall no longer execute
346 foreach (getExtensionUpdateDependencies() as $id => $ext_name) {
347 // Shall we remove this update?
348 if (in_array($ext_name, getExtensionRemovalList())) {
349 // Then remove this extension!
350 removeExtensionUpdateDependency($ext_name);
359 // Determines username for current user state
360 function FILTER_DETERMINE_USERNAME () {
361 // Check if logged in
363 // Is still logged in so we welcome him with his name
364 if (fetchUserData(getMemberId())) {
365 // Load surname and family's name and build the username
366 $content = getUserDataArray();
369 setUsername($content['surname'] . ' ' . $content['family']);
371 // Additionally admin?
374 setUsername(getUsername() . ' ({--USERNAME_ADMIN_SHORT--})');
377 // Hmmm, logged in and no valid userid?
378 setUsername('<em>{--USERNAME_UNKNOWN--}</em>');
381 destroyMemberSession();
383 } elseif (isAdmin()) {
385 setUsername('{--USERNAME_ADMIN--}');
387 // He's a guest, hello there... ;-)
388 setUsername('{--USERNAME_GUEST--}');
392 // Filter for compiling config entries
393 function FILTER_COMPILE_CONFIG ($code, $compiled = false) {
394 // Save the uncompiled code
398 if (!isset($GLOBALS['compiled_config'][$code])) {
399 // Compile {?some_var?} to getConfig('some_var')
400 preg_match_all('/\{\?(([a-zA-Z0-9-_]+)*)\?\}/', $code, $matches);
402 // Some entries found?
403 if ((count($matches) > 0) && (count($matches[0]) > 0)) {
404 // Replace all matches
405 foreach ($matches[0] as $key => $match) {
407 if (!isset($GLOBALS['compile_config'][$matches[1][$key]])) {
408 // Is the config valid?
409 if (isConfigEntrySet($matches[1][$key])) {
410 // Set it for caching
411 $GLOBALS['compile_config'][$matches[1][$key]] = "\".getConfig('" . $matches[1][$key] . "').\"";
412 } elseif (isConfigEntrySet('default_' . strtoupper($matches[1][$key]))) {
414 $GLOBALS['compile_config'][$matches[1][$key]] = "\".getConfig('" . 'DEFAULT_' . strtoupper($matches[1][$key]) . "').\"";
415 } elseif (isMessageIdValid('DEFAULT_' . strtoupper($matches[1][$key]))) {
416 // No config, try the language system
417 $GLOBALS['compile_config'][$matches[1][$key]] = "\" . getMessage('". 'DEFAULT_' . strtoupper($matches[1][$key]) . "') . \"";
420 $GLOBALS['compile_config'][$matches[1][$key]] = '!' . $matches[1][$key] . '!';
424 // Use this for replacing
425 $code = str_replace($match, $GLOBALS['compile_config'][$matches[1][$key]], $code);
426 //* DEBUG: */ if (($match == '{?URL?}') && (strlen($code) > 10000)) die('<pre>'.secureString($code).'</pre>');
431 $GLOBALS['compiled_config'][$uncompiled] = $code;
434 // Should we compile it?
435 if ($compiled === true) {
437 $eval = "\$GLOBALS['compiled_config'][\$uncompiled] = \"" . $GLOBALS['compiled_config'][$uncompiled] . "\";";
438 //* DEBUG: */ print('<pre>' . str_replace('$', '$', htmlentities($eval)) . '</pre>');
442 // Return compiled code
443 return $GLOBALS['compiled_config'][$uncompiled];
446 // Filter for compiling extension data
447 function FILTER_COMPILE_EXTENSION ($code) {
448 // Compile {%cmd=some_value%} to get extension data
450 // - version -> getExtensionVersion() call
451 preg_match_all('/\{%(([a-zA-Z0-9-_,]+)(=([^\}]+)){0,1})*%\}/', $code, $matches);
452 //* DEBUG: */ print('<pre>'.print_r($matches, true).'</pre>');
454 // Default is from OUTPUT_HTML
455 $outputMode = getOutputMode();
457 // Some entries found?
458 if ((count($matches) > 0) && (count($matches[3]) > 0)) {
459 // Replace all matches
460 foreach ($matches[2] as $key => $cmd) {
461 // Init replacer variable
464 // Is the extension installed or code provided?
465 // @TODO This whole if-block is very static
466 if ($cmd == 'code') {
468 $code = str_replace($matches[0][$key], "\" . getCode('" . $matches[4][$key] . "') . \"", $code);
469 } elseif (substr($cmd, 0, 3) == 'url') {
470 // Do we have JS-mode?
471 if (substr($cmd, -2, 2) == 'js') $outputMode = 1;
473 // Handle an URL here
474 $replacer = "\" . encodeUrl(\"" . $matches[4][$key] . "\", " . $outputMode . ") . \"";
477 $code = str_replace($matches[0][$key], $replacer, $code);
478 } elseif (substr($cmd, 0, 6) == 'server') {
479 // Get data from $_SERVER by their respective functions
480 $serverCmd = explode(',', $cmd);
481 $serverCmd = $serverCmd[1];
483 // This will make 'foo_bar' to detectFooBar()
484 $functionName = "'detect' . implode('', array_map('ucfirst', explode('_', '" . $serverCmd . "')))";
487 $code = str_replace($matches[0][$key], "\" . call_user_func(" . $functionName . ") . \"", $code);
488 } elseif (substr($cmd, 0, 4) == 'user') {
489 // Extract user command
490 $userCmdArray = explode(',', $cmd);
491 $userCmd = $userCmdArray[1];
493 // Use current userid by default
494 $functionName = 'getMemberId()';
496 // User-related data, so is there a userid?
497 if (!empty($matches[4][$key])) {
498 // Do we have a userid or $userid?
499 if ($matches[4][$key] == '$userid') {
501 $functionName = "getFetchedUserData('userid', \$userid, '" . $userCmd . "')";
502 } elseif ($matches[4][$key] > 0) {
504 $functionName = "getFetchedUserData('userid', " . $matches[4][$key] . ", " . $userCmd . "')";
508 // Do we have another function to run (e.g. translations)
509 if (isset($userCmdArray[2])) {
510 // Surround the original function call with it
511 $functionName = $userCmdArray[2] . '(' . $functionName . ')';
514 // Now replace the code
515 $code = str_replace($matches[0][$key], "\" . " . $functionName . " . \"", $code);
516 } elseif (substr($cmd, 0, 3) == 'ext') {
517 // Get the extension command
518 $extCmd = explode(',', $cmd);
519 $extCmd = $extCmd[1];
521 // Construct call-back function name
522 $functionName = 'getExtension' . ucfirst(strtolower($extCmd));
524 // Construct call of the function
525 $replacer = "\" . call_user_func_array('" . $functionName . "', array('" . $matches[4][$key] . "', true)) . \"";
527 // Replace it and insert parameter for GET request
528 $code = str_replace($matches[0][$key], sprintf("&ext=%s&rev=\" . getConfig('CURR_SVN_REVISION') . \"", $replacer), $code);
530 // Unknown command detected
531 debug_report_bug('Unknown command ' . $cmd . ' detected.');
536 // Do we have non-HTML mode?
537 if ((getOutputMode() != '0') || ($outputMode != '0')) $code = html_entity_decode($code);
539 // Return compiled code
540 //* DEBUG: */ die('<pre>'.htmlentities($code).'</pre>');
544 // Runs some generic filter update steps
545 function FILTER_UPDATE_EXTENSION_DATA ($ext_name) {
547 createExtensionUpdateTask(getCurrentAdminId(), $ext_name, $GLOBALS['update_ver'][$ext_name], SQL_ESCAPE(getExtensionNotes(getExtensionNotes())));
549 // Update extension's version
550 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_version`='%s' WHERE `ext_name`='%s' LIMIT 1",
551 array($GLOBALS['update_ver'][$ext_name], $ext_name), __FUNCTION__, __LINE__);
555 unset($GLOBALS['update_ver'][$ext_name]);
558 // Load more reset scripts
559 function FILTER_RUN_RESET_INCLUDES () {
560 // Is the reset set or old sql_patches?
561 if (((!isResetModeEnabled()) || (!isExtensionInstalled('sql_patches'))) && (getOutputMode() == '0')) {
563 logDebugMessage(__FUNCTION__, __LINE__, 'Cannot run reset! Please report this bug. Thanks');
566 // Get more daily reset scripts
567 setIncludePool('reset', getArrayFromDirectory('inc/reset/', 'reset_'));
570 if ((!isConfigEntrySet('DEBUG_RESET')) || (getConfig('DEBUG_RESET') != 'Y')) updateConfiguration('last_update', 'UNIX_TIMESTAMP()');
572 // Is the config entry set?
573 if (isExtensionInstalledAndNewer('sql_patches', '0.4.2')) {
574 // Create current week mark
575 $currWeek = date('W', time());
578 if ((getConfig('last_week') != $currWeek) || (getConfig('DEBUG_WEEKLY') == 'Y')) {
579 // Include weekly reset scripts
580 mergeIncludePool('reset', getArrayFromDirectory('inc/weekly/', 'weekly_'));
583 if ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') != 'Y')) updateConfiguration('last_week', $currWeek);
586 // Create current month mark
587 $currMonth = date('m', time());
590 if ((getConfig('last_month') != $currMonth) || (getConfig('DEBUG_MONTHLY') == 'Y')) {
591 // Include monthly reset scripts
592 mergeIncludePool('reset', getArrayFromDirectory('inc/monthly/', 'monthly_'));
595 if ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') != 'Y')) updateConfiguration('last_month', $currMonth);
600 runFilterChain('load_includes', 'reset');
603 // Filter for removing the given extension
604 function FILTER_REMOVE_EXTENSION () {
605 // Delete this extension (remember to remove it from your server *before* you click on welcome!
606 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
607 array(getCurrentExtensionName()), __FUNCTION__, __LINE__);
609 // Remove the extension from global cache array as well
610 removeExtensionFromArray();
613 rebuildCacheFile('extension', 'extension');
616 // Filter for flushing the output
617 function FILTER_FLUSH_OUTPUT () {
622 // Prepares an SQL statement part for HTML mail and/or holiday depency
623 function FILTER_HTML_INCLUDE_USERS ($mode) {
624 // Exclude no users by default
628 if ($mode == 'html') $MORE = " AND `html`='Y'";
629 if ((isExtensionActive('holiday')) && (getExtensionVersion('holiday') >= '0.1.3')) {
630 // Add something for the holiday extension
631 $MORE .= " AND `holiday_active`='N'";
638 // Filter for determining what/action/module
639 function FILTER_DETERMINE_WHAT_ACTION () {
640 // In installation phase we don't have what/action
641 if (isInstallationPhase()) {
651 if ((getOutputMode() != 1) && (getOutputMode() != -1)) {
653 if (!isModuleSet()) {
654 // Is the request element set?
655 if (isGetRequestElementSet('module')) {
656 // Set module from request
657 setModule(getRequestElement('module'));
658 } elseif (getOutputMode() == '0') {
659 // Set default module 'index'
663 setModule('unknown');
667 // Fix 'what' if not yet set
668 if (!isWhatSet()) setWhat(getWhatFromModule(getModule()));
670 // Fix 'action' if not yet set
671 if (!isActionSet()) setAction(getModeAction(getModule(), getWhat()));
673 // Set action/what to empty
678 // Set default 'what' value
679 //* DEBUG: */ outputHtml('-'.getModule().'/'.getWhat()."-<br />");
680 if ((!isWhatSet()) && (!isActionSet()) && (getOutputMode() != 1) && (getOutputMode() != -1)) {
681 if (getModule() == 'admin') {
682 // Set 'action' value to 'login' in admin menu
683 setAction(getModeAction(getModule(), getWhat()));
684 } elseif ((getModule() == 'index') || (getModule() == 'login')) {
685 // Set 'what' value to 'welcome' in guest and member menu
686 setWhatFromConfig('index_home');
688 // Anything else like begging link
694 // Sends out pooled mails
695 function FILTER_TRIGGER_SENDING_POOL () {
696 // Are we in normal output mode?
697 if (getOutputMode() != 0) {
698 // Only in normal output mode to prevent race-conditons!
702 $GLOBALS['pool_cnt'] = '0';
704 // Init & set the include pool
705 initIncludePool('pool');
706 setIncludePool('pool', getArrayFromDirectory('inc/pool/', 'pool-'));
709 runFilterChain('load_includes', 'pool');
711 // Remove the counter
712 unset($GLOBALS['pool_cnt']);
715 // Filter for checking and updating SVN revision
716 function FILTER_CHECK_SVN_REVISION () {
717 // Only execute this filter if installed and all config entries are there
718 if ((!isInstalled()) || (!isConfigEntrySet('patch_level'))) return;
720 // Check for patch level differences between databases and current hard-coded
721 if ((getConfig('CURR_SVN_REVISION') > getConfig('patch_level')) || (getConfig('patch_level') == 'CURR_SVN_REVISION') || (getConfig('patch_ctime') == 'UNIX_TIMES')) {
722 // Update database and CONFIG array
723 updateConfiguration(array('patch_level', 'patch_ctime'), array(getConfig('CURR_SVN_REVISION'), 'UNIX_TIMESTAMP()'));
724 setConfigEntry('patch_level', getConfig('CURR_SVN_REVISION'));
725 setConfigEntry('patch_ctime', time());
729 // Filter for running daily reset
730 function FILTER_RUN_DAILY_RESET () {
731 // Only execute this filter if installed
732 if ((!isInstalled()) || (!isAdminRegistered())) return;
734 // Shall we run the reset scripts? If a day has changed, maybe also a week/month has changed... Simple! :D
735 // 012 3 4 43 3 4432 2 3 3 21 1 221 1 221 1 2 21 1 22 10
736 if (((date('d', getConfig('last_update')) != date('d', time())) || ((isConfigEntrySet('DEBUG_RESET')) && (getConfig('DEBUG_RESET') == 'Y'))) && (!isInstallationPhase()) && (isAdminRegistered()) && (!isGetRequestElementSet('register')) && (getOutputMode() != 1)) {
737 // Tell every module we are in reset-mode!
742 // Filter for loading more runtime includes (not for installation)
743 function FILTER_LOAD_RUNTIME_INCLUDES () {
744 // Load more includes
745 foreach (array('inc/databases.php','inc/session.php','inc/versions.php') as $inc) {
747 loadIncludeOnce($inc);
750 // Load admin include file if he is admin
752 // Administrative functions
753 loadIncludeOnce('inc/modules/admin/admin-inc.php');
755 //* DEBUG: */ addPointsThroughReferalSystem('test', 36, 1000);
759 // Filter for checking admin ACL
760 function FILTER_CHECK_ADMIN_ACL () {
761 // Extension not installed so it's always allowed to access everywhere!
764 // Ok, Cookie-Update done
765 if ((isExtensionInstalledAndNewer('admins', '0.3.0')) && (isExtensionActive('admins'))) {
766 // Check if action GET variable was set
767 $action = getAction();
769 // Get action value by what-value
770 $action = getModeAction('admin', getWhat());
773 // Check for access control line of current menu entry
774 $ret = adminsCheckAdminAcl($action, getWhat());
778 $GLOBALS['acl_allow'] = $ret;
781 // Init random number/cache buster
782 function FILTER_INIT_RANDOM_NUMBER () {
783 // Is the extension sql_patches installed and at least 0.3.6?
784 if ((isExtensionInstalledAndNewer('sql_patches', '0.3.6')) && (isExtensionInstalledAndNewer('other', '0.2.5'))) {
785 // Generate random number
786 setConfigEntry('RAND_NUMBER', generateRandomCode(10, mt_rand(10000, 32766), getMemberId(), ''));
788 // Generate weak (!!!) code
789 setConfigEntry('RAND_NUMBER', mt_rand(1000000, 9999999));
792 // Copy it to CACHE_BUSTER
793 setConfigEntry('CACHE_BUSTER', getConfig('RAND_NUMBER'));
796 // Update module counter
797 function FILTER_COUNT_MODULE () {
798 // Do count all other modules but not accesses on CSS file css.php!
799 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_mod_reg` SET `clicks`=`clicks`+1 WHERE `module`='%s' LIMIT 1",
800 array(getModule()), __FUNCTION__, __LINE__);
803 // Handles fatal errors
804 function FILTER_HANDLE_FATAL_ERRORS () {
805 // Do we have errors to handle and right output mode?
806 if ((getTotalFatalErrors() == '0') || (getOutputMode() != 0)) {
807 // Abort executing here
812 setContentType('text/html');
815 loadIncludeOnce('inc/load_config.php');
817 // Set unset variable
818 if (empty($check)) $check = '';
823 // Installation phase or regular mode?
824 if ((isInstallationPhase())) {
825 // While we are installing ouput other header than while it is installed... :-)
827 foreach (getFatalArray() as $key => $value) {
828 // Prepare content for the template
835 $OUT .= loadTemplate('install_fatal_row', true, $content);
838 // Load main template
839 $content = loadTemplate('install_fatal_table', true, $OUT);
840 } elseif (isInstalled()) {
841 // Display all runtime fatal errors
843 foreach (getFatalArray() as $key => $value) {
844 // Prepare content for the template
851 $OUT .= loadTemplate('runtime_fatal_row', true, $content);
854 // Load main template
855 $content = loadTemplate('runtime_fatal_table', true, $OUT);
858 // Message to regular users (non-admin)
859 $CORR = getMessage('FATAL_REPORT_ERRORS');
861 // PHP warnings fixed
862 if ($check == 'done') {
863 if (isAdmin()) $CORR = getMessage('FATAL_CORRECT_ERRORS');
866 // Remember all in array
873 loadIncludeOnce('inc/header.php');
875 // Load main template
876 loadTemplate('fatal_errors', false, $content);
878 // Delete all to prevent double-display
882 loadIncludeOnce('inc/footer.php');
888 // Filter for displaying copyright line
889 function FILTER_DISPLAY_COPYRIGHT () {
890 // Shall we display the copyright notice?
891 if ((!isGetRequestElementSet('frame')) && (basename($_SERVER['PHP_SELF']) != 'mailid_top.php') && ((getConfig('WRITE_FOOTER') == 'Y') || (isInstalling())) && ($GLOBALS['header_sent'] == 2)) {
893 if (((isConfigEntrySet('ENABLE_BACKLINK')) && (getConfig('ENABLE_BACKLINK') == 'Y')) || (isInstalling())) {
894 // Copyright with backlink, thanks! :-)
895 loadTemplate('copyright_backlink');
897 // No backlink in Copyright note
898 loadTemplate('copyright');
903 // Filter for displaying parsing time
904 function FILTER_DISPLAY_PARSING_TIME () {
905 // Shall we display the parsing time and number of queries?
906 // 1234 5 54 4 5 5 4 4 5 543 3 4432 2 33 2 2 21
907 if ((((isExtensionInstalledAndNewer('sql_patches', '0.4.1')) && (getConfig('show_timings') == 'Y') && (!isGetRequestElementSet('frame'))) || (isInstallationPhase())) && (getOutputMode() == '0') && ($GLOBALS['header_sent'] == 2)) {
908 // Then display it here
909 displayParsingTime();
913 // Filter for flushing template cache
914 function FILTER_FLUSH_TEMPLATE_CACHE () {
915 // Do not flush when debugging the template cache
916 if (isDebuggingTemplateCache()) return;
918 // Do we have cached eval() data?
919 if ((isset($GLOBALS['template_eval'])) && (count($GLOBALS['template_eval']) > 0)) {
921 foreach ($GLOBALS['template_eval'] as $template => $eval) {
922 // Flush the cache (if not yet found)
923 flushTemplateCache($template, $eval);
928 // Filter for loading user data
929 function FILTER_FETCH_USER_DATA ($userid = 0) {
930 // Is the userid not set? Then use member id
931 if (($userid == '0') || (is_null($userid))) $userid = getMemberId();
934 if (!fetchUserData($userid)) {
935 // Userid is not valid
936 debug_report_bug('User id '.$userid . ' is invalid.');
940 setMemberId($userid);
943 // Filter for reseting users' last login failure, only available with latest ext-sql_patches
944 function FILTER_RESET_USER_LOGIN_FAILURE () {
945 // Is the user data valid?
947 // Do only run for logged in members
948 debug_report_bug('Please only run this filter for logged in users.');
951 // Remmeber login failures if available
952 if (isExtensionInstalledAndNewer('sql_patches', '0.6.1')) {
953 // Reset login failures
954 SQL_QUERY_ESC("UPDATE
955 `{?_MYSQL_PREFIX?}_user_data`
958 `last_failure`='0000-00-00 00:00:00'
962 array(getMemberId()), __FILE__, __LINE__);
964 // Store it in session
965 setSession('mxchange_member_failures' , getUserData('login_failures'));
966 setSession('mxchange_member_last_fail', getUserData('last_failure'));