Skip to content

Commit

Permalink
Fix category creation error when using xmlrpc (typecho#1443)
Browse files Browse the repository at this point in the history
* Fix category creation error when using xmlrpc

* Add use Typecho\Request
  • Loading branch information
sy-records authored May 23, 2022
1 parent 3119c05 commit 59a5c8d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
9 changes: 5 additions & 4 deletions var/Typecho/Widget/Helper/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Typecho\Widget\Helper;

use Typecho\Cookie;
use Typecho\Request;
use Typecho\Validate;
use Typecho\Widget\Helper\Form\Element;

Expand Down Expand Up @@ -131,10 +132,10 @@ public function getInput(string $name)
public function getAllRequest(): array
{
$result = [];
$source = (self::POST_METHOD == $this->getAttribute('method')) ? $_POST : $_GET;
$request = Request::getInstance();

foreach ($this->inputs as $name => $input) {
$result[$name] = $source[$name] ?? null;
$result[$name] = $request->get($name, null);
}
return $result;
}
Expand Down Expand Up @@ -204,10 +205,10 @@ public function validate(): array
public function getParams(array $params): array
{
$result = [];
$source = (self::POST_METHOD == $this->getAttribute('method')) ? $_POST : $_GET;
$request = Request::getInstance();

foreach ($params as $param) {
$result[$param] = $source[$param] ?? null;
$result[$param] = $request->get($param, null);
}

return $result;
Expand Down
8 changes: 6 additions & 2 deletions var/Widget/XmlRpc.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,6 @@ public function mwNewPost(int $blogId, string $userName, string $password, array
*/
public function wpNewCategory(int $blogId, string $userName, string $password, array $category): int
{

/** 开始接受数据 */
$input['name'] = $category['name'];
$input['slug'] = Common::slugName(empty($category['slug']) ? $category['name'] : $category['slug']);
Expand All @@ -474,6 +473,11 @@ public function wpNewCategory(int $blogId, string $userName, string $password, a
$categoryWidget = CategoryEdit::alloc(null, $input, function (CategoryEdit $category) {
$category->insertCategory();
});

if (!$categoryWidget->have()) {
throw new Exception(_t('分类不存在'), 404);
}

return $categoryWidget->mid;
}

Expand Down Expand Up @@ -1833,7 +1837,7 @@ public function action()
'wp.suggestCategories' => [$this, 'wpSuggestCategories'],
'wp.uploadFile' => [$this, 'mwNewMediaObject'],

/** New Wordpress API since 2.9.2 */
/** New WordPress API since 2.9.2 */
'wp.getUsersBlogs' => [$this, 'wpGetUsersBlogs'],
'wp.getTags' => [$this, 'wpGetTags'],
'wp.deleteCategory' => [$this, 'wpDeleteCategory'],
Expand Down

0 comments on commit 59a5c8d

Please sign in to comment.