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 if (isset($GLOBALS['inc_pool'][$pool])) {
61 // Return found pool (array)
62 return $GLOBALS['inc_pool'][$pool];
64 // Return empty array if not found
70 function countIncludePool ($pool) {
71 //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
72 return count($GLOBALS['inc_pool'][$pool]);
75 // Merge INC_POOL into given
76 function mergeIncludePool ($pool, $includePool) {
77 //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
78 setIncludePool($pool, merge_array(getIncludePool($pool), $includePool));
81 // Add single include file to INC_POOL
82 function addIncludeToPool ($pool, $inc) {
83 //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
84 $GLOBALS['inc_pool'][$pool][] = (string) $inc;
87 // Remove an include file from INC_POOL
88 function removeIncludeFromPool ($pool, $inc) {
89 //* DEBUG: */ print __FUNCTION__.':pool='.$pool.'<br />';
91 $key = array_search($inc, getIncludePool($pool));
96 unset($GLOBALS['inc_pool'][$pool][$key]);
99 asort($GLOBALS['inc_pool'][$pool]);
103 // Load the whole include pool
104 function loadIncludePool ($pool) {
105 //* DEBUG: */ print __FUNCTION__.':pool='.$pool.' - START<br />';
106 foreach (getIncludePool($pool) as $inc) {
107 //* DEBUG: */ print __FUNCTION__.':inc='.$inc.'<br />';
108 loadIncludeOnce($inc);
110 //* DEBUG: */ print __FUNCTION__.':pool='.$pool.' - END<br />';
113 initIncludePool($pool);
116 // Loads an include file and logs any missing files for debug purposes
117 function loadInclude ($inc) {
119 if (!isset($GLOBALS['inc_loaded'][$inc])) {
120 // Add the path. This is why we need a trailing slash in config.php
121 $GLOBALS['inc_loaded'][$inc] = getConfig('PATH') . $inc;
123 // Is the include file there?
124 if (!isIncludeReadable($inc)) {
125 // Not there so log it
126 debug_report_bug(__FUNCTION__, __LINE__, sprintf("Include file %s not found.", $inc));
131 include($GLOBALS['inc_loaded'][$inc]);
134 // Loads an include file once
135 function loadIncludeOnce ($inc) {
136 // Remove double path
137 $inc = str_replace(getConfig('PATH'), '', $inc);
140 if (!isset($GLOBALS['load_once'][$inc])) {
142 $GLOBALS['load_once'][$inc] = 'loaded';
144 // Then try to load it
149 // Checks wether an include file (non-FQFN better) is readable
150 function isIncludeReadable ($inc) {
152 if (!isset($GLOBALS['inc_readable'][$inc])) {
153 // Remove double path
154 $inc = str_replace(getConfig('PATH'), '', $inc);
157 $FQFN = getConfig('PATH') . $inc;
160 $GLOBALS['inc_readable'][$inc] = isFileReadable($FQFN);
164 return $GLOBALS['inc_readable'][$inc];