qrcode.php 1.6 KB

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