function _oembed_field_extract_urls in oEmbed 8
Same name and namespace in other branches
- 7 oembed.filter.inc \_oembed_field_extract_urls()
- 7.0 oembed.filter.inc \_oembed_field_extract_urls()
Extract all URLs for oEmbed to process.
Returns an array of URLs grouped by field, delta, and column.
1 call to _oembed_field_extract_urls()
- oembed_field_attach_validate in ./
oembed.filter.inc - Implements hook_field_attach_validate().
File
- ./
oembed.filter.inc, line 50 - Input filter that enhances oEmbed enabled URLs with extra content
Code
function _oembed_field_extract_urls($entity_type, $entity) {
$urls = array();
// Determine if any formats use oEmbed filter.
$filter_settings = array();
foreach (filter_formats() as $format) {
$filters = filter_list_format($format->format);
if (isset($filters['oembed']) && $filters['oembed']->status) {
$filter_settings[$format->format] = $filters['oembed']->settings;
}
}
if (!empty($filter_settings)) {
list(, , $bundle) = entity_extract_ids($entity_type, $entity);
$instances = field_info_instances($entity_type, $bundle);
foreach ($instances as $info) {
// All text fields have a text_processing setting. Only search text fields with
// text processing enabled.
if (isset($info['settings']['text_processing']) && $info['settings']['text_processing']) {
$items = field_get_items($entity_type, $entity, $info['field_name']);
if (!$items) {
continue;
}
foreach ($items as $delta => $item) {
if (isset($filter_settings[$item['format']])) {
// URLs may be contained within the other column values.
foreach (array(
'value',
'summary',
) as $column) {
if (!empty($item[$column])) {
$text = $item[$column];
// copied from oembed_filter_oembed_prepare().
if ($filter_settings[$item['format']]['autoembed']) {
$text = preg_replace_callback(OEMBED_PATTERN_AUTOEMBED, 'oembed_preg_auto_replace', $text);
}
// copied from oembed_filter_oembed_process().
$matches = array();
preg_match_all(OEMBED_PATTERN_EMBED_SHORTCODE, $text, $matches);
$urls[$info['field_name']][$delta][$column] = array_filter($matches[3], '_oembed_field_filter_urls');
}
}
}
}
}
}
}
return $urls;
}