More fixes/rewrites for rallye
[mailer.git] / inc / inc-functions.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 03/10/2009 *
4  * ===============                              Last change: 03/10/2009 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : inc-functions.php                                *
8  * -------------------------------------------------------------------- *
9  * Short description : Special functions for handling include files     *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Spezielle Funktionen fuer Include-Dateien        *
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 - 2009 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         die();
42 } // END - if
43
44 // Init INC_POOL
45 function initIncludePool ($pool) {
46         //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
47         $GLOBALS['inc_pool'][$pool] = array();
48 }
49
50 // Setter for INC_POOL
51 function setIncludePool ($pool, $includePool) {
52         //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
53         $GLOBALS['inc_pool'][$pool] = (array) $includePool;
54 }
55
56 // Getter for INC_POOL
57 function getIncludePool ($pool) {
58         //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
59         return $GLOBALS['inc_pool'][$pool];
60 }
61
62 // Count INC_POOL
63 function countIncludePool ($pool) {
64         //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
65         return count($GLOBALS['inc_pool'][$pool]);
66 }
67
68 // Merge INC_POOL into given
69 function mergeIncludePool ($pool, $includePool) {
70         //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
71         setIncludePool($pool, merge_array(getIncludePool($pool), $includePool));
72 }
73
74 // Add single include file to INC_POOL
75 function addIncludeToPool ($pool, $inc) {
76         //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
77         $GLOBALS['inc_pool'][$pool][] = (string) $inc;
78 }
79
80 // Remove an include file from INC_POOL
81 function removeIncludeFromPool ($pool, $inc) {
82         //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
83         // First look it up
84         $key = array_search($inc, getIncludePool($pool));
85
86         // Is it valid?
87         if ($key !== false) {
88                 // Then remove it
89                 unset($GLOBALS['inc_pool'][$pool][$key]);
90
91                 // And sort the list
92                 asort($GLOBALS['inc_pool'][$pool]);
93         } // END - if
94 }
95
96 // Load the whole include pool
97 function loadIncludePool ($pool) {
98         //* DEBUG: */ print __FUNCTION__.':pool='.$pool.' - START<br />';
99         foreach (getIncludePool($pool) as $inc) {
100                 //* DEBUG: */ print __FUNCTION__.':inc='.$inc.'<br />';
101                 loadIncludeOnce($inc);
102         } // END - foreach
103         //* DEBUG: */ print __FUNCTION__.':pool='.$pool.' - END<br />';
104
105         // Remove it
106         initIncludePool($pool);
107 }
108
109 // Loads an include file and logs any missing files for debug purposes
110 function loadInclude ($inc) {
111         // Do we have cache?
112         if (!isset($GLOBALS['inc_loaded'][$inc])) {
113                 // Add the path. This is why we need a trailing slash in config.php
114                 $GLOBALS['inc_loaded'][$inc] = getConfig('PATH') . $inc;
115
116                 // Is the include file there?
117                 if (!isIncludeReadable($inc)) {
118                         // Not there so log it
119                         debug_report_bug(sprintf("Include file %s not found.", $inc));
120                 } // END - if
121         } // END - if
122
123         // Try to load it
124         require($GLOBALS['inc_loaded'][$inc]);
125 }
126
127 // Loads an include file once
128 function loadIncludeOnce ($inc) {
129         // Remove double path
130         $inc = str_replace(getConfig('PATH'), '', $inc);
131
132         // Is it not loaded?
133         if (!isset($GLOBALS['load_once'][$inc])) {
134                 // Mark it as loaded
135                 $GLOBALS['load_once'][$inc] = 'loaded';
136
137                 // Then try to load it
138                 loadInclude($inc);
139         } // END - if
140 }
141
142 // Checks wether an include file (non-FQFN better) is readable
143 function isIncludeReadable ($inc) {
144         // Do we have cache?
145         if (!isset($GLOBALS['inc_readable'][$inc])) {
146                 // Remove double path
147                 $inc = str_replace(getConfig('PATH'), '', $inc);
148
149                 // Construct FQFN
150                 $FQFN = getConfig('PATH') . $inc;
151
152                 // Is it readable?
153                 $GLOBALS['inc_readable'][$inc] = isFileReadable($FQFN);
154         } // END - if
155
156         // Return result
157         return $GLOBALS['inc_readable'][$inc];
158 }
159
160 // [EOF]
161 ?>