aboutsummaryrefslogtreecommitdiffhomepage
path: root/plugins/qrcode
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-07-26 14:43:10 +0200
committerArthurHoaro <arthur@hoa.ro>2020-07-26 14:43:10 +0200
commit9fbc42294e7667c5ef19cafa0d1fcfbc1c0f36a9 (patch)
tree9bfc3c9b185eb0c185d23146d44d42dd6685a4da /plugins/qrcode
parentbc583903adfd768f115fae438e4d9ed1043682d9 (diff)
downloadShaarli-9fbc42294e7667c5ef19cafa0d1fcfbc1c0f36a9.tar.gz
Shaarli-9fbc42294e7667c5ef19cafa0d1fcfbc1c0f36a9.tar.zst
Shaarli-9fbc42294e7667c5ef19cafa0d1fcfbc1c0f36a9.zip
New basePath: fix officiel plugin paths and vintage template
Diffstat (limited to 'plugins/qrcode')
-rw-r--r--plugins/qrcode/qrcode.php5
-rw-r--r--plugins/qrcode/shaarli-qrcode.js15
2 files changed, 11 insertions, 9 deletions
diff --git a/plugins/qrcode/qrcode.php b/plugins/qrcode/qrcode.php
index 2ec0cb65..3b5dae34 100644
--- a/plugins/qrcode/qrcode.php
+++ b/plugins/qrcode/qrcode.php
@@ -19,11 +19,12 @@ function hook_qrcode_render_linklist($data)
19{ 19{
20 $qrcode_html = file_get_contents(PluginManager::$PLUGINS_PATH . '/qrcode/qrcode.html'); 20 $qrcode_html = file_get_contents(PluginManager::$PLUGINS_PATH . '/qrcode/qrcode.html');
21 21
22 $path = ($data['_BASE_PATH_'] ?? '') . '/' . PluginManager::$PLUGINS_PATH;
22 foreach ($data['links'] as &$value) { 23 foreach ($data['links'] as &$value) {
23 $qrcode = sprintf( 24 $qrcode = sprintf(
24 $qrcode_html, 25 $qrcode_html,
25 $value['url'], 26 $value['url'],
26 PluginManager::$PLUGINS_PATH 27 $path
27 ); 28 );
28 $value['link_plugin'][] = $qrcode; 29 $value['link_plugin'][] = $qrcode;
29 } 30 }
@@ -41,7 +42,7 @@ function hook_qrcode_render_linklist($data)
41function hook_qrcode_render_footer($data) 42function hook_qrcode_render_footer($data)
42{ 43{
43 if ($data['_PAGE_'] == TemplatePage::LINKLIST) { 44 if ($data['_PAGE_'] == TemplatePage::LINKLIST) {
44 $data['js_files'][] = PluginManager::$PLUGINS_PATH . '/qrcode/shaarli-qrcode.js'; 45 $data['js_files'][] = PluginManager::$PLUGINS_PATH . '/qrcode/shaarli-qrcode.js';
45 } 46 }
46 47
47 return $data; 48 return $data;
diff --git a/plugins/qrcode/shaarli-qrcode.js b/plugins/qrcode/shaarli-qrcode.js
index fe77c4cd..3316d6f6 100644
--- a/plugins/qrcode/shaarli-qrcode.js
+++ b/plugins/qrcode/shaarli-qrcode.js
@@ -28,14 +28,15 @@
28 28
29// Show the QR-Code of a permalink (when the QR-Code icon is clicked). 29// Show the QR-Code of a permalink (when the QR-Code icon is clicked).
30function showQrCode(caller,loading) 30function showQrCode(caller,loading)
31{ 31{
32 // Dynamic javascript lib loading: We only load qr.js if the QR code icon is clicked: 32 // Dynamic javascript lib loading: We only load qr.js if the QR code icon is clicked:
33 if (typeof(qr) == 'undefined') // Load qr.js only if not present. 33 if (typeof(qr) == 'undefined') // Load qr.js only if not present.
34 { 34 {
35 if (!loading) // If javascript lib is still loading, do not append script to body. 35 if (!loading) // If javascript lib is still loading, do not append script to body.
36 { 36 {
37 var element = document.createElement("script"); 37 var basePath = document.querySelector('input[name="js_base_path"]').value;
38 element.src = "plugins/qrcode/qr-1.1.3.min.js"; 38 var element = document.createElement("script");
39 element.src = basePath + "/plugins/qrcode/qr-1.1.3.min.js";
39 document.body.appendChild(element); 40 document.body.appendChild(element);
40 } 41 }
41 setTimeout(function() { showQrCode(caller,true);}, 200); // Retry in 200 milliseconds. 42 setTimeout(function() { showQrCode(caller,true);}, 200); // Retry in 200 milliseconds.
@@ -44,7 +45,7 @@ function showQrCode(caller,loading)
44 45
45 // Remove previous qrcode if present. 46 // Remove previous qrcode if present.
46 removeQrcode(); 47 removeQrcode();
47 48
48 // Build the div which contains the QR-Code: 49 // Build the div which contains the QR-Code:
49 var element = document.createElement('div'); 50 var element = document.createElement('div');
50 element.id = 'permalinkQrcode'; 51 element.id = 'permalinkQrcode';
@@ -57,11 +58,11 @@ function showQrCode(caller,loading)
57 // Damn IE 58 // Damn IE
58 element.setAttribute('onclick', 'this.parentNode.removeChild(this);' ); 59 element.setAttribute('onclick', 'this.parentNode.removeChild(this);' );
59 } 60 }
60 61
61 // Build the QR-Code: 62 // Build the QR-Code:
62 var image = qr.image({size: 8,value: caller.dataset.permalink}); 63 var image = qr.image({size: 8,value: caller.dataset.permalink});
63 if (image) 64 if (image)
64 { 65 {
65 element.appendChild(image); 66 element.appendChild(image);
66 element.innerHTML += "<br>Click to close"; 67 element.innerHTML += "<br>Click to close";
67 caller.parentNode.appendChild(element); 68 caller.parentNode.appendChild(element);
@@ -87,4 +88,4 @@ function removeQrcode()
87 elem.parentNode.removeChild(elem); 88 elem.parentNode.removeChild(elem);
88 } 89 }
89 return false; 90 return false;
90} \ No newline at end of file 91}