You are here

function _vars_check_remote_directory in Variable API 7.2

1 string reference to '_vars_check_remote_directory'
Vars::getLibraryPath in ./vars.classes.inc
Returns the list of the directories where library files are looked in.

File

./vars.module, line 143
Implements an API to handle persistent variables.

Code

function _vars_check_remote_directory($dir, array $files) {
  $codes = array(
    200,
    301,
    302,
    307,
  );
  if (empty($dir) && !valid_url($dir, TRUE)) {
    return FALSE;
  }
  $info = @parse_url($dir);
  if (!empty($info)) {
    if (empty($info['scheme']) || !preg_match('/https?/i', $info['scheme'])) {
      return FALSE;
    }
    $url = $info['scheme'] . '://';
    if (!empty($info['user'])) {
      $url .= $info['user'];
    }
    if (!empty($info['pass'])) {
      $url .= ':' . $info['pass'];
    }
    if (!empty($info['user'])) {
      $url .= '@';
    }
    $url .= $info['host'];
    if (!empty($info['port'])) {
      $url .= ':' . $info['port'];
    }
    $url .= '/';
    if (!empty($info['path'])) {
      $path = implode('/', preg_grep('/^\\.{0,2}$/', explode('/', $info['path']), PREG_GREP_INVERT));
      if (!empty($path)) {
        $url .= $path . '/';
      }
    }
    foreach ($files as $file) {
      $filename = implode('/', preg_grep('/^\\.{0,2}$/', explode('/', $file), PREG_GREP_INVERT));
      $result = drupal_http_request($url . $filename);
      if (!in_array($result->code, $codes) && empty($result->data)) {
        return FALSE;
      }
    }
  }
  else {
    return FALSE;
  }
}