X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Ffilters.php;h=239d9048c122537fc62ad0e6d9cfe67b10feb4b6;hb=7770a9545292d628afd2be4f58f86da5c9139619;hp=90478a949f36383aa99488d420c6249a4b4d63d2;hpb=aaf81b8f35512782d34f78c1a0dac8b42d745393;p=mailer.git
diff --git a/inc/filters.php b/inc/filters.php
index 90478a949f..239d9048c1 100644
--- a/inc/filters.php
+++ b/inc/filters.php
@@ -1,7 +1,7 @@
$filterArray) {
// Walk through all filters
foreach ($filterArray as $filterFunction => $active) {
// Is this filter loaded?
- //* DEBUG: */ print 'FOUND:'.$filterName.'/'.$filterFunction.'='.$active.'
';
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'FOUND:'.$filterName.'/'.$filterFunction.'='.$active);
if (((!isset($GLOBALS['cache_array']['filter']['loaded'][$filterName][$filterFunction])) && ($active != 'R')) || ($active == 'A')) {
- // Add this filter (all filters are active by default)
- //* DEBUG: */ print 'ADD:'.$filterName.'/'.$filterFunction.'
';
- $insertSQL .= sprintf("('%s','%s','Y'),", $filterName, $filterFunction);
- $inserted++;
+ // Is this filter already in database?
+ if (countSumTotalData($filterFunction, 'filters', 'filter_name', 'filter_function', TRUE, sprintf(" AND `filter_name`='%s'", sqlEscapeString($filterName))) == 0) {
+ // Add this filter (all filters are active by default)
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ADD:'.$filterName.'/'.$filterFunction);
+ $insertSQL .= sprintf("('%s','%s','Y'),", $filterName, $filterFunction);
+ $inserted++;
+ } elseif (isDebugModeEnabled()) {
+ // Log already registered filters
+ logDebugMessage(__FUNCTION__, __LINE__, 'Already registered: filterName=' . $filterName . ',filterFunction=' . $filterFunction . ',active=' . $active);
+ }
} elseif ($active == 'R') {
// Remove this filter
- //* DEBUG: */ print 'REMOVE:'.$filterName.'/'.$filterFunction.'
';
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'REMOVE:'.$filterName.'/'.$filterFunction);
$removeSQL .= sprintf(" (`filter_name`='%s' AND `filter_function`='%s') OR", $filterName, $filterFunction);
$removed++;
}
} // END - foreach
} // END - foreach
+ // Debug message
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'inserted=' . $inserted . ',removed=' . $removed . ' - AFTER COLLECTION');
+
// Something has been added?
if ($inserted > 0) {
// Finish SQL command and add it
@@ -106,14 +116,14 @@ function FILTER_FLUSH_FILTERS () {
} // END - if
// Shall we update usage counters (ONLY FOR DEBUGGING!)
- if (getConfig('update_filter_usage') == 'Y') {
+ if (isFilterUsageUpdateEnabled()) {
// Update all counters
foreach ($GLOBALS['cache_array']['filter']['counter'] as $filterName => $filterArray) {
// Walk through all filters
- foreach ($filterArray as $filterFunction => $cnt) {
+ foreach ($filterArray as $filterFunction => $count) {
// Construct and add the query
addSql(sprintf("UPDATE `{?_MYSQL_PREFIX?}_filters` SET `filter_counter`=%s WHERE `filter_name`='%s' AND `filter_function`='%s' LIMIT 1",
- bigintval($cnt),
+ bigintval($count),
$filterName,
$filterFunction
));
@@ -127,90 +137,79 @@ function FILTER_FLUSH_FILTERS () {
// Should we rebuild cache?
if (($inserted > 0) || ($removed > 0)) {
// Destroy cache
- rebuildCacheFile('filter', 'filter');
+ rebuildCache('filter', 'filter');
} // END - if
}
// Filter for calling the handler for login failures
-function FILTER_CALL_HANDLER_LOGIN_FAILTURES ($data) {
+function FILTER_CALL_HANDLER_LOGIN_FAILTURES ($filterData) {
// Init content
- $content = $data;
+ $content = $filterData;
// Handle failed logins here if not in guest
- //* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__."):type={$data['type']},action={getAction()},what={getWhat()},level={$data['access_level']}
");
- 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')))) {
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'type=' . $filterData['type'] . ',action=' . getAction() . ',what=' . getWhat() . ',level=' . $filterData['access_level']);
+ 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')))) {
// Handle failure
- $content['content'] .= handleLoginFailtures($data['access_level']);
+ $content['content'] .= handleLoginFailures($filterData['access_level']);
} // END - if
// Return the content
return $content;
}
-// Filter for redirecting to logout if sql_patches has been installed
-function FILTER_REDIRECT_TO_LOGOUT_SQL_PATCHES () {
- // Remove this filter
- unregisterFilter('shutdown', __FUNCTION__);
-
- // Is the element set?
- if (isset($GLOBALS['ext_load_mode'])) {
- // Redirect here
- redirectToUrl('modules.php?module=admin&logout=1&' . $GLOBALS['ext_load_mode'] . '=sql_patches');
- } // END - if
-
- // This should not happen!
- logDebugMessage(__FUNCTION__, __LINE__, 'Cannot auto-logout because no extension load-mode has been set.');
-}
-
// Filter for auto-activation of a extension
-function FILTER_AUTO_ACTIVATE_EXTENSION ($data) {
+function FILTER_AUTO_ACTIVATE_EXTENSION ($filterData) {
+ // Debug message
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $filterData['ext_name'] . ',isThisExtensionAlwaysActive()=' . intval(isThisExtensionAlwaysActive()));
+
// Is this extension always activated?
- if (getExtensionAlwaysActive() == 'Y') {
+ if (isThisExtensionAlwaysActive()) {
// Then activate the extension
- //* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__."): ext_name={$data['ext_name']}
");
- doActivateExtension($data['ext_name']);
+ doActivateExtension($filterData['ext_name']);
} // END - if
// Return the data
- return $data;
+ return $filterData;
}
// Filter for solving task given task
-function FILTER_SOLVE_TASK ($data) {
+function FILTER_SOLVE_TASK ($filterData) {
// Don't solve anything if no admin!
- if (!isAdmin()) return $data;
+ if (!isAdmin()) {
+ return $filterData;
+ } // END - if
// Is this a direct task id or array element task_id is found?
- if (is_int($data)) {
+ if (is_int($filterData)) {
// Then solve it...
- adminSolveTask($data);
- } elseif ((is_array($data)) && (isset($data['task_id']))) {
+ adminSolveTask($filterData);
+ } elseif ((is_array($filterData)) && (isset($filterData['task_id']))) {
// Solve it...
- adminSolveTask($data['task_id']);
+ adminSolveTask($filterData['task_id']);
} else {
// Not detectable!
- debug_report_bug(sprintf("Cannot resolve task. data[%s]=
%s", gettype($data), print_r($data, true))); + reportBug(__FUNCTION__, __LINE__, sprintf('Cannot resolve task. data[%s]=
%s', gettype($filterData), print_r($filterData, TRUE))); } // Return the data - return $data; + return $filterData; } // Filter to load include files -function FILTER_LOAD_INCLUDES ($pool) { +function FILTER_LOAD_INCLUDES ($filterData) { // Is it null? - if (is_null($pool)) { + if (is_null($filterData)) { // This should not happen! - debug_report_bug('pool is null.'); + reportBug(__FUNCTION__, __LINE__, 'pool is null.'); } // END - if // Is the pool an array and 'pool' set? - if ((is_array($pool)) && (isset($pool['pool']))) { + if ((is_array($filterData)) && (isset($filterData['pool']))) { // Then use it as pool - $realPool = $pool['pool']; + $realPool = $filterData['pool']; } else { // Default is $data as inclusion list - $realPool = $pool; + $realPool = $filterData; } // Get inc pool @@ -219,7 +218,7 @@ function FILTER_LOAD_INCLUDES ($pool) { // Is it an array? if ((!isset($data)) || (!is_array($data))) { // Then abort here - debug_report_bug(sprintf("INC_POOL is no array! Type: %s", gettype($data))); + reportBug(__FUNCTION__, __LINE__, sprintf('INC_POOL is no array! Type: %s', gettype($data))); } elseif (isset($data['inc_pool'])) { // Use this as new inclusion pool! setIncludePool($realPool, $data['inc_pool']); @@ -235,52 +234,77 @@ function FILTER_LOAD_INCLUDES ($pool) { } // END - if // Continue with processing - return $pool; + return $filterData; } // Filter for running SQL commands -function FILTER_RUN_SQLS ($data) { +function FILTER_RUN_SQLS ($filterData) { + // Init counter + $count = 0; + // Debug message - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "- Entered!"); + //* DEBUG: */ die('getSqls()=
'.print_r(getSqls(), TRUE).'ext_update_depends=
'.print_r($GLOBALS['ext_update_depends'], TRUE).''); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '- Entered!'); // Is the array there? - if ((isSqlsValid()) && ((!isset($data['dry_run'])) || ($data['dry_run'] == false))) { + if ((ifSqlsRegistered()) && ((!isset($filterData['dry_run'])) || ($filterData['dry_run'] == FALSE))) { // Run SQL commands - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "- Found ".countSqls()." queries to run."); - foreach (getSqls() as $sqls) { + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '- Found ' . countSqls() . ' queries to run.'); + foreach (getSqls() as $mode => $sqls) { + // Debug message + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'mode=' . $mode . ',count()=' . count($sqls)); + // New cache format... foreach ($sqls as $sql) { // Trim spaces away $sql = trim($sql); + // Is 'enable_codes' not set? Then set it to true + if (!isset($filterData['enable_codes'])) { + $filterData['enable_codes'] = TRUE; + } // END - if + // Is there still a query left? if (!empty($sql)) { - // Do we have an "ALTER TABLE" command? - if (substr(strtolower($sql), 0, 11) == 'alter table') { + // Is there an "ALTER TABLE" command? Exclude installation phase here as it would cause this query to fail + if ((substr(strtolower($sql), 0, 11) == 'alter table') && (!isset($filterData['ext_installing']))) { // Analyse the alteration command - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "Alterting table: {$sql}"); - SQL_ALTER_TABLE($sql, __FUNCTION__, __LINE__); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Alterting table: ' . $sql . ',enable_codes=' . intval($filterData['enable_codes'])); + sqlQueryAlterTable($sql, __FUNCTION__, __LINE__, $filterData['enable_codes']); } else { // Run regular SQL command - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "Running regular query: {$sql}"); - SQL_QUERY($sql, __FUNCTION__, __LINE__, false); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Running regular query: ' . $sql . ',enable_codes=' . intval($filterData['enable_codes'])); + sqlQuery($sql, __FUNCTION__, __LINE__, $filterData['enable_codes']); } + + // Has a line changed? + if (!ifSqlHasZeroAffectedRows()) { + // Add it to total account + $count += sqlAffectedRows(); + } // END - if } // END - if } // END - foreach } // END - foreach } // END - if // Debug message - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "- Left!"); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '- Left!'); + + // Return counter + return $count; } // Filter for updating/validating login data function FILTER_UPDATE_LOGIN_DATA () { // Add missing array - if ((!isset($GLOBALS['last_online'])) || (!is_array($GLOBALS['last_online']))) $GLOBALS['last_online'] = array(); + if ((!isset($GLOBALS['last_online'])) || (!is_array($GLOBALS['last_online']))) { + $GLOBALS['last_online'] = array(); + } // END - if // Recheck if logged in - if (!isMember()) return false; + if ((!isMember()) || ((isAdmin()) && (!isDebugModeEnabled()))) { + return FALSE; + } // END - if // Secure user id setMemberId(getSession('userid')); @@ -291,11 +315,13 @@ function FILTER_UPDATE_LOGIN_DATA () { $content = getUserDataArray(); // Maybe first login time? - if (empty($content['last_module'])) $content['last_module'] = 'login'; + if (empty($content[getUserLastWhatName()])) { + $content[getUserLastWhatName()] = 'login'; + } // END - if // This will be displayed on welcome page! :-) if (empty($GLOBALS['last_online']['module'])) { - $GLOBALS['last_online']['module'] = $content['last_module']; + $GLOBALS['last_online']['module'] = $content[getUserLastWhatName()]; $GLOBALS['last_online']['online'] = $content['last_online']; } // END - if @@ -303,7 +329,9 @@ function FILTER_UPDATE_LOGIN_DATA () { if (!isWhatSet()) { // Fix it to default setWhat('welcome'); - if (getConfig('index_home') != '') setWhatFromConfig('index_home'); + if (getIndexHome() != '') { + setWhatFromConfig('index_home'); + } // END - if } // END - if // Update last module / online time @@ -316,21 +344,28 @@ function FILTER_UPDATE_LOGIN_DATA () { // 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); + // Initialize array with all allowed chars + $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,-,+,_,/,.'); + + // 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', (getConfig('_PRIME') * getConfig('_PRIME') / (pi() * getConfig('code_length') + 1))); + 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 ($data) { +function FILTER_REMOVE_UPDATES ($filterData) { // Init removal list initExtensionRemovalList(); @@ -340,20 +375,20 @@ function FILTER_REMOVE_UPDATES ($data) { // Simply remove it unsetExtensionSqls(); - // Do we need to remove update depency? + // Are there update dependencies to remove? if (countExtensionUpdateDependencies() > 0) { // Then find all updates we shall no longer execute - foreach (getExtensionUpdateDependencies() as $id=>$ext_name) { + foreach (getExtensionUpdateDependencies() as $id => $ext_name) { // Shall we remove this update? if (in_array($ext_name, getExtensionRemovalList())) { // Then remove this extension! - removeExtensionUpdateDependency($ext_name); + removeExtensionDependency($ext_name); } // END - if } // END - foreach } // END - if // Return data - return $data; + return $filterData; } // Determines username for current user state @@ -375,7 +410,7 @@ function FILTER_DETERMINE_USERNAME () { } // END - if } else { // Hmmm, logged in and no valid userid? - setUsername('{--USERNAME_UNKNOWN--}'); + setUsername('{--USERNAME_UNKNOWN--}'); // Destroy session destroyMemberSession(); @@ -390,31 +425,31 @@ function FILTER_DETERMINE_USERNAME () { } // Filter for compiling config entries -function FILTER_COMPILE_CONFIG ($code, $compiled = false) { +function FILTER_COMPILE_CONFIG ($code, $compiled = FALSE) { // Save the uncompiled code $uncompiled = $code; - // Do we have cache? + // Is there 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)) { + if ((isFilledArray($matches)) && (isFilledArray($matches[0]))) { // Replace all matches foreach ($matches[0] as $key => $match) { - // Do we have cache? + // Is there 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] . "').\""; + $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]] = "\".getConfig('" . 'DEFAULT_' . strtoupper($matches[1][$key]) . "').\""; + $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]] = "\".getMessage('". 'DEFAULT_' . strtoupper($matches[1][$key]) . "').\""; + $GLOBALS['compile_config'][$matches[1][$key]] = '{%message,DEFAULT_' . strtoupper($matches[1][$key]) . '%}'; } else { // Unhandled! $GLOBALS['compile_config'][$matches[1][$key]] = '!' . $matches[1][$key] . '!'; @@ -423,7 +458,7 @@ function FILTER_COMPILE_CONFIG ($code, $compiled = false) { // Use this for replacing $code = str_replace($match, $GLOBALS['compile_config'][$matches[1][$key]], $code); - //* DEBUG: */ if (($match == '{?URL?}') && (strlen($code) > 10000)) die('
'.secureString($code).''); + //* DEBUG: */ if (($match == '{?URL?}') && (strlen($code) > 10000)) die(__FUNCTION__.'['.__LINE__.']:
'.secureString($code).''); } // END - foreach } // END - if @@ -432,58 +467,110 @@ function FILTER_COMPILE_CONFIG ($code, $compiled = false) { } // END - if // Should we compile it? - if ($compiled === true) { + if ($compiled === TRUE) { // Run the code - eval("\$GLOBALS['compiled_config'][\$uncompiled] = \"" . $GLOBALS['compiled_config'][$uncompiled] . "\";"); + $eval = "\$GLOBALS['compiled_config'][\$uncompiled] = \"" . $GLOBALS['compiled_config'][$uncompiled] . '";'; + //* DEBUG: */ debugOutput(__FUNCTION__.'['.__LINE__.']:
' . encodeEntities($eval) . ''); + eval($eval); } // END - if // Return compiled code return $GLOBALS['compiled_config'][$uncompiled]; } -// 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); +// 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__.']:
'.print_r($matches, TRUE).''); + + // Default is from outputHtml() + $outputMode = getScriptOutputMode(); // Some entries found? - if ((count($matches) > 0) && (count($matches[3]) > 0)) { + if ((isFilledArray($matches)) && (isFilledArray($matches[3]))) { // Replace all matches - foreach ($matches[3] as $key => $cmd) { - // Init replacer variable - $replacer = ''; - - // Is the extension installed or code provided? - if ($cmd == 'code') { - // Code asked for - $replacer = "\".getCode(\"" . $matches[4][$key] . "\").\""; - } else { - // Construct call-back function name - $functionName = 'getExtension' . ucfirst(strtolower($cmd)); + foreach ($matches[2] as $key => $eti) { + // Init replacer/call-back variable + $replacer = ''; + $callback = ''; + $extraFunction = ''; + $extraFunction2 = ''; + $value = NULL; + + // Extract command and call-back + $etiArray = explode(',', $eti); + $eti = $etiArray[0]; + + // Detect call-back function + if (isset($etiArray[1])) { + // Call-back function detected + $callback = $etiArray[1]; + } // END - if - // Construct call of the function - $replacer = "\".call_user_func_array('" . $functionName . "', array('" . $matches[4][$key] . "', true)).\""; - } + // Detect extra function + if (isset($etiArray[2])) { + // Also detected + $extraFunction = $etiArray[2]; + } // END - if + + // Detect extra function 2 + if (isset($etiArray[3])) { + // Also detected + $extraFunction2 = $etiArray[3]; + } // END - if - // Replace it and insert parameter for GET request - $code = str_replace($matches[0][$key], sprintf("&%s=%s&rev=\".getConfig('CURR_SVN_REVISION').\"", $cmd, $replacer), $code); + // 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 + $etiFunction = 'doExpression' . capitalizeUnderscoreString($eti); + + // Is this function there? + if (function_exists($etiFunction)) { + // 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__ . ']: etiFunction=' . $etiFunction); + $filterData = call_user_func($etiFunction, $data); + } else { + // Unsupported command detected + logDebugMessage(__FUNCTION__, __LINE__, 'eti=' . $eti . ',etiFunction=' . $etiFunction . ',callback=' . $callback . ',extraFunction=' . $extraFunction . ',extraFunction2=' . $extraFunction2 . ' - UNSUPPORTED'); + } } // END - foreach } // END - if + // Is there non-HTML/AJAX mode? + if ((!isHtmlOutputMode()) && (!isAjaxOutputMode())) { + $filterData = decodeEntities($filterData); + } // END - if + // Return compiled code - //* DEBUG: */ die('
'.secureString($code).''); - return $code; + //* DEBUG: */ debugOutput(__FUNCTION__.'['.__LINE__.']:
'.($filterData).''); + return $filterData; } // 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()))); + // Create task (we ignore the task id here) + createExtensionUpdateTask(getCurrentAdminId(), $ext_name, $GLOBALS['update_ver'][$ext_name], sqlEscapeString(getExtensionNotes(getExtensionNotes()))); // Update extension's version - SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_version`='%s' WHERE `ext_name`='%s' LIMIT 1", + sqlQueryEscaped("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 @@ -491,90 +578,143 @@ function FILTER_UPDATE_EXTENSION_DATA ($ext_name) { unset($GLOBALS['update_ver'][$ext_name]); } -// Load more reset scripts -function FILTER_RUN_RESET_INCLUDES () { +// Load more hourly reset scripts +function FILTER_RUN_HOURLY_INCLUDES () { + // Is the reset set or old sql_patches? + if (((!isHourlyResetEnabled()) || (!isExtensionInstalledAndNewer('sql_patches', '0.9.8'))) && (isHtmlOutputMode())) { + // Then abort here + reportBug(__FUNCTION__, __LINE__, 'Cannot run hourly reset! enabled='.intval(isHourlyResetEnabled()).',isExtensionInstalledAndNewer='.intval(isExtensionInstalledAndNewer('sql_patches', '0.9.8')).' Please report this bug. Thanks'); + } // END - if + + // Is ext-sql_patches at least 0.9.8? + if (isExtensionInstalledAndNewer('sql_patches', '0.9.8')) { + // Has it changed? + if ((getLastHourly() != getHour()) || (isDebugHourlyEnabled())) { + // Get more hourly reset scripts + setIncludePool('hourly', getArrayFromDirectory('inc/hourly/', 'hourly_')); + + // Run the filter + runFilterChain('load_includes', 'hourly'); + } // END - if + } // END - if +} + +// Load more daily scripts +function FILTER_RUN_DAILY_INCLUDES () { // Is the reset set or old sql_patches? - if (((!isResetModeEnabled()) || (!isExtensionInstalled('sql_patches'))) && (getOutputMode() == '0')) { + if (((!isDailyResetEnabled()) || (!isExtensionInstalledAndNewer('sql_patches', '0.9.8'))) && (isHtmlOutputMode())) { // Then abort here - logDebugMessage(__FUNCTION__, __LINE__, 'Cannot run reset! Please report this bug. Thanks'); + reportBug(__FUNCTION__, __LINE__, 'Cannot run daily reset! enabled='.intval(isDailyResetEnabled()).',isExtensionInstalledAndNewer='.intval(isExtensionInstalledAndNewer('sql_patches', '0.9.8')).' Please report this bug. Thanks'); } // END - if - // Get more daily reset scripts - setIncludePool('reset', getArrayFromDirectory('inc/reset/', 'reset_')); + // Is ext-sql_patches at least 0.9.8? + if (isExtensionInstalledAndNewer('sql_patches', '0.9.8')) { + // Has it changed? + if ((getLastDaily() != getDay()) || (isDebugDailyEnabled())) { + // Get more daily reset scripts + setIncludePool('daily', getArrayFromDirectory('inc/daily/', 'daily_')); - // Update database - if ((!isConfigEntrySet('DEBUG_RESET')) || (getConfig('DEBUG_RESET') != 'Y')) updateConfiguration('last_update', 'UNIX_TIMESTAMP()'); + // Run the filter + runFilterChain('load_includes', 'daily'); + } // END - if + } // END - if +} - // Is the config entry set? - if (isExtensionInstalledAndNewer('sql_patches', '0.4.2')) { - // Create current week mark - $currWeek = date('W', time()); +// Load more weeklt scripts +function FILTER_RUN_WEEKLY_INCLUDES () { + // Is the reset set or old sql_patches? + if (((!isWeeklyResetEnabled()) || (!isExtensionInstalledAndNewer('sql_patches', '0.9.8'))) && (isHtmlOutputMode())) { + // Then abort here + reportBug(__FUNCTION__, __LINE__, 'Cannot run weekly reset! enabled='.intval(isWeeklyResetEnabled()).',isExtensionInstalledAndNewer()='.intval(isExtensionInstalledAndNewer('sql_patches', '0.9.8')).' Please report this bug. Thanks'); + } // END - if + // Is ext-sql_patches at least 0.9.8? + if (isExtensionInstalledAndNewer('sql_patches', '0.9.8')) { // Has it changed? - if ((getConfig('last_week') != $currWeek) || (getConfig('DEBUG_WEEKLY') == 'Y')) { + if ((getLastWeekly() != getWeek()) || (isDebugWeeklyEnabled())) { // Include weekly reset scripts - mergeIncludePool('reset', getArrayFromDirectory('inc/weekly/', 'weekly_')); + setIncludePool('weekly', getArrayFromDirectory('inc/weekly/', 'weekly_')); - // Update config - if ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') != 'Y')) updateConfiguration('last_week', $currWeek); + // Run the filter + runFilterChain('load_includes', 'weekly'); } // END - if + } // END - if +} - // Create current month mark - $currMonth = date('m', time()); +// Load more monthly scripts +function FILTER_RUN_MONTHLY_INCLUDES () { + // Is the reset set or old sql_patches? + if (((!isMonthlyResetEnabled()) || (!isExtensionInstalledAndNewer('sql_patches', '0.9.8'))) && (isHtmlOutputMode())) { + // Then abort here + reportBug(__FUNCTION__, __LINE__, 'Cannot run monthly reset! enabled='.intval(isMonthlyResetEnabled()).',isExtensionInstalledAndNewer='.intval(isExtensionInstalledAndNewer('sql_patches', '0.9.8')).' Please report this bug. Thanks'); + } // END - if + // Is ext-sql_patches at least 0.9.8? + if (isExtensionInstalledAndNewer('sql_patches', '0.9.8')) { // Has it changed? - if ((getConfig('last_month') != $currMonth) || (getConfig('DEBUG_MONTHLY') == 'Y')) { + if ((getLastMonthly() != getMonth()) || (isDebugMonthlyEnabled())) { // Include monthly reset scripts - mergeIncludePool('reset', getArrayFromDirectory('inc/monthly/', 'monthly_')); + setIncludePool('monthly', getArrayFromDirectory('inc/monthly/', 'monthly_')); - // Update config - if ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') != 'Y')) updateConfiguration('last_month', $currMonth); + // Run the filter + runFilterChain('load_includes', 'monthly'); } // END - if } // END - if +} - // Run the filter - runFilterChain('load_includes', 'reset'); +// Load more yearly scripts +function FILTER_RUN_YEARLY_INCLUDES () { + // Is the reset set or old sql_patches? + if (((!isYearlyResetEnabled()) || (!isExtensionInstalledAndNewer('sql_patches', '0.9.8'))) && (isHtmlOutputMode())) { + // Then abort here + reportBug(__FUNCTION__, __LINE__, 'Cannot run yearly reset! enabled='.intval(isYearlyResetEnabled()).',isExtensionInstalledAndNewer='.intval(isExtensionInstalledAndNewer('sql_patches', '0.9.8')).' Please report this bug. Thanks'); + } // END - if + + // Is ext-sql_patches at least 0.9.8? + if (isExtensionInstalledAndNewer('sql_patches', '0.9.8')) { + // Has it changed? + if ((getLastYearly() != getYear()) || (isDebugYearlyEnabled())) { + // Include yearly reset scripts + setIncludePool('yearly', getArrayFromDirectory('inc/yearly/', 'yearly_')); + + // Run the filter + runFilterChain('load_includes', 'yearly'); + } // END - if + } // END - if } // 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", + sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1", array(getCurrentExtensionName()), __FUNCTION__, __LINE__); - // Remove the extension from global cache array as well + // Remove the extension from cache array as well removeExtensionFromArray(); // Remove the cache - rebuildCacheFile('extension', 'extension'); + 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 depency -function FILTER_HTML_INCLUDE_USERS ($mode) { - // Exclude no users by default - $MORE = ''; - - // HTML mail? - if ($mode == 'html') $MORE = " AND `html`='Y'"; - if ((isExtensionActive('holiday')) && (getExtensionVersion('holiday') >= '0.1.3')) { - // Add something for the holiday extension - $MORE .= " AND `holiday_active`='N'"; + // Is this filter called? + if (isset($GLOBALS[__FUNCTION__])) { + // Abort here + reportBug(__FUNCTION__, __LINE__, 'Double call of ' . __FUNCTION__ . ' causes problems with sent headers.'); } // END - if - // Return result - return $MORE; + // Mark this filter as called + $GLOBALS[__FUNCTION__] = TRUE; + + // Simple, he? + outputHtml(); } // Filter for determining what/action/module function FILTER_DETERMINE_WHAT_ACTION () { // In installation phase we don't have what/action - if (isInstallationPhase()) { + if (isInstaller()) { // Set both to empty setAction(''); setWhat(''); @@ -584,24 +724,45 @@ function FILTER_DETERMINE_WHAT_ACTION () { } // END - if // Get all values - if ((getOutputMode() != 1) && (getOutputMode() != -1)) { + if ((!isCssOutputMode()) && (!isRawOutputMode())) { // Fix module if (!isModuleSet()) { + // Is the module registered? + if (!isModuleRegistered(getRequestElement('module'))) { + // Is not a valid module + redirectToUrl('modules.php?module=index'); + } // END - if + // Is the request element set? if (isGetRequestElementSet('module')) { // Set module from request setModule(getRequestElement('module')); - } else { + } 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())); + if (!isWhatSet()) { + setWhat(getWhatFromModule(getModule())); + } // END - if // Fix 'action' if not yet set - if (!isActionSet()) setAction(getModeAction(getModule(), getWhat())); + if (!isActionSet()) { + // Is 'what' set? + if (isWhatSet()) { + // Set action + setAction(getActionFromModuleWhat(getModule(), getWhat())); + } else { + // Set action/what to empty + setAction(''); + setWhat(''); + } + } // END - if } else { // Set action/what to empty setAction(''); @@ -609,11 +770,11 @@ function FILTER_DETERMINE_WHAT_ACTION () { } // Set default 'what' value - //* DEBUG: */ outputHtml('-'.getModule().'/'.getWhat()."-