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