qrcode.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. * Add qrcode icon to link_plugin when rendering linklist.
  9. *
  10. * @param array $data - linklist data.
  11. *
  12. * @return mixed - linklist data with qrcode plugin.
  13. */
  14. function hook_qrcode_render_linklist($data)
  15. {
  16. $qrcode_html = file_get_contents(PluginManager::$PLUGINS_PATH . '/qrcode/qrcode.html');
  17. foreach ($data['links'] as &$value) {
  18. $qrcode = sprintf(
  19. $qrcode_html,
  20. urlencode($value['url']),
  21. $value['url'],
  22. PluginManager::$PLUGINS_PATH
  23. );
  24. $value['link_plugin'][] = $qrcode;
  25. }
  26. return $data;
  27. }
  28. /**
  29. * When linklist is displayed, include qrcode JS files.
  30. *
  31. * @param array $data - footer data.
  32. *
  33. * @return mixed - footer data with qrcode JS files added.
  34. */
  35. function hook_qrcode_render_footer($data)
  36. {
  37. if ($data['_PAGE_'] == Router::$PAGE_LINKLIST) {
  38. $data['js_files'][] = PluginManager::$PLUGINS_PATH . '/qrcode/shaarli-qrcode.js';
  39. }
  40. return $data;
  41. }
  42. /**
  43. * When linklist is displayed, include qrcode CSS file.
  44. *
  45. * @param array $data - header data.
  46. *
  47. * @return mixed - header data with qrcode CSS file added.
  48. */
  49. function hook_qrcode_render_includes($data)
  50. {
  51. if ($data['_PAGE_'] == Router::$PAGE_LINKLIST) {
  52. $data['css_files'][] = PluginManager::$PLUGINS_PATH . '/qrcode/qrcode.css';
  53. }
  54. return $data;
  55. }
  56. /**
  57. * This function is never called, but contains translation calls for GNU gettext extraction.
  58. */
  59. function qrcode_dummy_translation()
  60. {
  61. // meta
  62. t('For each link, add a QRCode icon.');
  63. }