++MainController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2013-present http://www.thinkcmf.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 小夏 < 449134904@qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\controller;
  12. use cmf\controller\AdminBaseController;
  13. use app\admin\model\Menu;
  14. class MainController extends AdminBaseController
  15. {
  16. /**
  17. * 后台欢迎页
  18. */
  19. public function index()
  20. {
  21. $dashboardWidgets = [];
  22. $widgets = cmf_get_option('admin_dashboard_widgets');
  23. $defaultDashboardWidgets = [
  24. '_SystemCmfHub' => ['name' => 'CmfHub', 'is_system' => 1],
  25. '_SystemCmfDocuments' => ['name' => 'CmfDocuments', 'is_system' => 1],
  26. '_SystemMainContributors' => ['name' => 'MainContributors', 'is_system' => 1],
  27. '_SystemContributors' => ['name' => 'Contributors', 'is_system' => 1],
  28. '_SystemCustom1' => ['name' => 'Custom1', 'is_system' => 1],
  29. '_SystemCustom2' => ['name' => 'Custom2', 'is_system' => 1],
  30. '_SystemCustom3' => ['name' => 'Custom3', 'is_system' => 1],
  31. '_SystemCustom4' => ['name' => 'Custom4', 'is_system' => 1],
  32. '_SystemCustom5' => ['name' => 'Custom5', 'is_system' => 1],
  33. ];
  34. if (empty($widgets)) {
  35. $dashboardWidgets = $defaultDashboardWidgets;
  36. } else {
  37. foreach ($widgets as $widget) {
  38. if ($widget['is_system']) {
  39. $dashboardWidgets['_System' . $widget['name']] = ['name' => $widget['name'], 'is_system' => 1];
  40. } else {
  41. $dashboardWidgets[$widget['name']] = ['name' => $widget['name'], 'is_system' => 0];
  42. }
  43. }
  44. foreach ($defaultDashboardWidgets as $widgetName => $widget) {
  45. $dashboardWidgets[$widgetName] = $widget;
  46. }
  47. }
  48. $dashboardWidgetPlugins = [];
  49. $hookResults = hook('admin_dashboard');
  50. if (!empty($hookResults)) {
  51. foreach ($hookResults as $hookResult) {
  52. if (isset($hookResult['width']) && isset($hookResult['view']) && isset($hookResult['plugin'])) { //验证插件返回合法性
  53. $dashboardWidgetPlugins[$hookResult['plugin']] = $hookResult;
  54. if (!isset($dashboardWidgets[$hookResult['plugin']])) {
  55. $dashboardWidgets[$hookResult['plugin']] = ['name' => $hookResult['plugin'], 'is_system' => 0];
  56. }
  57. }
  58. }
  59. }
  60. $smtpSetting = cmf_get_option('smtp_setting');
  61. $this->assign('dashboard_widgets', $dashboardWidgets);
  62. $this->assign('dashboard_widget_plugins', $dashboardWidgetPlugins);
  63. $this->assign('has_smtp_setting', empty($smtpSetting) ? false : true);
  64. return $this->fetch();
  65. }
  66. public function dashboardWidget()
  67. {
  68. $dashboardWidgets = [];
  69. $widgets = $this->request->param('widgets/a');
  70. if (!empty($widgets)) {
  71. foreach ($widgets as $widget) {
  72. if ($widget['is_system']) {
  73. array_push($dashboardWidgets, ['name' => $widget['name'], 'is_system' => 1]);
  74. } else {
  75. array_push($dashboardWidgets, ['name' => $widget['name'], 'is_system' => 0]);
  76. }
  77. }
  78. }
  79. cmf_set_option('admin_dashboard_widgets', $dashboardWidgets, true);
  80. $this->success('更新成功!');
  81. }
  82. }