mirror of
https://github.com/typecho/typecho.git
synced 2025-04-19 09:14:35 +02:00
Fix category creation error when using xmlrpc (#1443)
* Fix category creation error when using xmlrpc * Add use Typecho\Request
This commit is contained in:
parent
3119c05e2c
commit
59a5c8d14d
@ -3,6 +3,7 @@
|
||||
namespace Typecho\Widget\Helper;
|
||||
|
||||
use Typecho\Cookie;
|
||||
use Typecho\Request;
|
||||
use Typecho\Validate;
|
||||
use Typecho\Widget\Helper\Form\Element;
|
||||
|
||||
@ -131,10 +132,10 @@ class Form extends Layout
|
||||
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;
|
||||
}
|
||||
@ -204,10 +205,10 @@ class Form extends Layout
|
||||
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;
|
||||
|
@ -463,7 +463,6 @@ class XmlRpc extends Contents implements ActionInterface, Hook
|
||||
*/
|
||||
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']);
|
||||
@ -474,6 +473,11 @@ class XmlRpc extends Contents implements ActionInterface, Hook
|
||||
$categoryWidget = CategoryEdit::alloc(null, $input, function (CategoryEdit $category) {
|
||||
$category->insertCategory();
|
||||
});
|
||||
|
||||
if (!$categoryWidget->have()) {
|
||||
throw new Exception(_t('分类不存在'), 404);
|
||||
}
|
||||
|
||||
return $categoryWidget->mid;
|
||||
}
|
||||
|
||||
@ -1833,7 +1837,7 @@ EOF;
|
||||
'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'],
|
||||
|
Loading…
x
Reference in New Issue
Block a user