Action.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace Widget;
  3. use Typecho\Widget;
  4. if (!defined('__TYPECHO_ROOT_DIR__')) {
  5. exit;
  6. }
  7. /**
  8. * 执行模块
  9. *
  10. * @package Widget
  11. */
  12. class Action extends Widget
  13. {
  14. /**
  15. * 路由映射
  16. *
  17. * @access private
  18. * @var array
  19. */
  20. private $map = [
  21. 'ajax' => '\Widget\Ajax',
  22. 'login' => '\Widget\Login',
  23. 'logout' => '\Widget\Logout',
  24. 'register' => '\Widget\Register',
  25. 'upgrade' => '\Widget\Upgrade',
  26. 'upload' => '\Widget\Upload',
  27. 'service' => '\Widget\Service',
  28. 'xmlrpc' => '\Widget\XmlRpc',
  29. 'comments-edit' => '\Widget\Comments\Edit',
  30. 'contents-page-edit' => '\Widget\Contents\Page\Edit',
  31. 'contents-post-edit' => '\Widget\Contents\Post\Edit',
  32. 'contents-attachment-edit' => '\Widget\Contents\Attachment\Edit',
  33. 'metas-category-edit' => '\Widget\Metas\Category\Edit',
  34. 'metas-tag-edit' => '\Widget\Metas\Tag\Edit',
  35. 'options-discussion' => '\Widget\Options\Discussion',
  36. 'options-general' => '\Widget\Options\General',
  37. 'options-permalink' => '\Widget\Options\Permalink',
  38. 'options-reading' => '\Widget\Options\Reading',
  39. 'plugins-edit' => '\Widget\Plugins\Edit',
  40. 'themes-edit' => '\Widget\Themes\Edit',
  41. 'users-edit' => '\Widget\Users\Edit',
  42. 'users-profile' => '\Widget\Users\Profile',
  43. 'backup' => '\Widget\Backup'
  44. ];
  45. /**
  46. * 入口函数,初始化路由器
  47. *
  48. * @throws Widget\Exception
  49. */
  50. public function execute()
  51. {
  52. /** 验证路由地址 **/
  53. $action = $this->request->action;
  54. /** 判断是否为plugin */
  55. $actionTable = array_merge($this->map, unserialize(Options::alloc()->actionTable));
  56. if (isset($actionTable[$action])) {
  57. $widgetName = $actionTable[$action];
  58. }
  59. if (isset($widgetName) && class_exists($widgetName)) {
  60. $widget = self::widget($widgetName);
  61. if ($widget instanceof ActionInterface) {
  62. $widget->action();
  63. return;
  64. }
  65. }
  66. throw new Widget\Exception(_t('请求的地址不存在'), 404);
  67. }
  68. }