function bootstrap_cdn_provider

8.x-3.x deprecated.php bootstrap_cdn_provider($provider = NULL, $reset = FALSE)
7.x-3.x cdn.inc bootstrap_cdn_provider($provider = NULL, $reset = FALSE)

Retrieves a list of available CDN providers for the Bootstrap framework.

Parameters

string $provider: A specific provider data to return.

bool $reset: Toggle determining whether or not to reset the database cache.

Return value

array|false An associative array of CDN providers, keyed by their machine name if $provider is not set. If $provider is set and exists, its individual data array will be returned. If $provider is set and the data does not exist then FALSE will be returned.

Source includes/cdn.inc (line 62)

function bootstrap_cdn_provider($provider = NULL, $reset = FALSE) {
  $original_provider = $provider;

  // Use the advanced drupal_static() pattern, since this is called very often.
  static $drupal_static_fast;
  if (!isset($drupal_static_fast)) {
    $drupal_static_fast['providers'] = &drupal_static(__FUNCTION__);
  }
  $providers = &$drupal_static_fast['providers'];
  if ($reset || !isset($providers)) {
    $provider_path = BOOTSTRAP_CDN_PROVIDER_PATH;
    file_prepare_directory($provider_path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);

    $cid = 'theme_registry:bootstrap:cdn_providers';
    if (($cached = cache_get($cid)) && !empty($cached->data)) {
      $providers = $cached->data;
    }
    if ($reset || !isset($providers)) {
      $providers = array(
        'custom' => array(
          'title' => t('Custom'),
        ),
        'jsdelivr' => array(
          'title' => t('jsDelivr'),
          'description' => t('<p><a href="!jsdelivr" target="_blank">jsDelivr</a> is a free multi-CDN infrastructure that uses <a href="!maxcdn" target="_blank">MaxCDN</a>, <a href="!cloudflare" target="_blank">Cloudflare</a> and many others to combine their powers for the good of the open source community... <a href="!jsdelivr_about" target="_blank">read more</a></p>', array(
            '!jsdelivr' => 'https://www.jsdelivr.com',
            '!jsdelivr_about' => 'https://www.jsdelivr.com/about',
            '!maxcdn' => 'https://www.maxcdn.com',
            '!cloudflare' => 'https://www.cloudflare.com',
          )),
        ),
      );

      // Defaults properties each provider must have.
      $defaults = array(
        'api' => NULL,
        'css' => array(),
        'description' => NULL,
        'error' => FALSE,
        'js' => array(),
        'imported' => FALSE,
        'min' => array(
          'css' => array(),
          'js' => array(),
        ),
        'title' => NULL,
      );

      // Process the providers.
      foreach ($providers as $name => &$data) {
        $data += $defaults;
        $data['name'] = $name;
        if (empty($name)) {
          continue;
        }

        // Use manually imported API data, if it exists.
        $request = NULL;
        if (!empty($data['api']) && file_exists("$provider_path/$name.json") && ($imported_data = file_get_contents("$provider_path/$name.json"))) {
          $data['imported'] = TRUE;
          $request = new stdClass();
          $request->code = '200';
          $request->data = $imported_data;
        }
        // Otherwise, attempt to request API data if the provider has specified
        // an "api" URL to use.
        elseif (!empty($data['api'])) {
          $request = drupal_http_request($data['api']);
        }

        // Skip alter (processing) if using backported CDN Provider logic.
        if ($instance = _bootstrap_backport_cdn_provider(NULL, $name)) {
          // Go ahead and use its description and label though.
          $data['description'] = $instance->getDescription();
          $data['title'] = $instance->getLabel();
          continue;
        }

        // Alter the specific provider.
        $function = 'bootstrap_bootstrap_cdn_provider_' . $name . '_alter';
        if (function_exists($function)) {
          $function($data, $request);
        }
      }
      cache_set($cid, $providers);
    }
  }
  if (isset($original_provider)) {
    if (!isset($providers[$original_provider])) {
      return FALSE;
    }
    return $providers[$original_provider];
  }
  return $providers;
}