<?php
require_once('XML/RPC.php');

list(
$nothing,$username,$password) = explode('/',$_SERVER['PATH_INFO']);


$lj = New xml_rpc_client('/interface/xmlrpc','www.livejournal.com',80);

if (isset(
$_REQUEST['usejournal'])) {
    
$stuff['usejournal'] = new XML_RPC_Value($_REQUEST['usejournal'],'string');
}

if(isset(
$_REQUEST['noreadmore'])) {
    
$event_append '';
} else {
    if (isset(
$_REQUEST['readmoretext'])) {
        
$event_append '<br><br><b>(<a href="' $_REQUEST['url'] . '">' $_REQUEST['readmoretext'] . '</a>)</b>';
    } else {
        
$event_append '<br><br><b>(<a href="' $_REQUEST['url'] . '">Read More...</a>)</b>';
    }
}


if(isset(
$_REQUEST['nocomments'])) {
    
$props['opt_nocomments'] = new XML_RPC_Value(1,'boolean');
}

if (isset(
$_REQUEST['preformatted'])) {
    
$props['opt_preformatted'] = new XML_RPC_Value(1,'boolean');
}

if (isset(
$_REQUEST['titleprepend'])) {
    
$title_prepend $_REQUEST['titleprepend'];
} else {
    
$title_prepend '';
}

    
$stuff['username'] = new XML_RPC_Value($username,'string');
$stuff['hpassword'] = new XML_RPC_Value(md5($password),'string');
$stuff['event'] = new XML_RPC_Value($_REQUEST['excerpt'] . $event_append,'string');
$stuff['subject'] = new XML_RPC_Value($title_prepend $_REQUEST['title'],'string');
$stuff['year'] = new XML_RPC_Value(date('Y'),'string');
$stuff['mon'] = new XML_RPC_Value(date('m'),'string');
$stuff['day'] = new XML_RPC_Value(date('d'),'string');
$stuff['hour'] = new XML_RPC_Value(date('H'),'string');
$stuff['min'] = new XML_RPC_Value(date('i'),'string');

if(isset(
$props)) {
    
$stuff['props'] = new XML_RPC_Value($props,'struct');
}

$passme = new xml_rpc_value($stuff,'struct');

$msg = new XML_RPC_Message('LJ.XMLRPC.postevent',array($passme));

$res $lj->send($msg,10);


$error 0;
if (
$res->faultCode())  {
    
$error 1;
    
$message $res->faultString();
}

header('Content-Type: text/xml');

print 
'<?xml version="1.0" encoding="iso-8859-1"?>' "\n";
print 
'<response>' "\n";
print 
'<error>' $error '</error>' "\n";
if (
$error) {
    print 
'<message>' $message '</message>' "\n";

print 
'</response>' "\n";
?>