thieumao

xmlrpcclientwp.php - Them vao wordpress

Feb 5th, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.08 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. class XMLRPClientWordPress
  5. {
  6.  
  7.     var $XMLRPCURL = "http://9football.net/xmlrpc.php";
  8.     var $UserName  = "admin";
  9.     var $PassWord = "123456789a@";
  10.  
  11.     // constructor
  12.     public function __construct($xmlrpcurl, $username, $password)
  13.     {
  14.         $this->XMLRPCURL = $xmlrpcurl;
  15.         $this->UserName  = $username;
  16.         $this->PassWord = $password;
  17.            
  18.     }
  19.     function send_request($requestname, $params)
  20.     {
  21.         $request = xmlrpc_encode_request($requestname, $params);
  22.         $ch = curl_init();
  23.         curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
  24.         curl_setopt($ch, CURLOPT_URL, $this->XMLRPCURL);
  25.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  26.         curl_setopt($ch, CURLOPT_TIMEOUT, 1);
  27.         $results = curl_exec($ch);
  28.         curl_close($ch);
  29.         return $results;
  30.     }
  31.  
  32.     function create_post($title,$body,$category,$keywords='',$encoding='UTF-8')
  33.     {
  34.         $title = htmlentities($title,ENT_NOQUOTES,$encoding);
  35.         $keywords = htmlentities($keywords,ENT_NOQUOTES,$encoding);
  36.  
  37.         $content = array(
  38.             'title'=>$title,
  39.             'description'=>$body,
  40.             'mt_allow_comments'=>0,  // 1 to allow comments
  41.             'mt_allow_pings'=>0,  // 1 to allow trackbacks
  42.             'post_type'=>'post',
  43.             'mt_keywords'=>$keywords,
  44.             "custom_fields" => array(
  45.         array( 'key' => 'linksource', 'value' => 'linksource ngay valentin' ),
  46.         array( 'key' => '_linksource', 'value' => 'field_52f1e88803f57'),
  47.         array( 'key' => 'matchtime', 'value' => '14/02/2014' ),
  48.         array( 'key' => '_matchtime', 'value' => 'field_52f1e88805c33')
  49.         ),
  50.  
  51.             'categories'=>array($category)
  52.         );
  53.         $params = array(0,$this->UserName,$this->PassWord,$content,true);
  54.  
  55.         return $this->send_request('metaWeblog.newPost',$params);
  56.  
  57.     }
  58.  
  59.     function create_page($title,$body,$encoding='UTF-8')
  60.     {
  61.         $title = htmlentities($title,ENT_NOQUOTES,$encoding);
  62.  
  63.         $content = array(
  64.             'title'=>$title,
  65.             'description'=>$body
  66.         );
  67.         $params = array(0,$this->UserName,$this->PassWord,$content,true);
  68.  
  69.         return $this->send_request('wp.newPage',$params);
  70.     }
  71.  
  72.     function display_authors()
  73.     {
  74.         $params = array(0,$this->UserName,$this->PassWord);
  75.         return $this->send_request('wp.getAuthors',$params);
  76.     }
  77.  
  78.     function sayHello()
  79.     {
  80.         $params = array();
  81.         return $this->send_request('demo.sayHello',$params);
  82.     }
  83.  
  84. }
  85.  
  86. $objXMLRPClientWordPress = new XMLRPClientWordPress("http://9football.net/xmlrpc.php" , "thieumao" , "12345678a@");
  87.  
  88. echo '<table border="1" cellpadding="10">';
  89.  
  90. echo '<tr>';
  91. echo '<td>Request Name</td>';
  92. echo '<td>Result</td>';
  93. echo '</tr>';
  94.  
  95. echo '<tr>';
  96. echo '<td>demo.sayHello</td>';
  97. echo '<td>'.$objXMLRPClientWordPress->sayHello().'</td>';
  98. echo '</tr>';
  99.  
  100. echo '<tr>';
  101. echo '<td>metaWeblog.newPost</td>';
  102. echo '<td>'.$objXMLRPClientWordPress->create_post('Valentin', 'Ngay ty','').'</td>';
  103. echo '</tr>';
  104.  
  105. echo '<tr>';
  106. echo '<td>wp.newPage</td>';
  107. echo '<td>'.$objXMLRPClientWordPress->create_page('WordPress XML-RPC page thieaou ', 'This is the content of First Page done via XML-RPC').'</td>';
  108. echo '</tr>';
  109.  
  110.  
  111. echo '<tr>';
  112. echo '<td>wp.getAuthors</td>';
  113. echo '<td>'. $objXMLRPClientWordPress->display_authors().'</td>';
  114. echo '</tr>';
  115.  
  116. echo '</table>';
  117.  
  118.  
  119.  
  120. ?>
Advertisement
Add Comment
Please, Sign In to add comment