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