You are here

function oembed_oembed_response_alter in oEmbed 7

Same name and namespace in other branches
  1. 8 oembed.oembed.inc \oembed_oembed_response_alter()
  2. 7.0 oembed.oembed.inc \oembed_oembed_response_alter()

Implement hook_oembed_response_alter().

File

./oembed.oembed.inc, line 6

Code

function oembed_oembed_response_alter(&$response) {

  // Soundcloud rich responses are audio players that should be re-cast as audio files.
  if ($response['type'] == 'rich' && $response['provider'] == 'default:soundcloud') {
    $response['mime_type'] = 'audio/oembed';

    // Soundcloud responses also mistake the thumbnail url property name.
    foreach ($response as $key => $value) {
      if (strpos($key, '-')) {
        $new_key = strtr($key, array(
          '-' => '_',
        ));
        if (!isset($response[$new_key])) {
          $response[$new_key] = $value;
        }
      }
    }
  }

  // Slideshare sets thumbnail URL on the wrong property.
  if ($response['provider'] == 'default:slideshare' && empty($response['thumbnail_url']) && !empty($response['thumbnail'])) {
    $response['thumbnail_url'] = $response['thumbnail'];
  }
}