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 * Copyright (c) 2009, 2010 by Mailer Developer Team *
22 * For more information visit: http://www.mxchange.org *
24 * This program is free software; you can redistribute it and/or modify *
25 * it under the terms of the GNU General Public License as published by *
26 * the Free Software Foundation; either version 2 of the License, or *
27 * (at your option) any later version. *
29 * This program is distributed in the hope that it will be useful, *
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
32 * GNU General Public License for more details. *
34 * You should have received a copy of the GNU General Public License *
35 * along with this program; if not, write to the Free Software *
36 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
38 ************************************************************************/
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
46 function initIncludePool ($pool) {
47 //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
48 $GLOBALS['inc_pool'][$pool] = array();
51 // Setter for INC_POOL
52 function setIncludePool ($pool, $includePool) {
53 //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
54 $GLOBALS['inc_pool'][$pool] = (array) $includePool;
57 // Getter for INC_POOL
58 function getIncludePool ($pool) {
59 //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
60 return $GLOBALS['inc_pool'][$pool];
64 function countIncludePool ($pool) {
65 //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
66 return count($GLOBALS['inc_pool'][$pool]);
69 // Merge INC_POOL into given
70 function mergeIncludePool ($pool, $includePool) {
71 //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
72 setIncludePool($pool, merge_array(getIncludePool($pool), $includePool));
75 // Add single include file to INC_POOL
76 function addIncludeToPool ($pool, $inc) {
77 //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
78 $GLOBALS['inc_pool'][$pool][] = (string) $inc;
81 // Remove an include file from INC_POOL
82 function removeIncludeFromPool ($pool, $inc) {
83 //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
85 $key = array_search($inc, getIncludePool($pool));
90 unset($GLOBALS['inc_pool'][$pool][$key]);
93 asort($GLOBALS['inc_pool'][$pool]);
97 // Load the whole include pool
98 function loadIncludePool ($pool) {
99 //* DEBUG: */ print __FUNCTION__.':pool='.$pool.' - START<br />';
100 foreach (getIncludePool($pool) as $inc) {
101 //* DEBUG: */ print __FUNCTION__.':inc='.$inc.'<br />';
102 loadIncludeOnce($inc);
104 //* DEBUG: */ print __FUNCTION__.':pool='.$pool.' - END<br />';
107 initIncludePool($pool);
110 // Loads an include file and logs any missing files for debug purposes
111 function loadInclude ($inc) {
113 if (!isset($GLOBALS['inc_loaded'][$inc])) {
114 // Add the path. This is why we need a trailing slash in config.php
115 $GLOBALS['inc_loaded'][$inc] = getConfig('PATH') . $inc;
117 // Is the include file there?
118 if (!isIncludeReadable($inc)) {
119 // Not there so log it
120 debug_report_bug(sprintf("Include file %s not found.", $inc));
125 include($GLOBALS['inc_loaded'][$inc]);
128 // Loads an include file once
129 function loadIncludeOnce ($inc) {
130 // Remove double path
131 $inc = str_replace(getConfig('PATH'), '', $inc);
134 if (!isset($GLOBALS['load_once'][$inc])) {
136 $GLOBALS['load_once'][$inc] = 'loaded';
138 // Then try to load it
143 // Checks wether an include file (non-FQFN better) is readable
144 function isIncludeReadable ($inc) {
146 if (!isset($GLOBALS['inc_readable'][$inc])) {
147 // Remove double path
148 $inc = str_replace(getConfig('PATH'), '', $inc);
151 $FQFN = getConfig('PATH') . $inc;
154 $GLOBALS['inc_readable'][$inc] = isFileReadable($FQFN);
158 return $GLOBALS['inc_readable'][$inc];