Projet

Général

Profil

Paste
Télécharger (9,93 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / piwik / piwik.install @ 651307cd

1 85ad3d82 Assos Assos
<?php
2
3
/**
4
 * @file
5
 * Installation file for Piwik - Web analytics module.
6
 */
7
8
function piwik_install() {
9
  // Remove tracking from all administrative pages, see http://drupal.org/node/34970.
10
  variable_set('piwik_visibility_roles', 0);
11
  variable_set('piwik_visibility_pages', 0);
12
  $pages = array(
13
    'admin',
14
    'admin/*',
15
    'batch',
16
    'node/add*',
17
    'node/*/*',
18
    'user/*/*',
19
  );
20
  variable_set('piwik_pages', implode("\n", $pages));
21
}
22
23
function piwik_uninstall() {
24
  variable_del('piwik_cache');
25
  variable_del('piwik_codesnippet_before');
26
  variable_del('piwik_codesnippet_after');
27
  variable_del('piwik_custom');
28
  variable_del('piwik_custom_var');
29
  variable_del('piwik_domain_mode');
30
  variable_del('piwik_js_scope');
31
  variable_del('piwik_last_cache');
32
  variable_del('piwik_page_title_hierarchy');
33
  variable_del('piwik_page_title_hierarchy_exclude_home');
34
  variable_del('piwik_pages');
35
  variable_del('piwik_privacy_donottrack');
36
  variable_del('piwik_roles');
37
  variable_del('piwik_site_id');
38
  variable_del('piwik_site_search');
39 d756b39a Assos Assos
  variable_del('piwik_trackcolorbox');
40 e9f59589 Assos Assos
  variable_del('piwik_trackmailto');
41 85ad3d82 Assos Assos
  variable_del('piwik_track'); // interrims solution
42
  variable_del('piwik_trackfiles_extensions');
43 e9f59589 Assos Assos
  variable_del('piwik_trackmessages');
44 2f8c40f0 Assos Assos
  variable_del('piwik_trackuserid');
45 85ad3d82 Assos Assos
  variable_del('piwik_translation_set');
46
  variable_del('piwik_url_http');
47
  variable_del('piwik_url_https');
48
  variable_del('piwik_visibility_pages');
49
  variable_del('piwik_visibility_roles');
50
51
  // Remove backup variables if exits. Remove this code in D8.
52
  variable_del('piwik_codesnippet_before_backup_7202');
53
  variable_del('piwik_codesnippet_after_backup_7202');
54
}
55
56
/**
57
 * Remove cache directory if module is disabled (or uninstalled).
58
 */
59
function piwik_disable() {
60
  piwik_clear_js_cache();
61
}
62
63
/**
64
 * Implementation of hook_requirements().
65
 */
66
function piwik_requirements($phase) {
67
  $requirements = array();
68
  $t = get_t();
69
70
  switch ($phase) {
71 d756b39a Assos Assos
    case 'runtime':
72 85ad3d82 Assos Assos
      // Module cannot validate piwik URL without external HTTP requests.
73
      if (variable_get('drupal_http_request_fails', TRUE) && !system_check_http_request()) {
74 d756b39a Assos Assos
        $requirements['piwik_http_requests'] = array(
75 85ad3d82 Assos Assos
          'title' => $t('HTTP request status'),
76
          'value' => $t('Fails'),
77
          'severity' => REQUIREMENT_ERROR,
78
          '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.'),
79
        );
80
      }
81
82
      // Raise warning if Piwik user account has not been set yet.
83
      if (!preg_match('/^\d{1,}$/', variable_get('piwik_site_id', ''))) {
84
        $requirements['piwik'] = array(
85
          'title' => $t('Piwik module'),
86
          'description' => $t('Piwik module has not been configured yet. Please configure its settings from the <a href="@url">Piwik settings page</a>.', array('@url' => url('admin/config/system/piwik'))),
87
          'severity' => REQUIREMENT_WARNING,
88
          'value' => $t('Not configured'),
89
        );
90
      }
91
      break;
92
  }
93
  return $requirements;
94
}
95
96
97
/**
98
 * Change visibility setting for paths.
99
 */
100
function piwik_update_6000() {
101
  // Orginal pages setting.
102
  $pages = array(
103
    'admin*',
104
    'user*',
105
    'node/add*',
106
    'node/*/*',
107
  );
108
109
  $diff = array_diff($pages, preg_split('/(\r\n?|\n)/', variable_get('piwik_pages', implode("\n", $pages))));
110
  if (empty($diff)) {
111
    // No diff to original settings found. Update with new settings.
112
    $pages = array(
113
      'admin',
114
      'admin/*',
115
      'user/*/*',
116
      'node/add*',
117
      'node/*/*',
118
    );
119
    variable_set('piwik_pages', implode("\n", $pages));
120
    return t('Path visibility filter setting changed from "admin*" to "admin, admin/*" and "user*" changed to "user/*/*".');
121
  }
122
  else {
123
    return t('Custom path visibility filter setting found. Update skipped!');
124
  }
125
}
126
127
/**
128
 * Upgrade custom javascript settings.
129
 */
130
function piwik_update_6001() {
131
  variable_set('piwik_codesnippet_before', variable_get('piwik_codesnippet', ''));
132
  variable_del('piwik_codesnippet');
133
  return t('Upgraded custom javascript codesnippet setting.');
134
}
135
136
/**
137
 * Remove obsolte token auth.
138
 */
139
function piwik_update_6002() {
140
  variable_del('piwik_auth');
141
  return t('The global token_auth setting has been deleted. Users need to configure their personal token_auth.');
142
}
143
144
/**
145
 * Update list of default extensions
146
 */
147
function piwik_update_6003() {
148
  if (variable_get('piwik_trackfiles_extensions', '') == '7z|aac|avi|csv|doc|exe|flv|gif|gz|jpe?g|js|mp(3|4|e?g)|mov|pdf|phps|png|ppt|rar|sit|tar|torrent|txt|wma|wmv|xls|xml|zip') {
149
    variable_set('piwik_trackfiles_extensions', '7z|aac|arc|arj|asf|asx|avi|bin|csv|doc|exe|flv|gif|gz|gzip|hqx|jar|jpe?g|js|mp(2|3|4|e?g)|mov(ie)?|msi|msp|pdf|phps|png|ppt|qtm?|ra(m|r)?|sea|sit|tar|tgz|torrent|txt|wav|wma|wmv|wpd|xls|xml|z|zip');
150
  }
151
  return t('The default extensions for download tracking have been updated to piwik defaults.');
152
}
153
154
/**
155
 * Add trailing slash to piwik URLs.
156
 */
157
function piwik_update_7200() {
158
  $url_http = variable_get('piwik_url_http', '');
159
  $url_https = variable_get('piwik_url_https', '');
160
161
  if (!empty($url_http)) {
162
    variable_set('piwik_url_http', $url_http . '/');
163
  }
164
  if (!empty($url_https)) {
165
    variable_set('piwik_url_https', $url_https . '/');
166
  }
167
168
  return t('Added trailing slash to piwik URLs.');
169
}
170
171
/**
172
 * Move async tracking code to header.
173
 */
174
function piwik_update_7201() {
175
  variable_set('piwik_js_scope', 'header');
176
177
  return t('Async tracking code has been moved to header.');
178
}
179
180
/**
181
 * Backup synchronous code snippets.
182
 */
183
function piwik_update_7202() {
184
  $messages = array();
185
186
  // TODO: Backup synchronous code snippets. Remove variables in D8.
187
  variable_set('piwik_codesnippet_before_backup_7202', variable_get('piwik_codesnippet_before', ''));
188
  variable_set('piwik_codesnippet_after_backup_7202', variable_get('piwik_codesnippet_after', ''));
189
190
  // Upgrade of BEFORE code snippet.
191
  $code_before = variable_get('piwik_codesnippet_before', '');
192
  if (!empty($code_before)) {
193
    // No value, e.g. piwikTracker.enableLinkTracking()
194
    $code_before = preg_replace('/(.*)piwikTracker\.(\w+)\(\);(.*)/i', '$1_paq.push(["$2"]);$3', $code_before);
195
    // One value, e.g. piwikTracker.addDownloadExtensions("mp5|mp6"), piwikTracker.trackGoal(1)
196
    $code_before = preg_replace('/(.*)piwikTracker\.(\w+)\(("|\'?)(\w+)("|\'?)\);(.*)/i', '$1_paq.push(["$2", $3$4$5]);$6', $code_before);
197
    // Multiple values e.g. piwikTracker.trackLink('/store', 'addTransaction', trans)
198
    $code_before = preg_replace('/(.*)piwikTracker\.(\w+)\((.*)\);(.*)/i', '$1_paq.push(["$2", $3]);$4', $code_before);
199
200
    variable_set('piwik_codesnippet_before', $code_before);
201
202
    drupal_set_message(Database::getConnection()->prefixTables("<strong>Attempted</strong> to upgrade Piwik custom 'before' code snippet. Backup of previous code snippet has been saved in database table '{variable}' as 'piwik_codesnippet_before_backup_7202'. Please consult Piwik's <a href='http://piwik.org/docs/javascript-tracking/#toc-asynchronous-tracking'>Asynchronous tracking Guide</a> if the upgrade was successfully."), 'warning');
203
    $messages[] = t('Upgraded custom "before" code snippet.');
204
  }
205
206
  // Upgrade of AFTER code snippet.
207
  // We cannot update this code snippet automatically. Show message that the upgrade has been skipped.
208
  $code_after = variable_get('piwik_codesnippet_after', '');
209
  if (!empty($code_after)) {
210
    drupal_set_message(Database::getConnection()->prefixTables("Automatic upgrade of Google Analytics custom 'after' code snippet has been skipped. Backup of previous code snippet has been saved in database table '{variable}' as 'piwik_codesnippet_after_backup_7202'. You need to manually upgrade the custom 'after' code snippet."), 'error');
211
    $messages[] = t('Skipped custom "after" code snippet.');
212
  }
213
214
  return empty($messages) ? t('No custom code snipped found. Nothing to do.') : implode(' ', $messages);
215
}
216
217
/**
218
 * Path visibility filter setting should hide "batch" path.
219
 */
220
function piwik_update_7203() {
221
  // Latest pages setting.
222
  $pages = array(
223
    'admin',
224
    'admin/*',
225
    'user/*/*',
226
    'node/add*',
227
    'node/*/*',
228
  );
229
230
  $diff = array_diff($pages, preg_split('/(\r\n?|\n)/', variable_get('piwik_pages', implode("\n", $pages))));
231
  if (empty($diff)) {
232
    // No diff to latest settings found. Update with new settings.
233
    $pages = array(
234
      'admin',
235
      'admin/*',
236
      'batch',
237
      'node/add*',
238
      'node/*/*',
239
      'user/*/*',
240
    );
241
    variable_set('piwik_pages', implode("\n", $pages));
242
    return t('Added "batch" to path visibility filter setting.');
243
  }
244
  else {
245
    return t('Custom path visibility filter setting found. Update skipped!');
246
  }
247
}
248
249
/**
250
 * Rename piwik_visibility variable to piwik_visibility_pages for consistency.
251
 */
252
function piwik_update_7204() {
253
  variable_set('piwik_visibility_pages', variable_get('piwik_visibility', 1));
254
  variable_del('piwik_visibility');
255
256
  return t('Renamed "piwik_visibility" settings variable to piwik_visibility_pages.');
257
}
258 de644da6 Julien Enselme
259
/**
260
 * Update list of default file extensions.
261
 */
262
function piwik_update_7205() {
263
  if (variable_get('piwik_trackfiles_extensions', '') == '7z|aac|arc|arj|asf|asx|avi|bin|csv|doc|exe|flv|gif|gz|gzip|hqx|jar|jpe?g|js|mp(2|3|4|e?g)|mov(ie)?|msi|msp|pdf|phps|png|ppt|qtm?|ra(m|r)?|sea|sit|tar|tgz|torrent|txt|wav|wma|wmv|wpd|xls|xml|z|zip') {
264
    variable_set('piwik_trackfiles_extensions', '7z|aac|arc|arj|asf|asx|avi|bin|csv|doc(x|m)?|dot(x|m)?|exe|flv|gif|gz|gzip|hqx|jar|jpe?g|js|mp(2|3|4|e?g)|mov(ie)?|msi|msp|pdf|phps|png|ppt(x|m)?|pot(x|m)?|pps(x|m)?|ppam|sld(x|m)?|thmx|qtm?|ra(m|r)?|sea|sit|tar|tgz|torrent|txt|wav|wma|wmv|wpd|xls(x|m|b)?|xlt(x|m)|xlam|xml|z|zip');
265
    return t('The default extensions for download tracking have been updated.');
266
  }
267
  else {
268
    return t('Custom extensions for download tracking setting found. Update skipped!');
269
  }
270
}