You are here

mobile_detect_import.module in Mobile Switch 7.2

Update and import functions for the Mobile Detect PHP class.

The import funtions needs the enabled automatic version check or the manually Refresh Mobile detect action in the module administration.

File

modules/mobile_detect_import/mobile_detect_import.module
View source
<?php

/**
 * @file
 * Update and import functions for the Mobile Detect PHP class.
 *
 * The import funtions needs the enabled automatic version check or the
 * manually Refresh Mobile detect action in the module administration.
 */

// Include Mobile Detect class import functions.
include_once 'mobile_detect_import.import.inc';

/**
 * Implements hook_menu().
 */
function mobile_detect_import_menu() {
  $items['admin/config/user-interface/mobile-switch/mobile-detect-import'] = array(
    'title' => 'Mobile Detect',
    'description' => 'Configure Mobile Detect Import settings.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'mobile_detect_import_settings_form',
    ),
    'access callback' => 'mobile_switch_administer',
    'file' => 'mobile_detect_import.admin.inc',
    'type' => MENU_LOCAL_TASK,
    'weight' => -4,
  );
  return $items;
}

/**
 * Implements hook_cron().
 */
function mobile_detect_import_cron() {
  if (variable_get('mobile_detect_import_enable_automatic_updates', TRUE) == TRUE) {

    // Check the current update timer.
    $automatic_update_timer = variable_get('mobile_detect_import_automatic_updates_timer', 604800);

    // Check when the last update occurred.
    $last_imported = variable_get('mobile_detect_import_imported', REQUEST_TIME);

    // Update the Mobile Detect class file if the amount of time
    // specified by the update timer has passed.
    if ($last_imported + $automatic_update_timer < REQUEST_TIME) {

      // Update the Mobile Detect class file.
      _mobile_detect_import_import();

      // Record when the Mobile Detect class file was updated.
      variable_set('mobile_detect_import_imported', REQUEST_TIME);
    }
  }
}

/**
 * Implements hook_help().
 */
function mobile_detect_import_help($path, $arg) {
  switch ($path) {
    case 'admin/config/user-interface/mobile-switch/mobile-detect-import':
      return '<p>' . t('Mobile Detect - The lightweight PHP class for detecting mobile devices.') . '</p>';
    case 'admin/help#mobile_detect_import':
      return check_markup(file_get_contents(dirname(__FILE__) . '/README.txt'));
  }
}

Functions