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 - 2016 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 ($poolName) {
40 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'poolName=' . $poolName);
41 $GLOBALS['inc_pool'][$poolName] = array();
44 // Setter for INC_POOL
45 function setIncludePool ($poolName, $includePool) {
46 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'poolName=' . $poolName);
47 $GLOBALS['inc_pool'][$poolName] = (array) $includePool;
50 // Getter for INC_POOL
51 function getIncludePool ($poolName) {
52 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'poolName=' . $poolName);
53 // Default is empty pool
57 if (isset($GLOBALS['inc_pool'][$poolName])) {
58 // Return found pool (array)
59 $poolArray = $GLOBALS['inc_pool'][$poolName];
67 function countIncludePool ($poolNAme) {
68 // Is the pool initialized?
69 if (!isset($GLOBALS['inc_pool'][$poolNAme])) {
70 // Not initialized with initIncludePool()
71 reportBug(__FUNCTION__, __LINE__, sprintf("Pool %s is not initialized.", $poolNAme));
74 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'poolNAme=' . $poolNAme);
75 return count($GLOBALS['inc_pool'][$poolNAme]);
78 // Merge INC_POOL into given
79 function mergeIncludePool ($poolName, $includeArray) {
80 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'poolNAme=' . $poolNAme);
81 setIncludePool($poolName, merge_array(getIncludePool($poolName), $includeArray));
84 // Add single include file to INC_POOL
85 function addIncludeToPool ($poolName, $includeFileName) {
86 // Is the pool initialized?
87 if (!isset($GLOBALS['inc_pool'][$poolName])) {
88 // Not initialized with initIncludePool()
89 reportBug(__FUNCTION__, __LINE__, sprintf("Pool %s is not initialized, not adding include %s.", $poolName, $includeFileName));
92 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'poolNAme=' . $poolNAme);
93 array_push($GLOBALS['inc_pool'][$poolName], $includeFileName);
96 // Remove an include file from INC_POOL
97 function removeIncludeFromPool ($poolNAme, $inc) {
98 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'poolNAme=' . $poolNAme);
100 $key = array_search($inc, getIncludePool($poolNAme));
103 if ($key !== FALSE) {
105 unset($GLOBALS['inc_pool'][$poolNAme][$key]);
108 asort($GLOBALS['inc_pool'][$poolNAme]);
112 // Load the whole include pool
113 function loadIncludePool ($poolName) {
114 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'poolNAme=' . $poolNAme.' - START');
115 foreach (getIncludePool($poolName) as $includeFileName) {
116 //* DEBUG: */ debugOutput(__FUNCTION__.':includeFileName='.$includeFileName);
117 loadIncludeOnce($includeFileName);
119 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'poolNAme=' . $poolNAme.' - END');
122 initIncludePool($poolName);
125 // Loads an include file and logs any missing files for debug purposes
126 function loadInclude ($includeFileName) {
128 if (!isset($GLOBALS['inc_loaded'][$includeFileName])) {
129 // Is the include file there?
130 if (!isIncludeReadable($includeFileName)) {
131 // Not there so log it
132 reportBug(__FUNCTION__, __LINE__, sprintf('Include file %s not found or deprecated.', $includeFileName));
135 // Add the path. This is why we need a trailing slash in config.php
136 $GLOBALS['inc_loaded'][$includeFileName] = getPath() . $includeFileName;
140 include($GLOBALS['inc_loaded'][$includeFileName]);
143 // Loads an include file once
144 function loadIncludeOnce ($inc) {
146 if (!isset($GLOBALS['inc_loaded'][$inc])) {
147 // Then try to load it
152 // Checks whether an include file (non-FQFN better) is readable
153 function isIncludeReadable ($inc) {
155 if (!isset($GLOBALS['inc_readable'][$inc])) {
157 $fqfn = getPath() . $inc;
159 // Is it readable and at least 50 byte large? Include file sizes < 50 byte are always deprecated
160 $GLOBALS['inc_readable'][$inc] = ((isFileReadable($fqfn)) && (filesize($fqfn) >= 50));
164 return $GLOBALS['inc_readable'][$inc];