From 8dcb2512d8d472133111112936b7139e4975e4a2 Mon Sep 17 00:00:00 2001 From: Loftor Date: Wed, 25 Dec 2013 17:13:04 +0800 Subject: [PATCH 1/3] =?UTF-8?q?wordpress=20=E6=89=8B=E6=9C=BA=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- var/Widget/Archive.php | 6 +- var/Widget/Feedback.php | 4 +- var/Widget/XmlRpc.php | 145 +++++++++++++++++++++++++++++++++++----- 3 files changed, 135 insertions(+), 20 deletions(-) diff --git a/var/Widget/Archive.php b/var/Widget/Archive.php index f5f25af5..eb3aee8a 100644 --- a/var/Widget/Archive.php +++ b/var/Widget/Archive.php @@ -736,7 +736,10 @@ class Widget_Archive extends Widget_Abstract_Contents $this->_archiveType = 'single'; /** 匹配类型 */ - $select->where('table.contents.type = ?', $this->parameter->type); + + if ('single'!=$this->parameter->type) { + $select->where('table.contents.type = ?', $this->parameter->type); + } /** 如果是单篇文章或独立页面 */ if (isset($this->request->cid)) { @@ -1215,6 +1218,7 @@ class Widget_Archive extends Widget_Abstract_Contents 'archive' => 'error404Handle', 'archive_page' => 'error404Handle', 404 => 'error404Handle', + 'single' => 'singleHandle', 'page' => 'singleHandle', 'post' => 'singleHandle', 'attachment' => 'singleHandle', diff --git a/var/Widget/Feedback.php b/var/Widget/Feedback.php index fb4cf7c8..58ee846f 100644 --- a/var/Widget/Feedback.php +++ b/var/Widget/Feedback.php @@ -275,9 +275,9 @@ class Widget_Feedback extends Widget_Abstract_Comments implements Widget_Interfa if (!$this->_content->allow('comment')) { throw new Typecho_Widget_Exception(_t('对不起,此内容的反馈被禁止.'), 403); } - + /** 检查来源 */ - if ($this->options->commentsCheckReferer) { + if ($this->options->commentsCheckReferer&&'false'!=$this->parameter->checkReferer) { $referer = $this->request->getReferer(); if (empty($referer)) { diff --git a/var/Widget/XmlRpc.php b/var/Widget/XmlRpc.php index 6afd17e5..235ff393 100644 --- a/var/Widget/XmlRpc.php +++ b/var/Widget/XmlRpc.php @@ -217,6 +217,27 @@ class Widget_XmlRpc extends Widget_Abstract_Contents implements Widget_Interface 'readonly' => true, 'option' => 'siteUrl' ), + 'home_url' => array( + 'desc' => _t( '博客首页地址' ), + 'readonly' => true, + 'option' => 'siteUrl' + ), + 'login_url' => array( + 'desc' => _t( '登录地址' ), + 'readonly' => true, + 'value' => $this->options->siteUrl.'admin/login.php' + ), + 'admin_url' => array( + 'desc' => _t( '管理区域的地址' ), + 'readonly' => true, + 'value' => $this->options->siteUrl.'admin/' + ), + + 'post_thumbnail' => array( + 'desc' => _t( '文章缩略图' ), + 'readonly' => true, + 'value' => true + ), // Updatable options 'time_zone' => array( @@ -315,7 +336,7 @@ class Widget_XmlRpc extends Widget_Abstract_Contents implements Widget_Interface 'description' => $excerpt, 'title' => $page->title, 'link' => $page->permalink, - 'permalink' => $page->permalink, + 'permaLink' => $page->permalink, 'categories' => $page->categories, 'excerpt' => $page->description, 'text_more' => $more, @@ -365,13 +386,13 @@ class Widget_XmlRpc extends Widget_Abstract_Contents implements Widget_Interface $pageStructs[] = array( 'dateCreated' => new IXR_Date($this->options->timezone + $pages->created), 'userid' => $pages->authorId, - 'page_id' => $pages->cid, + 'page_id' => intval($pages->cid), /** todo:此处有疑问 */ 'page_status' => $this->typechoToWordpressStatus($pages->status, 'page'), 'description' => $excerpt, 'title' => $pages->title, 'link' => $pages->permalink, - 'permalink' => $pages->permalink, + 'permaLink' => $pages->permalink, 'categories' => $pages->categories, 'excerpt' => $pages->description, 'text_more' => $more, @@ -380,9 +401,9 @@ class Widget_XmlRpc extends Widget_Abstract_Contents implements Widget_Interface 'wp_slug' => $pages->slug, 'wp_password' => $pages->password, 'wp_author' => $pages->author->name, - 'wp_page_parent_id' => '0', + 'wp_page_parent_id' => 0, 'wp_page_parent_title' => '', - 'wp_page_order' => $pages->order, //meta是描述字段, 在page时表示顺序 + 'wp_page_order' => intval($pages->order), //meta是描述字段, 在page时表示顺序 'wp_author_id' => $pages->authorId, 'wp_author_display_name' => $pages->author->screenName, 'date_created_gmt' => new IXR_Date($pages->created), @@ -548,13 +569,14 @@ class Widget_XmlRpc extends Widget_Abstract_Contents implements Widget_Interface /** 调用已有组件 */ try { /** 插入 */ - $this->singletonWidget('Widget_Metas_Category_Edit', NULL, $input, false)->action(); - return $this->singletonWidget('Widget_Notice')->getHighlightId() ? true : false; + $categoryWidget = $this->singletonWidget('Widget_Metas_Category_Edit', NULL, $input, false); + $categoryWidget->action(); + return $categoryWidget->mid; } catch (Typecho_Widget_Exception $e) { return new IXR_Error($e->getCode(), $e->getMessage()); } - return true; + return new IXR_Error(403, _t('无法添加分类')); } /** @@ -606,6 +628,7 @@ class Widget_XmlRpc extends Widget_Abstract_Contents implements Widget_Interface */ public function wpGetUsersBlogs($userName, $password) { + if (!$this->checkAccess($userName, $password)) { return $this->error; } @@ -613,12 +636,42 @@ class Widget_XmlRpc extends Widget_Abstract_Contents implements Widget_Interface $struct = array(); $struct[] = array( 'isAdmin' => $this->user->pass('administrator', true), - 'url' => $this->options->siteUrl, + 'url' => $this->options->siteUrl, 'blogid' => '1', 'blogName' => $this->options->title, 'xmlrpc' => $this->options->xmlRpcUrl ); - + return $struct; + } + + /** + * 获取用户 + * + * @access public + * @param string $userName 用户名 + * @param string $password 密码 + * @return array + */ + public function wpGetProfile($blogId, $userName, $password) + { + + if (!$this->checkAccess($userName, $password)) { + return $this->error; + } + + $struct = array( + 'user_id' => $this->user->uid, + 'username' => $this->user->name, + 'first_name' => '', + 'last_name' => '', + 'registered' => new IXR_Date($this->options->timezone + $this->user->created), + 'bio' => '', + 'email' => $this->user->mail, + 'nickname' => $this->user->screenName, + 'url' => $this->user->url, + 'display_name' => $this->user->screenName, + 'roles' => $this->user->group + ); return $struct; } @@ -706,6 +759,28 @@ class Widget_XmlRpc extends Widget_Abstract_Contents implements Widget_Interface 'total_comments' => $stat->currentCommentsNum ); } + + + /** + * 获取文章类型列表 + * + * @access public + * @param integer $blogId + * @param string $userName + * @param string $password + * @return array + */ + public function wpGetPostFormats($blogId, $userName, $password) + { + /** 检查权限*/ + if (!$this->checkAccess($userName, $password)) { + return $this->error; + } + + return array( + 'standard' => _t('标准') + ); + } /** * 获取文章状态列表 @@ -751,6 +826,8 @@ class Widget_XmlRpc extends Widget_Abstract_Contents implements Widget_Interface 'publish' => _t('已发布') ); } + + /** * 获取评论状态列表 @@ -998,8 +1075,14 @@ class Widget_XmlRpc extends Widget_Abstract_Contents implements Widget_Interface } $commentId = abs(intval($commentId)); - return intval($this->singletonWidget('Widget_Abstract_Comments')->delete( - $this->db->sql()->where('coid = ?', $commentId))) > 0; + $commentWidget = $this->singletonWidget('Widget_Abstract_Comments'); + $where = $this->db->sql()->where('coid = ?', $commentId); + + if (!$commentWidget->commentIsWriteable($where)) { + return new IXR_Error(403, _t('无法编辑此评论')); + } + + return intval($this->singletonWidget('Widget_Abstract_Comments')->delete($where)) > 0; } /** @@ -1119,14 +1202,19 @@ class Widget_XmlRpc extends Widget_Abstract_Contents implements Widget_Interface } try { - $this->singletonWidget('Widget_Feedback', NULL, $input, false); + $commentWidget = $this->singletonWidget('Widget_Feedback', 'checkReferer=false', $input, false); + $commentWidget->action(); + return intval($commentWidget->coid); } catch (Typecho_Exception $e) { return new IXR_Error(500, $e->getMessage()); } - return true; + return new IXR_Error(403, _t('无法添加评论')); } + + + /**about MetaWeblog API, you can see http://www.xmlrpc.com/metaWeblogApi*/ /** * MetaWeblog API @@ -1306,7 +1394,7 @@ class Widget_XmlRpc extends Widget_Abstract_Contents implements Widget_Interface 'description' => $excerpt, 'title' => $post->title, 'link' => $post->permalink, - 'permalink' => $post->permalink, + 'permaLink' => $post->permalink, 'categories' => $categories, 'mt_excerpt' => $post->description, 'mt_text_more' => $more, @@ -1363,10 +1451,11 @@ class Widget_XmlRpc extends Widget_Abstract_Contents implements Widget_Interface 'description' => $excerpt, 'title' => $posts->title, 'link' => $posts->permalink, - 'permalink' => $posts->permalink, + 'permaLink' => $posts->permalink, 'categories' => $categories, 'mt_excerpt' => $posts->description, 'mt_text_more' => $more, + 'wp_more_text' => $more, 'mt_allow_comments' => intval($posts->allowComment), 'mt_allow_pings' => intval($posts->allowPing), 'mt_keywords' => implode(', ', $tags), @@ -1378,6 +1467,10 @@ class Widget_XmlRpc extends Widget_Abstract_Contents implements Widget_Interface 'date_created_gmt' => new IXR_Date($posts->created), 'post_status' => $this->typechoToWordpressStatus($posts->status, 'post'), 'custom_fields' => array(), + 'wp_post_format'=>'standard', + 'date_modified'=>new IXR_Date($this->options->timezone + $posts->modified), + 'date_modified_gmt' => new IXR_Date($posts->modified), + 'wp_post_thumbnail' => '', 'sticky' => 0 ); } @@ -1953,6 +2046,13 @@ class Widget_XmlRpc extends Widget_Abstract_Contents implements Widget_Interface } } + public function log($value='') + { + $fp = fopen("log.txt", "a+"); + fwrite($fp,"[".date('Y-m-d H:i:s')."]\t".$value."\n"); + fclose($fp); + } + /** * 入口执行方法 @@ -1962,6 +2062,9 @@ class Widget_XmlRpc extends Widget_Abstract_Contents implements Widget_Interface */ public function action() { + + // $this->log($GLOBALS['HTTP_RAW_POST_DATA']); + if (isset($this->request->rsd)) { echo << EOF; } else { + + + /** 直接把初始化放到这里 */ new IXR_Server(array( /** WordPress API */ @@ -2049,7 +2155,12 @@ EOF; 'wp.editComment' => array($this, 'wpEditComment'), 'wp.newComment' => array($this, 'wpNewComment'), 'wp.getCommentStatusList' => array($this, 'wpGetCommentStatusList'), - + + /** New Wordpress API after 2.9.2 */ + 'wp.getProfile' => array($this, 'wpGetProfile'), + 'wp.getPostFormats' => array($this, 'wpGetPostFormats'), + + /** Blogger API */ 'blogger.getUsersBlogs' => array($this, 'bloggerGetUsersBlogs'), From c5541ff5c37946430a7b4c803091d0004c78e268 Mon Sep 17 00:00:00 2001 From: loftor Date: Wed, 25 Dec 2013 20:14:31 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- var/Widget/XmlRpc.php | 50 +++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/var/Widget/XmlRpc.php b/var/Widget/XmlRpc.php index 235ff393..f7685404 100644 --- a/var/Widget/XmlRpc.php +++ b/var/Widget/XmlRpc.php @@ -217,27 +217,27 @@ class Widget_XmlRpc extends Widget_Abstract_Contents implements Widget_Interface 'readonly' => true, 'option' => 'siteUrl' ), - 'home_url' => array( - 'desc' => _t( '博客首页地址' ), - 'readonly' => true, - 'option' => 'siteUrl' - ), - 'login_url' => array( - 'desc' => _t( '登录地址' ), - 'readonly' => true, - 'value' => $this->options->siteUrl.'admin/login.php' - ), - 'admin_url' => array( - 'desc' => _t( '管理区域的地址' ), - 'readonly' => true, - 'value' => $this->options->siteUrl.'admin/' - ), - - 'post_thumbnail' => array( - 'desc' => _t( '文章缩略图' ), - 'readonly' => true, - 'value' => true - ), + 'home_url' => array( + 'desc' => _t( '博客首页地址' ), + 'readonly' => true, + 'option' => 'siteUrl' + ), + 'login_url' => array( + 'desc' => _t( '登录地址' ), + 'readonly' => true, + 'value' => $this->options->siteUrl.'admin/login.php' + ), + 'admin_url' => array( + 'desc' => _t( '管理区域的地址' ), + 'readonly' => true, + 'value' => $this->options->siteUrl.'admin/' + ), + + 'post_thumbnail' => array( + 'desc' => _t( '文章缩略图' ), + 'readonly' => true, + 'value' => false + ), // Updatable options 'time_zone' => array( @@ -2063,7 +2063,7 @@ class Widget_XmlRpc extends Widget_Abstract_Contents implements Widget_Interface public function action() { - // $this->log($GLOBALS['HTTP_RAW_POST_DATA']); + //$this->log($GLOBALS['HTTP_RAW_POST_DATA']); if (isset($this->request->rsd)) { echo @@ -2157,8 +2157,8 @@ EOF; 'wp.getCommentStatusList' => array($this, 'wpGetCommentStatusList'), /** New Wordpress API after 2.9.2 */ - 'wp.getProfile' => array($this, 'wpGetProfile'), - 'wp.getPostFormats' => array($this, 'wpGetPostFormats'), + 'wp.getProfile' => array($this, 'wpGetProfile'), + 'wp.getPostFormats' => array($this, 'wpGetPostFormats'), @@ -2197,7 +2197,7 @@ EOF; 'pingback.extensions.getPingbacks' => array($this,'pingbackExtensionsGetPingbacks'), /** hook after */ - 'hook.afterCall' => array($this, 'hookAfterCall'), + 'hook.afterCall' => array($this, 'hookAfterCall'), )); } } From 4843b2b30a6c6c5c0726a6b55f16eee5a1d84e90 Mon Sep 17 00:00:00 2001 From: loftor Date: Wed, 25 Dec 2013 23:51:52 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AA=92=E4=BD=93?= =?UTF-8?q?=E4=B8=AD=E5=BF=83=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- var/Widget/XmlRpc.php | 139 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 136 insertions(+), 3 deletions(-) diff --git a/var/Widget/XmlRpc.php b/var/Widget/XmlRpc.php index f7685404..e2fc23b2 100644 --- a/var/Widget/XmlRpc.php +++ b/var/Widget/XmlRpc.php @@ -481,6 +481,38 @@ class Widget_XmlRpc extends Widget_Abstract_Contents implements Widget_Interface $this->mwEditPost($blogId, $pageId, $userName, $password, $content, $publish); } + + /** + * 编辑postId指定的post + * + * @param int $blogId + * @param string $userName + * @param string $password + * @param int $postId + * @param struct $content + * @access public + * @return bool + */ + public function wpEditPost($blogId, $userName, $password, $postId, $content) + { + + $post = $this->singletonWidget('Widget_Archive', 'type=single', 'cid=' . $postId, false); + if ($post->type=='attachment') { + $attachment['title'] = $content['post_title']; + $attachment['slug'] = $content['post_excerpt']; + + $text = unserialize($post->text); + $text['description'] = $content['description']; + + $attachment['text'] = serialize($text); + + /** 更新数据 */ + $updateRows = $this->update($attachment, $this->db->sql()->where('cid = ?', $postId)); + return true; + } + return $this->mwEditPost($blogId, $postId, $userName, $password, $content, $publish); + } + /** * 获取page列表,没有wpGetPages获得的详细 * @@ -1153,9 +1185,9 @@ class Widget_XmlRpc extends Widget_Abstract_Contents implements Widget_Interface * @param integer $blogId * @param string $userName * @param string $password - * @param mixed $post + * @param mixed $path * @param array $struct - * @return boolean + * @return int */ public function wpNewComment($blogId, $userName, $password, $path, $struct) { @@ -1214,6 +1246,104 @@ class Widget_XmlRpc extends Widget_Abstract_Contents implements Widget_Interface + /** + * 获取媒体文件 + * + * @access public + * @param integer $blogId + * @param string $userName + * @param string $password + * @param struct $struct + * @return boolean + */ + public function wpGetMediaLibrary($blogId, $userName, $password, $struct) + { + /** 检查权限*/ + if (!$this->checkAccess($userName, $password)) { + return $this->error; + } + + + $input = array(); + + if (!empty($struct['parent_id'])) { + $input['parent'] = $struct['parent_id']; + } + + if (!empty($struct['mime_type'])) { + $input['mime'] = $struct['mime_type']; + } + + $pageSize = 10; + if (!empty($struct['number'])) { + $pageSize = abs(intval($struct['number'])); + } + + if (!empty($struct['offset'])) { + $input['page'] = abs(intval($struct['offset']))+1; + } + + $attachments = $this->singletonWidget('Widget_Contents_Attachment_Admin', 'pageSize=' . $pageSize, $input, false); + $attachmentsStruct = array(); + + while ($attachments->next()) { + $attachmentsStruct[] = array( + 'attachment_id' => $attachments->cid, + 'date_created_gmt' => new IXR_Date($this->options->timezone + $attachments->created), + 'parent' => $attachments->parent, + 'link' => $attachments->attachment->url, + 'title' => $attachments->title, + 'caption' => $attachments->slug, + 'description' => $attachments->attachment->description, + 'metadata' => array( + 'file'=>$attachments->attachment->path, + 'size'=>$attachments->attachment->size, + ), + 'thumbnail' => $attachments->attachment->url, + + ); + } + return $attachmentsStruct; + } + + /** + * 获取媒体文件 + * + * @access public + * @param integer $blogId + * @param string $userName + * @param string $password + * @param int $attachmentId + * @return boolean + */ + public function wpGetMediaItem($blogId, $userName, $password, $attachmentId) + { + /** 检查权限*/ + if (!$this->checkAccess($userName, $password)) { + return $this->error; + } + + + $attachment = $this->singletonWidget('Widget_Contents_Attachment_Edit', NULL, "cid={$attachmentId}"); + $struct = array( + 'attachment_id' => $attachment->cid, + 'date_created_gmt' => new IXR_Date($this->options->timezone + $attachment->created), + 'parent' => $attachment->parent, + 'link' => $attachment->attachment->url, + 'title' => $attachment->title, + 'caption' => $attachment->slug, + 'description' => $attachment->attachment->description, + 'metadata' => array( + 'file'=>$attachment->attachment->path, + 'size'=>$attachment->attachment->size, + ), + 'thumbnail' => $attachment->attachment->url, + + ); + return $struct; + } + + /**about MetaWeblog API, you can see http://www.xmlrpc.com/metaWeblogApi*/ /** @@ -2159,8 +2289,11 @@ EOF; /** New Wordpress API after 2.9.2 */ 'wp.getProfile' => array($this, 'wpGetProfile'), 'wp.getPostFormats' => array($this, 'wpGetPostFormats'), + 'wp.getMediaLibrary' => array($this, 'wpGetMediaLibrary'), + 'wp.getMediaItem' => array($this, 'wpGetMediaItem'), + 'wp.editPost' => array($this, 'wpEditPost'), - + /** Blogger API */ 'blogger.getUsersBlogs' => array($this, 'bloggerGetUsersBlogs'),