mirror of
https://github.com/typecho/typecho.git
synced 2025-01-18 04:58:20 +01:00
Merge branch 'master' of https://github.com/typecho/typecho
This commit is contained in:
commit
ec58adb202
@ -405,7 +405,7 @@ class Widget_Abstract_Contents extends Widget_Abstract
|
||||
*/
|
||||
public function deleteFields($cid)
|
||||
{
|
||||
return $this->db->query($this->db->delete('table.contents')
|
||||
return $this->db->query($this->db->delete('table.fields')
|
||||
->where('cid = ?', $cid));
|
||||
}
|
||||
|
||||
|
@ -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',
|
||||
|
@ -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)) {
|
||||
|
@ -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' => false
|
||||
),
|
||||
|
||||
// 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,
|
||||
@ -363,31 +384,31 @@ class Widget_XmlRpc extends Widget_Abstract_Contents implements Widget_Interface
|
||||
/** 对文章内容做截取处理,以获得description和text_more*/
|
||||
list($excerpt, $more) = $this->getPostExtended($pages);
|
||||
$pageStructs[] = array(
|
||||
'dateCreated' => new IXR_Date($this->options->timezone + $pages->created),
|
||||
'userid' => $pages->authorId,
|
||||
'page_id' => $pages->cid,
|
||||
'dateCreated' => new IXR_Date($this->options->timezone + $pages->created),
|
||||
'userid' => $pages->authorId,
|
||||
'page_id' => intval($pages->cid),
|
||||
/** todo:此处有疑问 */
|
||||
'page_status' => $this->typechoToWordpressStatus($pages->status, 'page'),
|
||||
'description' => $excerpt,
|
||||
'title' => $pages->title,
|
||||
'link' => $pages->permalink,
|
||||
'permalink' => $pages->permalink,
|
||||
'categories' => $pages->categories,
|
||||
'excerpt' => $pages->description,
|
||||
'text_more' => $more,
|
||||
'mt_allow_comments' => intval($pages->allowComment),
|
||||
'mt_allow_pings' => intval($pages->allowPing),
|
||||
'wp_slug' => $pages->slug,
|
||||
'wp_password' => $pages->password,
|
||||
'wp_author' => $pages->author->name,
|
||||
'wp_page_parent_id' => '0',
|
||||
'wp_page_parent_title' => '',
|
||||
'wp_page_order' => $pages->order, //meta是描述字段, 在page时表示顺序
|
||||
'wp_author_id' => $pages->authorId,
|
||||
'page_status' => $this->typechoToWordpressStatus($pages->status, 'page'),
|
||||
'description' => $excerpt,
|
||||
'title' => $pages->title,
|
||||
'link' => $pages->permalink,
|
||||
'permaLink' => $pages->permalink,
|
||||
'categories' => $pages->categories,
|
||||
'excerpt' => $pages->description,
|
||||
'text_more' => $more,
|
||||
'mt_allow_comments' => intval($pages->allowComment),
|
||||
'mt_allow_pings' => intval($pages->allowPing),
|
||||
'wp_slug' => $pages->slug,
|
||||
'wp_password' => $pages->password,
|
||||
'wp_author' => $pages->author->name,
|
||||
'wp_page_parent_id' => 0,
|
||||
'wp_page_parent_title' => '',
|
||||
'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),
|
||||
'custom_fields' => array(),
|
||||
'wp_page_template' => $pages->template
|
||||
'date_created_gmt' => new IXR_Date($pages->created),
|
||||
'custom_fields' => array(),
|
||||
'wp_page_template' => $pages->template
|
||||
);
|
||||
}
|
||||
|
||||
@ -460,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获得的详细
|
||||
*
|
||||
@ -548,13 +601,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 +660,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 +668,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 +791,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 +858,8 @@ class Widget_XmlRpc extends Widget_Abstract_Contents implements Widget_Interface
|
||||
'publish' => _t('已发布')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取评论状态列表
|
||||
@ -998,8 +1107,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;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1070,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)
|
||||
{
|
||||
@ -1119,14 +1234,117 @@ 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('无法添加评论'));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取媒体文件
|
||||
*
|
||||
* @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*/
|
||||
/**
|
||||
* MetaWeblog API
|
||||
@ -1306,7 +1524,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,
|
||||
@ -1357,28 +1575,33 @@ class Widget_XmlRpc extends Widget_Abstract_Contents implements Widget_Interface
|
||||
$tags = Typecho_Common::arrayFlatten($posts->tags, 'name');
|
||||
|
||||
$postStructs[] = array(
|
||||
'dateCreated' => new IXR_Date($this->options->timezone + $posts->created),
|
||||
'userid' => $posts->authorId,
|
||||
'postid' => $posts->cid,
|
||||
'description' => $excerpt,
|
||||
'title' => $posts->title,
|
||||
'link' => $posts->permalink,
|
||||
'permalink' => $posts->permalink,
|
||||
'categories' => $categories,
|
||||
'mt_excerpt' => $posts->description,
|
||||
'mt_text_more' => $more,
|
||||
'mt_allow_comments' => intval($posts->allowComment),
|
||||
'mt_allow_pings' => intval($posts->allowPing),
|
||||
'mt_keywords' => implode(', ', $tags),
|
||||
'wp_slug' => $posts->slug,
|
||||
'wp_password' => $posts->password,
|
||||
'wp_author' => $posts->author->name,
|
||||
'wp_author_id' => $posts->authorId,
|
||||
'dateCreated' => new IXR_Date($this->options->timezone + $posts->created),
|
||||
'userid' => $posts->authorId,
|
||||
'postid' => $posts->cid,
|
||||
'description' => $excerpt,
|
||||
'title' => $posts->title,
|
||||
'link' => $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),
|
||||
'wp_slug' => $posts->slug,
|
||||
'wp_password' => $posts->password,
|
||||
'wp_author' => $posts->author->name,
|
||||
'wp_author_id' => $posts->authorId,
|
||||
'wp_author_display_name' => $posts->author->screenName,
|
||||
'date_created_gmt' => new IXR_Date($posts->created),
|
||||
'post_status' => $this->typechoToWordpressStatus($posts->status, 'post'),
|
||||
'custom_fields' => array(),
|
||||
'sticky' => 0
|
||||
'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 +2176,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 +2192,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
|
||||
@ -2018,6 +2251,9 @@ EOF;
|
||||
</manifest>
|
||||
EOF;
|
||||
} else {
|
||||
|
||||
|
||||
|
||||
/** 直接把初始化放到这里 */
|
||||
new IXR_Server(array(
|
||||
/** WordPress API */
|
||||
@ -2049,6 +2285,14 @@ 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'),
|
||||
'wp.getMediaLibrary' => array($this, 'wpGetMediaLibrary'),
|
||||
'wp.getMediaItem' => array($this, 'wpGetMediaItem'),
|
||||
'wp.editPost' => array($this, 'wpEditPost'),
|
||||
|
||||
|
||||
|
||||
/** Blogger API */
|
||||
@ -2086,7 +2330,7 @@ EOF;
|
||||
'pingback.extensions.getPingbacks' => array($this,'pingbackExtensionsGetPingbacks'),
|
||||
|
||||
/** hook after */
|
||||
'hook.afterCall' => array($this, 'hookAfterCall'),
|
||||
'hook.afterCall' => array($this, 'hookAfterCall'),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user