]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - plugins/qrcode/qrcode.php
namespacing: \Shaarli\Router
[github/shaarli/Shaarli.git] / plugins / qrcode / qrcode.php
index 5db409291c772e3ad811ed26eb9c199163e14b76..21908cee6817b33d1094651e9c58d7de910b260d 100644 (file)
@@ -1,11 +1,17 @@
 <?php
+/**
+ * Plugin qrcode
+ * Add QRCode containing URL for each links.
+ * Display a QRCode icon in link list.
+ */
 
-// TODO: Can't be tested in localhost
+use Shaarli\Router;
 
 /**
  * Add qrcode icon to link_plugin when rendering linklist.
  *
- * @param $data - linklist data.
+ * @param array $data - linklist data.
+ *
  * @return mixed - linklist data with qrcode plugin.
  */
 function hook_qrcode_render_linklist($data)
@@ -13,7 +19,12 @@ function hook_qrcode_render_linklist($data)
     $qrcode_html = file_get_contents(PluginManager::$PLUGINS_PATH . '/qrcode/qrcode.html');
 
     foreach ($data['links'] as &$value) {
-        $qrcode = sprintf($qrcode_html, $value['url'], $value['url'], PluginManager::$PLUGINS_PATH);
+        $qrcode = sprintf(
+            $qrcode_html,
+            urlencode($value['url']),
+            $value['url'],
+            PluginManager::$PLUGINS_PATH
+        );
         $value['link_plugin'][] = $qrcode;
     }
 
@@ -24,6 +35,7 @@ function hook_qrcode_render_linklist($data)
  * When linklist is displayed, include qrcode JS files.
  *
  * @param array $data - footer data.
+ *
  * @return mixed - footer data with qrcode JS files added.
  */
 function hook_qrcode_render_footer($data)
@@ -33,4 +45,29 @@ function hook_qrcode_render_footer($data)
     }
 
     return $data;
-}
\ No newline at end of file
+}
+
+/**
+ * When linklist is displayed, include qrcode CSS file.
+ *
+ * @param array $data - header data.
+ *
+ * @return mixed - header data with qrcode CSS file added.
+ */
+function hook_qrcode_render_includes($data)
+{
+    if ($data['_PAGE_'] == Router::$PAGE_LINKLIST) {
+        $data['css_files'][] = PluginManager::$PLUGINS_PATH . '/qrcode/qrcode.css';
+    }
+
+    return $data;
+}
+
+/**
+ * This function is never called, but contains translation calls for GNU gettext extraction.
+ */
+function qrcode_dummy_translation()
+{
+    // meta
+    t('For each link, add a QRCode icon.');
+}