]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - plugins/qrcode/qrcode.php
Inject ROOT_PATH in plugin instead of regenerating it everywhere
[github/shaarli/Shaarli.git] / plugins / qrcode / qrcode.php
CommitLineData
14c8efbe 1<?php
abb3ff38
A
2/**
3 * Plugin qrcode
4 * Add QRCode containing URL for each links.
5 * Display a QRCode icon in link list.
6 */
14c8efbe 7
e1850388 8use Shaarli\Plugin\PluginManager;
1a8ac737 9use Shaarli\Render\TemplatePage;
a932f486 10
14c8efbe
A
11/**
12 * Add qrcode icon to link_plugin when rendering linklist.
13 *
abb3ff38
A
14 * @param array $data - linklist data.
15 *
14c8efbe
A
16 * @return mixed - linklist data with qrcode plugin.
17 */
18function hook_qrcode_render_linklist($data)
19{
20 $qrcode_html = file_get_contents(PluginManager::$PLUGINS_PATH . '/qrcode/qrcode.html');
21
3adbdc2a 22 $path = ($data['_ROOT_PATH_'] ?? '') . '/' . PluginManager::$PLUGINS_PATH;
14c8efbe 23 foreach ($data['links'] as &$value) {
a0ab3c3f
V
24 $qrcode = sprintf(
25 $qrcode_html,
49e62f22 26 $value['url'],
9fbc4229 27 $path
49e62f22 28 );
14c8efbe
A
29 $value['link_plugin'][] = $qrcode;
30 }
31
32 return $data;
33}
34
35/**
36 * When linklist is displayed, include qrcode JS files.
37 *
38 * @param array $data - footer data.
abb3ff38 39 *
14c8efbe
A
40 * @return mixed - footer data with qrcode JS files added.
41 */
42function hook_qrcode_render_footer($data)
43{
1a8ac737 44 if ($data['_PAGE_'] == TemplatePage::LINKLIST) {
76fe68d9 45 $data['js_files'][] = PluginManager::$PLUGINS_PATH . '/qrcode/shaarli-qrcode.js';
14c8efbe
A
46 }
47
48 return $data;
abb3ff38 49}
28a4fc54
A
50
51/**
52 * When linklist is displayed, include qrcode CSS file.
53 *
54 * @param array $data - header data.
55 *
56 * @return mixed - header data with qrcode CSS file added.
57 */
58function hook_qrcode_render_includes($data)
59{
1a8ac737 60 if ($data['_PAGE_'] == TemplatePage::LINKLIST) {
76fe68d9 61 $data['css_files'][] = PluginManager::$PLUGINS_PATH . '/qrcode/qrcode.css';
28a4fc54
A
62 }
63
64 return $data;
65}
12266213
A
66
67/**
68 * This function is never called, but contains translation calls for GNU gettext extraction.
69 */
70function qrcode_dummy_translation()
71{
72 // meta
73 t('For each link, add a QRCode icon.');
74}