aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/PluginManager.php
diff options
context:
space:
mode:
authorArthur <arthur@hoa.ro>2016-01-31 19:00:13 +0100
committerArthur <arthur@hoa.ro>2016-01-31 19:00:13 +0100
commit53603f582300fc2709932b62652a5acfed088910 (patch)
tree9dbc383bf66cf9881a9b22d2437545740e26f7c1 /application/PluginManager.php
parent893338f0d407a0989454d5e3c0e43c97f7eface5 (diff)
parentdea0ba28f950867532eae572e7bcda49e81bbcf0 (diff)
downloadShaarli-53603f582300fc2709932b62652a5acfed088910.tar.gz
Shaarli-53603f582300fc2709932b62652a5acfed088910.tar.zst
Shaarli-53603f582300fc2709932b62652a5acfed088910.zip
Merge pull request #388 from ArthurHoaro/pluginadmin
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/**