piwik.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Piwik plugin.
  4. * Adds tracking code on each page.
  5. */
  6. /**
  7. * Initialization function.
  8. * It will be called when the plugin is loaded.
  9. * This function can be used to return a list of initialization errors.
  10. *
  11. * @param $conf ConfigManager instance.
  12. *
  13. * @return array List of errors (optional).
  14. */
  15. function piwik_init($conf)
  16. {
  17. $piwikUrl = $conf->get('plugins.PIWIK_URL');
  18. $piwikSiteid = $conf->get('plugins.PIWIK_SITEID');
  19. if (empty($piwikUrl) || empty($piwikSiteid)) {
  20. $error = t('Piwik plugin error: ' .
  21. 'Please define PIWIK_URL and PIWIK_SITEID in the plugin administration page.');
  22. return array($error);
  23. }
  24. }
  25. /**
  26. * Hook render_footer.
  27. * Executed on every page redering.
  28. *
  29. * Template placeholders:
  30. * - text
  31. * - endofpage
  32. * - js_files
  33. *
  34. * Data:
  35. * - _PAGE_: current page
  36. * - _LOGGEDIN_: true/false
  37. *
  38. * @param array $data data passed to plugin
  39. *
  40. * @return array altered $data.
  41. */
  42. function hook_piwik_render_footer($data, $conf)
  43. {
  44. $piwikUrl = $conf->get('plugins.PIWIK_URL');
  45. $piwikSiteid = $conf->get('plugins.PIWIK_SITEID');
  46. if (empty($piwikUrl) || empty($piwikSiteid)) {
  47. return $data;
  48. }
  49. // Free elements at the end of the page.
  50. $data['endofpage'][] = sprintf(
  51. file_get_contents(PluginManager::$PLUGINS_PATH . '/piwik/piwik.html'),
  52. $piwikUrl,
  53. $piwikSiteid,
  54. $piwikUrl,
  55. $piwikSiteid
  56. );
  57. return $data;
  58. }
  59. /**
  60. * This function is never called, but contains translation calls for GNU gettext extraction.
  61. */
  62. function piwik_dummy_translation()
  63. {
  64. // meta
  65. t('A plugin that adds Piwik tracking code to Shaarli pages.');
  66. t('Piwik URL');
  67. t('Piwik site ID');
  68. }