cache.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /*
  3. [UCenter] (C)2001-2099 Comsenz Inc.
  4. This is NOT a freeware, use is subject to license terms
  5. $Id: cache.php 1059 2011-03-01 07:25:09Z monkey $
  6. */
  7. !defined('IN_UC') && exit('Access Denied');
  8. if (!function_exists('file_put_contents'))
  9. {
  10. function file_put_contents($filename, $s)
  11. {
  12. $fp = @fopen($filename, 'w');
  13. @fwrite($fp, $s);
  14. @fclose($fp);
  15. }
  16. }
  17. class cachemodel
  18. {
  19. var $db;
  20. var $base;
  21. var $map;
  22. function __construct(&$base)
  23. {
  24. $this->cachemodel($base);
  25. }
  26. function cachemodel(&$base)
  27. {
  28. $this->base = $base;
  29. $this->db = $base->db;
  30. $this->map = array(
  31. 'settings' => array('settings'),
  32. 'badwords' => array('badwords'),
  33. 'apps' => array('apps')
  34. );
  35. }
  36. function updatedata($cachefile = '')
  37. {
  38. if ($cachefile)
  39. {
  40. foreach ((array) $this->map[$cachefile] as $modules)
  41. {
  42. $s = "<?php\r\n";
  43. foreach ((array) $modules as $m)
  44. {
  45. $method = "_get_$m";
  46. $s .= '$_CACHE[\'' . $m . '\'] = ' . var_export($this->$method(), TRUE) . ";\r\n";
  47. }
  48. $s .= "\r\n?>";
  49. @file_put_contents(UC_DATADIR . "./cache/$cachefile.php", $s);
  50. }
  51. }
  52. else
  53. {
  54. foreach ((array) $this->map as $file => $modules)
  55. {
  56. $s = "<?php\r\n";
  57. foreach ($modules as $m)
  58. {
  59. $method = "_get_$m";
  60. $s .= '$_CACHE[\'' . $m . '\'] = ' . var_export($this->$method(), TRUE) . ";\r\n";
  61. }
  62. $s .= "\r\n?>";
  63. @file_put_contents(UC_DATADIR . "./cache/$file.php", $s);
  64. }
  65. }
  66. }
  67. function updatetpl()
  68. {
  69. }
  70. function _get_badwords()
  71. {
  72. $data = $this->db->fetch_all("SELECT * FROM " . UC_DBTABLEPRE . "badwords");
  73. $return = array();
  74. if (is_array($data))
  75. {
  76. foreach ($data as $k => $v)
  77. {
  78. $return['findpattern'][$k] = $v['findpattern'];
  79. $return['replace'][$k] = $v['replacement'];
  80. }
  81. }
  82. return $return;
  83. }
  84. function _get_apps()
  85. {
  86. $this->base->load('app');
  87. $apps = $_ENV['app']->get_apps();
  88. $apps2 = array();
  89. if (is_array($apps))
  90. {
  91. foreach ($apps as $v)
  92. {
  93. $v['extra'] = unserialize($v['extra']);
  94. $apps2[$v['appid']] = $v;
  95. }
  96. }
  97. return $apps2;
  98. }
  99. function _get_settings()
  100. {
  101. return $this->base->get_setting();
  102. }
  103. }