init.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <?php
  2. /**
  3. * Sloodle core script.
  4. *
  5. * Sets up the basic Sloodle information, and includes the necessary Moodle data/functionality.
  6. *
  7. * @package sloodle
  8. *
  9. */
  10. /*
  11. Linker scripts don't maintain cookies.
  12. We need to set NO_MOODLE_COOKIES to prevent Moodle from creating a new session on every request.
  13. */
  14. if (defined('SLOODLE_LINKER_SCRIPT')) {
  15. define('NO_MOODLE_COOKIES', true);
  16. }
  17. // Pull in the main moodle config
  18. // NB the following is necessary for when we pull in this config.php from a module under sloodle/mod
  19. require_once (realpath(dirname(__FILE__) . "/" . "../../config.php"));
  20. require_once (realpath(dirname(__FILE__) . "/" . "lib/db.php"));
  21. require_once (realpath(dirname(__FILE__) . "/" . "lib/compat.php"));
  22. // Is this a linker script?
  23. if (defined('SLOODLE_LINKER_SCRIPT')) {
  24. // If the site is in maintenance mode, then stop the script
  25. if (file_exists($CFG->dataroot.'/'.SITEID.'/maintenance.html')) {
  26. exit("-111|SYSTEM\nThe Moodle site is in maintenance mode. Please try again later.");
  27. }
  28. // Use Unicode UTF-8 encoding to support non-English alphabets
  29. if (!headers_sent()) header('Content-Type: text/plain; charset=UTF-8');
  30. }
  31. //---------------------------------------------------------------------
  32. /** The path for browsing to the root of the Sloodle folder. */
  33. define('SLOODLE_WWWROOT', $CFG->wwwroot.'/mod/sloodle');
  34. /** The data path for the root of the Sloodle folder. */
  35. define('SLOODLE_DIRROOT', $CFG->dirroot.'/mod/sloodle');
  36. /** The data path for the root of the Sloodle library folder. */
  37. define('SLOODLE_LIBROOT', $CFG->dirroot.'/mod/sloodle/lib');
  38. /** The Sloodle version number. */
  39. define('SLOODLE_VERSION', 2.1); // This is the release version, not the module version (which is in version.php)
  40. // The following tells us whether Moodle is at > version 2 or not.
  41. define('SLOODLE_IS_ENVIRONMENT_MOODLE_2', ($CFG->version >= 2010060800) );
  42. //---------------------------------------------------------------------
  43. /** The name of the HTTP parameter which can be used to activate Sloodle debug mode. */
  44. define('SLOODLE_DEBUG_MODE_PARAM_NAME', 'sloodledebug');
  45. // Check if debug mode is active
  46. $sloodle_debug = 'false';
  47. if (isset($_REQUEST[SLOODLE_DEBUG_MODE_PARAM_NAME])) $sloodle_debug = $_REQUEST[SLOODLE_DEBUG_MODE_PARAM_NAME];
  48. if (strcasecmp($sloodle_debug, 'true') == 0 || $sloodle_debug == '1') {
  49. define('SLOODLE_DEBUG', true);
  50. } else {
  51. define('SLOODLE_DEBUG', false);
  52. }
  53. // Apply the effects of debug mode
  54. if (SLOODLE_DEBUG) {
  55. // Report all errors and warnings
  56. @ini_set('display_errors', '1');
  57. // Since we're in basic UTF8 text mode, disable the HTML in error codes
  58. @ini_set('html_errors', '0');
  59. //@error_reporting(2047);
  60. } else {
  61. // Debug mode is NOT active. Are we in a linker script?
  62. if (defined('SLOODLE_LINKER_SCRIPT') && SLOODLE_LINKER_SCRIPT == true) {
  63. // Yes - suppress the display of messages
  64. @ini_set('display_errors', '0');
  65. }
  66. }
  67. @ini_set('display_errors', '0');
  68. /**
  69. * Outputs messages if in debug mode.
  70. * @uses SLOODLE_DEBUG
  71. * @param string $msg The debug message to output
  72. * @return void
  73. */
  74. function sloodle_debug($msg)
  75. {
  76. if (SLOODLE_DEBUG) echo $msg;
  77. }
  78. //---------------------------------------------------------------------
  79. // Types of Sloodle module
  80. // These correspond to the "type" field in the "Sloodle" DB table
  81. // Each name should be lower-case letters only (max 50)
  82. // The full name should be specified in the appropriate language file, as "moduletype:type".
  83. // Each course needs to have at least one Sloodle Access Controller before it can be accessed from in-world.
  84. // This is what grants access to the course as a whole, and sets prim passwords.
  85. define('SLOODLE_TYPE_CTRL', 'controller');
  86. // These are the regular module types
  87. define('SLOODLE_TYPE_DISTRIB', 'distributor');
  88. define('SLOODLE_TYPE_PRESENTER', 'presenter');
  89. define('SLOODLE_TYPE_MAP', 'map');
  90. define('SLOODLE_TYPE_TRACKER', 'tracker');
  91. // Store the types in an array (used in lists)
  92. global $SLOODLE_TYPES;
  93. $SLOODLE_TYPES = array();
  94. $SLOODLE_TYPES[] = SLOODLE_TYPE_CTRL;
  95. $SLOODLE_TYPES[] = SLOODLE_TYPE_DISTRIB;
  96. $SLOODLE_TYPES[] = SLOODLE_TYPE_PRESENTER;
  97. $SLOODLE_TYPES[] = SLOODLE_TYPE_TRACKER;
  98. //---------------------------------------------------------------------
  99. // Access level constants
  100. /** Indicates that anybody may access an object in-world. */
  101. define('SLOODLE_OBJECT_ACCESS_LEVEL_PUBLIC', 0);
  102. /** Indicates that only the owner may access an object in-world. */
  103. define('SLOODLE_OBJECT_ACCESS_LEVEL_OWNER', 1);
  104. /** Indicates that only in-world group-members may access an object in-world. */
  105. define('SLOODLE_OBJECT_ACCESS_LEVEL_GROUP', 2);
  106. /** Indicates that anybody may access a server resource (still requires an authenticated request). */
  107. define('SLOODLE_SERVER_ACCESS_LEVEL_PUBLIC', 0);
  108. /** Indicates that only those registered and enrolled in a specific course may access a server resource. */
  109. define('SLOODLE_SERVER_ACCESS_LEVEL_COURSE', 1);
  110. /** Indicates that only those registered on the site may access a server resource. */
  111. define('SLOODLE_SERVER_ACCESS_LEVEL_SITE', 2);
  112. /** Indicates that only those with Sloodle staff status on a course may access a server resource. */
  113. define('SLOODLE_SERVER_ACCESS_LEVEL_STAFF', 3);
  114. //---------------------------------------------------------------------
  115. /*
  116. Customizable parameters follow.
  117. Normally these will be defined in an optional 'sloodle_config.php' file.
  118. For ease of upgrading, the sloodle_config.php will not be included in the release, although we will provide a sample.
  119. */
  120. if ( file_exists(SLOODLE_DIRROOT.'/sloodle_config.php') ) {
  121. require_once(SLOODLE_DIRROOT.'/sloodle_config.php');
  122. }
  123. /*
  124. Constants that need to have a default parameter for people with no config.php should set it below this line
  125. ... conditional on it being undefined.
  126. */
  127. /**
  128. The collections of objects the rezzer supports.
  129. This corresponds to the collections parameter in the object definition of each object.
  130. NB The array should be serialized because PHP won't do arrays as constants.
  131. */
  132. if ( !defined('SLOODLE_SUPPORTED_OBJECT_COLLECTIONS') ) {
  133. define('SLOODLE_SUPPORTED_OBJECT_COLLECTIONS', serialize(array('SLOODLE 2.0') ) ); //
  134. }
  135. /*
  136. How often objects should be told to ping us to let us know they're alive.
  137. NB The initial ping from an object will be at a random proportion of this number
  138. ...to provide some jitter and prevent the server being hammered by all the scripts at the same time.
  139. */
  140. if ( !defined('SLOODLE_PING_INTERVAL') ) {
  141. define('SLOODLE_PING_INTERVAL', 3600);
  142. }
  143. /*
  144. How often the rezzer should poll to check which objects may be rezzed
  145. ...and provide a report of which, in any, are missing.
  146. Since there is usually only one rezzer, you should be able to make this happen fairly fast without worrying about killing your server.
  147. If you aren't worried about server resources, it would be meaningful to bring it down as low as 3 seconds.
  148. */
  149. if ( !defined('SLOODLE_REZZER_STATUS_CONFIRM_INTERVAL')) {
  150. define('SLOODLE_REZZER_STATUS_CONFIRM_INTERVAL', 15);
  151. }
  152. // This activates freemail blogging.
  153. // This is off by default in sloodle 2.1, as we haven't tested it properly yet.
  154. // We will probably turn it on in 2.2.
  155. // NB it will only work on Moodle 2.0 or higher.
  156. if ( !defined('SLOODLE_FREEMAIL_ACTIVATE')) {
  157. define('SLOODLE_FREEMAIL_ACTIVATE', false);
  158. }
  159. //---------------------------------------------------------------------
  160. /** General functionality. */
  161. require_once(SLOODLE_LIBROOT.'/general.php');
  162. /** Sloodle core library functionality */
  163. require_once(SLOODLE_DIRROOT.'/lib.php');
  164. /** Request and response functionality. */
  165. require_once(SLOODLE_LIBROOT.'/io.php');
  166. /** User functionality. */
  167. require_once(SLOODLE_LIBROOT.'/user.php');
  168. /** Course functionality. */
  169. require_once(SLOODLE_LIBROOT.'/course.php');
  170. /** Sloodle Controller functionality. */
  171. require_once(SLOODLE_LIBROOT.'/controller.php');
  172. /** Module functionality. */
  173. require_once(SLOODLE_LIBROOT.'/modules.php');
  174. /** Plugin management. */
  175. require_once(SLOODLE_LIBROOT.'/plugins.php');
  176. /** Active Objects config definitions. */
  177. require_once(SLOODLE_LIBROOT.'/object_configs.php');
  178. /** Active Objects and their definitions. */
  179. require_once(SLOODLE_LIBROOT.'/active_object.php');
  180. ?>