<?

// A simple PHP script to post to your Jaiku account using PHP, cUrl and XML-RPC.
// Kosso - October 2007

// Free free to use this code as you like. Gimme a shoutout if you do use it, eh? :)

// Requirements : A Jaiku account and PHP with Curl and XMLRPC
// Though you dont *really need* xmlrpc installed, it makes life easy creating the call to the method and reading the reply
// You could just as easily create the full XML-RPC methodCall xml yourself


$username "thisismyusername";
// Your Jaiku username

$key "xxxxxxxxxxxxxxxxxx";
// Your Jaiku API key. This is a kind of password (different to your Jaiku login password)
// Find out your API Key here (while logged in) http://api.jaiku.com/


// usage: postToJaiku($username,$key,"your message here" [optional: ,$location,$icon_code, $generated ] );

// Options: 
// $location : eg: "Dalston, London, UK"
// $icon_code : For a list of icons and their code see: http://kosso.co.uk/jaiku/icons 
// $generated : 0 (default) or 1. When set to 1, the message willonlny appear as your 'presence', not in your main Jaiku stream
// Your 'presence' can be accessed here : http://YourUserName.jaiku.com/presence/(json|xml)

// See the Jaiku API for further documentation: http://api.jaiku.com

// Cheers! Kosso

function postToJaiku($username,$key,$message,$location='',$icon=300,$generated=0){

    
$host "http://api.jaiku.com/xmlrpc";

    
$postArray = Array();
    
$postArray['user'] = $username;
    
$postArray['personal_key'] = $key;
    
$postArray['message'] = $message;
    
$postArray['location'] = $location;
    
$postArray['icon'] = $icon;
    
$postArray['generated'] = $generated;

    
$entry xmlrpc_encode_request("presence.send",$postArray);

    
$ch curl_init();
    
curl_setopt($chCURLOPT_URL$host);
    
curl_setopt($chCURLOPT_VERBOSE1);
    
curl_setopt($chCURLOPT_RETURNTRANSFER1);
    
curl_setopt($chCURLOPT_HTTP_VERSIONCURL_HTTP_VERSION_1_1);
    
curl_setopt($chCURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
    
curl_setopt($chCURLOPT_POST1);
    
curl_setopt($chCURLOPT_POSTFIELDS,$entry);

    
// Go for it!!!
    
$result curl_exec($ch);

    
// close curl
    
curl_close($ch);

    
// Lets have a look at the reply
    
$reply xmlrpc_decode($result);

    if(
$reply['status']=="ok"){
    
        echo 
"posted to Jaiku OK! :)";
        
    } else {
    
        echo 
"there was an error posting your message to Jaiku! :(";
        
    }

    
// debug the result if you like ;)

    // $sResult = str_replace("&gt;&lt;","&gt;<br />&lt;",htmlentities($result));
    // echo "<hr><pre>";
    // print_r($sResult);
    // echo "</pre><hr>";

}




// ok, you can stop reading now.....














// no. seriously. stop now. go and code summit! :)






// you know you want to!

?>