心理咨询网
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

DeleCacheController.php 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <?php
  2. /**
  3. * @author xsh
  4. * @email hnxsh@foxmail.com
  5. * @date 2021年10月31日
  6. *
  7. */
  8. namespace app\admin\controller\content;
  9. use core\basic\Controller;
  10. use app\home\controller\GetPageController;
  11. use core\basic\Config;
  12. class DeleCacheController extends GetPageController
  13. {
  14. public function index($type = null, $data = null)
  15. {
  16. if ($type || ! ! $type = get('type', 'int')) {
  17. // 设置基础信息
  18. $this->setinfo();
  19. // 执行更新过程
  20. switch ($type) {
  21. case '1':
  22. $this->deleIndex();
  23. $this->deleSort("0");
  24. json(1, '更新更新首页和栏目成功');
  25. break;
  26. case '2':
  27. $this->deleSortAll("0");
  28. json(1, '更新全部栏目分页成功');
  29. break;
  30. case '3':
  31. $this->deleContont($data);
  32. json(1, '更新内容成功');
  33. break;
  34. default:
  35. json(0, '传递参数错误');
  36. }
  37. } else {
  38. $sort_model = model('admin.content.ContentSort');
  39. $sort_tree = $sort_model->getSelect();
  40. $this->assign('sort_select', $this->makeSortSelect($sort_tree));
  41. $this->assign('sort_select2', $this->makeSortSelect($sort_tree, true));
  42. $this->display('content/delecache.html');
  43. }
  44. }
  45. // 删除首页缓存
  46. private function deleIndex()
  47. {
  48. $path = '/';
  49. $lg = cookie('lg');
  50. $wap = '';
  51. $cacheFile = RUN_PATH . '/cache/' . md5(get_http_url() . $path . $lg . $wap) . '.html';
  52. unlink($cacheFile);
  53. if (Config::get('open_wap')){
  54. $wap = 'wap';
  55. $cacheFilewap = RUN_PATH . '/cache/' . md5(get_http_url() . $path . $lg . $wap) . '.html';
  56. unlink($cacheFilewap);
  57. }
  58. }
  59. // 删除栏目首页缓存
  60. private function deleSort($scode = null)
  61. {
  62. $lg = cookie('lg');
  63. $wap = '';
  64. $scode = $scode ?: get('scode', 'var');
  65. if (! $scode) {
  66. $scodes = $this->model->getScodes('1,2');
  67. } else {
  68. $scodes = $this->model->getSubScodes($scode);
  69. }
  70. $err = '';
  71. foreach ($scodes as $value) {
  72. $sort = $this->model->getSort($value);
  73. if ($sort) {
  74. if ($sort->type == 1) {
  75. $link = $this->parser->parserLink($sort->type, $sort->urlname, 'list', $sort->scode, $sort->filename, '', '');
  76. $cacheFile = RUN_PATH . '/cache/' . md5(get_http_url() . $link . $lg . $wap) . '.html';
  77. unlink($cacheFile);
  78. if (Config::get('open_wap')){
  79. $wap = 'wap';
  80. $cacheFilewap = RUN_PATH . '/cache/' . md5(get_http_url() . $link . $lg . $wap) . '.html';
  81. unlink($cacheFilewap);
  82. }
  83. } else {
  84. $pagelink = $this->parser->parserLink($sort->type, $sort->urlname, 'list', $sort->scode, $sort->filename, '', '');
  85. $page = 10;
  86. for ($i = 1; $i <= $page; $i ++) {
  87. if ($i > 1) {
  88. $path = rtrim($pagelink, '/') . '_' . $i . '/';
  89. } else {
  90. $path = $pagelink;
  91. }
  92. $cacheFile = RUN_PATH . '/cache/' . md5(get_http_url() . $path . $lg . $wap) . '.html';
  93. if (Config::get('open_wap')){
  94. $wap = 'wap';
  95. $cacheFilewap = RUN_PATH . '/cache/' . md5(get_http_url() . $path . $lg . $wap) . '.html';
  96. unlink($cacheFilewap);
  97. }
  98. unlink($cacheFile);
  99. }
  100. }
  101. }
  102. }
  103. }
  104. // 删除全部栏目缓存
  105. private function deleSortAll($scode = null)
  106. {
  107. $lg = cookie('lg');
  108. $wap = '';
  109. $scode = $scode ?: get('scode', 'var');
  110. if (! $scode) {
  111. $scodes = $this->model->getScodes('1,2');
  112. } else {
  113. $scodes = $this->model->getSubScodes($scode);
  114. }
  115. $err = '';
  116. foreach ($scodes as $value) {
  117. $sort = $this->model->getSort($value);
  118. if ($sort) {
  119. if ($sort->type == 1) {
  120. $link = $this->parser->parserLink($sort->type, $sort->urlname, 'list', $sort->scode, $sort->filename, '', '');
  121. $cacheFile = RUN_PATH . '/cache/' . md5(get_http_url() . $link . $lg . $wap) . '.html';
  122. unlink($cacheFile);
  123. if (Config::get('open_wap')){
  124. $wap = 'wap';
  125. $cacheFilewap = RUN_PATH . '/cache/' . md5(get_http_url() . $link . $lg . $wap) . '.html';
  126. unlink($cacheFilewap);
  127. }
  128. } else {
  129. $pagelink = $this->parser->parserLink($sort->type, $sort->urlname, 'list', $sort->scode, $sort->filename, '', '');
  130. $page = 5000;
  131. $jishu = 1;
  132. for ($i = 2; $i <= $page; $i ++) {
  133. if ($i > 1) {
  134. $path = rtrim($pagelink, '/') . '_' . $i . '/';
  135. } else {
  136. $path = $pagelink;
  137. }
  138. $cacheFile = RUN_PATH . '/cache/' . md5(get_http_url() . $path . $lg . $wap) . '.html';
  139. if(!file_exists($cacheFile)){
  140. $jishu ++;
  141. if($jishu > 100){
  142. break;
  143. }
  144. }
  145. if (Config::get('open_wap')){
  146. $wap = 'wap';
  147. $cacheFilewap = RUN_PATH . '/cache/' . md5(get_http_url() . $path . $lg . $wap) . '.html';
  148. unlink($cacheFilewap);
  149. }
  150. unlink($cacheFile);
  151. }
  152. }
  153. }
  154. }
  155. }
  156. // 删除详情页面缓存
  157. private function deleContont()
  158. { $lg = cookie('lg');
  159. $wap = '';
  160. $idzuixiao = get('idzuixiao', 'var');
  161. $idzuida = get('idzuida', 'var');
  162. for($i=$idzuixiao;$i<=$idzuida;$i++){
  163. $data = $this->model->getContent($i);
  164. if ($data) {
  165. $path = $this->parser->parserLink($data->type, $data->urlname, 'content', $data->scode, $data->sortfilename, $data->id, $data->filename);
  166. $cacheFile = RUN_PATH . '/cache/' . md5(get_http_url() . $path . $lg . $wap) . '.html';
  167. unlink($cacheFile);
  168. if (Config::get('open_wap')){
  169. $wap = 'wap';
  170. $cacheFilewap = RUN_PATH . '/cache/' . md5(get_http_url() . $path . $lg . $wap) . '.html';
  171. unlink($cacheFilewap);
  172. }
  173. }
  174. }
  175. }
  176. // 更新内容栏目下拉选择
  177. private function makeSortSelect($tree, $ext_about = false)
  178. {
  179. $list_html = '';
  180. foreach ($tree as $value) {
  181. if (get('scode') != $value->scode) { // 不显示本身,避免出现自身为自己的父节点
  182. if (($ext_about && $value->type == 1) || $value->outlink != '') {
  183. $list_html .= "<option value='{$value->scode}' disabled='disabled'>{$this->blank}{$value->name}</option>";
  184. } else {
  185. $list_html .= "<option value='{$value->scode}' >{$this->blank}{$value->name}</option>";
  186. }
  187. }
  188. // 子菜单处理
  189. if ($value->son) {
  190. $this->blank .= '  ';
  191. $list_html .= $this->makeSortSelect($value->son, $ext_about);
  192. }
  193. }
  194. // 循环完后回归位置
  195. $this->blank = substr($this->blank, 0, - 6);
  196. return $list_html;
  197. }
  198. // 设置公共信息
  199. private function setinfo()
  200. {
  201. // 设置前台模板路径,避免后端调用问题
  202. if (($tpl_dir = Config::get('tpl_dir')) && array_key_exists('home', $tpl_dir)) {
  203. $this->assign('tplpath', ROOT_PATH . $tpl_dir['home']);
  204. } else {
  205. $this->assign('tplpath', APP_PATH . '/home/view');
  206. }
  207. // 定义当前操作为更新静态,后期动作判断
  208. define('DeleCache', true);
  209. }
  210. }