You are here

function bxslider_requirements in BxSlider 7

Same name and namespace in other branches
  1. 8 bxslider.install \bxslider_requirements()

Implements hook_requirements().

File

./bxslider.install, line 11
Installation file for BxSlider.

Code

function bxslider_requirements($phase) {
  $requirements = array();

  // Ensure translations don't break at install time.
  $t = get_t();
  if ($phase == 'runtime') {
    $path = libraries_get_path('bxslider');
    $ok = FALSE;
    $js = file_exists($path . '/jquery.bxslider.min.js') ? fopen($path . '/jquery.bxslider.min.js', 'r') : fopen($path . '/jquery.bxslider.js', 'r');
    $header = fread($js, 64);
    $matches = array();
    if (preg_match('/ v([0-9]+)\\.([0-9]+)\\.(.+)/', $header, $matches)) {
      if (intval($matches[1]) == 4) {
        $ok = TRUE;
      }
    }
    if ($ok) {
      $requirements['real_estate_bxslider'] = array(
        'title' => $t('bxSlider library'),
        'value' => $t('bxSlider version 4.@x1.@x2 is installed.', array(
          '@x1' => $matches[2],
          '@x2' => $matches[3],
        )),
        'severity' => REQUIREMENT_OK,
      );
    }
    else {
      $requirements['real_estate_bxslider'] = array(
        'title' => $t('bxSlider library'),
        'value' => $t("bxSlider library doesn't seem to be available or incorrect version. Required version 4.x.x."),
        'severity' => REQUIREMENT_ERROR,
        'description' => $t('
            bxSlider library version 4.x.x is required.<br/>
            See the <a href="@help_url">project page</a> for install instructions.<br/>
            Either:
            <ul>
            <li>
            Download the required libraries from
            <a href="@library_url">the bxSlider project</a>
            and place it in <code>@install_path</code>
            </li>
            </ul>', array(
          '@help_url' => url('https://drupal.org/project/bxslider'),
          '@library_url' => 'http://bxslider.com/lib/jquery.bxslider.zip',
          '@install_path' => 'sites/all/libraries/bxslider',
        )),
      );
    }
  }
  return $requirements;
}