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(); ?>