Source for file linker.php

Documentation is available at linker.php

  1. <?php
  2.     /**
  3.     * Sloodle glossary linker (for Sloodle 0.3).
  4.     * Allows a Sloodle MetaGloss to search a Moodle glossary.
  5.     *
  6.     * @package sloodleglossary
  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.     * @todo Implement ability to add new entries?
  11.     *
  12.     * @contributor (various)
  13.     * @contributor Peter R. Bloomfield
  14.     */
  15.     
  16.     // This script should be called with the following parameters:
  17.     //  sloodlecontrollerid = ID of a Sloodle Controller through which to access Moodle
  18.     //  sloodlepwd = the prim password or object-specific session key to authenticate the request
  19.     //  sloodlemoduleid = ID of a glossary
  20.     //
  21.     // If requested with only the above parameters, then the glossary name will be returned on the first data line (status code 1).
  22.     // The 'intro' (description), if available, will be provided on the second line, without any HTML markup.
  23.     //
  24.     // In order to search the glossary, the following parameters must also be specified:
  25.     //  sloodleterm = a string to search by
  26.     //  sloodleuuid = UUID of the avatar searching
  27.     //  sloodleavname = name of the avatar searching
  28.     //
  29.     // The following parameters are optional:
  30.     //  sloodlepartialmatches = if 'true' or '1' then searches will show partial matches too (defaults to true)
  31.     //  sloodlesearchaliases = if 'true' or '1' then searches will search by aliases too (defaults to false)
  32.     //  sloodlesearchdefinitions = if 'true' or '1' then searches will search by definitions too (defaults to false)
  33.     //
  34.     //  sloodleserveraccesslevel = defines the access level to the resource (ignored if unspecified)
  35.     //
  36.     // The following parameter is optional:
  37.     //  sloodledebug = if 'true', then Sloodle debugging mode is activated    
  38.     
  39.     // If successful, status code 1 will be returned.
  40.     // Each data line will contain a concept and definition separated by a pipe: <concept>|<definition>
  41.     
  42.  
  43.     /** Lets Sloodle know we are in a linker script. */
  44.     define('SLOODLE_LINKER_SCRIPT'true);
  45.     
  46.     /** Grab the Sloodle/Moodle configuration. */
  47.     require_once('../../sl_config.php');
  48.     /** Include the Sloodle PHP API. */
  49.     require_once(SLOODLE_LIBROOT.'/sloodle_session.php');
  50.     
  51.     // Authenticate the request, and load a glossary module
  52.     $sloodle new SloodleSession();
  53.     $sloodle->authenticate_request();
  54.     $sloodle->load_module('glossary'true);
  55.  
  56.     // Has a search term been specified?
  57.     $sloodleterm $sloodle->request->optional_param('sloodleterm'null);
  58.     if (empty($sloodleterm)) {
  59.         // Just fetch the name of the glossary
  60.         $sloodle->response->set_status_code(1);
  61.         $sloodle->response->set_status_descriptor('OK');
  62.         $sloodle->response->add_data_line($sloodle->module->get_name());
  63.         $sloodle->response->add_data_line(strip_tags($sloodle->module->get_intro()));
  64.         $sloodle->response->render_to_output();
  65.         exit();
  66.     }
  67.     
  68.     // For searching, we must authenticate the user
  69.     $sloodle->validate_user();
  70.     
  71.     // Get our other parameters
  72.     $sloodleterm addslashes($sloodleterm);
  73.     $sloodlepartialmatches $sloodle->request->optional_param('sloodlepartialmatches''true');
  74.     $sloodlesearchaliases $sloodle->request->optional_param('sloodlesearchaliases''false');
  75.     $sloodlesearchdefinitions $sloodle->request->optional_param('sloodlesearchdefinitions''false');
  76.     
  77.     // Convert our incoming parameters as necessary
  78.     if (strcasecmp($sloodlepartialmatches'true'== || $sloodlepartialmatches == '1'$sloodlepartialmatches true;
  79.     else $sloodlepartialmatches false;
  80.     if (strcasecmp($sloodlesearchaliases'true'== || $sloodlesearchaliases == '1'$sloodlesearchaliases true;
  81.     else $sloodlesearchaliases false;
  82.     if (strcasecmp($sloodlesearchdefinitions'true'== || $sloodlesearchdefinitions == '1'$sloodlesearchdefinitions true;
  83.     else $sloodlesearchdefinitions false;
  84.     
  85.     // Search the glossary
  86.     $results $sloodle->module->search($sloodleterm$sloodlepartialmatches$sloodlesearchaliases$sloodlesearchdefinitions);
  87.     if (is_array($results)) {
  88.         $sloodle->response->set_status_code(1);
  89.         $sloodle->response->set_status_descriptor('OK');
  90.         // Go through each result
  91.         foreach ($results as $r{
  92.             $concept strip_tags($r->concept);
  93.             $def str_replace("\n"""strip_tags($r->definition));
  94.             $sloodle->response->add_data_line(array($concept$def));
  95.         }
  96.     else {
  97.         $sloodle->response->set_status_code(-103);
  98.         $sloodle->response->set_status_descriptor('SYSTEM');
  99.         $sloodle->response->add_data_line('Failed to search glossary');
  100.     }
  101.     
  102.     // Output our response
  103.     sloodle_debug('<pre>')// For debug mode, lets us see the response in a browser
  104.     $sloodle->response->render_to_output();
  105.     sloodle_debug('</pre>');
  106.     
  107. ?>

Documentation generated on Mon, 16 Jun 2008 15:56:31 +0100 by phpDocumentor 1.4.0