Guest User

Untitled

a guest
Aug 4th, 2014
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.23 KB | None | 0 0
  1. <?php
  2.     $USER = "user de WP";
  3.     $PASS = "pass de WP";
  4.     $URL = "http://urldelsitio.com/"; //con la / al final
  5.  
  6.     $title = utf8_encode(html_entity_decode("Test WP"));
  7.     $body = "Veamos si esto funciona";
  8.     $category = "ninguna";
  9.     $keywords = "";
  10.     $custom = array();
  11.  
  12.     echo "ID: ".wpPostXMLRPC($title,$body,$URL.'xmlrpc.php',$USER,$PASS,$category,$keywords,$custom,'UTF-8').'<br/>';
  13.  
  14.     function utf8tohtml($utf8, $encodeTags) {
  15.         $result = '';
  16.         for ($i = 0; $i < strlen($utf8); $i++) {
  17.             $char = $utf8[$i];
  18.             $ascii = ord($char);
  19.             if ($ascii < 128) {
  20.                 $result .= ($encodeTags) ? htmlentities($char) : $char;
  21.             } else if ($ascii < 192) {
  22.  
  23.             } else if ($ascii < 224) {
  24.                 $result .= htmlentities(substr($utf8, $i, 2), ENT_QUOTES, 'UTF-8');
  25.                 $i++;
  26.             } else if ($ascii < 240) {
  27.                 $ascii1 = ord($utf8[$i+1]);
  28.                 $ascii2 = ord($utf8[$i+2]);
  29.                 $unicode = (15 & $ascii) * 4096 + (63 & $ascii1) * 64 + (63 & $ascii2);
  30.                 $result .= "&#$unicode;";
  31.                 $i += 2;
  32.             } else if ($ascii < 248) {
  33.                 $ascii1 = ord($utf8[$i+1]);
  34.                 $ascii2 = ord($utf8[$i+2]);
  35.                 $ascii3 = ord($utf8[$i+3]);
  36.                 $unicode = (15 & $ascii) * 262144 + (63 & $ascii1) * 4096 + (63 & $ascii2) * 64 + (63 & $ascii3);
  37.                 $result .= "&#$unicode;";
  38.                 $i += 3;
  39.             }
  40.         }
  41.         return $result;
  42.     }
  43.  
  44.     function wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$category,$keywords='',$custom='',$encoding='UTF-8'){
  45.         $title = htmlentities($title,ENT_NOQUOTES,$encoding);
  46.         $keywords = htmlentities($keywords,ENT_NOQUOTES,$encoding);
  47.         $content = array(
  48.             'title'=>$title,
  49.             'description'=>$body,
  50.             'mt_allow_comments'=>1,  // 1 to allow comments
  51.             'mt_allow_pings'=>0,  // 1 to allow trackbacks
  52.             'post_type'=>'post',
  53.             'mt_keywords'=>$keywords,
  54.             'categories'=>array($category),
  55.             'custom_fields'=>$custom
  56.         );
  57.         $params = array(0,$username,$password,$content,true);
  58.         $request = xmlrpc_encode_request('metaWeblog.newPost',$params);
  59.         $ch = curl_init();
  60.         curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
  61.         curl_setopt($ch, CURLOPT_URL, $rpcurl);
  62.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  63.         curl_setopt($ch, CURLOPT_TIMEOUT, 1);
  64.         $results = curl_exec($ch);
  65.         curl_close($ch);
  66.  
  67.         return strip_tags($results);
  68.     }
  69. ?>
Advertisement
Add Comment
Please, Sign In to add comment