Not this turned on...
[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         if (isset($GLOBALS['inc_pool'][$pool])) {
61                 // Return found pool (array)
62                 return $GLOBALS['inc_pool'][$pool];
63         } else {
64                 // Return empty array if not found
65                 return array();
66         }
67 }
68
69 // Count INC_POOL
70 function countIncludePool ($pool) {
71         //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
72         return count($GLOBALS['inc_pool'][$pool]);
73 }
74
75 // Merge INC_POOL into given
76 function mergeIncludePool ($pool, $includePool) {
77         //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
78         setIncludePool($pool, merge_array(getIncludePool($pool), $includePool));
79 }
80
81 // Add single include file to INC_POOL
82 function addIncludeToPool ($pool, $inc) {
83         //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
84         $GLOBALS['inc_pool'][$pool][] = (string) $inc;
85 }
86
87 // Remove an include file from INC_POOL
88 function removeIncludeFromPool ($pool, $inc) {
89         //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
90         // First look it up
91         $key = array_search($inc, getIncludePool($pool));
92
93         // Is it valid?
94         if ($key !== false) {
95                 // Then remove it
96                 unset($GLOBALS['inc_pool'][$pool][$key]);
97
98                 // And sort the list
99                 asort($GLOBALS['inc_pool'][$pool]);
100         } // END - if
101 }
102
103 // Load the whole include pool
104 function loadIncludePool ($pool) {
105         //* DEBUG: */ print __FUNCTION__.':pool='.$pool.' - START<br />';
106         foreach (getIncludePool($pool) as $inc) {
107                 //* DEBUG: */ print __FUNCTION__.':inc='.$inc.'<br />';
108                 loadIncludeOnce($inc);
109         } // END - foreach
110         //* DEBUG: */ print __FUNCTION__.':pool='.$pool.' - END<br />';
111
112         // Remove it
113         initIncludePool($pool);
114 }
115
116 // Loads an include file and logs any missing files for debug purposes
117 function loadInclude ($inc) {
118         // Do we have cache?
119         if (!isset($GLOBALS['inc_loaded'][$inc])) {
120                 // Add the path. This is why we need a trailing slash in config.php
121                 $GLOBALS['inc_loaded'][$inc] = getConfig('PATH') . $inc;
122
123                 // Is the include file there?
124                 if (!isIncludeReadable($inc)) {
125                         // Not there so log it
126                         debug_report_bug(sprintf("Include file %s not found.", $inc));
127                 } // END - if
128         } // END - if
129
130         // Try to load it
131         include($GLOBALS['inc_loaded'][$inc]);
132 }
133
134 // Loads an include file once
135 function loadIncludeOnce ($inc) {
136         // Remove double path
137         $inc = str_replace(getConfig('PATH'), '', $inc);
138
139         // Is it not loaded?
140         if (!isset($GLOBALS['load_once'][$inc])) {
141                 // Mark it as loaded
142                 $GLOBALS['load_once'][$inc] = 'loaded';
143
144                 // Then try to load it
145                 loadInclude($inc);
146         } // END - if
147 }
148
149 // Checks wether an include file (non-FQFN better) is readable
150 function isIncludeReadable ($inc) {
151         // Do we have cache?
152         if (!isset($GLOBALS['inc_readable'][$inc])) {
153                 // Remove double path
154                 $inc = str_replace(getConfig('PATH'), '', $inc);
155
156                 // Construct FQFN
157                 $FQFN = getConfig('PATH') . $inc;
158
159                 // Is it readable?
160                 $GLOBALS['inc_readable'][$inc] = isFileReadable($FQFN);
161         } // END - if
162
163         // Return result
164         return $GLOBALS['inc_readable'][$inc];
165 }
166
167 // [EOF]
168 ?>