From fcbfccf2c7215c22d7565b1a402def6a56c50319 Mon Sep 17 00:00:00 2001 From: yoichi Date: Sun, 14 Jun 2015 18:07:37 +0900 Subject: [PATCH] =?UTF-8?q?=E8=A8=98=E4=BA=8B=E3=81=AE=E7=B7=A8=E9=9B=86?= =?UTF-8?q?=E3=80=81=E5=89=8A=E9=99=A4=E3=80=81=E8=A8=98=E4=BA=8B=E3=81=AE?= =?UTF-8?q?=E5=8F=96=E5=BE=97=E6=98=A8=E6=97=A5=E3=82=92=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?=E3=80=82=E3=82=AB=E3=82=B9=E3=82=BF=E3=83=A0=E3=83=95=E3=82=A3?= =?UTF-8?q?=E3=83=BC=E3=83=AB=E3=83=89=E3=81=AE=E6=A9=9F=E8=83=BD=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wp.xmlrpc.php | 97 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 81 insertions(+), 16 deletions(-) diff --git a/wp.xmlrpc.php b/wp.xmlrpc.php index 21e82a7..977802f 100644 --- a/wp.xmlrpc.php +++ b/wp.xmlrpc.php @@ -54,14 +54,9 @@ protected function sendXMLRPC($message) { } return XML_RPC_decode($res->value()); } - - /** - * 新規記事投稿 - * - * @param struct $data 投稿内容のデータ - * @return struct - */ - public function newPost(array $data) { + + + public function contentData(array $data){ $content = array(); // 投稿タイプ (post|page|attachment) @@ -150,13 +145,24 @@ public function newPost(array $data) { if ( $custom_fields = $data['custom_fields'] ) { $content['custom_fields'] = array(); foreach($custom_fields as $field) { - $content['custom_fields'][] = new XML_RPC_Value( - array( - 'key' => new XML_RPC_Value($field['key'], 'string'), - 'value' => new XML_RPC_Value($field['value'], 'string') - ), - 'struct' - ); + if(!$field['id']){ + $content['custom_fields'][] = new XML_RPC_Value( + array( + 'key' => new XML_RPC_Value($field['key'], 'string'), + 'value' => new XML_RPC_Value($field['value'], 'string') + ), + 'struct' + ); + }else{ + $content['custom_fields'][] = new XML_RPC_Value( + array( + 'id' => new XML_RPC_Value($field['id'], 'string'), + 'key' => new XML_RPC_Value($field['key'], 'string'), + 'value' => new XML_RPC_Value($field['value'], 'string') + ), + 'struct' + ); + } } $content['custom_fields'] = new XML_RPC_Value($content['custom_fields'], 'struct'); } @@ -165,7 +171,7 @@ public function newPost(array $data) { $content['post_name'] = new XML_RPC_Value($post_name, 'string'); } // terms - if ( $terms = $data['terms'] ) { + if ( $terms = $data['terms'] ) { $content['terms'] = array(); foreach($terms as $key => $value) { $content['terms'][$key] = array(); @@ -215,6 +221,9 @@ public function newPost(array $data) { 'taxonomy' => $key ); } + //termKey urlencode + $termKey = urlencode($termKey); + $termKey = mb_strtolower($termKey); $term_id = (!$termList[$termKey]) ? $this->newTerm($termValue) : $termList[$termKey]['term_id']; $content['terms'][$key][] = new XML_RPC_Value($term_id, 'int'); @@ -270,6 +279,18 @@ public function newPost(array $data) { 'struct' ); } + return $content; + } + /** + * 新規記事投稿 + * + * @param struct $data 投稿内容のデータ + * @return struct + */ + public function newPost(array $data) { + + $content = $this->contentData($data); + $content = new XML_RPC_Value($content, 'struct'); $publish = new XML_RPC_Value(1, 'boolean'); $message = new XML_RPC_Message( @@ -278,6 +299,50 @@ public function newPost(array $data) { ); return $this->sendXMLRPC($message); } + /** + * 記事編集 + */ + public function editPost(array $data, $wp_post_id=null) { + + $content = $this->contentData($data); + + $wp_id = new XML_RPC_Value($wp_post_id, 'int'); + $content = new XML_RPC_Value($content, 'struct'); + $message = new XML_RPC_Message( + 'wp.editPost', + array($this->blog_id, $this->user, $this->password, $wp_id, $content) + ); + + return $this->sendXMLRPC($message); + } + + /** + * 記事削除 + */ + public function deletePost($wp_post_id=null, $force_delete=false) { + + $wp_id = new XML_RPC_Value($wp_post_id, 'int'); + $message = new XML_RPC_Message( + 'wp.deletePost', + array($this->blog_id, $this->user, $this->password, $wp_id) + ); + + return $this->sendXMLRPC($message); + } + + /** + * 記事取得 + */ +public function getPost($wp_post_id=null) { + $wp_id = new XML_RPC_Value($wp_post_id, 'int'); + + $message = new XML_RPC_Message( + 'wp.getPost', + array($this->blog_id, $this->user, $this->password, $wp_id) + ); + + return $this->sendXMLRPC($message); +} /** * Term一覧取得