diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/Console/PluginUpgradeCommand.php | 3 | ||||
-rw-r--r-- | app/Controller/PluginController.php | 3 | ||||
-rw-r--r-- | app/Core/Plugin/Directory.php | 56 |
3 files changed, 60 insertions, 2 deletions
diff --git a/app/Console/PluginUpgradeCommand.php b/app/Console/PluginUpgradeCommand.php index 6ec5836d..839124b1 100644 --- a/app/Console/PluginUpgradeCommand.php +++ b/app/Console/PluginUpgradeCommand.php @@ -3,6 +3,7 @@ namespace Kanboard\Console; use Kanboard\Core\Plugin\Base as BasePlugin; +use Kanboard\Core\Plugin\Directory; use Kanboard\Core\Plugin\Installer; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -24,7 +25,7 @@ class PluginUpgradeCommand extends BaseCommand } $installer = new Installer($this->container); - $availablePlugins = $this->httpClient->getJson(PLUGIN_API_URL); + $availablePlugins = Directory::getInstance($this->container)->getAvailablePlugins(); foreach ($this->pluginLoader->getPlugins() as $installedPlugin) { $pluginDetails = $this->getPluginDetails($availablePlugins, $installedPlugin); diff --git a/app/Controller/PluginController.php b/app/Controller/PluginController.php index b6f9a33b..7b9d64d9 100644 --- a/app/Controller/PluginController.php +++ b/app/Controller/PluginController.php @@ -2,6 +2,7 @@ namespace Kanboard\Controller; +use Kanboard\Core\Plugin\Directory; use Kanboard\Core\Plugin\Installer; use Kanboard\Core\Plugin\PluginInstallerException; @@ -40,7 +41,7 @@ class PluginController extends BaseController $this->response->html($this->helper->layout->plugin('plugin/directory', array( 'installed_plugins' => $installedPlugins, - 'available_plugins' => $this->httpClient->getJson(PLUGIN_API_URL), + 'available_plugins' => Directory::getInstance($this->container)->getAvailablePlugins(), 'title' => t('Plugin Directory'), 'is_configured' => Installer::isConfigured(), ))); diff --git a/app/Core/Plugin/Directory.php b/app/Core/Plugin/Directory.php new file mode 100644 index 00000000..21f11ca9 --- /dev/null +++ b/app/Core/Plugin/Directory.php @@ -0,0 +1,56 @@ +<?php + +namespace Kanboard\Core\Plugin; + +use Kanboard\Core\Base as BaseCore; + +/** + * Class Directory + * + * @package Kanboard\Core\Plugin + * @author Frederic Guillot + */ +class Directory extends BaseCore +{ + /** + * Get all plugins available + * + * @access public + * @param string $url + * @return array + */ + public function getAvailablePlugins($url = PLUGIN_API_URL) + { + $plugins = $this->httpClient->getJson($url); + $plugins = array_filter($plugins, array($this, 'isCompatible')); + $plugins = array_filter($plugins, array($this, 'isInstallable')); + return $plugins; + } + + /** + * Filter plugins + * + * @param array $plugin + * @param string $appVersion + * @return bool + */ + public function isCompatible(array $plugin, $appVersion = APP_VERSION) + { + if (strpos($appVersion, 'master') !== false) { + return true; + } + + return $plugin['compatible_version'] === $appVersion; + } + + /** + * Filter plugins + * + * @param array $plugin + * @return bool + */ + public function isInstallable(array $plugin) + { + return $plugin['remote_install']; + } +} |