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