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 // In normal mode return a true on success
330 } elseif (getExtensionDryRun() === true) {
331 // In "dry-run" mode return array with all SQL commands
332 $ret = getExtensionSqls();
334 // Remove all SQL commands
337 // Extension has been removed for updates, so all is fine!
341 // No, an error occurs while registering extension :-(
342 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "".getCurrentExtensionName());
345 } elseif (($task_id > 0) && (getCurrentExtensionName() != '')) {
346 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()."");
347 // Remove task from system when id and extension's name is valid
348 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s AND `status`='NEW' LIMIT 1",
349 array(bigintval($task_id)), __FUNCTION__, __LINE__);
352 // Is this the sql_patches?
353 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ':'.getCurrentExtensionName()."/".getExtensionMode()."");
354 if ((getCurrentExtensionName() == 'sql_patches') && ((getExtensionMode() == 'register') || (getExtensionMode() == 'remove')) && (!getExtensionDryRun()) && ($test)) {
355 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": LOAD!");
356 if ($logout === true) {
357 // Then redirect to logout
358 redirectToUrl('modules.php?module=admin&logout=1&' . getExtensionMode() . '=sql_patches');
360 // Add temporary filter
361 registerFilter('shutdown', 'REDIRECT_TO_LOGOUT_SQL_PATCHES', true, true);
362 $GLOBALS['ext_load_mode'] = getExtensionMode();
366 // Return status code
367 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()." - LEFT!");
368 //* DEBUG: */ print getCurrentExtensionName().':<pre>'.print_r($ret, true).'</pre>';
372 // Run SQL queries for given extension id
373 // @TODO Change from ext_id to ext_name (not just even the variable! ;-) )
374 function doExtensionSqls ($ext_id, $load_mode) {
375 // This shall never do a non-admin user!
376 if (!isAdmin()) return false;
378 // Get extension's name
379 $ext_name = getExtensionName($ext_id);
381 // Set current SQL name
382 setCurrentExtensionName($ext_name);
384 // Init EXT_UPDATE_DEPENDS
385 initExtensionUpdateDependencies();
390 // By default no SQL has been executed
393 // Load extension in detected mode
394 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ":ext_name[{$ext_id}]=".getCurrentExtensionName()."");
395 loadExtension(getCurrentExtensionName(), $load_mode, '', false);
399 setSqlsArray(getExtensionSqls());
401 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ":SQLs::count=".countSqls()."");
403 // Run SQL commands...
404 runFilterChain('run_sqls');
407 // Run any filters depending on the action here
408 runFilterChain('extension_' . $load_mode);
410 // Remove cache file(s) if extension is active
411 if (((isExtensionActive('cache')) && ((SQL_AFFECTEDROWS() == 1)) || ($sqlRan === true) || ($load_mode == 'activate') || ($load_mode == 'deactivate'))) {
413 runFilterChain('post_extension_run_sql', getCurrentExtensionName());
416 // Is this the sql_patches?
417 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": id=".$ext_id.",currName=".getCurrentExtensionName().",loadMode=".$load_mode);
418 if ((getCurrentExtensionName() == 'sql_patches') && (($load_mode == 'register') || ($load_mode == 'remove'))) {
419 // Then redirect to logout
420 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": LOAD!");
421 redirectToUrl('modules.php?module=admin&logout=1&' . $load_mode . '=sql_patches');
425 // Check wether the given extension is installed
426 function isExtensionInstalled ($ext_name) {
427 // We don't like empty extension names here
428 if (empty($ext_name)) {
429 // Please fix them all
430 debug_report_bug(__FUNCTION__.': ext_name is empty.');
433 // By default non is installed
434 $isInstalled = false;
436 // Check if there is a cache entry
437 if (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) {
442 incrementStatsEntry('cache_hits');
443 } elseif ((isInstallationPhase())) {
444 // Extensions are all inactive/not installed during installation
447 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
448 array($ext_name), __FILE__, __LINE__);
450 // Do we have a record?
451 $isInstalled = (SQL_NUMROWS($result) == 1);
453 // Is it installed, then cache the entry
454 if ($isInstalled === true) {
456 getExtensionId($ext_name, true);
460 SQL_FREERESULT($result);
467 // Check if given extension is active
468 function isExtensionActive ($ext_name) {
469 // Extensions are all inactive during installation
470 if ((isInstallationPhase()) || (empty($ext_name))) return false;
472 // Not active is the default
476 if (isset($GLOBALS['cache_array']['extension']['ext_active'][$ext_name])) {
478 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "CACHE! ext_name={$ext_name}");
479 $active = $GLOBALS['cache_array']['extension']['ext_active'][$ext_name];
482 incrementStatsEntry('cache_hits');
483 } elseif (isset($GLOBALS['ext_loaded'][$ext_name])) {
484 // @TODO Extension is loaded, what next?
485 app_die(__FUNCTION__, __LINE__, "LOADED:$ext_name");
486 } elseif (($ext_name == 'cache') || (!isExtensionInstalled('cache'))) {
487 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "DB! ext_name={$ext_name}");
488 // Load from database
489 $result = SQL_QUERY_ESC("SELECT `ext_active` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
490 array($ext_name), __FUNCTION__, __LINE__);
493 if (SQL_NUMROWS($result) == 1) {
495 list($active) = SQL_FETCHROW($result);
499 SQL_FREERESULT($result);
502 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name=".$ext_name."[DB]: {$active}");
503 $GLOBALS['cache_array']['extension']['ext_active'][$ext_name] = $active;
505 // Extension not active!
506 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name=".$ext_name.": Not active!");
507 $GLOBALS['cache_array']['extension']['ext_active'][$ext_name] = 'N';
511 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name={$ext_name},active={$active}");
513 // Is this extension activated? (For admins we always have active extensions...)
514 return ($active == 'Y');
517 // Get version from extensions
518 function getExtensionVersion ($ext_name) {
519 // By default no extension is found
520 $ext_ver = 'invalid';
522 // Empty extension name should be fixed!
523 if (empty($ext_name)) {
524 // Please report this bug!
525 debug_report_bug(__FUNCTION__ . ': ext_name is empty which is not allowed here.');
528 // Extensions are all inactive during installation
529 if (isInstallationPhase()) return '';
530 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": ext_name={$ext_name}");
532 // Is the cache written?
533 if (isset($GLOBALS['cache_array']['extension']['ext_version'][$ext_name])) {
534 // Load data from cache
535 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": CACHE!");
536 $ext_ver = $GLOBALS['cache_array']['extension']['ext_version'][$ext_name];
539 incrementStatsEntry('cache_hits');
540 } elseif ((!isCacheInstanceValid()) || (isset($GLOBALS['cache_array']['extension'])) || (getOutputMode() != 0)) {
541 // Load from database
542 $result = SQL_QUERY_ESC("SELECT `ext_version` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
543 array($ext_name), __FUNCTION__, __LINE__);
544 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": DB - ".SQL_NUMROWS($result)."");
546 // Is the extension there?
547 if (SQL_NUMROWS($result) == 1) {
549 list($ext_ver) = SQL_FETCHROW($result);
550 } elseif (isDebugModeEnabled()) {
552 logDebugMessage(__FUNCTION__, __LINE__, sprintf(": Cannot find extension %s in database!", $ext_name));
556 SQL_FREERESULT($result);
559 $GLOBALS['cache_array']['extension']['ext_version'][$ext_name] = $ext_ver;
562 // Extension version should not be invalid
563 if ($ext_ver == 'invalid') {
564 // Please report this trouble
565 debug_report_bug(sprintf("Extension <strong>%s</strong> has empty version!", $ext_name));
569 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": ret={$ext_ver}");
573 // Updates a given extension with current extension version to latest version
574 function updateExtension ($ext_name, $ext_ver, $dry_run = false) {
575 // Only admins are allowed to update extensions
576 if ((!isAdmin()) || (empty($ext_name))) return false;
578 // Set current SQL name
579 setCurrentExtensionName($ext_name);
583 initExtensionNotes();
584 initIncludePool('extension');
586 // Load extension in test mode
587 loadExtension($ext_name, 'test', $ext_ver, getExtensionDryRun());
589 // Save version history
590 $history = getExtensionVersionHistory();
592 // Remove old SQLs array to prevent possible bugs
595 // Check if version is updated
596 //* DEBUG: */ print getCurrentExtensionName().'/'.$ext_name.':'.getThisExtensionVersion().'/'.$ext_ver.'/'.intval(is_array($history)).'<br />';
597 if (((getThisExtensionVersion() != $ext_ver) || (getExtensionDryRun())) && (is_array($history))) {
598 // Search for starting point
599 $start = array_search($ext_ver, $history);
601 // And load SQL queries in order of version history
602 for ($idx = ($start + 1); $idx < count($history); $idx++) {
603 // Set extension version
604 $GLOBALS['update_ver'][getCurrentExtensionName()] = $history[$idx];
607 loadExtension(getCurrentExtensionName(), 'update', $GLOBALS['update_ver'][getCurrentExtensionName()], getExtensionDryRun());
610 $depencies = getExtensionUpdateDependencies();
613 if (count($depencies) > 0) {
614 // Apply all extension depencies
615 foreach ($depencies as $ext_depend) {
616 // Did we already update/register this?
617 if (!isset($GLOBALS['ext_updated'][$ext_depend])) {
619 setCurrentExtensionName($ext_depend);
621 // Mark it as already updated before we update it
622 $GLOBALS['ext_updated'][$ext_depend] = true;
624 // Is the extension there?
625 if (isExtensionInstalled($ext_depend)) {
626 // Update another extension first!
627 $test = updateExtension($ext_depend, getExtensionVersion($ext_depend), getExtensionDryRun());
629 // Register new extension
630 $test = registerExtension($ext_depend, 0, getExtensionDryRun(), false);
636 setCurrentExtensionName($ext_name);
640 addExtensionNotes($history[$idx]);
643 // In real-mode execute any existing includes
644 if (getExtensionDryRun() === false) {
645 $GLOBALS['ext_inc_pool'][getCurrentExtensionName()] = getIncludePool('extension');
646 runFilterChain('load_includes', 'extension');
647 setIncludePool('extension', $GLOBALS['ext_inc_pool'][getCurrentExtensionName()]);
648 unset($GLOBALS['ext_inc_pool'][getCurrentExtensionName()]);
653 setSqlsArray(getExtensionSqls());
656 runFilterChain('run_sqls', array('dry_run' => getExtensionDryRun()));
658 if (getExtensionDryRun() === false) {
659 // Run filters on success extension update
660 runFilterChain('extension_update', getCurrentExtensionName());
665 // Output verbose SQL table for extension
666 function addExtensionVerboseSqlTable ($title = '', $dashed = '', $switch = false, $width = '100%') {
669 // Then fix it to default
670 $title = getMessage('ADMIN_SQLS_EXECUTED_ON_REMOVAL');
676 // Do we have queries?
677 if ((getExtensionVersion('sql_patches') >= '0.0.7') && (getConfig('verbose_sql') == 'Y')) {
682 foreach (getExtensionSqls() as $sqls) {
683 // New array format is recursive
684 foreach ($sqls as $idx => $sql) {
688 // Output command if set
690 // Prepare output for template
698 $OUT .= loadTemplate('admin_ext_sql_row', true, $content);
706 // Prepare content for template
714 // Load main template
715 $OUT = loadTemplate('admin_ext_sql_table', true, $content);
716 } elseif ((getExtensionVersion('sql_patches') >= '0.0.7') && (getConfig('verbose_sql') == 'Y')) {
717 // No addional SQL commands to run
718 $OUT = loadTemplate('admin_settings_saved', true, getMessage('ADMIN_NO_ADDITIONAL_SQLS'));
725 // Get extension name from id
726 function getExtensionName ($ext_id) {
727 // Init extension name
731 if (isset($GLOBALS['cache_array']['extension']['ext_name'][$ext_id])) {
733 $ret = $GLOBALS['cache_array']['extension']['ext_name'][$ext_id];
736 incrementStatsEntry('cache_hits');
737 } elseif (!isExtensionActive('cache')) {
738 // Load from database
739 $result = SQL_QUERY_ESC("SELECT `ext_name` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `id`=%s LIMIT 1",
740 array(bigintval($ext_id)), __FUNCTION__, __LINE__);
742 // Is the entry there?
743 if (SQL_NUMROWS($result) == 1) {
744 // Get the extension's name from database
745 list($ret) = SQL_FETCHROW($result);
749 SQL_FREERESULT($result);
752 // Did we find some extension?
754 // We should fix these all!
755 debug_report_bug(__FUNCTION__ . ': ext_name is empty. ext_id=' . $ext_id);
758 // Return the extension name
762 // Get extension id from name
763 function getExtensionId ($ext_name, $forceDb = false) {
767 if (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) {
769 $ret = $GLOBALS['cache_array']['extension']['ext_id'][$ext_name];
772 incrementStatsEntry('cache_hits');
773 } elseif (($forceDb === true) || (!isExtensionActive('cache'))) {
774 // Load from database
775 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
776 array($ext_name), __FUNCTION__, __LINE__);
778 // Is the entry there?
779 if (SQL_NUMROWS($result) == 1) {
780 // Get the extension's id from database
781 list($ret) = SQL_FETCHROW($result);
784 $GLOBALS['cache_array']['extension']['ext_id'][$ext_name] = $ret;
788 SQL_FREERESULT($result);
792 // We should fix these all!
793 debug_report_bug(__FUNCTION__ . ': Invalid extension name found. ext_name=' . $ext_name);
800 // Determines wether the given extension name is valid
801 function isExtensionNameValid ($ext_name) {
803 if (!isset($GLOBALS['ext_name_valid'][$ext_name])) {
804 // Generate include file name
805 $INC = sprintf("inc/extensions/ext-%s.php", $ext_name);
807 // Is there a file in inc/extensions/ ?
808 $GLOBALS['ext_name_valid'][$ext_name] = isIncludeReadable($INC);
812 return $GLOBALS['ext_name_valid'][$ext_name];
815 // Determines wether the given extension id is valid
816 function isExtensionIdValid ($ext_id) {
817 // Default is nothing valid
820 // Check in cache then in database
821 if (isset($GLOBALS['cache_array']['extension']['ext_name'][$ext_id])) {
826 incrementStatsEntry('cache_hits');
829 $isValid = (countSumTotalData($ext_id, 'extensions', 'id', 'id', true) == 1);
836 // Activate given extension
837 function doActivateExtension ($ext_name) {
838 // Activate the extension
839 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='Y' WHERE `ext_name`='%s' LIMIT 1",
840 array($ext_name), __FUNCTION__, __LINE__);
842 // Extension has been activated?
843 if (SQL_AFFECTEDROWS() == 1) {
844 // Then run all queries
845 doExtensionSqls(getExtensionId($ext_name), 'activate');
849 // Deactivate given extension
850 function doDeactivateExtension($ext_name) {
851 // Activate the extension
852 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='N' WHERE `ext_name`='%s' LIMIT 1",
853 array($ext_name), __FUNCTION__, __LINE__);
855 // Extension has been activated?
856 if (SQL_AFFECTEDROWS() == 1) {
857 // Then run all queries
858 doExtensionSqls(getExtensionId($ext_name), 'deactivate');
861 createExtensionDeactivationTask($ext_name);
864 sendAdminNotification(
865 getMessage('ADMIN_SUBJECT_EXTENSION_DEACTIVATED'),
866 'admin_ext_deactivated',
867 array('ext_name' => $ext_name)
872 // Checks wether the extension is older than given
873 function isExtensionOlder ($ext_name, $ext_ver) {
874 // Get current extension version
875 $currVersion = getExtensionVersion($ext_name);
877 // Remove all dots from both versions
878 $currVersion = str_replace('.', '', $currVersion);
879 $ext_ver = str_replace('.', '', $ext_ver);
881 // Now compare both and return the result
882 return ($currVersion < $ext_ver);
885 // Creates a new task for updated extension
886 function createExtensionUpdateTask ($adminId, $ext_name, $ext_ver, $notes) {
887 // Create subject line
888 $subject = '[UPDATE-' . $ext_name . '-' . $ext_ver . ':] {--ADMIN_UPDATE_EXT_SUBJ--}';
890 // Is the extension there?
891 if (isExtensionInstalled($ext_name)) {
892 // Check if task is not there
893 if (determineTaskIdBySubject($subject) == 0) {
894 // Create extension update-task
895 createNewTask($subject, $notes, 'EXTENSION_UPDATE', 0, $adminId);
898 // Extension not there! :-(
899 debug_report_bug(sprintf("Extension <strong>%s</strong> not found but should be updated?", $ext_name));
903 // Creates a new task for newly installed extension
904 function createNewExtensionTask ($adminId, $subject, $ext) {
905 // Not installed and do we have created a task for the admin?
906 if ((determineTaskIdBySubject($subject) == 0) && (!isExtensionInstalled($ext))) {
907 // Set default message if ext-foo is missing
908 $message = sprintf(getMessage('ADMIN_EXT_TEXT_FILE_MISSING'), $ext);
911 $tpl = sprintf("%stemplates/%s/html/ext/ext_%s.tpl",
917 // Load text for task if found
918 if (isFileReadable($tpl)) {
919 // Load extension's own text template (HTML!)
920 $message = loadTemplate('ext_' . $ext, true);
922 // Write this in debug.log as well
923 logDebugMessage(__FUNCTION__, __LINE__, $message);
926 // Task not created so it's a brand-new extension which we need to register and create a task for!
927 createNewTask($subject, $message, 'EXTENSION', 0, $adminId, false);
931 // Creates a task for automatically deactivated (deprecated) extension
932 function createExtensionDeactivationTask ($ext) {
933 // Create subject line
934 $subject = sprintf("[%s:] %s", $ext, getMessage('TASK_SUBJ_EXTENSION_DEACTIVATED'));
936 // Not installed and do we have created a task for the admin?
937 if ((determineTaskIdBySubject($subject) == 0) && (getExtensionVersion($ext) != '')) {
938 // Task not created so add it
939 createNewTask($subject, SQL_ESCAPE(loadTemplate('task_ext_deactivated', true, $ext)), 'EXTENSION_DEACTIVATION');
943 // Checks if the module has a menu
944 function ifModuleHasMenu ($mod, $forceDb = false) {
945 // All is false by default
948 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "mod={$mod},cache=".getExtensionVersion('cache'));
949 if (isExtensionInstalledAndNewer('cache', '0.1.2')) {
950 // Cache version is okay, so let's check the cache!
951 if (isset($GLOBALS['cache_array']['modules']['has_menu'][$mod])) {
952 // Check module cache and count hit
953 $ret = ($GLOBALS['cache_array']['modules']['has_menu'][$mod] == 'Y');
954 incrementStatsEntry('cache_hits');
955 } elseif (isset($GLOBALS['cache_array']['extension']['ext_menu'][$mod])) {
956 // Check cache and count hit
957 $ret = ($GLOBALS['cache_array']['extension']['ext_menu'][$mod] == 'Y');
958 incrementStatsEntry('cache_hits');
959 } elseif ($mod == 'admin') {
960 // Admin module has always a menu!
963 } elseif ((isExtensionInstalled('sql_patches')) && (getExtensionVersion('sql_patches') >= '0.3.6') && ((!isExtensionActive('cache')) || ($forceDb === true))) {
964 // Check database for entry
965 $result = SQL_QUERY_ESC("SELECT `has_menu` FROM `{?_MYSQL_PREFIX?}_mod_reg` WHERE `module`='%s' LIMIT 1",
966 array($mod), __FUNCTION__, __LINE__);
969 if (SQL_NUMROWS($result) == 1) {
970 // Load "has_menu" column
971 list($has_menu) = SQL_FETCHROW($result);
974 $GLOBALS['cache_array']['extension']['ext_menu'][$mod] = $has_menu;
976 // Does it have a menu?
977 $ret = ($has_menu == 'Y');
981 SQL_FREERESULT($result);
982 } elseif (!isExtensionInstalled('sql_patches')) {
983 // No sql_patches installed, so maybe in admin area or no admin registered?
984 $ret = (((isAdmin()) || (!isAdminRegistered())) && ($mod == 'admin')); // Then there is a menu!
988 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName().intval($ret));
992 // Determines the task id for given extension
993 function determineExtensionTaskId ($ext_name) {
994 // Default is not found
997 // Search for extension task's id
998 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `task_type`='EXTENSION' AND `subject`='[%s:]' LIMIT 1",
999 array($ext_name), __FUNCTION__, __LINE__);
1002 if (SQL_NUMROWS($result) == 1) {
1003 // Task found so load task's ID and register extension...
1004 list($task_id) = SQL_FETCHROW($result);
1008 SQL_FREERESULT($result);
1014 // Determines the task id for given subject
1015 function determineTaskIdBySubject ($subject) {
1016 // Default is not found
1019 // Search for task id
1020 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `subject` LIKE '%s%%' LIMIT 1",
1021 array($subject), __FUNCTION__, __LINE__);
1024 if (SQL_NUMROWS($result) == 1) {
1025 // Task found so load task's ID and register extension...
1026 list($task_id) = SQL_FETCHROW($result);
1030 SQL_FREERESULT($result);
1036 // Add updates notes for given version
1037 function addExtensionNotes ($ver) {
1038 // Init notes/content
1039 $out = ''; $content = array();
1041 // Is do we have verbose output enabled?
1042 if ((!isExtensionActive('sql_patches')) || (getConfig('verbose_sql') == 'Y')) {
1043 // Update notes found?
1044 if (getExtensionUpdateNotes($ver) != '') {
1045 // Update notes found
1048 'notes' => getExtensionUpdateNotes($ver)
1052 setExtensionUpdateNotes('', $ver);
1053 } elseif (($ver == '0.0') || ($ver == '0.0.0')) {
1057 'notes' => getMessage('INITIAL_RELEASE')
1060 // No update notes found!
1063 'notes' => getMessage('NO_UPDATE_NOTES')
1068 $out = loadTemplate('admin_ext_notes', true, $content);
1072 appendExtensionNotes($out);
1075 // Getter for CSS files array
1076 function getExtensionCssFiles () {
1077 // By default no additional CSS files are found
1078 $cssFiles = array();
1080 // Is the array there?
1081 if (isset($GLOBALS['css_files'])) {
1083 $cssFiles = $GLOBALS['css_files'];
1090 // Init CSS files array
1091 function initExtensionCssFiles () {
1093 $GLOBALS['css_files'] = array();
1097 function addExtensionCssFile ($file) {
1098 // Is the array there?
1099 if (!isset($GLOBALS['css_files'])) {
1100 // Then auto-init them
1101 initExtensionCssFiles();
1105 $GLOBALS['css_files'][] = $file;
1108 // Setter for EXT_ALWAYS_ACTIVE flag
1109 function setExtensionAlwaysActive ($active) {
1110 $GLOBALS['ext_always_active'][getCurrentExtensionName()] = (string) $active;
1113 // Getter for EXT_ALWAYS_ACTIVE flag
1114 function getExtensionAlwaysActive () {
1115 return $GLOBALS['ext_always_active'][getCurrentExtensionName()];
1118 // Setter for EXT_VERSION flag
1119 function setThisExtensionVersion ($version) {
1120 $GLOBALS['ext_version'][getCurrentExtensionName()] = (string) $version;
1123 // Getter for EXT_VERSION flag
1124 function getThisExtensionVersion () {
1125 return $GLOBALS['ext_version'][getCurrentExtensionName()];
1128 // Setter for EXT_DEPRECATED flag
1129 function setExtensionDeprecated ($deprecated) {
1130 $GLOBALS['ext_deprecated'][getCurrentExtensionName()] = (string) $deprecated;
1133 // Getter for EXT_DEPRECATED flag
1134 function isExtensionDeprecated () {
1135 return ($GLOBALS['ext_deprecated'][getCurrentExtensionName()] == 'Y');
1138 // Setter for EXT_UPDATE_DEPENDS flag
1139 function addExtensionUpdateDependency ($updateDepends) {
1140 // Is the update depency empty? (NEED TO BE FIXED!)
1141 if (empty($updateDepends)) {
1142 // Please report this bug!
1143 debug_report_bug("updateDepends is left empty!");
1146 // Is it not yet added?
1147 if (!in_array($updateDepends, $GLOBALS['ext_running_updates'])) {
1148 //* DEBUG */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName().'/'.$updateDepends);
1149 // Add it to the list of extension update depencies map
1150 $GLOBALS['ext_update_depends'][getCurrentExtensionName()][] = (string) $updateDepends;
1152 // Remember it in the list of running updates
1153 $GLOBALS['ext_running_updates'][] = $updateDepends;
1157 // Checks wether the given extension registration is in progress
1158 function isExtensionRegisterRunning ($ext_name) {
1159 return ((isset($GLOBALS['ext_register_running'])) && (in_array($ext_name, $GLOBALS['ext_register_running'])));
1162 // Init EXT_UPDATE_DEPENDS flag
1163 function initExtensionUpdateDependencies () {
1164 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1166 // Init update depency map automatically if not found
1167 if (!isExtensionUpdateDependenciesInitialized()) {
1168 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()." - INIT!");
1169 $GLOBALS['ext_update_depends'][getCurrentExtensionName()] = array();
1172 // Init running updates array
1173 initExtensionRuningUpdates();
1176 // Adds an extension as "registration in progress"
1177 function addExtensionRunningRegistration ($ext_name) {
1179 if (!isExtensionRegisterRunning($ext_name)) {
1181 $GLOBALS['ext_register_running'][] = $ext_name;
1185 // Checks wether EXT_UPDATE_DEPENDS is initialized
1186 function isExtensionUpdateDependenciesInitialized () {
1187 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1188 return (isset($GLOBALS['ext_update_depends'][getCurrentExtensionName()]));
1191 // Initializes the list of running updates
1192 function initExtensionRuningUpdates () {
1193 // Auto-init ext_running_updates
1194 if (!isset($GLOBALS['ext_running_updates'])) {
1195 $GLOBALS['ext_running_updates'] = array();
1196 $GLOBALS['ext_register_running'] = array();
1200 // Getter for EXT_UPDATE_DEPENDS flag
1201 function getExtensionUpdateDependencies () {
1202 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1203 return $GLOBALS['ext_update_depends'][getCurrentExtensionName()];
1206 // Getter for next iterator depency
1207 function getExtensionUpdateDependenciesIterator () {
1208 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1209 return ($GLOBALS['ext_update_depends'][getCurrentExtensionName()][getExtensionUpdateIterator()]);
1212 // Counter for extension update depencies
1213 function countExtensionUpdateDependencies () {
1214 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1215 return count($GLOBALS['ext_update_depends'][getCurrentExtensionName()]);
1218 // Removes given extension from update denpency list
1219 function removeExtensionUpdateDependency ($ext_name) {
1221 $key = array_search($ext_name, getExtensionUpdateDependencies());
1224 if ($key !== false) {
1226 unset($GLOBALS['ext_update_depends'][getCurrentExtensionName()][$key]);
1228 // And sort the array
1229 ksort($GLOBALS['ext_update_depends'][getCurrentExtensionName()]);
1233 // Init iterator for update depencies
1234 function initExtensionUpdateIterator () {
1235 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1236 $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()] = 0;
1239 // Getter for depency iterator
1240 function getExtensionUpdateIterator () {
1241 // Auto-init iterator
1242 if (!isset($GLOBALS['ext_depend_iterator'][getCurrentExtensionName()])) initExtensionUpdateIterator();
1245 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName().'/'.$GLOBALS['ext_depend_iterator'][getCurrentExtensionName()]);
1246 return $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()];
1249 // Increments the update iterator
1250 function incrementExtensionUpdateIterator () {
1251 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1252 $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()]++;
1255 // Setter for EXT_REPORTS_FAILURE flag
1256 function setExtensionReportsFailure ($reportsFailure) {
1257 $GLOBALS['ext_reports_failure'] = (bool) $reportsFailure;
1260 // Getter for EXT_REPORTS_FAILURE flag
1261 function getExtensionReportsFailure () {
1262 return $GLOBALS['ext_reports_failure'];
1265 // Setter for EXT_VER_HISTORY flag
1266 function setExtensionVersionHistory ($verHistory) {
1267 $GLOBALS['ext_ver_history'][getCurrentExtensionName()] = (array) $verHistory;
1270 // Getter for EXT_VER_HISTORY array
1271 function getExtensionVersionHistory () {
1272 return $GLOBALS['ext_ver_history'][getCurrentExtensionName()];
1275 // Setter for EXT_UPDATE_NOTES
1276 function setExtensionUpdateNotes ($updateNotes, $ver='') {
1277 //* DEBUG: */ print __FUNCTION__.':'.getCurrentExtensionName().'/'.getCurrentExtensionVersion().'/'.$ver.'='.$updateNotes.'<br />';
1279 $GLOBALS['ext_update_notes'][getCurrentExtensionName()][getCurrentExtensionVersion()] = (string) $updateNotes;
1281 $GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ver] = (string) $updateNotes;
1285 // Getter for EXT_UPDATE_NOTES
1286 function getExtensionUpdateNotes ($ver) {
1287 return $GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ver];
1290 // Init extension notice
1291 function initExtensionNotes () {
1292 $GLOBALS['ext_notes'][getCurrentExtensionName()] = '';
1295 // Append extension notice
1296 function appendExtensionNotes ($notes) {
1297 $GLOBALS['ext_notes'][getCurrentExtensionName()] .= (string) trim($notes);
1300 // Getter for extension notes
1301 function getExtensionNotes () {
1302 return $GLOBALS['ext_notes'][getCurrentExtensionName()];
1305 // Setter for current extension name
1306 function setCurrentExtensionName ($ext_name) {
1307 $GLOBALS['curr_ext_name'] = (string) trim($ext_name);
1310 // Getter for current extension name
1311 function getCurrentExtensionName () {
1312 if (isset($GLOBALS['curr_ext_name'])) {
1313 return $GLOBALS['curr_ext_name'];
1317 debug_report_bug(__FUNCTION__.": curr_ext_name not initialized. Please execute initExtensionSqls() before calling this function.");
1320 // Init SQLs array for current extension
1321 function initExtensionSqls () {
1322 // Auto-init the array now...
1323 if (!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()])) {
1324 $GLOBALS['ext_sqls'][getCurrentExtensionName()] = array();
1328 // Adds SQLs to the SQLs array but "assigns" it with current extension name
1329 function addExtensionSql ($sql) {
1331 $GLOBALS['ext_sqls'][getCurrentExtensionName()][getCurrentExtensionVersion()][] = $sql;
1334 // Getter for SQLs array for current extension
1335 function getExtensionSqls () {
1336 // Output debug backtrace if not found (SHOULD NOT HAPPEN!)
1337 if (!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()])) {
1338 // Not found, should not happen
1339 debug_report_bug(sprintf("ext_sqls is empty, current extension: %s",
1340 getCurrentExtensionName()
1345 return $GLOBALS['ext_sqls'][getCurrentExtensionName()];
1348 // Removes SQLs for current extension
1349 function unsetExtensionSqls () {
1350 unset($GLOBALS['ext_sqls'][getCurrentExtensionName()]);
1353 // Auto-initializes the removal list
1354 function initExtensionRemovalList () {
1355 // Is the remove list there?
1356 if (!isset($GLOBALS['ext_update_remove'])) {
1358 $GLOBALS['ext_update_remove'] = array();
1362 // Checks wether the current extension is on the removal list
1363 function isExtensionOnRemovalList () {
1364 // Init removal list
1365 initExtensionRemovalList();
1368 return (in_array(getCurrentExtensionName(), $GLOBALS['ext_update_remove']));
1371 // Adds the current extension to the removal list
1372 function addCurrentExtensionToRemovalList () {
1374 $GLOBALS['ext_update_remove'][] = getCurrentExtensionName();
1377 // Getter for removal list
1378 function getExtensionRemovalList () {
1379 // Return the removal list
1380 return $GLOBALS['ext_update_remove'];
1383 // Redirects if the provided extension is not installed
1384 function redirectOnUninstalledExtension ($ext_name) {
1385 // So is the extension there?
1386 if ((!isExtensionInstalled($ext_name)) || (!isExtensionActive($ext_name))) {
1387 // Redirect to index
1388 redirectToUrl('modules.php?module=index&code=' . getCode('EXTENSION_PROBLEM') . '&ext=' . $ext_name);
1392 // Filter for initialization of all extensions by loading them in 'init' mode
1393 function FILTER_INIT_EXTENSIONS () {
1394 // Do we have some entries?
1395 //* DEBUG */ print __FUNCTION__.': ENTRY!<br />';
1396 if (isset($GLOBALS['cache_array']['extension']['ext_name'])) {
1397 // Load all found extensions if found
1398 //* DEBUG */ print __FUNCTION__.': CACHE - START!<br />';
1399 foreach ($GLOBALS['cache_array']['extension']['ext_name'] as $key => $ext_name) {
1401 //* DEBUG */ print __FUNCTION__.': '.$ext_name.' - START<br />';
1402 loadExtension($ext_name, 'init');
1403 //* DEBUG */ print __FUNCTION__.': '.$ext_name.' - END<br />';
1405 //* DEBUG */ print __FUNCTION__.': CACHE - END!<br />';
1407 //* DEBUG */ print __FUNCTION__.': EXIT!<br />';
1410 // Setter for extension mode
1411 function setExtensionMode ($ext_mode) {
1412 $GLOBALS['ext_mode'] = (string) $ext_mode;
1415 // Getter for extension mode
1416 function getExtensionMode () {
1417 return $GLOBALS['ext_mode'];
1420 // Setter for dry-run
1421 function enableExtensionDryRun ($dry_run = true) {
1422 //* DEBUG: */ print __FUNCTION__.': '.getCurrentExtensionName().'='.intval($dry_run).'<br />';
1423 $GLOBALS['ext_dry_run'] = (bool) $dry_run;
1426 // Getter for dry-run
1427 function getExtensionDryRun () {
1428 return $GLOBALS['ext_dry_run'];
1431 // Setter for current extension version
1432 function setCurrentExtensionVersion ($ext_ver) {
1433 if (empty($ext_ver)) {
1435 $GLOBALS['ext_current_version'] = '0.0';
1438 $GLOBALS['ext_current_version'] = (string) $ext_ver;
1442 // Getter for current extension version
1443 function getCurrentExtensionVersion () {
1444 return $GLOBALS['ext_current_version'];
1447 // Remove the extension from global cache array
1448 function removeExtensionFromArray () {
1449 // "Cache" this name
1450 $ext_name = getCurrentExtensionName();
1452 // Now loop through the whole cache
1453 foreach ($GLOBALS['cache_array']['extension'] as $cacheName=>$cacheArray) {
1454 // Is it an element?
1455 if (isset($cacheArray[$ext_name])) {
1457 unset($cacheArray[$ext_name]);
1458 $GLOBALS['cache_array']['extension'][$cacheName] = $cacheArray;
1461 $key = array_search($ext_name, $cacheArray);
1464 if ($key !== false) {
1465 // Found, so remove it
1466 unset($cacheArray[$key]);
1467 $GLOBALS['cache_array']['extension'][$cacheName] = $cacheArray;
1473 // "Getter" for 'extension has a CSS file' (with same name, of course)
1474 function getExtensionHasCss () {
1475 // Default is no CSS
1478 // Construct FQFN for check
1479 $FQFN = sprintf("%stheme/%s/css/%s.css",
1482 getCurrentExtensionName()
1486 if (isFileReadable($FQFN)) {
1487 // Readable, so it is there...
1495 // Checks wether the given extension has a language file
1496 function ifExtensionHasLanguageFile ($ext_name) {
1497 // Default is no language file
1498 $hasLanguage = false;
1500 // Do we have cache?
1501 if (isset($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name])) {
1503 $hasLanguage = ($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] == 'Y');
1506 incrementStatsEntry('cache_hits');
1508 // Not readable is default
1511 // Is the language file readable for this extension?
1512 if (isLanguageIncludeReadable($ext_name)) {
1518 $GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] = 'Y';
1522 return ($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] == 'Y');
1525 // Load an extension's include file
1526 function loadExtensionInclude () {
1528 if (!isExtensionIncludeReadable()) {
1530 debug_report_bug('Extension ' . getCurrentExtensionName() . ' should be loaded, but is not readable.');
1533 // Generate INC name
1534 $INC = sprintf("inc/extensions/ext-%s.php", getCurrentExtensionName());
1540 // Checks wether an extension is readable
1541 function isExtensionIncludeReadable ($ext_name = '') {
1542 // If empty, use current
1543 if (empty($ext_name)) $ext_name = getCurrentExtensionName();
1546 if (!isset($GLOBALS['ext_inc_readable'][$ext_name])) {
1547 // Generate INC name
1548 $INC = sprintf("inc/extensions/ext-%s.php", getCurrentExtensionName());
1551 $GLOBALS['ext_inc_readable'][$ext_name] = isIncludeReadable($INC);
1555 //* DEBUG: */ print __FUNCTION__.': '.$ext_name.'='.intval($GLOBALS['ext_inc_readable'][$ext_name]).'<br />';
1556 return $GLOBALS['ext_inc_readable'][$ext_name];
1559 // Checks if an extension's function file is readable
1560 function isExtensionFunctionFileReadable ($ext_name) {
1561 if (isset($GLOBALS['cache_array']['extension']['ext_func'][$ext_name])) {
1562 // Just count cache hits
1563 incrementStatsEntry('cache_hits');
1565 // Construct FQFN for functions file
1566 $funcsInclude = sprintf("inc/libs/%s_functions.php", $ext_name);
1568 // Is this include there?
1569 if ((isFileReadable($funcsInclude)) && (!isset($GLOBALS['ext_loaded']['funcs'][$ext_name])) && (getExtensionMode() == 'test')) {
1571 $GLOBALS['cache_array']['extension']['ext_func'][$ext_name] = 'Y';
1574 $GLOBALS['cache_array']['extension']['ext_func'][$ext_name] = 'N';
1579 return ($GLOBALS['cache_array']['extension']['ext_func'][$ext_name] == 'Y');
1582 // Adds an admin menu to the SQL queue of the menu entry is not found
1583 function addAdminMenuSql ($action, $what, $title, $descr, $sort) {
1584 // Now check if this menu is there
1585 if (!isMenuActionValid('admin', $action, $what)) {
1587 if (is_null($what)) {
1589 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES('%s',NULL,'%s','%s',%s)",
1597 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES('%s','%s','%s','%s',%s)",
1606 // Add it to the queue
1607 addExtensionSql($sql);
1608 } elseif (isDebugModeEnabled()) {
1609 // Double menus should be located and fixed!
1610 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double admin menu action=%s, what=%s detected.", $action, $what));
1614 // Adds a guest menu to the SQL queue if the menu entry is not found
1615 function addGuestMenuSql ($action, $what, $title, $visible, $locked, $sort) {
1616 // Now check if this menu is there
1617 if (!isMenuActionValid('guest', $action, $what)) {
1619 if (is_null($what)) {
1621 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s',NULL,'%s','%s','%s',%s)",
1630 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s','%s','%s','%s','%s',%s)",
1640 // Add it to the queue
1641 addExtensionSql($sql);
1642 } elseif (isDebugModeEnabled()) {
1643 // Double menus should be located and fixed!
1644 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double guest menu action=%s, what=%s detected.", $action, $what));
1648 // Adds a member menu to the SQL queue if the menu entry is not found
1649 function addMemberMenuSql ($action, $what, $title, $visible, $locked, $sort) {
1650 // Now check if this menu is there
1651 if (!isMenuActionValid('member', $action, $what)) {
1653 if (is_null($what)) {
1655 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s',NULL,'%s','%s','%s',%s)",
1664 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s','%s','%s','%s','%s',%s)",
1674 // Add it to the queue
1675 addExtensionSql($sql);
1676 } elseif (isDebugModeEnabled()) {
1677 // Double menus should be located and fixed!
1678 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double member menu action=%s, what=%s detected.", $action, $what));
1682 // Adds a sponsor menu to the SQL queue if the menu entry is not found
1683 function addSponsorMenuSql ($action, $what, $title, $active, $sort) {
1684 // Now check if this menu is there, if no ext-sponsor is installed all is not yet added
1685 if ((!isExtensionInstalled('sponsor')) || (!isMenuActionValid('sponsor', $action, $what))) {
1687 if (is_null($what)) {
1689 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_menu` (`action`,`what`,`title`,`active`,`sort`) VALUES('%s',NULL,'%s','%s',%s)",
1697 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_menu` (`action`,`what`,`title`,`active`,`sort`) VALUES('%s','%s','%s','%s',%s)",
1706 // Add it to the queue
1707 addExtensionSql($sql);
1708 } elseif (isDebugModeEnabled()) {
1709 // Double menus should be located and fixed!
1710 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double sponsor menu action=%s, what=%s detected.", $action, $what));
1714 // Enables/disables productive mode for current extension (used only while
1716 function enableExtensionProductive ($isProductive = true) {
1717 $GLOBALS['ext_productive'][getCurrentExtensionName()] = (bool) $isProductive;
1720 // Checks wether the extension is in productive phase. If not set, development
1721 // phase (=false) is assumed.
1722 function isExtensionProductive () {
1723 return ((isset($GLOBALS['ext_productive'][getCurrentExtensionName()])) && ($GLOBALS['ext_productive'][getCurrentExtensionName()] === true));