Inject ROOT_PATH in plugin instead of regenerating it everywhere
This commit is contained in:
parent
7f5250421b
commit
3adbdc2a83
7 changed files with 14 additions and 9 deletions
|
@ -106,6 +106,7 @@ protected function buildPluginParameters(?string $template): array
|
|||
'target' => $template,
|
||||
'loggedin' => $this->container->loginManager->isLoggedIn(),
|
||||
'basePath' => $this->container->basePath,
|
||||
'rootPath' => preg_replace('#/index\.php$#', '', $this->container->basePath),
|
||||
'bookmarkService' => $this->container->bookmarkService
|
||||
];
|
||||
}
|
||||
|
|
|
@ -104,6 +104,7 @@ public function executeHooks($hook, &$data, $params = array())
|
|||
'target' => '_PAGE_',
|
||||
'loggedin' => '_LOGGEDIN_',
|
||||
'basePath' => '_BASE_PATH_',
|
||||
'rootPath' => '_ROOT_PATH_',
|
||||
'bookmarkService' => '_BOOKMARK_SERVICE_',
|
||||
];
|
||||
|
||||
|
|
|
@ -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!
|
||||
|
||||
|
|
|
@ -17,8 +17,7 @@
|
|||
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/');
|
||||
|
|
|
@ -54,7 +54,7 @@ function hook_isso_render_linklist($data, $conf)
|
|||
if ($conf->get('resource.theme') === 'default') {
|
||||
$button .= '<i class="linklist-plugin-icon fa fa-comment"></i>';
|
||||
} else {
|
||||
$button .= '<img class="linklist-plugin-icon" src="plugins/isso/comment.png" ';
|
||||
$button .= '<img class="linklist-plugin-icon" src="'. $data['_ROOT_PATH_'].'/plugins/isso/comment.png" ';
|
||||
$button .= 'title="Comment on this shaare" alt="Comments" />';
|
||||
}
|
||||
$button .= '</a></span>';
|
||||
|
|
|
@ -19,8 +19,7 @@ function hook_qrcode_render_linklist($data)
|
|||
{
|
||||
$qrcode_html = file_get_contents(PluginManager::$PLUGINS_PATH . '/qrcode/qrcode.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) {
|
||||
$qrcode = sprintf(
|
||||
$qrcode_html,
|
||||
|
|
|
@ -45,7 +45,7 @@ function hook_wallabag_render_linklist($data, $conf)
|
|||
$wallabagHtml = file_get_contents(PluginManager::$PLUGINS_PATH . '/wallabag/wallabag.html');
|
||||
|
||||
$linkTitle = t('Save to wallabag');
|
||||
$path = ($data['_BASE_PATH_'] ?? '') . '/' . PluginManager::$PLUGINS_PATH;
|
||||
$path = ($data['_ROOT_PATH_'] ?? '') . '/' . PluginManager::$PLUGINS_PATH;
|
||||
|
||||
foreach ($data['links'] as &$value) {
|
||||
$wallabag = sprintf(
|
||||
|
|
Loading…
Reference in a new issue