1
|
<?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
|
variable_del('piwik_trackmailto');
|
40
|
variable_del('piwik_track'); // interrims solution
|
41
|
variable_del('piwik_trackfiles_extensions');
|
42
|
variable_del('piwik_trackmessages');
|
43
|
variable_del('piwik_trackuserid');
|
44
|
variable_del('piwik_translation_set');
|
45
|
variable_del('piwik_url_http');
|
46
|
variable_del('piwik_url_https');
|
47
|
variable_del('piwik_visibility_pages');
|
48
|
variable_del('piwik_visibility_roles');
|
49
|
|
50
|
// Remove backup variables if exits. Remove this code in D8.
|
51
|
variable_del('piwik_codesnippet_before_backup_7202');
|
52
|
variable_del('piwik_codesnippet_after_backup_7202');
|
53
|
}
|
54
|
|
55
|
/**
|
56
|
* Remove cache directory if module is disabled (or uninstalled).
|
57
|
*/
|
58
|
function piwik_disable() {
|
59
|
piwik_clear_js_cache();
|
60
|
}
|
61
|
|
62
|
/**
|
63
|
* Implementation of hook_requirements().
|
64
|
*/
|
65
|
function piwik_requirements($phase) {
|
66
|
$requirements = array();
|
67
|
$t = get_t();
|
68
|
|
69
|
switch ($phase) {
|
70
|
case 'runtime' :
|
71
|
// Module cannot validate piwik URL without external HTTP requests.
|
72
|
if (variable_get('drupal_http_request_fails', TRUE) && !system_check_http_request()) {
|
73
|
$requirements['http requests'] = array(
|
74
|
'title' => $t('HTTP request status'),
|
75
|
'value' => $t('Fails'),
|
76
|
'severity' => REQUIREMENT_ERROR,
|
77
|
'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.'),
|
78
|
);
|
79
|
}
|
80
|
|
81
|
// Raise warning if Piwik user account has not been set yet.
|
82
|
if (!preg_match('/^\d{1,}$/', variable_get('piwik_site_id', ''))) {
|
83
|
$requirements['piwik'] = array(
|
84
|
'title' => $t('Piwik module'),
|
85
|
'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'))),
|
86
|
'severity' => REQUIREMENT_WARNING,
|
87
|
'value' => $t('Not configured'),
|
88
|
);
|
89
|
}
|
90
|
break;
|
91
|
}
|
92
|
return $requirements;
|
93
|
}
|
94
|
|
95
|
|
96
|
/**
|
97
|
* Change visibility setting for paths.
|
98
|
*/
|
99
|
function piwik_update_6000() {
|
100
|
// Orginal pages setting.
|
101
|
$pages = array(
|
102
|
'admin*',
|
103
|
'user*',
|
104
|
'node/add*',
|
105
|
'node/*/*',
|
106
|
);
|
107
|
|
108
|
$diff = array_diff($pages, preg_split('/(\r\n?|\n)/', variable_get('piwik_pages', implode("\n", $pages))));
|
109
|
if (empty($diff)) {
|
110
|
// No diff to original settings found. Update with new settings.
|
111
|
$pages = array(
|
112
|
'admin',
|
113
|
'admin/*',
|
114
|
'user/*/*',
|
115
|
'node/add*',
|
116
|
'node/*/*',
|
117
|
);
|
118
|
variable_set('piwik_pages', implode("\n", $pages));
|
119
|
return t('Path visibility filter setting changed from "admin*" to "admin, admin/*" and "user*" changed to "user/*/*".');
|
120
|
}
|
121
|
else {
|
122
|
return t('Custom path visibility filter setting found. Update skipped!');
|
123
|
}
|
124
|
}
|
125
|
|
126
|
/**
|
127
|
* Upgrade custom javascript settings.
|
128
|
*/
|
129
|
function piwik_update_6001() {
|
130
|
variable_set('piwik_codesnippet_before', variable_get('piwik_codesnippet', ''));
|
131
|
variable_del('piwik_codesnippet');
|
132
|
return t('Upgraded custom javascript codesnippet setting.');
|
133
|
}
|
134
|
|
135
|
/**
|
136
|
* Remove obsolte token auth.
|
137
|
*/
|
138
|
function piwik_update_6002() {
|
139
|
variable_del('piwik_auth');
|
140
|
return t('The global token_auth setting has been deleted. Users need to configure their personal token_auth.');
|
141
|
}
|
142
|
|
143
|
/**
|
144
|
* Update list of default extensions
|
145
|
*/
|
146
|
function piwik_update_6003() {
|
147
|
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') {
|
148
|
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');
|
149
|
}
|
150
|
return t('The default extensions for download tracking have been updated to piwik defaults.');
|
151
|
}
|
152
|
|
153
|
/**
|
154
|
* Add trailing slash to piwik URLs.
|
155
|
*/
|
156
|
function piwik_update_7200() {
|
157
|
$url_http = variable_get('piwik_url_http', '');
|
158
|
$url_https = variable_get('piwik_url_https', '');
|
159
|
|
160
|
if (!empty($url_http)) {
|
161
|
variable_set('piwik_url_http', $url_http . '/');
|
162
|
}
|
163
|
if (!empty($url_https)) {
|
164
|
variable_set('piwik_url_https', $url_https . '/');
|
165
|
}
|
166
|
|
167
|
return t('Added trailing slash to piwik URLs.');
|
168
|
}
|
169
|
|
170
|
/**
|
171
|
* Move async tracking code to header.
|
172
|
*/
|
173
|
function piwik_update_7201() {
|
174
|
variable_set('piwik_js_scope', 'header');
|
175
|
|
176
|
return t('Async tracking code has been moved to header.');
|
177
|
}
|
178
|
|
179
|
/**
|
180
|
* Backup synchronous code snippets.
|
181
|
*/
|
182
|
function piwik_update_7202() {
|
183
|
$messages = array();
|
184
|
|
185
|
// TODO: Backup synchronous code snippets. Remove variables in D8.
|
186
|
variable_set('piwik_codesnippet_before_backup_7202', variable_get('piwik_codesnippet_before', ''));
|
187
|
variable_set('piwik_codesnippet_after_backup_7202', variable_get('piwik_codesnippet_after', ''));
|
188
|
|
189
|
// Upgrade of BEFORE code snippet.
|
190
|
$code_before = variable_get('piwik_codesnippet_before', '');
|
191
|
if (!empty($code_before)) {
|
192
|
// No value, e.g. piwikTracker.enableLinkTracking()
|
193
|
$code_before = preg_replace('/(.*)piwikTracker\.(\w+)\(\);(.*)/i', '$1_paq.push(["$2"]);$3', $code_before);
|
194
|
// One value, e.g. piwikTracker.addDownloadExtensions("mp5|mp6"), piwikTracker.trackGoal(1)
|
195
|
$code_before = preg_replace('/(.*)piwikTracker\.(\w+)\(("|\'?)(\w+)("|\'?)\);(.*)/i', '$1_paq.push(["$2", $3$4$5]);$6', $code_before);
|
196
|
// Multiple values e.g. piwikTracker.trackLink('/store', 'addTransaction', trans)
|
197
|
$code_before = preg_replace('/(.*)piwikTracker\.(\w+)\((.*)\);(.*)/i', '$1_paq.push(["$2", $3]);$4', $code_before);
|
198
|
|
199
|
variable_set('piwik_codesnippet_before', $code_before);
|
200
|
|
201
|
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');
|
202
|
$messages[] = t('Upgraded custom "before" code snippet.');
|
203
|
}
|
204
|
|
205
|
// Upgrade of AFTER code snippet.
|
206
|
// We cannot update this code snippet automatically. Show message that the upgrade has been skipped.
|
207
|
$code_after = variable_get('piwik_codesnippet_after', '');
|
208
|
if (!empty($code_after)) {
|
209
|
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');
|
210
|
$messages[] = t('Skipped custom "after" code snippet.');
|
211
|
}
|
212
|
|
213
|
return empty($messages) ? t('No custom code snipped found. Nothing to do.') : implode(' ', $messages);
|
214
|
}
|
215
|
|
216
|
/**
|
217
|
* Path visibility filter setting should hide "batch" path.
|
218
|
*/
|
219
|
function piwik_update_7203() {
|
220
|
// Latest pages setting.
|
221
|
$pages = array(
|
222
|
'admin',
|
223
|
'admin/*',
|
224
|
'user/*/*',
|
225
|
'node/add*',
|
226
|
'node/*/*',
|
227
|
);
|
228
|
|
229
|
$diff = array_diff($pages, preg_split('/(\r\n?|\n)/', variable_get('piwik_pages', implode("\n", $pages))));
|
230
|
if (empty($diff)) {
|
231
|
// No diff to latest settings found. Update with new settings.
|
232
|
$pages = array(
|
233
|
'admin',
|
234
|
'admin/*',
|
235
|
'batch',
|
236
|
'node/add*',
|
237
|
'node/*/*',
|
238
|
'user/*/*',
|
239
|
);
|
240
|
variable_set('piwik_pages', implode("\n", $pages));
|
241
|
return t('Added "batch" to path visibility filter setting.');
|
242
|
}
|
243
|
else {
|
244
|
return t('Custom path visibility filter setting found. Update skipped!');
|
245
|
}
|
246
|
}
|
247
|
|
248
|
/**
|
249
|
* Rename piwik_visibility variable to piwik_visibility_pages for consistency.
|
250
|
*/
|
251
|
function piwik_update_7204() {
|
252
|
variable_set('piwik_visibility_pages', variable_get('piwik_visibility', 1));
|
253
|
variable_del('piwik_visibility');
|
254
|
|
255
|
return t('Renamed "piwik_visibility" settings variable to piwik_visibility_pages.');
|
256
|
}
|
257
|
|
258
|
/**
|
259
|
* Update list of default file extensions.
|
260
|
*/
|
261
|
function piwik_update_7205() {
|
262
|
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') {
|
263
|
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');
|
264
|
return t('The default extensions for download tracking have been updated.');
|
265
|
}
|
266
|
else {
|
267
|
return t('Custom extensions for download tracking setting found. Update skipped!');
|
268
|
}
|
269
|
}
|