2 /************************************************************************
3 * MXChange v0.2.1 Start: 10/25/2009 *
4 * =============== Last change: 10/25/2009 *
6 * -------------------------------------------------------------------- *
7 * File : extensions-functions.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Extension management *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Erweiterungen-Management *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * Needs to be in all Files and every File needs "svn propset *
18 * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
19 * -------------------------------------------------------------------- *
20 * Copyright (c) 2003 - 2009 by Roland Haeder *
21 * For more information visit: http://www.mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
44 // Load the extension and maybe found language and function files.
45 function loadExtension ($ext_name, $ext_mode = 'init', $ext_ver = '', $dry_run = false) {
46 // Set current extension name
47 setCurrentExtensionName($ext_name);
49 // Set current extension version
50 setCurrentExtensionVersion($ext_ver);
53 setExtensionMode($ext_mode);
56 enableExtensionDryRun($dry_run);
59 initIncludePool('extension');
61 // Init EXT_UPDATE_DEPENDS
62 initExtensionUpdateDependencies();
64 // Init current extension name list
67 // Is the extension already loaded?
68 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "Loading extension {$ext_name}, mode=".getExtensionMode().", ver=".getCurrentExtensionVersion()."");
69 if ((isset($GLOBALS['ext_loaded']['ext'][$ext_name])) && (getExtensionMode() == 'init')) {
71 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Extension %s already loaded.", $ext_name));
77 // Is the extension file NOT there?
78 if (!isExtensionNameValid($ext_name)) {
80 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Extension %s not found or not readable.", $ext_name));
86 // Load extension's own language file if not in test mode
87 if ((getExtensionMode() != 'test') && (ifExtensionHasLanguageFile($ext_name))) {
89 loadLanguageFile($ext_name);
93 if (isExtensionFunctionFileReadable($ext_name)) {
95 if ((($GLOBALS['cache_array']['extension']['ext_func'][$ext_name] == 'Y') || (!isset($GLOBALS['cache_array']['extension']['ext_func'][$ext_name]))) && (!isset($GLOBALS['ext_loaded']['funcs'][$ext_name]))) {
96 // Construct FQFN for functions file
97 $funcsInclude = sprintf("inc/libs/%s_functions.php", $ext_name);
100 $GLOBALS['ext_loaded']['funcs'][$ext_name] = true;
102 // Download functions file
103 loadIncludeOnce($funcsInclude);
105 } elseif ((!isset($GLOBALS['cache_array']['extension']['ext_func'][$ext_name])) && (isDebugModeEnabled()) && (getOutputMode() == 0) && ($ext_name != 'sql_patches') && (substr($ext_name, 0, 10) != 'admintheme') && (getExtensionMode() == 'test')) {
106 // No functions file is not so good...
107 logDebugMessage(__FUNCTION__, __LINE__, sprintf("NOTICE: Extension %s has no own functions file or we cannot read from it. mode=%s",
113 // Extensions are not deprecated by default
114 setExtensionDeprecated('N');
116 // Extensions are not always active by default
117 setExtensionAlwaysActive('N');
119 // Extension update notes
120 setExtensionUpdateNotes('');
122 // Include the extension file
123 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "Extension loaded.");
124 loadExtensionInclude();
126 // Is this extension deprecated?
127 if (isExtensionDeprecated()) {
128 // Deactivate the extension
129 doDeactivateExtension($ext_name);
135 // Mark it as loaded in normal mode
136 if (getExtensionMode() == '') {
138 $GLOBALS['ext_loaded']['ext'][$ext_name] = true;
145 // Registeres an extension and possible update depencies
146 function registerExtension ($ext_name, $task_id, $dry_run = false, $logout = true) {
147 // Set current extension name
148 setCurrentExtensionName($ext_name);
151 enableExtensionDryRun($dry_run);
153 // By default all extensions are in productive phase
154 enableExtensionProductive();
156 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()." - ENTERED!");
157 // This shall never do a non-admin user or if the extension is active (already installed)
158 if ((!isAdmin()) || (isExtensionInstalled($ext_name))) {
162 // When this extension is already in install/update phase, all is fine
163 if (isExtensionRegisterRunning($ext_name)) {
164 // Then abort here which is fine
165 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()." - ALREADY!");
169 // This registration is running
170 addExtensionRunningRegistration($ext_name);
172 // Init EXT_UPDATE_DEPENDS
173 initExtensionUpdateDependencies();
175 // Is the task id zero? Then we need to auto-fix it here
177 // Try to find the task
178 $task_id = determineExtensionTaskId(getCurrentExtensionName());
180 // Still zero and not in dry-run?
181 if (($task_id == 0) && (!getExtensionDryRun())) {
182 // Then request a bug report
183 debug_report_bug(sprintf("%s: task_id is still zero after determineExtensionTaskId(%s)",
185 getCurrentExtensionName()
190 // Init queries and notes
192 initExtensionNotes();
197 initIncludePool('extension');
199 // By default we have no failures
200 setExtensionReportsFailure(false);
202 // Does this extension exists?
203 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()."");
204 if (loadExtension(getCurrentExtensionName(), 'register', '', getExtensionDryRun())) {
205 // Set current extension name again
206 setCurrentExtensionName($ext_name);
208 // And run possible updates
209 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "".getCurrentExtensionName());
210 $history = getExtensionVersionHistory();
211 foreach ($history as $ver) {
212 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name=".getCurrentExtensionName().", ext_ver={$ver}");
213 // Load extension in update mode
214 loadExtension(getCurrentExtensionName(), 'update', $ver, getExtensionDryRun());
216 // Add update notes to our output
217 addExtensionNotes($ver);
220 // Does this extension depends on an outstanding update of another update?
221 for ($dmy = getExtensionUpdateIterator(); getExtensionUpdateIterator() < countExtensionUpdateDependencies();) {
223 $ext_update = getExtensionUpdateDependenciesIterator();
225 // Increment here to avoid endless loop
226 incrementExtensionUpdateIterator();
228 // Check for required file
229 if (loadExtension($ext_update, 'register', '', getExtensionDryRun())) {
230 // Set current extension name again
231 setCurrentExtensionName($ext_name);
233 // If versions mismatch update extension first
235 if (isExtensionInstalled($ext_update)) {
236 // Get version only if installed
237 $ext_ver = getExtensionVersion($ext_update);
240 // Extension version set? If empty the extension is not registered
241 if (empty($ext_ver)) {
242 // Extension not registered so far so first load task's id...
243 $task = determineExtensionTaskId($ext_update);
247 // Try to register the extension
248 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName().":ext_update=".$ext_update.",taskId=".$task."");
249 $test = registerExtension($ext_update, $task, getExtensionDryRun(), false);
251 // Reset extension name
252 setCurrentExtensionName($ext_name);
253 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()); print getCurrentExtensionName().':<pre>'.print_r($test);
255 } elseif ($ext_ver != getCurrentExtensionVersion()) {
256 // Ok, update this extension now
257 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName().",ext_update=".$ext_update.",ext_ver=".$ext_ver."/".getCurrentExtensionVersion()."");
258 $GLOBALS['ext_backup'][$ext_update][$ext_ver] = getCurrentExtensionName();
259 updateExtension($ext_update, $ext_ver, getExtensionDryRun());
260 setCurrentExtensionName($GLOBALS['ext_backup'][$ext_update][$ext_ver]);
261 unset($GLOBALS['ext_backup'][$ext_update][$ext_ver]);
262 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()."");
267 // Nothing to register / update before...
271 // Required file for update does not exists!
273 // But this is fine for the first time...
276 // Restore the current extension name
277 setCurrentExtensionName($ext_name);
280 // Is there no update?
281 if (countExtensionUpdateDependencies(getCurrentExtensionName()) == 0) {
282 // Then test is passed!
286 // Switch back to register mode
287 setExtensionMode('register');
289 // Remains true if extension registration reports no failures
290 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()); print getCurrentExtensionName().':<pre>'.print_r($test, true).'</pre>';
291 $test = (($test === true) && (getExtensionReportsFailure() === false));
292 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()); print getCurrentExtensionName().':<pre>'.print_r($test, true).'</pre>';
294 // Does everthing before wents ok?
295 if ($test === true) {
296 // "Dry-run-mode" activated?
297 if ((getExtensionDryRun() === false) && (!isExtensionOnRemovalList())) {
298 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name=".getCurrentExtensionName());
299 // Init SQLs and transfer ext->generic
301 setSqlsArray(getExtensionSqls());
303 // Run installation pre-installation filters
304 runFilterChain('pre_extension_installed', array('dry_run' => getExtensionDryRun()));
306 // Register extension
307 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "insert=".getCurrentExtensionName().'/'.getCurrentExtensionVersion()." - INSERT!");
308 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
310 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_extensions` (`ext_name`, `ext_active`, `ext_version`,`ext_has_css`) VALUES ('%s','%s','%s','%s')",
311 array(getCurrentExtensionName(), getExtensionAlwaysActive(), getCurrentExtensionVersion(), getExtensionHasCss()), __FUNCTION__, __LINE__);
314 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_extensions` (`ext_name`, `ext_active`, `ext_version`) VALUES ('%s','%s','%s')",
315 array(getCurrentExtensionName(), getExtensionAlwaysActive(), getCurrentExtensionVersion()), __FUNCTION__, __LINE__);
318 // Remove cache file(s) if extension is active
319 runFilterChain('post_extension_installed', array(
320 'pool' => 'extension',
321 'ext_name' => getCurrentExtensionName(),
322 'task_id' => $task_id
325 // Remove all SQL commands
328 // Mark it as installed
329 $GLOBALS['ext_is_installed'][getCurrentExtensionName()] = true;
331 // In normal mode return a true on success
333 } elseif (getExtensionDryRun() === true) {
334 // In "dry-run" mode return array with all SQL commands
335 $ret = getExtensionSqls();
337 // Remove all SQL commands
340 // Extension has been removed for updates, so all is fine!
344 // No, an error occurs while registering extension :-(
345 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "".getCurrentExtensionName());
348 } elseif (($task_id > 0) && (getCurrentExtensionName() != '')) {
349 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()."");
350 // Remove task from system when id and extension's name is valid
351 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s AND `status`='NEW' LIMIT 1",
352 array(bigintval($task_id)), __FUNCTION__, __LINE__);
355 // Is this the sql_patches?
356 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ':'.getCurrentExtensionName()."/".getExtensionMode()."");
357 if ((getCurrentExtensionName() == 'sql_patches') && ((getExtensionMode() == 'register') || (getExtensionMode() == 'remove')) && (!getExtensionDryRun()) && ($test)) {
358 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": LOAD!");
359 if ($logout === true) {
360 // Then redirect to logout
361 redirectToUrl('modules.php?module=admin&logout=1&' . getExtensionMode() . '=sql_patches');
363 // Add temporary filter
364 registerFilter('shutdown', 'REDIRECT_TO_LOGOUT_SQL_PATCHES', true, true);
365 $GLOBALS['ext_load_mode'] = getExtensionMode();
369 // Return status code
370 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()." - LEFT!");
371 //* DEBUG: */ print getCurrentExtensionName().':<pre>'.print_r($ret, true).'</pre>';
375 // Run SQL queries for given extension id
376 // @TODO Change from ext_id to ext_name (not just even the variable! ;-) )
377 function doExtensionSqls ($ext_id, $load_mode) {
378 // This shall never do a non-admin user!
379 if (!isAdmin()) return false;
381 // Get extension's name
382 $ext_name = getExtensionName($ext_id);
384 // Set current SQL name
385 setCurrentExtensionName($ext_name);
387 // Init EXT_UPDATE_DEPENDS
388 initExtensionUpdateDependencies();
393 // By default no SQL has been executed
396 // Load extension in detected mode
397 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ":ext_name[{$ext_id}]=".getCurrentExtensionName()."");
398 loadExtension(getCurrentExtensionName(), $load_mode, '', false);
402 setSqlsArray(getExtensionSqls());
404 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ":SQLs::count=".countSqls()."");
406 // Run SQL commands...
407 runFilterChain('run_sqls');
410 // Run any filters depending on the action here
411 runFilterChain('extension_' . $load_mode);
413 // Remove cache file(s) if extension is active
414 if (((isExtensionActive('cache')) && ((SQL_AFFECTEDROWS() == 1)) || ($sqlRan === true) || ($load_mode == 'activate') || ($load_mode == 'deactivate'))) {
416 runFilterChain('post_extension_run_sql', getCurrentExtensionName());
419 // Is this the sql_patches?
420 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": id=".$ext_id.",currName=".getCurrentExtensionName().",loadMode=".$load_mode);
421 if ((getCurrentExtensionName() == 'sql_patches') && (($load_mode == 'register') || ($load_mode == 'remove'))) {
422 // Then redirect to logout
423 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": LOAD!");
424 redirectToUrl('modules.php?module=admin&logout=1&' . $load_mode . '=sql_patches');
428 // Check wether the given extension is installed
429 function isExtensionInstalled ($ext_name) {
430 // We don't like empty extension names here
431 if (empty($ext_name)) {
432 // Please fix them all
433 debug_report_bug(__FUNCTION__.': ext_name is empty.');
436 // By default non is installed
437 $isInstalled = false;
439 // Check if there is a cache entry
440 if (isset($GLOBALS['ext_is_installed'][$ext_name])) {
441 // Use cache built from below queries
442 $isInstalled = $GLOBALS['ext_is_installed'][$ext_name];
443 } elseif (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) {
448 incrementStatsEntry('cache_hits');
449 } elseif ((isInstallationPhase())) {
450 // Extensions are all inactive/not installed during installation
453 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
454 array($ext_name), __FILE__, __LINE__);
456 // Do we have a record?
457 $isInstalled = (SQL_NUMROWS($result) == 1);
459 // Is it installed, then cache the entry
460 if ($isInstalled === true) {
461 // Dummy call (get is okay here)
462 getExtensionId($ext_name, true);
466 SQL_FREERESULT($result);
468 // Remember the status
469 $GLOBALS['ext_is_installed'][$ext_name] = $isInstalled;
476 // Check if given extension is active
477 function isExtensionActive ($ext_name) {
478 // Extensions are all inactive during installation
479 if ((isInstallationPhase()) || (empty($ext_name))) return false;
481 // Not active is the default
485 if (isset($GLOBALS['cache_array']['extension']['ext_active'][$ext_name])) {
487 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "CACHE! ext_name={$ext_name}");
488 $active = $GLOBALS['cache_array']['extension']['ext_active'][$ext_name];
491 incrementStatsEntry('cache_hits');
492 } elseif (isset($GLOBALS['ext_loaded'][$ext_name])) {
493 // @TODO Extension is loaded, what next?
494 app_die(__FUNCTION__, __LINE__, "LOADED:$ext_name");
495 } elseif (($ext_name == 'cache') || (!isExtensionInstalled('cache'))) {
496 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "DB! ext_name={$ext_name}");
497 // Load from database
498 $result = SQL_QUERY_ESC("SELECT `ext_active` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
499 array($ext_name), __FUNCTION__, __LINE__);
502 if (SQL_NUMROWS($result) == 1) {
504 list($active) = SQL_FETCHROW($result);
508 SQL_FREERESULT($result);
511 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name=".$ext_name."[DB]: {$active}");
512 $GLOBALS['cache_array']['extension']['ext_active'][$ext_name] = $active;
514 // Extension not active!
515 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name=".$ext_name.": Not active!");
516 $GLOBALS['cache_array']['extension']['ext_active'][$ext_name] = 'N';
520 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name={$ext_name},active={$active}");
522 // Is this extension activated? (For admins we always have active extensions...)
523 return ($active == 'Y');
526 // Get version from extensions
527 function getExtensionVersion ($ext_name) {
528 // By default no extension is found
529 $ext_ver = 'invalid';
531 // Empty extension name should be fixed!
532 if (empty($ext_name)) {
533 // Please report this bug!
534 debug_report_bug(__FUNCTION__ . ': ext_name is empty which is not allowed here.');
537 // Extensions are all inactive during installation
538 if (isInstallationPhase()) return '';
539 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": ext_name={$ext_name}");
541 // Is the cache written?
542 if (isset($GLOBALS['cache_array']['extension']['ext_version'][$ext_name])) {
543 // Load data from cache
544 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": CACHE!");
545 $ext_ver = $GLOBALS['cache_array']['extension']['ext_version'][$ext_name];
548 incrementStatsEntry('cache_hits');
549 } elseif ((!isCacheInstanceValid()) || (isset($GLOBALS['cache_array']['extension'])) || (getOutputMode() != 0)) {
550 // Load from database
551 $result = SQL_QUERY_ESC("SELECT `ext_version` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
552 array($ext_name), __FUNCTION__, __LINE__);
553 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": DB - ".SQL_NUMROWS($result)."");
555 // Is the extension there?
556 if (SQL_NUMROWS($result) == 1) {
558 list($ext_ver) = SQL_FETCHROW($result);
559 } elseif (isDebugModeEnabled()) {
561 logDebugMessage(__FUNCTION__, __LINE__, sprintf(": Cannot find extension %s in database!", $ext_name));
565 SQL_FREERESULT($result);
568 $GLOBALS['cache_array']['extension']['ext_version'][$ext_name] = $ext_ver;
571 // Extension version should not be invalid
572 if ($ext_ver == 'invalid') {
573 // Please report this trouble
574 debug_report_bug(sprintf("Extension <strong>%s</strong> has empty version!", $ext_name));
578 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": ret={$ext_ver}");
582 // Updates a given extension with current extension version to latest version
583 function updateExtension ($ext_name, $ext_ver, $dry_run = false) {
584 // Only admins are allowed to update extensions
585 if ((!isAdmin()) || (empty($ext_name))) return false;
587 // Set current SQL name
588 setCurrentExtensionName($ext_name);
592 initExtensionNotes();
593 initIncludePool('extension');
595 // Load extension in test mode
596 loadExtension($ext_name, 'test', $ext_ver, getExtensionDryRun());
598 // Save version history
599 $history = getExtensionVersionHistory();
601 // Remove old SQLs array to prevent possible bugs
604 // Check if version is updated
605 //* DEBUG: */ print getCurrentExtensionName().'/'.$ext_name.':'.getThisExtensionVersion().'/'.$ext_ver.'/'.intval(is_array($history)).'<br />';
606 if (((getThisExtensionVersion() != $ext_ver) || (getExtensionDryRun())) && (is_array($history))) {
607 // Search for starting point
608 $start = array_search($ext_ver, $history);
610 // And load SQL queries in order of version history
611 for ($idx = ($start + 1); $idx < count($history); $idx++) {
612 // Set extension version
613 $GLOBALS['update_ver'][getCurrentExtensionName()] = $history[$idx];
616 loadExtension(getCurrentExtensionName(), 'update', $GLOBALS['update_ver'][getCurrentExtensionName()], getExtensionDryRun());
619 $depencies = getExtensionUpdateDependencies();
622 if (count($depencies) > 0) {
623 // Apply all extension depencies
624 foreach ($depencies as $ext_depend) {
625 // Did we already update/register this?
626 if (!isset($GLOBALS['ext_updated'][$ext_depend])) {
628 setCurrentExtensionName($ext_depend);
630 // Mark it as already updated before we update it
631 $GLOBALS['ext_updated'][$ext_depend] = true;
633 // Is the extension there?
634 if (isExtensionInstalled($ext_depend)) {
635 // Update another extension first!
636 $test = updateExtension($ext_depend, getExtensionVersion($ext_depend), getExtensionDryRun());
638 // Register new extension
639 $test = registerExtension($ext_depend, 0, getExtensionDryRun(), false);
645 setCurrentExtensionName($ext_name);
649 addExtensionNotes($history[$idx]);
652 // In real-mode execute any existing includes
653 if (getExtensionDryRun() === false) {
654 $GLOBALS['ext_inc_pool'][getCurrentExtensionName()] = getIncludePool('extension');
655 runFilterChain('load_includes', 'extension');
656 setIncludePool('extension', $GLOBALS['ext_inc_pool'][getCurrentExtensionName()]);
657 unset($GLOBALS['ext_inc_pool'][getCurrentExtensionName()]);
662 setSqlsArray(getExtensionSqls());
665 runFilterChain('run_sqls', array('dry_run' => getExtensionDryRun()));
667 if (getExtensionDryRun() === false) {
668 // Run filters on success extension update
669 runFilterChain('extension_update', getCurrentExtensionName());
674 // Output verbose SQL table for extension
675 function addExtensionVerboseSqlTable ($title = '', $dashed = '', $switch = false, $width = '100%') {
678 // Then fix it to default
679 $title = getMessage('ADMIN_SQLS_EXECUTED_ON_REMOVAL');
685 // Do we have queries?
686 if ((getExtensionVersion('sql_patches') >= '0.0.7') && (getConfig('verbose_sql') == 'Y')) {
691 foreach (getExtensionSqls() as $sqls) {
692 // New array format is recursive
693 foreach ($sqls as $idx => $sql) {
697 // Output command if set
699 // Prepare output for template
707 $OUT .= loadTemplate('admin_ext_sql_row', true, $content);
715 // Prepare content for template
723 // Load main template
724 $OUT = loadTemplate('admin_ext_sql_table', true, $content);
725 } elseif ((getExtensionVersion('sql_patches') >= '0.0.7') && (getConfig('verbose_sql') == 'Y')) {
726 // No addional SQL commands to run
727 $OUT = loadTemplate('admin_settings_saved', true, getMessage('ADMIN_NO_ADDITIONAL_SQLS'));
734 // Get extension name from id
735 function getExtensionName ($ext_id) {
736 // Init extension name
740 if (isset($GLOBALS['cache_array']['extension']['ext_name'][$ext_id])) {
742 $ret = $GLOBALS['cache_array']['extension']['ext_name'][$ext_id];
745 incrementStatsEntry('cache_hits');
746 } elseif (!isExtensionActive('cache')) {
747 // Load from database
748 $result = SQL_QUERY_ESC("SELECT `ext_name` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `id`=%s LIMIT 1",
749 array(bigintval($ext_id)), __FUNCTION__, __LINE__);
751 // Is the entry there?
752 if (SQL_NUMROWS($result) == 1) {
753 // Get the extension's name from database
754 list($ret) = SQL_FETCHROW($result);
758 SQL_FREERESULT($result);
761 // Did we find some extension?
763 // We should fix these all!
764 debug_report_bug(__FUNCTION__ . ': ext_name is empty. ext_id=' . $ext_id);
767 // Return the extension name
771 // Get extension id from name
772 function getExtensionId ($ext_name, $forceDb = false) {
776 if (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) {
778 $ret = $GLOBALS['cache_array']['extension']['ext_id'][$ext_name];
781 incrementStatsEntry('cache_hits');
782 } elseif (($forceDb === true) || (!isExtensionActive('cache'))) {
783 // Load from database
784 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
785 array($ext_name), __FUNCTION__, __LINE__);
787 // Is the entry there?
788 if (SQL_NUMROWS($result) == 1) {
789 // Get the extension's id from database
790 list($ret) = SQL_FETCHROW($result);
794 SQL_FREERESULT($result);
797 $GLOBALS['cache_array']['extension']['ext_id'][$ext_name] = $ret;
801 // We should fix these all!
802 debug_report_bug(__FUNCTION__ . ': Invalid extension name found. ext_name=' . $ext_name);
809 // Determines wether the given extension name is valid
810 function isExtensionNameValid ($ext_name) {
812 if (!isset($GLOBALS['ext_name_valid'][$ext_name])) {
813 // Generate include file name
814 $INC = sprintf("inc/extensions/ext-%s.php", $ext_name);
816 // Is there a file in inc/extensions/ ?
817 $GLOBALS['ext_name_valid'][$ext_name] = isIncludeReadable($INC);
821 return $GLOBALS['ext_name_valid'][$ext_name];
824 // Determines wether the given extension id is valid
825 function isExtensionIdValid ($ext_id) {
826 // Default is nothing valid
829 // Check in cache then in database
830 if (isset($GLOBALS['cache_array']['extension']['ext_name'][$ext_id])) {
835 incrementStatsEntry('cache_hits');
838 $isValid = (countSumTotalData($ext_id, 'extensions', 'id', 'id', true) == 1);
845 // Activate given extension
846 function doActivateExtension ($ext_name) {
847 // Activate the extension
848 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='Y' WHERE `ext_name`='%s' LIMIT 1",
849 array($ext_name), __FUNCTION__, __LINE__);
851 // Extension has been activated?
852 if (SQL_AFFECTEDROWS() == 1) {
853 // Then run all queries
854 doExtensionSqls(getExtensionId($ext_name), 'activate');
858 // Deactivate given extension
859 function doDeactivateExtension($ext_name) {
860 // Activate the extension
861 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='N' WHERE `ext_name`='%s' LIMIT 1",
862 array($ext_name), __FUNCTION__, __LINE__);
864 // Extension has been activated?
865 if (SQL_AFFECTEDROWS() == 1) {
866 // Then run all queries
867 doExtensionSqls(getExtensionId($ext_name), 'deactivate');
870 createExtensionDeactivationTask($ext_name);
873 sendAdminNotification(
874 getMessage('ADMIN_SUBJECT_EXTENSION_DEACTIVATED'),
875 'admin_ext_deactivated',
876 array('ext_name' => $ext_name)
881 // Checks wether the extension is older than given
882 function isExtensionOlder ($ext_name, $ext_ver) {
883 // Get current extension version
884 $currVersion = getExtensionVersion($ext_name);
886 // Remove all dots from both versions
887 $currVersion = str_replace('.', '', $currVersion);
888 $ext_ver = str_replace('.', '', $ext_ver);
890 // Now compare both and return the result
891 return ($currVersion < $ext_ver);
894 // Creates a new task for updated extension
895 function createExtensionUpdateTask ($adminId, $ext_name, $ext_ver, $notes) {
896 // Create subject line
897 $subject = '[UPDATE-' . $ext_name . '-' . $ext_ver . ':] {--ADMIN_UPDATE_EXT_SUBJ--}';
899 // Is the extension there?
900 if (isExtensionInstalled($ext_name)) {
901 // Check if task is not there
902 if (determineTaskIdBySubject($subject) == 0) {
903 // Create extension update-task
904 createNewTask($subject, $notes, 'EXTENSION_UPDATE', 0, $adminId);
907 // Extension not there! :-(
908 debug_report_bug(sprintf("Extension <strong>%s</strong> not found but should be updated?", $ext_name));
912 // Creates a new task for newly installed extension
913 function createNewExtensionTask ($adminId, $subject, $ext) {
914 // Not installed and do we have created a task for the admin?
915 if ((determineTaskIdBySubject($subject) == 0) && (!isExtensionInstalled($ext))) {
916 // Set default message if ext-foo is missing
917 $message = sprintf(getMessage('ADMIN_EXT_TEXT_FILE_MISSING'), $ext);
920 $tpl = sprintf("%stemplates/%s/html/ext/ext_%s.tpl",
926 // Load text for task if found
927 if (isFileReadable($tpl)) {
928 // Load extension's own text template (HTML!)
929 $message = loadTemplate('ext_' . $ext, true);
931 // Write this in debug.log as well
932 logDebugMessage(__FUNCTION__, __LINE__, $message);
935 // Task not created so it's a brand-new extension which we need to register and create a task for!
936 createNewTask($subject, $message, 'EXTENSION', 0, $adminId, false);
940 // Creates a task for automatically deactivated (deprecated) extension
941 function createExtensionDeactivationTask ($ext) {
942 // Create subject line
943 $subject = sprintf("[%s:] %s", $ext, getMessage('TASK_SUBJ_EXTENSION_DEACTIVATED'));
945 // Not installed and do we have created a task for the admin?
946 if ((determineTaskIdBySubject($subject) == 0) && (getExtensionVersion($ext) != '')) {
947 // Task not created so add it
948 createNewTask($subject, SQL_ESCAPE(loadTemplate('task_ext_deactivated', true, $ext)), 'EXTENSION_DEACTIVATION');
952 // Checks if the module has a menu
953 function ifModuleHasMenu ($mod, $forceDb = false) {
954 // All is false by default
957 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "mod={$mod},cache=".getExtensionVersion('cache'));
958 if (isExtensionInstalledAndNewer('cache', '0.1.2')) {
959 // Cache version is okay, so let's check the cache!
960 if (isset($GLOBALS['cache_array']['modules']['has_menu'][$mod])) {
961 // Check module cache and count hit
962 $ret = ($GLOBALS['cache_array']['modules']['has_menu'][$mod] == 'Y');
963 incrementStatsEntry('cache_hits');
964 } elseif (isset($GLOBALS['cache_array']['extension']['ext_menu'][$mod])) {
965 // Check cache and count hit
966 $ret = ($GLOBALS['cache_array']['extension']['ext_menu'][$mod] == 'Y');
967 incrementStatsEntry('cache_hits');
968 } elseif ($mod == 'admin') {
969 // Admin module has always a menu!
972 } elseif ((isExtensionInstalled('sql_patches')) && (getExtensionVersion('sql_patches') >= '0.3.6') && ((!isExtensionActive('cache')) || ($forceDb === true))) {
973 // Check database for entry
974 $result = SQL_QUERY_ESC("SELECT `has_menu` FROM `{?_MYSQL_PREFIX?}_mod_reg` WHERE `module`='%s' LIMIT 1",
975 array($mod), __FUNCTION__, __LINE__);
978 if (SQL_NUMROWS($result) == 1) {
979 // Load "has_menu" column
980 list($has_menu) = SQL_FETCHROW($result);
983 $GLOBALS['cache_array']['extension']['ext_menu'][$mod] = $has_menu;
985 // Does it have a menu?
986 $ret = ($has_menu == 'Y');
990 SQL_FREERESULT($result);
991 } elseif (!isExtensionInstalled('sql_patches')) {
992 // No sql_patches installed, so maybe in admin area or no admin registered?
993 $ret = (((isAdmin()) || (!isAdminRegistered())) && ($mod == 'admin')); // Then there is a menu!
997 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName().intval($ret));
1001 // Determines the task id for given extension
1002 function determineExtensionTaskId ($ext_name) {
1003 // Default is not found
1006 // Search for extension task's id
1007 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `task_type`='EXTENSION' AND `subject`='[%s:]' LIMIT 1",
1008 array($ext_name), __FUNCTION__, __LINE__);
1011 if (SQL_NUMROWS($result) == 1) {
1012 // Task found so load task's id and register extension...
1013 list($task_id) = SQL_FETCHROW($result);
1017 SQL_FREERESULT($result);
1023 // Determines the task id for given subject
1024 function determineTaskIdBySubject ($subject) {
1025 // Default is not found
1028 // Search for task id
1029 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `subject` LIKE '%s%%' LIMIT 1",
1030 array($subject), __FUNCTION__, __LINE__);
1033 if (SQL_NUMROWS($result) == 1) {
1034 // Task found so load task's id and register extension...
1035 list($task_id) = SQL_FETCHROW($result);
1039 SQL_FREERESULT($result);
1045 // Add updates notes for given version
1046 function addExtensionNotes ($ver) {
1047 // Init notes/content
1048 $out = ''; $content = array();
1050 // Is do we have verbose output enabled?
1051 if ((!isExtensionActive('sql_patches')) || (getConfig('verbose_sql') == 'Y')) {
1052 // Update notes found?
1053 if (getExtensionUpdateNotes($ver) != '') {
1054 // Update notes found
1057 'notes' => getExtensionUpdateNotes($ver)
1061 setExtensionUpdateNotes('', $ver);
1062 } elseif (($ver == '0.0') || ($ver == '0.0.0')) {
1066 'notes' => getMessage('INITIAL_RELEASE')
1069 // No update notes found!
1072 'notes' => getMessage('NO_UPDATE_NOTES')
1077 $out = loadTemplate('admin_ext_notes', true, $content);
1081 appendExtensionNotes($out);
1084 // Getter for CSS files array
1085 function getExtensionCssFiles () {
1086 // By default no additional CSS files are found
1087 $cssFiles = array();
1089 // Is the array there?
1090 if (isset($GLOBALS['css_files'])) {
1092 $cssFiles = $GLOBALS['css_files'];
1099 // Init CSS files array
1100 function initExtensionCssFiles () {
1102 $GLOBALS['css_files'] = array();
1106 function addExtensionCssFile ($file) {
1107 // Is the array there?
1108 if (!isset($GLOBALS['css_files'])) {
1109 // Then auto-init them
1110 initExtensionCssFiles();
1114 $GLOBALS['css_files'][] = $file;
1117 // Setter for EXT_ALWAYS_ACTIVE flag
1118 function setExtensionAlwaysActive ($active) {
1119 $GLOBALS['ext_always_active'][getCurrentExtensionName()] = (string) $active;
1122 // Getter for EXT_ALWAYS_ACTIVE flag
1123 function getExtensionAlwaysActive () {
1124 return $GLOBALS['ext_always_active'][getCurrentExtensionName()];
1127 // Setter for EXT_VERSION flag
1128 function setThisExtensionVersion ($version) {
1129 $GLOBALS['ext_version'][getCurrentExtensionName()] = (string) $version;
1132 // Getter for EXT_VERSION flag
1133 function getThisExtensionVersion () {
1134 return $GLOBALS['ext_version'][getCurrentExtensionName()];
1137 // Setter for EXT_DEPRECATED flag
1138 function setExtensionDeprecated ($deprecated) {
1139 $GLOBALS['ext_deprecated'][getCurrentExtensionName()] = (string) $deprecated;
1142 // Getter for EXT_DEPRECATED flag
1143 function isExtensionDeprecated () {
1144 return ($GLOBALS['ext_deprecated'][getCurrentExtensionName()] == 'Y');
1147 // Setter for EXT_UPDATE_DEPENDS flag
1148 function addExtensionUpdateDependency ($updateDepends) {
1149 // Is the update depency empty? (NEED TO BE FIXED!)
1150 if (empty($updateDepends)) {
1151 // Please report this bug!
1152 debug_report_bug("updateDepends is left empty!");
1155 // Is it not yet added?
1156 if (!in_array($updateDepends, $GLOBALS['ext_running_updates'])) {
1157 //* DEBUG */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName().'/'.$updateDepends);
1158 // Add it to the list of extension update depencies map
1159 $GLOBALS['ext_update_depends'][getCurrentExtensionName()][] = (string) $updateDepends;
1161 // Remember it in the list of running updates
1162 $GLOBALS['ext_running_updates'][] = $updateDepends;
1166 // Checks wether the given extension registration is in progress
1167 function isExtensionRegisterRunning ($ext_name) {
1168 return ((isset($GLOBALS['ext_register_running'])) && (in_array($ext_name, $GLOBALS['ext_register_running'])));
1171 // Init EXT_UPDATE_DEPENDS flag
1172 function initExtensionUpdateDependencies () {
1173 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1175 // Init update depency map automatically if not found
1176 if (!isExtensionUpdateDependenciesInitialized()) {
1177 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()." - INIT!");
1178 $GLOBALS['ext_update_depends'][getCurrentExtensionName()] = array();
1181 // Init running updates array
1182 initExtensionRuningUpdates();
1185 // Adds an extension as "registration in progress"
1186 function addExtensionRunningRegistration ($ext_name) {
1188 if (!isExtensionRegisterRunning($ext_name)) {
1190 $GLOBALS['ext_register_running'][] = $ext_name;
1194 // Checks wether EXT_UPDATE_DEPENDS is initialized
1195 function isExtensionUpdateDependenciesInitialized () {
1196 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1197 return (isset($GLOBALS['ext_update_depends'][getCurrentExtensionName()]));
1200 // Initializes the list of running updates
1201 function initExtensionRuningUpdates () {
1202 // Auto-init ext_running_updates
1203 if (!isset($GLOBALS['ext_running_updates'])) {
1204 $GLOBALS['ext_running_updates'] = array();
1205 $GLOBALS['ext_register_running'] = array();
1209 // Getter for EXT_UPDATE_DEPENDS flag
1210 function getExtensionUpdateDependencies () {
1211 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1212 return $GLOBALS['ext_update_depends'][getCurrentExtensionName()];
1215 // Getter for next iterator depency
1216 function getExtensionUpdateDependenciesIterator () {
1217 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1218 return ($GLOBALS['ext_update_depends'][getCurrentExtensionName()][getExtensionUpdateIterator()]);
1221 // Counter for extension update depencies
1222 function countExtensionUpdateDependencies () {
1223 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1224 return count($GLOBALS['ext_update_depends'][getCurrentExtensionName()]);
1227 // Removes given extension from update denpency list
1228 function removeExtensionUpdateDependency ($ext_name) {
1230 $key = array_search($ext_name, getExtensionUpdateDependencies());
1233 if ($key !== false) {
1235 unset($GLOBALS['ext_update_depends'][getCurrentExtensionName()][$key]);
1237 // And sort the array
1238 ksort($GLOBALS['ext_update_depends'][getCurrentExtensionName()]);
1242 // Init iterator for update depencies
1243 function initExtensionUpdateIterator () {
1244 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1245 $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()] = 0;
1248 // Getter for depency iterator
1249 function getExtensionUpdateIterator () {
1250 // Auto-init iterator
1251 if (!isset($GLOBALS['ext_depend_iterator'][getCurrentExtensionName()])) initExtensionUpdateIterator();
1254 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName().'/'.$GLOBALS['ext_depend_iterator'][getCurrentExtensionName()]);
1255 return $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()];
1258 // Increments the update iterator
1259 function incrementExtensionUpdateIterator () {
1260 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1261 $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()]++;
1264 // Setter for EXT_REPORTS_FAILURE flag
1265 function setExtensionReportsFailure ($reportsFailure) {
1266 $GLOBALS['ext_reports_failure'] = (bool) $reportsFailure;
1269 // Getter for EXT_REPORTS_FAILURE flag
1270 function getExtensionReportsFailure () {
1271 return $GLOBALS['ext_reports_failure'];
1274 // Setter for EXT_VER_HISTORY flag
1275 function setExtensionVersionHistory ($verHistory) {
1276 $GLOBALS['ext_ver_history'][getCurrentExtensionName()] = (array) $verHistory;
1279 // Getter for EXT_VER_HISTORY array
1280 function getExtensionVersionHistory () {
1281 return $GLOBALS['ext_ver_history'][getCurrentExtensionName()];
1284 // Setter for EXT_UPDATE_NOTES
1285 function setExtensionUpdateNotes ($updateNotes, $ver='') {
1286 //* DEBUG: */ print __FUNCTION__.':'.getCurrentExtensionName().'/'.getCurrentExtensionVersion().'/'.$ver.'='.$updateNotes.'<br />';
1288 $GLOBALS['ext_update_notes'][getCurrentExtensionName()][getCurrentExtensionVersion()] = (string) $updateNotes;
1290 $GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ver] = (string) $updateNotes;
1294 // Getter for EXT_UPDATE_NOTES
1295 function getExtensionUpdateNotes ($ver) {
1296 return $GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ver];
1299 // Init extension notice
1300 function initExtensionNotes () {
1301 $GLOBALS['ext_notes'][getCurrentExtensionName()] = '';
1304 // Append extension notice
1305 function appendExtensionNotes ($notes) {
1306 $GLOBALS['ext_notes'][getCurrentExtensionName()] .= (string) trim($notes);
1309 // Getter for extension notes
1310 function getExtensionNotes () {
1311 return $GLOBALS['ext_notes'][getCurrentExtensionName()];
1314 // Setter for current extension name
1315 function setCurrentExtensionName ($ext_name) {
1316 $GLOBALS['curr_ext_name'] = (string) trim($ext_name);
1319 // Getter for current extension name
1320 function getCurrentExtensionName () {
1321 if (isset($GLOBALS['curr_ext_name'])) {
1322 return $GLOBALS['curr_ext_name'];
1326 debug_report_bug(__FUNCTION__.": curr_ext_name not initialized. Please execute initExtensionSqls() before calling this function.");
1329 // Init SQLs array for current extension
1330 function initExtensionSqls () {
1331 // Auto-init the array now...
1332 if (!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()])) {
1333 $GLOBALS['ext_sqls'][getCurrentExtensionName()] = array();
1337 // Adds SQLs to the SQLs array but "assigns" it with current extension name
1338 function addExtensionSql ($sql) {
1340 $GLOBALS['ext_sqls'][getCurrentExtensionName()][getCurrentExtensionVersion()][] = $sql;
1343 // Getter for SQLs array for current extension
1344 function getExtensionSqls () {
1345 // Output debug backtrace if not found (SHOULD NOT HAPPEN!)
1346 if (!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()])) {
1347 // Not found, should not happen
1348 debug_report_bug(sprintf("ext_sqls is empty, current extension: %s",
1349 getCurrentExtensionName()
1354 return $GLOBALS['ext_sqls'][getCurrentExtensionName()];
1357 // Removes SQLs for current extension
1358 function unsetExtensionSqls () {
1359 unset($GLOBALS['ext_sqls'][getCurrentExtensionName()]);
1362 // Auto-initializes the removal list
1363 function initExtensionRemovalList () {
1364 // Is the remove list there?
1365 if (!isset($GLOBALS['ext_update_remove'])) {
1367 $GLOBALS['ext_update_remove'] = array();
1371 // Checks wether the current extension is on the removal list
1372 function isExtensionOnRemovalList () {
1373 // Init removal list
1374 initExtensionRemovalList();
1377 return (in_array(getCurrentExtensionName(), $GLOBALS['ext_update_remove']));
1380 // Adds the current extension to the removal list
1381 function addCurrentExtensionToRemovalList () {
1383 $GLOBALS['ext_update_remove'][] = getCurrentExtensionName();
1386 // Getter for removal list
1387 function getExtensionRemovalList () {
1388 // Return the removal list
1389 return $GLOBALS['ext_update_remove'];
1392 // Redirects if the provided extension is not installed
1393 function redirectOnUninstalledExtension ($ext_name) {
1394 // So is the extension there?
1395 if ((!isExtensionInstalled($ext_name)) || (!isExtensionActive($ext_name))) {
1396 // Redirect to index
1397 redirectToUrl('modules.php?module=index&code=' . getCode('EXTENSION_PROBLEM') . '&ext=' . $ext_name);
1401 // Filter for initialization of all extensions by loading them in 'init' mode
1402 function FILTER_INIT_EXTENSIONS () {
1403 // Do we have some entries?
1404 //* DEBUG */ print __FUNCTION__.': ENTRY!<br />';
1405 if (isset($GLOBALS['cache_array']['extension']['ext_name'])) {
1406 // Load all found extensions if found
1407 //* DEBUG */ print __FUNCTION__.': CACHE - START!<br />';
1408 foreach ($GLOBALS['cache_array']['extension']['ext_name'] as $key => $ext_name) {
1410 //* DEBUG */ print __FUNCTION__.': '.$ext_name.' - START<br />';
1411 loadExtension($ext_name, 'init');
1412 //* DEBUG */ print __FUNCTION__.': '.$ext_name.' - END<br />';
1414 //* DEBUG */ print __FUNCTION__.': CACHE - END!<br />';
1416 //* DEBUG */ print __FUNCTION__.': EXIT!<br />';
1419 // Setter for extension mode
1420 function setExtensionMode ($ext_mode) {
1421 $GLOBALS['ext_mode'] = (string) $ext_mode;
1424 // Getter for extension mode
1425 function getExtensionMode () {
1426 return $GLOBALS['ext_mode'];
1429 // Setter for dry-run
1430 function enableExtensionDryRun ($dry_run = true) {
1431 //* DEBUG: */ print __FUNCTION__.': '.getCurrentExtensionName().'='.intval($dry_run).'<br />';
1432 $GLOBALS['ext_dry_run'] = (bool) $dry_run;
1435 // Getter for dry-run
1436 function getExtensionDryRun () {
1437 return $GLOBALS['ext_dry_run'];
1440 // Setter for current extension version
1441 function setCurrentExtensionVersion ($ext_ver) {
1442 if (empty($ext_ver)) {
1444 $GLOBALS['ext_current_version'] = '0.0';
1447 $GLOBALS['ext_current_version'] = (string) $ext_ver;
1451 // Getter for current extension version
1452 function getCurrentExtensionVersion () {
1453 return $GLOBALS['ext_current_version'];
1456 // Remove the extension from global cache array
1457 function removeExtensionFromArray () {
1458 // "Cache" this name
1459 $ext_name = getCurrentExtensionName();
1461 // Now loop through the whole cache
1462 foreach ($GLOBALS['cache_array']['extension'] as $cacheName=>$cacheArray) {
1463 // Is it an element?
1464 if (isset($cacheArray[$ext_name])) {
1466 unset($cacheArray[$ext_name]);
1467 $GLOBALS['cache_array']['extension'][$cacheName] = $cacheArray;
1470 $key = array_search($ext_name, $cacheArray);
1473 if ($key !== false) {
1474 // Found, so remove it
1475 unset($cacheArray[$key]);
1476 $GLOBALS['cache_array']['extension'][$cacheName] = $cacheArray;
1482 // "Getter" for 'extension has a CSS file' (with same name, of course)
1483 function getExtensionHasCss () {
1484 // Default is no CSS
1487 // Construct FQFN for check
1488 $FQFN = sprintf("%stheme/%s/css/%s.css",
1491 getCurrentExtensionName()
1495 if (isFileReadable($FQFN)) {
1496 // Readable, so it is there...
1504 // Checks wether the given extension has a language file
1505 function ifExtensionHasLanguageFile ($ext_name) {
1506 // Default is no language file
1507 $hasLanguage = false;
1509 // Do we have cache?
1510 if (isset($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name])) {
1512 $hasLanguage = ($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] == 'Y');
1515 incrementStatsEntry('cache_hits');
1517 // Not readable is default
1520 // Is the language file readable for this extension?
1521 if (isLanguageIncludeReadable($ext_name)) {
1527 $GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] = 'Y';
1531 return ($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] == 'Y');
1534 // Load an extension's include file
1535 function loadExtensionInclude () {
1537 if (!isExtensionIncludeReadable()) {
1539 debug_report_bug('Extension ' . getCurrentExtensionName() . ' should be loaded, but is not readable.');
1542 // Generate INC name
1543 $INC = sprintf("inc/extensions/ext-%s.php", getCurrentExtensionName());
1549 // Checks wether an extension is readable
1550 function isExtensionIncludeReadable ($ext_name = '') {
1551 // If empty, use current
1552 if (empty($ext_name)) $ext_name = getCurrentExtensionName();
1555 if (!isset($GLOBALS['ext_inc_readable'][$ext_name])) {
1556 // Generate INC name
1557 $INC = sprintf("inc/extensions/ext-%s.php", getCurrentExtensionName());
1560 $GLOBALS['ext_inc_readable'][$ext_name] = isIncludeReadable($INC);
1564 //* DEBUG: */ print __FUNCTION__.': '.$ext_name.'='.intval($GLOBALS['ext_inc_readable'][$ext_name]).'<br />';
1565 return $GLOBALS['ext_inc_readable'][$ext_name];
1568 // Checks if an extension's function file is readable
1569 function isExtensionFunctionFileReadable ($ext_name) {
1570 if (isset($GLOBALS['cache_array']['extension']['ext_func'][$ext_name])) {
1571 // Just count cache hits
1572 incrementStatsEntry('cache_hits');
1574 // Construct FQFN for functions file
1575 $funcsInclude = sprintf("inc/libs/%s_functions.php", $ext_name);
1577 // Is this include there?
1578 if ((isFileReadable($funcsInclude)) && (!isset($GLOBALS['ext_loaded']['funcs'][$ext_name])) && (getExtensionMode() == 'test')) {
1580 $GLOBALS['cache_array']['extension']['ext_func'][$ext_name] = 'Y';
1583 $GLOBALS['cache_array']['extension']['ext_func'][$ext_name] = 'N';
1588 return ($GLOBALS['cache_array']['extension']['ext_func'][$ext_name] == 'Y');
1591 // Adds an admin menu to the SQL queue of the menu entry is not found
1592 function addAdminMenuSql ($action, $what, $title, $descr, $sort) {
1593 // Now check if this menu is there
1594 if (!isMenuActionValid('admin', $action, $what)) {
1596 if (is_null($what)) {
1598 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES('%s',NULL,'%s','%s',%s)",
1606 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES('%s','%s','%s','%s',%s)",
1615 // Add it to the queue
1616 addExtensionSql($sql);
1617 } elseif (isDebugModeEnabled()) {
1618 // Double menus should be located and fixed!
1619 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double admin menu action=%s, what=%s detected.", $action, $what));
1623 // Adds a guest menu to the SQL queue if the menu entry is not found
1624 function addGuestMenuSql ($action, $what, $title, $visible, $locked, $sort) {
1625 // Now check if this menu is there
1626 if (!isMenuActionValid('guest', $action, $what)) {
1628 if (is_null($what)) {
1630 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s',NULL,'%s','%s','%s',%s)",
1639 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s','%s','%s','%s','%s',%s)",
1649 // Add it to the queue
1650 addExtensionSql($sql);
1651 } elseif (isDebugModeEnabled()) {
1652 // Double menus should be located and fixed!
1653 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double guest menu action=%s, what=%s detected.", $action, $what));
1657 // Adds a member menu to the SQL queue if the menu entry is not found
1658 function addMemberMenuSql ($action, $what, $title, $visible, $locked, $sort) {
1659 // Now check if this menu is there
1660 if (!isMenuActionValid('member', $action, $what)) {
1662 if (is_null($what)) {
1664 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s',NULL,'%s','%s','%s',%s)",
1673 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s','%s','%s','%s','%s',%s)",
1683 // Add it to the queue
1684 addExtensionSql($sql);
1685 } elseif (isDebugModeEnabled()) {
1686 // Double menus should be located and fixed!
1687 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double member menu action=%s, what=%s detected.", $action, $what));
1691 // Adds a sponsor menu to the SQL queue if the menu entry is not found
1692 function addSponsorMenuSql ($action, $what, $title, $active, $sort) {
1693 // Now check if this menu is there, if no ext-sponsor is installed all is not yet added
1694 if ((!isExtensionInstalled('sponsor')) || (!isMenuActionValid('sponsor', $action, $what))) {
1696 if (is_null($what)) {
1698 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_menu` (`action`,`what`,`title`,`active`,`sort`) VALUES('%s',NULL,'%s','%s',%s)",
1706 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_menu` (`action`,`what`,`title`,`active`,`sort`) VALUES('%s','%s','%s','%s',%s)",
1715 // Add it to the queue
1716 addExtensionSql($sql);
1717 } elseif (isDebugModeEnabled()) {
1718 // Double menus should be located and fixed!
1719 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double sponsor menu action=%s, what=%s detected.", $action, $what));
1723 // Enables/disables productive mode for current extension (used only while
1725 function enableExtensionProductive ($isProductive = true) {
1726 $GLOBALS['ext_productive'][getCurrentExtensionName()] = (bool) $isProductive;
1729 // Checks wether the extension is in productive phase. If not set, development
1730 // phase (=false) is assumed.
1731 function isExtensionProductive () {
1732 return ((isset($GLOBALS['ext_productive'][getCurrentExtensionName()])) && ($GLOBALS['ext_productive'][getCurrentExtensionName()] === true));