View source
<?php
function oembed_oembed_response_alter(&$response) {
if ($response['type'] == 'rich' && $response['provider'] == 'default:soundcloud') {
$response['mime_type'] = 'audio/oembed';
foreach ($response as $key => $value) {
if (strpos($key, '-')) {
$new_key = strtr($key, array(
'-' => '_',
));
if (!isset($response[$new_key])) {
$response[$new_key] = $value;
}
}
}
}
if ($response['provider'] == 'default:slideshare' && empty($response['thumbnail_url']) && !empty($response['thumbnail'])) {
$response['thumbnail_url'] = $response['thumbnail'];
}
}
function oembed_provider_process(&$plugin, $info) {
$function = ctools_plugin_get_function($plugin, 'scheme callback');
if ($function) {
$schemes = array();
$plugin['scheme map'] = $function();
foreach ($plugin['scheme map'] as $id => $scheme) {
if (is_array($scheme)) {
$scheme = implode("\n", $scheme);
}
$schemes[] = $scheme;
$plugin['scheme map'][$id] = oembed_scheme_to_regex($scheme, $plugin['capture subpatterns']);
}
uasort($plugin['scheme map'], '_oembed_specificity_compare');
}
else {
if (is_array($plugin['scheme'])) {
$schemes = $plugin['scheme'];
}
else {
$schemes = array(
$plugin['scheme'],
);
}
}
if (!empty($schemes)) {
$plugin['scheme'] = implode("\n", $schemes);
$plugin['scheme'] = oembed_scheme_to_regex($plugin['scheme'], $plugin['capture subpatterns']);
if (empty($plugin['weight'])) {
$plugin['weight'] = strlen($plugin['scheme']);
}
}
}
function _oembed_specificity_compare($a, $b) {
return strlen($a) - strlen($b);
}
function oembed_scheme_to_regex($scheme, $capture_subpatterns = FALSE) {
$patterns = array();
$schemes = array_filter(preg_split("/(\r\n?|\n)/", $scheme));
foreach ($schemes as $scheme) {
$patterns[] = str_replace('\\*', $capture_subpatterns ? '(.*)' : '.*', preg_quote($scheme, '#'));
}
return '#' . implode('|', $patterns) . '#i';
}