cache.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. function file_put_contents($filename, $s) {
  10. $fp = @fopen($filename, 'w');
  11. @fwrite($fp, $s);
  12. @fclose($fp);
  13. }
  14. }
  15. class cachemodel {
  16. var $db;
  17. var $base;
  18. var $map;
  19. function __construct(&$base) {
  20. $this->cachemodel($base);
  21. }
  22. function cachemodel(&$base) {
  23. $this->base = $base;
  24. $this->db = $base->db;
  25. $this->map = array(
  26. 'settings' => array('settings'),
  27. 'badwords' => array('badwords'),
  28. 'apps' => array('apps')
  29. );
  30. }
  31. //public
  32. function updatedata($cachefile = '') {
  33. if($cachefile) {
  34. foreach((array)$this->map[$cachefile] as $modules) {
  35. $s = "<?php\r\n";
  36. foreach((array)$modules as $m) {
  37. $method = "_get_$m";
  38. $s .= '$_CACHE[\''.$m.'\'] = '.var_export($this->$method(), TRUE).";\r\n";
  39. }
  40. $s .= "\r\n?>";
  41. @file_put_contents(UC_DATADIR."./cache/$cachefile.php", $s);
  42. }
  43. } else {
  44. foreach((array)$this->map as $file => $modules) {
  45. $s = "<?php\r\n";
  46. foreach($modules as $m) {
  47. $method = "_get_$m";
  48. $s .= '$_CACHE[\''.$m.'\'] = '.var_export($this->$method(), TRUE).";\r\n";
  49. }
  50. $s .= "\r\n?>";
  51. @file_put_contents(UC_DATADIR."./cache/$file.php", $s);
  52. }
  53. }
  54. }
  55. function updatetpl() {
  56. }
  57. //private
  58. function _get_badwords() {
  59. $data = $this->db->fetch_all("SELECT * FROM ".UC_DBTABLEPRE."badwords");
  60. $return = array();
  61. if(is_array($data)) {
  62. foreach($data as $k => $v) {
  63. $return['findpattern'][$k] = $v['findpattern'];
  64. $return['replace'][$k] = $v['replacement'];
  65. }
  66. }
  67. return $return;
  68. }
  69. //private
  70. function _get_apps() {
  71. $this->base->load('app');
  72. $apps = $_ENV['app']->get_apps();
  73. $apps2 = array();
  74. if(is_array($apps)) {
  75. foreach($apps as $v) {
  76. $v['extra'] = unserialize($v['extra']);
  77. $apps2[$v['appid']] = $v;
  78. }
  79. }
  80. return $apps2;
  81. }
  82. function _get_settings() {
  83. return $this->base->get_setting();
  84. }
  85. }
  86. ?>