CacheAction.class.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Fanwe 方维直播系统
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: 云淡风轻(1956838968@qq.com)
  8. // +----------------------------------------------------------------------
  9. class CacheAction extends CommonAction{
  10. public function clear_admin()
  11. {
  12. set_time_limit(0);
  13. es_session::close();
  14. $this->clear_admin_file();
  15. header("Content-Type:text/html; charset=utf-8");
  16. exit("<div style='line-height:50px; text-align:center; color:#f30;'>".L('CLEAR_SUCCESS')."</div><div style='text-align:center;'><input type='button' onclick='$.weeboxs.close();' class='button' value='关闭' /></div>");
  17. }
  18. private function clear_admin_file(){
  19. clear_dir_file(get_real_path()."public/runtime/admin/Cache/");
  20. clear_dir_file(get_real_path()."public/runtime/admin/Data/_fields/");
  21. clear_dir_file(get_real_path()."public/runtime/admin/Temp/");
  22. clear_dir_file(get_real_path()."public/runtime/admin/Logs/");
  23. clear_file(get_real_path()."public/runtime/admin/~app.php");
  24. clear_file(get_real_path()."public/runtime/admin/~runtime.php");
  25. clear_file(get_real_path()."public/runtime/admin/lang.js");
  26. clear_file(get_real_path()."public/runtime/app/config_cache.php");
  27. }
  28. public function clear_parse_file()
  29. {
  30. set_time_limit(0);
  31. es_session::close();
  32. $this->clear_parse_file_fun();
  33. header("Content-Type:text/html; charset=utf-8");
  34. if($GLOBALS['distribution_cfg']['CACHE_TYPE']!="File"&&$GLOBALS['distribution_cfg']['CACHE_TYPE']!="Db")
  35. {
  36. exit("<div style='line-height:25px; text-align:center; color:#f30;'>".L('CLEAR_SUCCESS').",如未生效,请进入缓存管理平台重置缓存</div><div style='text-align:center;'><input type='button' onclick='$.weeboxs.close();' class='button' value='关闭' /></div>");
  37. }
  38. else
  39. exit("<div style='line-height:50px; text-align:center; color:#f30;'>".L('CLEAR_SUCCESS')."</div><div style='text-align:center;'><input type='button' onclick='$.weeboxs.close();' class='button' value='关闭' /></div>");
  40. }
  41. private function clear_parse_file_fun(){
  42. clear_dir_file(get_real_path()."public/runtime/statics/");
  43. clear_dir_file(get_real_path()."public/runtime/app/tpl_caches/");
  44. clear_dir_file(get_real_path()."public/runtime/app/tpl_compiled/");
  45. clear_dir_file(get_real_path()."public/runtime/wap/tpl_caches/");
  46. clear_dir_file(get_real_path()."public/runtime/wap/tpl_compiled/");
  47. clear_dir_file(get_real_path()."public/runtime/wap_app/tpl_caches/");
  48. clear_dir_file(get_real_path()."public/runtime/wap_app/tpl_compiled/");
  49. }
  50. public function clear_data()
  51. {
  52. set_time_limit(0);
  53. es_session::close();
  54. $this->clear_data_file();
  55. header("Content-Type:text/html; charset=utf-8");
  56. if($GLOBALS['distribution_cfg']['CACHE_TYPE']!="File"&&$GLOBALS['distribution_cfg']['CACHE_TYPE']!="Db")
  57. {
  58. exit("<div style='line-height:25px; text-align:center; color:#f30;'>".L('CLEAR_SUCCESS').",如未生效,请进入缓存管理平台重置缓存</div><div style='text-align:center;'><input type='button' onclick='$.weeboxs.close();' class='button' value='关闭' /></div>");
  59. }
  60. else
  61. exit("<div style='line-height:50px; text-align:center; color:#f30;'>".L('CLEAR_SUCCESS')."</div><div style='text-align:center;'><input type='button' onclick='$.weeboxs.close();' class='button' value='关闭' /></div>");
  62. }
  63. private function clear_data_file(){
  64. clear_file(get_real_path()."public/runtime/app/deal_cate_conf.js");
  65. clear_dir_file(get_real_path()."public/runtime/app/deal_region_conf/");
  66. if(intval($_REQUEST['is_all'])==0)
  67. {
  68. //数据缓存
  69. clear_dir_file(get_real_path()."public/runtime/app/data_caches/");
  70. clear_dir_file(get_real_path()."public/runtime/app/db_caches/");
  71. clear_dir_file(get_real_path()."public/runtime/mapi/data_caches/");
  72. $GLOBALS['cache']->clear();
  73. clear_dir_file(get_real_path()."public/runtime/app/tpl_caches/");
  74. clear_dir_file(get_real_path()."public/runtime/app/tpl_compiled/");
  75. clear_dir_file(get_real_path()."public/runtime/wap/tpl_caches/");
  76. clear_dir_file(get_real_path()."public/runtime/wap/tpl_compiled/");
  77. clear_dir_file(get_real_path()."public/runtime/wap_app/tpl_caches/");
  78. clear_dir_file(get_real_path()."public/runtime/wap_app/tpl_compiled/");
  79. clear_file(get_real_path()."public/runtime/app/lang.js");
  80. //删除相关未自动清空的数据缓存
  81. clear_auto_cache("page_image");
  82. }
  83. else
  84. {
  85. clear_dir_file(get_real_path()."public/runtime/data/");
  86. clear_dir_file(get_real_path()."public/runtime/app/data_caches/");
  87. clear_dir_file(get_real_path()."public/runtime/app/db_caches/");
  88. clear_dir_file(get_real_path()."public/runtime/mapi/data_caches/");
  89. $GLOBALS['cache']->clear();
  90. clear_dir_file(get_real_path()."public/runtime/app/tpl_caches/");
  91. clear_dir_file(get_real_path()."public/runtime/app/tpl_compiled/");
  92. clear_dir_file(get_real_path()."public/runtime/wap/tpl_caches/");
  93. clear_dir_file(get_real_path()."public/runtime/wap/tpl_compiled/");
  94. clear_dir_file(get_real_path()."public/runtime/wap_app/tpl_caches/");
  95. clear_dir_file(get_real_path()."public/runtime/wap_app/tpl_compiled/");
  96. clear_file(get_real_path()."public/runtime/app/lang.js");
  97. //后台
  98. clear_dir_file(get_real_path()."public/runtime/admin/Cache/");
  99. clear_dir_file(get_real_path()."public/runtime/admin/Data/_fields/");
  100. clear_dir_file(get_real_path()."public/runtime/admin/Temp/");
  101. clear_dir_file(get_real_path()."public/runtime/admin/Logs/");
  102. clear_file(get_real_path()."public/runtime/admin/~app.php");
  103. clear_file(get_real_path()."public/runtime/admin/~runtime.php");
  104. clear_file(get_real_path()."public/runtime/admin/lang.js");
  105. clear_file(get_real_path()."public/runtime/app/config_cache.php");
  106. $GLOBALS['db']->query("update ".DB_PREFIX."deal_log set comment_data_cache = '',deal_info_cache=''");
  107. $GLOBALS['db']->query("update ".DB_PREFIX."deal set deal_extra_cache = ''");
  108. $GLOBALS['db']->query("update ".DB_PREFIX."deal_comment set deal_info_cache=''");
  109. }
  110. }
  111. public function clear_image()
  112. {
  113. set_time_limit(0);
  114. es_session::close();
  115. $this->clear_image_file_fun();
  116. header("Content-Type:text/html; charset=utf-8");
  117. if($GLOBALS['distribution_cfg']['CACHE_TYPE']!="File"&&$GLOBALS['distribution_cfg']['CACHE_TYPE']!="Db")
  118. {
  119. exit("<div style='line-height:25px; text-align:center; color:#f30;'>".L('CLEAR_SUCCESS').",如未生效,请进入缓存管理平台重置缓存</div><div style='text-align:center;'><input type='button' onclick='$.weeboxs.close();' class='button' value='关闭' /></div>");
  120. }
  121. else
  122. exit("<div style='line-height:50px; text-align:center; color:#f30;'>".L('CLEAR_SUCCESS')."</div><div style='text-align:center;'><input type='button' onclick='$.weeboxs.close();' class='button' value='关闭' /></div>");
  123. }
  124. private function clear_image_file_fun(){
  125. $path = APP_ROOT_PATH."public/attachment/";
  126. $this->clear_image_file($path);
  127. $path = APP_ROOT_PATH."public/images/";
  128. $this->clear_image_file($path);
  129. $qrcode_path = APP_ROOT_PATH."public/images/qrcode/";
  130. $this->clear_qrcode($qrcode_path);
  131. clear_dir_file(get_real_path()."public/runtime/app/tpl_caches/");
  132. clear_dir_file(get_real_path()."public/runtime/app/tpl_compiled/");
  133. }
  134. public function clear_all(){
  135. set_time_limit(0);
  136. es_session::close();
  137. $GLOBALS['cache']->clear();
  138. // $GLOBALS['cache']->celar_con();
  139. $this->updateRegionJS();
  140. $this->clear_admin_file();
  141. $this->clear_parse_file_fun();
  142. $this->clear_data_file();
  143. $this->clear_image_file_fun();
  144. header("Content-Type:text/html; charset=utf-8");
  145. exit("<div style='line-height:50px; text-align:center; color:#f30;'>".L('CLEAR_SUCCESS')."</div><div style='text-align:center;'><input type='button' onclick='$.weeboxs.close();' class='button' value='关闭' /></div>");
  146. }
  147. private function updateRegionJS()
  148. {
  149. $jsStr = "var regionConf = ".$this->getRegionJS();
  150. $path = get_real_path()."public/region.js";
  151. @file_put_contents($path,$jsStr);
  152. }
  153. private function getRegionJS()
  154. {
  155. $jsStr = "";
  156. $childRegionList = M("RegionConf")->where("region_level = 2")->order("id asc")->findAll();
  157. foreach($childRegionList as $childRegion)
  158. {
  159. if(empty($jsStr))
  160. $jsStr .= "{";
  161. else
  162. $jsStr .= ",";
  163. $childStr = $this->getRegionChildJS($childRegion['id']);
  164. $jsStr .= "\"r$childRegion[id]\":{\"i\":$childRegion[id],\"n\":\"$childRegion[name]\",\"c\":$childStr}";
  165. }
  166. if(!empty($jsStr))
  167. $jsStr .= "}";
  168. else
  169. $jsStr .= "\"\"";
  170. return $jsStr;
  171. }
  172. private function getRegionChildJS($pid)
  173. {
  174. $jsStr = "";
  175. $childRegionList = M("RegionConf")->where("pid=".$pid)->order("id asc")->findAll();
  176. foreach($childRegionList as $childRegion)
  177. {
  178. if(empty($jsStr))
  179. $jsStr .= "{";
  180. else
  181. $jsStr .= ",";
  182. $childStr = $this->getRegionChildJS($childRegion['id']);
  183. $jsStr .= "\"r$childRegion[id]\":{\"i\":$childRegion[id],\"n\":\"$childRegion[name]\",\"c\":$childStr}";
  184. }
  185. if(!empty($jsStr))
  186. $jsStr .= "}";
  187. else
  188. $jsStr .= "\"\"";
  189. return $jsStr;
  190. }
  191. private function clear_qrcode($path)
  192. {
  193. if ( $dir = opendir( $path ) )
  194. {
  195. while ( $file = readdir( $dir ) )
  196. {
  197. $check = is_dir( $path. $file );
  198. if ( !$check )
  199. {
  200. @unlink ( $path . $file);
  201. }
  202. else
  203. {
  204. if($file!='.'&&$file!='..')
  205. {
  206. $this->clear_qrcode($path.$file."/");
  207. }
  208. }
  209. }
  210. closedir( $dir );
  211. return true;
  212. }
  213. }
  214. private function clear_image_file($path)
  215. {
  216. if ( $dir = opendir( $path ) )
  217. {
  218. while ( $file = readdir( $dir ) )
  219. {
  220. $check = is_dir( $path. $file );
  221. if ( !$check )
  222. {
  223. if(preg_match("/_(\d+)x(\d+)/i",$file,$matches))
  224. @unlink ( $path . $file);
  225. }
  226. else
  227. {
  228. if($file!='.'&&$file!='..')
  229. {
  230. $this->clear_image_file($path.$file."/");
  231. }
  232. }
  233. }
  234. closedir( $dir );
  235. return true;
  236. }
  237. }
  238. }
  239. ?>