forked from backdrop-contrib/ip_geoloc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathip_geoloc.install
394 lines (376 loc) · 17.9 KB
/
ip_geoloc.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
<?php
/**
* @file
* Install and uninstall hooks for IP Geolocation Views & Maps.
*/
/**
* Implments hook_enable().
*/
function ip_geoloc_enable() {
backdrop_set_message(t('IP Geolocation Views & Maps is now enabled. Please note that some of the canned Views that come with this module require the "<a target="project_page" href="!views_php">Views PHP</a>" module. The "Set my location" block requires <a target="project_page" href="!geocoder">Geocoder</a>. <br/>Module "<a target="project_page" href="!session_cache">Session Cache API</a>" is optional and recommended.', array(
'!views_php' => url('http://drupal.org/project/views_php'),
'!geocoder' => url('http://drupal.org/project/geocoder'),
'!session_cache' => url('http://drupal.org/project/session_cache'),
)));
}
/**
* Implements hook_requirements().
*
* $phase typically is one of 'install', 'runtime', 'update'.
*/
function ip_geoloc_requirements($phase) {
$config = config('ip_geoloc.settings');
$requirements = array();
// Avoid 'undefined function: ip_geoloc_get_css_library_path' during 'install'
// and some warnings not relevant while executing an 'update'.
if ($phase != 'runtime') {
return $requirements;
}
$t = get_t();
$geolocation_methods = array();
if ($config->get('ip_geoloc_google_to_reverse_geocode')) {
$geolocation_methods[] = $t('Google Maps reverse-geocode');
}
if ($config->get('ip_geoloc_smart_ip_as_backup')) {
if (module_exists('smart_ip')) {
$geolocation_methods[] = 'Smart IP';
}
else {
$requirements['ip_geoloc_lbs']['severity'] = REQUIREMENT_WARNING;
$requirements['ip_geoloc_lbs']['description'] = $t('Smart IP is configured as a backup in case the Google Maps reverse-geocode fails. However the Smart IP module is not enabled.');
}
}
elseif (module_exists('geoip')) {
$geolocation_methods[] = 'GeoIP API';
}
$geolocation_methods = array_merge($geolocation_methods, module_implements('get_ip_geolocation_alter'));
$requirements['ip_geoloc_lbs']['title'] = $t('IP Geolocation Views & Maps,<br/>data collection methods employed');
$requirements['ip_geoloc_lbs']['value'] = implode(', ', $geolocation_methods);
if (empty($geolocation_methods)) {
$note = $t('You currently have no data collection methods enabled. Therefore no new address information can be added to the IP geolocation database.');
if (empty($requirements['ip_geoloc']['description'])) {
$requirements['ip_geoloc_lbs']['severity'] = REQUIREMENT_OK;
$requirements['ip_geoloc_lbs']['description'] = $note;
}
else {
$requirements['ip_geoloc_lbs']['description'] .= ' ' . $note;
}
}
$library = backdrop_get_library('leaflet_markercluster', 'leaflet_markercluster');
if (isset($library['js'][0]['data'])) {
$requirements['ip_geoloc_markercluster']['title'] = t('IP Geolocation Views & Maps; Leaflet Markercluster library');
if (strpos($library['js'][0]['data'], IP_GEOLOC_LEAFLET_MARKERCLUSTER_REGIONBOUND_JS)) {
$requirements['ip_geoloc_markercluster']['value'] = t('Installed with RegionBound extension');
$requirements['ip_geoloc_markercluster']['severity'] = REQUIREMENT_OK;
}
else {
$requirements['ip_geoloc_markercluster']['value'] = t('Using basic version');
$requirements['ip_geoloc_markercluster']['severity'] = REQUIREMENT_INFO;
$requirements['ip_geoloc_markercluster']['description'] = t('Leaflet Markercluster installed without region-aware extension. You are not making the most of your clustering. We suggest you obtain the <a href="http://regionbound.com">RegionBound</a> marker cluster .js file and drop it in %directory for superior clustering.', array(
'%directory' => dirname($library['js'][0]['data']),
));
}
}
$requirements['ip_geoloc_font_libs']['title'] = $t('IP Geolocation Views & Maps,<br/>font icon libraries');
$requirements['ip_geoloc_font_libs']['severity'] = REQUIREMENT_OK;
$requirements['ip_geoloc_font_libs']['description'] = $t('When using Leaflet you may superimpose font icons on your markers. <a target="fsymbols" href="!url_fsymbols">fsymbols</a> do not require any files to be downloaded. Other font icons like those from <a target="fontello" href="!url_fontello">Fontello</a> do. See the <a target="readme" href="!url_readme">README</a> for more details on font icon repositories.', array(
'!url_fsymbols' => url('http://text-symbols.com'),
'!url_fontello' => url('http://fontello.com'),
'!url_readme' => url(backdrop_get_path('module', 'ip_geoloc') . '/README.txt'),
));
$requirements['ip_geoloc_font_libs']['value'] = '';
$num_font_libs = 0;
foreach (ip_geoloc_get_font_icon_libs() as $i => $css_file) {
$css_file = trim($css_file);
if (!empty($css_file)) {
if (file_exists($css_file)) {
$msg = $t('Font icon library #@i found at %css_file', array(
'@i' => $i,
'%css_file' => $css_file,
));
$num_font_libs++;
}
else {
$msg = $t('File %file was entered on the <a target="config" href="!url_config">configuration page</a> but not found.', array(
'%file' => $css_file,
'!url_config' => url('admin/config/system/ip_geoloc'),
));
$requirements['ip_geoloc_font_libs']['severity'] = REQUIREMENT_WARNING;
}
$requirements['ip_geoloc_font_libs']['value'] .= $msg . '<br/>';
}
}
if ($num_font_libs == 0) {
$requirements['ip_geoloc_font_libs']['value'] .= $t('No font icon libraries found. However you can still copy and paste font icons from <a target="fsybmols" href="!url_fsymbols">fsymbols</a>.', array(
'!url_fsymbols' => url('http://text-symbols.com'),
));
}
switch ($config->get('ip_geoloc_auth_method')) {
case 1:
$key_provided = $config->get('ip_geoloc_apikey');
break;
case 2:
$key_provided = $config->get('ip_geoloc_client_id');
break;
default:
}
if (empty($key_provided)) {
$requirements['ip_geoloc_map'] = array(
'title' => 'IP Geolocation Views & Maps',
'severity' => REQUIREMENT_WARNING,
'value' => t('No Google Maps API Key or Client ID. Keyless access to Google Maps is no longer supported and may impact rendering of maps. Obtain and enter an API Key or Client ID <a href="!url">here</a>.', array(
'!url' => url('admin/config/system/ip_geoloc'),
)),
);
}
return $requirements;
}
/**
* Implements hook_install().
*/
function ip_geoloc_install() {
// Set high weight so our implementation of hook init comes last.
db_update('system')
->fields(array('weight' => 10))
->condition('name', 'ip_geoloc')
->execute();
// Dynamically generated variable data was detected on the following lines.
// /ip_geoloc/ip_geoloc.module line 510
// /ip_geoloc/ip_geoloc.module line 641
// /ip_geoloc/ip_geoloc.module line 846
// /ip_geoloc/ip_geoloc_blocks.inc line 359
// /ip_geoloc/views/ip_geoloc_plugin_style.inc line 614
}
/**
* Implements hook_uninstall().
*/
function ip_geoloc_uninstall() {
// Delete all ip_geoloc_* variables at once.
db_query("DELETE FROM {variable} WHERE name LIKE 'ip_geoloc_%%'");
}
/**
* Implements hook_schema().
*
* Smart IP module provides:
* IP address
* Latitude/Longitude
* Country
* Country Code
* Region
* Region Code (usually empty for Australia)
* City
* ZIP (which we store under Postal Code)
*
* GeoIP City provides:
* TBA
*
* Google provides:
* TBA
*
* Note: some of the varchar should be varbinary, see drupal.org/node/1793674
*/
function ip_geoloc_schema() {
$schema['ip_geoloc'] = array(
'description' => 'Store visitor IP addresses and geolocation information',
'fields' => array(
'id' => array(
'description' => 'Unique id',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'ip_address' => array(
'description' => 'IP address',
'type' => 'varchar',
// Support IPv6 as well as standard IPv4 addresses, e.g.
// 2001:0db8:0000:0000:0000:ff00:0042:8329
// http://en.wikipedia.org/wiki/IPv6
'length' => '64',
'not null' => TRUE,
),
'latitude' => array(
'description' => 'Latitude',
'type' => 'float',
'size' => 'big',
'not null' => FALSE,
),
'longitude' => array(
'description' => 'Longitude',
'type' => 'float',
'size' => 'big',
'not null' => FALSE,
),
'country' => array(
'description' => 'Country',
'type' => 'varchar',
'length' => 64,
'not null' => FALSE,
),
'country_code' => array(
'description' => 'ISO 3166 2-Character Country Code',
'type' => 'varchar',
'length' => 3,
'not null' => FALSE,
),
'region' => array(
'description' => 'Region',
'type' => 'varchar',
'length' => 64,
'not null' => FALSE,
),
'region_code' => array(
'description' => '2-Character Region Code',
'type' => 'varchar',
'length' => 3,
'not null' => FALSE,
),
'city' => array(
'description' => 'City',
'type' => 'varchar',
'length' => 64,
'not null' => FALSE,
),
'postal_code' => array(
'description' => 'Post code',
'type' => 'varchar',
'length' => 12,
'not null' => FALSE,
),
'locality' => array(
'description' => 'Suburb',
'type' => 'varchar',
'length' => 64,
'not null' => FALSE,
),
'route' => array(
'description' => 'Street',
'type' => 'varchar',
'length' => 64,
'not null' => FALSE,
),
'street_number' => array(
'description' => 'Street number',
'type' => 'varchar',
'length' => 32,
'not null' => FALSE,
),
'administrative_area_level_1' => array(
'description' => 'State or province',
'type' => 'varchar',
'length' => 64,
'not null' => FALSE,
),
'formatted_address' => array(
'description' => 'Address',
'type' => 'varchar',
'length' => 128,
'not null' => FALSE,
),
),
'primary key' => array('id'),
'indexes' => array(
'ip_address' => array('ip_address'),
),
);
return $schema;
}
// TODO The old hook_update_N functions cannot be applied to Backdrop.
function ip_geoloc_update_7125() { }
/**
* Implements hook_update_last_removed().
*/
function ip_geoloc_update_last_removed() {
return 7125;
}
/**
* Implements hook_update_N().
*/
function ip_geoloc_update_1000() {
$config = config('ip_geoloc.settings');
$config->set('ip_geoloc_auth_method', update_variable_get('ip_geoloc_auth_method', 'novalue'));
$config->set('ip_geoloc_apikey', update_variable_get('ip_geoloc_apikey', ''));
$config->set('ip_geoloc_client_id', update_variable_get('ip_geoloc_client_id', ''));
$config->set('ip_geoloc_signature', update_variable_get('ip_geoloc_signature', ''));
$config->set('ip_geoloc_marker_anchor_pos', update_variable_get('ip_geoloc_marker_anchor_pos', 'bottom'));
$config->set('ip_geoloc_num_location_marker_layers', update_variable_get('ip_geoloc_num_location_marker_layers', 'IP_GEOLOC_DEF_NUM_MARKER_LAYERS'));
$config->set('ip_geoloc_sync_batch_size', update_variable_get('ip_geoloc_sync_batch_size', '500'));
$config->set('ip_geoloc_allow_session_storage', update_variable_get('ip_geoloc_allow_session_storage', 'TRUE'));
$config->set('ip_geoloc_store_addresses', update_variable_get('ip_geoloc_store_addresses', 'TRUE'));
$config->set('ip_geoloc_google_to_reverse_geocode', update_variable_get('ip_geoloc_google_to_reverse_geocode', 'FALSE'));
$config->set('ip_geoloc_location_check_interval', update_variable_get('ip_geoloc_location_check_interval', 'IP_GEOLOC_LOCATION_CHECK_INTERVAL'));
$config->set('ip_geoloc_include_pages', update_variable_get('ip_geoloc_include_pages', '*'));
$config->set('ip_geoloc_exclude_pages', update_variable_get('ip_geoloc_exclude_pages', 'IP_GEOLOC_DEFAULT_PAGE_EXCLUSIONS'));
$config->set('ip_geoloc_roles_to_reverse_geocode', update_variable_get('ip_geoloc_roles_to_reverse_geocode', 'dynamic value in file /ip_geoloc/ip_geoloc.module line 510'));
$config->set('ip_geoloc_smart_ip_as_backup', update_variable_get('ip_geoloc_smart_ip_as_backup', 'FALSE'));
$config->set('ip_geoloc_throbber_text2', update_variable_get('ip_geoloc_throbber_text2', 'novalue'));
$config->set('ip_geoloc_page_refresh', update_variable_get('ip_geoloc_page_refresh', 'TRUE'));
$config->set('ip_geoloc_debug', update_variable_get('ip_geoloc_debug', 'novalue'));
$config->set('ip_geoloc_geo_vocabulary_id', update_variable_get('ip_geoloc_geo_vocabulary_id', 'novalue'));
$config->set('ip_geoloc_marker_directory', update_variable_get('ip_geoloc_marker_directory', 'dynamic value in file /ip_geoloc/ip_geoloc.module line 641'));
$config->set('ip_geoloc_marker_dimensions', update_variable_get('ip_geoloc_marker_dimensions', 'novalue'));
$config->set('ip_geoloc_font_icon_libi', update_variable_get('ip_geoloc_font_icon_libi', 'dynamic variable in file /ip_geoloc/ip_geoloc.module line 846'));
$config->set('ip_geoloc_return_address_street', update_variable_get('ip_geoloc_return_address_street', 'novalue'));
$config->set('ip_geoloc_return_address_locality', update_variable_get('ip_geoloc_return_address_locality', 'novalue'));
$config->set('ip_geoloc_return_address_country', update_variable_get('ip_geoloc_return_address_country', 'novalue'));
$config->set('ip_geoloc_visitor_reverse_geocode', update_variable_get('ip_geoloc_visitor_reverse_geocode', 'TRUE'));
$config->set('ip_geoloc_recent_visitors_map_number_of_visitors', update_variable_get('ip_geoloc_recent_visitors_map_number_of_visitors', '20'));
$config->set('ip_geoloc_delta_div_style', update_variable_get('ip_geoloc_delta_div_style', 'dynamic variable in file /ip_geoloc/ip_geoloc_blocks.inc line 359'));
$config->set('ip_geoloc_current_visitor_map_options', update_variable_get('ip_geoloc_current_visitor_map_options', 'IP_GEOLOC_CURRENT_VISITOR_MAP_OPTIONS'));
$config->set('ip_geoloc_recent_visitors_map_options', update_variable_get('ip_geoloc_recent_visitors_map_options', 'IP_GEOLOC_RECENT_VISITORS_MAP_OPTIONS'));
$config->set('ip_geoloc_visitor_find', update_variable_get('ip_geoloc_visitor_find', 'TRUE'));
$config->set('ip_geoloc_visitor_find_label', update_variable_get('ip_geoloc_visitor_find_label', ''));
$config->set('ip_geoloc_visitor_find_position', update_variable_get('ip_geoloc_visitor_find_position', 'novalue'));
$config->set('ip_geoloc_throbber_text', update_variable_get('ip_geoloc_throbber_text', ''));
$config->set('ip_geoloc_visitor_address_editable', update_variable_get('ip_geoloc_visitor_address_editable', 'TRUE'));
$config->set('ip_geoloc_visitor_address_label', update_variable_get('ip_geoloc_visitor_address_label', ''));
$config->set('ip_geoloc_address_element', update_variable_get('ip_geoloc_address_element', '2'));
$config->set('ip_geoloc_visitor_address_default', update_variable_get('ip_geoloc_visitor_address_default', ''));
$config->set('ip_geoloc_region_autocomplete', update_variable_get('ip_geoloc_region_autocomplete', 'novalue'));
$config->set('ip_geoloc_visitor_region_label', update_variable_get('ip_geoloc_visitor_region_label', ''));
$config->set('ip_geoloc_region_parent', update_variable_get('ip_geoloc_region_parent', 'novalue'));
$config->set('ip_geoloc_address_redirect', update_variable_get('ip_geoloc_address_redirect', 'novalue'));
$config->set('ip_geoloc_view_id_color_mappings', update_variable_get('ip_geoloc_view_id_color_mappings', 'dynamic variable in file /ip_geoloc/views/ip_geoloc_plugin_style.inc line 614'));
update_variable_del('ip_geoloc_auth_method');
update_variable_del('ip_geoloc_apikey');
update_variable_del('ip_geoloc_client_id');
update_variable_del('ip_geoloc_signature');
update_variable_del('ip_geoloc_marker_anchor_pos');
update_variable_del('ip_geoloc_num_location_marker_layers');
update_variable_del('ip_geoloc_sync_batch_size');
update_variable_del('ip_geoloc_allow_session_storage');
update_variable_del('ip_geoloc_store_addresses');
update_variable_del('ip_geoloc_google_to_reverse_geocode');
update_variable_del('ip_geoloc_location_check_interval');
update_variable_del('ip_geoloc_include_pages');
update_variable_del('ip_geoloc_exclude_pages');
update_variable_del('ip_geoloc_roles_to_reverse_geocode');
update_variable_del('ip_geoloc_smart_ip_as_backup');
update_variable_del('ip_geoloc_throbber_text2');
update_variable_del('ip_geoloc_page_refresh');
update_variable_del('ip_geoloc_debug');
update_variable_del('ip_geoloc_geo_vocabulary_id');
update_variable_del('ip_geoloc_marker_directory');
update_variable_del('ip_geoloc_marker_dimensions');
update_variable_del('ip_geoloc_font_icon_libi');
update_variable_del('ip_geoloc_return_address_street');
update_variable_del('ip_geoloc_return_address_locality');
update_variable_del('ip_geoloc_return_address_country');
update_variable_del('ip_geoloc_visitor_reverse_geocode');
update_variable_del('ip_geoloc_recent_visitors_map_number_of_visitors');
update_variable_del('ip_geoloc_delta_div_style');
update_variable_del('ip_geoloc_current_visitor_map_options');
update_variable_del('ip_geoloc_recent_visitors_map_options');
update_variable_del('ip_geoloc_visitor_find');
update_variable_del('ip_geoloc_visitor_find_label');
update_variable_del('ip_geoloc_visitor_find_position');
update_variable_del('ip_geoloc_throbber_text');
update_variable_del('ip_geoloc_visitor_address_editable');
update_variable_del('ip_geoloc_visitor_address_label');
update_variable_del('ip_geoloc_address_element');
update_variable_del('ip_geoloc_visitor_address_default');
update_variable_del('ip_geoloc_region_autocomplete');
update_variable_del('ip_geoloc_visitor_region_label');
update_variable_del('ip_geoloc_region_parent');
update_variable_del('ip_geoloc_address_redirect');
update_variable_del('ip_geoloc_view_id_color_mappings');
}