thieumao

1xxxxClassXMLRPClientWordPress.php

Mar 15th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.71 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.  
  12.     var $XMLRPCURL;
  13.     var $UserName;
  14.     var $PassWord;
  15.  
  16.     // constructor
  17.     public function __construct($xmlrpcurl, $username, $password)
  18.     {
  19.         $this->XMLRPCURL = $xmlrpcurl;
  20.         $this->UserName  = $username;
  21.         $this->PassWord = $password;
  22.            
  23.     }
  24.  
  25.     function send_request($requestname, $params)
  26.     {
  27.         //$request = xmlrpc_encode_request($requestname, $params);
  28.         $request = xmlrpc_encode_request('metaWeblog.newPost',$params,array('encoding'=>'UTF-8','escaping'=>'markup'));
  29.         $ch = curl_init();
  30.         curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
  31.         curl_setopt($ch, CURLOPT_URL, $this->XMLRPCURL);
  32.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  33.         curl_setopt($ch, CURLOPT_TIMEOUT, 1);
  34.         $results = curl_exec($ch);
  35.         curl_close($ch);
  36.         return $results;
  37.     }
  38.  
  39.     function create_post($title,$body,$category,$keywords='',$encoding='UTF-8')
  40.     {
  41.         $title = htmlentities($title,ENT_NOQUOTES,$encoding);
  42.         $keywords = htmlentities($keywords,ENT_NOQUOTES,$encoding);
  43.  
  44.         $content = array(
  45.             'title'=>$title,
  46.             'description'=>$body,
  47.             'mt_allow_comments'=>0,  // 1 to allow comments
  48.             'mt_allow_pings'=>0,  // 1 to allow trackbacks
  49.             'post_type'=>'post',
  50.             'mt_keywords'=>$keywords,
  51.         /*
  52.          "custom_fields" => array(
  53.          array( 'key' => 'linksource', 'value' => 'linksource ngay valentin' ),
  54.          array( 'key' => '_linksource', 'value' => 'field_52f1e88803f57'),
  55.          array( 'key' => 'matchtime', 'value' => '14/02/2014' ),
  56.          array( 'key' => '_matchtime', 'value' => 'field_52f1e88805c33')
  57.          ),
  58.          */
  59.  
  60.             'categories'=>array($category)
  61.         );
  62.         $params = array(0,$this->UserName,$this->PassWord,$content,false);
  63.  
  64.         return $this->send_request('metaWeblog.newPost',$params);
  65.  
  66.     }
  67.  
  68.     function create_post_tivi($post_type,$title,$body,$category,$icon,$tiviid,$description,$link1,$link2,$link3,$link4,$isdefault,$arrURL,$arrDescription,$keywords='',$encoding='UTF-8')
  69.     {
  70.         $title = htmlentities($title,ENT_NOQUOTES,$encoding);
  71.         $keywords = htmlentities($keywords,ENT_NOQUOTES,$encoding);
  72.         $count = count($arrURL);
  73.         /*
  74.          $content['title'] = $title;
  75.          $content['description'] = $body;
  76.          $content['mt_allow_comments'] = 1;
  77.          $content['mt_allow_pings'] = 1;
  78.          $content['mt_allow_pings'] = $post_type;
  79.          $content['mt_keywords'] = $keywords;
  80.          */
  81.          /*
  82.         $arr_custom_fields = array();
  83.         array_push($arr_custom_fields ,array( 'key' => 'icon', 'value' => $icon ));
  84.         array_push($arr_custom_fields,array( 'key' => '_icon', 'value' => 'field_531eb2f70a7bc'));
  85.  
  86.         array_push($arr_custom_fields,array( 'key' => 'tiviid', 'value' => $tiviid ));
  87.         array_push($arr_custom_fields,array( 'key' => '_tiviid', 'value' => 'field_531eb2f70ac7a'));
  88.  
  89.         array_push($arr_custom_fields,array( 'key' => 'description', 'value' => $description ));
  90.         array_push($arr_custom_fields,array( 'key' => '_description', 'value' => 'field_531eb2f70b124'));
  91.  
  92.         array_push($arr_custom_fields,array( 'key' => 'link1', 'value' => $link1 ));
  93.         array_push($arr_custom_fields,array( 'key' => '_link1', 'value' => 'field_52f1e88803f57'));
  94.  
  95.         array_push($arr_custom_fields,array( 'key' => 'link2', 'value' => $link2 ));
  96.         array_push($arr_custom_fields,array( 'key' => '_link2', 'value' => 'field_531eb2f70ba9a'));
  97.  
  98.         array_push($arr_custom_fields,array( 'key' => 'link3', 'value' => $link3 ));
  99.         array_push($arr_custom_fields,array( 'key' => '_link3', 'value' => 'field_531eb2f70bf70'));
  100.  
  101.         array_push($arr_custom_fields,array( 'key' => 'link4', 'value' => $link4 ));
  102.         array_push($arr_custom_fields,array( 'key' => '_link4', 'value' => 'field_531eb2f70c438'));
  103.  
  104.         array_push($arr_custom_fields,array( 'key' => 'isdefault', 'value' => $isdefault ));
  105.         array_push($arr_custom_fields,array( 'key' => '_isdefault', 'value' => 'field_531eb2f70c91b'));
  106.            
  107.         for ($i = 0; $i < $count; $i++) {
  108.             array_push($arr_custom_fields,array( 'key' => 'linkstream_'.$i.'_url', 'value' => $arrURL[$i]));
  109.             array_push($arr_custom_fields,array( 'key' => '_linkstream_'.$i.'_url', 'value' => 'field_5323d3cb82ae9'));
  110.             array_push($arr_custom_fields,array( 'key' => 'linkstream_'.$i.'_description', 'value' => $arrDescription[$i]));
  111.             array_push($arr_custom_fields,array( 'key' => '_linkstream_'.$i.'_description', 'value' => 'field_5323d3cb82a91'));
  112.  
  113.         }
  114.  
  115.  
  116.         $content = array(
  117.          'title'=>$title,
  118.          'description'=>$body,
  119.          'mt_allow_comments'=>1,  // 1 to allow comments
  120.          'mt_allow_pings'=>1,  // 1 to allow trackbacks
  121.          'post_type'=>$post_type, // post
  122.         // 'post_status'  => 'inherit'
  123.          'mt_keywords'=>$keywords,
  124.          //"custom_fields" =>$arr_custom_fields,
  125.          'categories'=>array($category)
  126.         );
  127.             */
  128.             echo "1123";
  129.            
  130.         $content = array(
  131.             'title'=>$title,
  132.             'description'=>$body,
  133.             'mt_allow_comments'=>0,  // 1 to allow comments
  134.             'mt_allow_pings'=>0,  // 1 to allow trackbacks
  135.             'post_type'=>'post',
  136.             'mt_keywords'=>$keywords,
  137.         /*
  138.          "custom_fields" => array(
  139.          array( 'key' => 'linksource', 'value' => 'linksource ngay valentin' ),
  140.          array( 'key' => '_linksource', 'value' => 'field_52f1e88803f57'),
  141.          array( 'key' => 'matchtime', 'value' => '14/02/2014' ),
  142.          array( 'key' => '_matchtime', 'value' => 'field_52f1e88805c33')
  143.          ),
  144.          */
  145.  
  146.             'categories'=>array($category)
  147.         );
  148.            
  149.         $params = array(0,$this->UserName,$this->PassWord,$content,true);
  150.         return $this->send_request('metaWeblog.newPost',$params);
  151.  
  152.     }
  153.  
  154.     function create_post_football($title,$body,$category,$introtext,$imageFull,$thumbnail,$linksource,
  155.     $linkserver,$linkyoutube,$linkdropbox,$matchtime,$ishot,$keywords='',$encoding='UTF-8')
  156.     {
  157.         $title = htmlentities($title,ENT_NOQUOTES,$encoding);
  158.         $keywords = htmlentities($keywords,ENT_NOQUOTES,$encoding);
  159.         $content = array(
  160.             'title'=>$title,
  161.             'description'=>$body,
  162.             'mt_allow_comments'=>1,  // 1 to allow comments
  163.             'mt_allow_pings'=>1,  // 1 to allow trackbacks
  164.             'post_type'=>'post',
  165.             'mt_keywords'=>$keywords,
  166.             "custom_fields" => array(
  167.         array( 'key' => 'introtext', 'value' => $introtext ),
  168.         array( 'key' => '_introtext', 'value' => 'field_52f1e887ee97f'),
  169.         array( 'key' => 'imageFull', 'value' => $imageFull ),
  170.         array( 'key' => '_imageFull', 'value' => 'field_52f1e887ef089'),
  171.         array( 'key' => 'thumbnail', 'value' => $thumbnail ),
  172.         array( 'key' => '_thumbnail', 'value' => 'field_52f1e887ef759'),
  173.         array( 'key' => 'linksource', 'value' => $linksource ),
  174.         array( 'key' => '_linksource', 'value' => 'field_52f1e88803f57'),
  175.         array( 'key' => 'linkserver', 'value' => $linkserver ),
  176.         array( 'key' => '_linkserver', 'value' => 'field_52f1e88804684'),
  177.         array( 'key' => 'linkyoutube', 'value' => $linkyoutube ),
  178.         array( 'key' => '_linkyoutube', 'value' => 'field_52f1e88804d93'),
  179.         array( 'key' => 'linkdropbox', 'value' => $linkdropbox ),
  180.         array( 'key' => '_linkdropbox', 'value' => 'field_52f1e888054e4'),
  181.         array( 'key' => 'matchtime', 'value' => $matchtime ),
  182.         array( 'key' => '_matchtime', 'value' => 'field_52f1e88805c33'),
  183.         array( 'key' => 'ishot', 'value' => $ishot ),
  184.         array( 'key' => '_ishot', 'value' => 'field_52f1e888063a4'),
  185.         ),
  186.             'categories'=>array($category)
  187.         );
  188.         $params = array(0,$this->UserName,$this->PassWord,$content,true);
  189.         return $this->send_request('metaWeblog.newPost',$params);
  190.  
  191.     }
  192.  
  193.     function create_page($title,$body,$encoding='UTF-8')
  194.     {
  195.         $title = htmlentities($title,ENT_NOQUOTES,$encoding);
  196.  
  197.         $content = array(
  198.             'title'=>$title,
  199.             'description'=>$body
  200.         );
  201.         $params = array(0,$this->UserName,$this->PassWord,$content,true);
  202.  
  203.         return $this->send_request('wp.newPage',$params);
  204.     }
  205.  
  206.     function display_authors()
  207.     {
  208.         $params = array(0,$this->UserName,$this->PassWord);
  209.         return $this->send_request('wp.getAuthors',$params);
  210.     }
  211.  
  212.     function sayHello()
  213.     {
  214.         $params = array();
  215.         return $this->send_request('demo.sayHello',$params);
  216.     }
  217.  
  218. }
  219.  
  220.  
  221. $objXMLRPClientWordPress = new XMLRPClientWordPress("http://tivi.9appstore.com/xmlrpc.php" , "thieumao" , "12345678a@");
  222. //$objXMLRPClientWordPress->create_post('Post thu ma 2', 'Noi dung thu ma','');
  223. $post_type='post';
  224. $title="tuan11111111111111111111111111";
  225. $body="thieumao body";
  226. $category="Gi?i Trí";
  227. $icon=48;
  228. $tiviid="thieumao tiviid";
  229. $description="thieumao des";
  230. $link1="thieumao 1";
  231. $link2="thieumao 2";
  232. $link3="thieumao 3";
  233. $link4="thieumao 4";
  234. $isdefault="thieumao isdefault";
  235. $arrURL = array('http://tuan.com','http:tuann1.com','http://tuann2.com');
  236. $arrDescription = array('net ','cuc net','sieu cuc net');
  237. $objXMLRPClientWordPress->create_post_tivi($post_type,$title,$body,$category,$icon,$tiviid,$description,$link1,$link2,$link3,$link4,$isdefault,$arrURL,$arrDescription);
  238. echo "thanh cong12344";
  239.  
  240.  
  241.  
  242. ?>
Advertisement
Add Comment
Please, Sign In to add comment