From 3902d3f43330504945e78627b4c49e67ae88aea9 Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Wed, 6 Dec 2017 21:04:45 +0100 Subject: Show existing extensions in admin panel (#1708) * first draft * display installed extension state * fixed whitespace vs tabs * added translation in all languages * added error checks and log messages * fixed tabs vs whitespace * another try in fixing whitespaces * another try in fixing whitespaces * improved extension list translations * using JSON from official extension repo * improved version compare * updated translations * French translation --- app/Controllers/extensionController.php | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'app/Controllers/extensionController.php') diff --git a/app/Controllers/extensionController.php b/app/Controllers/extensionController.php index b6d2d3fe4..bb846e921 100644 --- a/app/Controllers/extensionController.php +++ b/app/Controllers/extensionController.php @@ -25,10 +25,47 @@ class FreshRSS_extension_Controller extends Minz_ActionController { 'user' => array(), ); + $this->view->extensions_installed = array(); + $extensions = Minz_ExtensionManager::listExtensions(); foreach ($extensions as $ext) { $this->view->extension_list[$ext->getType()][] = $ext; + $this->view->extensions_installed[$ext->getEntrypoint()] = $ext->getVersion(); + } + + $availableExtensions = $this->getAvailableExtensionList(); + $this->view->available_extensions = $availableExtensions; + } + + /** + * fetch extension list from GitHub + */ + protected function getAvailableExtensionList() { + $extensionListUrl = 'https://raw.githubusercontent.com/FreshRSS/Extensions/master/extensions.json'; + $json = file_get_contents($extensionListUrl); + + // we ran into problems, simply ignore them + if ($json === false) { + Minz_Log::error('Could not fetch available extension from GitHub'); + return array(); + } + + // fetch the list as an array + $list = json_decode($json, true); + if (empty($list)) { + Minz_Log::warning('Failed to convert extension file list'); + return array(); } + + // we could use that for comparing and caching later + $version = $list['version']; + + // By now, all the needed data is kept in the main extension file. + // In the future we could fetch detail information from the extensions metadata.json, but I tend to stick with + // the current implementation for now, unless it becomes too much effort maintain the extension list manually + $extensions = $list['extensions']; + + return $extensions; } /** -- cgit v1.2.3