1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

xmlrpc blog poster in PHP with built-in article spinner

Discussion in 'Blogging' started by phpbuilt, Mar 20, 2013.

  1. phpbuilt

    phpbuilt Jr. VIP Jr. VIP

    Joined:
    May 16, 2011
    Messages:
    1,650
    Likes Received:
    5,208
    Occupation:
    $ from websites I own.
    Location:
    putting monkeys in paypal
    Someone asked me to share this so I figured I'd just post it here for everyone.

    This is an XMLRPC poster that has a built-in spinner. You can supply spintax to the title, body, excerpt and it will spin them and post via xmlrpc to any wordpress blog, including wordpress.com, your own hosted wordpress blogs, or many of the free web2.0 blogs that are based on wordpress.

    You will need the incurito IXR_Library.php file in the same directory as this script.

    My original file taps into a database to grab all the important data, I slashed this file up so you can figure out what kind of data the function is looking for. This file started as me copying it from somewhere else, but I've since modified it to accept things the original wouldn't (make it so it can't receive postbacks or comments, adding the excerpt, etc)

    I don't send keywords to the function because for seo purposes I don't like tags, but if you want to then just change the $keywords = '' area in the function.

    Code:
    <?php
    
    
    require_once "IXR_Library.php";
    
    
    function inStr($needle, $haystack){
        return @strpos($haystack, $needle) !== false;
    }
    function str_replaceFirst($s,$r,$str){
        $l = strlen($str);
        $a = strpos($str,$s);
        $b = $a + strlen($s);
        $temp = substr($str,0,$a) . $r . substr($str,$b,($l-$b));
        return $temp;
    }
    function spinner($pass){
        $mytext = $pass;
        $mytext = str_replace("/*".chr(13).chr(10),"",$mytext);
        $mytext = str_replace(chr(13).chr(10)."*/","",$mytext);
        while(inStr("}",$mytext)){
            $rbracket = strpos($mytext,"}",0);
            $tString = substr($mytext,0,$rbracket);
            $tStringToken = explode("{",$tString);
            $tStringCount = count($tStringToken) - 1;
            $tString = $tStringToken[$tStringCount];
            $tStringToken = explode("|",$tString);
            $tStringCount = count($tStringToken) - 1;
            $i = rand(0,$tStringCount);
            $replace = $tStringToken[$i];
            $tString = "{".$tString."}";
            $mytext = str_replaceFirst($tString,$replace,$mytext);
        }
        //$mytext = str_replace("\n\n","\n<br />",$mytext);
        return $mytext;
    }
    
    
    function xmlrpc($rpcurl,$user,$pass,$published,$title,$body,$excerpt,$keywords='',$category,$postdate,$allowcomments,$allowtrackbacks,$mysticky,$encoding='UTF-8'){
        $title = htmlentities($title,ENT_NOQUOTES,$encoding);
        $keywords = htmlentities($keywords,ENT_NOQUOTES,$encoding);
        $body = urldecode($body);
        $excerpt = urldecode($excerpt);
        $mypost = new IXR_Client($rpcurl);
        $date = new IXR_Date($postdate);
        
        
        $mypost->query('metaWeblog.newPost', 1, $user, $pass,    
             array('post_status'=>$published, // draft or published or pending review
                'title'=>$title,
                'description'=>$body,
                'mt_excerpt'=>$excerpt,
                'post_type'=>'post',
                'mt_keywords'=>$keywords,
                'categories'=>array($category),            
                'mt_allow_comments'=>$allowcomments, // 1 to allow comments
                'mt_allow_pings'=>$allowtrackbacks, // 1 to allow trackback
                'dateCreated' => $date,
                'sticky'=>$mysticky), 1);
                       
                           
        $res = $mypost->getResponse();
    
    
        if ($res) {
            return $res;
        } else {
            return "fail";
        }
    }
    
    // in the xmlrpc function, $title, $body, $excerpt should be spun using the spinner function before passing to xmlrpc
    // $category has to = an existing category, like 'health' or 'uncategorized'
    
    $time = time();
    $postdate = date('Ymd\T03:00:00',$time);
    $published = "published";
    $rpcurl = 'your blog's xmlrpc.php file, full path';
    $sticky = 'false';
    
    $myresponse = xmlrpc($rpcurl,$user,$pass,$published,$title,$body,$excerpt,$keywords = '',$category,$postdate,$allowcomments = 0,$allowtrackbacks = 0,$sticky);
    
    In order to send title/body/excerpt as spintax, you'll utilize the spinner function like this:

    Code:
    $body = <<< EOF
    {This is a great spinner|Spinning is awesome}
    EOF;
    $body = spinner($body);
    
    That line that says {This is a great spinner|Spinning is awesome}, just take your premade spin and paste it in there.

    Do the same for $excerpt and $title

    Any questions let me know.
     
    • Thanks Thanks x 1
    Last edited: Mar 20, 2013
  2. naweed

    naweed Junior Member

    Joined:
    Dec 25, 2011
    Messages:
    186
    Likes Received:
    37
    Thanks man. This was what i needed. But can you tell me where i add the blogs url and if it is possible to send the post in html format?
     
    Last edited: Mar 21, 2013
  3. phpbuilt

    phpbuilt Jr. VIP Jr. VIP

    Joined:
    May 16, 2011
    Messages:
    1,650
    Likes Received:
    5,208
    Occupation:
    $ from websites I own.
    Location:
    putting monkeys in paypal
    It'll be here:

    Code:
    $rpcurl = 'your blog's xmlrpc.php file, full path';
    
    That $rpcurl will look something like http://mycoolblog.wordpress.com/xmlrpc.php.

    To send html in the blog post, simply put html in the blog post lol.

    In the xmlrpc function, $body is the body of the post where you'll want to put the html. Like I mentioned in the original post, you set the $blog var like this ...

    Code:
    $body = <<< EOF
    {Put your spintax here|This is where the spintax goes}.
    EOF;
    $body = spinner($body);
    
    If you want html in there, you just make it like this,
    Code:
    $body = <<< EOF
    {<strong>Put your spintax here</strong>|<em>This is where the spintax goes</em>}.
    EOF;
    $body = spinner($body);