]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - plugins/demo_plugin/demo_plugin.php
lint: apply phpcbf to plugins/
[github/shaarli/Shaarli.git] / plugins / demo_plugin / demo_plugin.php
index 8fdbf66383c144226770cc03334701801e7f5da8..bdbc719bc778c98c4a2396e8dc1049ecc20a26eb 100644 (file)
  * and check user status with _LOGGEDIN_.
  */
 
+use Shaarli\Config\ConfigManager;
+
+/**
+ * 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,6 +47,12 @@ 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;
 }
@@ -47,7 +73,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) {
             /*
@@ -160,7 +185,7 @@ 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.';
+    $data['text'][] = '<br>'. demo_plugin_t('Shaarli is now enhanced by the awesome demo_plugin.');
 
     // Free elements at the end of the page.
     $data['endofpage'][] = '<marquee id="demo_marquee">' .
@@ -352,17 +377,13 @@ function hook_demo_plugin_render_daily($data)
 
 
     // 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 +447,18 @@ 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;
 }
+
+/**
+ * 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.');
+}