linker.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /**
  3. * Sloodle Presenter linker.
  4. * Allows a Sloodle Presenter object in-world to request a list of entries for a presentation.
  5. *
  6. * @package sloodle
  7. * @copyright Copyright (c) 2007-8 Sloodle (various contributors)
  8. * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  9. *
  10. * @contributor Peter R. Bloomfield
  11. */
  12. // This script should be called with the following parameters:
  13. // sloodlecontrollerid = ID of a Sloodle Controller through which to access Moodle
  14. // sloodlepwd = the prim password or object-specific session key to authenticate the request
  15. // sloodlemoduleid = ID of a presenter
  16. //
  17. // The following parameter is optional:
  18. // sloodleslidenum = the number of a slide within a presentation (this is a 1 based number, so 1 is the first slide, 2 is the second, and so on)
  19. //
  20. // Status code 1 will be returned on success of any request.
  21. // The first line will always contain the following data:
  22. //
  23. // num_slides|name
  24. //
  25. // "name" is the name of the presentation, and "num_slides" is the total number of slides currently in the presentation.
  26. // The second data line will contain data about a particular slide in the presentation, as follows:
  27. //
  28. // num|type|source|name
  29. //
  30. // num = the number of slide within the presentation, starting at 1
  31. // type = the mimetype of the slide, such as "video/*"
  32. // source = the source of the slide, which will usually be a URL (although we might use it for other things later)
  33. // name = the name of the slide
  34. //
  35. // By default, the first slide's data will always be returned.
  36. // However, by including the "sloodleslidenum" parameter in the request, a specific slide can be requested.i
  37. //
  38. // In the event that the Presenter plugins fail to load at all, the response will be status code -131.
  39. // If the presentation is empty (no slides at all) then the response will be status code -10501.
  40. // If a particular slide's plugin cannot be loaded, then the main status code will still be 1 and the basic presenter data will be given. But there will be side effect code -132, and the 'type' field for the slide will say 'ERROR'. (This allows the presentation to continue to work -- the specific slide can simply be skipped.)
  41. //
  42. // Future modifications may include:
  43. // - text-based display in SL
  44. // - UUID-based texture or object loading in SL
  45. // - aspect ratio specified for each slide
  46. //
  47. /** Lets Sloodle know we are in a linker script. */
  48. define('SLOODLE_LINKER_SCRIPT', true);
  49. /** Grab the Sloodle/Moodle configuration. */
  50. require_once('../../init.php');
  51. /** Include the Sloodle PHP API. */
  52. require_once(SLOODLE_LIBROOT.'/sloodle_session.php');
  53. // Authenticate the request, and load a slideshow module
  54. $sloodle = new SloodleSession();
  55. $sloodle->authenticate_request();
  56. $sloodle->load_module(SLOODLE_TYPE_PRESENTER, true);
  57. // Load the necessary Presenter plugins
  58. sloodle_debug("Loading Presenter plugins\n");
  59. if (!$sloodle->plugins->load_plugins('presenter')) {
  60. $sloodle->response->quick_output(-131, 'PLUGIN', 'Failed to load any SLOODLE Presenter plugins. Please check your "sloodle/plugin" folder.', false);
  61. exit();
  62. }
  63. // Get all the slides in this presentation
  64. $slides = $sloodle->module->get_slides();
  65. if (!is_array($slides) || count($slides) == 0) {
  66. $sloodle->response->quick_output(-10501, 'PRESENTER', 'There are no slides in this presentation', false);
  67. exit();
  68. }
  69. $numslides = count($slides);
  70. // Has a particular slide been requested?
  71. $sloodleslidenum = (int)$sloodle->request->optional_param('sloodleslidenum', 0);
  72. if ($sloodleslidenum < 1 || $sloodleslidenum > $numslides) $sloodleslidenum = 1;
  73. // Figure out which slide we are going to output
  74. $outputslide = null;
  75. $curslidenum = 1;
  76. foreach ($slides as $curslide) {
  77. // If this is the current slide we are after, then output it
  78. if ($curslidenum == $sloodleslidenum) {
  79. $outputslide = $curslide;
  80. break;
  81. }
  82. $curslidenum++;
  83. }
  84. // Output the basic presenter information
  85. $sloodle->response->set_status_code(1);
  86. $sloodle->response->set_status_descriptor('OK');
  87. $sloodle->response->add_data_line(array($numslides, sloodle_clean_for_output($sloodle->module->get_name())));
  88. // Our plugin data will be store in these variables
  89. $slidetype = ''; $slidesource = '';
  90. // Attempt to load the plugin required by our current slide
  91. sloodle_debug("Attempting to load plugin \"{$outputslide->type}\"...");
  92. $slideplugin = $sloodle->plugins->get_plugin('presenter-slide', $outputslide->type);
  93. if ($slideplugin === false) {
  94. // Indicate the error as a side effect, and specify the type as an error
  95. sloodle_debug("Failed to load Presenter slide plugin.\n");
  96. $sloodle->response->add_side_effect(-132);
  97. $slidetype = 'ERROR';
  98. $slidesource = '';
  99. } else {
  100. // Load the slide data from the plugin
  101. sloodle_debug("Loaded plugin OK\n");
  102. list($slidetype, $slidesource) = $slideplugin->render_slide_for_sl($outputslide);
  103. }
  104. // Output the slide data
  105. $sloodle->response->add_data_line(array($sloodleslidenum, sloodle_clean_for_output($slidetype), sloodle_clean_for_output($slidesource), sloodle_clean_for_output($outputslide->name)));
  106. $sloodle->response->render_to_output();
  107. exit();
  108. ?>