Huge script change, see http://forum.mxchange.org/topic-458.html for details:
[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 // Next cached table is the extension
47 if (($GLOBALS['cache_instance']->loadCacheFile('extension')) && ($GLOBALS['cache_instance']->extensionVersionMatches('sql_patches'))) {
48         // Load extension from cache
49         $EXT_DUMMY = $GLOBALS['cache_instance']->getArrayFromCache();
50
51         // Init extension inc-pool
52         $EXT_POOL = array();
53
54         // Do we have entries?
55         if (count($EXT_DUMMY) > 0) {
56                 // Init arrays
57                 $EXT_NAMES = array();
58
59                 // Loop through all
60                 foreach ($EXT_DUMMY['ext_name'] as $k => $name) {
61                         // Load CSS file
62                         if ($EXT_DUMMY['ext_css'][$k] == 'Y') addExtensionCssFile($name . '.css');
63
64                         // Load extension file itself
65                         if ((($EXT_DUMMY['ext_active'][$k] == 'Y') || ($EXT_DUMMY['ext_keep'][$k] == 'Y') || (isAdmin()))) {
66                                 $EXT_POOL[] = $name;
67                         } // END - if
68
69                         // Version number
70                         $EXT_DUMMY['ext_version'][$name] = $EXT_DUMMY['ext_version'][$k];
71                         unset($EXT_DUMMY['ext_version'][$k]);
72
73                         // Extension is active
74                         $EXT_DUMMY['ext_active'][$name] = $EXT_DUMMY['ext_active'][$k];
75                         unset($EXT_DUMMY['ext_active'][$k]);
76
77                         // Ext menu
78                         $EXT_DUMMY['ext_menu'][$name] = $EXT_DUMMY['ext_menu'][$k];
79                         unset($EXT_DUMMY['ext_menu'][$k]);
80
81                         // Language file
82                         $EXT_DUMMY['ext_lang'][$name] = $EXT_DUMMY['ext_lang'][$k];
83                         unset($EXT_DUMMY['ext_lang'][$k]);
84
85                         // Functions file
86                         $EXT_DUMMY['ext_func'][$name] = $EXT_DUMMY['ext_func'][$k];
87                         unset($EXT_DUMMY['ext_func'][$k]);
88
89                         // Extension id
90                         $EXT_DUMMY['ext_id'][$name] = $EXT_DUMMY['ext_id'][$k];
91                         $id = $EXT_DUMMY['ext_id'][$name];
92                         unset($EXT_DUMMY['ext_id'][$k]);
93
94                         // Add ext name
95                         $EXT_NAMES[$id] = $name;
96
97                         // Add deprecated flag (defaults to 'not deprecated')
98                         $EXT_DUMMY['ext_deprecated'][$name] = 'N';
99
100                         // Mark it as active extension
101                         $GLOBALS['cache_array']['active_extensions'][$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 (getOutputMode() != '1') {
132         // Create cache file here
133         $GLOBALS['cache_instance']->init('extension');
134
135         // Add more if sql_patches is recent enougth
136         $add = '';
137         if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) $add = ", `ext_has_css` AS ext_css";
138
139         // Load all modules and their data
140         $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__);
141         while ($content = SQL_FETCHARRAY($result)) {
142                 // Load extension
143                 loadExtension($content['ext_name'], 'test');
144
145                 // Get menu entry
146                 $content['ext_menu'] = 'N';
147                 if (ifModuleHasMenu($content['ext_name'], true)) {
148                         // Extension is a module and has menu... pew!
149                         $content['ext_menu'] = 'Y';
150                 } // END - if
151
152                 // Get language entry
153                 $content['ext_lang'] = 'N';
154                 if (isLanguageIncludeReadable($content['ext_name'])) {
155                         // Readable
156                         $content['ext_lang'] = 'Y';
157                 } // END - if
158
159                 // Get function entry
160                 $content['ext_func'] = 'N';
161                 if (isExtensionFunctionFileReadable($content['ext_name'])) {
162                         // Readable
163                         $content['ext_func'] = 'Y';
164                 } // END - if
165
166                 // Transfer EXT_ALWAYS_ACTIVE flag
167                 $content['ext_keep'] = getExtensionAlwaysActive();
168
169                 // Fix missing ext_css
170                 if (!isset($content['ext_css'])) $content['ext_css'] = 'N';
171
172                 // Add row to cache file
173                 $GLOBALS['cache_instance']->addRow($content);
174         } // END - while
175
176         // Free memory
177         SQL_FREERESULT($result);
178
179         // Close the cache
180         $GLOBALS['cache_instance']->storeExtensionVersion('sql_patches');
181         $GLOBALS['cache_instance']->finalize();
182
183         // Include loader again
184         loadInclude('inc/loader/'.basename(__FILE__));
185 }
186
187 // [EOF]
188 ?>