aboutsummaryrefslogtreecommitdiffhomepage
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/qrcode/qrcode.css23
-rw-r--r--plugins/qrcode/qrcode.html8
-rw-r--r--plugins/qrcode/qrcode.php22
-rw-r--r--plugins/qrcode/shaarli-qrcode.js10
-rw-r--r--plugins/wallabag/README.md25
-rw-r--r--plugins/wallabag/WallabagInstance.php71
-rw-r--r--plugins/wallabag/config.php.dist3
-rw-r--r--plugins/wallabag/wallabag.html2
-rw-r--r--plugins/wallabag/wallabag.php17
9 files changed, 165 insertions, 16 deletions
diff --git a/plugins/qrcode/qrcode.css b/plugins/qrcode/qrcode.css
new file mode 100644
index 00000000..0d514a0e
--- /dev/null
+++ b/plugins/qrcode/qrcode.css
@@ -0,0 +1,23 @@
1.linkqrcode {
2 display: inline;
3 position: relative;
4}
5
6#permalinkQrcode {
7 position: absolute;
8 z-index: 200;
9 padding: 20px;
10 width: 220px;
11 height: 220px;
12 background-color: #ffffff;
13 border: 1px solid black;
14 top: -110px;
15 left: -110px;
16 text-align: center;
17 font-size: 8pt;
18 box-shadow: 2px 2px 20px 2px #333333;
19}
20
21#permalinkQrcode img {
22 margin-bottom: 5px;
23}
diff --git a/plugins/qrcode/qrcode.html b/plugins/qrcode/qrcode.html
index 58ac5007..ffdaf3b8 100644
--- a/plugins/qrcode/qrcode.html
+++ b/plugins/qrcode/qrcode.html
@@ -1,3 +1,5 @@
1<a href="http://qrfree.kaywa.com/?l=1&amp;s=8&amp;d=%s" onclick="showQrCode(this); return false;" class="qrcode" data-permalink="%s"> 1<div class="linkqrcode">
2 <img src="%s/qrcode/qrcode.png" width="13" height="13" title="QR-Code"> 2 <a href="http://qrfree.kaywa.com/?l=1&amp;s=8&amp;d=%s" onclick="showQrCode(this); return false;" class="qrcode" data-permalink="%s">
3</a> 3 <img src="%s/qrcode/qrcode.png" width="13" height="13" title="QR-Code">
4 </a>
5</div>
diff --git a/plugins/qrcode/qrcode.php b/plugins/qrcode/qrcode.php
index 5f6e76a2..8bc610d1 100644
--- a/plugins/qrcode/qrcode.php
+++ b/plugins/qrcode/qrcode.php
@@ -17,7 +17,11 @@ function hook_qrcode_render_linklist($data)
17 $qrcode_html = file_get_contents(PluginManager::$PLUGINS_PATH . '/qrcode/qrcode.html'); 17 $qrcode_html = file_get_contents(PluginManager::$PLUGINS_PATH . '/qrcode/qrcode.html');
18 18
19 foreach ($data['links'] as &$value) { 19 foreach ($data['links'] as &$value) {
20 $qrcode = sprintf($qrcode_html, $value['real_url'], $value['real_url'], PluginManager::$PLUGINS_PATH); 20 $qrcode = sprintf($qrcode_html,
21 urlencode($value['url']),
22 $value['url'],
23 PluginManager::$PLUGINS_PATH
24 );
21 $value['link_plugin'][] = $qrcode; 25 $value['link_plugin'][] = $qrcode;
22 } 26 }
23 27
@@ -39,3 +43,19 @@ function hook_qrcode_render_footer($data)
39 43
40 return $data; 44 return $data;
41} 45}
46
47/**
48 * When linklist is displayed, include qrcode CSS file.
49 *
50 * @param array $data - header data.
51 *
52 * @return mixed - header data with qrcode CSS file added.
53 */
54function hook_qrcode_render_includes($data)
55{
56 if ($data['_PAGE_'] == Router::$PAGE_LINKLIST) {
57 $data['css_files'][] = PluginManager::$PLUGINS_PATH . '/qrcode/qrcode.css';
58 }
59
60 return $data;
61}
diff --git a/plugins/qrcode/shaarli-qrcode.js b/plugins/qrcode/shaarli-qrcode.js
index 0a8de21d..615f54c7 100644
--- a/plugins/qrcode/shaarli-qrcode.js
+++ b/plugins/qrcode/shaarli-qrcode.js
@@ -19,7 +19,7 @@ function showQrCode(caller,loading)
19 19
20 // Build the div which contains the QR-Code: 20 // Build the div which contains the QR-Code:
21 var element = document.createElement('div'); 21 var element = document.createElement('div');
22 element.id="permalinkQrcode"; 22 element.id = 'permalinkQrcode';
23 23
24 // Make QR-Code div commit sepuku when clicked: 24 // Make QR-Code div commit sepuku when clicked:
25 if ( element.attachEvent ){ 25 if ( element.attachEvent ){
@@ -37,6 +37,12 @@ function showQrCode(caller,loading)
37 element.appendChild(image); 37 element.appendChild(image);
38 element.innerHTML += "<br>Click to close"; 38 element.innerHTML += "<br>Click to close";
39 caller.parentNode.appendChild(element); 39 caller.parentNode.appendChild(element);
40
41 // Show the QRCode
42 qrcodeImage = document.getElementById('permalinkQrcode');
43 // Workaround to deal with newly created element lag for transition.
44 window.getComputedStyle(qrcodeImage).opacity;
45 qrcodeImage.className = 'show';
40 } 46 }
41 else 47 else
42 { 48 {
@@ -48,7 +54,7 @@ function showQrCode(caller,loading)
48// Remove any displayed QR-Code 54// Remove any displayed QR-Code
49function removeQrcode() 55function removeQrcode()
50{ 56{
51 var elem = document.getElementById("permalinkQrcode"); 57 var elem = document.getElementById('permalinkQrcode');
52 if (elem) { 58 if (elem) {
53 elem.parentNode.removeChild(elem); 59 elem.parentNode.removeChild(elem);
54 } 60 }
diff --git a/plugins/wallabag/README.md b/plugins/wallabag/README.md
index 08e0d44a..5bc35be1 100644
--- a/plugins/wallabag/README.md
+++ b/plugins/wallabag/README.md
@@ -2,7 +2,8 @@
2 2
3For each link in your Shaarli, adds a button to save the target page in your [wallabag](https://www.wallabag.org/). 3For each link in your Shaarli, adds a button to save the target page in your [wallabag](https://www.wallabag.org/).
4 4
5### Installation/configuration 5### Installation
6
6Clone this repository inside your `tpl/plugins/` directory, or download the archive and unpack it there. 7Clone this repository inside your `tpl/plugins/` directory, or download the archive and unpack it there.
7The directory structure should look like: 8The directory structure should look like:
8 9
@@ -11,19 +12,31 @@ The directory structure should look like:
11 └── plugins 12 └── plugins
12    └── wallabag 13    └── wallabag
13    ├── README.md 14    ├── README.md
15 ├── config.php.dist
14    ├── wallabag.html 16    ├── wallabag.html
17    ├── wallabag.php
15    └── wallabag.png 18    └── wallabag.png
16``` 19```
17 20
18To enable the plugin, add `'wallabag'` to your list of enabled plugins in `data/options.php` (`PLUGINS` array) 21To enable the plugin, add `'wallabag'` to your list of enabled plugins in `data/options.php` (`PLUGINS` array).
19. This should look like: 22This should look like:
20 23
21``` 24```
22$GLOBALS['config']['PLUGINS'] = array('qrcode', 'any_other_plugin', 'wallabag') 25$GLOBALS['config']['PLUGINS'] = array('qrcode', 'any_other_plugin', 'wallabag')
23``` 26```
24 27
25Then, set the `WALLABAG_URL` variable in `data/options.php` pointing to your wallabag URL. Example: 28### Configuration
29
30Copy `config.php.dist` into `config.php` and setup your instance.
26 31
32*Wallabag instance URL*
27``` 33```
28$GLOBALS['config']['WALLABAG_URL'] = 'http://demo.wallabag.org' ; //Base URL of your wallabag installation 34$GLOBALS['config']['WALLABAG_URL'] = 'http://v2.wallabag.org' ;
29``` \ No newline at end of file 35```
36
37*Wallabag version*: either `1` (for 1.x) or `2` (for 2.x)
38```
39$GLOBALS['config']['WALLABAG_VERSION'] = 2;
40```
41
42> Note: these settings can also be set in `data/config.php`. \ No newline at end of file
diff --git a/plugins/wallabag/WallabagInstance.php b/plugins/wallabag/WallabagInstance.php
new file mode 100644
index 00000000..72cc2e5e
--- /dev/null
+++ b/plugins/wallabag/WallabagInstance.php
@@ -0,0 +1,71 @@
1<?php
2
3/**
4 * Class WallabagInstance.
5 */
6class WallabagInstance
7{
8 /**
9 * @var array Static reference to differrent WB API versions.
10 * - key: version ID, must match plugin settings.
11 * - value: version name.
12 */
13 private static $wallabagVersions = array(
14 1 => '1.x',
15 2 => '2.x',
16 );
17
18 /**
19 * @var array Static reference to WB endpoint according to the API version.
20 * - key: version name.
21 * - value: endpoint.
22 */
23 private static $wallabagEndpoints = array(
24 '1.x' => '?plainurl=',
25 '2.x' => 'bookmarklet?url=',
26 );
27
28 /**
29 * @var string Wallabag user instance URL.
30 */
31 private $instanceUrl;
32
33 /**
34 * @var string Wallabag user instance API version.
35 */
36 private $apiVersion;
37
38 function __construct($instance, $version)
39 {
40 if ($this->isVersionAllowed($version)) {
41 $this->apiVersion = self::$wallabagVersions[$version];
42 } else {
43 // Default API version: 1.x.
44 $this->apiVersion = self::$wallabagVersions[1];
45 }
46
47 $this->instanceUrl = add_trailing_slash($instance);
48 }
49
50 /**
51 * Build the Wallabag URL to reach from instance URL and API version endpoint.
52 *
53 * @return string wallabag url.
54 */
55 public function getWallabagUrl()
56 {
57 return $this->instanceUrl . self::$wallabagEndpoints[$this->apiVersion];
58 }
59
60 /**
61 * Checks version configuration.
62 *
63 * @param mixed $version given version ID.
64 *
65 * @return bool true if it's valid, false otherwise.
66 */
67 private function isVersionAllowed($version)
68 {
69 return isset(self::$wallabagVersions[$version]);
70 }
71}
diff --git a/plugins/wallabag/config.php.dist b/plugins/wallabag/config.php.dist
index 7cf0d303..a602708f 100644
--- a/plugins/wallabag/config.php.dist
+++ b/plugins/wallabag/config.php.dist
@@ -1,3 +1,4 @@
1<?php 1<?php
2 2
3$GLOBALS['plugins']['WALLABAG_URL'] = 'https://demo.wallabag.org/'; \ No newline at end of file 3$GLOBALS['plugins']['WALLABAG_URL'] = 'https://demo.wallabag.org';
4$GLOBALS['plugins']['WALLABAG_VERSION'] = 1; \ No newline at end of file
diff --git a/plugins/wallabag/wallabag.html b/plugins/wallabag/wallabag.html
index ddcf8126..d0382adc 100644
--- a/plugins/wallabag/wallabag.html
+++ b/plugins/wallabag/wallabag.html
@@ -1 +1 @@
<span><a href="%s/?plainurl=%s" target="_blank"><img width="13" height="13" src="%s/wallabag/wallabag.png" title="Save to wallabag" /></a></span> <span><a href="%s%s" target="_blank"><img width="13" height="13" src="%s/wallabag/wallabag.png" title="Save to wallabag" /></a></span>
diff --git a/plugins/wallabag/wallabag.php b/plugins/wallabag/wallabag.php
index 37969c97..e3c399a9 100644
--- a/plugins/wallabag/wallabag.php
+++ b/plugins/wallabag/wallabag.php
@@ -4,6 +4,8 @@
4 * Plugin Wallabag. 4 * Plugin Wallabag.
5 */ 5 */
6 6
7require_once 'WallabagInstance.php';
8
7// don't raise unnecessary warnings 9// don't raise unnecessary warnings
8if (is_file(PluginManager::$PLUGINS_PATH . '/wallabag/config.php')) { 10if (is_file(PluginManager::$PLUGINS_PATH . '/wallabag/config.php')) {
9 include PluginManager::$PLUGINS_PATH . '/wallabag/config.php'; 11 include PluginManager::$PLUGINS_PATH . '/wallabag/config.php';
@@ -28,12 +30,23 @@ function hook_wallabag_render_linklist($data)
28 return $data; 30 return $data;
29 } 31 }
30 32
31 $wallabag_html = file_get_contents(PluginManager::$PLUGINS_PATH . '/wallabag/wallabag.html'); 33 $version = isset($GLOBALS['plugins']['WALLABAG_VERSION'])
34 ? $GLOBALS['plugins']['WALLABAG_VERSION']
35 : '';
36 $wallabagInstance = new WallabagInstance($GLOBALS['plugins']['WALLABAG_URL'], $version);
37
38 $wallabagHtml = file_get_contents(PluginManager::$PLUGINS_PATH . '/wallabag/wallabag.html');
32 39
33 foreach ($data['links'] as &$value) { 40 foreach ($data['links'] as &$value) {
34 $wallabag = sprintf($wallabag_html, $GLOBALS['plugins']['WALLABAG_URL'], $value['url'], PluginManager::$PLUGINS_PATH); 41 $wallabag = sprintf(
42 $wallabagHtml,
43 $wallabagInstance->getWallabagUrl(),
44 urlencode($value['url']),
45 PluginManager::$PLUGINS_PATH
46 );
35 $value['link_plugin'][] = $wallabag; 47 $value['link_plugin'][] = $wallabag;
36 } 48 }
37 49
38 return $data; 50 return $data;
39} 51}
52