diff --git a/README.md b/README.md index 5c0afe2..dcf658a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [Shaarli](https://github.com/shaarli/Shaarli) plugin to easily insert markdown syntax into the **Description** field when editing a link. -Tested on Shaarli 0.11.1 with the [Shaarli-Material](https://github.com/kalvn/Shaarli-Material) and the built-in [default](https://github.com/shaarli/Shaarli/tree/master/tpl/default) themes using desktop and Android Chrome browsers. +Tested on Shaarli 0.11.1 with the [Shaarli-Material](https://github.com/kalvn/Shaarli-Material) and the built-in [default](https://github.com/shaarli/Shaarli/tree/master/tpl/default) themes using desktop and Android Chrome browsers. Should be compatible with Shaarli 0.12.0-beta as well which introduced a major internal rewrite ([#1511](https://github.com/shaarli/Shaarli/pull/1511)). ## Features diff --git a/markdown_toolbar/markdown_toolbar.php b/markdown_toolbar/markdown_toolbar.php index 1519471..0b375a3 100755 --- a/markdown_toolbar/markdown_toolbar.php +++ b/markdown_toolbar/markdown_toolbar.php @@ -1,4 +1,5 @@ get('plugins.MD_TOOLBAR_LOCALE'); - if (empty($mdToolbarLocale) || ! in_array($mdToolbarLocale, $locales)) { + if (empty($mdToolbarLocale) || !in_array($mdToolbarLocale, $locales)) { $mdToolbarLocale = MD_TOOLBAR_DEFAULT_LOCALE; } @@ -44,7 +87,9 @@ function get_valid_locale($conf) { */ function hook_markdown_toolbar_render_includes($data) { - if ($data['_PAGE_'] == Router::$PAGE_EDITLINK) { + $router = mdtb_get_router(); + + if (mdtb_strip_underscores($data['_PAGE_']) == mdtb_strip_underscores($router::$PAGE_EDITLINK)) { $include_dir = PluginManager::$PLUGINS_PATH . '/markdown_toolbar/includes'; $data['css_files'][] = $include_dir . '/bootstrap/dist/css/bootstrap-pruned.min.css'; $data['css_files'][] = $include_dir . '/font_awesome/css/font-awesome.min.css'; @@ -57,24 +102,36 @@ function hook_markdown_toolbar_render_includes($data) /** * When editlink page is displayed, include markdown_toolbar JS files. * - * @param $data array footer data. - * @param $conf ConfigManager instance + * @param array $data - footer data. + * @param ConfigManager $conf - configmanager instance * * @return mixed - footer data with markdown_toolbar JS files added. */ function hook_markdown_toolbar_render_footer($data, $conf) { - if ( ! in_array($data['_PAGE_'], [Router::$PAGE_ADDLINK, Router::$PAGE_EDITLINK]) ) { + $router = mdtb_get_router(); + + if (!in_array( + mdtb_strip_underscores($data['_PAGE_']), + [ + mdtb_strip_underscores($router::$PAGE_ADDLINK), + mdtb_strip_underscores($router::$PAGE_EDITLINK) + ] + )) { return $data; } - $mdToolbarLocale = get_valid_locale($conf); - $mdToolbarAutofocus = ($data['_PAGE_'] == Router::$PAGE_ADDLINK) ? "true" : "false"; - // There is a bug in Router.php:L125-131 that is why the above condition is never true, the page is + if (mdtb_strip_underscores($data['_PAGE_']) == mdtb_strip_underscores($router::$PAGE_ADDLINK)) { + $mdToolbarAutofocus = "true"; + } else { + $mdToolbarAutofocus = "false"; + } + // There is a bug in (Legacy)Router::findPage() that is why the above condition is never true, the page is // always stated as editlink even if it is addlink. So I'm setting this to always true for now. - $mdToolbarAutofocus = "true"; + $mdToolbarAutofocus = "true"; + $mdToolbarLocale = mdtb_get_valid_locale($conf); - $html = file_get_contents(PluginManager::$PLUGINS_PATH .'/markdown_toolbar/markdown_toolbar.html'); + $html = file_get_contents(PluginManager::$PLUGINS_PATH . '/markdown_toolbar/markdown_toolbar.html'); $html = sprintf($html, $mdToolbarLocale, $mdToolbarAutofocus); $data['endofpage'][] = $html; @@ -82,7 +139,7 @@ function hook_markdown_toolbar_render_footer($data, $conf) $data['js_files'][] = $include_dir . '/jquery/jquery-3.2.1.min.js'; $data['js_files'][] = $include_dir . '/markdown_toolbar.js'; $data['js_files'][] = $include_dir . '/bootstrap_markdown/js/bootstrap-markdown.js'; - + if ($mdToolbarLocale != MD_TOOLBAR_DEFAULT_LOCALE) { $data['js_files'][] = $include_dir . '/bootstrap_markdown/locale/bootstrap-markdown.' . $mdToolbarLocale . '.js'; }