From: ArthurHoaro Date: Fri, 16 Oct 2020 11:06:06 +0000 (+0200) Subject: Inject ROOT_PATH in plugin instead of regenerating it everywhere X-Git-Tag: v0.12.1^2~36^2~1 X-Git-Url: https://git.immae.eu/?p=github%2Fshaarli%2FShaarli.git;a=commitdiff_plain;h=3adbdc2a83e6b77a4ca62094c5d857524e39d211 Inject ROOT_PATH in plugin instead of regenerating it everywhere --- diff --git a/application/front/controller/visitor/ShaarliVisitorController.php b/application/front/controller/visitor/ShaarliVisitorController.php index 55c075a2..54f9fe03 100644 --- a/application/front/controller/visitor/ShaarliVisitorController.php +++ b/application/front/controller/visitor/ShaarliVisitorController.php @@ -106,6 +106,7 @@ abstract class ShaarliVisitorController 'target' => $template, 'loggedin' => $this->container->loginManager->isLoggedIn(), 'basePath' => $this->container->basePath, + 'rootPath' => preg_replace('#/index\.php$#', '', $this->container->basePath), 'bookmarkService' => $this->container->bookmarkService ]; } diff --git a/application/plugin/PluginManager.php b/application/plugin/PluginManager.php index 1b2197c9..da66dea3 100644 --- a/application/plugin/PluginManager.php +++ b/application/plugin/PluginManager.php @@ -104,6 +104,7 @@ class PluginManager 'target' => '_PAGE_', 'loggedin' => '_LOGGEDIN_', 'basePath' => '_BASE_PATH_', + 'rootPath' => '_ROOT_PATH_', 'bookmarkService' => '_BOOKMARK_SERVICE_', ]; diff --git a/doc/md/dev/Plugin-system.md b/doc/md/dev/Plugin-system.md index c29774de..f09fadc2 100644 --- a/doc/md/dev/Plugin-system.md +++ b/doc/md/dev/Plugin-system.md @@ -148,11 +148,16 @@ If a file needs to be included in server end, use simple relative path: `PluginManager::$PLUGINS_PATH . '/mything/template.html'`. If it needs to be included in front end side (e.g. an image), -the relative path must be prefixed with special data `_BASE_PATH_`: -`($data['_BASE_PATH_'] ?? '') . '/' . PluginManager::$PLUGINS_PATH . '/mything/picture.png`. +the relative path must be prefixed with special data: + + * if it's a link that will need to be processed by Shaarli, use `_BASE_PATH_`: + for e.g. `$data['_BASE_PATH_'] . '/admin/tools`. + * if you want to include an asset, you need to add the root URL (base path without `/index.php`, for people using Shaarli without URL rewriting), then use `_ROOT_PATH_`: + for e.g +`$['_ROOT_PATH_'] . '/' . PluginManager::$PLUGINS_PATH . '/mything/picture.png`. Note that special placeholders for CSS and JS files (respectively `css_files` and `js_files`) are already prefixed -with the base path in template files. +with the root path in template files. ### It's not working! diff --git a/plugins/archiveorg/archiveorg.php b/plugins/archiveorg/archiveorg.php index a7b595e1..ed271532 100644 --- a/plugins/archiveorg/archiveorg.php +++ b/plugins/archiveorg/archiveorg.php @@ -17,8 +17,7 @@ use Shaarli\Plugin\PluginManager; function hook_archiveorg_render_linklist($data) { $archive_html = file_get_contents(PluginManager::$PLUGINS_PATH . '/archiveorg/archiveorg.html'); - $rootPath = preg_replace('#/index\.php$#', '', $data['_BASE_PATH_'] ?? ''); - $path = $rootPath . '/' . PluginManager::$PLUGINS_PATH; + $path = ($data['_ROOT_PATH_'] ?? '') . '/' . PluginManager::$PLUGINS_PATH; foreach ($data['links'] as &$value) { $isNote = startsWith($value['real_url'], '/shaare/'); diff --git a/plugins/isso/isso.php b/plugins/isso/isso.php index 79e7380b..d4632163 100644 --- a/plugins/isso/isso.php +++ b/plugins/isso/isso.php @@ -54,7 +54,7 @@ function hook_isso_render_linklist($data, $conf) if ($conf->get('resource.theme') === 'default') { $button .= ''; } else { - $button .= '