Source for file sl_blog_linker.php

Documentation is available at sl_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 - original design and implementation)
  15.     * @contributor Peter R. Bloomfield - updated to use new API and communications format
  16.     *
  17.     */
  18.  
  19.     // This script is expected to be accessed from in-world.
  20.     // The following parameters are required:
  21.     //
  22.     //   sloodlepwd = the prim password used to authenticate the blog toolbar for this site
  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.  
  30.     require_once('../config.php');
  31.     require_once(SLOODLE_DIRROOT.'/sl_debug.php');
  32.     require_once(SLOODLE_DIRROOT.'/lib/sl_lsllib.php');
  33.     require_once($CFG->dirroot .'/blog/lib.php')// Moodle blog functionality
  34.     
  35.     // Create an LSL handler and process the basic request data
  36.     sloodle_debug_output('Creating LSL handler...<br/>');
  37.     $lsl new SloodleLSLHandler();
  38.     sloodle_debug_output('Processing basic request data...<br/>');
  39.     $lsl->request->process_request_data();
  40.     
  41.     // Ensure the request is authenticated
  42.     sloodle_debug_output('Authenticating request...<br/>');
  43.     $lsl->request->authenticate_request();
  44.     // Attempt to login the user
  45.     sloodle_debug_output('Logging-in user...<br/>');
  46.     $lsl->login_by_request();
  47.     
  48.     
  49.     // Obtain the additional parameters for the blog entry
  50.     sloodle_debug_output('Obtaining additional parameters...<br/>');
  51.     $sloodleblogsubject $lsl->request->required_param('sloodleblogsubject'PARAM_RAW);
  52.     $sloodleblogbody $lsl->request->required_param('sloodleblogbody'PARAM_RAW);
  53.  
  54.     // We need to know if all header data was retrieved
  55.     $use_slurl (isset($_SERVER['HTTP_X_SECONDLIFE_REGION']&& isset($_SERVER['HTTP_X_SECONDLIFE_LOCAL_POSITION']));
  56.     // Use the HTTP headers added by SL to get the region and position data, and construct a SLurl from them
  57.     if ($use_slurl{
  58.         sloodle_debug_output('Reading header data...<br/>');
  59.         $region $_SERVER['HTTP_X_SECONDLIFE_REGION'];
  60.         $region substr $region,0strpos($region'(' );
  61.         $position $_SERVER['HTTP_X_SECONDLIFE_LOCAL_POSITION'];
  62.         sloodle_debug_output('Constructing SLurl...<br/>');
  63.         sscanf($position"(%f, %f, %f)"$x$y$z);
  64.         $slurl "http://slurl.com/secondlife/" .$region ."/" .$x ."/" .$y ."/" .$z;
  65.         $slurl '<a href="' .$slurl .'">' .$region .'</a>';
  66.     else {
  67.         sloodle_debug_output('Header data not available. Skipping SLurl...<br/>');
  68.         $slurl '[location unknown]';
  69.     }
  70.  
  71.     // Make all string data safe
  72.     sloodle_debug_output('Processing data...<br/>');
  73.     $sloodleblogsubject addslashes(clean_text(stripslashes($sloodleblogsubject)FORMAT_MOODLE));
  74.     $sloodleblogbody addslashes(clean_text(stripslashes($sloodleblogbody)FORMAT_MOODLE));
  75.     // Construct the final blog body
  76.     sloodle_debug_output('Constructing entry text...<br/>');
  77.     $sloodleblogbody "Posted from Second Life: " .$slurl ."\n\n" .$sloodleblogbody;
  78.     
  79.     // Write a blog entry into database
  80.     sloodle_debug_output('Constructing database entry...<br/>');
  81.     $blogEntry new stdClass();
  82.     $blogEntry->subject $sloodleblogsubject;
  83.     $blogEntry->summary $sloodleblogbody;
  84.     $blogEntry->module 'blog';
  85.     $blogEntry->userid $lsl->user->get_moodle_user_id();
  86.     $blogEntry->format 1;
  87.     $blogEntry->publishstate 'site'// 'draft' or 'site' or 'public'
  88.     $blogEntry->lastmodified time();
  89.     $blogEntry->created time();
  90.     
  91.     // Insert the new blog entry, making sure it is successful
  92.     sloodle_debug_output('Attempting to add post to database...<br/>');
  93.     if ($entryID insert_record('post',$blogEntry)) {
  94.         sloodle_debug_output('-&gt; Success.<br/>');
  95.         $lsl->response->set_status_code(1);
  96.         $lsl->response->set_status_descriptor('OK');
  97.     else {
  98.         sloodle_debug_output('-&gt; Failed.<br/>');
  99.         $lsl->response->set_status_code(-1);
  100.         $lsl->response->set_status_descriptor('ERROR');
  101.         $lsl->response->add_data_line('Failed to insert blog entry into database.');
  102.     }
  103.     
  104.     // Output the response
  105.     sloodle_debug_output('Outputting response...<br/>');
  106.     $lsl->response->render_to_output();
  107.     
  108.     exit();
  109. ?>

Documentation generated on Tue, 04 Mar 2008 15:08:36 +0000 by phpDocumentor 1.4.0