Source for file video.php

Documentation is available at video.php

  1. <?php
  2. // This file is part of the Sloodle project (www.sloodle.org) and is released under the GNU GPL v3.
  3.  
  4. /**
  5. * Defines the SLOODLE Presenter plugin for showing video slides.
  6. *
  7. @package sloodle
  8. @copyright Copyright (c) 2009 Sloodle (various contributors)
  9. @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  10. @since Sloodle 0.4.1
  11. *
  12. @contributor Peter R. Bloomfield
  13. @contributor dz questi (YouTube link conversion)
  14. *
  15. */
  16.  
  17.  
  18. /**
  19. * Presenter plugin for showing video slides.
  20. *
  21. @package sloodle
  22. */
  23. {
  24.  
  25.     /**
  26.     * Construct an absolute URL, based on the given source data.
  27.     * Leaves existing absolute URLs alone, but converts relative URLs as necessary.
  28.     * (This allows the site to be moved without disrupting these slides.)
  29.     * @param string $source The source data from the slide.
  30.     * @return string An absolute URL.
  31.     */
  32.     function get_absolute_url($source)
  33.     {
  34.         global $CFG;
  35.         // If we have a protocol specifier, then assume this is already an absolute URL
  36.         if (strpos($source'://'!== falsereturn $source;
  37.         // Assume the source URL is relative to the Moodle WWW root.
  38.         // Make sure we don't duplicate a forward slash.
  39.         if (strpos($source'/'=== 0return $CFG->wwwroot.$source;
  40.         return $CFG->wwwroot.'/'.$source;
  41.     }
  42.  
  43.     /**
  44.     * Render the given slide for browser output -- NOTE: render to a string, and return the string.
  45.     * The title of the slide need not be included -- simply the basic iFrame or embedded player etc.
  46.     * @param SloodlePresenterSlide $slide An object containing the raw slide data.
  47.     * @return string 
  48.     */
  49.     function render_slide_for_browser($slide)
  50.     {
  51.         $url $this->get_absolute_url($slide->source);
  52.         $framewidth 500;
  53.         $frameheight 500;
  54.         if (isset($this->presenter)) {
  55.             $framewidth $this->presenter->get_frame_width();
  56.             $frameheight $this->presenter->get_frame_height();
  57.         }
  58.         
  59.         // Check to see if we can use a proper embedded player from a video sharing site
  60.         if (strpos($url'://www.youtube.com'!== false || strpos($url'://youtube.com'!== false{
  61.             // Embed a YouTube player
  62.             $index strpos($url'v=');
  63.             $vidid substr($url$index 211);
  64.             $output = <<<XXXEODXXX
  65. <object width="{$framewidth}" height="{$frameheight}">
  66.  <param name="movie" value="http://www.youtube.com/v/{$vidid}"></param>
  67.  <param name="allowFullScreen" value="true"></param>
  68.  <param name="allowscriptaccess" value="always"></param>
  69.  <embed src="http://www.youtube.com/v/{$vidid}" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="{$framewidth}" height="{$frameheight}"></embed>
  70. </object>
  71. XXXEODXXX;
  72.         else {
  73.             // Just embed the video normally
  74.             $output "<embed src=\"{$url}\" align=\"center\" autoplay=\"true\" controller=\"true\" width=\"{$framewidth}\" height=\"{$frameheight}\" scale=\"aspect\" />";
  75.         }
  76.  
  77.         return $output;
  78.     }
  79.  
  80.     /**
  81.     * Render the given slide for virtual-world output.
  82.     * This returns two items of data in a numeric array.
  83.     * The first is the virtual world compatible type identifier: web, image, video, or audio (or a mime type).
  84.     * The second is the absolute URL to give it.
  85.     * @param SloodlePresenterSlide $slide An object containing the raw slide data.
  86.     * @return array Numeric array containg (type, url)
  87.     */
  88.     function render_slide_for_sl($slide)
  89.     {
  90.         $url $this->get_absolute_url($slide->source);
  91.         $type 'video/*';
  92.         
  93.         // Check to see if we need to convert the video URL for video-sharing sites
  94.         if (strpos($url'://www.youtube.com'!== false || strpos($url'://youtube.com'!== false{
  95.             $index strpos($url'v=');
  96.             $vidid substr($url$index 211);
  97.             $url "http://www.youtubemp4.com/video/".$vidid.".mp4";
  98.             $type "video/mp4";
  99.         }
  100.  
  101.         return array($type$url);
  102.     }
  103.  
  104.     /**
  105.     * Gets the human-readable name of this plugin.
  106.     * This MUST be overridden by base classes. If not, it will just return the name of the class.
  107.     * @param string $lang Optional -- can specify the language we want the plugin name in, as an identifier like "en_utf8". If unspecified, then the current Moodle language should be used.
  108.     * @access public
  109.     * @return string The human-readable name of this plugin
  110.     */
  111.     function get_plugin_name($lang null)
  112.     {
  113.         return 'Video';
  114.     }
  115.  
  116.     /**
  117.     * Gets the internal version number of this plugin.
  118.     * This MUST be overridden.
  119.     * This should be a number like the internal version number for Moodle modules, containing the date and release number.
  120.     * Format is: YYYYMMDD##.
  121.     * For example, "2009012302" would be the 3rd release on the 23rd January 2009.
  122.     * @return int The version number of this module.
  123.     */
  124.     function get_version()
  125.     {
  126.         return 2009050600;
  127.     }
  128.  
  129.  
  130. }
  131.  
  132.  
  133. ?>

Documentation generated on Fri, 17 Jul 2009 11:02:45 +0100 by phpDocumentor 1.4.0