X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2Fplugin%2FPluginManager.php;h=da66dea3952ad3cb0086a4594858f392f3270ba0;hb=3adbdc2a83e6b77a4ca62094c5d857524e39d211;hp=b3e8b2f8e28c0ebdd9def9e8d7f8df00c7f4e903;hpb=9fbc42294e7667c5ef19cafa0d1fcfbc1c0f36a9;p=github%2Fshaarli%2FShaarli.git diff --git a/application/plugin/PluginManager.php b/application/plugin/PluginManager.php index b3e8b2f8..da66dea3 100644 --- a/application/plugin/PluginManager.php +++ b/application/plugin/PluginManager.php @@ -100,25 +100,36 @@ class PluginManager */ public function executeHooks($hook, &$data, $params = array()) { - if (!empty($params['target'])) { - $data['_PAGE_'] = $params['target']; - } - - if (isset($params['loggedin'])) { - $data['_LOGGEDIN_'] = $params['loggedin']; - } - - if (isset($params['basePath'])) { - $data['_BASE_PATH_'] = $params['basePath']; + $metadataParameters = [ + 'target' => '_PAGE_', + 'loggedin' => '_LOGGEDIN_', + 'basePath' => '_BASE_PATH_', + 'rootPath' => '_ROOT_PATH_', + 'bookmarkService' => '_BOOKMARK_SERVICE_', + ]; + + foreach ($metadataParameters as $parameter => $metaKey) { + if (array_key_exists($parameter, $params)) { + $data[$metaKey] = $params[$parameter]; + } } foreach ($this->loadedPlugins as $plugin) { $hookFunction = $this->buildHookName($hook, $plugin); if (function_exists($hookFunction)) { - $data = call_user_func($hookFunction, $data, $this->conf); + try { + $data = call_user_func($hookFunction, $data, $this->conf); + } catch (\Throwable $e) { + $error = $plugin . t(' [plugin incompatibility]: ') . $e->getMessage(); + $this->errors = array_unique(array_merge($this->errors, [$error])); + } } } + + foreach ($metadataParameters as $metaKey) { + unset($data[$metaKey]); + } } /**