{"id":6846,"date":"2011-05-28T08:00:33","date_gmt":"2011-05-27T23:00:33","guid":{"rendered":"http:\/\/www.sssg.org\/blogs\/hiro345\/?p=6846"},"modified":"2011-06-08T17:04:11","modified_gmt":"2011-06-08T08:04:11","slug":"php-xml-rpc%e3%81%ab%e3%82%88%e3%82%8bwordpress%e3%81%b8%e3%81%ae%e8%a8%98%e4%ba%8b%e6%8a%95%e7%a8%bf","status":"publish","type":"post","link":"https:\/\/www.hiro345.net\/blogs\/hiro345\/archives\/6846.html","title":{"rendered":"PHP XML-RPC\u306b\u3088\u308bWordPress\u3078\u306e\u8a18\u4e8b\u6295\u7a3f"},"content":{"rendered":"<p>CentOS\u3092\u4f7f\u3063\u3066\u3044\u307e\u3059\u3002php-xmlrpc\uff08PHP XML-RPC\uff09\u3092\u4f7f\u3063\u3066\u3001WordPress\u3078\u8a18\u4e8b\u6295\u7a3f\u3092\u3059\u308b\u305f\u3081\u306b\u306f\u6b21\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p><!--more--><br \/>\nXML-RPC\u3092\u4f7f\u3046\u51e6\u7406\u306e\u809d\u306f\u3001wpPostXMLRPC\u95a2\u6570\u3067\u3059\u3002\u3053\u3053\u3078\u6295\u7a3f\u3059\u308b\u969b\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u6e21\u3059\u5fc5\u8981\u304c\u3042\u308b\u306e\u3067\u3001\u305d\u308c\u3092\u69cb\u7bc9\u3059\u308bcreateParam\u95a2\u6570\u3092\u7528\u610f\u3057\u3066\u3044\u307e\u3059\u3002\u30b3\u30f3\u30c6\u30f3\u30c4\u306e\u5185\u5bb9\u306b\u3064\u3044\u3066\u306f\u3001WordPress\u306e\u8a18\u4e8b\u3068\u5bfe\u5fdc\u3057\u305f\u5024\u3092\u8a2d\u5b9a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u306e\u3067\u3001\u305d\u308c\u3092\u69cb\u7bc9\u3059\u308bcreateContent\u95a2\u6570\u3082\u7528\u610f\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<div class=\"code\" style=\"overflow: scroll; width: 490px; white-space: nowrap;background-color:black;color:white;padding:4px;\">&#x24;&nbsp;cat&nbsp;wpxmlrpc.php&nbsp;<br \/>\n&lt;?php<br \/>\n&#x24;host&nbsp;=&nbsp;&quot;localhost&quot;&#x3b;<br \/>\n&#x24;xmlrpc_path&nbsp;=&nbsp;&quot;&#x2f;wp&#x2f;xmlrpc.php&quot;&#x3b;<br \/>\n&#x24;appkey&nbsp;=&nbsp;&#x27;&#x27;&#x3b;<br \/>\n&#x24;user&nbsp;=&nbsp;&#x27;user&#x27;&#x3b;<br \/>\n&#x24;pass&nbsp;=&nbsp;&#x27;pass&#x27;&#x3b;<br \/>\n&#x24;uri&nbsp;=&nbsp;&quot;http&#x3a;&#x2f;&#x2f;&quot;&nbsp;.&nbsp;&#x24;host&nbsp;.&nbsp;&#x24;xmlrpc_path&#x3b;<\/p>\n<p>function&nbsp;createContent(<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&#x24;title,<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&#x24;body,<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&#x24;keywords=&#x27;&#x27;,<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&#x24;category,<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&#x24;encoding=&#x27;UTF&#x2d;8&#x27;<br \/>\n&nbsp;&nbsp;)&nbsp;{<br \/>\n&nbsp;&nbsp;&#x24;title&nbsp;=&nbsp;htmlentities(&#x24;title,&nbsp;ENT_NOQUOTES,&nbsp;&#x24;encoding)&#x3b;<br \/>\n&nbsp;&nbsp;&#x24;keywords&nbsp;=&nbsp;htmlentities(&#x24;keywords,&nbsp;ENT_NOQUOTES,&nbsp;&#x24;encoding)&#x3b;<br \/>\n&nbsp;&nbsp;&#x24;content&nbsp;=&nbsp;array(<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&#x27;title&#x27;=&gt;&#x24;title,<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&#x27;description&#x27;=&gt;&#x24;body,<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&#x27;mt_allow_comments&#x27;=&gt;0,&nbsp;&nbsp;&#x2f;&#x2f;&nbsp;1&#x3a;\u30b3\u30e1\u30f3\u30c8\u8a31\u53ef<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&#x27;mt_allow_pings&#x27;=&gt;0,&nbsp;&nbsp;&#x2f;&#x2f;&nbsp;1&#x3a;\u30c8\u30e9\u30c3\u30af\u30d0\u30c3\u30af\u8a31\u53ef<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&#x27;post_type&#x27;=&gt;&#x27;post&#x27;,<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&#x27;mt_keywords&#x27;=&gt;&#x24;keywords,<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&#x27;categories&#x27;=&gt;array(&#x24;category)<br \/>\n&nbsp;&nbsp;)&#x3b;<br \/>\n&nbsp;&nbsp;return&nbsp;&#x24;content&#x3b;<br \/>\n}<\/p>\n<p>function&nbsp;createParam(<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&#x24;content,<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&#x24;username,<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&#x24;password,<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&#x24;status=false<br \/>\n&nbsp;&nbsp;)&nbsp;{<br \/>\n&nbsp;&nbsp;&#x24;params&nbsp;=&nbsp;array(0,&nbsp;&#x24;username,&nbsp;&#x24;password,&nbsp;&#x24;content,&nbsp;&#x24;status)&#x3b;<br \/>\n&nbsp;&nbsp;return&nbsp;&#x24;params&#x3b;<br \/>\n}<\/p>\n<p>function&nbsp;wpPostXMLRPC(&#x24;uri,&nbsp;&#x24;method,&nbsp;&#x24;params,&nbsp;&#x24;isXml)&nbsp;{<br \/>\n&nbsp;&nbsp;&#x24;request&nbsp;=&nbsp;xmlrpc_encode_request(&#x24;method,&nbsp;&#x24;params)&#x3b;<br \/>\n&nbsp;&nbsp;&#x24;ch&nbsp;=&nbsp;curl_init()&#x3b;&nbsp;&#x2f;&#x2f;&nbsp;curl&nbsp;handle<br \/>\n&nbsp;&nbsp;curl_setopt(&#x24;ch,&nbsp;CURLOPT_POSTFIELDS,&nbsp;&#x24;request)&#x3b;<br \/>\n&nbsp;&nbsp;curl_setopt(&#x24;ch,&nbsp;CURLOPT_URL,&nbsp;&#x24;uri)&#x3b;<br \/>\n&nbsp;&nbsp;curl_setopt(&#x24;ch,&nbsp;CURLOPT_HEADER,&nbsp;false)&#x3b;<br \/>\n&nbsp;&nbsp;if&nbsp;(&#x24;isXml)&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;&nbsp;xml\u30c7\u30fc\u30bf&nbsp;\u3092\u53d7\u3051\u53d6\u308a\u305f\u3044\u5834\u5408<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt(&#x24;ch,&nbsp;CURLOPT_HTTPHEADER,&nbsp;array(&quot;Content&#x2d;Type&#x3a;&nbsp;text&#x2f;xml&quot;))&#x3b;<br \/>\n&nbsp;&nbsp;}&nbsp;else&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;&nbsp;entry&nbsp;id&nbsp;\u3092\u53d7\u3051\u53d6\u308a\u305f\u3044\u5834\u5408<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt(&#x24;ch,&nbsp;CURLOPT_RETURNTRANSFER,&nbsp;1)&#x3b;<br \/>\n&nbsp;&nbsp;}<br \/>\n&nbsp;&nbsp;curl_setopt(&#x24;ch,&nbsp;CURLOPT_TIMEOUT,&nbsp;1)&#x3b;<br \/>\n&nbsp;&nbsp;&#x24;results&nbsp;=&nbsp;curl_exec(&#x24;ch)&#x3b;<br \/>\n&nbsp;&nbsp;curl_close(&#x24;ch)&#x3b;<br \/>\n&nbsp;&nbsp;return&nbsp;&#x24;results&#x3b;<br \/>\n}<\/p>\n<p>&#x24;body&nbsp;=&nbsp;createContent(<br \/>\n&nbsp;&nbsp;&quot;title&nbsp;3&quot;,<br \/>\n&nbsp;&nbsp;&quot;test&nbsp;text3.&quot;,<br \/>\n&nbsp;&nbsp;&quot;\u672a\u5206\u985e&quot;<br \/>\n)&#x3b;<br \/>\n&#x24;param&nbsp;=&nbsp;createParam(&#x24;user,&nbsp;&#x24;pass,&nbsp;true)&#x3b;<\/p>\n<p>&#x24;method&nbsp;=&nbsp;&#x27;metaWeblog.newPost&#x27;&#x3b;<br \/>\n&#x24;isXml&nbsp;=&nbsp;true&#x3b;<br \/>\n&#x24;response&nbsp;=&nbsp;wpPostXMLRPC(&#x24;uri,&nbsp;&#x24;method,&nbsp;&#x24;param,&nbsp;&#x24;isXml)&#x3b;<br \/>\nprint_r(&#x24;response)&#x3b;<br \/>\n?&gt;\n<\/p><\/div>\n<p>\u52d5\u4f5c\u672a\u78ba\u8a8d\u3067\u3059\u304c\u3001class\u306b\u3059\u308b\u3068\u3057\u305f\u3089\u4e0b\u8a18\u306e\u3088\u3046\u306a\u611f\u3058\u306b\u306a\u308b\u306f\u305a\u3067\u3059\u3002\u3053\u3061\u3089\u306e\u4f8b\u3067\u306f\u3001CURLOPT_POST\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u6307\u5b9a\u3092__call\u30e1\u30bd\u30c3\u30c9\u5185\u3067\u6307\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002xmlrpc_decode_request\u95a2\u6570\u3082\u4f7f\u3063\u3066\u3044\u307e\u3059\u3002\u306a\u304a\u3001XML\u3067\u53d7\u3051\u3068\u308b\u304b\u3001entry id\u3067\u53d7\u3051\u3068\u308b\u304b\u306e\u6307\u5b9a\u306b\u3064\u3044\u3066\u306f\u7701\u7565\u3092\u3057\u3066\u3042\u308b\u3001\u3068\u3044\u3063\u305f\u9055\u3044\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<div class=\"code\" style=\"overflow: scroll; width: 490px; white-space: nowrap;background-color:black;color:white;padding:4px;\">class&nbsp;XMLRPCClient&nbsp;{<br \/>\n&nbsp;&nbsp;public&nbsp;function&nbsp;__construct(&#x24;uri)&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&#x24;this&#x2d;&gt;uri&nbsp;=&nbsp;&#x24;uri&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&#x24;this&#x2d;&gt;ch&nbsp;=&nbsp;null&#x3b;&nbsp;&#x2f;&#x2f;&nbsp;curl&nbsp;handle<br \/>\n&nbsp;&nbsp;}<br \/>\n&nbsp;&nbsp;public&nbsp;function&nbsp;__destruct()&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&#x24;this&#x2d;&gt;close()&#x3b;<br \/>\n&nbsp;&nbsp;}<br \/>\n&nbsp;&nbsp;public&nbsp;function&nbsp;close()&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&#x24;this&#x2d;&gt;ch&nbsp;&#x21;==&nbsp;null)&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_close(&#x24;this&#x2d;&gt;ch)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&#x24;this&#x2d;&gt;ch&nbsp;=&nbsp;null&#x3b;<br \/>\n&nbsp;&nbsp;}<br \/>\n&nbsp;&nbsp;public&nbsp;function&nbsp;__call(&#x24;method,&nbsp;&#x24;params)&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&#x24;ch&nbsp;=&nbsp;&#x24;this&#x2d;&gt;ch&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&#x24;ch&nbsp;===&nbsp;null)&nbsp;&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x24;this&#x2d;&gt;ch&nbsp;=&nbsp;curl_init()&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt(&#x24;ch,&nbsp;CURLOPT_URL,&nbsp;&#x24;this&#x2d;&gt;uri)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt(&#x24;ch,&nbsp;CURLOPT_HEADER,&nbsp;false)&#x3b;&nbsp;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt(&#x24;ch,&nbsp;CURLOPT_RETURNTRANSFER,&nbsp;true)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt(&#x24;ch,&nbsp;CURLOPT_POST,&nbsp;true)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&#x24;xml&nbsp;=&nbsp;xmlrpc_encode_request(&#x24;method,&nbsp;&#x24;params)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt(&#x24;ch,&nbsp;CURLOPT_POSTFIELDS,&nbsp;&#x24;xml)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&#x24;response&nbsp;=&nbsp;curl_exec(&#x24;ch)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&#x24;result&nbsp;=&nbsp;xmlrpc_decode_request(&#x24;response,&nbsp;&#x24;method)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;&#x24;result&#x3b;<br \/>\n&nbsp;&nbsp;}<br \/>\n}\n<\/div>\n<p><a href=\"http:\/\/codex.wordpress.org\/XML-RPC_wp\">XML-RPC wp \u00ab WordPress Codex<\/a>\u3082\u53c2\u8003\u306b\u306a\u308b\u3067\u3057\u3087\u3046\u3002<\/p>\n<p>WordPress 3.0 \u95a2\u9023\u66f8\u7c4d\uff1a<br \/>\n<iframe src=\"\/\/rcm-jp.amazon.co.jp\/e\/cm?t=hiro345-22&#038;o=9&#038;p=8&#038;l=as1&#038;asins=4883377245&#038;ref=tf_til&#038;fc1=000000&#038;IS2=1&#038;lt1=_blank&#038;m=amazon&#038;lc1=0000FF&#038;bc1=000000&#038;bg1=FFFFFF&#038;f=ifr\" style=\"width:120px;height:240px;\" scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\"><\/iframe><iframe src=\"\/\/rcm-jp.amazon.co.jp\/e\/cm?t=hiro345-22&#038;o=9&#038;p=8&#038;l=as1&#038;asins=4839935416&#038;ref=tf_til&#038;fc1=000000&#038;IS2=1&#038;lt1=_blank&#038;m=amazon&#038;lc1=0000FF&#038;bc1=000000&#038;bg1=FFFFFF&#038;f=ifr\" style=\"width:120px;height:240px;\" scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\"><\/iframe><iframe src=\"\/\/rcm-jp.amazon.co.jp\/e\/cm?t=hiro345-22&#038;o=9&#038;p=8&#038;l=as1&#038;asins=4797360887&#038;ref=tf_til&#038;fc1=000000&#038;IS2=1&#038;lt1=_blank&#038;m=amazon&#038;lc1=0000FF&#038;bc1=000000&#038;bg1=FFFFFF&#038;f=ifr\" style=\"width:120px;height:240px;\" scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\"><\/iframe><iframe src=\"\/\/rcm-jp.amazon.co.jp\/e\/cm?t=hiro345-22&#038;o=9&#038;p=8&#038;l=as1&#038;asins=4839936072&#038;ref=tf_til&#038;fc1=000000&#038;IS2=1&#038;lt1=_blank&#038;m=amazon&#038;lc1=0000FF&#038;bc1=000000&#038;bg1=FFFFFF&#038;f=ifr\" style=\"width:120px;height:240px;\" scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\"><\/iframe><iframe src=\"\/\/rcm-jp.amazon.co.jp\/e\/cm?t=hiro345-22&#038;o=9&#038;p=8&#038;l=as1&#038;asins=488337730X&#038;ref=tf_til&#038;fc1=000000&#038;IS2=1&#038;lt1=_blank&#038;m=amazon&#038;lc1=0000FF&#038;bc1=000000&#038;bg1=FFFFFF&#038;f=ifr\" style=\"width:120px;height:240px;\" scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>CentOS\u3092\u4f7f\u3063\u3066\u3044\u307e\u3059\u3002php-xmlrpc\uff08PHP XML-RPC\uff09\u3092\u4f7f\u3063\u3066\u3001WordPress\u3078\u8a18\u4e8b\u6295\u7a3f\u3092\u3059\u308b\u305f\u3081\u306b\u306f\u6b21\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[26,295,70,467],"class_list":["post-6846","post","type-post","status-publish","format-standard","hentry","category-program","tag-centos","tag-php","tag-wordpress","tag-xml-rpc"],"_links":{"self":[{"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/posts\/6846","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/comments?post=6846"}],"version-history":[{"count":7,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/posts\/6846\/revisions"}],"predecessor-version":[{"id":7095,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/posts\/6846\/revisions\/7095"}],"wp:attachment":[{"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/media?parent=6846"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/categories?post=6846"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/tags?post=6846"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}