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 ($entry) {
58 // Is the entry there?
59 if (isConfigEntrySet($entry)) {
61 $value = $_CONFIG[$entry];
68 // Setter for $_CONFIG entries
69 function setConfigEntry ($entry, $value) {
72 // Secure the entry name
73 $entry = SQL_ESCAPE($entry);
76 $_CONFIG[$entry] = $value;
79 // Checks wether the given config entry is set
80 function isConfigEntrySet ($entry) {
82 return (isset($_CONFIG[$entry]));
85 // Increment or init with given value or 1 as default the given config entry
86 function incrementConfigEntry ($configEntry, $value=1) {
89 // Increment it if set or init it with 1
90 if (getConfig($configEntry) > 0) {
91 $_CONFIG[$configEntry] += $value;
93 $_CONFIG[$configEntry] = $value;
97 // Checks wether the configuration array is set so the config is loaded
98 function isConfigLoaded () {
102 return ((isset($_CONFIG)) && (is_array($_CONFIG)) && (count($_CONFIG) > 0));
105 // Init the config array
106 function initConfig () {
109 // Set a minimum dummy configuration
113 'last_update' => time()
117 // Load configuration and return it as an arry
118 function loadConfiguration ($no="0") {
121 // Check for cache extension, cache-array and if the requested configuration is in cache
122 if ((is_array($GLOBALS['cache_array'])) && (isset($GLOBALS['cache_array']['config'][$no])) && (is_array($GLOBALS['cache_array']['config'][$no]))) {
123 // Load config from cache
124 //* DEBUG: */ echo gettype($GLOBALS['cache_array']['config'][$no])."<br />\n";
125 foreach ($GLOBALS['cache_array']['config'][$no] as $key => $value) {
126 $_CONFIG[$key] = $value;
129 // Count cache hits if exists
130 if ((isset($_CONFIG['cache_hits'])) && (EXT_IS_ACTIVE("cache"))) {
131 $_CONFIG['cache_hits']++;
133 } elseif ((!EXT_IS_ACTIVE("cache")) || (!isset($GLOBALS['cache_array']['config'][$no]))) {
134 // Load config from DB
135 $result_config = SQL_QUERY_ESC("SELECT * FROM `{!_MYSQL_PREFIX!}_config` WHERE config=%d LIMIT 1",
136 array(bigintval($no)), __FUNCTION__, __LINE__);
138 // Is the config there?
139 if (SQL_NUMROWS($result_config) == 1) {
140 // Get config from database
141 $_CONFIG = SQL_FETCHARRAY($result_config);
145 SQL_FREERESULT($result_config);
147 // Remember this config in the array
148 $GLOBALS['cache_array']['config'][$no] = $_CONFIG;