Base.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace addons\cms\controller;
  3. use addons\cms\library\IntCode;
  4. use addons\cms\library\Service;
  5. use addons\cms\model\SpiderLog;
  6. use app\admin\model\cms\Channel;
  7. use think\Config;
  8. use think\Request;
  9. /**
  10. * CMS控制器基类
  11. */
  12. class Base extends \think\addons\Controller
  13. {
  14. // 初始化
  15. public function __construct(Request $request = null)
  16. {
  17. parent::__construct($request);
  18. $config = get_addon_config('cms');
  19. // 设定主题模板目录
  20. $this->view->engine->config('view_path', $this->view->engine->config('view_path') . $config['theme'] . DS);
  21. // 加载自定义标签库
  22. //$this->view->engine->config('taglib_pre_load', 'addons\cms\taglib\Cms');
  23. // 默认渲染栏目为空
  24. $this->view->assign('__CHANNEL__', null);
  25. $this->view->assign('isWechat', strpos($this->request->server('HTTP_USER_AGENT'), 'MicroMessenger') !== false);
  26. // 定义CMS首页的URL
  27. Config::set('cms.indexurl', addon_url('cms/index/index', [], false));
  28. // 定义分页类
  29. Config::set('paginate.type', '\\addons\\cms\\library\\Bootstrap');
  30. $this->assign("channels", recursion(collection(Channel::where("id", "NOT IN", [22, 44])->order("weigh desc,id desc")->select())->toArray()));
  31. $this->assign("baike_channels", recursion(collection(Channel::where("id", "NOT IN", [2, 22, 44])->order("weigh desc,id desc")->select())->toArray()));
  32. $this->assign("soft_channels", recursion(collection(Channel::where("id", "NOT IN", [1, 22, 44])->order("weigh desc,id desc")->select())->toArray()));
  33. $this->assign("is_ruanjiankaifagongsi", $request->url() === "/ruanjiankaifagongsi.html" || strstr($request->url(), 'ruanjiankaifagongsi'));
  34. //判断站点状态
  35. if (isset($config['openedsite']) && !in_array('pc', explode(',', $config['openedsite']))) {
  36. if ($this->controller != 'order' && $this->action != 'epay') {
  37. $this->error('站点已关闭');
  38. }
  39. }
  40. }
  41. public function _initialize()
  42. {
  43. parent::_initialize();
  44. // 如果请求参数action的值为一个方法名,则直接调用
  45. $action = $this->request->post("action");
  46. if ($action && $this->request->isPost()) {
  47. return $this->$action();
  48. }
  49. }
  50. /**
  51. * 是否加密ID处理
  52. */
  53. protected function hashids($name = 'id')
  54. {
  55. $config = get_addon_config('cms');
  56. $getValue = $this->request->get($name);
  57. $postValue = $this->request->post($name);
  58. if ($config['archiveshashids'] && ($getValue || $postValue)) {
  59. if ($getValue) {
  60. $getValue = (int)IntCode::decode($getValue);
  61. $this->request->get([$name => $getValue]);
  62. }
  63. if ($postValue) {
  64. $postValue = (int)IntCode::decode($postValue);
  65. $this->request->post([$name => $postValue]);
  66. }
  67. $this->request->param('');
  68. }
  69. }
  70. }