Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $USER = "user de WP";
- $PASS = "pass de WP";
- $URL = "http://urldelsitio.com/"; //con la / al final
- $title = utf8_encode(html_entity_decode("Test WP"));
- $body = "Veamos si esto funciona";
- $category = "ninguna";
- $keywords = "";
- $custom = array();
- echo "ID: ".wpPostXMLRPC($title,$body,$URL.'xmlrpc.php',$USER,$PASS,$category,$keywords,$custom,'UTF-8').'<br/>';
- function utf8tohtml($utf8, $encodeTags) {
- $result = '';
- for ($i = 0; $i < strlen($utf8); $i++) {
- $char = $utf8[$i];
- $ascii = ord($char);
- if ($ascii < 128) {
- $result .= ($encodeTags) ? htmlentities($char) : $char;
- } else if ($ascii < 192) {
- } else if ($ascii < 224) {
- $result .= htmlentities(substr($utf8, $i, 2), ENT_QUOTES, 'UTF-8');
- $i++;
- } else if ($ascii < 240) {
- $ascii1 = ord($utf8[$i+1]);
- $ascii2 = ord($utf8[$i+2]);
- $unicode = (15 & $ascii) * 4096 + (63 & $ascii1) * 64 + (63 & $ascii2);
- $result .= "&#$unicode;";
- $i += 2;
- } else if ($ascii < 248) {
- $ascii1 = ord($utf8[$i+1]);
- $ascii2 = ord($utf8[$i+2]);
- $ascii3 = ord($utf8[$i+3]);
- $unicode = (15 & $ascii) * 262144 + (63 & $ascii1) * 4096 + (63 & $ascii2) * 64 + (63 & $ascii3);
- $result .= "&#$unicode;";
- $i += 3;
- }
- }
- return $result;
- }
- function wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$category,$keywords='',$custom='',$encoding='UTF-8'){
- $title = htmlentities($title,ENT_NOQUOTES,$encoding);
- $keywords = htmlentities($keywords,ENT_NOQUOTES,$encoding);
- $content = array(
- 'title'=>$title,
- 'description'=>$body,
- 'mt_allow_comments'=>1, // 1 to allow comments
- 'mt_allow_pings'=>0, // 1 to allow trackbacks
- 'post_type'=>'post',
- 'mt_keywords'=>$keywords,
- 'categories'=>array($category),
- 'custom_fields'=>$custom
- );
- $params = array(0,$username,$password,$content,true);
- $request = xmlrpc_encode_request('metaWeblog.newPost',$params);
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
- curl_setopt($ch, CURLOPT_URL, $rpcurl);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_TIMEOUT, 1);
- $results = curl_exec($ch);
- curl_close($ch);
- return strip_tags($results);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment