暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Yzncms [ 御宅男工作室 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2018 http://yzncms.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 御宅男 <530765310@qq.com>
  10. // +----------------------------------------------------------------------
  11. // +----------------------------------------------------------------------
  12. // | 前台控制模块
  13. // +----------------------------------------------------------------------
  14. namespace app\common\controller;
  15. use think\facade\Config;
  16. use think\facade\Hook;
  17. class Homebase extends Base
  18. {
  19. protected $modulename = null;
  20. protected $controllername = null;
  21. protected $actionname = null;
  22. //初始化
  23. protected function initialize()
  24. {
  25. //移除HTML标签
  26. $this->request->filter('trim,strip_tags,htmlspecialchars');
  27. parent::initialize();
  28. $this->modulename = $this->request->module();
  29. $this->controllername = parse_name($this->request->controller());
  30. $this->actionname = strtolower($this->request->action());
  31. $site = Config::get("site.");
  32. $config = [
  33. 'modulename' => $this->modulename,
  34. 'controllername' => $this->controllername,
  35. 'actionname' => $this->actionname,
  36. ];
  37. //监听插件传入的变量
  38. $site = array_merge($site, $config, ...Hook::listen("config_init"));
  39. $this->assign('site', $site);
  40. $this->view->filter(function ($content) {
  41. return Hook::listen("index_view_filter", $content, true) ?: $content;
  42. });
  43. }
  44. /**
  45. * 渲染配置信息
  46. * @param mixed $name 键名或数组
  47. * @param mixed $value 值
  48. */
  49. protected function assignconfig($name, $value = '')
  50. {
  51. $this->view->site = array_merge($this->view->site ? $this->view->site : [], is_array($name) ? $name : [$name => $value]);
  52. }
  53. protected function fetch($template = '', $vars = [], $config = [], $renderContent = false)
  54. {
  55. $Theme = empty(Config::get('site.theme')) ? 'default' : Config::get('site.theme');
  56. $viewPath = TEMPLATE_PATH . $Theme . DS . $this->modulename . DS;
  57. $tempPath = TEMPLATE_PATH . $Theme . DS . $this->modulename . DS . ($this->modulename === 'index' ? $this->controllername : '') . DS;
  58. $templateFile = $tempPath . trim($template, '/') . '.' . Config::get('template.view_suffix');
  59. if ('default' !== $Theme && !is_file($templateFile)) {
  60. $viewPath = TEMPLATE_PATH . 'default' . DS . $this->modulename . DS;
  61. }
  62. $this->view->config('view_path', $viewPath);
  63. return $this->view->fetch($template, $vars, $config, $renderContent);
  64. }
  65. }