<?php

	class YoutubeModel {

		public static function isValidYoutubeLink( $url ) {
			$youtube_prefix = "http://www.youtube.com/";
			if (strpos( $url , $youtube_prefix )!==0) return false;
			return true;
		}

		public static function extractVideoIdFromLink( $url ) {
			$u = parse_url( $url );
			if (!isset( $u["query"] )) return false;
			$a = array();
			parse_str( $u["query"] , $a );
			if (!isset( $a["v"] )) return false;
			return $a["v"];
		}

		public static function embedLink( $url ) {
			if (!self::isValidYoutubeLink( $url )) return "";
			$width = 480;
			$height = 385;
			$yt = self::extractVideoIdFromLink( $url );
			if (!strlen( $yt )) return "";
			$retval =  sprintf( "<object width=\"%d\" height=\"%d\"><param name=\"movie\" value=\"http://www.youtube.com/v/%s?fs=1&amp;hl=hu_HU\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/%s?fs=1&amp;hl=hu_HU\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"%d\" height=\"%d\"></embed></object>",
				$width,
				$height,
				$yt,
				$yt,
				$width,
				$height );
			return $retval;
		}
	}
?>
