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

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

// add your myspace details here!
define( "MYSPACE_EMAIL", "" );
define( "MYSPACE_PASSWORD", "" );

// purpose: adding blogs to myspace
class CMySpacePublish extends CPublishBase
{
    // purpose: create the POST data for the blog
    // returns: string
    function CreateBlogPost( $strSubject, $iDate, $strBody, $strHash )
    {
        return "BlogID=-1" . 
        "&PostMonth=" . date( "m", $iDate ) .
        "&PostDay=" . date( "d", $iDate ) .
        "&PostYear=" . date( "Y", $iDate ) .
        "&PostHour=" . date( "h", $iDate ) .
        "&PostMinute=" . date( "i", $iDate ) .
        "&PostTimeMarker=" . date( "A", $iDate ) .
        "&Subject=" . EncodeString( $strSubject ) . 
        "&Body=" . EncodeString( BBCodeToHTML( $strBody ) ) .
        "&CurrentlyASIN=&CurrentlyProductName=&CurrentlyProductBy=&CurrentlyImageURL=&CurrentlyProductURL=&CurrentlyProductReleaseDate=&CurrentlyProductType=" . 
        "&MoodID=0&MoodOther=&BlogViewingPrivacyID=0&ProhibitComments=0&Editor=false&MoodSetID=7&isPreviewed=true&BlogCategoryID=0" .
        "&hash=" . urlencode( $strHash ) .
        "&Enclosure=";
    }
 
    // purpose: find the login hash
    // returns: bool
    function FindHash( &$strHash, $strBlogOutput )
    {
        return FindSubString( $strHash, $strBlogOutput, "name=\"hash\" value=\"", "\">" );
    }
 
    // 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(); 
        
         // set cookie jar
        $strTempCookie = tempnam( "/tmp", "myspace" );
        curl_setopt( $hCurl, CURLOPT_COOKIEJAR, $strTempCookie );        
        
        // config
        $strLoginURL = "http://login.myspace.com/index.cfm?fuseaction=login.process";
        $strLoginData = "NextPage=&email=" . urlencode( MYSPACE_EMAIL ) . "&password=" . urlencode( MYSPACE_PASSWORD ) . "&loginbutton.x=35&loginbutton.y=9";
   
        $rgLoginHeader = array( "Host: login.myspace.com",
                                "Content-Type: application/x-www-form-urlencoded", 
                                "Content-Length: " . strlen( $strLoginData ),
                                "Referer: http://login.myspace.com/index.cfm?fuseaction=login" );
      
        // login to myspace
        curl_setopt( $hCurl, CURLOPT_URL, $strLoginURL );
        curl_setopt( $hCurl, CURLOPT_HEADER, 1 );
        curl_setopt( $hCurl, CURLOPT_FOLLOWLOCATION, 0 );
        curl_setopt( $hCurl, CURLOPT_RETURNTRANSFER, 1 );
        curl_setopt( $hCurl, CURLOPT_COOKIEFILE, $strTempCookie );
        curl_setopt( $hCurl, CURLOPT_HTTPHEADER, $rgLoginHeader );
        curl_setopt( $hCurl, CURLOPT_POST, 1 );
        curl_setopt( $hCurl, CURLOPT_USERAGENT, $strAgent );
        curl_setopt( $hCurl, CURLOPT_POSTFIELDS, $strLoginData );

        curl_exec( $hCurl );
        
        // load an empty preview page to get the hash
        $strPreviewBlogURL = "http://blog.myspace.com/index.cfm?fuseaction=blog.previewBlog";
        $rgBlogHeader = array( "Host: blog.myspace.com" );
                                       
        curl_setopt( $hCurl, CURLOPT_URL, $strPreviewBlogURL );
        curl_setopt( $hCurl, CURLOPT_HEADER, 1 );
        curl_setopt( $hCurl, CURLOPT_FOLLOWLOCATION, 0 );
        curl_setopt( $hCurl, CURLOPT_RETURNTRANSFER, 1 );
        curl_setopt( $hCurl, CURLOPT_COOKIEFILE, $strTempCookie );
        curl_setopt( $hCurl, CURLOPT_HTTPHEADER, $rgBlogHeader );
        curl_setopt( $hCurl, CURLOPT_USERAGENT, $strAgent );
        
        $strBlogOutput = curl_exec( $hCurl ); 
        
        // find the hash
        if( !$this->FindHash( $strHash, $strBlogOutput ) )
            return "Unable to Find Hash";
        
         // post the data
        $strBlogPost = $this->CreateBlogPost( $strSubject, $iDate, $strBody, $strHash );
        
        $rgBlogHeader = array( "Host: blog.myspace.com",
                               "Content-Type: application/x-www-form-urlencoded", 
                               "Content-Length: " . strlen( $strBlogPost ) );
        
        curl_setopt( $hCurl, CURLOPT_URL, "http://blog.myspace.com/index.cfm?fuseaction=blog.processCreate" );
        curl_setopt( $hCurl, CURLOPT_REFERER, $strPreviewBlogURL );
        curl_setopt( $hCurl, CURLOPT_HEADER, 1 );
        curl_setopt( $hCurl, CURLOPT_FOLLOWLOCATION, 0 );
        curl_setopt( $hCurl, CURLOPT_RETURNTRANSFER, 1 );
        curl_setopt( $hCurl, CURLOPT_COOKIEFILE, $strTempCookie );
        curl_setopt( $hCurl, CURLOPT_HTTPHEADER, $rgBlogHeader );
        curl_setopt( $hCurl, CURLOPT_POST, 1 );
        curl_setopt( $hCurl, CURLOPT_USERAGENT, $strAgent );
        curl_setopt( $hCurl, CURLOPT_POSTFIELDS, $strBlogPost );

        curl_exec( $hCurl );

        // close cURL
        curl_close( $hCurl );

        // destory cookie
        unlink( $strTempCookie );
        
        return true;
    }
}

// create module
CreateModule( "MySpace", new CMySpacePublish );

?>
Return current item: PonPublish