All pastes #2056667 Raw Edit

Untitled

public php v1 · immutable
#2056667 ·published 2011-05-11 09:07 UTC
rendered paste body
<?phpfunction handle_video_tag($videoUri) {	$match = array();	// dirty trick to play arround do_clickable	preg_match('`href="([^"]+)"`', stripslashes($videoUri), $match);	if(!empty($match[1])) {		$videoUri = $match[1];	}	// the services list	$service = array(		'youtube' => array(			'match'=>'`watch\?v=([-_a-z0-9]+)`i',			'uri'=>'http://www.youtube.com/v/%s&amp;rel=0',			'width'=>425,			'height'=>344		),		'dailymotion' => array(			'match'=>'`video/([a-z0-9]+)_`i',			'uri'=>'http://www.dailymotion.com/swf/%s&amp;amp;related=0&amp;amp;canvas=medium',			'width'=>480,			'height'=>381		),		'vimeo' => array(			'match'=>'`/([0-9]+)`',			'uri'=>'http://www.vimeo.com/moogaloop.swf?clip_id=%s&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;fullscreen=1',			'width'=>400,			'height'=>302		),		'google' => array(			'match'=>'`\?docid=(-?[0-9]+)`',			'uri'=>'http://video.google.com/googleplayer.swf?docId=%s',			'width'=>425,			'height'=>364		),		'metacafe' => array(			'match'=>'`watch/([a-z0-9\/]+)_`i',			'uri'=>'http://www.metacafe.com/fplayer/%s.swf',			'width'=>400,			'height'=>345		)	);	// extract service's name and check for support	preg_match('`^http://(?:[^\.]*\.)?([^\.]*)\.[^/]*/`i', $videoUri, $match);	if(empty($match[1]) || !array_key_exists($match[1], $service)) {		return '<a href="'.$videoUri.'">[video (unkown provider)]</a>';	}	$s = $service[$match[1]];	// extract videoId	preg_match($s['match'], $videoUri, $match);	if(empty($match[1])) {		return '<a href="'.$videoUri.'">[video (cant extract ID)]</a>';	}	$playerUri = sprintf($s['uri'], $match[1]);	// display flash player	return		'<object type="application/x-shockwave-flash" data="'.$playerUri.'" width="'.$s['width'].'" height="'.$s['height'].'">'.			'<param name="movie" value="'.$playerUri.'" />'.			'<param name="wmode" value="transparent" />'.			'<param name="allowfullscreen" value="true" />'.			'<p><a href="'.$videoUri.'">[video (flash player not installed)]</a></p>'.		'</object>';}