aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/PluginManager.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2015-11-18 17:40:42 +0100
committerArthurHoaro <arthur@hoa.ro>2016-01-31 18:54:48 +0100
commitdea0ba28f950867532eae572e7bcda49e81bbcf0 (patch)
tree8a9c4f9d7525a2ba249bbaaabe456c2d0941293b /application/PluginManager.php
parent423e2a8b13dc0069c83f3e540f576aa1b89fe5d5 (diff)
downloadShaarli-dea0ba28f950867532eae572e7bcda49e81bbcf0.tar.gz
Shaarli-dea0ba28f950867532eae572e7bcda49e81bbcf0.tar.zst
Shaarli-dea0ba28f950867532eae572e7bcda49e81bbcf0.zip
Fixes #378 - Plugin administration UI.
Diffstat (limited to 'application/PluginManager.php')
-rw-r--r--application/PluginManager.php51
1 files changed, 51 insertions, 0 deletions
diff --git a/application/PluginManager.php b/application/PluginManager.php
index 803f11b4..787ac6a9 100644
--- a/application/PluginManager.php
+++ b/application/PluginManager.php
@@ -34,6 +34,12 @@ class PluginManager
34 public static $PLUGINS_PATH = 'plugins'; 34 public static $PLUGINS_PATH = 'plugins';
35 35
36 /** 36 /**
37 * Plugins meta files extension.
38 * @var string $META_EXT
39 */
40 public static $META_EXT = 'meta';
41
42 /**
37 * Private constructor: new instances not allowed. 43 * Private constructor: new instances not allowed.
38 */ 44 */
39 private function __construct() 45 private function __construct()
@@ -162,6 +168,51 @@ class PluginManager
162 { 168 {
163 return 'hook_' . $pluginName . '_' . $hook; 169 return 'hook_' . $pluginName . '_' . $hook;
164 } 170 }
171
172 /**
173 * Retrieve plugins metadata from *.meta (INI) files into an array.
174 * Metadata contains:
175 * - plugin description [description]
176 * - parameters split with ';' [parameters]
177 *
178 * Respects plugins order from settings.
179 *
180 * @return array plugins metadata.
181 */
182 public function getPluginsMeta()
183 {
184 $metaData = array();
185 $dirs = glob(self::$PLUGINS_PATH . '/*', GLOB_ONLYDIR | GLOB_MARK);
186
187 // Browse all plugin directories.
188 foreach ($dirs as $pluginDir) {
189 $plugin = basename($pluginDir);
190 $metaFile = $pluginDir . $plugin . '.' . self::$META_EXT;
191 if (!is_file($metaFile) || !is_readable($metaFile)) {
192 continue;
193 }
194
195 $metaData[$plugin] = parse_ini_file($metaFile);
196 $metaData[$plugin]['order'] = array_search($plugin, $this->authorizedPlugins);
197
198 // Read parameters and format them into an array.
199 if (isset($metaData[$plugin]['parameters'])) {
200 $params = explode(';', $metaData[$plugin]['parameters']);
201 } else {
202 $params = array();
203 }
204 $metaData[$plugin]['parameters'] = array();
205 foreach ($params as $param) {
206 if (empty($param)) {
207 continue;
208 }
209
210 $metaData[$plugin]['parameters'][$param] = '';
211 }
212 }
213
214 return $metaData;
215 }
165} 216}
166 217
167/** 218/**