FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » FUDforum Development » Plugins and Code Hacks » simple embed hack for youtube/polls/etc
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
simple embed hack for youtube/polls/etc [message #161885] Tue, 16 February 2010 20:41 Go to next message
XIXs is currently offline  XIXs   United Kingdom
Messages: 11
Registered: July 2004
Location: London
Karma: 0
Junior Member

This is a little fud forum hack I setup a while ago, I'm afraid I'm terribly behind keeping my fudforum upto date since the last time I tried an update things went badly. So it's not a plugin just some javascript for you to copypasta.

Here is a jqueery based hack that turns links posted in any forum msgs into appropriate embedded content. The content is chosen based on the link, so a link to a youtube video page turns into a youtube video embed, that sort of thing. Look at the code to see what sites are supported and add your own to support more, the available sites below are just what I needed.

Its horribly hacky and horribly simple and horribly useful Smile

Make sure jquery is included, eg <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> and add something like this into your main site template, personally I include the code as a separate js file but you could just copypasta the code below.

You can for instance see a polldady poll working here http://www.wetgenes.com/forum/index.php?t=msg&th=2430&start=0&r id=2

Hope its helpful to someone.

<script type="text/javascript">
// hit up jquery to update links into embeded things when document is ready

function expand_links()
{
	$(".MsgR3 a").each(
	function()
	{
	var width="600";
	var height="450";
	var link=$(this).attr("href");
	var linktype="unknown";
	var tail;
	var dots;
	var aa;
	var vid;
	var box;
	var megaupload;
	
		if(!link) { return; }
	
		dots=link.split(".");
		
		tail=dots[dots.length-1];
		tail=tail.toLowerCase();
	
		if( tail=="png" || tail=="gif" || tail=="jpg" )
		{
			linktype="image";
		}
		
		if(dots[1])
		{
			switch( dots[1].toLowerCase() )
			{
				case "youtube":
				
					vid=link.split("v=")[1];
					
					if(vid)
					{
						vid=vid.substr(0,11); // there are 11 chars in a you tube id
						linktype="youtube";
					}
				
				break;
				
				case "veoh":
				
					vid=link.split("permalinkId=")[1];
					
					if(vid)
					{
						vid=vid.split("&")[0]; // the id before the &
						vid=vid.split("\"")[0]; // the id before the "
						vid=vid.split("'")[0]; // the id before the '
						linktype="veoh";
					}
				
				break;
				
				case "polldaddy":
					if(tail=="js")
					{
						poll=link.split(".js")[0];
						poll=poll.split("/p/")[1];
					}
					else
					{
						poll=link.split("/");
						poll=poll[poll.length-1] ? poll[poll.length-1] : poll[poll.length-2];
					}
					if(poll)
					{
						linktype="polldaddy";
					}
				break;
			}
		}
		
		switch(linktype)
		{
			case "polldaddy":
			
				$(this).before("<a name=\"pd_a_"+poll+"\" style=\"display: inline; padding: 0px; margin: 0px;\"></a><div class=\"PDS_Poll\" id=\"PDI_container"+poll+"\"></div><script type=\"text/javascript\" charset=\"utf-8\" src=\"http://static.polldaddy.com/p/"+poll+".js\"></script><br />");
				
			break;
			
			case "image":
			
				$(this).before("<img src=\""+link+"\" width=\""+width+"\" /><br />");
				
			break;
			
			case "youtube":
			
				$(this).before(
'<object width="'+width+'" height="'+height+'"><param name="movie" value="http://www.youtube.com/v/'+vid+'&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/'+vid+'&hl=en&fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="'+width+'" height="'+height+'"></embed></object>'
				+"<br />"
				);
			
			break;
			
			case "veoh" :
			
				$(this).before(
'<embed src="http://www.veoh.com/static/swf/webplayer/WebPlayer.swf?version=AFrontend.5.4.3.1006&permalinkId='+vid+'&player=videodetailsembedded&videoAutoPlay=0&id=anonymous" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+width+'" height="'+height+'" ></embed>'
				+"<br />"
				);
			
			break;
			
		}
				
	});
}

// init if we have jquery available
if($)
{

$(document).ready(expand_links);
 
} 
</script>
Re: simple embed hack for youtube/polls/etc [message #161895 is a reply to message #161885] Wed, 17 February 2010 19:16 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3771
Registered: December 2004
Karma: 28
Senior Member
Administrator
Core Developer
It works quite well. Any reason why we cannot make this part of the main forum package?
Re : simple embed hack for youtube/polls/etc [message #161983 is a reply to message #161885] Wed, 03 March 2010 16:31 Go to previous messageGo to next message
fiz17 is currently offline  fiz17
Messages: 1
Registered: March 2010
Location: fr
Karma: 0
Junior Member
Hello,

Excuse me but...i don't understand how install this function (who as very interesting!)

It would be very kind from your part to help me to install this function.

In advance, thank you sirs (and excuse my dirty frenglish...).

Regards.

Philippe
Re: simple embed hack for youtube/polls/etc [message #162470 is a reply to message #161895] Sun, 16 May 2010 16:16 Go to previous messageGo to next message
XIXs is currently offline  XIXs   United Kingdom
Messages: 11
Registered: July 2004
Location: London
Karma: 0
Junior Member

The only mildly annoying thing about it is that it becomes impossible to just have links, links always get turned into embeds.

So if you wanted to list say 50 youtube links for some reason it would be nice to have a way to turn it off.

Apart from that I haven't hit any drawbacks from using it.

So yes, I'd say put it in the core rather than having special tags for various embeds. It's a simpler system, mostly since it is all client side, albeit slightly hacky.

I'll have a think about it I'll see if I can come up with something that works within the plugin architecture and is extendible. I think it probably belongs there.
Re: simple embed hack for youtube/polls/etc [message #162471 is a reply to message #162470] Sun, 16 May 2010 16:28 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3771
Registered: December 2004
Karma: 28
Senior Member
Administrator
Core Developer
If it works well we can make it an "official" plugin that admins can enable or disable. It don't think, however, that it belongs in core.

Best regards.

Frank
Re: simple embed hack for youtube/polls/etc [message #162517 is a reply to message #161885] Sun, 30 May 2010 14:58 Go to previous message
Ernesto is currently offline  Ernesto   Sweden
Messages: 413
Registered: August 2005
Karma: 0
Senior Member
I actually caved in and wrote a snip for youtube embedding. Embedding is slightly annoying though hehe, but i figured why the hell not.

The code looks like this and its ugly, very very ugly:

In the file DATA_ROOT/src/post_proc.inc.t

After the part that contains:
case 'wikipedia':
bla bla
break;

				case 'youtube':
					$url = substr($str, $epos+1, $cpos-1-$epos);
					
					$url = str_replace("/watch?v=","",$url);
					$url = str_replace("www.","",$url);
					$url = str_replace("http://","",$url);
					$url = str_replace("/v/","",$url);
					$url = str_replace("youtube.com","",$url);
					$url = substr($url, 0, strpos("$url&", "&"));
					$url = substr($url, 0, strpos("$url%", "%"));
					$ostr .= '<object width="720" height="480"><param name="movie" value="http://www.youtube.com/v/'.$url.'"></param><embed src="http://www.youtube.com/v/'.$url.'&amp;fs=1&amp;hd=1&amp;iv_load_policy=3&amp;color1=0x999999&amp;color2=0xF3F2E7" type="application/x-shockwave-flash"  allowscriptaccess="always" allowfullscreen="true" width="720" height="480"></embed></object>';
					$epos = $cepos;
					break;



and then after:
	array(
		'[b]', '[/b]', '[i]', '[/i]', '[u]', '[/u]', '[s]', '[/s]', '[sub]', '[/sub]', '[sup]', '[/sup]', '[del]', '[/del]', 
		'[code]', '[/code]', '[align=center]', '[align=left]', '[align=right]', '[/align]', '[list]', '[/list]',
		'[notag]', '[/notag]', '[*]', '@', '://', '', '[pre]', '[/pre]','[hr]'
	),
	$fudml);

input
while (preg_match('!<object width="720" height="480"><param name="movie" value="(.*?)"></param><embed src="(.*?)" type="application/x-shockwave-flash"  allowscriptaccess="always" allowfullscreen="true" width="720" height="480"></embed></object>!is', $fudml)) {
		$fudml = preg_replace('!<object width="720" height="480"><param name="movie" value="(.*?)"></param><embed src="(.*?)" type="application/x-shockwave-flash"  allowscriptaccess="always" allowfullscreen="true" width="720" height="480"></embed></object>!is', '[youtube]\1[/youtube]', $fudml);
	}


[Updated on: Sun, 30 May 2010 14:58]

Report message to a moderator

  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: ML/FUD Forum Gateway - Import archives of a mailing-list
Next Topic: New plugin call hook type & OpenID plugin
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 11:59:01 GMT 2024

Total time taken to generate the page: 0.02422 seconds