matomo.install 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * @file
  4. * Installation file for Matomo Analytics module.
  5. */
  6. function matomo_install() {
  7. // Remove tracking from all administrative pages, see https://drupal.org/node/34970.
  8. variable_set('matomo_visibility_roles', 0);
  9. variable_set('matomo_visibility_pages', 0);
  10. $pages = array(
  11. 'admin',
  12. 'admin/*',
  13. 'batch',
  14. 'node/add*',
  15. 'node/*/*',
  16. 'user/*/*',
  17. );
  18. variable_set('matomo_pages', implode("\n", $pages));
  19. // Make the default install more user and GDPR friendly.
  20. user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('opt-in or out of matomo tracking'));
  21. drupal_set_message(t('Module %module granted %permission permission to authenticated users.', array('%module' => 'Matomo Analytics', '%permission' => t('Opt-in or out of tracking'))), 'status');
  22. }
  23. function matomo_uninstall() {
  24. variable_del('matomo_cache');
  25. variable_del('matomo_codesnippet_before');
  26. variable_del('matomo_codesnippet_after');
  27. variable_del('matomo_custom');
  28. variable_del('matomo_custom_var');
  29. variable_del('matomo_domain_mode');
  30. variable_del('matomo_js_scope');
  31. variable_del('matomo_last_cache');
  32. variable_del('matomo_page_title_hierarchy');
  33. variable_del('matomo_page_title_hierarchy_exclude_home');
  34. variable_del('matomo_pages');
  35. variable_del('matomo_privacy_donottrack');
  36. variable_del('matomo_roles');
  37. variable_del('matomo_site_id');
  38. variable_del('matomo_site_search');
  39. variable_del('matomo_trackcolorbox');
  40. variable_del('matomo_trackmailto');
  41. variable_del('matomo_track'); // interrims solution
  42. variable_del('matomo_trackfiles_extensions');
  43. variable_del('matomo_trackmessages');
  44. variable_del('matomo_trackuserid');
  45. variable_del('matomo_translation_set');
  46. variable_del('matomo_url_http');
  47. variable_del('matomo_url_https');
  48. variable_del('matomo_visibility_pages');
  49. variable_del('matomo_visibility_roles');
  50. // Remove backup variables if exits. Remove this code in D8.
  51. variable_del('matomo_codesnippet_before_backup_7202');
  52. variable_del('matomo_codesnippet_after_backup_7202');
  53. }
  54. /**
  55. * Remove cache directory if module is disabled (or uninstalled).
  56. */
  57. function matomo_disable() {
  58. matomo_clear_js_cache();
  59. }
  60. /**
  61. * Implementation of hook_requirements().
  62. */
  63. function matomo_requirements($phase) {
  64. $requirements = array();
  65. $t = get_t();
  66. switch ($phase) {
  67. case 'runtime':
  68. // Module cannot validate matomo URL without external HTTP requests.
  69. if (variable_get('drupal_http_request_fails', TRUE) && !system_check_http_request()) {
  70. $requirements['matomo_http_requests'] = array(
  71. 'title' => $t('HTTP request status'),
  72. 'value' => $t('Fails'),
  73. 'severity' => REQUIREMENT_ERROR,
  74. 'description' => $t('Your system or network configuration does not allow Drupal to access web pages, resulting in reduced functionality. This could be due to your webserver configuration or PHP settings, and should be resolved in order to download information about available updates, fetch aggregator feeds, sign in via OpenID, or use other network-dependent services.'),
  75. );
  76. }
  77. // Raise warning if Matomo user account has not been set yet.
  78. if (!preg_match('/^\d{1,}$/', variable_get('matomo_site_id', ''))) {
  79. $requirements['matomo'] = array(
  80. 'title' => $t('Matomo module'),
  81. 'description' => $t('Matomo module has not been configured yet. Please configure its settings from the <a href="@url">Matomo settings page</a>.', array('@url' => url('admin/config/system/matomo'))),
  82. 'severity' => REQUIREMENT_WARNING,
  83. 'value' => $t('Not configured'),
  84. );
  85. }
  86. break;
  87. }
  88. return $requirements;
  89. }
  90. /**
  91. * NOTE: Next update need to be 7206 or updates for 'dev' users may break.
  92. */