flea_cache.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4. */
  5. defined('InShopNC') or exit('Access Invalid!');
  6. final class flea_Cache {
  7. public static function getCache($type, $param = "") {
  8. Language::read("core_lang_index");
  9. $lang = Language::getlangcontent();
  10. $type = strtoupper($type[0]) . strtolower(substr($type, 1));
  11. $function = "get" . $type . "Cache";
  12. try {
  13. do {
  14. if (method_exists(flea_Cache, $function)) {
  15. break;
  16. } else {
  17. $error = $lang['please_check_your_cache_type'];
  18. throw new Exception($error);
  19. }
  20. } while (0);
  21. }
  22. catch(Exception $e) {
  23. showmessage($e->getMessage() , "", "exception");
  24. }
  25. $result = self::$function($param);
  26. return $result;
  27. }
  28. private static function getFlea_areaCache($param) {
  29. Language::read("core_lang_index");
  30. $lang = Language::getlangcontent();
  31. $deep = $param['deep'];
  32. $cache_file = BASE_DATA_PATH . DS . "cache" . DS . "flea_area" . DS . "flea_area_" . $deep . ".php";
  33. if (file_exists($cache_file) && time() - SESSION_EXPIRE <= filemtime($cache_file) && empty($param['new'])) {
  34. require ($cache_file);
  35. return $data;
  36. }
  37. $param = array();
  38. $param['table'] = "flea_area";
  39. $param['where'] = "flea_area_deep = '" . $deep . "'";
  40. $param['order'] = "flea_area_sort asc";
  41. $result = Db::select($param);
  42. $tmp.= "<?php \r\n";
  43. $tmp.= "defined('InShopNC') or exit('Access Invalid!'); \r\n";
  44. $tmp.= "\$data = array(\r\n";
  45. if (is_array($result)) {
  46. foreach ($result as $k => $v) {
  47. $tmp.= "\tarray(\r\n";
  48. $tmp.= "\t\t'flea_area_id'=>'" . $v['flea_area_id'] . "',\r\n";
  49. $tmp.= "\t\t'flea_area_name'=>'" . htmlspecialchars($v['flea_area_name']) . "',\r\n";
  50. $tmp.= "\t\t'flea_area_parent_id'=>'" . $v['flea_area_parent_id'] . "',\r\n";
  51. $tmp.= "\t\t'flea_area_sort'=>'" . $v['flea_area_sort'] . "',\r\n";
  52. $tmp.= "\t\t'flea_area_deep'=>'" . $v['flea_area_deep'] . "',\r\n";
  53. $tmp.= "\t),\r\n";
  54. }
  55. }
  56. $tmp.= ");";
  57. try {
  58. $fp = @fopen($cache_file, "wb+");
  59. if (fwrite($fp, $tmp) === FALSE) {
  60. $error = $lang['please_check_your_system_chmod_area'];
  61. throw new Exception();
  62. }
  63. @fclose($fp);
  64. require ($cache_file);
  65. return $data;
  66. }
  67. catch(Exception $e) {
  68. showmessage($e->getMessage() , "", "exception");
  69. }
  70. }
  71. public static function makeallcache($type) {
  72. Language::read("core_lang_index");
  73. $lang = Language::getlangcontent();
  74. $time = time();
  75. switch ($type) {
  76. case "area":
  77. $file_list = readfilelist(BASE_DATA_PATH . DS . "cache" . DS . "flea_area");
  78. if (is_array($file_list)) {
  79. foreach ($file_list as $v) {
  80. @unlink(BASE_DATA_PATH . DS . "cache" . DS . "flea_area" . DS . $v);
  81. }
  82. }
  83. $maxdeep = 1;
  84. default:
  85. $param = array();
  86. $param['table'] = "flea_area";
  87. $param['where'] = "flea_area_deep = '" . $maxdeep . "'";
  88. $param['order'] = "flea_area_sort asc";
  89. $result = Db::select($param);
  90. if (!empty($result)) {
  91. $cache_file_area = BASE_DATA_PATH . DS . "cache" . DS . "area" . DS . "flea_area_" . $maxdeep . ".php";
  92. $tmp.= "<?php \r\n";
  93. $tmp.= "defined('InShopNC') or exit('Access Invalid!'); \r\n";
  94. $tmp.= "\$data = array(\r\n";
  95. if (is_array($result)) {
  96. foreach ($result as $k => $v) {
  97. $tmp.= "\tarray(\r\n";
  98. $tmp.= "\t\t'flea_area_id'=>'" . $v['flea_area_id'] . "',\r\n";
  99. $tmp.= "\t\t'flea_area_name'=>'" . htmlspecialchars($v['flea_area_name']) . "',\r\n";
  100. $tmp.= "\t\t'flea_area_parent_id'=>'" . $v['flea_area_parent_id'] . "',\r\n";
  101. $tmp.= "\t\t'flea_area_sort'=>'" . $v['flea_area_sort'] . "',\r\n";
  102. $tmp.= "\t\t'flea_area_deep'=>'" . $v['flea_area_deep'] . "',\r\n";
  103. $tmp.= "\t),\r\n";
  104. }
  105. }
  106. $tmp.= ");";
  107. try {
  108. $fp = @fopen($cache_file_area, "wb+");
  109. if (fwrite($fp, $tmp) === FALSE) {
  110. $error = $lang['please_check_your_system_chmod_area'];
  111. throw new Exception();
  112. }
  113. unset($tmp);
  114. @fclose($fp);
  115. }
  116. catch(Exception $e) {
  117. showmessage($e->getMessage() , "", "exception");
  118. }
  119. }
  120. ++$maxdeep;
  121. }
  122. }
  123. }
  124. ?>