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 - 2013 by Mailer Developer Team *
20 * For more information visit: http://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: */ logDebugMessage(__FUNCTION__, __LINE__, 'pool=' . $pool);
46 $GLOBALS['inc_pool'][$pool] = array();
49 // Setter for INC_POOL
50 function setIncludePool ($pool, $includePool) {
51 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'pool=' . $pool);
52 $GLOBALS['inc_pool'][$pool] = (array) $includePool;
55 // Getter for INC_POOL
56 function getIncludePool ($pool) {
57 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'pool=' . $pool);
58 // Default is empty pool
62 if (isset($GLOBALS['inc_pool'][$pool])) {
63 // Return found pool (array)
64 $poolArray = $GLOBALS['inc_pool'][$pool];
72 function countIncludePool ($pool) {
73 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'pool=' . $pool);
74 return count($GLOBALS['inc_pool'][$pool]);
77 // Merge INC_POOL into given
78 function mergeIncludePool ($pool, $includePool) {
79 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'pool=' . $pool);
80 setIncludePool($pool, merge_array(getIncludePool($pool), $includePool));
83 // Add single include file to INC_POOL
84 function addIncludeToPool ($pool, $inc) {
85 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'pool=' . $pool);
86 array_push($GLOBALS['inc_pool'][$pool], $inc);
89 // Remove an include file from INC_POOL
90 function removeIncludeFromPool ($pool, $inc) {
91 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'pool=' . $pool);
93 $key = array_search($inc, getIncludePool($pool));
98 unset($GLOBALS['inc_pool'][$pool][$key]);
101 asort($GLOBALS['inc_pool'][$pool]);
105 // Load the whole include pool
106 function loadIncludePool ($pool) {
107 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'pool=' . $pool.' - START');
108 foreach (getIncludePool($pool) as $inc) {
109 //* DEBUG: */ debugOutput(__FUNCTION__.':inc='.$inc);
110 loadIncludeOnce($inc);
112 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'pool=' . $pool.' - END');
115 initIncludePool($pool);
118 // Loads an include file and logs any missing files for debug purposes
119 function loadInclude ($inc) {
121 if (!isset($GLOBALS['inc_loaded'][$inc])) {
122 // Is the include file there?
123 if (!isIncludeReadable($inc)) {
124 // Not there so log it
125 reportBug(__FUNCTION__, __LINE__, sprintf("Include file %s not found or deprecated.", $inc));
128 // Add the path. This is why we need a trailing slash in config.php
129 $GLOBALS['inc_loaded'][$inc] = getPath() . $inc;
133 include($GLOBALS['inc_loaded'][$inc]);
136 // Loads an include file once
137 function loadIncludeOnce ($inc) {
139 if (!isset($GLOBALS['inc_loaded'][$inc])) {
140 // Then try to load it
145 // Checks whether an include file (non-FQFN better) is readable
146 function isIncludeReadable ($inc) {
148 if (!isset($GLOBALS['inc_readable'][$inc])) {
150 $FQFN = getPath() . $inc;
152 // Is it readable and at least 50 byte large? Include file sizes < 50 byte are always deprecated
153 $GLOBALS['inc_readable'][$inc] = ((isFileReadable($FQFN)) && (filesize($FQFN) >= 50));
157 return $GLOBALS['inc_readable'][$inc];