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 * -------------------------------------------------------------------- *
13 * Copyright (c) 2003 - 2009 by Roland Haeder *
14 * Copyright (c) 2009 - 2013 by Mailer Developer Team *
15 * For more information visit: http://mxchange.org *
17 * This program is free software; you can redistribute it and/or modify *
18 * it under the terms of the GNU General Public License as published by *
19 * the Free Software Foundation; either version 2 of the License, or *
20 * (at your option) any later version. *
22 * This program is distributed in the hope that it will be useful, *
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
25 * GNU General Public License for more details. *
27 * You should have received a copy of the GNU General Public License *
28 * along with this program; if not, write to the Free Software *
29 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
31 ************************************************************************/
33 // Some security stuff...
34 if (!defined('__SECURITY')) {
39 function initIncludePool ($pool) {
40 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'pool=' . $pool);
41 $GLOBALS['inc_pool'][$pool] = array();
44 // Setter for INC_POOL
45 function setIncludePool ($pool, $includePool) {
46 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'pool=' . $pool);
47 $GLOBALS['inc_pool'][$pool] = (array) $includePool;
50 // Getter for INC_POOL
51 function getIncludePool ($pool) {
52 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'pool=' . $pool);
53 // Default is empty pool
57 if (isset($GLOBALS['inc_pool'][$pool])) {
58 // Return found pool (array)
59 $poolArray = $GLOBALS['inc_pool'][$pool];
67 function countIncludePool ($pool) {
68 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'pool=' . $pool);
69 return count($GLOBALS['inc_pool'][$pool]);
72 // Merge INC_POOL into given
73 function mergeIncludePool ($pool, $includePool) {
74 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'pool=' . $pool);
75 setIncludePool($pool, merge_array(getIncludePool($pool), $includePool));
78 // Add single include file to INC_POOL
79 function addIncludeToPool ($pool, $inc) {
80 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'pool=' . $pool);
81 array_push($GLOBALS['inc_pool'][$pool], $inc);
84 // Remove an include file from INC_POOL
85 function removeIncludeFromPool ($pool, $inc) {
86 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'pool=' . $pool);
88 $key = array_search($inc, getIncludePool($pool));
93 unset($GLOBALS['inc_pool'][$pool][$key]);
96 asort($GLOBALS['inc_pool'][$pool]);
100 // Load the whole include pool
101 function loadIncludePool ($pool) {
102 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'pool=' . $pool.' - START');
103 foreach (getIncludePool($pool) as $inc) {
104 //* DEBUG: */ debugOutput(__FUNCTION__.':inc='.$inc);
105 loadIncludeOnce($inc);
107 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'pool=' . $pool.' - END');
110 initIncludePool($pool);
113 // Loads an include file and logs any missing files for debug purposes
114 function loadInclude ($inc) {
116 if (!isset($GLOBALS['inc_loaded'][$inc])) {
117 // Is the include file there?
118 if (!isIncludeReadable($inc)) {
119 // Not there so log it
120 reportBug(__FUNCTION__, __LINE__, sprintf('Include file %s not found or deprecated.', $inc));
123 // Add the path. This is why we need a trailing slash in config.php
124 $GLOBALS['inc_loaded'][$inc] = getPath() . $inc;
128 include($GLOBALS['inc_loaded'][$inc]);
131 // Loads an include file once
132 function loadIncludeOnce ($inc) {
134 if (!isset($GLOBALS['inc_loaded'][$inc])) {
135 // Then try to load it
140 // Checks whether an include file (non-FQFN better) is readable
141 function isIncludeReadable ($inc) {
143 if (!isset($GLOBALS['inc_readable'][$inc])) {
145 $FQFN = getPath() . $inc;
147 // Is it readable and at least 50 byte large? Include file sizes < 50 byte are always deprecated
148 $GLOBALS['inc_readable'][$inc] = ((isFileReadable($FQFN)) && (filesize($FQFN) >= 50));
152 return $GLOBALS['inc_readable'][$inc];