X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=plugins%2Fdemo_plugin%2Fdemo_plugin.php;h=8ae1b47969e15dafa1b142c68e98aaf19d8813b4;hb=2a891ca6b19b021550ebb9b9fb610d0c4baf82c4;hp=8fdbf66383c144226770cc03334701801e7f5da8;hpb=9cf93bcfc53c36e0dd59fcfc717ac483ee74b35a;p=github%2Fshaarli%2FShaarli.git diff --git a/plugins/demo_plugin/demo_plugin.php b/plugins/demo_plugin/demo_plugin.php index 8fdbf663..8ae1b479 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\Router; + +/** + * 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 @@ -47,7 +75,6 @@ function hook_demo_plugin_render_header($data) { // Only execute when linklist is rendered. if ($data['_PAGE_'] == Router::$PAGE_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'][] = '
'. demo_plugin_t('Shaarli is now enhanced by the awesome demo_plugin.'); // Free elements at the end of the page. $data['endofpage'][] = '' . @@ -250,7 +277,7 @@ function hook_demo_plugin_render_editlink($data) // Load HTML into a string $html = file_get_contents(PluginManager::$PLUGINS_PATH .'/demo_plugin/field.html'); - // replace value in HTML if it exists in $data + // Replace value in HTML if it exists in $data if (!empty($data['link']['stuff'])) { $html = sprintf($html, $data['link']['stuff']); } else { @@ -297,9 +324,7 @@ function hook_demo_plugin_render_tools($data) */ function hook_demo_plugin_render_picwall($data) { - // plugin_start_zone $data['plugin_start_zone'][] = '
BEFORE
'; - // plugin_end_zone $data['plugin_end_zone'][] = '
AFTER
'; return $data; @@ -321,9 +346,7 @@ function hook_demo_plugin_render_picwall($data) */ function hook_demo_plugin_render_tagcloud($data) { - // plugin_start_zone $data['plugin_start_zone'][] = '
BEFORE
'; - // plugin_end_zone $data['plugin_end_zone'][] = '
AFTER
'; return $data; @@ -345,24 +368,18 @@ function hook_demo_plugin_render_tagcloud($data) */ function hook_demo_plugin_render_daily($data) { - // plugin_start_zone $data['plugin_start_zone'][] = '
BEFORE
'; - // plugin_end_zone $data['plugin_end_zone'][] = '
AFTER
'; // Manipulate columns data - foreach ($data['cols'] as &$value) { - foreach ($value as &$value2) { - $value2['formatedDescription'] .= ' ಠ_ಠ'; - } + foreach ($data['linksToDisplay'] as &$value) { + $value['formatedDescription'] .= ' ಠ_ಠ'; } // Add plugin content at the end of each link - foreach ($data['cols'] as &$value) { - foreach ($value as &$value2) { - $value2['link_plugin'][] = 'DEMO'; - } + foreach ($data['linksToDisplay'] as &$value) { + $value['link_plugin'][] = 'DEMO'; } return $data; @@ -426,10 +443,38 @@ function hook_demo_plugin_render_feed($data) foreach ($data['links'] as &$link) { if ($data['_PAGE_'] == Router::$PAGE_FEED_ATOM) { $link['description'] .= ' - ATOM Feed' ; - } - elseif ($data['_PAGE_'] == Router::$PAGE_FEED_RSS) { + } elseif ($data['_PAGE_'] == Router::$PAGE_FEED_RSS) { $link['description'] .= ' - RSS Feed'; } } return $data; } + +/** + * When plugin parameters are saved. + * + * @param array $data $_POST array + * + * @return array Updated $_POST array + */ +function hook_demo_plugin_save_plugin_parameters($data) +{ + // Here we edit the provided value. + // This hook can also be used to generate config files, etc. + if (! empty($data['DEMO_PLUGIN_PARAMETER']) && ! endsWith($data['DEMO_PLUGIN_PARAMETER'], '_SUFFIX')) { + $data['DEMO_PLUGIN_PARAMETER'] .= '_SUFFIX'; + } + + return $data; +} + +/** + * This function is never called, but contains translation calls for GNU gettext extraction. + */ +function demo_dummy_translation() +{ + // meta + t('A demo plugin covering all use cases for template designers and plugin developers.'); + t('This is a parameter dedicated to the demo plugin. It\'ll be suffixed.'); + t('Other demo parameter'); +}