Added update_year.sh (still not fully flexible) and updated all years with it.
[mailer.git] / inc / loader / load-extension.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 06/26/2004 *
4  * ===================                          Last change: 07/01/2005 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : load-extension.php                               *
8  * -------------------------------------------------------------------- *
9  * Short description : Load all extensions                              *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Alle Erweiterungen laden                         *
12  * -------------------------------------------------------------------- *
13  * @TODO Rewrite this whole file                                        *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
16  * Copyright (c) 2009 - 2015 by Mailer Developer Team                   *
17  * For more information visit: http://mxchange.org                      *
18  *                                                                      *
19  * This program is free software; you can redistribute it and/or modify *
20  * it under the terms of the GNU General Public License as published by *
21  * the Free Software Foundation; either version 2 of the License, or    *
22  * (at your option) any later version.                                  *
23  *                                                                      *
24  * This program is distributed in the hope that it will be useful,      *
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
27  * GNU General Public License for more details.                         *
28  *                                                                      *
29  * You should have received a copy of the GNU General Public License    *
30  * along with this program; if not, write to the Free Software          *
31  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
32  * MA  02110-1301  USA                                                  *
33  ************************************************************************/
34
35 // Some security stuff...
36 if (!defined('__SECURITY')) {
37         die();
38 } elseif (isInstaller()) {
39         // Do not run in installation phase
40         //* DEBUG: */ logDebugMessage(__FILE__, __LINE__, 'Run from installation phase.');
41         return FALSE;
42 }
43
44 // Next cached table is the extension
45 if (($GLOBALS['cache_instance']->loadCacheFile('extension')) && ($GLOBALS['cache_instance']->extensionVersionMatches('sql_patches'))) {
46         // Load extension from cache
47         $EXT_DUMMY = $GLOBALS['cache_instance']->getArrayFromCache();
48
49         // Init extension inc-pool
50         $EXT_POOL = array();
51
52         // Are there entries?
53         if (count($EXT_DUMMY) > 0) {
54                 // Init arrays
55                 $EXT_NAMES = array();
56
57                 // Loop through all
58                 foreach ($EXT_DUMMY['ext_name'] as $k => $ext_name) {
59                         // Load CSS file?
60                         if ($EXT_DUMMY['ext_css'][$k] == 'Y') {
61                                 addExtensionCssFile($ext_name . '.css');
62                         } // END - if
63
64                         // Load extension file itself
65                         if (($EXT_DUMMY['ext_active'][$k] == 'Y') || ($EXT_DUMMY['ext_keep'][$k] == 'Y')) {
66                                 array_push($EXT_POOL, $ext_name);
67                         } // END - if
68
69                         // Version number
70                         $EXT_DUMMY['ext_version'][$ext_name] = $EXT_DUMMY['ext_version'][$k];
71                         unset($EXT_DUMMY['ext_version'][$k]);
72
73                         // Extension is active
74                         $EXT_DUMMY['ext_active'][$ext_name] = $EXT_DUMMY['ext_active'][$k];
75                         unset($EXT_DUMMY['ext_active'][$k]);
76
77                         // Ext menu
78                         $EXT_DUMMY['ext_menu'][$ext_name] = $EXT_DUMMY['ext_menu'][$k];
79                         unset($EXT_DUMMY['ext_menu'][$k]);
80
81                         // Language file
82                         $EXT_DUMMY['ext_lang'][$ext_name] = $EXT_DUMMY['ext_lang'][$k];
83                         unset($EXT_DUMMY['ext_lang'][$k]);
84
85                         // Functions file
86                         $EXT_DUMMY['ext_func'][$ext_name] = $EXT_DUMMY['ext_func'][$k];
87                         unset($EXT_DUMMY['ext_func'][$k]);
88
89                         // Extension id
90                         $EXT_DUMMY['ext_id'][$ext_name] = $EXT_DUMMY['ext_id'][$k];
91                         $id = $EXT_DUMMY['ext_id'][$ext_name];
92                         unset($EXT_DUMMY['ext_id'][$k]);
93
94                         // Add ext name
95                         $EXT_NAMES[$id] = $ext_name;
96
97                         // Add deprecated flag (defaults to 'not deprecated')
98                         $EXT_DUMMY['ext_deprecated'][$ext_name] = 'N';
99
100                         // Mark it as active extension
101                         $GLOBALS['cache_array']['always_active'][$ext_name] = $EXT_DUMMY['ext_keep'][$k];
102                         unset($EXT_DUMMY['ext_keep'][$k]);
103
104                         // Remove unneccessary data from memory
105                         unset($EXT_DUMMY['ext_css'][$k]);
106                 } // END - foreach
107
108                 // Write dummy array back
109                 $EXT_DUMMY['ext_name'] = $EXT_NAMES;
110                 unset($EXT_NAMES);
111
112                 // Loading cache is done so let's free some memory!
113                 unset($EXT_DUMMY['ext_keep']);
114                 unset($EXT_DUMMY['ext_css']);
115         } // END - if
116
117         // Transfer dummy array
118         $GLOBALS['cache_array']['extension'] = $EXT_DUMMY;
119         unset($EXT_DUMMY);
120
121         // No database load needed
122         $res_ext_crt = FALSE;
123
124         // Load all extension files in test-mode (we initialize them later)
125         foreach ($EXT_POOL as $ext) {
126                 loadExtension($ext, 'test');
127         } // END - foreach
128
129         // Remove array and mark cache as loaded
130         unset($EXT_POOL);
131 } elseif ((isHtmlOutputMode()) || (isAjaxOutputMode()) || (isRawOutputMode())) {
132         // Create cache file here
133         $GLOBALS['cache_instance']->init();
134
135         // Add more if ext-sql_patches is recent enougth
136         $add = '';
137         if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
138                 // Old naming
139                 $add = ', `ext_has_css` AS `ext_css`';
140         } // END - if
141
142         // Query for all extensions
143         $result = sqlQuery('SELECT
144         `id` AS `ext_id`,
145         `ext_name`,
146         `ext_active`,
147         `ext_version`
148 ' . $add . '
149 FROM
150         `{?_MYSQL_PREFIX?}_extensions`
151 ORDER BY
152         `ext_name` ASC', __FILE__, __LINE__);
153
154         // Load all entries
155         while ($content = sqlFetchArray($result)) {
156                 // Load extension
157                 if (!loadExtension($content['ext_name'], 'test')) {
158                         // Is the name valid?
159                         if (!isExtensionNameValid($content['ext_name'])) {
160                                 // Is not valid name (empty ext-foo.php script)
161                                 sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
162                                         array($content['ext_name']), __FILE__, __LINE__);
163                         } else {
164                                 // Didn't load so deactivate it
165                                 doDeactivateExtension($content['ext_name'], TRUE);
166                         }
167
168                         // ... and skip it
169                         continue;
170                 } // END - if
171
172                 // Get menu entry
173                 $content['ext_menu'] = convertBooleanToYesNo(ifModuleHasMenu($content['ext_name'], TRUE));
174
175                 // Get language entry
176                 $content['ext_lang'] = convertBooleanToYesNo(isLanguageIncludeReadable($content['ext_name']));
177
178                 // Get function entry
179                 $content['ext_func'] = convertBooleanToYesNo(isExtensionFunctionFileReadable($content['ext_name']));
180
181                 // Transfer EXT_ALWAYS_ACTIVE flag
182                 $content['ext_keep'] = getThisExtensionAlwaysActive();
183
184                 // Fix missing ext_css
185                 if (!isset($content['ext_css'])) {
186                         $content['ext_css'] = 'N';
187                 } // END - if
188
189                 // Add row to cache file
190                 $GLOBALS['cache_instance']->addRow($content);
191         } // END - while
192
193         // Free memory
194         sqlFreeResult($result);
195
196         // Close the cache
197         $GLOBALS['cache_instance']->storeExtensionVersion('sql_patches');
198         $GLOBALS['cache_instance']->finalize();
199 }
200
201 // [EOF]
202 ?>