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