Reverted of changes in 1704, see ticket #160
[mailer.git] / inc / inc-functions.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
42         die();
43 } // END - if
44
45 // Init INC_POOL
46 function initIncludePool ($pool) {
47         //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
48         $GLOBALS['inc_pool'][$pool] = array();
49 }
50
51 // Setter for INC_POOL
52 function setIncludePool ($pool, $includePool) {
53         //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
54         $GLOBALS['inc_pool'][$pool] = (array) $includePool;
55 }
56
57 // Getter for INC_POOL
58 function getIncludePool ($pool) {
59         //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
60         return $GLOBALS['inc_pool'][$pool];
61 }
62
63 // Count INC_POOL
64 function countIncludePool ($pool) {
65         //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
66         return count($GLOBALS['inc_pool'][$pool]);
67 }
68
69 // Merge INC_POOL into given
70 function mergeIncludePool ($pool, $includePool) {
71         //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
72         setIncludePool($pool, merge_array(getIncludePool($pool), $includePool));
73 }
74
75 // Add single include file to INC_POOL
76 function addIncludeToPool ($pool, $inc) {
77         //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
78         $GLOBALS['inc_pool'][$pool][] = (string) $inc;
79 }
80
81 // Remove an include file from INC_POOL
82 function removeIncludeFromPool ($pool, $inc) {
83         //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
84         // First look it up
85         $key = array_search($inc, getIncludePool($pool));
86
87         // Is it valid?
88         if ($key !== false) {
89                 // Then remove it
90                 unset($GLOBALS['inc_pool'][$pool][$key]);
91
92                 // And sort the list
93                 asort($GLOBALS['inc_pool'][$pool]);
94         } // END - if
95 }
96
97 // Load the whole include pool
98 function loadIncludePool ($pool) {
99         //* DEBUG: */ print __FUNCTION__.':pool='.$pool.' - START<br />';
100         foreach (getIncludePool($pool) as $inc) {
101                 //* DEBUG: */ print __FUNCTION__.':inc='.$inc.'<br />';
102                 loadIncludeOnce($inc);
103         } // END - foreach
104         //* DEBUG: */ print __FUNCTION__.':pool='.$pool.' - END<br />';
105
106         // Remove it
107         initIncludePool($pool);
108 }
109
110 // Loads an include file and logs any missing files for debug purposes
111 function loadInclude ($inc) {
112         // Do we have cache?
113         if (!isset($GLOBALS['inc_loaded'][$inc])) {
114                 // Add the path. This is why we need a trailing slash in config.php
115                 $GLOBALS['inc_loaded'][$inc] = getConfig('PATH') . $inc;
116
117                 // Is the include file there?
118                 if (!isIncludeReadable($inc)) {
119                         // Not there so log it
120                         debug_report_bug(sprintf("Include file %s not found.", $inc));
121                 } // END - if
122         } // END - if
123
124         // Try to load it
125         include($GLOBALS['inc_loaded'][$inc]);
126 }
127
128 // Loads an include file once
129 function loadIncludeOnce ($inc) {
130         // Remove double path
131         $inc = str_replace(getConfig('PATH'), '', $inc);
132
133         // Is it not loaded?
134         if (!isset($GLOBALS['load_once'][$inc])) {
135                 // Mark it as loaded
136                 $GLOBALS['load_once'][$inc] = 'loaded';
137
138                 // Then try to load it
139                 loadInclude($inc);
140         } // END - if
141 }
142
143 // Checks wether an include file (non-FQFN better) is readable
144 function isIncludeReadable ($inc) {
145         // Do we have cache?
146         if (!isset($GLOBALS['inc_readable'][$inc])) {
147                 // Remove double path
148                 $inc = str_replace(getConfig('PATH'), '', $inc);
149
150                 // Construct FQFN
151                 $FQFN = getConfig('PATH') . $inc;
152
153                 // Is it readable?
154                 $GLOBALS['inc_readable'][$inc] = isFileReadable($FQFN);
155         } // END - if
156
157         // Return result
158         return $GLOBALS['inc_readable'][$inc];
159 }
160
161 // [EOF]
162 ?>