Several kinky code smoothed, fixes for admin login
[mailer.git] / inc / loader / load_cache-extension.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 06/26/2004 *
4  * ===============                              Last change: 07/01/2005 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : load_cache-extensions.php                        *
8  * -------------------------------------------------------------------- *
9  * Short description : Load all extensions                              *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Alle Erweiterungen laden                         *
12  * -------------------------------------------------------------------- *
13  * @TODO Rewrite this whole file to load_cache-extensions.php           *
14  * -------------------------------------------------------------------- *
15  * $Revision::                                                        $ *
16  * $Date::                                                            $ *
17  * $Tag:: 0.2.1-FINAL                                                 $ *
18  * $Author::                                                          $ *
19  * Needs to be in all Files and every File needs "svn propset           *
20  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
21  * -------------------------------------------------------------------- *
22  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
23  * For more information visit: http://www.mxchange.org                  *
24  *                                                                      *
25  * This program is free software; you can redistribute it and/or modify *
26  * it under the terms of the GNU General Public License as published by *
27  * the Free Software Foundation; either version 2 of the License, or    *
28  * (at your option) any later version.                                  *
29  *                                                                      *
30  * This program is distributed in the hope that it will be useful,      *
31  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
32  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
33  * GNU General Public License for more details.                         *
34  *                                                                      *
35  * You should have received a copy of the GNU General Public License    *
36  * along with this program; if not, write to the Free Software          *
37  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
38  * MA  02110-1301  USA                                                  *
39  ************************************************************************/
40
41 // Some security stuff...
42 if (!defined('__SECURITY')) {
43         die();
44 } // END - if
45
46 // Use this code if you don't want to run this cache loader on installation phase
47 if (isInstallationPhase()) return;
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         // Do we have 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 => $name) {
64                         // Load CSS file
65                         if ($EXT_DUMMY['ext_css'][$k] == 'Y') addExtensionCssFile($name . '.css');
66
67                         // Load extension file itself
68                         if (($EXT_DUMMY['ext_active'][$k] == 'Y') || ($EXT_DUMMY['ext_keep'][$k] == 'Y')) {
69                                 $EXT_POOL[] = $name;
70                         } // END - if
71
72                         // Version number
73                         $EXT_DUMMY['ext_version'][$name] = $EXT_DUMMY['ext_version'][$k];
74                         unset($EXT_DUMMY['ext_version'][$k]);
75
76                         // Extension is active
77                         $EXT_DUMMY['ext_active'][$name] = $EXT_DUMMY['ext_active'][$k];
78                         unset($EXT_DUMMY['ext_active'][$k]);
79
80                         // Ext menu
81                         $EXT_DUMMY['ext_menu'][$name] = $EXT_DUMMY['ext_menu'][$k];
82                         unset($EXT_DUMMY['ext_menu'][$k]);
83
84                         // Language file
85                         $EXT_DUMMY['ext_lang'][$name] = $EXT_DUMMY['ext_lang'][$k];
86                         unset($EXT_DUMMY['ext_lang'][$k]);
87
88                         // Functions file
89                         $EXT_DUMMY['ext_func'][$name] = $EXT_DUMMY['ext_func'][$k];
90                         unset($EXT_DUMMY['ext_func'][$k]);
91
92                         // Extension id
93                         $EXT_DUMMY['ext_id'][$name] = $EXT_DUMMY['ext_id'][$k];
94                         $id = $EXT_DUMMY['ext_id'][$name];
95                         unset($EXT_DUMMY['ext_id'][$k]);
96
97                         // Add ext name
98                         $EXT_NAMES[$id] = $name;
99
100                         // Add deprecated flag (defaults to 'not deprecated')
101                         $EXT_DUMMY['ext_deprecated'][$name] = 'N';
102
103                         // Mark it as active extension
104                         $GLOBALS['cache_array']['active_extensions'][$name] = $EXT_DUMMY['ext_keep'][$k];
105                         unset($EXT_DUMMY['ext_keep'][$k]);
106
107                         // Remove unneccessary data from memory
108                         unset($EXT_DUMMY['ext_css'][$k]);
109                 } // END - foreach
110
111                 // Write dummy array back
112                 $EXT_DUMMY['ext_name'] = $EXT_NAMES;
113                 unset($EXT_NAMES);
114
115                 // Loading cache is done so let's free some memory!
116                 unset($EXT_DUMMY['ext_keep']);
117                 unset($EXT_DUMMY['ext_css']);
118         } // END - if
119
120         // Transfer dummy array
121         $GLOBALS['cache_array']['extension'] = $EXT_DUMMY;
122         unset($EXT_DUMMY);
123
124         // No database load needed
125         $res_ext_crt = false;
126
127         // Load all extension files in test-mode (we initialize them later)
128         foreach ($EXT_POOL as $ext) {
129                 loadExtension($ext, 'test');
130         } // END - foreach
131
132         // Remove array and mark cache as loaded
133         unset($EXT_POOL);
134 } elseif (getOutputMode() != 1) {
135         // Create cache file here
136         $GLOBALS['cache_instance']->init();
137
138         // Add more if sql_patches is recent enougth
139         $add = '';
140         if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) $add = ", `ext_has_css` AS ext_css";
141
142         // Load all modules and their data
143         $result = SQL_QUERY('SELECT `id` AS ext_id, `ext_name`, `ext_active`, `ext_version`'.$add.' FROM `{?_MYSQL_PREFIX?}_extensions` ORDER BY `ext_name` ASC', __FILE__, __LINE__);
144         while ($content = SQL_FETCHARRAY($result)) {
145                 // Load extension
146                 loadExtension($content['ext_name'], 'test');
147
148                 // Get menu entry
149                 $content['ext_menu'] = 'N';
150                 if (ifModuleHasMenu($content['ext_name'], true)) {
151                         // Extension is a module and has menu... pew!
152                         $content['ext_menu'] = 'Y';
153                 } // END - if
154
155                 // Get language entry
156                 $content['ext_lang'] = 'N';
157                 if (isLanguageIncludeReadable($content['ext_name'])) {
158                         // Readable
159                         $content['ext_lang'] = 'Y';
160                 } // END - if
161
162                 // Get function entry
163                 $content['ext_func'] = 'N';
164                 if (isExtensionFunctionFileReadable($content['ext_name'])) {
165                         // Readable
166                         $content['ext_func'] = 'Y';
167                 } // END - if
168
169                 // Transfer EXT_ALWAYS_ACTIVE flag
170                 $content['ext_keep'] = getExtensionAlwaysActive();
171
172                 // Fix missing ext_css
173                 if (!isset($content['ext_css'])) $content['ext_css'] = 'N';
174
175                 // Add row to cache file
176                 $GLOBALS['cache_instance']->addRow($content);
177         } // END - while
178
179         // Free memory
180         SQL_FREERESULT($result);
181
182         // Close the cache
183         $GLOBALS['cache_instance']->storeExtensionVersion('sql_patches');
184         $GLOBALS['cache_instance']->finalize();
185 }
186
187 // [EOF]
188 ?>