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