Loader for cache files renamed to avoid a lot naming conflicts
[mailer.git] / inc / loader / load-extensions.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-extensions.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, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.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 } // END - if
44
45 // Use this code if you don't want to run this cache loader on installation phase
46 if (isInstallationPhase()) return;
47
48 // Next cached table is the extension
49 if (($GLOBALS['cache_instance']->loadCacheFile('extension')) && ($GLOBALS['cache_instance']->extensionVersionMatches('sql_patches'))) {
50         // Load extension from cache
51         $EXT_DUMMY = $GLOBALS['cache_instance']->getArrayFromCache();
52
53         // Init extension inc-pool
54         $EXT_POOL = array();
55
56         // Do we have entries?
57         if (count($EXT_DUMMY) > 0) {
58                 // Init arrays
59                 $EXT_NAMES = array();
60
61                 // Loop through all
62                 foreach ($EXT_DUMMY['ext_name'] as $k => $name) {
63                         // Load CSS file
64                         if ($EXT_DUMMY['ext_css'][$k] == 'Y') addExtensionCssFile($name . '.css');
65
66                         // Load extension file itself
67                         if (($EXT_DUMMY['ext_active'][$k] == 'Y') || ($EXT_DUMMY['ext_keep'][$k] == 'Y')) {
68                                 $EXT_POOL[] = $name;
69                         } // END - if
70
71                         // Version number
72                         $EXT_DUMMY['ext_version'][$name] = $EXT_DUMMY['ext_version'][$k];
73                         unset($EXT_DUMMY['ext_version'][$k]);
74
75                         // Extension is active
76                         $EXT_DUMMY['ext_active'][$name] = $EXT_DUMMY['ext_active'][$k];
77                         unset($EXT_DUMMY['ext_active'][$k]);
78
79                         // Ext menu
80                         $EXT_DUMMY['ext_menu'][$name] = $EXT_DUMMY['ext_menu'][$k];
81                         unset($EXT_DUMMY['ext_menu'][$k]);
82
83                         // Language file
84                         $EXT_DUMMY['ext_lang'][$name] = $EXT_DUMMY['ext_lang'][$k];
85                         unset($EXT_DUMMY['ext_lang'][$k]);
86
87                         // Functions file
88                         $EXT_DUMMY['ext_func'][$name] = $EXT_DUMMY['ext_func'][$k];
89                         unset($EXT_DUMMY['ext_func'][$k]);
90
91                         // Extension id
92                         $EXT_DUMMY['ext_id'][$name] = $EXT_DUMMY['ext_id'][$k];
93                         $id = $EXT_DUMMY['ext_id'][$name];
94                         unset($EXT_DUMMY['ext_id'][$k]);
95
96                         // Add ext name
97                         $EXT_NAMES[$id] = $name;
98
99                         // Add deprecated flag (defaults to 'not deprecated')
100                         $EXT_DUMMY['ext_deprecated'][$name] = 'N';
101
102                         // Mark it as active extension
103                         $GLOBALS['cache_array']['always_active'][$name] = $EXT_DUMMY['ext_keep'][$k];
104                         unset($EXT_DUMMY['ext_keep'][$k]);
105
106                         // Remove unneccessary data from memory
107                         unset($EXT_DUMMY['ext_css'][$k]);
108                 } // END - foreach
109
110                 // Write dummy array back
111                 $EXT_DUMMY['ext_name'] = $EXT_NAMES;
112                 unset($EXT_NAMES);
113
114                 // Loading cache is done so let's free some memory!
115                 unset($EXT_DUMMY['ext_keep']);
116                 unset($EXT_DUMMY['ext_css']);
117         } // END - if
118
119         // Transfer dummy array
120         $GLOBALS['cache_array']['extension'] = $EXT_DUMMY;
121         unset($EXT_DUMMY);
122
123         // No database load needed
124         $res_ext_crt = false;
125
126         // Load all extension files in test-mode (we initialize them later)
127         foreach ($EXT_POOL as $ext) {
128                 loadExtension($ext, 'test');
129         } // END - foreach
130
131         // Remove array and mark cache as loaded
132         unset($EXT_POOL);
133 } elseif (isHtmlOutputMode()) {
134         // Create cache file here
135         $GLOBALS['cache_instance']->init();
136
137         // Add more if sql_patches is recent enougth
138         $add = '';
139         if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) $add = ", `ext_has_css` AS ext_css";
140
141         // Load all modules and their data
142         $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__);
143         while ($content = SQL_FETCHARRAY($result)) {
144                 // Load extension
145                 loadExtension($content['ext_name'], 'test');
146
147                 // Get menu entry
148                 $content['ext_menu'] = 'N';
149                 if (ifModuleHasMenu($content['ext_name'], true)) {
150                         // Extension is a module and has menu... pew!
151                         $content['ext_menu'] = 'Y';
152                 } // END - if
153
154                 // Get language entry
155                 $content['ext_lang'] = 'N';
156                 if (isLanguageIncludeReadable($content['ext_name'])) {
157                         // Readable
158                         $content['ext_lang'] = 'Y';
159                 } // END - if
160
161                 // Get function entry
162                 $content['ext_func'] = 'N';
163                 if (isExtensionFunctionFileReadable($content['ext_name'])) {
164                         // Readable
165                         $content['ext_func'] = 'Y';
166                 } // END - if
167
168                 // Transfer EXT_ALWAYS_ACTIVE flag
169                 $content['ext_keep'] = getExtensionAlwaysActive();
170
171                 // Fix missing ext_css
172                 if (!isset($content['ext_css'])) $content['ext_css'] = 'N';
173
174                 // Add row to cache file
175                 $GLOBALS['cache_instance']->addRow($content);
176         } // END - while
177
178         // Free memory
179         SQL_FREERESULT($result);
180
181         // Close the cache
182         $GLOBALS['cache_instance']->storeExtensionVersion('sql_patches');
183         $GLOBALS['cache_instance']->finalize();
184 }
185
186 // [EOF]
187 ?>