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.     * @todo Implement ability to read blog entries too.
  11.     *
  12.     * @package sloodle
  13.     * @copyright Copyright (c) 2007-8 Sloodle (various contributors)
  14.     * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  15.     *
  16.     * @contributor (various)
  17.     * @contributor Peter R. Bloomfield
  18.     *
  19.     */
  20.  
  21.     // This script is expected to be accessed from in-world.
  22.     // The following parameters are required:
  23.     //
  24.     //   sloodlepwd = the password used to authenticate the request (user-centric authentication)
  25.     //   sloodleuuid = the SL UUID of the agent making the blog entry
  26.     //   sloodleavname = the name of the avatar making the blog entry
  27.     //
  28.     // If called with only the above parameters, then the system will simply check the user's
  29.     //  object authorisation and ability to write blogs.
  30.     // The following parameters are needed to write a blog entry:
  31.     //
  32.     //   sloodleblogsubject = the subject line of the blog entry
  33.     //   sloodleblogbody = the main body of the blog entry
  34.     //
  35.     // The followign parameter is optional:
  36.     //
  37.     //   sloodleblogvisibility = the visibility of the post: public, site, private (or draft)
  38.     //
  39.     //
  40.     // Returns status code 1 if successful in simply checking authorisation and blogging ability.
  41.     // Returns status code 103 is successful in adding blog entry.
  42.     // Can also return various blog-specific error codes.
  43.  
  44.     /** Lets Sloodle know we are in a linker script. */
  45.     define('SLOODLE_LINKER_SCRIPT'true);
  46.     
  47.     /** Grab the Sloodle/Moodle configuration. */
  48.     require_once('../sl_config.php');
  49.     /** Include the Sloodle PHP API. */
  50.     require_once(SLOODLE_LIBROOT.'/sloodle_session.php');
  51.     
  52.     // Authenticate the request as user-specific, and load a blog module
  53.     $sloodle new SloodleSession();
  54.     $sloodle->authenticate_user_request();
  55.     $sloodle->load_module('blog'false)// No database data required
  56.     // Attempt to validate the avatar
  57.     $sloodle->validate_avatar();
  58.     $sloodle->user->login();
  59.     
  60.     
  61.     // Is blogging enabled?
  62.     if (!$sloodle->module->is_enabled()) {
  63.         $sloodle->response->quick_output(-10401'BLOG''Blogging is disabled on this site.'false);
  64.         exit();
  65.     }
  66.  
  67.     // Check if the user has permission to create blog entries
  68.     if (!$sloodle->module->user_can_write()) {
  69.         $sloodle->response->quick_output(-10402'BLOG''User lacks permission to write blog entries.'false);
  70.         exit();
  71.     }
  72.  
  73.     // Check for our additional parameters
  74.     $sloodleblogsubject $sloodle->request->optional_param('sloodleblogsubject''');
  75.     $sloodleblogbody $sloodle->request->optional_param('sloodleblogbody''');
  76.     $sloodleblogvisibility $sloodle->request->optional_param('sloodleblogvisibility''site');
  77.     
  78.     // If subject or body parameters were given, then both are required
  79.     if (!empty($sloodleblogsubject)) $sloodle->request->required_param('sloodleblogbody');
  80.     else if (!empty($sloodleblogbody)) $sloodle->request->required_param('sloodleblogsubject');
  81.     else {
  82.         // Neither parameter was specified
  83.         $sloodle->response->quick_output(1'OK'''false);
  84.         exit();
  85.     }
  86.     
  87.     // We need to know if all header data was retrieved
  88.     $use_slurl (isset($_SERVER['HTTP_X_SECONDLIFE_REGION']&& isset($_SERVER['HTTP_X_SECONDLIFE_LOCAL_POSITION']));
  89.     // Use the HTTP headers added by SL to get the region and position data, and construct a SLurl from them
  90.     if ($use_slurl{
  91.         $region $_SERVER['HTTP_X_SECONDLIFE_REGION'];
  92.         $region substr $region,0strpos($region'(' );
  93.         $position $_SERVER['HTTP_X_SECONDLIFE_LOCAL_POSITION'];
  94.         sloodle_debug('Constructing SLurl...<br/>');
  95.         sscanf($position"(%f, %f, %f)"$x$y$z);
  96.         $slurl "http://slurl.com/secondlife/" .$region ."/" .$x ."/" .$y ."/" .$z;
  97.         $slurl '<a href="' .$slurl .'">' .$region .'</a>';
  98.     else {
  99.         $slurl '['.get_string('unknown','sloodle').']';
  100.     }
  101.     
  102.     // Construct the final blog body
  103.     $sloodleblogbody get_string('postedfromsl','sloodle').': '.$slurl ."\n\n" .$sloodleblogbody;
  104.     // Make all string data safe
  105.     $sloodleblogsubject addslashes(clean_text(stripslashes($sloodleblogsubject)FORMAT_PLAIN));
  106.     $sloodleblogbody addslashes(clean_text(stripslashes($sloodleblogbody)FORMAT_MOODLE));
  107.     $sloodleblogvisibility addslashes(clean_text(stripslashes($sloodleblogvisibility)FORMAT_PLAIN));
  108.     
  109.     // Write the entry to the database
  110.     if ($sloodle->module->add_entry($sloodleblogsubject$sloodleblogbody$sloodleblogvisibility)) {
  111.         $sloodle->response->set_status_code(103);
  112.         $sloodle->response->set_status_descriptor('OK');
  113.     else {
  114.         $sloodle->response->set_status_code(-1);
  115.         $sloodle->response->set_status_descriptor('ERROR');
  116.         $sloodle->response->add_data_line('Failed to insert blog entry into database.');
  117.     }
  118.     
  119.     // Output the response
  120.     $sloodle->response->render_to_output();
  121.     exit();
  122. ?>

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