Location: PHPKode > scripts > PonPublish > ponpublish/modules/livejournal.php
<?php

/***************************
* PonPublish               *
* Written By: Pongles      *
* Website: pongles.com     *
* Licence: GPL             *
****************************/

// add your myspace details here!
define( "LIVEJOURNAL_USERNAME", "" );
define( "LIVEJOURNAL_PASSWORD", "" );

// purpose: adding blogs to myspace
class CLJPublish extends CPublishBase
{
    // purpose: find the challange to hash the password
    // returns: string
    function FindChallenge( &$strChallenge, $strOutput )
    {
        return FindSubString( $strChallenge, $strOutput, "name='chal' id='login_chal' value='", "' />" );
    }
    
    // purpose: get the journal data
    // returns: string
    function CreateJournalPost( $strSubject, $iDate, $strBody, $strChallenge )
    {
        return  "chal=" . urlencode( $strChallenge ) .
            "&response=" . md5( $strChallenge . md5( LIVEJOURNAL_PASSWORD ) ) .
            "&user=" . urlencode( LIVEJOURNAL_USERNAME ) .
            "&password=" .
            "&date_ymd_mm=" . date( "m", $iDate ) .
            "&date_ymd_dd=" . date( "d", $iDate ) .
            "&date_ymd_yyyy=" . date( "Y", $iDate ) .
            "&hour=" . date( "H", $iDate ) .
            "&min=" . date( "i", $iDate ) .
            "&subject=" . EncodeString( $strSubject ) .
            "&insobjsel=insert" . 
            "&event=" . EncodeString( $strBody ) .
            "&switched_rte_on=0&security=public&event_format=auto&prop_current_location=&prop_current_music=&prop_current_moodid=&prop_current_mood=&prop_taglist=&comment_settings=&prop_opt_screening=&usejournal=&action%3Aupdate=Update+Journal";
    }
    
    // purpose: publish the blog on myspace
    // returns: bool   
    function Publish( $strSubject, $iDate, $strBody )
    {
        // get user agent
        $strAgent = $_SERVER[ "HTTP_USER_AGENT" ];
        
        // setup cURL
        $hCurl = curl_init(); 
        
        // load up the journal update page to get data
        $strJournalURL = "http://www.livejournal.com/update.bml";
        $rgJournalHeader = array( "Host: www.livejournal.com" );
                                       
        curl_setopt( $hCurl, CURLOPT_URL, $strJournalURL );
        curl_setopt( $hCurl, CURLOPT_HEADER, 1 );
        curl_setopt( $hCurl, CURLOPT_FOLLOWLOCATION, 0 );
        curl_setopt( $hCurl, CURLOPT_RETURNTRANSFER, 1 );
        curl_setopt( $hCurl, CURLOPT_HTTPHEADER, $rgJournalHeader );
        curl_setopt( $hCurl, CURLOPT_USERAGENT, $strAgent );
        
        $strPreviewOutput = curl_exec( $hCurl );
        
        if( !$this->FindChallenge( $strChallenge, $strPreviewOutput ) )
            return "Cannot Find Challenge in Post";
            
        // post the data
        $strJournalPost = $this->CreateJournalPost( $strSubject, $iDate, $strBody, $strChallenge );
        
        $rgJournalHeader = array( "Host: www.livejournal.com",
                               "Content-Type: application/x-www-form-urlencoded",
                               "Content-Length: " . strlen( $strJournalPost ) );
        
        curl_setopt( $hCurl, CURLOPT_URL, $strJournalURL );
        curl_setopt( $hCurl, CURLOPT_REFERER, $strJournalURL );
        curl_setopt( $hCurl, CURLOPT_HEADER, 1 );
        curl_setopt( $hCurl, CURLOPT_FOLLOWLOCATION, 0 );
        curl_setopt( $hCurl, CURLOPT_RETURNTRANSFER, 1 );
        curl_setopt( $hCurl, CURLOPT_HTTPHEADER, $rgJournalHeader );
        curl_setopt( $hCurl, CURLOPT_POST, 1 );
        curl_setopt( $hCurl, CURLOPT_USERAGENT, $strAgent );
        curl_setopt( $hCurl, CURLOPT_POSTFIELDS, $strJournalPost );

        curl_exec( $hCurl );

        // close cURL
        curl_close( $hCurl );

        return true;
    }
}

// create module
CreateModule( "LiveJournal", new CLJPublish );

?>
Return current item: PonPublish