video.php 5.5 KB

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