From e15c2966a93ea95d3c2d527ab095372fdebb01c6 Mon Sep 17 00:00:00 2001 From: joyqi Date: Mon, 30 Aug 2021 14:52:52 +0800 Subject: [PATCH] still working on it --- .phpstorm.meta.php | 1 + admin/common.php | 8 +- install.php | 175 +++++++++++++++++- var/Typecho/Common.php | 8 +- var/Typecho/Widget.php | 41 ++++- var/Widget/Action.php | 2 +- var/Widget/Archive.php | 23 ++- var/Widget/Backup.php | 108 ++++++----- var/Widget/Base.php | 6 +- var/Widget/Base/Comments.php | 4 +- var/Widget/Base/Contents.php | 10 +- var/Widget/Comments/Admin.php | 4 +- var/Widget/Comments/Edit.php | 10 +- var/Widget/Contents/Attachment/Edit.php | 2 +- var/Widget/Contents/Page/Edit.php | 16 +- var/Widget/Contents/Post/Admin.php | 1 + var/Widget/Contents/Post/Date.php | 2 +- var/Widget/Contents/Post/Edit.php | 30 +-- var/Widget/Init.php | 8 +- var/Widget/Login.php | 62 ++++--- var/Widget/Logout.php | 22 +-- var/Widget/Menu.php | 124 +++++++------ var/Widget/Metas/Category/Edit.php | 30 +-- var/Widget/Metas/Tag/Edit.php | 22 +-- var/Widget/Notice.php | 6 +- var/Widget/Options.php | 6 +- var/Widget/Plugins/Config.php | 59 +++--- var/Widget/Plugins/Edit.php | 152 +++++++-------- var/Widget/Plugins/{List.php => Rows.php} | 32 ++-- var/Widget/Register.php | 45 +++-- var/Widget/Security.php | 4 +- var/Widget/Service.php | 2 +- var/Widget/Stat.php | 34 ++-- var/Widget/Themes/Config.php | 43 +++-- var/Widget/Themes/Edit.php | 81 ++++---- var/Widget/Themes/Files.php | 85 ++++----- var/Widget/Themes/{List.php => Rows.php} | 36 ++-- var/Widget/Upgrade.php | 62 ++++--- var/Widget/Upload.php | 4 +- var/Widget/User.php | 2 +- var/Widget/Users/Admin.php | 73 ++++---- var/Widget/Users/Edit.php | 118 ++++++------ var/Widget/Users/Profile.php | 214 ++++++++++++---------- 43 files changed, 1024 insertions(+), 753 deletions(-) rename var/Widget/Plugins/{List.php => Rows.php} (82%) rename var/Widget/Themes/{List.php => Rows.php} (72%) diff --git a/.phpstorm.meta.php b/.phpstorm.meta.php index 02b16ddd..6b437ed2 100644 --- a/.phpstorm.meta.php +++ b/.phpstorm.meta.php @@ -10,6 +10,7 @@ namespace PHPSTORM_META { exitPoint(\Typecho\Widget\Response::throwFile()); exitPoint(\Typecho\Widget\Response::throwJson()); exitPoint(\Typecho\Widget\Response::throwXml()); + exitPoint(\Typecho\Widget\Response::goBack()); override(\Widget\Options::__get(0), map([ 'feedUrl' => string, diff --git a/admin/common.php b/admin/common.php index b18173bb..84ed18ae 100644 --- a/admin/common.php +++ b/admin/common.php @@ -12,14 +12,14 @@ if (!defined('__TYPECHO_ROOT_DIR__') && !@include_once __DIR__ . '/../config.inc } /** 初始化组件 */ -\Typecho\Widget::widget('Widget_Init'); +\Widget\Init::alloc(); /** 注册一个初始化插件 */ \Typecho\Plugin::factory('admin/common.php')->begin(); -\Typecho\Widget::widget('Widget_Options')->to($options); -\Typecho\Widget::widget('Widget_User')->to($user); -\Typecho\Widget::widget('Widget_Security')->to($security); +\Widget\Options::alloc()->to($options); +\Widget\User::alloc()->to($user); +\Widget\Security::alloc()->to($security); \Typecho\Widget::widget('Widget_Menu')->to($menu); /** 初始化上下文 */ diff --git a/install.php b/install.php index 8d5d31c5..5edcb270 100644 --- a/install.php +++ b/install.php @@ -77,6 +77,167 @@ function install_is_cli(): bool return \Typecho\Request::getInstance()->isCli(); } +/** + * get default router + * + * @return string[][] + */ +function install_get_default_routers(): array +{ + return [ + 'index' => + [ + 'url' => '/', + 'widget' => '\Widget\Archive', + 'action' => 'render', + ], + 'archive' => + [ + 'url' => '/blog/', + 'widget' => '\Widget\Archive', + 'action' => 'render', + ], + 'do' => + [ + 'url' => '/action/[action:alpha]', + 'widget' => '\Widget\Action', + 'action' => 'action', + ], + 'post' => + [ + 'url' => '/archives/[cid:digital]/', + 'widget' => '\Widget\Archive', + 'action' => 'render', + ], + 'attachment' => + [ + 'url' => '/attachment/[cid:digital]/', + 'widget' => '\Widget\Archive', + 'action' => 'render', + ], + 'category' => + [ + 'url' => '/category/[slug]/', + 'widget' => '\Widget\Archive', + 'action' => 'render', + ], + 'tag' => + [ + 'url' => '/tag/[slug]/', + 'widget' => '\Widget\Archive', + 'action' => 'render', + ], + 'author' => + [ + 'url' => '/author/[uid:digital]/', + 'widget' => '\Widget\Archive', + 'action' => 'render', + ], + 'search' => + [ + 'url' => '/search/[keywords]/', + 'widget' => '\Widget\Archive', + 'action' => 'render', + ], + 'index_page' => + [ + 'url' => '/page/[page:digital]/', + 'widget' => '\Widget\Archive', + 'action' => 'render', + ], + 'archive_page' => + [ + 'url' => '/blog/page/[page:digital]/', + 'widget' => '\Widget\Archive', + 'action' => 'render', + ], + 'category_page' => + [ + 'url' => '/category/[slug]/[page:digital]/', + 'widget' => '\Widget\Archive', + 'action' => 'render', + ], + 'tag_page' => + [ + 'url' => '/tag/[slug]/[page:digital]/', + 'widget' => '\Widget\Archive', + 'action' => 'render', + ], + 'author_page' => + [ + 'url' => '/author/[uid:digital]/[page:digital]/', + 'widget' => '\Widget\Archive', + 'action' => 'render', + ], + 'search_page' => + [ + 'url' => '/search/[keywords]/[page:digital]/', + 'widget' => '\Widget\Archive', + 'action' => 'render', + ], + 'archive_year' => + [ + 'url' => '/[year:digital:4]/', + 'widget' => '\Widget\Archive', + 'action' => 'render', + ], + 'archive_month' => + [ + 'url' => '/[year:digital:4]/[month:digital:2]/', + 'widget' => '\Widget\Archive', + 'action' => 'render', + ], + 'archive_day' => + [ + 'url' => '/[year:digital:4]/[month:digital:2]/[day:digital:2]/', + 'widget' => '\Widget\Archive', + 'action' => 'render', + ], + 'archive_year_page' => + [ + 'url' => '/[year:digital:4]/page/[page:digital]/', + 'widget' => '\Widget\Archive', + 'action' => 'render', + ], + 'archive_month_page' => + [ + 'url' => '/[year:digital:4]/[month:digital:2]/page/[page:digital]/', + 'widget' => '\Widget\Archive', + 'action' => 'render', + ], + 'archive_day_page' => + [ + 'url' => '/[year:digital:4]/[month:digital:2]/[day:digital:2]/page/[page:digital]/', + 'widget' => '\Widget\Archive', + 'action' => 'render', + ], + 'comment_page' => + [ + 'url' => '[permalink:string]/comment-page-[commentPage:digital]', + 'widget' => '\Widget\Archive', + 'action' => 'render', + ], + 'feed' => + [ + 'url' => '/feed[feed:string:0]', + 'widget' => '\Widget\Archive', + 'action' => 'feed', + ], + 'feedback' => + [ + 'url' => '[permalink:string]/[type:alpha]', + 'widget' => '\Widget\Feedback', + 'action' => 'action', + ], + 'page' => + [ + 'url' => '/[slug].html', + 'widget' => '\Widget\Archive', + 'action' => 'render', + ], + ]; +} + /** * list all default options * @@ -142,7 +303,7 @@ function install_get_default_options(): array 'commentsAvatar' => 1, 'commentsAvatarRating' => 'G', 'commentsAntiSpam' => 1, - 'routingTable' => 'a:25:{s:5:"index";a:3:{s:3:"url";s:1:"/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:7:"archive";a:3:{s:3:"url";s:6:"/blog/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:2:"do";a:3:{s:3:"url";s:22:"/action/[action:alpha]";s:6:"widget";s:9:"Widget_Do";s:6:"action";s:6:"action";}s:4:"post";a:3:{s:3:"url";s:24:"/archives/[cid:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:10:"attachment";a:3:{s:3:"url";s:26:"/attachment/[cid:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:8:"category";a:3:{s:3:"url";s:17:"/category/[slug]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:3:"tag";a:3:{s:3:"url";s:12:"/tag/[slug]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:6:"author";a:3:{s:3:"url";s:22:"/author/[uid:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:6:"search";a:3:{s:3:"url";s:19:"/search/[keywords]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:10:"index_page";a:3:{s:3:"url";s:21:"/page/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:12:"archive_page";a:3:{s:3:"url";s:26:"/blog/page/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:13:"category_page";a:3:{s:3:"url";s:32:"/category/[slug]/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:8:"tag_page";a:3:{s:3:"url";s:27:"/tag/[slug]/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:11:"author_page";a:3:{s:3:"url";s:37:"/author/[uid:digital]/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:11:"search_page";a:3:{s:3:"url";s:34:"/search/[keywords]/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:12:"archive_year";a:3:{s:3:"url";s:18:"/[year:digital:4]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:13:"archive_month";a:3:{s:3:"url";s:36:"/[year:digital:4]/[month:digital:2]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:11:"archive_day";a:3:{s:3:"url";s:52:"/[year:digital:4]/[month:digital:2]/[day:digital:2]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:17:"archive_year_page";a:3:{s:3:"url";s:38:"/[year:digital:4]/page/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:18:"archive_month_page";a:3:{s:3:"url";s:56:"/[year:digital:4]/[month:digital:2]/page/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:16:"archive_day_page";a:3:{s:3:"url";s:72:"/[year:digital:4]/[month:digital:2]/[day:digital:2]/page/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:12:"comment_page";a:3:{s:3:"url";s:53:"[permalink:string]/comment-page-[commentPage:digital]";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:4:"feed";a:3:{s:3:"url";s:20:"/feed[feed:string:0]";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:4:"feed";}s:8:"feedback";a:3:{s:3:"url";s:31:"[permalink:string]/[type:alpha]";s:6:"widget";s:15:"Widget_Feedback";s:6:"action";s:6:"action";}s:4:"page";a:3:{s:3:"url";s:12:"/[slug].html";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}}', + 'routingTable' => serialize(install_get_default_routers()), 'actionTable' => 'a:0:{}', 'panelTable' => 'a:0:{}', 'attachmentTypes' => '@image@', @@ -405,7 +566,7 @@ function install_redirect(string $url) */ function install_js_support() { - $options = \Typecho\Widget::widget(\Widget\Options::class); + $options = \Widget\Options::alloc(); ?>