Skip to content

Commit

Permalink
Fix plugin base path in core plugins
Browse files Browse the repository at this point in the history
Also fix note check in archiveorg plugin, and regression on vintage template.
Documentation regarding relative path has been added.

Fixes shaarli#1548
  • Loading branch information
ArthurHoaro committed Sep 22, 2020
1 parent 0d93045 commit 0873cf9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
14 changes: 14 additions & 0 deletions doc/md/dev/Plugin-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,20 @@ Each file contain two keys:

> Note: In PHP, `parse_ini_file()` seems to want strings to be between by quotes `"` in the ini file.
### Understanding relative paths

Because Shaarli is a self-hosted tool, an instance can either be installed at the root directory, or under a subfolder.
This means that you can *never* use absolute paths (eg `/plugins/mything/file.png`).

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`.

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.

### It's not working!

Expand Down
6 changes: 4 additions & 2 deletions plugins/archiveorg/archiveorg.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ function hook_archiveorg_render_linklist($data)
$path = ($data['_BASE_PATH_'] ?? '') . '/' . PluginManager::$PLUGINS_PATH;

foreach ($data['links'] as &$value) {
if ($value['private'] && preg_match('/^\?[a-zA-Z0-9-_@]{6}($|&|#)/', $value['real_url'])) {
$isNote = startsWith($value['real_url'], '/shaare/');
if ($value['private'] && $isNote) {
continue;
}
$archive = sprintf($archive_html, $value['url'], $path, t('View on archive.org'));
$url = $isNote ? rtrim(index_url($_SERVER), '/') . $value['real_url'] : $value['real_url'];
$archive = sprintf($archive_html, $url, $path, t('View on archive.org'));
$value['link_plugin'][] = $archive;
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/isso/isso.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function hook_isso_render_linklist($data, $conf)
$isso = sprintf($issoHtml, $issoUrl, $issoUrl, $link['id'], $link['id']);
$data['plugin_end_zone'][] = $isso;
} else {
$button = '<span><a href="?%s#isso-thread">';
$button = '<span><a href="'. $data['_BASE_PATH_'] .'/shaare/%s#isso-thread">';
// For the default theme we use a FontAwesome icon which is better than an image
if ($conf->get('resource.theme') === 'default') {
$button .= '<i class="linklist-plugin-icon fa fa-comment"></i>';
Expand Down
4 changes: 2 additions & 2 deletions plugins/qrcode/qrcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function hook_qrcode_render_linklist($data)
function hook_qrcode_render_footer($data)
{
if ($data['_PAGE_'] == TemplatePage::LINKLIST) {
$data['js_files'][] = ($data['_BASE_PATH_'] ?? '') . '/' . PluginManager::$PLUGINS_PATH . '/qrcode/shaarli-qrcode.js';
$data['js_files'][] = PluginManager::$PLUGINS_PATH . '/qrcode/shaarli-qrcode.js';
}

return $data;
Expand All @@ -58,7 +58,7 @@ function hook_qrcode_render_footer($data)
function hook_qrcode_render_includes($data)
{
if ($data['_PAGE_'] == TemplatePage::LINKLIST) {
$data['css_files'][] = ($data['_BASE_PATH_'] ?? '') . '/' . PluginManager::$PLUGINS_PATH . '/qrcode/qrcode.css';
$data['css_files'][] = PluginManager::$PLUGINS_PATH . '/qrcode/qrcode.css';
}

return $data;
Expand Down
2 changes: 1 addition & 1 deletion tpl/vintage/linklist.paging.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
</form>
</div>
{if="$previous_page_url"} <a href="{$previous_page_url}" class="paging_older">&#x25C4;Older</a> {/if}
<div class="paging_current">page {$page_current} / {$page_max} </div>
{if="$page_max>1"}<div class="paging_current">page {$page_current} / {$page_max} </div>{/if}
{if="$next_page_url"} <a href="{$next_page_url}" class="paging_newer">Newer&#x25BA;</a> {/if}
</div>

0 comments on commit 0873cf9

Please sign in to comment.