summaryrefslogtreecommitdiff
path: root/app/Core/Plugin
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-05-24 21:39:36 -0400
committerFrederic Guillot <fred@kanboard.net>2016-05-24 21:39:36 -0400
commit8ba05940e9ee76e95ce808d8da163c2af29e4e93 (patch)
treeaa25adca7227774dfbbcddfd5e294ef3e44f7692 /app/Core/Plugin
parentb9f2d5650d464983a80f84f3ed0845028a355c92 (diff)
Filter non compatible plugins
Diffstat (limited to 'app/Core/Plugin')
-rw-r--r--app/Core/Plugin/Directory.php56
1 files changed, 56 insertions, 0 deletions
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'];
+ }
+}