]> git.mxchange.org Git - mailer.git/blob - inc/inc-functions.php
Continued a bit:
[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 ($poolName) {
40         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'poolName=' . $poolName);
41         $GLOBALS['inc_pool'][$poolName] = array();
42 }
43
44 // Setter for INC_POOL
45 function setIncludePool ($poolName, $includePool) {
46         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'poolName=' . $poolName);
47         $GLOBALS['inc_pool'][$poolName] = (array) $includePool;
48 }
49
50 // Getter for INC_POOL
51 function getIncludePool ($poolName) {
52         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'poolName=' . $poolName);
53         // Default is empty pool
54         $poolArray = array();
55
56         // Is it set?
57         if (isset($GLOBALS['inc_pool'][$poolName])) {
58                 // Return found pool (array)
59                 $poolArray = $GLOBALS['inc_pool'][$poolName];
60         } // END - if
61
62         // Return it
63         return $poolArray;
64 }
65
66 // Count INC_POOL
67 function countIncludePool ($poolNAme) {
68         // Is the pool initialized?
69         if (!isset($GLOBALS['inc_pool'][$poolNAme])) {
70                 // Not initialized with initIncludePool()
71                 reportBug(__FUNCTION__, __LINE__, sprintf("Pool %s is not initialized.", $poolNAme));
72         } // END - if
73
74         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'poolNAme=' . $poolNAme);
75         return count($GLOBALS['inc_pool'][$poolNAme]);
76 }
77
78 // Merge INC_POOL into given
79 function mergeIncludePool ($poolName, $includeArray) {
80         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'poolNAme=' . $poolNAme);
81         setIncludePool($poolName, merge_array(getIncludePool($poolName), $includeArray));
82 }
83
84 // Add single include file to INC_POOL
85 function addIncludeToPool ($poolName, $includeFileName) {
86         // Is the pool initialized?
87         if (!isset($GLOBALS['inc_pool'][$poolName])) {
88                 // Not initialized with initIncludePool()
89                 reportBug(__FUNCTION__, __LINE__, sprintf("Pool %s is not initialized, not adding include %s.", $poolName, $includeFileName));
90         } // END - if
91
92         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'poolNAme=' . $poolNAme);
93         array_push($GLOBALS['inc_pool'][$poolName], $includeFileName);
94 }
95
96 // Remove an include file from INC_POOL
97 function removeIncludeFromPool ($poolNAme, $inc) {
98         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'poolNAme=' . $poolNAme);
99         // First look it up
100         $key = array_search($inc, getIncludePool($poolNAme));
101
102         // Is it valid?
103         if ($key !== FALSE) {
104                 // Then remove it
105                 unset($GLOBALS['inc_pool'][$poolNAme][$key]);
106
107                 // And sort the list
108                 asort($GLOBALS['inc_pool'][$poolNAme]);
109         } // END - if
110 }
111
112 // Load the whole include pool
113 function loadIncludePool ($poolName) {
114         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'poolNAme=' . $poolNAme.' - START');
115         foreach (getIncludePool($poolName) as $includeFileName) {
116                 //* DEBUG: */ debugOutput(__FUNCTION__.':includeFileName='.$includeFileName);
117                 loadIncludeOnce($includeFileName);
118         } // END - foreach
119         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'poolNAme=' . $poolNAme.' - END');
120
121         // Remove it
122         initIncludePool($poolName);
123 }
124
125 // Loads an include file and logs any missing files for debug purposes
126 function loadInclude ($includeFileName) {
127         // Is there cache?
128         if (!isset($GLOBALS['inc_loaded'][$includeFileName])) {
129                 // Is the include file there?
130                 if (!isIncludeReadable($includeFileName)) {
131                         // Not there so log it
132                         reportBug(__FUNCTION__, __LINE__, sprintf('Include file %s not found or deprecated.', $includeFileName));
133                 } // END - if
134
135                 // Add the path. This is why we need a trailing slash in config.php
136                 $GLOBALS['inc_loaded'][$includeFileName] = getPath() . $includeFileName;
137         } // END - if
138
139         // Try to load it
140         include($GLOBALS['inc_loaded'][$includeFileName]);
141 }
142
143 // Loads an include file once
144 function loadIncludeOnce ($inc) {
145         // Is it not loaded?
146         if (!isset($GLOBALS['inc_loaded'][$inc])) {
147                 // Then try to load it
148                 loadInclude($inc);
149         } // END - if
150 }
151
152 // Checks whether an include file (non-FQFN better) is readable
153 function isIncludeReadable ($inc) {
154         // Is there cache?
155         if (!isset($GLOBALS['inc_readable'][$inc])) {
156                 // Construct FQFN
157                 $fqfn = getPath() . $inc;
158
159                 // Is it readable and at least 50 byte large? Include file sizes < 50 byte are always deprecated
160                 $GLOBALS['inc_readable'][$inc] = ((isFileReadable($fqfn)) && (filesize($fqfn) >= 50));
161         } // END - if
162
163         // Return result
164         return $GLOBALS['inc_readable'][$inc];
165 }
166
167 // [EOF]
168 ?>