Embed YouTube Video


This is a simple plugin that enables you to embed a YouTube video into a wiki page.

Usage

When you view a video at YouTube there is a small box to the right of the video titled 'About this video'. There is a text box labeled URL that contains the URL you can use to share the video with others. NOTE: this plugin uses this URL as it's input - not the URL included in the object/embed tag.

{{youtube url="http://www.youtube.com/watch?v=XXXXXXXXXXX" [width="425" height="350" bgcolor="#ffffff"]}}


Install

Add youtube.php to the actions folder of your Wikka install.

Code

youtube.php (line 1)
  1. <?php
  2. /*
  3. YouTube plugin created by Grant Young for WWF-Australia.
  4.  
  5. USE: {{youtube url="http://www.youtube.com/watch?v=XXXXXXXXXXX" [width="425" height="350" bgcolor="#ffffff"]}}
  6.  
  7. 'url' must be provided, and is the URL specified in the 'About this video' section next to the video.
  8. 'width', 'height' and 'bgcolor' are all optional.  Defaults are listed above.
  9. */
  10.  
  11. if (!($url)) {
  12.     print "<strong>You must provide the YouTube url, including 'http://'.</strong>";
  13.     return;
  14. } else {
  15.     if (!$width)
  16.     {
  17.         $width = 425;
  18.     }
  19.     if (!$height)
  20.     {
  21.         $height = 350;
  22.     }
  23.     if (!$bgcolor)
  24.     {
  25.         $bgcolor = "#ffffff";
  26.     }
  27. }
  28.  
  29. // http://www.youtube.com/watch?v=LvU6UFF1_MA - if URL in this format, need to change to /v/LvU6UFF1_MA
  30. $ptn = "/watch\?v=([A-Za-z0-9_\-]{11})$/";
  31. if (preg_match($ptn, $url, $matches))
  32. {
  33.     $id = $matches[1];
  34. }
  35. else
  36. {
  37.     print "<strong>The provided URL was not in the correct format.</strong>";
  38.     return;
  39. }
  40.  
  41. print '<object type="application/x-shockwave-flash" data="http://www.youtube.com/v/'.$id.'" width="'.$width.'" height="'.$height.'" id="VideoPlayback">
  42.  <param name="movie" value="http://www.youtube.com/v/'.$id.'" />
  43.  <param name="allowScriptAccess" value="sameDomain" />
  44.  <param name="quality" value="best" />
  45.  <param name="bgcolor" value="'.$bgcolor.'" />
  46.  <param name="scale" value="noScale" />
  47.  <param name="FlashVars" value="playerMode=embedded" />
  48. </object>';
  49. ?>


There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki
Page was generated in 0.4668 seconds