-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrowscap.module
45 lines (39 loc) · 1.4 KB
/
browscap.module
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
<?php
/**
* @file
* Replacement for PHP's get_browser() function.
*/
use \Drupal\browscap\BrowscapImporter;
use \Drupal\Core\Url;
use Drupal\browscap\BrowscapEndpoint;
/**
* Implements hook_help().
*/
function browscap_help($route_name, \Drupal\Core\Routing\RouteMatchInterface $route_match) {
switch ($route_name) {
case 'browscap.admin':
return '<p>' . t('Settings for user agent detection and the log that Browscap will keep about user agents that visit the site. See ' . Drupal::l('user agent statistics', Url::fromRoute('browscap.admin')) . ' for the actual information.') . '</p>';
break;
}
}
/**
* Implements hook_cron().
*/
function browscap_cron() {
$config = \Drupal::configFactory()->getEditable('browscap.settings');
if ($config->get('enable_automatic_updates') == TRUE) {
// Check the current update timer
$automatic_update_timer = $config->get('automatic_updates_timer');
// Check when the last update occurred
$last_imported = $config->get('imported');
// Update the browscap data if the amount of time specified by the update
// timer has passed
if (($last_imported + $automatic_update_timer) < REQUEST_TIME) {
// Update the browscap information
$endpoint = new BrowscapEndpoint();
BrowscapImporter::import($endpoint);
// Record when the browscap information was updated
$config->set('imported', REQUEST_TIME);
}
}
}