From 49754a84202b2a2aca22917d8ab42996daa46a0f Mon Sep 17 00:00:00 2001 From: instantflorian Date: Wed, 30 Oct 2024 06:58:10 +0100 Subject: [PATCH] Update Addon Monitor Fix for hybrid modules --- wbce/modules/addon_monitor/functions.php | 155 ++++++++++++----------- wbce/modules/addon_monitor/info.php | 4 +- 2 files changed, 83 insertions(+), 76 deletions(-) diff --git a/wbce/modules/addon_monitor/functions.php b/wbce/modules/addon_monitor/functions.php index 9932f0bc4..32bd1b3b9 100644 --- a/wbce/modules/addon_monitor/functions.php +++ b/wbce/modules/addon_monitor/functions.php @@ -11,100 +11,105 @@ */ // prevent this file from being accessed directly: -if (!defined('WB_PATH')) { - die("Cannot access this file directly"); -} +defined('WB_PATH') or die("Cannot access this file directly"); if (!function_exists('getModulesArray')) { function getModulesArray() - { - global $database; - $aAddons['addons'] = array(); - $aAddons['count_tools'] = 0; - $aAddons['count_snippets'] = 0; - $aAddons['count_pagemodules'] = 0; - $aAddons['count_wysiwygeditors'] = 0; - $aAddons['default_wysiwyg'] = $database->get_one("SELECT `value` FROM `". TABLE_PREFIX ."settings` WHERE `name` = 'wysiwyg_editor'"); - $sQueryAddons = ( - "SELECT DISTINCT a . * , - IF( s.module IS NOT NULL , 'Y', 'N' ) AS active - FROM ".TABLE_PREFIX."addons a - LEFT JOIN ".TABLE_PREFIX."sections s - ON a.directory = s.module - WHERE `function` LIKE '%page%' OR `function` LIKE '%snippet%' OR `function` LIKE '%tool%' OR `function` LIKE '%wysiwyg%'" - ); +{ + $whiteListAddons = ['page', 'tool', 'snippet', 'wysiwyg']; + global $database; + $aAddons['addons'] = array(); + $aAddons['count_tools'] = 0; + $aAddons['count_snippets'] = 0; + $aAddons['count_pagemodules'] = 0; + $aAddons['count_wysiwygeditors'] = 0; + $aAddons['default_wysiwyg'] = $database->get_one("SELECT `value` FROM `{TP}settings` WHERE `name` = 'wysiwyg_editor'"); + + $sQueryAddons = ( + "SELECT DISTINCT a.*, + IF(s.module IS NOT NULL, 'Y', 'N') AS active + FROM {TP}addons a + LEFT JOIN {TP}sections s ON a.directory = s.module + WHERE `type` = 'module'" + ); - if ($oAddons = $database->query($sQueryAddons)) { - $sLanguageFileLocation = WB_PATH."/modules/%s/languages/".LANGUAGE.".php"; - $mod_name = ''; - $module_name = ''; - // Loop through addons - while ($aRec = $oAddons->fetchRow(MYSQLI_ASSOC)) { - // grab for page_id's and section_id's if Addon is a PAGE TYPE MODULE - if ($aRec['function'] == 'page') { - ++$aAddons['count_pagemodules']; - if ($aRec['active'] == 'Y') { - $sQueryActiveSections = ("SELECT `section_id`, `page_id` FROM `".TABLE_PREFIX."sections` WHERE `module` = '".$aRec['directory']."'"); - if ($oActiveSections = $database->query($sQueryActiveSections)) { - while ($aSections = $oActiveSections->fetchRow(MYSQLI_ASSOC)) { - $aRec['active_sections'][$aSections['section_id']] = $aSections['page_id']; + if ($oAddons = $database->query($sQueryAddons)) { + $sLanguageFileLocation = WB_PATH . "/modules/%s/languages/" . LANGUAGE . ".php"; + + // Loop through addons + while ($aRec = $oAddons->fetchRow(MYSQLI_ASSOC)) { + // Split the function string into an array + $functions = array_map('trim', explode(',', $aRec['function'])); + foreach ($functions as $function) { + if (!in_array($function, $whiteListAddons)) continue; + $aRec['function'] = $function; + #debug_dump($function, $aRec['name']); + switch ($function) { + case 'page': + ++$aAddons['count_pagemodules']; + if ($aRec['active'] == 'Y') { + $sQueryActiveSections = ("SELECT `section_id`, `page_id` FROM `{TP}sections` WHERE `module` = '" . $aRec['directory'] . "'"); + if ($oActiveSections = $database->query($sQueryActiveSections)) { + while ($aSections = $oActiveSections->fetchRow(MYSQLI_ASSOC)) { + $aRec['active_sections'][$aSections['section_id']] = $aSections['page_id']; + } } } - } - } - if ($aRec['function'] == 'tool') { - $aAddons['count_tools']++; - $sIconFile = WB_PATH."/modules/".$aRec['directory']."/tool_icon.png"; - if (is_readable($sIconFile)) { - $aRec['icon'] = "../../modules/".$aRec['directory']."/tool_icon.png"; - } else { - $aRec['icon'] = "../../modules/".basename(dirname(__FILE__))."/icons/tool.png"; - } - } - if ($aRec['function'] == 'snippet') { - ++$aAddons['count_snippets']; - } - if ($aRec['function'] == 'wysiwyg') { - ++$aAddons['count_wysiwygeditors']; - } - if ($aRec['function'] == 'snippet' || $aRec['function'] == 'page') { - $sIconFile = "/modules/".$aRec['directory']."/addon_icon.png"; - if (is_readable(WB_PATH.$sIconFile)) { - $aRec['icon'] = "../..".$sIconFile; - } else { - $sType = ($aRec['function'] == 'snippet') ? 'snippet' : 'page_module'; - $aRec['icon'] = "../../modules/".basename(dirname(__FILE__))."/icons/".$sType.".png"; - } + break; + + case 'tool': + $aAddons['count_tools']++; + $sIconFile = WB_PATH . "/modules/" . $aRec['directory'] . "/tool_icon.png"; + $aRec['icon'] = is_readable($sIconFile) ? "../../modules/" . $aRec['directory'] . "/tool_icon.png" : "../../modules/" . basename(dirname(__FILE__)) . "/icons/tool.png"; + break; + + case 'snippet': + ++$aAddons['count_snippets']; + break; + + case 'wysiwyg': + ++$aAddons['count_wysiwygeditors']; + break; } - // replace description if description in the current LANGUAGE exists - $sLanguageFile = sprintf($sLanguageFileLocation, $aRec['directory']); - if (is_readable($sLanguageFile)) { - require_once($sLanguageFile); - if (isset($module_description) && $module_description != "") { - $aRec['description'] = $module_description; - unset($module_description); - } + + // Handle icons for snippets and page modules + if ($function === 'snippet' || $function === 'page') { + $sIconFile = "/modules/" . $aRec['directory'] . "/addon_icon.png"; + $aRec['icon'] = is_readable(WB_PATH . $sIconFile) ? "../.." . $sIconFile : "../../modules/" . basename(dirname(__FILE__)) . "/icons/" . ($function === 'snippet' ? 'snippet' : 'page_module') . ".png"; } - $aAddons['addons'][] = $aRec; + + // Replace description if description in the current LANGUAGE exists + $sLanguageFile = sprintf($sLanguageFileLocation, $aRec['directory']); + if (is_readable($sLanguageFile)) { + require_once($sLanguageFile); + if (isset($module_description) && $module_description != "") { + $aRec['description'] = $module_description; + unset($module_description); + } + } + + $aAddons['addons'][] = $aRec; } } - return $aAddons; } + + return $aAddons; +} } if (!function_exists('getTemplatesArray')) { function getTemplatesArray() { global $database; - $sDefaultAcp = $database->get_one("SELECT `value` FROM `". TABLE_PREFIX ."settings` WHERE `name` = 'default_theme'"); + $sDefaultAcp = $database->get_one("SELECT `value` FROM `{TP}settings` WHERE `name` = 'default_theme'"); $aAddons['addons'] = array(); $aAddons['count_pagetemplates'] = 0; $aAddons['count_acpthemes'] = 0; $sQueryAddons = ( "SELECT DISTINCT a . * , IF( p.template IS NOT NULL , 'Y', 'N' ) AS active - FROM ".TABLE_PREFIX."addons a - LEFT JOIN ".TABLE_PREFIX."pages p + FROM {TP}addons a + LEFT JOIN {TP}pages p ON a.directory = p.template WHERE `function` = 'theme' OR `function` = 'template' ORDER BY `function`, `name`" @@ -118,7 +123,7 @@ function getTemplatesArray() ++$aAddons['count_pagetemplates']; // grab for page_id's if Addon is used on different pages if ($aRec['active'] == 'Y') { - $sQueryActiveSections = ("SELECT `page_id` FROM `".TABLE_PREFIX."pages` WHERE `template` = '".$aRec['directory']."'"); + $sQueryActiveSections = ("SELECT `page_id` FROM `{TP}pages` WHERE `template` = '".$aRec['directory']."'"); if ($oActiveSections = $database->query($sQueryActiveSections)) { while ($aSections = $oActiveSections->fetchRow(MYSQLI_ASSOC)) { $aRec['active_pages'][] = $aSections['page_id']; @@ -150,8 +155,8 @@ function getLanguagesArray() $sQueryAddons = ( "SELECT DISTINCT a . * , IF( p.language IS NOT NULL , 'Y', 'N' ) AS active - FROM ".TABLE_PREFIX."addons a - LEFT JOIN ".TABLE_PREFIX."pages p + FROM {TP}addons a + LEFT JOIN {TP}pages p ON a.directory = p.language WHERE type = 'language'" ); @@ -161,7 +166,7 @@ function getLanguagesArray() while ($aRec = $oAddons->fetchRow(MYSQLI_ASSOC)) { // grab for page_id's if Addon is used on different pages if ($aRec['active'] == 'Y') { - $sQueryActiveSections = ("SELECT `page_id` FROM `".TABLE_PREFIX."pages` WHERE `language` = '".$aRec['directory']."'"); + $sQueryActiveSections = ("SELECT `page_id` FROM `{TP}pages` WHERE `language` = '".$aRec['directory']."'"); if ($oActiveSections = $database->query($sQueryActiveSections)) { while ($aSections = $oActiveSections->fetchRow(MYSQLI_ASSOC)) { $aRec['active_pages'][] = $aSections['page_id']; diff --git a/wbce/modules/addon_monitor/info.php b/wbce/modules/addon_monitor/info.php index 1ac3727b2..de17b65b5 100644 --- a/wbce/modules/addon_monitor/info.php +++ b/wbce/modules/addon_monitor/info.php @@ -2,7 +2,7 @@ $module_directory = 'addon_monitor'; $module_name = 'Addon Monitor'; $module_function = 'tool'; -$module_version = '0.7.1'; +$module_version = '0.7.2'; $module_status = 'stable'; $module_platform = '1.0.0'; $module_author = 'Christian M. Stefan (Stefek)'; @@ -12,6 +12,8 @@ /** * Version history * + * 0.7.2 - fix for hybrid modules + * * 0.7.1 - cs fixed files * * 0.7.0 - fix issues changed twig version and PHP 8