Download embed_youtube.php.txt
<?php
/******************************************
embed_youtube v1.1 (2007.06.25)
< cyber slug labs at g mail dot com >
http://cyberslug.net
to activate in your template, add this tag:
<lb:embed_youtube />
immediately prior to the tag that reads:
<lb:message />
now you can embed youtube videos or
playlists into the text of your post
using these tags:
<yt>video-id</yt>
<ytp>playlist-id</ytp>
(http://www.youtube.com/watch?v=video-id)
(http://www.youtube.com/view_play_list?p=playlist-id)
multiple videos ok, each on a seperate line
******************************************/
function embed_youtube ($content) {
global $postings, $currentid;
$tags = array();
$x = $postings[$currentid]['message_html'];
// quick-n-dirty SGML parser in 5 lines!
foreach(explode("\n", $x) as $key => $value) {
unset($m);
ereg("<yt(p)?>[^<]+</yt(p)?>", $value, $m);
if(isset($m[0])) {
$tags[$m[0]] = ereg_replace("<[\/]?yt(p)?>", "", $m[0]);
}
}
foreach($tags as $key => $id) {
if(ereg("<ytp>", $key)) {
$y = "<object width='530' height='370'>".
"<param name='movie' value='http://www.youtube.com/p/".
$id. "'></param><embed src='http://www.youtube.com/p/".
$id. "' type='application/x-shockwave-flash'".
" width='530' height='370'></embed></object>";
$x = str_replace("<ytp>".$id."</ytp>", $y, $x);
} else {
$y = "<object width='425' height='350'>".
"<param name='movie' value='http://www.youtube.com/v/".
$id. "'></param><embed src='http://www.youtube.com/v/".
$id. "' type='application/x-shockwave-flash'".
" width='425' height='350'></embed></object>";
$x = str_replace("<yt>".$id."</yt>", $y, $x);
}
}
$postings[$currentid]['message_html'] = $x;
return "";
}
?>