X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=plugins%2Fdemo_plugin%2Fdemo_plugin.php;h=dd73d6a2129acd2be76a612a8b3c379f7e5bcd3f;hb=1a8ac737e52cb25a5c346232ee398f5908cee7d7;hp=3a90ae6a39a719459aae5147dec96ef0820e2f80;hpb=12266213d098a53c5f005b9afcbbe62771fd580c;p=github%2Fshaarli%2FShaarli.git diff --git a/plugins/demo_plugin/demo_plugin.php b/plugins/demo_plugin/demo_plugin.php index 3a90ae6a..dd73d6a2 100644 --- a/plugins/demo_plugin/demo_plugin.php +++ b/plugins/demo_plugin/demo_plugin.php @@ -2,8 +2,8 @@ /** * Demo Plugin. * - * This plugin try to cover Shaarli's plugin API entirely. - * Can be used by plugin developper to make their own. + * This plugin tries to completely cover Shaarli's plugin API. + * Can be used by plugin developers to make their own plugin. */ /* @@ -14,6 +14,28 @@ * and check user status with _LOGGEDIN_. */ +use Shaarli\Config\ConfigManager; +use Shaarli\Plugin\PluginManager; +use Shaarli\Render\TemplatePage; + +/** + * In the footer hook, there is a working example of a translation extension for Shaarli. + * + * The extension must be attached to a new translation domain (i.e. NOT 'shaarli'). + * Use case: any custom theme or non official plugin can use the translation system. + * + * See the documentation for more information. + */ +const EXT_TRANSLATION_DOMAIN = 'demo'; + +/* + * This is not necessary, but it's easier if you don't want Poedit to mix up your translations. + */ +function demo_plugin_t($text, $nText = '', $nb = 1) +{ + return t($text, $nText, $nb, EXT_TRANSLATION_DOMAIN); +} + /** * Initialization function. * It will be called when the plugin is loaded. @@ -27,13 +49,19 @@ function demo_plugin_init($conf) { $conf->get('toto', 'nope'); + if (! $conf->exists('translation.extensions.demo')) { + // Custom translation with the domain 'demo' + $conf->set('translation.extensions.demo', 'plugins/demo_plugin/languages/'); + $conf->write(true); + } + $errors[] = 'This a demo init error.'; return $errors; } /** * Hook render_header. - * Executed on every page redering. + * Executed on every page render. * * Template placeholders: * - buttons_toolbar @@ -46,8 +74,7 @@ function demo_plugin_init($conf) function hook_demo_plugin_render_header($data) { // Only execute when linklist is rendered. - if ($data['_PAGE_'] == Router::$PAGE_LINKLIST) { - + if ($data['_PAGE_'] == TemplatePage::LINKLIST) { // If loggedin if ($data['_LOGGEDIN_'] === true) { /* @@ -83,10 +110,10 @@ function hook_demo_plugin_render_header($data) * ], * ] * This example renders as: - *
+ * */ $form = array( 'attr' => array( @@ -118,7 +145,7 @@ function hook_demo_plugin_render_header($data) /** * Hook render_includes. - * Executed on every page redering. + * Executed on every page render. * * Template placeholders: * - css_files @@ -142,7 +169,7 @@ function hook_demo_plugin_render_includes($data) /** * Hook render_footer. - * Executed on every page redering. + * Executed on every page render. * * Template placeholders: * - text @@ -159,8 +186,8 @@ function hook_demo_plugin_render_includes($data) */ function hook_demo_plugin_render_footer($data) { - // footer text - $data['text'][] = 'Shaarli is now enhanced by the awesome demo_plugin.'; + // Footer text + $data['text'][] = '