X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Fextensions-functions.php;h=e1ccca57d11507a857823d0397eb97f0cadd86bb;hp=d1db294f1d097927d2b1925a5de3585e6e45db46;hb=e2148142f8b1a8f40fd6e7ca32185569c5a9083e;hpb=8268379f7f0f38f5cd605714ecd5cbfacff0e282 diff --git a/inc/extensions-functions.php b/inc/extensions-functions.php index d1db294f1d..e1ccca57d1 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 @@ -512,9 +520,9 @@ function isExtensionActive ($ext_name) { } // Get version from extensions -function getExtensionVersion ($ext_name) { +function getExtensionVersion ($ext_name, $force = false) { // By default no extension is found - $ext_ver = 'invalid'; + $ext_ver = 'false'; // Empty extension name should be fixed! if (empty($ext_name)) { @@ -534,7 +542,7 @@ function getExtensionVersion ($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__); @@ -557,7 +565,7 @@ function getExtensionVersion ($ext_name) { } // Extension version should not be invalid - if ($ext_ver == 'invalid') { + if (($ext_ver == 'false') && ($force === false)) { // Please report this trouble debug_report_bug(sprintf("Extension %s has empty version!", $ext_name)); } // END - if @@ -676,9 +684,9 @@ function addExtensionVerboseSqlTable ($title = '', $dashed = '', $switch = false $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); @@ -757,17 +765,18 @@ function getExtensionName ($ext_id) { } // Get extension id from name -function getExtensionId ($ext_name, $forceDb = false) { - // Init ID number - $ret = 0; +function getExtensionId ($ext_name) { + // Init id number + $ret = '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]; // 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", array($ext_name), __FUNCTION__, __LINE__); @@ -776,19 +785,14 @@ function getExtensionId ($ext_name, $forceDb = false) { 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; } // 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] = $ret; + } // Return value return $ret; @@ -887,7 +891,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 @@ -900,7 +904,7 @@ 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); @@ -931,7 +935,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 @@ -989,7 +993,7 @@ function ifModuleHasMenu ($mod, $forceDb = false) { // Determines the task id for given extension function determineExtensionTaskId ($ext_name) { // Default is not found - $task_id = 0; + $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", @@ -997,7 +1001,7 @@ function determineExtensionTaskId ($ext_name) { // Entry found? if (SQL_NUMROWS($result) == 1) { - // Task found so load task's ID and register extension... + // Task found so load task's id and register extension... list($task_id) = SQL_FETCHROW($result); } // END - if @@ -1011,7 +1015,7 @@ function determineExtensionTaskId ($ext_name) { // Determines the task id for given subject function determineTaskIdBySubject ($subject) { // Default is not found - $task_id = 0; + $task_id = '0'; // Search for task id $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `subject` LIKE '%s%%' LIMIT 1", @@ -1019,7 +1023,7 @@ function determineTaskIdBySubject ($subject) { // Entry found? if (SQL_NUMROWS($result) == 1) { - // Task found so load task's ID and register extension... + // Task found so load task's id and register extension... list($task_id) = SQL_FETCHROW($result); } // END - if @@ -1036,7 +1040,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 @@ -1137,7 +1141,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? @@ -1230,7 +1234,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 @@ -1391,9 +1395,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'); @@ -1447,7 +1451,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 @@ -1580,18 +1584,29 @@ function isExtensionFunctionFileReadable ($ext_name) { function addAdminMenuSql ($action, $what, $title, $descr, $sort) { // Now check if this menu is there if (!isMenuActionValid('admin', $action, $what)) { - // Not found, so construct it - $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) - ); + // 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); - } else { + } elseif (isDebugModeEnabled()) { // Double menus should be located and fixed! logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double admin menu action=%s, what=%s detected.", $action, $what)); } @@ -1601,19 +1616,31 @@ function addAdminMenuSql ($action, $what, $title, $descr, $sort) { function addGuestMenuSql ($action, $what, $title, $visible, $locked, $sort) { // Now check if this menu is there if (!isMenuActionValid('guest', $action, $what)) { - // Not found, so construct it - $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) - ); + // 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); - } else { + } elseif (isDebugModeEnabled()) { // Double menus should be located and fixed! logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double guest menu action=%s, what=%s detected.", $action, $what)); } @@ -1623,19 +1650,31 @@ function addGuestMenuSql ($action, $what, $title, $visible, $locked, $sort) { function addMemberMenuSql ($action, $what, $title, $visible, $locked, $sort) { // Now check if this menu is there if (!isMenuActionValid('member', $action, $what)) { - // Not found, so construct it - $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) - ); + // 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); - } else { + } elseif (isDebugModeEnabled()) { // Double menus should be located and fixed! logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double member menu action=%s, what=%s detected.", $action, $what)); } @@ -1645,22 +1684,45 @@ function addMemberMenuSql ($action, $what, $title, $visible, $locked, $sort) { 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))) { - // Not found, so construct it - $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) - ); + // 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); - } else { + } 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] ?>