You are here

function xbbcode_basic_render_youtube in Extensible BBCode 8.2

Same name and namespace in other branches
  1. 8 xbbcode_basic/xbbcode_basic.module \xbbcode_basic_render_youtube()
  2. 7 xbbcode_basic/xbbcode_basic.module \xbbcode_basic_render_youtube()
1 string reference to 'xbbcode_basic_render_youtube'
xbbcode_basic_xbbcode_info in xbbcode_basic/xbbcode_basic.module

File

xbbcode_basic/xbbcode_basic.module, line 214

Code

function xbbcode_basic_render_youtube($tag) {
  list($width, $height) = [
    560,
    315,
  ];
  if (preg_match('/^(\\d+)x(\\d+)$/', $tag->option, $match)) {
    list($width, $height) = [
      $match[1],
      $match[2],
    ];
  }
  else {
    $width = $tag
      ->attr('width') ? $tag
      ->attr('width') : $width;
    $height = $tag
      ->attr('height') ? $tag
      ->attr('height') : $height;
  }
  if (preg_match('/(\\/v\\/|((\\?|&amp;|&)v=))(?<id>.*?)(&|$)/', $tag->content, $match)) {
    $id = $match['id'];
  }
  else {
    $id = $tag->content;
  }
  return "<iframe width=\"{$width}\" height=\"{$height}\" src=\"http://www.youtube.com/embed/{$id}\" frameborder=\"0\" allowfullscreen></iframe>";
}