From 7f5250421be4832b9679d8140bc4a71c8005dfa3 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Fri, 16 Oct 2020 12:47:11 +0200 Subject: Support using Shaarli without URL rewriting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Shaarli can be fully used by prefixing any URL with /index.php/ - {$base_path} used in templates already works with this configuration - Assets path (outside of theme's assets) must be prefixed with {$root_url}/ - Documentation section in « Server configuration » Fixes #1590 --- plugins/archiveorg/archiveorg.php | 3 ++- plugins/qrcode/qrcode.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'plugins') diff --git a/plugins/archiveorg/archiveorg.php b/plugins/archiveorg/archiveorg.php index 922b5966..a7b595e1 100644 --- a/plugins/archiveorg/archiveorg.php +++ b/plugins/archiveorg/archiveorg.php @@ -17,7 +17,8 @@ use Shaarli\Plugin\PluginManager; function hook_archiveorg_render_linklist($data) { $archive_html = file_get_contents(PluginManager::$PLUGINS_PATH . '/archiveorg/archiveorg.html'); - $path = ($data['_BASE_PATH_'] ?? '') . '/' . PluginManager::$PLUGINS_PATH; + $rootPath = preg_replace('#/index\.php$#', '', $data['_BASE_PATH_'] ?? ''); + $path = $rootPath . '/' . PluginManager::$PLUGINS_PATH; foreach ($data['links'] as &$value) { $isNote = startsWith($value['real_url'], '/shaare/'); diff --git a/plugins/qrcode/qrcode.php b/plugins/qrcode/qrcode.php index 95499e39..45712859 100644 --- a/plugins/qrcode/qrcode.php +++ b/plugins/qrcode/qrcode.php @@ -19,7 +19,8 @@ function hook_qrcode_render_linklist($data) { $qrcode_html = file_get_contents(PluginManager::$PLUGINS_PATH . '/qrcode/qrcode.html'); - $path = ($data['_BASE_PATH_'] ?? '') . '/' . PluginManager::$PLUGINS_PATH; + $rootPath = preg_replace('#/index\.php$#', '', $data['_BASE_PATH_'] ?? ''); + $path = $rootPath . '/' . PluginManager::$PLUGINS_PATH; foreach ($data['links'] as &$value) { $qrcode = sprintf( $qrcode_html, -- cgit v1.2.3 From 3adbdc2a83e6b77a4ca62094c5d857524e39d211 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Fri, 16 Oct 2020 13:06:06 +0200 Subject: Inject ROOT_PATH in plugin instead of regenerating it everywhere --- plugins/archiveorg/archiveorg.php | 3 +-- plugins/isso/isso.php | 2 +- plugins/qrcode/qrcode.php | 3 +-- plugins/wallabag/wallabag.php | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) (limited to 'plugins') 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 .= ' Date: Sat, 24 Oct 2020 16:25:06 +0200 Subject: Plugin wallabag: minor improvements - hide the wallabag icon for logged out users - set API V2 as default parameter - fix URL encoding issue with special chars Fixes #1147 --- plugins/wallabag/wallabag.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'plugins') diff --git a/plugins/wallabag/wallabag.php b/plugins/wallabag/wallabag.php index d0df3501..8cd3f4ad 100644 --- a/plugins/wallabag/wallabag.php +++ b/plugins/wallabag/wallabag.php @@ -22,6 +22,7 @@ function wallabag_init($conf) 'Please define the "WALLABAG_URL" setting in the plugin administration page.'); return array($error); } + $conf->setEmpty('plugins.WALLABAG_URL', '2'); } /** @@ -35,7 +36,7 @@ function wallabag_init($conf) function hook_wallabag_render_linklist($data, $conf) { $wallabagUrl = $conf->get('plugins.WALLABAG_URL'); - if (empty($wallabagUrl)) { + if (empty($wallabagUrl) || !$data['_LOGGEDIN_']) { return $data; } @@ -51,7 +52,7 @@ function hook_wallabag_render_linklist($data, $conf) $wallabag = sprintf( $wallabagHtml, $wallabagInstance->getWallabagUrl(), - urlencode($value['url']), + urlencode(unescape($value['url'])), $path, $linkTitle ); -- cgit v1.2.3 From 53054b2bf6a919fd4ff9b44b6ad1986f21f488b6 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 22 Sep 2020 20:25:47 +0200 Subject: Apply PHP Code Beautifier on source code for linter automatic fixes --- plugins/addlink_toolbar/addlink_toolbar.php | 20 ++++++------- plugins/archiveorg/archiveorg.php | 1 + plugins/default_colors/default_colors.php | 12 ++++---- plugins/demo_plugin/demo_plugin.php | 45 +++++++++++++++-------------- plugins/isso/isso.php | 8 ++--- plugins/piwik/piwik.php | 3 +- plugins/playvideos/playvideos.php | 11 +++---- plugins/pubsubhubbub/pubsubhubbub.php | 14 ++++----- plugins/qrcode/qrcode.php | 1 + plugins/wallabag/WallabagInstance.php | 9 +++--- plugins/wallabag/wallabag.php | 5 ++-- 11 files changed, 68 insertions(+), 61 deletions(-) (limited to 'plugins') diff --git a/plugins/addlink_toolbar/addlink_toolbar.php b/plugins/addlink_toolbar/addlink_toolbar.php index ab6ed6de..80b1dd95 100644 --- a/plugins/addlink_toolbar/addlink_toolbar.php +++ b/plugins/addlink_toolbar/addlink_toolbar.php @@ -17,26 +17,26 @@ use Shaarli\Render\TemplatePage; function hook_addlink_toolbar_render_header($data) { if ($data['_PAGE_'] == TemplatePage::LINKLIST && $data['_LOGGEDIN_'] === true) { - $form = array( - 'attr' => array( + $form = [ + 'attr' => [ 'method' => 'GET', 'action' => $data['_BASE_PATH_'] . '/admin/shaare', 'name' => 'addform', 'class' => 'addform', - ), - 'inputs' => array( - array( + ], + 'inputs' => [ + [ 'type' => 'text', 'name' => 'post', 'placeholder' => t('URI'), - ), - array( + ], + [ 'type' => 'submit', 'value' => t('Add link'), 'class' => 'bigbutton', - ), - ), - ); + ], + ], + ]; $data['fields_toolbar'][] = $form; } diff --git a/plugins/archiveorg/archiveorg.php b/plugins/archiveorg/archiveorg.php index ed271532..88f2b653 100644 --- a/plugins/archiveorg/archiveorg.php +++ b/plugins/archiveorg/archiveorg.php @@ -1,4 +1,5 @@ get('plugins.'. $placeholder, '')); + $value = trim($conf->get('plugins.' . $placeholder, '')); if (strlen($value) > 0) { $params[$placeholder] = $value; } } if (empty($params)) { - $error = t('Default colors plugin error: '. + $error = t('Default colors plugin error: ' . 'This plugin is active and no custom color is configured.'); return [$error]; } @@ -56,7 +56,7 @@ function default_colors_init($conf) function hook_default_colors_render_includes($data) { $file = PluginManager::$PLUGINS_PATH . '/default_colors/default_colors.css'; - if (file_exists($file )) { + if (file_exists($file)) { $data['css_files'][] = $file ; } @@ -75,7 +75,7 @@ function default_colors_generate_css_file($params): void $content = ''; foreach (DEFAULT_COLORS_PLACEHOLDERS as $rule) { $content .= !empty($params[$rule]) - ? default_colors_format_css_rule($params, $rule) .';'. PHP_EOL + ? default_colors_format_css_rule($params, $rule) . ';' . PHP_EOL : ''; } @@ -99,8 +99,8 @@ function default_colors_format_css_rule($data, $parameter) } $key = str_replace('DEFAULT_COLORS_', '', $parameter); - $key = str_replace('_', '-', strtolower($key)) .'-color'; - return ' --'. $key .': '. $data[$parameter]; + $key = str_replace('_', '-', strtolower($key)) . '-color'; + return ' --' . $key . ': ' . $data[$parameter]; } diff --git a/plugins/demo_plugin/demo_plugin.php b/plugins/demo_plugin/demo_plugin.php index defb01f7..22d27b68 100644 --- a/plugins/demo_plugin/demo_plugin.php +++ b/plugins/demo_plugin/demo_plugin.php @@ -1,4 +1,5 @@ array ( + $button = [ + 'attr' => [ 'href' => '#', 'class' => 'mybutton', 'title' => 'hover me', - ), + ], 'html' => 'DEMO buttons toolbar', - ); + ]; $data['buttons_toolbar'][] = $button; } @@ -115,29 +116,29 @@ function hook_demo_plugin_render_header($data) * * */ - $form = array( - 'attr' => array( + $form = [ + 'attr' => [ 'method' => 'GET', 'action' => $data['_BASE_PATH_'] . '/', 'class' => 'addform', - ), - 'inputs' => array( - array( + ], + 'inputs' => [ + [ 'type' => 'text', 'name' => 'demo', 'placeholder' => 'demo', - ) - ) - ); + ] + ] + ]; $data['fields_toolbar'][] = $form; } // Another button always displayed - $button = array( - 'attr' => array( + $button = [ + 'attr' => [ 'href' => '#', - ), + ], 'html' => 'Demo', - ); + ]; $data['buttons_toolbar'][] = $button; return $data; @@ -187,7 +188,7 @@ function hook_demo_plugin_render_includes($data) function hook_demo_plugin_render_footer($data) { // Footer text - $data['text'][] = '
'. demo_plugin_t('Shaarli is now enhanced by the awesome demo_plugin.'); + $data['text'][] = '
' . demo_plugin_t('Shaarli is now enhanced by the awesome demo_plugin.'); // Free elements at the end of the page. $data['endofpage'][] = '' . @@ -229,13 +230,13 @@ function hook_demo_plugin_render_linklist($data) * and a mandatory `html` key, which contains its value. * It's also recommended to add key 'on' or 'off' for theme rendering. */ - $action = array( - 'attr' => array( + $action = [ + 'attr' => [ 'href' => '?up', 'title' => 'Uppercase!', - ), + ], 'html' => '←', - ); + ]; if (isset($_GET['up'])) { // Manipulate link data @@ -275,7 +276,7 @@ function hook_demo_plugin_render_linklist($data) function hook_demo_plugin_render_editlink($data) { // Load HTML into a string - $html = file_get_contents(PluginManager::$PLUGINS_PATH .'/demo_plugin/field.html'); + $html = file_get_contents(PluginManager::$PLUGINS_PATH . '/demo_plugin/field.html'); // Replace value in HTML if it exists in $data if (!empty($data['link']['stuff'])) { diff --git a/plugins/isso/isso.php b/plugins/isso/isso.php index d4632163..a5450989 100644 --- a/plugins/isso/isso.php +++ b/plugins/isso/isso.php @@ -19,9 +19,9 @@ function isso_init($conf) { $issoUrl = $conf->get('plugins.ISSO_SERVER'); if (empty($issoUrl)) { - $error = t('Isso plugin error: '. + $error = t('Isso plugin error: ' . 'Please define the "ISSO_SERVER" setting in the plugin administration page.'); - return array($error); + return [$error]; } } @@ -49,12 +49,12 @@ function hook_isso_render_linklist($data, $conf) $isso = sprintf($issoHtml, $issoUrl, $issoUrl, $link['id'], $link['id']); $data['plugin_end_zone'][] = $isso; } else { - $button = ''; + $button = ''; // For the default theme we use a FontAwesome icon which is better than an image if ($conf->get('resource.theme') === 'default') { $button .= ''; } else { - $button .= ' array( + $playvideo = [ + 'attr' => [ 'href' => '#', 'title' => t('Video player'), 'id' => 'playvideos', - ), - 'html' => '► '. t('Play Videos') - ); + ], + 'html' => '► ' . t('Play Videos') + ]; $data['buttons_toolbar'][] = $playvideo; } diff --git a/plugins/pubsubhubbub/pubsubhubbub.php b/plugins/pubsubhubbub/pubsubhubbub.php index 8fe6799c..299b84fb 100644 --- a/plugins/pubsubhubbub/pubsubhubbub.php +++ b/plugins/pubsubhubbub/pubsubhubbub.php @@ -42,7 +42,7 @@ function pubsubhubbub_init($conf) function hook_pubsubhubbub_render_feed($data, $conf) { $feedType = $data['_PAGE_'] == TemplatePage::FEED_RSS ? FeedBuilder::$FEED_RSS : FeedBuilder::$FEED_ATOM; - $template = file_get_contents(PluginManager::$PLUGINS_PATH . '/pubsubhubbub/hub.'. $feedType .'.xml'); + $template = file_get_contents(PluginManager::$PLUGINS_PATH . '/pubsubhubbub/hub.' . $feedType . '.xml'); $data['feed_plugins_header'][] = sprintf($template, $conf->get('plugins.PUBSUBHUB_URL')); return $data; @@ -59,10 +59,10 @@ function hook_pubsubhubbub_render_feed($data, $conf) */ function hook_pubsubhubbub_save_link($data, $conf) { - $feeds = array( - index_url($_SERVER) .'feed/atom', - index_url($_SERVER) .'feed/rss', - ); + $feeds = [ + index_url($_SERVER) . 'feed/atom', + index_url($_SERVER) . 'feed/rss', + ]; $httpPost = function_exists('curl_version') ? false : 'nocurl_http_post'; try { @@ -87,11 +87,11 @@ function hook_pubsubhubbub_save_link($data, $conf) */ function nocurl_http_post($url, $postString) { - $params = array('http' => array( + $params = ['http' => [ 'method' => 'POST', 'content' => $postString, 'user_agent' => 'PubSubHubbub-Publisher-PHP/1.0', - )); + ]]; $context = stream_context_create($params); $fp = @fopen($url, 'rb', false, $context); diff --git a/plugins/qrcode/qrcode.php b/plugins/qrcode/qrcode.php index 24fd18ba..2ae10476 100644 --- a/plugins/qrcode/qrcode.php +++ b/plugins/qrcode/qrcode.php @@ -1,4 +1,5 @@ '1.x', 2 => '2.x', - ); + ]; /** * @var array Static reference to WB endpoint according to the API version. * - key: version name. * - value: endpoint. */ - private static $wallabagEndpoints = array( + private static $wallabagEndpoints = [ '1.x' => '?plainurl=', '2.x' => 'bookmarklet?url=', - ); + ]; /** * @var string Wallabag user instance URL. diff --git a/plugins/wallabag/wallabag.php b/plugins/wallabag/wallabag.php index 8cd3f4ad..f2003cb9 100644 --- a/plugins/wallabag/wallabag.php +++ b/plugins/wallabag/wallabag.php @@ -1,4 +1,5 @@ get('plugins.WALLABAG_URL'); if (empty($wallabagUrl)) { - $error = t('Wallabag plugin error: '. + $error = t('Wallabag plugin error: ' . 'Please define the "WALLABAG_URL" setting in the plugin administration page.'); - return array($error); + return [$error]; } $conf->setEmpty('plugins.WALLABAG_URL', '2'); } -- cgit v1.2.3