Source for file blog_linker.php

Documentation is available at blog_linker.php

  1. <?php 
  2.     
  3.     // This file is part of the Sloodle project (www.sloodle.org) and is released under the GNU GPL v3.
  4.     
  5.     /**
  6.     * Sloodle blog linker.
  7.     *
  8.     * Allows the Sloodle Toolbar HUD object in Second Life to write to a user's Moodle blog.
  9.     *
  10.     * @package sloodleblog
  11.     * @copyright Copyright (c) 2007-8 Sloodle (various contributors)
  12.     * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  13.     *
  14.     * @contributor (various)
  15.     * @contributor Peter R. Bloomfield
  16.     *
  17.     */
  18.  
  19.     // This script is expected to be accessed from in-world.
  20.     // The following parameters are required:
  21.     //
  22.     //   sloodlepwd = the password used to authenticate the request (CANNOT be a prim password... object-specific password only, and it MUST match the user specified)
  23.     //   sloodleuuid = the SL UUID of the agent making the blog entry (optional if 'sloodleavname' is specified)
  24.     //   sloodleavname = the name of the avatar making the blog entry (optional if 'sloodleuuid' is specified)
  25.     //   sloodleblogsubject = the subject line of the blog entry
  26.     //   sloodleblogbody = the main body of the blog entry
  27.     //
  28.  
  29.     /** Lets Sloodle know we are in a linker script. */
  30.     define('SLOODLE_LINKER_SCRIPT'true);
  31.     
  32.     /** Grab the Sloodle/Moodle configuration. */
  33.     require_once('../../sl_config.php');
  34.     /** Include the Sloodle PHP API. */
  35.     require_once(SLOODLE_LIBROOT.'/sloodle_session.php');
  36.     
  37.     // Authenticate the request as user-specific, and load a blog module
  38.     $sloodle new SloodleSession();
  39.     $sloodle->authenticate_request();
  40.     $sloodle->load_module('blog'false)// No database data required
  41.     // Attempt to validate the user
  42.     $sloodle->validate_user();
  43.     
  44.  
  45.     require_once('../config.php');
  46.     require_once(SLOODLE_DIRROOT.'/sl_debug.php');
  47.     require_once(SLOODLE_DIRROOT.'/lib/sl_lsllib.php');
  48.     require_once($CFG->dirroot .'/blog/lib.php')// Moodle blog functionality
  49.     
  50.     // Create an LSL handler and process the basic request data
  51.     sloodle_debug_output('Creating LSL handler...<br/>');
  52.     $lsl new SloodleLSLHandler();
  53.     sloodle_debug_output('Processing basic request data...<br/>');
  54.     $lsl->request->process_request_data();
  55.     
  56.     // Ensure the request is authenticated
  57.     sloodle_debug_output('Authenticating request...<br/>');
  58.     $lsl->request->authenticate_request();
  59.     // Attempt to login the user
  60.     sloodle_debug_output('Logging-in user...<br/>');
  61.     $lsl->login_by_request();
  62.     
  63.     
  64.     // Obtain the additional parameters for the blog entry
  65.     sloodle_debug_output('Obtaining additional parameters...<br/>');
  66.     $sloodleblogsubject $lsl->request->required_param('sloodleblogsubject'PARAM_RAW);
  67.     $sloodleblogbody $lsl->request->required_param('sloodleblogbody'PARAM_RAW);
  68.  
  69.     // We need to know if all header data was retrieved
  70.     $use_slurl (isset($_SERVER['HTTP_X_SECONDLIFE_REGION']&& isset($_SERVER['HTTP_X_SECONDLIFE_LOCAL_POSITION']));
  71.     // Use the HTTP headers added by SL to get the region and position data, and construct a SLurl from them
  72.     if ($use_slurl{
  73.         sloodle_debug_output('Reading header data...<br/>');
  74.         $region $_SERVER['HTTP_X_SECONDLIFE_REGION'];
  75.         $region substr $region,0strpos($region'(' );
  76.         $position $_SERVER['HTTP_X_SECONDLIFE_LOCAL_POSITION'];
  77.         sloodle_debug_output('Constructing SLurl...<br/>');
  78.         sscanf($position"(%f, %f, %f)"$x$y$z);
  79.         $slurl "http://slurl.com/secondlife/" .$region ."/" .$x ."/" .$y ."/" .$z;
  80.         $slurl '<a href="' .$slurl .'">' .$region .'</a>';
  81.     else {
  82.         sloodle_debug_output('Header data not available. Skipping SLurl...<br/>');
  83.         $slurl '[location unknown]';
  84.     }
  85.  
  86.     // Make all string data safe
  87.     sloodle_debug_output('Processing data...<br/>');
  88.     $sloodleblogsubject addslashes(clean_text(stripslashes($sloodleblogsubject)FORMAT_MOODLE));
  89.     $sloodleblogbody addslashes(clean_text(stripslashes($sloodleblogbody)FORMAT_MOODLE));
  90.     // Construct the final blog body
  91.     sloodle_debug_output('Constructing entry text...<br/>');
  92.     $sloodleblogbody "Posted from Second Life: " .$slurl ."\n\n" .$sloodleblogbody;
  93.     
  94.     // Write a blog entry into database
  95.     sloodle_debug_output('Constructing database entry...<br/>');
  96.     $blogEntry new stdClass();
  97.     $blogEntry->subject $sloodleblogsubject;
  98.     $blogEntry->summary $sloodleblogbody;
  99.     $blogEntry->module 'blog';
  100.     $blogEntry->userid $lsl->user->get_moodle_user_id();
  101.     $blogEntry->format 1;
  102.     $blogEntry->publishstate 'site'// 'draft' or 'site' or 'public'
  103.     $blogEntry->lastmodified time();
  104.     $blogEntry->created time();
  105.     
  106.     // Insert the new blog entry, making sure it is successful
  107.     sloodle_debug_output('Attempting to add post to database...<br/>');
  108.     if ($entryID insert_record('post',$blogEntry)) {
  109.         sloodle_debug_output('-&gt; Success.<br/>');
  110.         $lsl->response->set_status_code(1);
  111.         $lsl->response->set_status_descriptor('OK');
  112.     else {
  113.         sloodle_debug_output('-&gt; Failed.<br/>');
  114.         $lsl->response->set_status_code(-1);
  115.         $lsl->response->set_status_descriptor('ERROR');
  116.         $lsl->response->add_data_line('Failed to insert blog entry into database.');
  117.     }
  118.     
  119.     // Output the response
  120.     sloodle_debug_output('Outputting response...<br/>');
  121.     $lsl->response->render_to_output();
  122.     
  123.     exit();
  124. ?>

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