]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | /** | |
4 | * Plugin qrcode | |
5 | * Add QRCode containing URL for each links. | |
6 | * Display a QRCode icon in link list. | |
7 | */ | |
8 | ||
9 | use Shaarli\Plugin\PluginManager; | |
10 | use Shaarli\Render\TemplatePage; | |
11 | ||
12 | /** | |
13 | * Add qrcode icon to link_plugin when rendering linklist. | |
14 | * | |
15 | * @param array $data - linklist data. | |
16 | * | |
17 | * @return mixed - linklist data with qrcode plugin. | |
18 | */ | |
19 | function hook_qrcode_render_linklist($data) | |
20 | { | |
21 | $qrcode_html = file_get_contents(PluginManager::$PLUGINS_PATH . '/qrcode/qrcode.html'); | |
22 | ||
23 | $path = ($data['_ROOT_PATH_'] ?? '') . '/' . PluginManager::$PLUGINS_PATH; | |
24 | foreach ($data['links'] as &$value) { | |
25 | $qrcode = sprintf( | |
26 | $qrcode_html, | |
27 | $value['url'], | |
28 | $path | |
29 | ); | |
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. | |
40 | * | |
41 | * @return mixed - footer data with qrcode JS files added. | |
42 | */ | |
43 | function hook_qrcode_render_footer($data) | |
44 | { | |
45 | if ($data['_PAGE_'] == TemplatePage::LINKLIST) { | |
46 | $data['js_files'][] = PluginManager::$PLUGINS_PATH . '/qrcode/shaarli-qrcode.js'; | |
47 | } | |
48 | ||
49 | return $data; | |
50 | } | |
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 | */ | |
59 | function hook_qrcode_render_includes($data) | |
60 | { | |
61 | if ($data['_PAGE_'] == TemplatePage::LINKLIST) { | |
62 | $data['css_files'][] = PluginManager::$PLUGINS_PATH . '/qrcode/qrcode.css'; | |
63 | } | |
64 | ||
65 | return $data; | |
66 | } | |
67 | ||
68 | /** | |
69 | * This function is never called, but contains translation calls for GNU gettext extraction. | |
70 | */ | |
71 | function qrcode_dummy_translation() | |
72 | { | |
73 | // meta | |
74 | t('For each link, add a QRCode icon.'); | |
75 | } |