diff --git a/src/api.php b/src/api.php index ed58b79..c8177bd 100644 --- a/src/api.php +++ b/src/api.php @@ -65,7 +65,7 @@ foreach (MTTExtensionLoader::loadedExtensions() as $instance) { if ($instance instanceof MTTHttpApiExtender) { $newRoutes = $instance->extendHttpApi(); foreach ($newRoutes as $endpoint => $methods) { - $endpoint = '/ext/'. $instance::codename. $endpoint; + $endpoint = '/ext/'. $instance::bundleId. $endpoint; foreach ($methods as $k => &$v) { $v[2] = true; // Mark extension method } diff --git a/src/includes/classes.php b/src/includes/classes.php index e31afe3..551901f 100644 --- a/src/includes/classes.php +++ b/src/includes/classes.php @@ -73,7 +73,7 @@ abstract class ApiController abstract class MTTExtension { - const codename = ''; + const bundleId = ''; const title = ''; abstract function init(); } @@ -120,11 +120,11 @@ class MTTExtensionLoader } $className = get_class($instance); - if (!defined("$className::codename") || !defined("$className::title")) { - throw new Exception("Failed to register extension '$ext': require class constants (codename, title)"); + if (!defined("$className::bundleId") || !defined("$className::title")) { + throw new Exception("Failed to register extension '$ext': require class constants (bundleId, title)"); } - if ($instance::codename != $ext) { - throw new Exception("Extension '$ext' codename does not conforms to extension dir"); + if ($instance::bundleId != $ext) { + throw new Exception("Extension '$ext' bundleId does not conforms to extension dir"); } $instance->init(); @@ -151,10 +151,23 @@ class MTTExtensionLoader $a = []; $files = array_diff(scandir(MTT_EXT) ?? [], ['.', '..']); foreach ($files as $ext) { - if ( !is_dir(MTT_EXT. $ext) || !file_exists(MTT_EXT. $ext. '/loader.php') ) { + if ( !is_dir(MTT_EXT. $ext) + || !file_exists(MTT_EXT. $ext. '/loader.php') + || !file_exists(MTT_EXT. $ext. '/extension.json') ) { continue; } - $a[] = $ext; + $jsonData = file_get_contents(MTT_EXT. $ext. '/extension.json'); + if ($jsonData === false) { + continue; + } + $meta = json_decode($jsonData, true); + if (!is_array($meta) || !isset($meta['bundleId']) || !isset($meta['title']) || !isset($meta['description'])) { + continue; + } + if (!is_string($meta['bundleId']) || !is_string($meta['title']) || !is_string($meta['description'])) { + continue; + } + $a[$ext] = $meta; } return $a; } diff --git a/src/settings.php b/src/settings.php index bc3f10c..486b3c9 100644 --- a/src/settings.php +++ b/src/settings.php @@ -72,7 +72,8 @@ else if (isset($_POST['activate'])) $activate = (int)_post('activate'); $ext = _post('ext'); - $exts = MTTExtensionLoader::bundles(); + $extBundles = MTTExtensionLoader::bundles(); + $exts = array_keys($extBundles); $a = Config::get('extensions'); if (!is_array($a)) $a = []; @@ -189,11 +190,11 @@ function timezoneIdentifiers() function listExtensions() { - $exts = MTTExtensionLoader::bundles(); + $extBundles = MTTExtensionLoader::bundles(); $activatedExts = Config::get('extensions'); if (!is_array($activatedExts)) $activatedExts = []; - foreach ($exts as $ext) { - $out = "$ext "; + foreach ($extBundles as $ext => $meta) { + $out = htmlspecialchars($meta['title']). ' '; if (in_array($ext, $activatedExts)) { $out .= "". __('set_deactivate', true). ''; $instance = MTTExtensionLoader::extensionInstance($ext);