Full ELMS Learning Network documentation
function _video_filter_process
cis7 video_filter.module | _video_filter_process($text, $filter, $format, $langcode, $cache, $cache_id) |
cle7 video_filter.module | _video_filter_process($text, $filter, $format, $langcode, $cache, $cache_id) |
elmsmedia7 video_filter.module | _video_filter_process($text, $filter, $format, $langcode, $cache, $cache_id) |
icor7 video_filter.module | _video_filter_process($text, $filter, $format, $langcode, $cache, $cache_id) |
meedjum_blog7 video_filter.module | _video_filter_process($text, $filter, $format, $langcode, $cache, $cache_id) |
mooc7 video_filter.module | _video_filter_process($text, $filter, $format, $langcode, $cache, $cache_id) |
1 string reference to '_video_filter_process'
- video_filter_filter_info in sites/
all/ modules/ ulmus/ video_filter/ video_filter.module - Implements hook_filter_info().
File
- sites/
all/ modules/ ulmus/ video_filter/ video_filter.module, line 119 - Video filter is a highly flexible and easy extendable filter module to embed any type of video in your site using a simple tag.
Code
function _video_filter_process($text, $filter, $format, $langcode, $cache, $cache_id) {
if (preg_match_all('/\[video(\:(.+))?( .+)?\]/isU', $text, $matches_code)) {
foreach ($matches_code[0] as $ci => $code) {
$video = array(
'source' => $matches_code[2][$ci],
'autoplay' => $filter->settings['video_filter_autoplay'],
'related' => $filter->settings['video_filter_related'],
);
// Pick random out of multiple sources separated by comma (,).
if (strstr($video['source'], ',')) {
$sources = explode(',', $video['source']);
$random = array_rand($sources, 1);
$video['source'] = $sources[$random];
}
// Load all codecs.
$codecs = video_filter_get_codec_info();
// Find codec.
foreach ($codecs as $codec_name => $codec) {
if (!is_array($codec['regexp'])) {
$codec['regexp'] = array($codec['regexp']);
}
// Try different regular expressions.
foreach ($codec['regexp'] as $delta => $regexp) {
if (preg_match($regexp, $video['source'], $matches)) {
$video['codec'] = $codec;
$video['codec']['delta'] = $delta;
$video['codec']['matches'] = $matches;
// Used in theme function:
$video['codec']['codec_name'] = $codec_name;
break 2;
}
}
}
// Codec found.
if (isset($video['codec'])) {
// Override default attributes.
if ($matches_code[3][$ci] && preg_match_all('/\s+([a-zA-Z_]+)\:(\s+)?([0-9a-zA-Z\/]+)/i', $matches_code[3][$ci], $matches_attributes)) {
foreach ($matches_attributes[0] as $ai => $attribute) {
$video[$matches_attributes[1][$ai]] = $matches_attributes[3][$ai];
}
}
// Use configured ratio if present, otherwise use that from the codec,
// if set. Fall back to 1.
$ratio = 1;
if (isset($video['ratio']) && preg_match('/(\d+)\/(\d+)/', $video['ratio'], $tratio)) {
// Validate given ratio parameter.
$ratio = $tratio[1] / $tratio[2];
}
elseif (isset($video['codec']['ratio'])) {
$ratio = $video['codec']['ratio'];
}
// Sets video width & height after any user input has been parsed.
// First, check if user has set a width.
if (isset($video['width']) && !isset($video['height'])) {
$video['height'] = $filter->settings['video_filter_height'];
}
// Else, if user has set height.
elseif (isset($video['height']) && !isset($video['width'])) {
$video['width'] = $video['height'] * $ratio;
}
// Maybe both?
elseif (isset($video['height']) && isset($video['width'])) {
$video['width'] = $video['width'];
$video['height'] = $video['height'];
}
// Fall back to defaults.
elseif (!isset($video['height']) && !isset($video['width'])) {
$video['width'] = $filter->settings['video_filter_width'] != '' ? $filter->settings['video_filter_width'] : 400;
$video['height'] = $filter->settings['video_filter_height'] != '' ? $filter->settings['video_filter_height'] : 400;
}
// Default value for control bar height.
$control_bar_height = 0;
if (isset($video['control_bar_height'])) {
// Respect control_bar_height option if present.
$control_bar_height = $video['control_bar_height'];
}
elseif (isset($video['codec']['control_bar_height'])) {
// Respect setting provided by codec otherwise.
$control_bar_height = $video['codec']['control_bar_height'];
}
// Resize to fit within width and height repecting aspect ratio.
if ($ratio) {
$scale_factor = min(array(
($video['height'] - $control_bar_height),
$video['width'] / $ratio,
));
$video['height'] = round($scale_factor + $control_bar_height);
$video['width'] = round($scale_factor * $ratio);
}
$video['autoplay'] = (bool) $video['autoplay'];
$video['align'] = (isset($video['align']) && in_array($video['align'], array(
'left',
'right',
'center',
))) ? $video['align'] : NULL;
// Let modules have final say on video parameters.
drupal_alter('video_filter_video', $video);
if (isset($video['codec']['html5_callback']) && $filter->settings['video_filter_html5'] == 1 && is_callable($video['codec']['html5_callback'], FALSE)) {
$replacement = call_user_func($video['codec']['html5_callback'], $video);
}
elseif (is_callable($video['codec']['callback'], FALSE)) {
$replacement = call_user_func($video['codec']['callback'], $video);
}
else {
// Invalid callback.
$replacement = '<!-- VIDEO FILTER - INVALID CALLBACK IN: ' . $pattern . ' -->';
}
}
// Invalid format.
else {
$replacement = '<!-- VIDEO FILTER - INVALID CODEC IN: ' . $code . ' -->';
}
$text = str_replace($code, $replacement, $text);
}
}
return $text;
}