2 /************************************************************************
3 * MXChange v0.2.1 Start: 02/28/2009 *
4 * =============== Last change: 02/28/2009 *
6 * -------------------------------------------------------------------- *
7 * File : config-functions.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Many non-MySQL functions (also file access) *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Viele Nicht-MySQL-Funktionen (auch Dateizugriff) *
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 - 2008 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')) {
41 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
45 // Merges $_CONFIG with data in given array
46 function mergeConfig ($newConfig) {
48 $_CONFIG = merge_array($_CONFIG, $newConfig);
51 // Getter for $_CONFIG entries
52 function getConfig ($configEntry) {
58 // Is the entry there?
59 if (isConfigEntrySet($configEntry)) {
61 $value = $_CONFIG[$configEntry];
68 // Setter for $_CONFIG entries
69 function setConfigEntry ($configEntry, $value) {
72 // Secure the entry name
73 if (function_exists('SQL_ESCAPE')) {
74 // Use our secure function
75 $configEntry = SQL_ESCAPE($configEntry);
77 // Use maybe insecure function
78 $configEntry = smartAddSlashes($configEntry);
82 $_CONFIG[$configEntry] = $value;
85 // Checks wether the given config entry is set
86 function isConfigEntrySet ($configEntry) {
88 return (isset($_CONFIG[$configEntry]));
91 // Increment or init with given value or 1 as default the given config entry
92 function incrementConfigEntry ($configEntry, $value=1) {
95 // Increment it if set or init it with 1
96 if (getConfig($configEntry) > 0) {
97 $_CONFIG[$configEntry] += $value;
99 $_CONFIG[$configEntry] = $value;
103 // Checks wether the configuration array is set so the config is loaded
104 function isConfigLoaded () {
108 return ((isset($_CONFIG)) && (is_array($_CONFIG)) && (count($_CONFIG) > 0));
111 // Init the config array
112 function initConfig () {
114 debug_report_bug('Reached!');
116 // Set a minimum dummy configuration
120 'last_update' => time()
124 // Load configuration and return it as an arry
125 function loadConfiguration ($no = '0') {
126 // Check for cache extension, cache-array and if the requested configuration is in cache
127 if ((isset($GLOBALS['cache_array'])) && (is_array($GLOBALS['cache_array'])) && (isset($GLOBALS['cache_array']['config'][$no])) && (is_array($GLOBALS['cache_array']['config'][$no]))) {
128 // Load config from cache
129 //* DEBUG: */ echo gettype($GLOBALS['cache_array']['config'][$no])."<br />\n";
130 foreach ($GLOBALS['cache_array']['config'][$no] as $key => $value) {
131 setConfigEntry($key, $value);
134 // Count cache hits if exists
135 if ((isConfigEntrySet('cache_hits')) && (EXT_IS_ACTIVE('cache'))) {
136 incrementConfigEntry('cache_hits');
138 } elseif ((!EXT_IS_ACTIVE('cache')) || (!isset($GLOBALS['cache_array']['config'][$no]))) {
139 // Load config from DB
140 $result_config = SQL_QUERY_ESC("SELECT * FROM `{!_MYSQL_PREFIX!}_config` WHERE config=%d LIMIT 1",
141 array(bigintval($no)), __FUNCTION__, __LINE__);
143 // Is the config there?
144 if (SQL_NUMROWS($result_config) == 1) {
145 // Get config from database
146 mergeConfig(SQL_FETCHARRAY($result_config));
150 SQL_FREERESULT($result_config);
152 // Remember this config in the array
153 $GLOBALS['cache_array']['config'][$no] = getConfigArray();
157 // Getter for whole $_CONFIG array
158 function getConfigArray () {
164 // Is the config set?
165 if (isConfigLoaded()) {