控制台应用,yzncms本身基于tp5.1框架,里面的队列用不了,bug,坑
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.

Index.php 9.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. // | cms管理
  13. // +----------------------------------------------------------------------
  14. namespace app\cms\controller;
  15. use app\cms\model\Cms as Cms_Model;
  16. use think\Db;
  17. use think\Exception;
  18. class Index extends Cmsbase
  19. {
  20. protected $noNeedLogin = ['*'];
  21. protected $noNeedRight = [];
  22. protected function initialize()
  23. {
  24. parent::initialize();
  25. $this->Cms_Model = new Cms_Model;
  26. }
  27. // 首页
  28. public function index()
  29. {
  30. $page = $this->request->param('page/d', 1);
  31. $seo = seo();
  32. $this->assign([
  33. 'SEO' => $seo,
  34. 'page' => $page,
  35. ]);
  36. return $this->fetch('/index');
  37. }
  38. // 列表页
  39. public function lists()
  40. {
  41. $cat = $this->request->param('catid/d', 0);
  42. if (empty($cat)) {
  43. $cat = $this->request->param('catdir/s', '');
  44. }
  45. $page = $this->request->param('page/d', 1);
  46. //获取栏目数据
  47. $category = getCategory($cat);
  48. if (empty($category)) {
  49. throw new \think\exception\HttpException(404, '栏目不存在!');
  50. }
  51. $catid = $category['id'];
  52. //模型ID
  53. $modelid = $category['modelid'];
  54. $models = cache('Model');
  55. //栏目扩展配置信息
  56. $setting = $category['setting'];
  57. //类型为列表的栏目
  58. if ($category['type'] == 2) {
  59. //栏目首页模板
  60. $template = $setting['category_template'] ?: 'category';
  61. //栏目列表页模板
  62. $template_list = $setting['list_template'] ?: 'list';
  63. //判断使用模板类型,如果有子栏目使用频道页模板
  64. $template = $category['child'] ? $template : $template_list;
  65. $seo = seo($catid, '', $setting['meta_description'], $setting['meta_keywords']);
  66. //单页
  67. } elseif ($category['type'] == 1) {
  68. $template = $setting['page_template'] ?: 'page';
  69. $ifcache = $this->cmsConfig['site_cache_time'] ?: false;
  70. $info = model('Page')->getPage($catid, $ifcache);
  71. if (empty($info)) {
  72. throw new \think\exception\HttpException(404, '单页不存在!');
  73. }
  74. $info->setInc('hits');
  75. $info = $info->toArray();
  76. //SEO
  77. $keywords = $info['keywords'] ?? $setting['meta_keywords'];
  78. $description = $info['description'] ?? $setting['meta_description'];
  79. $seo = seo($catid, '', $description, $keywords);
  80. $this->assign($info);
  81. }
  82. $tpar = explode(".", $template, 2);
  83. $template = $tpar[0];
  84. unset($tpar);
  85. if ($this->request->isAjax()) {
  86. $this->success('', '', $this->fetch('/' . $template . '_ajax'));
  87. }
  88. //获取顶级栏目ID
  89. $category['arrparentid'] = explode(',', $category['arrparentid']);
  90. $top_parentid = isset($category['arrparentid'][1]) ? $category['arrparentid'][1] : $catid;
  91. unset($category['id']);
  92. $this->assign([
  93. 'category' => $category,
  94. 'top_parentid' => $top_parentid,
  95. 'SEO' => $seo,
  96. 'catid' => $catid,
  97. 'page' => $page,
  98. 'modelid' => $modelid,
  99. ]);
  100. return $this->fetch('/' . $template);
  101. }
  102. // 内容页
  103. public function shows()
  104. {
  105. //ID
  106. $id = $this->request->param('id/d', 0);
  107. $cat = $this->request->param('catid/d', 0);
  108. if (empty($cat)) {
  109. $cat = $this->request->param('catdir/s', '');
  110. }
  111. $page = $this->request->param('page/d', 1);
  112. $page = max(1, $page);
  113. //获取栏目数据
  114. $category = getCategory($cat);
  115. if (empty($category)) {
  116. throw new \think\exception\HttpException(404, '栏目不存在!');
  117. }
  118. $catid = $category['catid'] = $category['id'];
  119. unset($category['id']);
  120. //模型ID
  121. $modelid = $category['modelid'];
  122. $modelInfo = cache('Model')[$modelid];
  123. if (empty($modelInfo)) {
  124. throw new \think\exception\HttpException(404, '模型不存在!');
  125. }
  126. //更新点击量
  127. Db::name($modelInfo['tablename'])->where('id', $id)->setInc('hits');
  128. //内容所有字段
  129. $ifcache = $this->cmsConfig['site_cache_time'] ?: false;
  130. $info = $this->Cms_Model->getContent($modelid, ['catid' => $catid, 'id' => $id], true, '*', '', $ifcache);
  131. if (!$info || ($info['status'] !== 1 && !\app\admin\service\User::instance()->isLogin())) {
  132. throw new \think\exception\HttpException(404, '内容不存在或未审核!');
  133. }
  134. //内容分页
  135. $paginator = isset($info['content']) ? strpos($info['content'], '[page]') : false;
  136. if ($paginator !== false) {
  137. $contents = array_filter(explode('[page]', $info['content']));
  138. $total = count($contents);
  139. $pages = \app\cms\paginator\Page::make([], 1, $page, $total, false, ['path' => $this->request->baseUrl()]);
  140. //判断[page]出现的位置是否在第一位
  141. if ($paginator < 7) {
  142. $info['content'] = $contents[$page];
  143. } else {
  144. $info['content'] = $contents[$page - 1];
  145. }
  146. $this->assign("pages", $pages);
  147. } else {
  148. $this->assign("pages", '');
  149. }
  150. //栏目扩展配置信息
  151. $setting = $category['setting'];
  152. //内容页模板
  153. $template = $setting['show_template'] ?: 'show';
  154. //去除模板文件后缀
  155. $newstempid = explode(".", $template);
  156. $template = $newstempid[0];
  157. unset($newstempid);
  158. //阅读收费
  159. $info['readpoint'] = $info['readpoint'] ?? 0; //金额
  160. $info['paytype'] = $info['paytype'] ?? 1; //1钱 2积分
  161. $is_pay = 1;
  162. $is_part_content_pay = 0; //是否部分内容付费
  163. if (isset($info['content'])) {
  164. $info['content'] = str_replace(['###paidstart###', '###paidend###'], ['<paid>', '</paid>'], $info['content']);
  165. }
  166. if ($info['readpoint'] > 0) {
  167. //检查是否支付过
  168. $is_pay = \app\cms\model\Order::check_payment($info);
  169. if (!$is_pay) {
  170. //部分内容阅读付费
  171. if (isset($info['content'])) {
  172. $pattern = '/<paid>(.*?)<\/paid>/is';
  173. if (preg_match($pattern, $info['content'])) {
  174. //$payurl = url('cms/index/readpoint', ['allow_visitor' => $allow_visitor]);
  175. $info['content'] = preg_replace($pattern, "<div class='allow_visitor'>此处内容需要付费后方可阅读</div>", $info['content']);
  176. $is_part_content_pay = 1;
  177. }
  178. }
  179. } else {
  180. $is_pay = 1;
  181. }
  182. }
  183. //SEO
  184. $keywords = $info['keywords'] ? $info['keywords'] : $setting['meta_keywords'];
  185. $title = $info['title'] ? $info['title'] : $setting['meta_title'];
  186. $description = $info['description'] ? $info['description'] : $setting['meta_description'];
  187. $seo = seo($catid, $title, $description, $keywords);
  188. //获取顶级栏目ID
  189. $arrparentid = explode(',', $category['arrparentid']);
  190. $top_parentid = $arrparentid[1] ?? $catid;
  191. $this->assign($info);
  192. $this->assign([
  193. 'category' => $category,
  194. //'readpoint' => $readpoint,
  195. 'is_part_content_pay' => $is_part_content_pay,
  196. 'is_pay' => $is_pay,
  197. 'top_parentid' => $top_parentid,
  198. 'arrparentid' => $arrparentid,
  199. 'SEO' => $seo,
  200. 'catid' => $catid,
  201. 'page' => $page,
  202. 'modelid' => $modelid,
  203. ]);
  204. return $this->fetch('/' . $template);
  205. }
  206. // tags
  207. public function tags()
  208. {
  209. $page = $page = $this->request->param('page/d', 1);
  210. $tag = $this->request->param('tag', '');
  211. $where = [];
  212. if ($tag && is_numeric($tag)) {
  213. $where['id'] = $tag;
  214. } else {
  215. $where['tag'] = $tag;
  216. }
  217. //如果条件为空,则显示标签首页
  218. if (empty($tag)) {
  219. $data = Db::name('Tags')->order(['listorder' => 'DESC', 'hits' => 'DESC'])->limit(100)->select();
  220. $this->assign("SEO", seo('', '标签'));
  221. $this->assign('list', $data);
  222. return $this->fetch('/tags_list');
  223. }
  224. //根据条件获取tag信息
  225. $info = Db::name('Tags')->where($where)->find();
  226. if (empty($info)) {
  227. $this->error('抱歉,沒有找到您需要的内容!');
  228. }
  229. //访问数+1
  230. Db::name('Tags')->where($where)->setInc("hits");
  231. $this->assign($info);
  232. $this->assign("SEO", seo('', $info['tag'], $info['seo_description'], $info['seo_keyword']));
  233. $this->assign("page", $page);
  234. $this->assign($info);
  235. return $this->fetch('/tags');
  236. }
  237. }