Your IP : 172.71.120.3


Current Path : /var/www/element/data/www/wiki.element.ru/extensions/
Upload File :
Current File : /var/www/element/data/www/wiki.element.ru/extensions/YouTube.php

<?php
# YouTube Videos
# 
# Tag:
#   <youtube>v</youtube>
# Ex:
#   from url http://www.youtube.com/watch?v=WZpeeRSk-0A
#   <youtube>WZpeeRSk-0A</youtube>
# 
# Enjoy!
 
$wgExtensionFunctions[] = 'wfYouTube';
$wgExtensionCredits['parserhook'][] = array(
	'name' => 'YouTube',
	'description' => 'Display YouTube video',
	'author' => 'Sylvain Machefert',
	'url' => 'http://www.mediawiki.org/wiki/Extension:YouTube_(Iubito)'
);
 
function wfYouTube() {
	global $wgParser;
	$wgParser->setHook('youtube', 'renderYouTube');
}
 
# The callback function for converting the input text to HTML output
function renderYouTube($input, $argv) {
		//$input = "WZpeeRSk-0A"
 
		if (@$argv['align']!='left' and @$argv['align']!='right')
		{
			$align = 'right';
		}else{
			$align = $argv['align'];
		}
 
		if (@$argv['size'])
		{
			switch($argv['size'])
			{
				case 'small':
					$width = 210;
					$height = 175;
					break;
				case 'medium':
					$width = 330;
					$height = 260;
					break;
				case 'normal':
					$width = 425;
					$height = 350;
					break;
				case 'big':
					$width = 640;
					$height = 525;
					break;
				default:
					$width = 425;
					$height = 350;
					break;
			}
		}else{
			if (@$argv['width'])
				$width = $argv['width'];
			else
				$width = 425;
 
			if (@$argv['height'])
				$height = $argv['height'];
			else
				$height = 350;
		}
 
		//Validate the video ID
		if (preg_match('%[^A-Za-z0-9_\\-]%',$input)) {
				return 'YouTube : bad video ID !';
		}
 
		$url = 'http://www.youtube.com/v/' . $input;
		$output =
			Xml::openElement( 'object',
				array(
					'align' => $align,
					'width' => $width,
					'height' => $height ) ) .
			Xml::openElement( 'param',
				array(
					'name' => 'movie',
					'value' => $url ) ) .
			'</param>' .
			Xml::openElement( 'embed',
				array(
					'src' => $url,
					'type' => 'application/x-shockwave-flash',
					'wmode' => 'transparent',
					'width' => $width,
					'height' => $height ) ) .
			'</embed>' .
			'</object>';
 
		return $output;
}