Camen Design Forum

Video Embedding

rex

Currently I am using the following code in *theme.php*

Posted by *Martijn*

%

 foreach ($template->query('//article/div/p[a and count(*)=1 and not(normalize-space(text()))]') as $node) {
		$link = trim($node->nodeValue);
		$replace = false;

		if (
			preg_match('~(?:
				https?://(?:www\.)?youtu(?:be\.com/(?:embed/|watch\?(?:.+&)?v=)|\.be/)([a-z0-9_\-]+) # Parsing YouTube URLs.
				|
				(.+\.(?:png|jpe?g|gif)) # Parsing image URLs.
			)~ixA', $link, $matches)
		) {
			if (strlen($matches[1])) { // We found a YouTube video.
				$replace = '<iframe src="http://www.youtube-nocookie.com/embed/' . $matches[1] . '?autoplay=0&amp;rel=0" frameborder="0" allowfullscreen="allowfullscreen">' . safeHTML($link) . '</iframe>';
			} else if (strlen($matches[2])) { // We found an image link.
				$replace = '<a href="' . safeHTML($link) . '"><img src="' . $matches[2] . '" alt="' . safeHTML($link) . '" /></a>';
			}
		}

		if ($replace) {
			$frag = $node->ownerDocument->createDocumentFragment();
			if (!@$frag->appendXML($replace) || !@$node->parentNode->replaceChild($frag, $node)) {
				throw new Exception("Invalid HTML");
			}
		}
	}
%

My question is how do you go about adding support for other video services namely liveleak and vimeo?

Any help here would be greatly appreciated

Append

(Leave this as-is, it’s a trap!)

Only the original author or a moderator can append to this post.

Pro tip: Use markup to add links, quotes and more.

Your friendly neighbourhood moderators: Kroc, Impressed, Martijn