X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fextensions-functions.php;h=a9c6fd92391bdc6227654e03015edf95292af0a8;hb=215d0d0d066ee2924ec8fa4b8efe6bf93358ad6f;hp=daac4a821839455afe07eb3d7bca7ec1fbee2067;hpb=06d97fddd5c72e2b1c14ddb855b7eddc53f169a7;p=mailer.git diff --git a/inc/extensions-functions.php b/inc/extensions-functions.php index daac4a8218..a9c6fd9239 100644 --- a/inc/extensions-functions.php +++ b/inc/extensions-functions.php @@ -1,7 +1,7 @@ 0); // Is it installed, then cache the entry if ($isInstalled === true) { - // Dummy call + // Dummy call (get is okay here) getExtensionId($ext_name, true); } // END - if - // Free result - SQL_FREERESULT($result); + // Remember the status + $GLOBALS['ext_is_installed'][$ext_name] = $isInstalled; } // Return status @@ -467,19 +478,19 @@ function isExtensionActive ($ext_name) { if ((isInstallationPhase()) || (empty($ext_name))) return false; // Not active is the default - $active = 'N'; + $data['ext_active'] = 'N'; // Check cache if (isset($GLOBALS['cache_array']['extension']['ext_active'][$ext_name])) { // Load from cache //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "CACHE! ext_name={$ext_name}"); - $active = $GLOBALS['cache_array']['extension']['ext_active'][$ext_name]; + $data['ext_active'] = $GLOBALS['cache_array']['extension']['ext_active'][$ext_name]; // Count cache hits incrementStatsEntry('cache_hits'); } elseif (isset($GLOBALS['ext_loaded'][$ext_name])) { // @TODO Extension is loaded, what next? - app_die(__FUNCTION__, __LINE__, "LOADED:$ext_name"); + app_die(__FUNCTION__, __LINE__, 'LOADED:' . $ext_name); } elseif (($ext_name == 'cache') || (!isExtensionInstalled('cache'))) { //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "DB! ext_name={$ext_name}"); // Load from database @@ -489,15 +500,15 @@ function isExtensionActive ($ext_name) { // Entry found? if (SQL_NUMROWS($result) == 1) { // Load entry - list($active) = SQL_FETCHROW($result); + $data = SQL_FETCHARRAY($result); } // END - if // Free result SQL_FREERESULT($result); // Write cache array - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name=".$ext_name."[DB]: {$active}"); - $GLOBALS['cache_array']['extension']['ext_active'][$ext_name] = $active; + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name=".$ext_name."[DB]: ".$data['ext_active'].""); + $GLOBALS['cache_array']['extension']['ext_active'][$ext_name] = $data['ext_active']; } else { // Extension not active! //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name=".$ext_name.": Not active!"); @@ -505,16 +516,16 @@ function isExtensionActive ($ext_name) { } // Debug message - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name={$ext_name},active={$active}"); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name=".$ext_name.",active=".$data['ext_active'].""); // Is this extension activated? (For admins we always have active extensions...) - return ($active == 'Y'); + return ($data['ext_active'] == 'Y'); } // Get version from extensions -function getExtensionVersion ($ext_name) { +function getExtensionVersion ($ext_name, $force = false) { // By default no extension is found - $ext_ver = 'invalid'; + $data['ext_version'] = 'false'; // Empty extension name should be fixed! if (empty($ext_name)) { @@ -524,47 +535,47 @@ function getExtensionVersion ($ext_name) { // Extensions are all inactive during installation if (isInstallationPhase()) return ''; - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": ext_name={$ext_name}"); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": ext_name=".$ext_name.""); // Is the cache written? if (isset($GLOBALS['cache_array']['extension']['ext_version'][$ext_name])) { // Load data from cache - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": CACHE!"); - $ext_ver = $GLOBALS['cache_array']['extension']['ext_version'][$ext_name]; + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $ext_name . ': CACHE!'); + $data['ext_version'] = $GLOBALS['cache_array']['extension']['ext_version'][$ext_name]; // Count cache hits incrementStatsEntry('cache_hits'); - } elseif ((!isCacheInstanceValid()) || (isset($GLOBALS['cache_array']['extension'])) || (getOutputMode() != '0')) { + } elseif ((!isCacheInstanceValid()) || (isset($GLOBALS['cache_array']['extension'])) || (getOutputMode() != 0)) { // Load from database $result = SQL_QUERY_ESC("SELECT `ext_version` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1", array($ext_name), __FUNCTION__, __LINE__); - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": DB - ".SQL_NUMROWS($result).""); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $ext_name . ': DB - '.SQL_NUMROWS($result).''); // Is the extension there? if (SQL_NUMROWS($result) == 1) { // Load entry - list($ext_ver) = SQL_FETCHROW($result); + $data = SQL_FETCHARRAY($result); } elseif (isDebugModeEnabled()) { - // Not found! - logDebugMessage(__FUNCTION__, __LINE__, sprintf(": Cannot find extension %s in database!", $ext_name)); + // Not found, please report all + debug_report_bug(sprintf(": Cannot find extension %s in database!", $ext_name)); } // Free result SQL_FREERESULT($result); // Set cache - $GLOBALS['cache_array']['extension']['ext_version'][$ext_name] = $ext_ver; + $GLOBALS['cache_array']['extension']['ext_version'][$ext_name] = $data['ext_version']; } // Extension version should not be invalid - if ($ext_ver == 'invalid') { + if (($data['ext_version'] == 'false') && ($force === false)) { // Please report this trouble debug_report_bug(sprintf("Extension %s has empty version!", $ext_name)); } // END - if // Return result - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": ret={$ext_ver}"); - return $ext_ver; + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": ret={$data['ext_version']}"); + return $data['ext_version']; } // Updates a given extension with current extension version to latest version @@ -610,17 +621,23 @@ function updateExtension ($ext_name, $ext_ver, $dry_run = false) { if (count($depencies) > 0) { // Apply all extension depencies foreach ($depencies as $ext_depend) { - // Set it as current - setCurrentExtensionName($ext_depend); - - // Is the extension there? - if (isExtensionInstalled($ext_depend)) { - // Update another extension first! - $test = updateExtension($ext_depend, getExtensionVersion($ext_depend), getExtensionDryRun()); - } else { - // Register new extension - $test = registerExtension($ext_depend, 0, getExtensionDryRun(), false); - } + // Did we already update/register this? + if (!isset($GLOBALS['ext_updated'][$ext_depend])) { + // Set it as current + setCurrentExtensionName($ext_depend); + + // Mark it as already updated before we update it + $GLOBALS['ext_updated'][$ext_depend] = true; + + // Is the extension there? + if (isExtensionInstalled($ext_depend)) { + // Update another extension first! + $test = updateExtension($ext_depend, getExtensionVersion($ext_depend), getExtensionDryRun()); + } else { + // Register new extension + $test = registerExtension($ext_depend, 0, getExtensionDryRun(), false); + } + } // END - if } // END - foreach // Set name back @@ -665,14 +682,14 @@ function addExtensionVerboseSqlTable ($title = '', $dashed = '', $switch = false $OUT = ''; // Do we have queries? - if ((getExtensionVersion('sql_patches') >= '0.0.7') && (getConfig('verbose_sql') == 'Y')) { + if ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y')) { // Init switch color $SW = 2; // Get all SQLs - foreach (getExtensionSqls() as $idx => $sqls) { + foreach (getExtensionSqls() as $sqls) { // New array format is recursive - foreach ($sqls as $sql) { + foreach ($sqls as $idx => $sql) { // Trim out spaces $sql = trim($sql); @@ -704,7 +721,7 @@ function addExtensionVerboseSqlTable ($title = '', $dashed = '', $switch = false // Load main template $OUT = loadTemplate('admin_ext_sql_table', true, $content); - } elseif ((getExtensionVersion('sql_patches') >= '0.0.7') && (getConfig('verbose_sql') == 'Y')) { + } elseif ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y')) { // No addional SQL commands to run $OUT = loadTemplate('admin_settings_saved', true, getMessage('ADMIN_NO_ADDITIONAL_SQLS')); } // END - if @@ -716,12 +733,12 @@ function addExtensionVerboseSqlTable ($title = '', $dashed = '', $switch = false // Get extension name from id function getExtensionName ($ext_id) { // Init extension name - $ret = ''; + $data['ext_name'] = ''; // Is cache there? if (isset($GLOBALS['cache_array']['extension']['ext_name'][$ext_id])) { // Load from cache - $ret = $GLOBALS['cache_array']['extension']['ext_name'][$ext_id]; + $data['ext_name'] = $GLOBALS['cache_array']['extension']['ext_name'][$ext_id]; // Count cache hits incrementStatsEntry('cache_hits'); @@ -733,7 +750,7 @@ function getExtensionName ($ext_id) { // Is the entry there? if (SQL_NUMROWS($result) == 1) { // Get the extension's name from database - list($ret) = SQL_FETCHROW($result); + $data = SQL_FETCHARRAY($result); } // END - if // Free result @@ -741,51 +758,47 @@ function getExtensionName ($ext_id) { } // Did we find some extension? - if (empty($ret)) { + if (empty($data['ext_name'])) { // We should fix these all! debug_report_bug(__FUNCTION__ . ': ext_name is empty. ext_id=' . $ext_id); } // END - if // Return the extension name - return $ret; + return $data['ext_name']; } // Get extension id from name -function getExtensionId ($ext_name, $forceDb = false) { - // Init ID number - $ret = 0; +function getExtensionId ($ext_name) { + // Init id number + $data['ext_id'] = '0'; + // Do we have cache? if (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) { // Load from cache - $ret = $GLOBALS['cache_array']['extension']['ext_id'][$ext_name]; + $data['ext_id'] = $GLOBALS['cache_array']['extension']['ext_id'][$ext_name]; // Count cache hits incrementStatsEntry('cache_hits'); - } elseif (($forceDb === true) || (!isExtensionActive('cache'))) { + } else { // Load from database - $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1", + $result = SQL_QUERY_ESC("SELECT `id` AS ext_id FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1", array($ext_name), __FUNCTION__, __LINE__); // Is the entry there? if (SQL_NUMROWS($result) == 1) { // Get the extension's id from database - list($ret) = SQL_FETCHROW($result); - - // Cache it - $GLOBALS['cache_array']['extension']['ext_id'][$ext_name] = $ret; + $data = SQL_FETCHARRAY($result); } // END - if // Free result SQL_FREERESULT($result); - } - if ($ret == 0) { - // We should fix these all! - debug_report_bug(__FUNCTION__ . ': Invalid extension name found. ext_name=' . $ext_name); - } // END - if + // Cache it + $GLOBALS['cache_array']['extension']['ext_id'][$ext_name] = $data['ext_id']; + } // Return value - return $ret; + return $data['ext_id']; } // Determines wether the given extension name is valid @@ -853,7 +866,7 @@ function doDeactivateExtension($ext_name) { // Notify the admin sendAdminNotification( - getMessage('ADMIN_SUBJECT_EXTENSION_DEACTIVATED'), + getMessage('ADMIN_SUBJECT_EXTENSION_DEACTIVATED'), 'admin_ext_deactivated', array('ext_name' => $ext_name) ); @@ -881,7 +894,7 @@ function createExtensionUpdateTask ($adminId, $ext_name, $ext_ver, $notes) { // Is the extension there? if (isExtensionInstalled($ext_name)) { // Check if task is not there - if (determineTaskIdBySubject($subject) == 0) { + if (determineTaskIdBySubject($subject) == '0') { // Create extension update-task createNewTask($subject, $notes, 'EXTENSION_UPDATE', 0, $adminId); } // END - if @@ -894,9 +907,9 @@ function createExtensionUpdateTask ($adminId, $ext_name, $ext_ver, $notes) { // Creates a new task for newly installed extension function createNewExtensionTask ($adminId, $subject, $ext) { // Not installed and do we have created a task for the admin? - if ((determineTaskIdBySubject($subject) == 0) && (!isExtensionInstalled($ext))) { + if ((determineTaskIdBySubject($subject) == '0') && (!isExtensionInstalled($ext))) { // Set default message if ext-foo is missing - $message = sprintf(getMessage('ADMIN_EXT_TEXT_FILE_MISSING'), $ext); + $message = getMaskedMessage('ADMIN_EXT_TEXT_FILE_MISSING', $ext); // Template file $tpl = sprintf("%stemplates/%s/html/ext/ext_%s.tpl", @@ -925,7 +938,7 @@ function createExtensionDeactivationTask ($ext) { $subject = sprintf("[%s:] %s", $ext, getMessage('TASK_SUBJ_EXTENSION_DEACTIVATED')); // Not installed and do we have created a task for the admin? - if ((determineTaskIdBySubject($subject) == 0) && (getExtensionVersion($ext) != '')) { + if ((determineTaskIdBySubject($subject) == '0') && (getExtensionVersion($ext) != '')) { // Task not created so add it createNewTask($subject, SQL_ESCAPE(loadTemplate('task_ext_deactivated', true, $ext)), 'EXTENSION_DEACTIVATION'); } // END - if @@ -936,7 +949,7 @@ function ifModuleHasMenu ($mod, $forceDb = false) { // All is false by default $ret = false; - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "mod={$mod},cache=".getExtensionVersion('cache')); + // Extension installed and newer than or has version 0.1.2? if (isExtensionInstalledAndNewer('cache', '0.1.2')) { // Cache version is okay, so let's check the cache! if (isset($GLOBALS['cache_array']['modules']['has_menu'][$mod])) { @@ -947,9 +960,9 @@ function ifModuleHasMenu ($mod, $forceDb = false) { // Check cache and count hit $ret = ($GLOBALS['cache_array']['extension']['ext_menu'][$mod] == 'Y'); incrementStatsEntry('cache_hits'); - } elseif ($mod == 'admin') { - // Admin module has always a menu! - $ret = true; + } else { + // Admin/guest/member/sponsor modules have always a menu! + $ret = in_array($mod, array('admin', 'index', 'login', 'sponsor')); } } elseif ((isExtensionInstalled('sql_patches')) && (getExtensionVersion('sql_patches') >= '0.3.6') && ((!isExtensionActive('cache')) || ($forceDb === true))) { // Check database for entry @@ -959,69 +972,71 @@ function ifModuleHasMenu ($mod, $forceDb = false) { // Entry found? if (SQL_NUMROWS($result) == 1) { // Load "has_menu" column - list($has_menu) = SQL_FETCHROW($result); + $data = SQL_FETCHARRAY($result); // Fake cache... ;-) - $GLOBALS['cache_array']['extension']['ext_menu'][$mod] = $has_menu; + $GLOBALS['cache_array']['extension']['ext_menu'][$mod] = $data['has_menu']; // Does it have a menu? - $ret = ($has_menu == 'Y'); + $ret = ($data['has_menu'] == 'Y'); } // END - if // Free memory SQL_FREERESULT($result); } elseif (!isExtensionInstalled('sql_patches')) { - // No sql_patches installed, so maybe in admin area or no admin registered? - $ret = (((isAdmin()) || (!isAdminRegistered())) && ($mod == 'admin')); // Then there is a menu! + // No sql_patches installed, so maybe in admin/guest/member/sponsor area or no admin registered? + $ret = in_array($mod, array('admin', 'index', 'login', 'sponsor')); // Then there is a menu! + } else { + // Unsupported state! + debug_report_bug('This should never be reached.'); } // Return status - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName().intval($ret)); return $ret; } // Determines the task id for given extension function determineExtensionTaskId ($ext_name) { // Default is not found - $task_id = 0; + $data['task_id'] = '0'; // Search for extension task's id - $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `task_type`='EXTENSION' AND `subject`='[%s:]' LIMIT 1", + $result = SQL_QUERY_ESC("SELECT `id` AS task_id FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `task_type`='EXTENSION' AND `subject`='[%s:]' LIMIT 1", array($ext_name), __FUNCTION__, __LINE__); // Entry found? if (SQL_NUMROWS($result) == 1) { - // Task found so load task's ID and register extension... - list($task_id) = SQL_FETCHROW($result); + // Task found so load task's id and register extension... + $data = SQL_FETCHARRAY($result); } // END - if // Free result SQL_FREERESULT($result); // Return it - return $task_id; + return $data['task_id']; } // Determines the task id for given subject function determineTaskIdBySubject ($subject) { // Default is not found - $task_id = 0; + $data['task_id'] = '0'; // Search for task id - $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `subject` LIKE '%s%%' LIMIT 1", + $result = SQL_QUERY_ESC("SELECT `id` AS task_id FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `subject` LIKE '%s%%' LIMIT 1", array($subject), __FUNCTION__, __LINE__); // Entry found? if (SQL_NUMROWS($result) == 1) { - // Task found so load task's ID and register extension... - list($task_id) = SQL_FETCHROW($result); + // Task found so load task's id and register extension... + $data = SQL_FETCHARRAY($result); } // END - if // Free result SQL_FREERESULT($result); // Return it - return $task_id; + return $data['task_id']; } // Add updates notes for given version @@ -1030,7 +1045,7 @@ function addExtensionNotes ($ver) { $out = ''; $content = array(); // Is do we have verbose output enabled? - if ((getConfig('verbose_sql') == 'Y') || (!isExtensionActive('sql_patches'))) { + if ((!isExtensionActive('sql_patches')) || (getConfig('verbose_sql') == 'Y')) { // Update notes found? if (getExtensionUpdateNotes($ver) != '') { // Update notes found @@ -1131,7 +1146,7 @@ function addExtensionUpdateDependency ($updateDepends) { // Is the update depency empty? (NEED TO BE FIXED!) if (empty($updateDepends)) { // Please report this bug! - debug_report_bug("updateDepends is left empty!"); + debug_report_bug('updateDepends is left empty!'); } // END - if // Is it not yet added? @@ -1224,7 +1239,7 @@ function removeExtensionUpdateDependency ($ext_name) { // Init iterator for update depencies function initExtensionUpdateIterator () { //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()); - $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()] = 0; + $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()] = '0'; } // Getter for depency iterator @@ -1385,9 +1400,9 @@ function FILTER_INIT_EXTENSIONS () { // Do we have some entries? //* DEBUG */ print __FUNCTION__.': ENTRY!
'; if (isset($GLOBALS['cache_array']['extension']['ext_name'])) { - //* DEBUG */ print __FUNCTION__.': CACHE - START!
'; // Load all found extensions if found - foreach ($GLOBALS['cache_array']['extension']['ext_name'] as $key=>$ext_name) { + //* DEBUG */ print __FUNCTION__.': CACHE - START!
'; + foreach ($GLOBALS['cache_array']['extension']['ext_name'] as $key => $ext_name) { // Load it //* DEBUG */ print __FUNCTION__.': '.$ext_name.' - START
'; loadExtension($ext_name, 'init'); @@ -1441,7 +1456,7 @@ function removeExtensionFromArray () { $ext_name = getCurrentExtensionName(); // Now loop through the whole cache - foreach ($GLOBALS['cache_array']['extension'] as $cacheName=>$cacheArray) { + foreach ($GLOBALS['cache_array']['extension'] as $cacheName => $cacheArray) { // Is it an element? if (isset($cacheArray[$ext_name])) { // Array element @@ -1543,7 +1558,7 @@ function isExtensionIncludeReadable ($ext_name = '') { } // END - if // Return result - //* DEBUG: */ print __FUNCTION__.': '.$ext_name.'='.intval($GLOBALS['ext_inc_readable'][$ext_name]).'
'; + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',realable='.intval($GLOBALS['ext_inc_readable'][$ext_name])); return $GLOBALS['ext_inc_readable'][$ext_name]; } @@ -1570,5 +1585,149 @@ function isExtensionFunctionFileReadable ($ext_name) { return ($GLOBALS['cache_array']['extension']['ext_func'][$ext_name] == 'Y'); } +// Adds an admin menu to the SQL queue of the menu entry is not found +function addAdminMenuSql ($action, $what, $title, $descr, $sort) { + // Now check if this menu is there + if (!isMenuActionValid('admin', $action, $what)) { + // Is what null? + if (is_null($what)) { + // Add main menu + $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES('%s',NULL,'%s','%s',%s)", + $action, + $title, + $descr, + bigintval($sort) + ); + } else { + // Add sub menu + $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES('%s','%s','%s','%s',%s)", + $action, + $what, + $title, + $descr, + bigintval($sort) + ); + } + + // Add it to the queue + addExtensionSql($sql); + } elseif (isDebugModeEnabled()) { + // Double menus should be located and fixed! + logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double admin menu action=%s, what=%s detected.", $action, $what)); + } +} + +// Adds a guest menu to the SQL queue if the menu entry is not found +function addGuestMenuSql ($action, $what, $title, $visible, $locked, $sort) { + // Now check if this menu is there + if (!isMenuActionValid('guest', $action, $what)) { + // Is what null? + if (is_null($what)) { + // Add main menu + $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s',NULL,'%s','%s','%s',%s)", + $action, + $title, + $visible, + $locked, + bigintval($sort) + ); + } else { + // Add sub menu + $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s','%s','%s','%s','%s',%s)", + $action, + $what, + $title, + $visible, + $locked, + bigintval($sort) + ); + } + + // Add it to the queue + addExtensionSql($sql); + } elseif (isDebugModeEnabled()) { + // Double menus should be located and fixed! + logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double guest menu action=%s, what=%s detected.", $action, $what)); + } +} + +// Adds a member menu to the SQL queue if the menu entry is not found +function addMemberMenuSql ($action, $what, $title, $visible, $locked, $sort) { + // Now check if this menu is there + if (!isMenuActionValid('member', $action, $what)) { + // Is what null? + if (is_null($what)) { + // Add main menu + $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s',NULL,'%s','%s','%s',%s)", + $action, + $title, + $visible, + $locked, + bigintval($sort) + ); + } else { + // Add sub menu + $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s','%s','%s','%s','%s',%s)", + $action, + $what, + $title, + $visible, + $locked, + bigintval($sort) + ); + } + + // Add it to the queue + addExtensionSql($sql); + } elseif (isDebugModeEnabled()) { + // Double menus should be located and fixed! + logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double member menu action=%s, what=%s detected.", $action, $what)); + } +} + +// Adds a sponsor menu to the SQL queue if the menu entry is not found +function addSponsorMenuSql ($action, $what, $title, $active, $sort) { + // Now check if this menu is there, if no ext-sponsor is installed all is not yet added + if ((!isExtensionInstalled('sponsor')) || (!isMenuActionValid('sponsor', $action, $what))) { + // Is what null? + if (is_null($what)) { + // Add main menu + $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_menu` (`action`,`what`,`title`,`active`,`sort`) VALUES('%s',NULL,'%s','%s',%s)", + $action, + $title, + $active, + bigintval($sort) + ); + } else { + // Add sub menu + $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_menu` (`action`,`what`,`title`,`active`,`sort`) VALUES('%s','%s','%s','%s',%s)", + $action, + $what, + $title, + $active, + bigintval($sort) + ); + } + + // Add it to the queue + addExtensionSql($sql); + } elseif (isDebugModeEnabled()) { + // Double menus should be located and fixed! + logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double sponsor menu action=%s, what=%s detected.", $action, $what)); + } +} + +// Enables/disables productive mode for current extension (used only while +// registration). +function enableExtensionProductive ($isProductive = true) { + $GLOBALS['ext_productive'][getCurrentExtensionName()] = (bool) $isProductive; +} + +// Checks wether the extension is in productive phase. If not set, development +// phase (=false) is assumed. +function isExtensionProductive () { + return ((isset($GLOBALS['ext_productive'][getCurrentExtensionName()])) && ($GLOBALS['ext_productive'][getCurrentExtensionName()] === true)); +} + // [EOF] ?>