<?php

// Класс для тега [video]
class Xbb_Tags_Video extends bbcode {
    function get_html($tree = null) {
		$parsed_url=parse_url($this->tree[0]['str']);
		$width=intval($this->attrib['width'])?intval($this->attrib['width']):560;
		$height=intval($this->attrib['height'])?intval($this->attrib['height']):315;
		switch($parsed_url['host']) {
			case('www.youtube.com'):
				if (preg_match('/v=([a-z0-9\-_]+)/i', $parsed_url['query'], $result)) {
					return '<iframe width="'.$width.'" height="'.$height.'" src="https://www.youtube.com/embed/'.$result[1].'" frameborder="0" allowfullscreen></iframe>';
				}
			break;
			case('vimeo.com'):
				if (preg_match('/\/(\d+)/i', $parsed_url['path'], $result)) {
					return '<iframe src="//player.vimeo.com/video/'.$result[1].'" width="'.$width.'" height="'.$height.'" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>';
				}
			break;
		}
    }
}
?>