function soembed_filter_embed in Simple oEmbed 7
Make request against provider to get embedded code.
1 string reference to 'soembed_filter_embed'
- soembed_filter_embed_process in ./
soembed.module - Implements hook_filter_FILTER_process().
File
- ./
soembed.module, line 92 - Lets author embed rich media by inserting URL using oEmbed techonology.
Code
function soembed_filter_embed($match) {
static $providers;
if (empty($providers)) {
module_load_include('inc', 'soembed', 'soembed.providers');
}
$url = $match[2];
foreach ($providers as $matchmask => $data) {
list($providerurl, $regex) = $data;
if (!$regex) {
$matchmask = '#' . str_replace('___wildcard___', '(.+)', preg_quote(str_replace('*', '___wildcard___', $matchmask), '#')) . '#i';
}
if (preg_match($matchmask, $url)) {
$provider = $providerurl;
break;
}
}
if (!empty($provider)) {
// http://www.php-code.net/2010/05/oembed-transforming-video-links-to-embeds/
// SEE FOR RESIZING MEDIA: https://gist.github.com/1313517
if ($regex === 'LOCAL') {
$output = soembed_get_contents($provider, $url);
}
elseif ($response = drupal_http_request($provider . '?url=' . urlencode($url) . '&format=json&maxwidth=' . variable_get('soembed_maxwidth', 0))) {
if ($response->code == 200) {
$embed = json_decode($response->data);
$embed_type = strtolower(str_replace(' ', '-', $embed->type));
if (!empty($embed->html)) {
$output = $embed->html;
}
elseif ($embed->type == 'photo') {
$output = '<img src="' . $embed->url . '" title="' . $embed->title . '" style="width: 100%" />';
$output = '<a href="' . $url . '">' . $output . '</a>';
}
}
}
}
$output = empty($output) ? $url : $output;
if ($embed_type != 'video' && count($match) > 3) {
// Add <p> and </p> back.
$output = $match[1] . $output . $match[3];
}
$output = '<div class="soembed-item ' . $embed_type . '">' . $output . '</div>';
return $output;
}