You are here

function mobile_switch_requirements in Mobile Switch 7.2

Implements hook_requirements().

File

./mobile_switch.install, line 10
Install, update and uninstall functions for the Mobile Switch module.

Code

function mobile_switch_requirements($phase) {
  $requirements = array();
  $t = get_t();
  $requirements['mobile_detect']['value'] = '';
  switch ($phase) {
    case 'install':
    case 'update':

      // Ensure Mobile Detect class installed as library.
      require_once drupal_get_path('module', 'mobile_switch') . '/mobile_switch.module';
      $library['version'] = FALSE;
      $library_path = libraries_get_path(MOBILE_SWITCH_LIBRARY_NAME, $base_path = FALSE);
      $library_uri = $library_path . '/' . MOBILE_SWITCH_LIBRARY_FILE_NAME;
      if ($library_path && file_exists($library_uri)) {
        $library['version'] = mobile_switch_mobile_detect_get_version($library_uri);
      }
      if (!$library_path || !file_exists($library_uri) || !$library['version']) {
        $requirements['mobile_detect'] = array(
          'severity' => REQUIREMENT_ERROR,
          'description' => $t('<em>Mobile Detect PHP class</em> module: The Mobile Detect class could not be found. See README.txt for installation instructions.'),
        );
      }
      else {
        $requirements['mobile_detect'] = array(
          'severity' => REQUIREMENT_OK,
          'value' => $t('@version', array(
            '@version' => $library['version'],
          )),
        );
        variable_set('mobile_detect_import_library_uri', $library_uri);
      }
      break;
    case 'runtime':

      // Reports installed Mobile Detect class version.
      // Reports the availability of a new class version.
      $library = libraries_detect(MOBILE_SWITCH_LIBRARY_NAME);
      $library_import_version = variable_get('mobile_detect_import_version', 0);
      $value = $t('@version', array(
        '@version' => $library['version'],
      ));
      if ($library_import_version > 0) {
        if ($library_import_version > $library['version']) {
          $requirements['mobile_detect']['severity'] = REQUIREMENT_WARNING;
          $value .= '<br />' . $t('New Mobile Detect PHP class, version %new_version, available. See README.txt for installation instructions.', array(
            '%new_version' => $library_import_version,
          ));
        }
      }
      $requirements['mobile_detect']['value'] = $value;
      $requirements['mobile_detect']['title'] = $t('Mobile Detect PHP class');
      break;
  }
  return $requirements;
}