3358a302a9eedee88469c92e1048188bb11f233b
[mailer.git] / inc / config-functions.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 02/28/2009 *
4  * ===============                              Last change: 02/28/2009 *
5  *                                                                      *
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  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
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                  *
22  *                                                                      *
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.                                  *
27  *                                                                      *
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.                         *
32  *                                                                      *
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,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php";
42         require($INC);
43 }
44
45 // Merges $_CONFIG with data in given array
46 function mergeConfig ($newConfig) {
47         global $_CONFIG;
48         $_CONFIG = merge_array($_CONFIG, $newConfig);
49 }
50
51 // Getter for $_CONFIG entries
52 function getConfig ($entry) {
53         global $_CONFIG;
54
55         // Default value
56         $value = null;
57
58         // Is the entry there?
59         if (isConfigEntrySet($entry)) {
60                 // Then use it
61                 $value = $_CONFIG[$entry];
62         } // END - if
63
64         // Return it
65         return $value;
66 }
67
68 // Setter for $_CONFIG entries
69 function setConfigEntry ($entry, $value) {
70         global $_CONFIG;
71
72         // Secure the entry name
73         $entry = SQL_ESCAPE($entry);
74
75         // And set it
76         $_CONFIG[$entry] = $value;
77 }
78
79 // Checks wether the given config entry is set
80 function isConfigEntrySet ($entry) {
81         global $_CONFIG;
82         return (isset($_CONFIG[$entry]));
83 }
84
85 // Increment or init with given value or 1 as default the given config entry
86 function incrementConfigEntry ($configEntry, $value=1) {
87         global $_CONFIG;
88
89         // Increment it if set or init it with 1
90         if (getConfig($configEntry) > 0) {
91                 $_CONFIG[$configEntry] += $value;
92         } else {
93                 $_CONFIG[$configEntry] = $value;
94         }
95 }
96
97 // Checks wether the configuration array is set so the config is loaded
98 function isConfigLoaded () {
99         global $_CONFIG;
100
101         // Check all
102         return ((isset($_CONFIG)) && (is_array($_CONFIG)) && (count($_CONFIG) > 0));
103 }
104
105 // Init the config array
106 function initConfig () {
107         global $_CONFIG;
108
109         // Set a minimum dummy configuration
110         $_CONFIG = array(
111                 'code_length' => 0,
112                 'patch_level' => 0,
113                 'last_update' => time()
114         );
115 }
116
117 // Load configuration and return it as an arry
118 function loadConfiguration ($no="0") {
119         global $_CONFIG;
120
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;
127                 } // END - foreach
128
129                 // Count cache hits if exists
130                 if ((isset($_CONFIG['cache_hits'])) && (EXT_IS_ACTIVE("cache"))) {
131                         $_CONFIG['cache_hits']++;
132                 } // END - if
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__);
137
138                 // Is the config there?
139                 if (SQL_NUMROWS($result_config) == 1) {
140                         // Get config from database
141                         $_CONFIG = SQL_FETCHARRAY($result_config);
142                 } // END - if
143
144                 // Free result
145                 SQL_FREERESULT($result_config);
146
147                 // Remember this config in the array
148                 $GLOBALS['cache_array']['config'][$no] = $_CONFIG;
149         }
150 }
151
152 // [EOF]
153 ?>