You are here

function video_embed_field_filter_process in Video Embed Field 7

Same name and namespace in other branches
  1. 7.2 video_embed_field.module \video_embed_field_filter_process()

Video Embed Field filter process callback

1 string reference to 'video_embed_field_filter_process'
video_embed_field_filter_info in ./video_embed_field.module
Implements hook_filter_info().

File

./video_embed_field.module, line 305

Code

function video_embed_field_filter_process($text, $filter, $format) {
  preg_match_all('/ \\[VIDEO:: ( [^\\[\\]]+ )* \\] /x', $text, $matches);
  $tag_match = (array) array_unique($matches[1]);
  $handlers = video_embed_get_handlers();
  foreach ($tag_match as $video_url) {

    // Add http if needed
    if (!stristr($video_url, 'http://') && !stristr($video_url, 'https://')) {
      $video_url = 'http://' . $video_url;
    }
    $parts = parse_url($video_url);

    // Make sure bad data won't mess everything up
    if (!isset($parts['host'])) {
      $embed_code = l($video_url, $video_url);
    }
    else {
      $host = $parts['host'];
      if (stripos($host, 'www.') > -1) {
        $host = substr($host, 4);
      }
      if (isset($handlers[$host]['function']) && function_exists($handlers[$host]['function'])) {
        $defaults = $handlers[$host]['defaults'];

        //TODO We need a way for people to configure how an embed works
        $embed_code = call_user_func($handlers[$host]['function'], $video_url, $defaults);
      }
      else {
        $embed_code = l($video_url, $video_url);
      }
    }
    $text = str_replace('[VIDEO::' . $video_url . ']', $embed_code, $text);
  }
  return $text;
}