You are here

browscap.module in Browscap 8.3

Replacement for PHP's get_browser() function.

File

browscap.module
View source
<?php

/**
 * @file
 * Replacement for PHP's get_browser() function.
 */
use Drupal\Core\Url;
use Drupal\browscap\BrowscapEndpoint;
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function browscap_help($route_name, 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 @admin_link for the actual information.)', [
        '@admin_link' => Drupal::l('user agent statistics', Url::fromRoute('browscap.admin')),
      ]) . '</p>';
  }
}

/**
 * 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();
      \Drupal::service('browscap.importer')
        ->import($endpoint);

      // Record when the browscap information was updated.
      $config
        ->set('imported', REQUEST_TIME);
    }
  }
}

Functions

Namesort descending Description
browscap_cron Implements hook_cron().
browscap_help Implements hook_help().