version_linker.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. // This file is part of the Sloodle project (www.sloodle.org)
  3. /**
  4. * Version linker script, to allow in-world tools to check the Sloodle version information
  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. */
  13. // If called without any parameters, this script will return version info.
  14. // If successful in checking version information, this script will return
  15. // with status code 1, and the data line will contain 2 fields.
  16. // The first data field will be the Sloodle version (e.g. 0.2), and the
  17. // second will be the module verison (e.g. 2008020501).
  18. // For example:
  19. //
  20. // 1
  21. // 0.2|2008013101
  22. // If an error occurs, then an appropriate standard status code will be given
  23. // and a message should be given in the status line.
  24. // FUTURE WORK: the ability to query compatibility with a particular tool
  25. // version may implemented at some point. This will require a request
  26. // parameter, and will likely return "true" or "false" on the data line.
  27. /** Let's SLOODLE know we're in a linker script. */
  28. define('SLOODLE_LINKER_SCRIPT', true);
  29. /** Sloodle/Moodle configuration information. */
  30. require_once('init.php');
  31. /** Sloodle API. */
  32. require_once(SLOODLE_LIBROOT.'/sloodle_session.php');
  33. // Process the request
  34. sloodle_debug('Processing request...<br/>');
  35. $sloodle = new SloodleSession();
  36. // Check the installed Sloodle version
  37. sloodle_debug('Checking for installed Sloodle version...<br/>');
  38. $moduleinfo = sloodle_get_record('modules', 'name', 'sloodle');
  39. if (!$moduleinfo) {
  40. sloodle_debug('ERROR: Sloodle not installed<br/>');
  41. $sloodle->response->quick_output(-106, 'SYSTEM', 'The Sloodle module is not installed on this Moodle site.', false);
  42. exit();
  43. }
  44. // Extract the module version number
  45. $moduleversion = (string)$moduleinfo->version;
  46. sloodle_debug('Sloodle version: '.(string)SLOODLE_VERSION.'<br/>');
  47. sloodle_debug("Module version: $moduleversion<br/>");
  48. // Construct and render the response
  49. sloodle_debug('Rendering response...<br/>');
  50. $sloodle->response->set_status_code(1);
  51. $sloodle->response->set_status_descriptor('OK');
  52. $sloodle->response->add_data_line(array((string)SLOODLE_VERSION, $moduleversion));
  53. sloodle_debug('<br/><pre>');
  54. $sloodle->response->render_to_output();
  55. sloodle_debug('</pre>');
  56. exit();
  57. ?>