Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/share dev #1051

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 47 additions & 1 deletion var/Widget/XmlRpc.php
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,10 @@ public function wpNewCategory($blogId, $userName, $password, $category)
try {
/** 插入 */
$categoryWidget = $this->singletonWidget('Widget_Metas_Category_Edit', NULL, $input, false);

/** 如果是已经实例化过了,则会直接取到之前实例化的对象,$request参数是旧的数据。比如在newPost里调用此函数创建多个分类时有问题 */
$categoryWidget->request->setParams($input);

$categoryWidget->action();
return $categoryWidget->mid;
} catch (Typecho_Widget_Exception $e) {
Expand Down Expand Up @@ -1404,6 +1408,14 @@ public function mwNewPost($blogId, $userName, $password, $content, $publish)
$input['template'] = $content['wp_page_template'];
}

/** 添加自定义字段 */
foreach (['fieldNames', 'fieldTypes', 'fieldValues'] as $fieldKey) {
$fieldValue = array_key_exists($fieldKey, $content) ? $content[$fieldKey] : NULL;
if (!empty($fieldValue)) {
$input[$fieldKey] = $fieldValue;
}
}

if (isset($content['dateCreated'])) {
/** 解决客户端与服务器端时间偏移 */
$input['created'] = $content['dateCreated']->getTimestamp() - $this->options->timezone + $this->options->serverTimezone;
Expand All @@ -1414,7 +1426,9 @@ public function mwNewPost($blogId, $userName, $password, $content, $publish)
if (!$this->db->fetchRow($this->db->select('mid')
->from('table.metas')->where('type = ? AND name = ?', 'category', $category))) {
$result = $this->wpNewCategory($blogId, $userName, $password, array('name' => $category));
if (true !== $result) {
// if (true !== $result) {
/** 创建分类异常 */
if ($result instanceof IXR_Error) {
return $result;
}
}
Expand Down Expand Up @@ -1674,6 +1688,8 @@ public function mwNewMediaObject($blogId, $userName, $password, $data)
return IXR_Error(500, _t('上传失败'));
} else {

$result = $this->pluginHandle()->beforeUpload($result);

$insertId = $this->insert(array(
'title' => $result['name'],
'slug' => $result['name'],
Expand Down Expand Up @@ -2195,6 +2211,33 @@ public function hookAfterCall($methodName)
}
}


/**
* 根据分享id查找postId
*
* @param int $blogId
* @param string $userName
* @param string $password
* @access public
* @return void
*/
public function getPostIdByShareId($blogId, $userName, $password, $shareId)
{
if (!$this->checkAccess($userName, $password)) {
return ($this->error);
}

if (empty($shareId)) {
return new IXR_Error(1001, _t('无效的shareId'));
}

$db = Typecho_Db::get();
$query = $db->select()->from('table.fields')->where('str_value = ?', $shareId);
$result = $db->fetchRow($query);

return count($result) ? $result['cid'] : NULL;
}

/**
* 入口执行方法
*
Expand Down Expand Up @@ -2338,6 +2381,9 @@ public function action()

/** hook after */
'hook.afterCall' => array($this, 'hookAfterCall'),

/** blog share */
'share.getPostIdByShareId' => array($this, 'getPostIdByShareId'),
);

if (1 == $this->options->allowXmlRpc) {
Expand Down