You are here

function oembedembedly_default_oembedcore_provider in oEmbed 6.0

Implementation of hook_default_oembedcore_provider().

File

./oembedembedly.module, line 29
Embed.ly support for oEmbed.module

Code

function oembedembedly_default_oembedcore_provider() {
  $providers = array();
  $cache = cache_get('oembedly');
  if ($cache && isset($cache->data)) {
    $json = $cache->data;
  }
  else {
    $json = drupal_http_request('http://api.embed.ly/1/services');
    if ($json->code == 200) {
      $json = json_decode($json->data);
    }
    else {
      $json = FALSE;
    }
    cache_set('oembedly', $json, 'cache', time() + 3600 * ($json ? 24 : 6));
    if (variable_get('oembedembedly_default', TRUE)) {
      cache_clear_all('oembedcore:providers', 'cache');
    }
  }
  if (is_array($json)) {
    foreach ($json as $embedly_provider) {
      $provider = new stdClass();
      $provider->disabled = !variable_get('oembedembedly_default', TRUE);
      $provider->name = 'oembedembedly_' . $embedly_provider->name;
      $provider->title = $embedly_provider->displayname . ' (Embed.ly)';
      $provider->endpoint = 'http://api.embed.ly/1/oembed';
      $provider->scheme = implode("\n", $embedly_provider->regex);
      $providers['oembedembedly_' . $embedly_provider->name] = $provider;
    }
  }
  return $providers;
}