2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 03/10/2009 *
4 * =================== Last change: 03/10/2009 *
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 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
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 * For more information visit: http://www.mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
45 function initIncludePool ($pool) {
46 //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
47 $GLOBALS['inc_pool'][$pool] = array();
50 // Setter for INC_POOL
51 function setIncludePool ($pool, $includePool) {
52 //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
53 $GLOBALS['inc_pool'][$pool] = (array) $includePool;
56 // Getter for INC_POOL
57 function getIncludePool ($pool) {
58 //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
59 return $GLOBALS['inc_pool'][$pool];
63 function countIncludePool ($pool) {
64 //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
65 return count($GLOBALS['inc_pool'][$pool]);
68 // Merge INC_POOL into given
69 function mergeIncludePool ($pool, $includePool) {
70 //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
71 setIncludePool($pool, merge_array(getIncludePool($pool), $includePool));
74 // Add single include file to INC_POOL
75 function addIncludeToPool ($pool, $inc) {
76 //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
77 $GLOBALS['inc_pool'][$pool][] = (string) $inc;
80 // Remove an include file from INC_POOL
81 function removeIncludeFromPool ($pool, $inc) {
82 //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
84 $key = array_search($inc, getIncludePool($pool));
89 unset($GLOBALS['inc_pool'][$pool][$key]);
92 asort($GLOBALS['inc_pool'][$pool]);
96 // Load the whole include pool
97 function loadIncludePool ($pool) {
98 //* DEBUG: */ print __FUNCTION__.':pool='.$pool.' - START<br />';
99 foreach (getIncludePool($pool) as $inc) {
100 //* DEBUG: */ print __FUNCTION__.':inc='.$inc.'<br />';
101 loadIncludeOnce($inc);
103 //* DEBUG: */ print __FUNCTION__.':pool='.$pool.' - END<br />';
106 initIncludePool($pool);
109 // Loads an include file and logs any missing files for debug purposes
110 function loadInclude ($inc) {
112 if (!isset($GLOBALS['inc_loaded'][$inc])) {
113 // Add the path. This is why we need a trailing slash in config.php
114 $GLOBALS['inc_loaded'][$inc] = getConfig('PATH') . $inc;
116 // Is the include file there?
117 if (!isIncludeReadable($inc)) {
118 // Not there so log it
119 debug_report_bug(sprintf("Include file %s not found.", $inc));
124 require($GLOBALS['inc_loaded'][$inc]);
127 // Loads an include file once
128 function loadIncludeOnce ($inc) {
129 // Remove double path
130 $inc = str_replace(getConfig('PATH'), '', $inc);
133 if (!isset($GLOBALS['load_once'][$inc])) {
135 $GLOBALS['load_once'][$inc] = 'loaded';
137 // Then try to load it
142 // Checks wether an include file (non-FQFN better) is readable
143 function isIncludeReadable ($inc) {
145 if (!isset($GLOBALS['inc_readable'][$inc])) {
146 // Remove double path
147 $inc = str_replace(getConfig('PATH'), '', $inc);
150 $FQFN = getConfig('PATH') . $inc;
153 $GLOBALS['inc_readable'][$inc] = isFileReadable($FQFN);
157 return $GLOBALS['inc_readable'][$inc];