Source for file linker.php

Documentation is available at linker.php

  1. <?php
  2.     /**
  3.     * Sloodle chat linker (for Sloodle 0.3).
  4.     * Allows a Sloodle WebIntercom tool link into a Moodle chatroom.
  5.     * Fetches a recent chat history, and optionally inserts a new message.
  6.     *
  7.     * @package sloodlechat
  8.     * @copyright Copyright (c) 2007-8 Sloodle (various contributors)
  9.     * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  10.     *
  11.     * @todo Implement capabilities to make sure users can write to the chatroom (will need special handling to let guest users be permitted if desired)
  12.     *
  13.     * @contributor (various)
  14.     * @contributor Peter R. Bloomfield
  15.     */
  16.     
  17.     // This script should be called with the following parameters:
  18.     //  sloodlecontrollerid = ID of a Sloodle Controller through which to access Moodle
  19.     //  sloodlepwd = the prim password or object-specific session key to authenticate the request
  20.     //  sloodlemoduleid = ID of a chatroom
  21.     //
  22.     // If adding a new message, the following parameters should be provided:
  23.     //  sloodleuuid = UUID of the avatar
  24.     //  sloodleavname = name of the avatar
  25.     //  message = the body of the message
  26.     //
  27.     // The following parameter is optional:
  28.     //  sloodledebug = if 'true', then Sloodle debugging mode is activated    
  29.     
  30.  
  31.     /** Lets Sloodle know we are in a linker script. */
  32.     define('SLOODLE_LINKER_SCRIPT'true);
  33.     
  34.     /** Grab the Sloodle/Moodle configuration. */
  35.     require_once('../../sl_config.php');
  36.     /** Include the Sloodle PHP API. */
  37.     require_once(SLOODLE_LIBROOT.'/sloodle_session.php');
  38.     
  39.     // Authenticate the request, and load a chat module
  40.     $sloodle new SloodleSession();
  41.     $sloodle->authenticate_request();
  42.     $sloodle->load_module('chat'true);
  43.     // Attempt to validate the user... but it's not important if we can't
  44.     // (this will auto-register/enrol users where necessary and allowed)
  45.     $sloodle->validate_user(false);
  46.  
  47.     
  48.     // Has an incoming message been provided?
  49.     $message $sloodle->request->optional_param('message'null);
  50.     if ($message != null{
  51.         // Add it to the chatroom - if it fails add a negative side effect code to our response.
  52.         // The positive side effect will be added by the function if successful.
  53.         if (!$sloodle->module->add_message($message)) {
  54.             $sloodle->response->add_side_effect(-10101);
  55.             add_to_log($sloodle->course->get_course_id()'sloodle''add message''''Failed to add chat message to chatroom'$sloodle->request->get_module_id());
  56.         else {
  57.             add_to_log($sloodle->course->get_course_id()'sloodle''add message''''Added chat message to chatroom'$sloodle->request->get_module_id());
  58.         }
  59.     }
  60.     
  61.     // Start preparing the response
  62.     $sloodle->response->set_status_code(1);
  63.     $sloodle->response->set_status_descriptor('OK');
  64.     
  65.     // Fetch a chat history 
  66.     $messages $sloodle->module->get_chat_history();
  67.     foreach ($messages as $m{
  68.         $author $m->user->get_user_firstname().' '.$m->user->get_user_lastname();
  69.         $sloodle->response->add_data_line(array($m->id$author$m->message));
  70.     }
  71.     
  72.     // Output our response
  73.     sloodle_debug('<pre>')// For debug mode, lets us see the response in a browser
  74.     $sloodle->response->render_to_output();
  75.     sloodle_debug('</pre>');
  76.     
  77. ?>

Documentation generated on Mon, 07 Jul 2008 12:32:45 +0100 by phpDocumentor 1.4.0