Source for file modules.php

Documentation is available at modules.php

  1. <?php
  2.     // This file is part of the Sloodle project (www.sloodle.org)
  3.     
  4.     /**
  5.     * This file brings all of the Sloodle module classes together.
  6.     * It also provides functionality to create and load different module types.
  7.     *
  8.     * @package sloodle
  9.     * @copyright Copyright (c) 2008 Sloodle (various contributors)
  10.     * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  11.     *
  12.     * @contributor Peter R. Bloomfield
  13.     */
  14.     
  15.     
  16.     /** Base module. */
  17.     require_once(SLOODLE_LIBROOT.'/modules/module_base.php');
  18.  
  19.     
  20.     // Now we will go through every file in the "lib/modules" folder which starts "module_", and include it.
  21.     $MODULESPATH SLOODLE_LIBROOT.'/modules';
  22.     $modulefiles sloodle_get_files($MODULESPATHtrue);
  23.     // Go through each file
  24.     if (is_array($modulefiles)) {
  25.         foreach ($modulefiles as $mf{
  26.             // Does this filename start with "module_" and end with ".php"?
  27.             if (strcasecmp(substr($mf07)'module_'== && strcasecmp(substr($mf-4)'.php'== 0{
  28.                 // Yes - include it
  29.                 include_once($MODULESPATH.'/'.$mf);
  30.             }
  31.         }
  32.     }
  33.     
  34.     // We will store an associative array of module types to module class names
  35.     // e.g. { 'chat'=>'SloodleModuleChat', 'distributor'=>'SloodleModuleDistributor', ...}
  36.     global $SLOODLE_MODULE_CLASS;
  37.     $SLOODLE_MODULE_CLASS array();
  38.     // Go through each declared class
  39.     $allclasses get_declared_classes();
  40.     foreach ($allclasses as $c{
  41.         // Is this class a subclass of the Sloodle Module type?
  42.         if (strcasecmp(get_parent_class($c)'SloodleModule'== 0{
  43.             // Fetch the type name
  44.             $curtype call_user_func(array($c'get_type'));
  45.             if (!empty($curtype)) {
  46.                 // Add it to our array with its type
  47.                 $SLOODLE_MODULE_CLASS[$curtype$c;
  48.             }
  49.         }
  50.     }
  51.     
  52.     
  53.     /**
  54.     * Constructs a appropriate Sloodle module object based on the named type.
  55.     * @param string $type The type of module to construct - typically a short name, such as 'chat' or 'blog'
  56.     * @param SloodleSession &$_session The {@link SloodleSession} object to pass to the module on construction, or just null
  57.     * @param mixed $id The identifier of the module instance to load from the database (or null if there is no module data)
  58.     * @return SloodleModule|boolReturns the cosntructed module object, or false if it fails
  59.     */
  60.     function sloodle_load_module($type&$_session$id null)
  61.     {
  62.         global $SLOODLE_MODULE_CLASS;
  63.         
  64.         // Abort if the type is not recognised
  65.         if (!array_key_exists($type$SLOODLE_MODULE_CLASS)) {
  66.             sloodle_debug("Module load failed - type \"$type\" not recognised.<br/>");
  67.             return false;
  68.         }
  69.         // Construct the object, based on the class name in our array
  70.         $module new $SLOODLE_MODULE_CLASS[$type]($_session);
  71.         
  72.         // Load the data from the database, if necessary
  73.         if ($id != null{
  74.             if ($module->load($id)) return $module;
  75.             sloodle_debug("Failed to load module data from database with ID $id.<br/>");
  76.             return false;
  77.         }
  78.         
  79.         // Everything seems OK
  80.         return $module;
  81.     }
  82.  
  83. ?>

Documentation generated on Fri, 17 Jul 2009 11:01:50 +0100 by phpDocumentor 1.4.0