Projet

Général

Profil

Paste
Télécharger (3,7 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / matomo / matomo.install @ 60283730

1
<?php
2

    
3
/**
4
 * @file
5
 * Installation file for Matomo Analytics module.
6
 */
7

    
8
function matomo_install() {
9
  // Remove tracking from all administrative pages, see http://drupal.org/node/34970.
10
  variable_set('matomo_visibility_roles', 0);
11
  variable_set('matomo_visibility_pages', 0);
12
  $pages = array(
13
    'admin',
14
    'admin/*',
15
    'batch',
16
    'node/add*',
17
    'node/*/*',
18
    'user/*/*',
19
  );
20
  variable_set('matomo_pages', implode("\n", $pages));
21

    
22
  // Make the default install more user and GDPR friendly.
23
  user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('opt-in or out of matomo tracking'));
24
  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');
25
}
26

    
27
function matomo_uninstall() {
28
  variable_del('matomo_cache');
29
  variable_del('matomo_codesnippet_before');
30
  variable_del('matomo_codesnippet_after');
31
  variable_del('matomo_custom');
32
  variable_del('matomo_custom_var');
33
  variable_del('matomo_domain_mode');
34
  variable_del('matomo_js_scope');
35
  variable_del('matomo_last_cache');
36
  variable_del('matomo_page_title_hierarchy');
37
  variable_del('matomo_page_title_hierarchy_exclude_home');
38
  variable_del('matomo_pages');
39
  variable_del('matomo_privacy_donottrack');
40
  variable_del('matomo_roles');
41
  variable_del('matomo_site_id');
42
  variable_del('matomo_site_search');
43
  variable_del('matomo_trackcolorbox');
44
  variable_del('matomo_trackmailto');
45
  variable_del('matomo_track'); // interrims solution
46
  variable_del('matomo_trackfiles_extensions');
47
  variable_del('matomo_trackmessages');
48
  variable_del('matomo_trackuserid');
49
  variable_del('matomo_translation_set');
50
  variable_del('matomo_url_http');
51
  variable_del('matomo_url_https');
52
  variable_del('matomo_visibility_pages');
53
  variable_del('matomo_visibility_roles');
54

    
55
  // Remove backup variables if exits. Remove this code in D8.
56
  variable_del('matomo_codesnippet_before_backup_7202');
57
  variable_del('matomo_codesnippet_after_backup_7202');
58
}
59

    
60
/**
61
 * Remove cache directory if module is disabled (or uninstalled).
62
 */
63
function matomo_disable() {
64
  matomo_clear_js_cache();
65
}
66

    
67
/**
68
 * Implementation of hook_requirements().
69
 */
70
function matomo_requirements($phase) {
71
  $requirements = array();
72
  $t = get_t();
73

    
74
  switch ($phase) {
75
    case 'runtime':
76
      // Module cannot validate matomo URL without external HTTP requests.
77
      if (variable_get('drupal_http_request_fails', TRUE) && !system_check_http_request()) {
78
        $requirements['matomo_http_requests'] = array(
79
          'title' => $t('HTTP request status'),
80
          'value' => $t('Fails'),
81
          'severity' => REQUIREMENT_ERROR,
82
          '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.'),
83
        );
84
      }
85

    
86
      // Raise warning if Matomo user account has not been set yet.
87
      if (!preg_match('/^\d{1,}$/', variable_get('matomo_site_id', ''))) {
88
        $requirements['matomo'] = array(
89
          'title' => $t('Matomo module'),
90
          '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'))),
91
          'severity' => REQUIREMENT_WARNING,
92
          'value' => $t('Not configured'),
93
        );
94
      }
95
      break;
96
  }
97
  return $requirements;
98
}
99

    
100
/**
101
 * NOTE: Next update need to be 7206 or updates for 'dev' users may break.
102
 */