/[drupal]/contributions/modules/google_analytics/googleanalytics.install
ViewVC logotype

Contents of /contributions/modules/google_analytics/googleanalytics.install

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.13 - (show annotations) (download) (as text)
Sat Oct 17 14:02:51 2009 UTC (5 weeks, 5 days ago) by hass
Branch: MAIN
CVS Tags: HEAD
Changes since 1.12: +4 -4 lines
File MIME type: text/x-php
* Add stream wrapper / public folder support
* Add 'file' back to menu after the roll back
1 <?php
2 // $Id: googleanalytics.install,v 1.12 2009/08/22 11:57:24 hass Exp $
3
4 /**
5 * @file
6 * Installation file for Google Analytics module.
7 */
8
9 function googleanalytics_install() {
10 variable_set('googleanalytics_visibility', 0);
11
12 // Remove tracking from all administrative pages, see http://drupal.org/node/34970.
13 $pages = array(
14 'admin',
15 'admin/*',
16 'user/*/*',
17 'node/add*',
18 'node/*/*',
19 );
20 variable_set('googleanalytics_pages', implode("\n", $pages));
21 }
22
23 function googleanalytics_uninstall() {
24 variable_del('googleanalytics_account');
25 variable_del('googleanalytics_codesnippet_before');
26 variable_del('googleanalytics_codesnippet_after');
27 variable_del('googleanalytics_segmentation');
28 variable_del('googleanalytics_trackoutgoing');
29 variable_del('googleanalytics_trackmailto');
30 variable_del('googleanalytics_trackfiles');
31 variable_del('googleanalytics_trackfiles_extensions');
32 variable_del('googleanalytics_cache');
33 variable_del('googleanalytics_last_cache');
34 variable_del('googleanalytics_site_search');
35 variable_del('googleanalytics_trackadsense');
36 variable_del('googleanalytics_js_scope');
37 variable_del('googleanalytics_custom');
38 variable_del('googleanalytics_roles');
39 variable_del('googleanalytics_visibility');
40 variable_del('googleanalytics_pages');
41 variable_del('googleanalytics_translation_set');
42 }
43
44 /**
45 * Remove cache directory if module is disabled (or uninstalled).
46 */
47 function googleanalytics_disable() {
48 $path = 'public://googleanalytics';
49 if (file_exists($path)) {
50 file_unmanaged_delete($path . '/ga.js');
51 rmdir($path);
52 }
53 }
54
55 /**
56 * Upgrade old extension variable to new and use old name as enabled/disabled flag.
57 */
58 function googleanalytics_update_6000() {
59 $ret = array();
60
61 variable_set('googleanalytics_trackfiles_extensions', variable_get('googleanalytics_trackfiles', '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'));
62 $trackfiles = variable_get('googleanalytics_trackfiles', '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') ? TRUE : FALSE;
63 variable_set('googleanalytics_trackfiles', $trackfiles);
64 $ret[] = array('success' => TRUE, 'query' => 'Updated download tracking settings.');
65
66 return $ret;
67 }
68
69 function googleanalytics_update_6001() {
70 $ret = array();
71
72 variable_set('googleanalytics_visibility', 0);
73
74 // Remove tracking from all administrative pages, see http://drupal.org/node/34970.
75 $pages = array(
76 'admin*',
77 'user*',
78 'node/add*',
79 'node/*/*',
80 );
81 variable_set('googleanalytics_pages', implode("\n", $pages));
82 $ret[] = array('success' => TRUE, 'query' => 'Added page tracking to every page except the listed pages: '. implode(', ', $pages));
83
84 return $ret;
85 }
86
87 /**
88 * Upgrade role settings and per user tracking settings
89 * of "User 1" and remove outdated tracking variables.
90 */
91 function googleanalytics_update_6002() {
92 $ret = array();
93
94 // Upgrade enabled/disabled roles to new logic (correct for upgrades from 5.x-1.4 and 6.x-1.0).
95 $roles = array();
96 foreach (user_roles() as $rid => $name) {
97 if (variable_get('googleanalytics_track_'. $rid, FALSE)) {
98 // Role ID is activated for user tracking.
99 $roles[$rid] = $rid;
100 $ret[] = array('success' => TRUE, 'query' => 'Enabled page tracking for role: ' . $name);
101 }
102 else {
103 $ret[] = array('success' => TRUE, 'query' => 'Disabled page tracking for role: ' . $name);
104 }
105 }
106 variable_set('googleanalytics_roles', $roles);
107
108 // Upgrade disabled tracking of "user 1" to new logic.
109 if (!$track_user1 = variable_get('googleanalytics_track__user1', 1)) {
110 variable_set('googleanalytics_custom', 1);
111
112 // Load user 1 object, set appropiate value and save new user settings back.
113 $account = user_load(array('uid' => 1));
114 $account = user_save($account, array('googleanalytics' => array('custom' => 0)), 'account');
115 $ret[] = array('success' => TRUE, 'query' => 'Disabled user specific page tracking for website administrator.');
116 }
117
118 // Delete outdated tracking settings.
119 $ret[] = update_sql("DELETE FROM {variable} WHERE name LIKE 'googleanalytics_track_%'");
120
121 return $ret;
122 }
123
124 /**
125 * #262468: Clear menu cache to solve stale menu data in 5.x-1.5 and 6.x-1.1
126 */
127 function googleanalytics_update_6003() {
128 $ret = array();
129 menu_rebuild();
130 return $ret;
131 }
132
133 /**
134 * Change visibility setting for path "user/*".
135 */
136 function googleanalytics_update_6004() {
137 $ret = array();
138
139 // Orginal pages setting.
140 $pages = array(
141 'admin*',
142 'user*',
143 'node/add*',
144 'node/*/*',
145 );
146
147 $diff = array_diff($pages, preg_split('/(\r\n?|\n)/', variable_get('googleanalytics_pages', implode("\n", $pages))));
148 if (empty($diff)) {
149 // No diff to original settings found. Update with new settings.
150 $pages = array(
151 'admin*',
152 'user/*/*',
153 'node/add*',
154 'node/*/*',
155 );
156 variable_set('googleanalytics_pages', implode("\n", $pages));
157 $ret[] = array('success' => TRUE, 'query' => 'Path visibility filter setting changed from "user*" to "user/*/*".');
158 }
159 else {
160 $ret[] = array('success' => TRUE, 'query' => 'Custom path visibility filter setting found. Update skipped!');
161 }
162
163 return $ret;
164 }
165
166 /**
167 * Change visibility setting for path "admin*".
168 */
169 function googleanalytics_update_6005() {
170 $ret = array();
171
172 // Orginal pages setting.
173 $pages = array(
174 'admin*',
175 'user/*/*',
176 'node/add*',
177 'node/*/*',
178 );
179
180 $diff = array_diff($pages, preg_split('/(\r\n?|\n)/', variable_get('googleanalytics_pages', implode("\n", $pages))));
181 if (empty($diff)) {
182 // No diff to original settings found. Update with new settings.
183 $pages = array(
184 'admin',
185 'admin/*',
186 'user/*/*',
187 'node/add*',
188 'node/*/*',
189 );
190 variable_set('googleanalytics_pages', implode("\n", $pages));
191 $ret[] = array('success' => TRUE, 'query' => 'Path visibility filter setting changed from "admin*" to "admin" and "admin/*".');
192 }
193 else {
194 $ret[] = array('success' => TRUE, 'query' => 'Custom path visibility filter setting found. Update skipped!');
195 }
196
197 return $ret;
198 }
199
200 /**
201 * Upgrade custom javascript settings.
202 */
203 function googleanalytics_update_6006() {
204 $ret = array();
205
206 variable_set('googleanalytics_codesnippet_before', variable_get('googleanalytics_codesnippet', ''));
207 variable_del('googleanalytics_codesnippet');
208 $ret[] = array('success' => TRUE, 'query' => 'Upgraded custom javascript codesnippet setting.');
209
210 return $ret;
211 }
212
213 /**
214 * Remove "User identifier" and "User name" from segmentation fields.
215 *
216 * This is a data protection and privacy law change. For more information see Google Analytics
217 * terms of use section 8.1 (http://www.google.com/analytics/en-GB/tos.html).
218 */
219 function googleanalytics_update_6007() {
220 $ret = array();
221
222 $profile_fields = variable_get('googleanalytics_segmentation', array());
223 unset($profile_fields['uid']);
224 unset($profile_fields['name']);
225 variable_set('googleanalytics_segmentation', $profile_fields);
226 $ret[] = array('success' => TRUE, 'query' => 'Removed "User identifier" and "User name" from segmentation fields.');
227
228 return $ret;
229 }
230
231 /**
232 * Remove outdated legacy support variables and files.
233 */
234 function googleanalytics_update_6200() {
235 $ret = array();
236
237 $path = 'public://googleanalytics';
238 if (file_exists($path)) {
239 file_unmanaged_delete($path .'/urchin.js');
240 }
241 variable_del('googleanalytics_legacy_version');
242
243 $ret[] = array('success' => TRUE, 'query' => 'Removed legacy support.');
244
245 return $ret;
246 }
247
248 /**
249 * Update list of default file extensions.
250 */
251 function googleanalytics_update_6201() {
252 $ret = array();
253
254 if (variable_get('googleanalytics_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') {
255 variable_set('googleanalytics_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');
256 }
257 $ret[] = array('success' => TRUE, 'query' => 'The default extensions for download tracking have been updated.');
258
259 return $ret;
260 }

  ViewVC Help
Powered by ViewVC 1.1.2