You are here

function _flexslider_requirements_library_installed in Flex Slider 7

Check if the library is available

Parameters

array $requirements: Requirements definition

1 call to _flexslider_requirements_library_installed()
flexslider_requirements in ./flexslider.install
Implements hook_requirements().

File

./flexslider.install, line 149
Installation actions for Flex Slider

Code

function _flexslider_requirements_library_installed(&$requirements) {
  $t = get_t();
  $path = libraries_get_path('flexslider');
  $installed = file_exists($path . '/jquery.flexslider-min.js') && file_exists($path . '/jquery.flexslider.js');

  // Check the results of the test
  if (!$installed) {
    $requirements['flexslider']['description'] = $t('Flex Slider library not found. Please consult the README.txt for installation instructions.');
    $requirements['flexslider']['severity'] = REQUIREMENT_ERROR;
    $requirements['flexslider']['value'] = $t('Flex Slider library not found.');
    return;
  }
  $js = file_exists($path . '/jquery.flexslider-min.js') ? fopen($path . '/jquery.flexslider-min.js', 'r') : fopen($path . '/jquery.flexslider.js', 'r');
  $header = fread($js, 64);
  $matches = array();
  if (preg_match("/ v([0-9]+)\\.([0-9]+)/", $header, $matches)) {
    if (!($matches[1] == 1 and $matches[2] >= 8)) {
      $requirements['flexslider']['description'] = $t('Flex Slider must be version 1.8 or higher, but lower than version 2.0.  Please consult the README.txt for installation instructions.');
      $requirements['flexslider']['severity'] = REQUIREMENT_WARNING;
      $requirements['flexslider']['value'] = $t('Incorrect version detected.');
      return;
    }
    else {
      $requirements['flexslider']['description'] = $t('Version %version installed', array(
        '%version' => $matches[1] . "." . $matches[2],
      ));
      $requirements['flexslider']['value'] = $t('Flex Slider library installed.');
      return;
    }
  }
  else {
    $requirements['flexslider']['description'] = $t('Flex Slider version could not be determined.  Please consult the README.txt for installation instructions.');
    $requirements['flexslider']['severity'] = REQUIREMENT_WARNING;
    $requirements['flexslider']['value'] = $t('Unable to detect version.');
  }
}