+ redirectToUrl(getRequestUri());
+}
+
+// Update config entries
+function updateConfiguration ($entries, $values, $updateMode = '', $config = '0', $force = FALSE) {
+ // Do not update config in CSS mode
+ if (($force === FALSE) && ((isCssOutputMode()) || (isRawOutputMode()) || (isInstaller()))) {
+ // This logger line may be very noisy
+ /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Not updating configuration. entries[]=' . gettype($entries) . ',values[]=' . gettype($values) . ',updateMode=' . $updateMode . ',config=' . $config . ',isCssOutputMode()=' . intval(isCssOutputMode()) . ',isRawOutputMode()=' . intval(isRawOutputMode()) . ',isInstaller()=' . intval(isInstaller()));
+ return;
+ } // END - if
+
+ // Default is empty SQL
+ $SQL = '';
+
+ // Is there multiple entries?
+ if (is_array($entries)) {
+ // Walk through all
+ foreach ($entries as $idx => $entry) {
+ // Update mode set?
+ if (!empty($updateMode)) {
+ // Update entry
+ $SQL .= sprintf("`%s`=`%s`%s%01.5f,", $entry, $entry, $updateMode, (float) $values[$idx]);
+ } else {
+ // Check if string or number but no array
+ if (is_array($values[$idx])) {
+ // Arrays must be fixed...
+ reportBug(__FUNCTION__, __LINE__, 'values[' . $idx . '] should not be an array! Content=<pre>'.print_r($values[$idx], TRUE).'</pre>');
+ } elseif ($values[$idx] == 'UNIX_TIMESTAMP()') {
+ // Function UNIX_TIMESTAMP() detected
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Function UNIX_TIMESAMP() detected: entry=' . $entry);
+ $SQL .= sprintf('`%s`=UNIX_TIMESTAMP(),', $entry);
+
+ // Set timestamp in array as well
+ setConfigEntry($entry, time());
+ } elseif (!empty($updateMode)) {
+ // Is the value zero?
+ if ($values[$idx] == '0') {
+ // Then skip it
+ continue;
+ } // END - if
+
+ // Update mode set
+ // @TODO Call setConfigEntry() somehow
+ $SQL .= $entries = sprintf('`%s`=`%s`%s%01.5f', $entry, $entry, $updateMode, (float) $values[$idx]);
+ } elseif (($values[$idx] + 0) === $values[$idx]) {
+ // Number detected
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Number detected: entry=' . $entry . ',values[' . $idx . '/' . gettype($values[$idx]) . ']=' . $values[$idx]);
+ $SQL .= sprintf('`%s`=%01.5f,', $entry, (float) $values[$idx]);
+
+ // Set it in config as well
+ setConfigEntry($entry, $values[$idx]);
+ } else {
+ // String detected
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Regular value detected: entry=' . $entry . ',values[' . $idx . '/' . gettype($values[$idx]) . ']=' . $values[$idx]);
+ $SQL .= sprintf("`%s`='%s',", $entry, sqlEscapeString($values[$idx]));
+
+ // Set it in config as well
+ setConfigEntry($entry, $values[$idx]);
+ }
+ }
+ } // END - foreach
+
+ // Remove last comma
+ $SQL = substr($SQL, 0, -1);
+ } elseif (!empty($updateMode)) {
+ // Is the value zero?
+ if ($values == '0') {
+ // Then skip it
+ continue;
+ } // END - if
+
+ // Update mode set
+ // @TODO Call setConfigEntry() somehow
+ $SQL = sprintf('`%s`=`%s`%s%01.5f', $entries, $entries, $updateMode, (float) $values);
+ } elseif ($values == 'UNIX_TIMESTAMP()') {
+ // Function UNIX_TIMESTAMP() detected
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Function UNIX_TIMESAMP() detected: entries=' . $entries);
+ $SQL = sprintf('`%s`=UNIX_TIMESTAMP()', $entries);
+
+ // Set timestamp in array as well
+ setConfigEntry($entries, time());
+ } elseif (($values + 0) === $values) {
+ // Number detected
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Number detected: entries=' . $entries . ',values[' . gettype($values) . ']=' . $values);
+ $SQL = sprintf('`%s`=%01.5f', $entries, (float) $values);
+
+ // Set it in config first
+ setConfigEntry($entries, (float) $values);
+ } else {
+ // Regular entry to update
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Regular value detected: entries=' . $entries . ',values[' . gettype($values) . ']=' . $values);
+ $SQL = sprintf("`%s`='%s'", $entries, sqlEscapeString($values));
+
+ // Set it in config as well
+ setConfigEntry($entries, sqlEscapeString($values));
+ }
+
+ // Run database update
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'SQL=' . $SQL);
+ sqlQueryEscaped('UPDATE `{?_MYSQL_PREFIX?}_config` SET ' . $SQL . ' WHERE `config`=%s LIMIT 1',
+ array(bigintval($config)), __FUNCTION__, __LINE__);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'SQL=' . $SQL . ',affectedRows=' . sqlAffectedRows());
+
+ // Rebuild cache
+ rebuildCache('config', 'config');
+}
+
+// Filter for loading configuration
+function FILTER_LOAD_CONFIGURATION ($no = '0') {
+ // Is installation phase?
+ if (isInstaller()) {
+ // Then don't load any configuration
+ return;
+ } // END - if
+
+ // Is the value null, it comes from the 'init' filter chain
+ if (is_null($no)) {
+ $no = '0';
+ } // END - if
+
+ // Check for cache extension, cache-array and if the requested configuration is in cache
+ if ((isset($GLOBALS['cache_array']['config'][$no])) && (is_array($GLOBALS['cache_array']['config'][$no]))) {
+ // Load config from cache
+ mergeConfig($GLOBALS['cache_array']['config'][$no]);
+
+ // Count cache hits
+ incrementStatsEntry('cache_hits');
+ } elseif ((!isExtensionActive('cache')) || (!isset($GLOBALS['cache_array']['config'][$no]))) {
+ // Load config from DB
+ $result_config = sqlQueryEscaped('SELECT * FROM `{?_MYSQL_PREFIX?}_config` WHERE `config`=%s LIMIT 1',
+ array(bigintval($no)), __FUNCTION__, __LINE__);
+
+ // Is the config there?
+ if (sqlNumRows($result_config) == 1) {
+ // Get config from database
+ mergeConfig(sqlFetchArray($result_config));
+ } // END - if
+
+ // Free result
+ sqlFreeResult($result_config);
+
+ // Remember this config in the array
+ $GLOBALS['cache_array']['config'][$no] = getConfigArray();
+ }
+}
+
+// "Getter" for "checked" configuration entries
+function getCheckedConfig ($configEntries) {
+ // Add entries
+ $content = getConfigEntries($configEntries, ' checked="checked"');
+
+ // Return it
+ return $content;
+}
+
+// "Getter" for "selected" configuration entries
+function getSelectedConfig ($configEntries) {
+ // Add entries
+ $content = getConfigEntries($configEntries, ' selected="selected"');
+
+ // Return it
+ return $content;
+}
+
+// "Getter" for configuration entries
+function getConfigEntries ($configEntries, $value) {
+ // Init content
+ $content = array();
+
+ // "Walk" through all entries
+ foreach ($configEntries as $entry) {
+ $content[$entry . '_' . strtolower(getConfig($entry))] = $value;
+ } // END - foreach
+
+ // Return it
+ return $content;