web.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 web 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. *
  13. */
  14. /**
  15. * Presenter plugin for showing web slides.
  16. *
  17. * @package sloodle
  18. */
  19. class SloodlePluginPresenterSlideWeb extends SloodlePluginBasePresenterSlide
  20. {
  21. /**
  22. * Gets the identifier of this plugin.
  23. * This function MUST be overridden by sub-classes to return an ID that is unique to the category.
  24. * It is possible to have different plugins of the same ID in different categories.
  25. * This function is given a very explicitly sloodley name as it lets us ignore any classes which don't declare it.
  26. * @access public
  27. * @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.
  28. */
  29. function sloodle_get_plugin_id()
  30. {
  31. return 'web';
  32. }
  33. /**
  34. * Construct an absolute URL, based on the given source data.
  35. * Leaves existing absolute URLs alone, but converts relative URLs as necessary.
  36. * (This allows the site to be moved without disrupting these slides.)
  37. * @param string $source The source data from the slide.
  38. * @return string An absolute URL.
  39. */
  40. function get_absolute_url($source)
  41. {
  42. global $CFG;
  43. // If we have a protocol specifier, then assume this is already an absolute URL
  44. if (strpos($source, '://') !== false) return $source;
  45. // Assume the source URL is relative to the Moodle WWW root.
  46. // Make sure we don't duplicate a forward slash.
  47. if (strpos($source, '/') === 0) return $CFG->wwwroot.$source;
  48. return $CFG->wwwroot.'/'.$source;
  49. }
  50. /**
  51. * Render the given slide for browser output -- NOTE: render to a string, and return the string.
  52. * The title of the slide need not be included -- simply the basic iFrame or embedded player etc.
  53. * @param SloodlePresenterSlide $slide An object containing the raw slide data.
  54. * @return string
  55. */
  56. function render_slide_for_browser($slide)
  57. {
  58. $url = $this->get_absolute_url($slide->source);
  59. $framewidth = 500;
  60. $frameheight = 500;
  61. if (isset($slide->presenter)) {
  62. $framewidth = $slide->presenter->get_frame_width();
  63. $frameheight = $slide->presenter->get_frame_height();
  64. }
  65. $output = "<iframe src=\"{$url}\" style=\"width:{$framewidth}px; height:{$frameheight}px;\"></iframe>";
  66. return $output;
  67. }
  68. /**
  69. * Render the given slide for virtual-world output.
  70. * This returns two items of data in a numeric array.
  71. * The first is the virtual world compatible type identifier: web, image, video, or audio (or a mime type).
  72. * The second is the absolute URL to give it.
  73. * @param SloodlePresenterSlide $slide An object containing the raw slide data.
  74. * @return array Numeric array containg (type, url)
  75. */
  76. function render_slide_for_sl($slide)
  77. {
  78. return array('text/html', $this->get_absolute_url($slide->source));
  79. }
  80. /**
  81. * Gets the human-readable name of this plugin.
  82. * This MUST be overridden by base classes. If not, it will just return the name of the class.
  83. * @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.
  84. * @access public
  85. * @return string The human-readable name of this plugin
  86. */
  87. function get_plugin_name($lang = null)
  88. {
  89. return 'Web';
  90. }
  91. /**
  92. * Gets the internal version number of this plugin.
  93. * This MUST be overridden.
  94. * This should be a number like the internal version number for Moodle modules, containing the date and release number.
  95. * Format is: YYYYMMDD##.
  96. * For example, "2009012302" would be the 3rd release on the 23rd January 2009.
  97. * @return int The version number of this module.
  98. */
  99. function get_version()
  100. {
  101. return 2009050600;
  102. }
  103. }
  104. ?>