I’ve been using youtube bracket for wp for long time.
Based on that Idea I isolated it to make it work at any installation.
This script allows you to write anywhere in your content this and will return a flash player with the video embed.
Function that embeds the flash in the content:
$content=mediaPostDesc($content);//usage
function mediaPostDesc($the_content){//from a description add the media
//using http://www.robertbuzink.nl/journal/2006/11/23/youtube-brackets-wordpress-plugin/
if (VIDEO){
$stag = "";
$spos = strpos($the_content, $stag);
if ($spos !== false){
$epos = strpos($the_content, $etag, $spos);
$spose = $spos + strlen($stag);
$slen = $epos - $spose;
$file = substr($the_content, $spose, $slen);
//youtube
$tags = '';
$new_content = substr($the_content,0,$spos);
$new_content .= $tags;
$new_content .= substr($the_content,($epos+1));
if ($epos+1 < strlen($the_content)) {//reciproco
$new_content = mediaPostDesc($new_content);
}
return $new_content;
}
else return $the_content;
}
else return $the_content;
}
But if we allow users to insert this code, why not make it easier to them?
HTML that we need, to previsualize the video:
Youtube Video:
JavaScript to insert youtube URL:
function youtubePrompt(){
vurl=prompt('Youtube.com URL','http://www.youtube.com/watch?v=XXXXXXX');
if(vurl.indexOf("http://www.youtube.com/watch?v=")==0){
document.getElementById('video').value=vurl;
file=vurl.substr(31,vurl.length);
tags = "";
document.getElementById('youtubeVideo').innerHTML=tags;
}
else {
document.getElementById('video').value="";
document.getElementById('youtubeVideo').innerHTML="";
}
}
Example of php code to insert it in our content:
if (strpos($_POST["video"], "http://www.youtube.com/watch?v=")==0) $desc.='.']';//youtube video
// then insert in DB
This feature it is already planned for OC 1.6.3 😉