2 /************************************************************************
3 * Mailer v0.2.1-FINAL 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 * Copyright (c) 2009, 2010 by Mailer Developer Team *
22 * For more information visit: http://www.mxchange.org *
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. *
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. *
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, *
38 ************************************************************************/
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
45 // Load the extension and maybe found language and function files.
46 function loadExtension ($ext_name, $ext_mode = 'init', $ext_ver = '', $dry_run = false) {
47 // Set current extension name
48 setCurrentExtensionName($ext_name);
50 // Set current extension version
51 setCurrentExtensionVersion($ext_ver);
54 setExtensionMode($ext_mode);
57 enableExtensionDryRun($dry_run);
60 initIncludePool('extension');
62 // Init EXT_UPDATE_DEPENDS
63 initExtensionUpdateDependencies();
65 // Init current extension name list
68 // Is the extension already loaded?
69 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "Loading extension {$ext_name}, mode=".getExtensionMode().", ver=".getCurrentExtensionVersion()."");
70 if ((isset($GLOBALS['ext_loaded']['ext'][$ext_name])) && (getExtensionMode() == 'init')) {
72 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Extension %s already loaded.", $ext_name));
78 // Is the extension file NOT there?
79 if (!isExtensionNameValid($ext_name)) {
81 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Extension %s not found or not readable.", $ext_name));
87 // Load extension's own language file if not in test mode
88 if ((getExtensionMode() != 'test') && (ifExtensionHasLanguageFile($ext_name))) {
90 loadLanguageFile($ext_name);
94 if (isExtensionFunctionFileReadable($ext_name)) {
96 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]))) {
97 // Construct FQFN for functions file
98 $funcsInclude = sprintf("inc/libs/%s_functions.php", $ext_name);
101 $GLOBALS['ext_loaded']['funcs'][$ext_name] = true;
103 // Download functions file
104 loadIncludeOnce($funcsInclude);
106 } 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')) {
107 // No functions file is not so good...
108 logDebugMessage(__FUNCTION__, __LINE__, sprintf("NOTICE: Extension %s has no own functions file or we cannot read from it. mode=%s",
114 // Extensions are not deprecated by default
115 setExtensionDeprecated('N');
117 // Extensions are not always active by default
118 setExtensionAlwaysActive('N');
120 // Extension update notes
121 setExtensionUpdateNotes('');
123 // Include the extension file
124 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "Extension loaded.");
125 loadExtensionInclude();
127 // Is this extension deprecated?
128 if (isExtensionDeprecated()) {
129 // Deactivate the extension
130 doDeactivateExtension($ext_name);
136 // Mark it as loaded in normal mode
137 if (getExtensionMode() == '') {
139 $GLOBALS['ext_loaded']['ext'][$ext_name] = true;
146 // Registeres an extension and possible update depencies
147 function registerExtension ($ext_name, $task_id, $dry_run = false, $logout = true) {
148 // Set current extension name
149 setCurrentExtensionName($ext_name);
152 enableExtensionDryRun($dry_run);
154 // By default all extensions are in productive phase
155 enableExtensionProductive();
157 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()." - ENTERED!");
158 // This shall never do a non-admin user or if the extension is active (already installed)
159 if ((!isAdmin()) || (isExtensionInstalled($ext_name))) {
163 // When this extension is already in install/update phase, all is fine
164 if (isExtensionRegisterRunning($ext_name)) {
165 // Then abort here which is fine
166 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()." - ALREADY!");
170 // This registration is running
171 addExtensionRunningRegistration($ext_name);
173 // Init EXT_UPDATE_DEPENDS
174 initExtensionUpdateDependencies();
176 // Is the task id zero? Then we need to auto-fix it here
177 if ($task_id == '0') {
178 // Try to find the task
179 $task_id = determineExtensionTaskId(getCurrentExtensionName());
181 // Still zero and not in dry-run?
182 if (($task_id == '0') && (!getExtensionDryRun())) {
183 // Then request a bug report
184 debug_report_bug(sprintf("%s: task_id is still zero after determineExtensionTaskId(%s)",
186 getCurrentExtensionName()
191 // Init queries and notes
193 initExtensionNotes();
198 initIncludePool('extension');
200 // By default we have no failures
201 setExtensionReportsFailure(false);
203 // Does this extension exists?
204 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()."");
205 if (loadExtension(getCurrentExtensionName(), 'register', '', getExtensionDryRun())) {
206 // Set current extension name again
207 setCurrentExtensionName($ext_name);
209 // And run possible updates
210 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "".getCurrentExtensionName());
211 $history = getExtensionVersionHistory();
212 foreach ($history as $ver) {
213 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name=".getCurrentExtensionName().", ext_ver={$ver}");
214 // Load extension in update mode
215 loadExtension(getCurrentExtensionName(), 'update', $ver, getExtensionDryRun());
217 // Add update notes to our output
218 addExtensionNotes($ver);
221 // Does this extension depends on an outstanding update of another update?
222 for ($dmy = getExtensionUpdateIterator(); getExtensionUpdateIterator() < countExtensionUpdateDependencies();) {
224 $ext_update = getExtensionUpdateDependenciesIterator();
226 // Increment here to avoid endless loop
227 incrementExtensionUpdateIterator();
229 // Check for required file
230 if ((!isExtensionInstalled($ext_update)) && (loadExtension($ext_update, 'register', '', getExtensionDryRun()))) {
231 // Set current extension name again
232 setCurrentExtensionName($ext_name);
234 // If versions mismatch update extension first
236 if (isExtensionInstalled($ext_update)) {
237 // Get version only if installed
238 $ext_ver = getExtensionVersion($ext_update);
241 // Extension version set? If empty the extension is not registered
242 if (empty($ext_ver)) {
243 // Extension not registered so far so first load task's id...
244 $task = determineExtensionTaskId($ext_update);
248 // Try to register the extension
249 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName().":ext_update=".$ext_update.",taskId=".$task."");
250 $test = registerExtension($ext_update, $task, getExtensionDryRun(), false);
252 // Reset extension name
253 setCurrentExtensionName($ext_name);
254 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()); print getCurrentExtensionName().':<pre>'.print_r($test);
256 } elseif ($ext_ver != getCurrentExtensionVersion()) {
257 // Ok, update this extension now
258 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName='.getCurrentExtensionName().',currVer='.getCurrentExtensionVersion().'');
259 $GLOBALS['ext_backup_name'][$ext_update][$ext_ver] = getCurrentExtensionName();
260 $GLOBALS['ext_backup_ver'][$ext_update][$ext_ver] = getCurrentExtensionVersion();
261 updateExtension($ext_update, $ext_ver, getExtensionDryRun());
262 setCurrentExtensionName($GLOBALS['ext_backup_name'][$ext_update][$ext_ver]);
263 setCurrentExtensionVersion($GLOBALS['ext_backup_ver'][$ext_update][$ext_ver]);
264 unset($GLOBALS['ext_backup_name'][$ext_update][$ext_ver]);
265 unset($GLOBALS['ext_backup_ver'][$ext_update][$ext_ver]);
266 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName='.getCurrentExtensionName().',currVer='.getCurrentExtensionVersion().'');
271 // Nothing to register / update before...
275 // Required file for update does not exists!
277 // But this is fine for the first time...
280 // Restore the current extension name
281 setCurrentExtensionName($ext_name);
284 // Is there no update?
285 if (countExtensionUpdateDependencies(getCurrentExtensionName()) == 0) {
286 // Then test is passed!
290 // Switch back to register mode
291 setExtensionMode('register');
293 // Remains true if extension registration reports no failures
294 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()); print getCurrentExtensionName().':<pre>'.print_r($test, true).'</pre>';
295 $test = (($test === true) && (getExtensionReportsFailure() === false));
296 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()); print getCurrentExtensionName().':<pre>'.print_r($test, true).'</pre>';
298 // Does everthing before wents ok?
299 if ($test === true) {
300 // "Dry-run-mode" activated?
301 if ((getExtensionDryRun() === false) && (!isExtensionOnRemovalList())) {
302 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name=".getCurrentExtensionName());
303 // Init SQLs and transfer ext->generic
305 setSqlsArray(getExtensionSqls());
307 // Run installation pre-installation filters
308 runFilterChain('pre_extension_installed', array('dry_run' => getExtensionDryRun()));
310 // Register extension
311 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "insert=".getCurrentExtensionName().'/'.getCurrentExtensionVersion()." - INSERT!");
312 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
314 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_extensions` (`ext_name`, `ext_active`, `ext_version`,`ext_has_css`) VALUES ('%s','%s','%s','%s')",
315 array(getCurrentExtensionName(), getExtensionAlwaysActive(), getCurrentExtensionVersion(), getExtensionHasCss()), __FUNCTION__, __LINE__);
318 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_extensions` (`ext_name`, `ext_active`, `ext_version`) VALUES ('%s','%s','%s')",
319 array(getCurrentExtensionName(), getExtensionAlwaysActive(), getCurrentExtensionVersion()), __FUNCTION__, __LINE__);
322 // Remove cache file(s) if extension is active
323 runFilterChain('post_extension_installed', array(
324 'pool' => 'extension',
325 'ext_name' => getCurrentExtensionName(),
326 'task_id' => $task_id
329 // Remove all SQL commands
332 // Mark it as installed
333 $GLOBALS['ext_is_installed'][getCurrentExtensionName()] = true;
335 // In normal mode return a true on success
337 } elseif (getExtensionDryRun() === true) {
338 // In "dry-run" mode return array with all SQL commands
339 $ret = getExtensionSqls();
341 // Remove all SQL commands
344 // Extension has been removed for updates, so all is fine!
348 // No, an error occurs while registering extension :-(
349 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "".getCurrentExtensionName());
352 } elseif (($task_id > 0) && (getCurrentExtensionName() != '')) {
353 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()."");
354 // Remove task from system when id and extension's name is valid
355 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s AND `status`='NEW' LIMIT 1",
356 array(bigintval($task_id)), __FUNCTION__, __LINE__);
359 // Is this the sql_patches?
360 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ':'.getCurrentExtensionName()."/".getExtensionMode()."");
361 if ((getCurrentExtensionName() == 'sql_patches') && ((getExtensionMode() == 'register') || (getExtensionMode() == 'remove')) && (!getExtensionDryRun()) && ($test)) {
362 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": LOAD!");
363 if ($logout === true) {
364 // Then redirect to logout
365 redirectToUrl('modules.php?module=admin&logout=1&' . getExtensionMode() . '=sql_patches');
367 // Add temporary filter
368 registerFilter('shutdown', 'REDIRECT_TO_LOGOUT_SQL_PATCHES', true, true);
369 $GLOBALS['ext_load_mode'] = getExtensionMode();
373 // Return status code
374 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()." - LEFT!");
375 //* DEBUG: */ print getCurrentExtensionName().':<pre>'.print_r($ret, true).'</pre>';
379 // Run SQL queries for given extension id
380 // @TODO Change from ext_id to ext_name (not just even the variable! ;-) )
381 function doExtensionSqls ($ext_id, $load_mode) {
382 // This shall never do a non-admin user!
383 if (!isAdmin()) return false;
385 // Get extension's name
386 $ext_name = getExtensionName($ext_id);
388 // Set current SQL name
389 setCurrentExtensionName($ext_name);
391 // Init EXT_UPDATE_DEPENDS
392 initExtensionUpdateDependencies();
397 // By default no SQL has been executed
400 // Load extension in detected mode
401 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ":ext_name[{$ext_id}]=".getCurrentExtensionName()."");
402 loadExtension(getCurrentExtensionName(), $load_mode, '', false);
406 setSqlsArray(getExtensionSqls());
408 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ":SQLs::count=".countSqls()."");
410 // Run SQL commands...
411 runFilterChain('run_sqls');
414 // Run any filters depending on the action here
415 runFilterChain('extension_' . $load_mode);
417 // Remove cache file(s) if extension is active
418 if (((isExtensionActive('cache')) && ((SQL_AFFECTEDROWS() == 1)) || ($sqlRan === true) || ($load_mode == 'activate') || ($load_mode == 'deactivate'))) {
420 runFilterChain('post_extension_run_sql', getCurrentExtensionName());
423 // Is this the sql_patches?
424 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": id=".$ext_id.",currName=".getCurrentExtensionName().",loadMode=".$load_mode);
425 if ((getCurrentExtensionName() == 'sql_patches') && (($load_mode == 'register') || ($load_mode == 'remove'))) {
426 // Then redirect to logout
427 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": LOAD!");
428 redirectToUrl('modules.php?module=admin&logout=1&' . $load_mode . '=sql_patches');
432 // Check wether the given extension is installed
433 function isExtensionInstalled ($ext_name) {
434 // We don't like empty extension names here
435 if (empty($ext_name)) {
436 // Please fix them all
437 debug_report_bug(__FUNCTION__.': ext_name is empty.');
440 // By default non is installed
441 $isInstalled = false;
443 // Check if there is a cache entry
444 if (isset($GLOBALS['ext_is_installed'][$ext_name])) {
445 // Use cache built from below queries
446 $isInstalled = $GLOBALS['ext_is_installed'][$ext_name];
447 } elseif (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) {
452 incrementStatsEntry('cache_hits');
453 } elseif ((isInstallationPhase())) {
454 // Extensions are all inactive/not installed during installation
457 $ext_id = getExtensionId($ext_name);
459 // Do we have a record?
460 $isInstalled = ($ext_id > 0);
462 // Is it installed, then cache the entry
463 if ($isInstalled === true) {
464 // Dummy call (get is okay here)
465 getExtensionId($ext_name, true);
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
482 $data['ext_active'] = 'N';
485 if (isset($GLOBALS['cache_array']['extension']['ext_active'][$ext_name])) {
487 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "CACHE! ext_name={$ext_name}");
488 $data['ext_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 $data = SQL_FETCHARRAY($result);
508 SQL_FREERESULT($result);
511 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name=".$ext_name."[DB]: ".$data['ext_active']."");
512 $GLOBALS['cache_array']['extension']['ext_active'][$ext_name] = $data['ext_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=".$data['ext_active']."");
522 // Is this extension activated? (For admins we always have active extensions...)
523 return ($data['ext_active'] == 'Y');
526 // Get version from extensions
527 function getExtensionVersion ($ext_name, $force = false) {
528 // By default no extension is found
529 $data['ext_version'] = 'false';
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__, $ext_name . ': CACHE!');
545 $data['ext_version'] = $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__, $ext_name . ': DB - '.SQL_NUMROWS($result).'');
555 // Is the extension there?
556 if (SQL_NUMROWS($result) == 1) {
558 $data = SQL_FETCHARRAY($result);
559 } elseif (isDebugModeEnabled()) {
560 // Not found, please report all
561 debug_report_bug(sprintf(": Cannot find extension %s in database!", $ext_name));
565 SQL_FREERESULT($result);
568 $GLOBALS['cache_array']['extension']['ext_version'][$ext_name] = $data['ext_version'];
571 // Extension version should not be invalid
572 if (($data['ext_version'] == 'false') && ($force === false)) {
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={$data['ext_version']}");
579 return $data['ext_version'];
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 ((isExtensionInstalledAndNewer('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 ((isExtensionInstalledAndNewer('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
737 $data['ext_name'] = '';
740 if (isset($GLOBALS['cache_array']['extension']['ext_name'][$ext_id])) {
742 $data['ext_name'] = $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 $data = SQL_FETCHARRAY($result);
758 SQL_FREERESULT($result);
761 // Did we find some extension?
762 if (empty($data['ext_name'])) {
763 // We should fix these all!
764 debug_report_bug(__FUNCTION__ . ': ext_name is empty. ext_id=' . $ext_id);
767 // Return the extension name
768 return $data['ext_name'];
771 // Get extension id from name
772 function getExtensionId ($ext_name) {
774 $data['ext_id'] = '0';
777 if (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) {
779 $data['ext_id'] = $GLOBALS['cache_array']['extension']['ext_id'][$ext_name];
782 incrementStatsEntry('cache_hits');
784 // Load from database
785 $result = SQL_QUERY_ESC("SELECT `id` AS ext_id FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
786 array($ext_name), __FUNCTION__, __LINE__);
788 // Is the entry there?
789 if (SQL_NUMROWS($result) == 1) {
790 // Get the extension's id from database
791 $data = SQL_FETCHARRAY($result);
795 SQL_FREERESULT($result);
798 $GLOBALS['cache_array']['extension']['ext_id'][$ext_name] = $data['ext_id'];
802 return $data['ext_id'];
805 // Determines wether the given extension name is valid
806 function isExtensionNameValid ($ext_name) {
808 if (!isset($GLOBALS['ext_name_valid'][$ext_name])) {
809 // Generate include file name
810 $INC = sprintf("inc/extensions/ext-%s.php", $ext_name);
812 // Is there a file in inc/extensions/ ?
813 $GLOBALS['ext_name_valid'][$ext_name] = isIncludeReadable($INC);
817 return $GLOBALS['ext_name_valid'][$ext_name];
820 // Determines wether the given extension id is valid
821 function isExtensionIdValid ($ext_id) {
822 // Default is nothing valid
825 // Check in cache then in database
826 if (isset($GLOBALS['cache_array']['extension']['ext_name'][$ext_id])) {
831 incrementStatsEntry('cache_hits');
834 $isValid = (countSumTotalData($ext_id, 'extensions', 'id', 'id', true) == 1);
841 // Activate given extension
842 function doActivateExtension ($ext_name) {
843 // Activate the extension
844 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='Y' WHERE `ext_name`='%s' LIMIT 1",
845 array($ext_name), __FUNCTION__, __LINE__);
847 // Extension has been activated?
848 if (SQL_AFFECTEDROWS() == 1) {
849 // Then run all queries
850 doExtensionSqls(getExtensionId($ext_name), 'activate');
854 // Deactivate given extension
855 function doDeactivateExtension($ext_name) {
856 // Activate the extension
857 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='N' WHERE `ext_name`='%s' LIMIT 1",
858 array($ext_name), __FUNCTION__, __LINE__);
860 // Extension has been activated?
861 if (SQL_AFFECTEDROWS() == 1) {
862 // Then run all queries
863 doExtensionSqls(getExtensionId($ext_name), 'deactivate');
866 createExtensionDeactivationTask($ext_name);
869 sendAdminNotification(
870 getMessage('ADMIN_SUBJECT_EXTENSION_DEACTIVATED'),
871 'admin_ext_deactivated',
872 array('ext_name' => $ext_name)
877 // Checks wether the extension is older than given
878 function isExtensionOlder ($ext_name, $ext_ver) {
879 // Get current extension version
880 $currVersion = getExtensionVersion($ext_name);
882 // Remove all dots from both versions
883 $currVersion = str_replace('.', '', $currVersion);
884 $ext_ver = str_replace('.', '', $ext_ver);
886 // Now compare both and return the result
887 return ($currVersion < $ext_ver);
890 // Creates a new task for updated extension
891 function createExtensionUpdateTask ($adminId, $ext_name, $ext_ver, $notes) {
892 // Create subject line
893 $subject = '[UPDATE-' . $ext_name . '-' . $ext_ver . ':] {--ADMIN_UPDATE_EXT_SUBJ--}';
895 // Is the extension there?
896 if (isExtensionInstalled($ext_name)) {
897 // Check if task is not there
898 if (determineTaskIdBySubject($subject) == '0') {
899 // Create extension update-task
900 createNewTask($subject, $notes, 'EXTENSION_UPDATE', 0, $adminId);
903 // Extension not there! :-(
904 debug_report_bug(sprintf("Extension <strong>%s</strong> not found but should be updated?", $ext_name));
908 // Creates a new task for newly installed extension
909 function createNewExtensionTask ($adminId, $subject, $ext) {
910 // Not installed and do we have created a task for the admin?
911 if ((determineTaskIdBySubject($subject) == '0') && (!isExtensionInstalled($ext))) {
912 // Set default message if ext-foo is missing
913 $message = getMaskedMessage('ADMIN_EXT_TEXT_FILE_MISSING', $ext);
916 $tpl = sprintf("%stemplates/%s/html/ext/ext_%s.tpl",
922 // Load text for task if found
923 if (isFileReadable($tpl)) {
924 // Load extension's own text template (HTML!)
925 $message = loadTemplate('ext_' . $ext, true);
927 // Write this in debug.log as well
928 logDebugMessage(__FUNCTION__, __LINE__, $message);
931 // Task not created so it's a brand-new extension which we need to register and create a task for!
932 createNewTask($subject, $message, 'EXTENSION', 0, $adminId, false);
936 // Creates a task for automatically deactivated (deprecated) extension
937 function createExtensionDeactivationTask ($ext) {
938 // Create subject line
939 $subject = sprintf("[%s:] %s", $ext, getMessage('TASK_SUBJ_EXTENSION_DEACTIVATED'));
941 // Not installed and do we have created a task for the admin?
942 if ((determineTaskIdBySubject($subject) == '0') && (getExtensionVersion($ext) != '')) {
943 // Task not created so add it
944 createNewTask($subject, SQL_ESCAPE(loadTemplate('task_ext_deactivated', true, $ext)), 'EXTENSION_DEACTIVATION');
948 // Checks if the module has a menu
949 function ifModuleHasMenu ($mod, $forceDb = false) {
950 // All is false by default
953 // Extension installed and newer than or has version 0.1.2?
954 if (isExtensionInstalledAndNewer('cache', '0.1.2')) {
955 // Cache version is okay, so let's check the cache!
956 if (isset($GLOBALS['cache_array']['modules']['has_menu'][$mod])) {
957 // Check module cache and count hit
958 $ret = ($GLOBALS['cache_array']['modules']['has_menu'][$mod] == 'Y');
959 incrementStatsEntry('cache_hits');
960 } elseif (isset($GLOBALS['cache_array']['extension']['ext_menu'][$mod])) {
961 // Check cache and count hit
962 $ret = ($GLOBALS['cache_array']['extension']['ext_menu'][$mod] == 'Y');
963 incrementStatsEntry('cache_hits');
965 // Admin/guest/member/sponsor modules have always a menu!
966 $ret = in_array($mod, array('admin', 'index', 'login', 'sponsor'));
968 } elseif ((isExtensionInstalled('sql_patches')) && (getExtensionVersion('sql_patches') >= '0.3.6') && ((!isExtensionActive('cache')) || ($forceDb === true))) {
969 // Check database for entry
970 $result = SQL_QUERY_ESC("SELECT `has_menu` FROM `{?_MYSQL_PREFIX?}_mod_reg` WHERE `module`='%s' LIMIT 1",
971 array($mod), __FUNCTION__, __LINE__);
974 if (SQL_NUMROWS($result) == 1) {
975 // Load "has_menu" column
976 $data = SQL_FETCHARRAY($result);
979 $GLOBALS['cache_array']['extension']['ext_menu'][$mod] = $data['has_menu'];
981 // Does it have a menu?
982 $ret = ($data['has_menu'] == 'Y');
986 SQL_FREERESULT($result);
987 } elseif (!isExtensionInstalled('sql_patches')) {
988 // No sql_patches installed, so maybe in admin/guest/member/sponsor area or no admin registered?
989 $ret = in_array($mod, array('admin', 'index', 'login', 'sponsor')); // Then there is a menu!
991 // Unsupported state!
992 logDebugMessage(__FUNCTION__, __LINE__, 'This should never be reached.');
999 // Determines the task id for given extension
1000 function determineExtensionTaskId ($ext_name) {
1001 // Default is not found
1002 $data['task_id'] = '0';
1004 // Search for extension task's id
1005 $result = SQL_QUERY_ESC("SELECT `id` AS task_id FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `task_type`='EXTENSION' AND `subject`='[%s:]' LIMIT 1",
1006 array($ext_name), __FUNCTION__, __LINE__);
1009 if (SQL_NUMROWS($result) == 1) {
1010 // Task found so load task's id and register extension...
1011 $data = SQL_FETCHARRAY($result);
1015 SQL_FREERESULT($result);
1018 return $data['task_id'];
1021 // Determines the task id for given subject
1022 function determineTaskIdBySubject ($subject) {
1023 // Default is not found
1024 $data['task_id'] = '0';
1026 // Search for task id
1027 $result = SQL_QUERY_ESC("SELECT `id` AS task_id FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `subject` LIKE '%s%%' LIMIT 1",
1028 array($subject), __FUNCTION__, __LINE__);
1031 if (SQL_NUMROWS($result) == 1) {
1032 // Task found so load task's id and register extension...
1033 $data = SQL_FETCHARRAY($result);
1037 SQL_FREERESULT($result);
1040 return $data['task_id'];
1043 // Add updates notes for given version
1044 function addExtensionNotes ($ver) {
1045 // Init notes/content
1046 $out = ''; $content = array();
1048 // Is do we have verbose output enabled?
1049 if ((!isExtensionActive('sql_patches')) || (getConfig('verbose_sql') == 'Y')) {
1050 // Update notes found?
1051 if (getExtensionUpdateNotes($ver) != '') {
1052 // Update notes found
1055 'notes' => getExtensionUpdateNotes($ver)
1059 setExtensionUpdateNotes('', $ver);
1060 } elseif (($ver == '0.0') || ($ver == '0.0.0')) {
1064 'notes' => getMessage('INITIAL_RELEASE')
1067 // No update notes found!
1070 'notes' => getMessage('NO_UPDATE_NOTES')
1075 $out = loadTemplate('admin_ext_notes', true, $content);
1079 appendExtensionNotes($out);
1082 // Getter for CSS files array
1083 function getExtensionCssFiles () {
1084 // By default no additional CSS files are found
1085 $cssFiles = array();
1087 // Is the array there?
1088 if (isset($GLOBALS['css_files'])) {
1090 $cssFiles = $GLOBALS['css_files'];
1097 // Init CSS files array
1098 function initExtensionCssFiles () {
1100 $GLOBALS['css_files'] = array();
1104 function addExtensionCssFile ($file) {
1105 // Is the array there?
1106 if (!isset($GLOBALS['css_files'])) {
1107 // Then auto-init them
1108 initExtensionCssFiles();
1112 $GLOBALS['css_files'][] = $file;
1115 // Setter for EXT_ALWAYS_ACTIVE flag
1116 function setExtensionAlwaysActive ($active) {
1117 $GLOBALS['ext_always_active'][getCurrentExtensionName()] = (string) $active;
1120 // Getter for EXT_ALWAYS_ACTIVE flag
1121 function getExtensionAlwaysActive () {
1122 return $GLOBALS['ext_always_active'][getCurrentExtensionName()];
1125 // Setter for EXT_VERSION flag
1126 function setThisExtensionVersion ($version) {
1127 $GLOBALS['ext_version'][getCurrentExtensionName()] = (string) $version;
1130 // Getter for EXT_VERSION flag
1131 function getThisExtensionVersion () {
1132 return $GLOBALS['ext_version'][getCurrentExtensionName()];
1135 // Setter for EXT_DEPRECATED flag
1136 function setExtensionDeprecated ($deprecated) {
1137 $GLOBALS['ext_deprecated'][getCurrentExtensionName()] = (string) $deprecated;
1140 // Getter for EXT_DEPRECATED flag
1141 function isExtensionDeprecated () {
1142 return ($GLOBALS['ext_deprecated'][getCurrentExtensionName()] == 'Y');
1145 // Setter for EXT_UPDATE_DEPENDS flag
1146 function addExtensionUpdateDependency ($updateDepends) {
1147 // Is the update depency empty? (NEED TO BE FIXED!)
1148 if (empty($updateDepends)) {
1149 // Please report this bug!
1150 debug_report_bug('updateDepends is left empty!');
1153 // Is it not yet added?
1154 if (!in_array($updateDepends, $GLOBALS['ext_running_updates'])) {
1155 //* DEBUG */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName().'/'.$updateDepends);
1156 // Add it to the list of extension update depencies map
1157 $GLOBALS['ext_update_depends'][getCurrentExtensionName()][] = (string) $updateDepends;
1159 // Remember it in the list of running updates
1160 $GLOBALS['ext_running_updates'][] = $updateDepends;
1164 // Checks wether the given extension registration is in progress
1165 function isExtensionRegisterRunning ($ext_name) {
1166 return ((isset($GLOBALS['ext_register_running'])) && (in_array($ext_name, $GLOBALS['ext_register_running'])));
1169 // Init EXT_UPDATE_DEPENDS flag
1170 function initExtensionUpdateDependencies () {
1171 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1173 // Init update depency map automatically if not found
1174 if (!isExtensionUpdateDependenciesInitialized()) {
1175 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()." - INIT!");
1176 $GLOBALS['ext_update_depends'][getCurrentExtensionName()] = array();
1179 // Init running updates array
1180 initExtensionRuningUpdates();
1183 // Adds an extension as "registration in progress"
1184 function addExtensionRunningRegistration ($ext_name) {
1186 if (!isExtensionRegisterRunning($ext_name)) {
1188 $GLOBALS['ext_register_running'][] = $ext_name;
1192 // Checks wether EXT_UPDATE_DEPENDS is initialized
1193 function isExtensionUpdateDependenciesInitialized () {
1194 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1195 return (isset($GLOBALS['ext_update_depends'][getCurrentExtensionName()]));
1198 // Initializes the list of running updates
1199 function initExtensionRuningUpdates () {
1200 // Auto-init ext_running_updates
1201 if (!isset($GLOBALS['ext_running_updates'])) {
1202 $GLOBALS['ext_running_updates'] = array();
1203 $GLOBALS['ext_register_running'] = array();
1207 // Getter for EXT_UPDATE_DEPENDS flag
1208 function getExtensionUpdateDependencies () {
1209 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1210 return $GLOBALS['ext_update_depends'][getCurrentExtensionName()];
1213 // Getter for next iterator depency
1214 function getExtensionUpdateDependenciesIterator () {
1215 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1216 return ($GLOBALS['ext_update_depends'][getCurrentExtensionName()][getExtensionUpdateIterator()]);
1219 // Counter for extension update depencies
1220 function countExtensionUpdateDependencies () {
1221 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1222 return count($GLOBALS['ext_update_depends'][getCurrentExtensionName()]);
1225 // Removes given extension from update denpency list
1226 function removeExtensionUpdateDependency ($ext_name) {
1228 $key = array_search($ext_name, getExtensionUpdateDependencies());
1231 if ($key !== false) {
1233 unset($GLOBALS['ext_update_depends'][getCurrentExtensionName()][$key]);
1235 // And sort the array
1236 ksort($GLOBALS['ext_update_depends'][getCurrentExtensionName()]);
1240 // Init iterator for update depencies
1241 function initExtensionUpdateIterator () {
1242 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1243 $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()] = '0';
1246 // Getter for depency iterator
1247 function getExtensionUpdateIterator () {
1248 // Auto-init iterator
1249 if (!isset($GLOBALS['ext_depend_iterator'][getCurrentExtensionName()])) initExtensionUpdateIterator();
1252 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName().'/'.$GLOBALS['ext_depend_iterator'][getCurrentExtensionName()]);
1253 return $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()];
1256 // Increments the update iterator
1257 function incrementExtensionUpdateIterator () {
1258 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1259 $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()]++;
1262 // Setter for EXT_REPORTS_FAILURE flag
1263 function setExtensionReportsFailure ($reportsFailure) {
1264 $GLOBALS['ext_reports_failure'] = (bool) $reportsFailure;
1267 // Getter for EXT_REPORTS_FAILURE flag
1268 function getExtensionReportsFailure () {
1269 return $GLOBALS['ext_reports_failure'];
1272 // Setter for EXT_VER_HISTORY flag
1273 function setExtensionVersionHistory ($verHistory) {
1274 $GLOBALS['ext_ver_history'][getCurrentExtensionName()] = (array) $verHistory;
1277 // Getter for EXT_VER_HISTORY array
1278 function getExtensionVersionHistory () {
1279 return $GLOBALS['ext_ver_history'][getCurrentExtensionName()];
1282 // Setter for EXT_UPDATE_NOTES
1283 function setExtensionUpdateNotes ($updateNotes, $ver='') {
1284 //* DEBUG: */ print __FUNCTION__.':'.getCurrentExtensionName().'/'.getCurrentExtensionVersion().'/'.$ver.'='.$updateNotes.'<br />';
1286 $GLOBALS['ext_update_notes'][getCurrentExtensionName()][getCurrentExtensionVersion()] = (string) $updateNotes;
1288 $GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ver] = (string) $updateNotes;
1292 // Getter for EXT_UPDATE_NOTES
1293 function getExtensionUpdateNotes ($ver) {
1294 return $GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ver];
1297 // Init extension notice
1298 function initExtensionNotes () {
1299 $GLOBALS['ext_notes'][getCurrentExtensionName()] = '';
1302 // Append extension notice
1303 function appendExtensionNotes ($notes) {
1304 $GLOBALS['ext_notes'][getCurrentExtensionName()] .= (string) trim($notes);
1307 // Getter for extension notes
1308 function getExtensionNotes () {
1309 return $GLOBALS['ext_notes'][getCurrentExtensionName()];
1312 // Setter for current extension name
1313 function setCurrentExtensionName ($ext_name) {
1314 $GLOBALS['curr_ext_name'] = (string) trim($ext_name);
1317 // Getter for current extension name
1318 function getCurrentExtensionName () {
1319 if (isset($GLOBALS['curr_ext_name'])) {
1320 return $GLOBALS['curr_ext_name'];
1324 debug_report_bug(__FUNCTION__.": curr_ext_name not initialized. Please execute initExtensionSqls() before calling this function.");
1327 // Init SQLs array for current extension
1328 function initExtensionSqls () {
1329 // Auto-init the array now...
1330 if (!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()])) {
1331 $GLOBALS['ext_sqls'][getCurrentExtensionName()] = array();
1335 // Adds SQLs to the SQLs array but "assigns" it with current extension name
1336 function addExtensionSql ($sql) {
1338 $GLOBALS['ext_sqls'][getCurrentExtensionName()][getCurrentExtensionVersion()][] = $sql;
1341 // Getter for SQLs array for current extension
1342 function getExtensionSqls () {
1343 // Output debug backtrace if not found (SHOULD NOT HAPPEN!)
1344 if (!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()])) {
1345 // Not found, should not happen
1346 debug_report_bug(sprintf("ext_sqls is empty, current extension: %s",
1347 getCurrentExtensionName()
1352 return $GLOBALS['ext_sqls'][getCurrentExtensionName()];
1355 // Removes SQLs for current extension
1356 function unsetExtensionSqls () {
1357 unset($GLOBALS['ext_sqls'][getCurrentExtensionName()]);
1360 // Auto-initializes the removal list
1361 function initExtensionRemovalList () {
1362 // Is the remove list there?
1363 if (!isset($GLOBALS['ext_update_remove'])) {
1365 $GLOBALS['ext_update_remove'] = array();
1369 // Checks wether the current extension is on the removal list
1370 function isExtensionOnRemovalList () {
1371 // Init removal list
1372 initExtensionRemovalList();
1375 return (in_array(getCurrentExtensionName(), $GLOBALS['ext_update_remove']));
1378 // Adds the current extension to the removal list
1379 function addCurrentExtensionToRemovalList () {
1381 $GLOBALS['ext_update_remove'][] = getCurrentExtensionName();
1384 // Getter for removal list
1385 function getExtensionRemovalList () {
1386 // Return the removal list
1387 return $GLOBALS['ext_update_remove'];
1390 // Redirects if the provided extension is not installed
1391 function redirectOnUninstalledExtension ($ext_name) {
1392 // So is the extension there?
1393 if ((!isExtensionInstalled($ext_name)) || (!isExtensionActive($ext_name))) {
1394 // Redirect to index
1395 redirectToUrl('modules.php?module=index&code=' . getCode('EXTENSION_PROBLEM') . '&ext=' . $ext_name);
1399 // Filter for initialization of all extensions by loading them in 'init' mode
1400 function FILTER_INIT_EXTENSIONS () {
1401 // Do we have some entries?
1402 //* DEBUG */ print __FUNCTION__.': ENTRY!<br />';
1403 if (isset($GLOBALS['cache_array']['extension']['ext_name'])) {
1404 // Load all found extensions if found
1405 //* DEBUG */ print __FUNCTION__.': CACHE - START!<br />';
1406 foreach ($GLOBALS['cache_array']['extension']['ext_name'] as $key => $ext_name) {
1408 //* DEBUG */ print __FUNCTION__.': '.$ext_name.' - START<br />';
1409 loadExtension($ext_name, 'init');
1410 //* DEBUG */ print __FUNCTION__.': '.$ext_name.' - END<br />';
1412 //* DEBUG */ print __FUNCTION__.': CACHE - END!<br />';
1414 //* DEBUG */ print __FUNCTION__.': EXIT!<br />';
1417 // Setter for extension mode
1418 function setExtensionMode ($ext_mode) {
1419 $GLOBALS['ext_mode'] = (string) $ext_mode;
1422 // Getter for extension mode
1423 function getExtensionMode () {
1424 return $GLOBALS['ext_mode'];
1427 // Setter for dry-run
1428 function enableExtensionDryRun ($dry_run = true) {
1429 //* DEBUG: */ print __FUNCTION__.': '.getCurrentExtensionName().'='.intval($dry_run).'<br />';
1430 $GLOBALS['ext_dry_run'] = (bool) $dry_run;
1433 // Getter for dry-run
1434 function getExtensionDryRun () {
1435 return $GLOBALS['ext_dry_run'];
1438 // Setter for current extension version
1439 function setCurrentExtensionVersion ($ext_ver) {
1440 if (empty($ext_ver)) {
1442 $GLOBALS['ext_current_version'] = '0.0';
1445 $GLOBALS['ext_current_version'] = (string) $ext_ver;
1449 // Getter for current extension version
1450 function getCurrentExtensionVersion () {
1451 return $GLOBALS['ext_current_version'];
1454 // Remove the extension from cache array
1455 function removeExtensionFromArray () {
1456 // "Cache" this name
1457 $ext_name = getCurrentExtensionName();
1459 // Now loop through the whole cache
1460 foreach ($GLOBALS['cache_array']['extension'] as $cacheName => $cacheArray) {
1461 // Is it an element?
1462 if (isset($cacheArray[$ext_name])) {
1464 unset($cacheArray[$ext_name]);
1465 $GLOBALS['cache_array']['extension'][$cacheName] = $cacheArray;
1468 $key = array_search($ext_name, $cacheArray);
1471 if ($key !== false) {
1472 // Found, so remove it
1473 unset($cacheArray[$key]);
1474 $GLOBALS['cache_array']['extension'][$cacheName] = $cacheArray;
1480 // "Getter" for 'extension has a CSS file' (with same name, of course)
1481 function getExtensionHasCss () {
1482 // Default is no CSS
1485 // Construct FQFN for check
1486 $FQFN = sprintf("%stheme/%s/css/%s.css",
1489 getCurrentExtensionName()
1493 if (isFileReadable($FQFN)) {
1494 // Readable, so it is there...
1502 // Checks wether the given extension has a language file
1503 function ifExtensionHasLanguageFile ($ext_name) {
1504 // Default is no language file
1505 $hasLanguage = false;
1507 // Do we have cache?
1508 if (isset($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name])) {
1510 $hasLanguage = ($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] == 'Y');
1513 incrementStatsEntry('cache_hits');
1515 // Not readable is default
1518 // Is the language file readable for this extension?
1519 if (isLanguageIncludeReadable($ext_name)) {
1525 $GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] = 'Y';
1529 return ($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] == 'Y');
1532 // Load an extension's include file
1533 function loadExtensionInclude () {
1535 if (!isExtensionIncludeReadable()) {
1537 debug_report_bug('Extension ' . getCurrentExtensionName() . ' should be loaded, but is not readable.');
1540 // Generate INC name
1541 $INC = sprintf("inc/extensions/ext-%s.php", getCurrentExtensionName());
1547 // Checks wether an extension is readable
1548 function isExtensionIncludeReadable ($ext_name = '') {
1549 // If empty, use current
1550 if (empty($ext_name)) $ext_name = getCurrentExtensionName();
1553 if (!isset($GLOBALS['ext_inc_readable'][$ext_name])) {
1554 // Generate INC name
1555 $INC = sprintf("inc/extensions/ext-%s.php", getCurrentExtensionName());
1558 $GLOBALS['ext_inc_readable'][$ext_name] = isIncludeReadable($INC);
1562 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',realable='.intval($GLOBALS['ext_inc_readable'][$ext_name]));
1563 return $GLOBALS['ext_inc_readable'][$ext_name];
1566 // Checks if an extension's function file is readable
1567 function isExtensionFunctionFileReadable ($ext_name) {
1568 if (isset($GLOBALS['cache_array']['extension']['ext_func'][$ext_name])) {
1569 // Just count cache hits
1570 incrementStatsEntry('cache_hits');
1572 // Construct FQFN for functions file
1573 $funcsInclude = sprintf("inc/libs/%s_functions.php", $ext_name);
1575 // Is this include there?
1576 if ((isFileReadable($funcsInclude)) && (!isset($GLOBALS['ext_loaded']['funcs'][$ext_name])) && (getExtensionMode() == 'test')) {
1578 $GLOBALS['cache_array']['extension']['ext_func'][$ext_name] = 'Y';
1581 $GLOBALS['cache_array']['extension']['ext_func'][$ext_name] = 'N';
1586 return ($GLOBALS['cache_array']['extension']['ext_func'][$ext_name] == 'Y');
1589 // Adds an admin menu to the SQL queue of the menu entry is not found
1590 function addAdminMenuSql ($action, $what, $title, $descr, $sort) {
1591 // Now check if this menu is there
1592 if (!isMenuActionValid('admin', $action, $what)) {
1594 if (is_null($what)) {
1596 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES('%s',NULL,'%s','%s',%s)",
1604 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES('%s','%s','%s','%s',%s)",
1613 // Add it to the queue
1614 addExtensionSql($sql);
1615 } elseif (isDebugModeEnabled()) {
1616 // Double menus should be located and fixed!
1617 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double admin menu action=%s, what=%s detected.", $action, $what));
1621 // Adds a guest menu to the SQL queue if the menu entry is not found
1622 function addGuestMenuSql ($action, $what, $title, $visible, $locked, $sort) {
1623 // Now check if this menu is there
1624 if (!isMenuActionValid('guest', $action, $what)) {
1626 if (is_null($what)) {
1628 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s',NULL,'%s','%s','%s',%s)",
1637 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s','%s','%s','%s','%s',%s)",
1647 // Add it to the queue
1648 addExtensionSql($sql);
1649 } elseif (isDebugModeEnabled()) {
1650 // Double menus should be located and fixed!
1651 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double guest menu action=%s, what=%s detected.", $action, $what));
1655 // Adds a member menu to the SQL queue if the menu entry is not found
1656 function addMemberMenuSql ($action, $what, $title, $visible, $locked, $sort) {
1657 // Now check if this menu is there
1658 if (!isMenuActionValid('member', $action, $what)) {
1660 if (is_null($what)) {
1662 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s',NULL,'%s','%s','%s',%s)",
1671 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s','%s','%s','%s','%s',%s)",
1681 // Add it to the queue
1682 addExtensionSql($sql);
1683 } elseif (isDebugModeEnabled()) {
1684 // Double menus should be located and fixed!
1685 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double member menu action=%s, what=%s detected.", $action, $what));
1689 // Adds a sponsor menu to the SQL queue if the menu entry is not found
1690 function addSponsorMenuSql ($action, $what, $title, $active, $sort) {
1691 // Now check if this menu is there, if no ext-sponsor is installed all is not yet added
1692 if ((!isExtensionInstalled('sponsor')) || (!isMenuActionValid('sponsor', $action, $what))) {
1694 if (is_null($what)) {
1696 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_menu` (`action`,`what`,`title`,`active`,`sort`) VALUES('%s',NULL,'%s','%s',%s)",
1704 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_menu` (`action`,`what`,`title`,`active`,`sort`) VALUES('%s','%s','%s','%s',%s)",
1713 // Add it to the queue
1714 addExtensionSql($sql);
1715 } elseif (isDebugModeEnabled()) {
1716 // Double menus should be located and fixed!
1717 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double sponsor menu action=%s, what=%s detected.", $action, $what));
1721 // Enables/disables productive mode for current extension (used only while
1723 function enableExtensionProductive ($isProductive = true) {
1724 $GLOBALS['ext_productive'][getCurrentExtensionName()] = (bool) $isProductive;
1727 // Checks wether the extension is in productive phase. If not set, development
1728 // phase (=false) is assumed.
1729 function isExtensionProductive () {
1730 return ((isset($GLOBALS['ext_productive'][getCurrentExtensionName()])) && ($GLOBALS['ext_productive'][getCurrentExtensionName()] === true));