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
  44.     // (this will auto-register/enrol users where necessary and allowed)
  45.     // If server access level is public, then validation is not essential... otherwise, it is
  46.     $sloodleserveraccesslevel $sloodle->request->get_server_access_level(false);
  47.     if ($sloodleserveraccesslevel == 0$sloodle->validate_user(false);
  48.     else $sloodle->validate_user(true);
  49.  
  50.     
  51.     // Has an incoming message been provided?
  52.     $message sloodle_clean_for_db($sloodle->request->optional_param('message'null));
  53.     if ($message != null{
  54.         // Add it to the chatroom - if it fails add a negative side effect code to our response.
  55.         // The positive side effect will be added by the function if successful.
  56.         if (!$sloodle->module->add_message($message)) {
  57.             $sloodle->response->add_side_effect(-10101);
  58.             add_to_log($sloodle->course->get_course_id()'sloodle''add message''''Failed to add chat message to chatroom'$sloodle->request->get_module_id());
  59.         else {
  60.             add_to_log($sloodle->course->get_course_id()'sloodle''add message''''Added chat message to chatroom'$sloodle->request->get_module_id());
  61.         }
  62.     }
  63.     
  64.     // Start preparing the response
  65.     $sloodle->response->set_status_code(1);
  66.     $sloodle->response->set_status_descriptor('OK');
  67.     
  68.     // Fetch a chat history 
  69.     $messages $sloodle->module->get_chat_history();
  70.     foreach ($messages as $m{
  71.         $author sloodle_clean_for_output($m->user->get_user_firstname().' '.$m->user->get_user_lastname());
  72.         $sloodle->response->add_data_line(array($m->id$authorsloodle_clean_for_output($m->message)));
  73.     }
  74.     
  75.     // Output our response
  76.     sloodle_debug('<pre>')// For debug mode, lets us see the response in a browser
  77.     $sloodle->response->render_to_output();
  78.     sloodle_debug('</pre>');
  79.     
  80. ?>

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