thieumao

postPages.php

Mar 5th, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.56 KB | None | 0 0
  1. <?php
  2. $response = array();
  3. require_once __DIR__ . '/db_connect.php';
  4. require_once __DIR__ . '/db_config.php';
  5. echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
  6.  
  7. $db = new DB_CONNECT();
  8. mysql_query('SET CHARACTER SET utf8') ;
  9. $cateid = isset($_GET['cateid'])?$_GET['cateid']:'0';
  10. if ($cateid == 0 ) {
  11.     $sql = "SELECT cateid,pageid,pagename,pagecontent FROM detailstory";
  12. } else {
  13.     $sql = "SELECT cateid,pageid,pagename,pagecontent FROM detailstory where `cateid` = '$cateid'";  
  14. }
  15. $result = mysql_query($sql) or die(mysql_error());
  16.  
  17. class XMLRPClientWordPress
  18. {
  19.  
  20.  
  21.     var $XMLRPCURL;
  22.     var $UserName;
  23.     var $PassWord;
  24.  
  25.     // constructor
  26.     public function __construct($xmlrpcurl, $username, $password)
  27.     {
  28.         $this->XMLRPCURL = $xmlrpcurl;
  29.         $this->UserName  = $username;
  30.         $this->PassWord = $password;
  31.            
  32.     }
  33.  
  34.     function send_request($requestname, $params)
  35.     {
  36.         //$request = xmlrpc_encode_request($requestname, $params);
  37.         $request = xmlrpc_encode_request('metaWeblog.newPost',$params,array('encoding'=>'UTF-8','escaping'=>'markup'));
  38.         $ch = curl_init();
  39.         curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
  40.         curl_setopt($ch, CURLOPT_URL, $this->XMLRPCURL);
  41.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  42.         curl_setopt($ch, CURLOPT_TIMEOUT, 1);
  43.         $results = curl_exec($ch);
  44.         curl_close($ch);
  45.         return $results;
  46.     }
  47.  
  48.     function create_post($title,$body,$category,$keywords='',$encoding='UTF-8')
  49.     {
  50.         $title = htmlentities($title,ENT_NOQUOTES,$encoding);
  51.         $keywords = htmlentities($keywords,ENT_NOQUOTES,$encoding);
  52.  
  53.         $content = array(
  54.             'title'=>'Nguyễn Văn Thiệu có dấu mà 123',
  55.             'description'=>$body,
  56.             'mt_allow_comments'=>0,  // 1 to allow comments
  57.             'mt_allow_pings'=>0,  // 1 to allow trackbacks
  58.             'post_type'=>'truyen',
  59.             'mt_keywords'=>$keywords,
  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_football($title,$body,$category,$introtext,$imageFull,$thumbnail,$linksource,
  69.     $linkserver,$linkyoutube,$linkdropbox,$matchtime,$ishot,$keywords='',$encoding='UTF-8')
  70.     {
  71.         $title = htmlentities($title,ENT_NOQUOTES,$encoding);
  72.         $keywords = htmlentities($keywords,ENT_NOQUOTES,$encoding);
  73.         $content = array(
  74.             'title'=>$title,
  75.             'description'=>$body,
  76.             'mt_allow_comments'=>1,  // 1 to allow comments
  77.             'mt_allow_pings'=>1,  // 1 to allow trackbacks
  78.             'post_type'=>'clip',
  79.             'mt_keywords'=>$keywords,
  80.             "custom_fields" => array(
  81.                 array( 'key' => 'introtext', 'value' => $introtext ),
  82.                 array( 'key' => '_introtext', 'value' => 'field_52f1e887ee97f'),
  83.                 array( 'key' => 'imageFull', 'value' => $imageFull ),
  84.                 array( 'key' => '_imageFull', 'value' => 'field_52f1e887ef089'),
  85.                 array( 'key' => 'thumbnail', 'value' => $thumbnail ),
  86.                 array( 'key' => '_thumbnail', 'value' => 'field_52f1e887ef759'),
  87.                 array( 'key' => 'linksource', 'value' => $linksource ),
  88.                 array( 'key' => '_linksource', 'value' => 'field_52f1e88803f57'),
  89.                 array( 'key' => 'linkserver', 'value' => $linkserver ),
  90.                 array( 'key' => '_linkserver', 'value' => 'field_52f1e88804684'),
  91.                 array( 'key' => 'linkyoutube', 'value' => $linkyoutube ),
  92.                 array( 'key' => '_linkyoutube', 'value' => 'field_52f1e88804d93'),
  93.                 array( 'key' => 'linkdropbox', 'value' => $linkdropbox ),
  94.                 array( 'key' => '_linkdropbox', 'value' => 'field_52f1e888054e4'),
  95.                 array( 'key' => 'matchtime', 'value' => $matchtime ),
  96.                 array( 'key' => '_matchtime', 'value' => 'field_52f1e88805c33'),
  97.                 array( 'key' => 'ishot', 'value' => $ishot ),
  98.                 array( 'key' => '_ishot', 'value' => 'field_52f1e888063a4'),
  99.             ),
  100.             'categories'=>array($category)
  101.         );
  102.         $params = array(0,$this->UserName,$this->PassWord,$content,true);
  103.         return $this->send_request('metaWeblog.newPost',$params);
  104.  
  105.     }
  106.  
  107.     function create_page($title,$body,$encoding='UTF-8')
  108.     {
  109.         $title = htmlentities($title,ENT_NOQUOTES,$encoding);
  110.  
  111.         $content = array(
  112.             'title'=>$title,
  113.             'description'=>$body
  114.         );
  115.         $params = array(0,$this->UserName,$this->PassWord,$content,true);
  116.  
  117.         return $this->send_request('wp.newPage',$params);
  118.     }
  119.  
  120.     function display_authors()
  121.     {
  122.         $params = array(0,$this->UserName,$this->PassWord);
  123.         return $this->send_request('wp.getAuthors',$params);
  124.     }
  125.  
  126.     function sayHello()
  127.     {
  128.         $params = array();
  129.         return $this->send_request('demo.sayHello',$params);
  130.     }
  131.  
  132. }
  133.  
  134. function convertEncoding($str, $from = 'auto', $to = "UTF-8") {
  135.     if($from == 'auto') $from = mb_detect_encoding($str);
  136.     return mb_convert_encoding ($str , $to, $from);
  137. }
  138.  
  139. $objXMLRPClientWordPress = new XMLRPClientWordPress(XMLRFC_LINK , XMLRFC_USER , XMLRFC_PASS);
  140. $dem = 0;
  141. if (mysql_num_rows($result) > 0) {
  142.     $response["detailstory"] = array();
  143.     while ($row = mysql_fetch_array($result)) {
  144.         $dem++;
  145.         $detailstory = array();
  146.         $detailstory["cateid"] = $row["cateid"];
  147.         $detailstory["pageid"] = $row["pageid"];
  148.         $detailstory["pagename"] = $row["pagename"];
  149.         $detailstory["pagecontent"] = $row["pagecontent"];
  150.         echo $dem . ' - ' . $row["pagename"] . "<br>";
  151.         if ($dem == 1329 ){
  152.             //$tieude = convertEncoding($row["pagename"]);
  153.             //$tieude = $row["pagename"];
  154.             $tieude = "Nguyễn Văn Thiệu 2";
  155.             $noidung = $row["pagecontent"];
  156.             $chuyenmuc = "";
  157.             $objXMLRPClientWordPress->create_post($tieude, $noidung, $chuyenmuc);
  158.             echo "<br><br>_________<br><br>";
  159.             echo $tieude;
  160.             echo "<br>";
  161.             echo $noidung;
  162.             echo "<br><br>_________<br><br>";
  163.         }
  164.         array_push($response["detailstory"], $detailstory);
  165.     }
  166.     //echo json_encode($response);
  167. } else {
  168.     $response["success"] = 0;
  169.     $response["message"] = "No products found";
  170.     echo json_encode($response);
  171. }
  172. ?>
Advertisement
Add Comment
Please, Sign In to add comment