You are here

function _google_webfont_loader_api_cache in Webfont Loader 6

Downloads and caches the webfont.js file locally.

Parameters

string $location: The full URL to the external javascript file.

Return value

mixed The path to the local javascript file on success, boolean FALSE on failure.

1 call to _google_webfont_loader_api_cache()
google_webfont_loader_api_init in ./google_webfont_loader_api.module
Implements hook_init().

File

./google_webfont_loader_api.module, line 184
Google Webfont Loader API primary file The designer/developer creates a set of packages (will use .fontinfo files created in a similar manner to a module or theme .info file) from which the site admin can then choose for their site. The fonts can…

Code

function _google_webfont_loader_api_cache($location) {
  $directory = file_directory_path() . '/google_webfont_loader_api';
  $file_destination = $directory . '/' . basename($location);
  if (!file_exists($file_destination)) {
    $result = drupal_http_request($location);
    if ($result->code == 200) {

      // Check that the files directory is writable.
      if (file_check_directory($directory, FILE_CREATE_DIRECTORY)) {
        return file_save_data($result->data, $directory . '/' . basename($location), FILE_EXISTS_REPLACE);
      }
    }
  }
  else {
    return $file_destination;
  }
}