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 * -------------------------------------------------------------------- *
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 *
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. *
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. *
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, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
44 function initIncludePool ($pool) {
45 //* DEBUG: */ debugOutput(__FUNCTION__.':pool='.$pool);
46 $GLOBALS['inc_pool'][$pool] = array();
49 // Setter for INC_POOL
50 function setIncludePool ($pool, $includePool) {
51 //* DEBUG: */ debugOutput(__FUNCTION__.':pool='.$pool);
52 $GLOBALS['inc_pool'][$pool] = (array) $includePool;
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];
62 // Return empty array if not found
68 function countIncludePool ($pool) {
69 //* DEBUG: */ debugOutput(__FUNCTION__.':pool='.$pool);
70 return count($GLOBALS['inc_pool'][$pool]);
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));
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;
85 // Remove an include file from INC_POOL
86 function removeIncludeFromPool ($pool, $inc) {
87 //* DEBUG: */ debugOutput(__FUNCTION__.':pool='.$pool);
89 $key = array_search($inc, getIncludePool($pool));
94 unset($GLOBALS['inc_pool'][$pool][$key]);
97 asort($GLOBALS['inc_pool'][$pool]);
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);
108 //* DEBUG: */ debugOutput(__FUNCTION__.':pool='.$pool.' - END');
111 initIncludePool($pool);
114 // Loads an include file and logs any missing files for debug purposes
115 function loadInclude ($inc) {
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;
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));
129 include($GLOBALS['inc_loaded'][$inc]);
132 // Loads an include file once
133 function loadIncludeOnce ($inc) {
134 // Remove double path
135 $inc = str_replace(getPath(), '', $inc);
138 if (!isset($GLOBALS['load_once'][$inc])) {
140 $GLOBALS['load_once'][$inc] = 'loaded';
142 // Then try to load it
147 // Checks wether an include file (non-FQFN better) is readable
148 function isIncludeReadable ($inc) {
150 if (!isset($GLOBALS['inc_readable'][$inc])) {
151 // Remove double path
152 $inc = str_replace(getPath(), '', $inc);
155 $FQFN = getPath() . $inc;
158 $GLOBALS['inc_readable'][$inc] = isFileReadable($FQFN);
162 return $GLOBALS['inc_readable'][$inc];