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