cache.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. function updatedata($cachefile = '') {
  32. if($cachefile) {
  33. foreach((array)$this->map[$cachefile] as $modules) {
  34. $s = "<?php\r\n";
  35. foreach((array)$modules as $m) {
  36. $method = "_get_$m";
  37. $s .= '$_CACHE[\''.$m.'\'] = '.var_export($this->$method(), TRUE).";\r\n";
  38. }
  39. $s .= "\r\n?>";
  40. @file_put_contents(UC_DATADIR."./cache/$cachefile.php", $s);
  41. }
  42. } else {
  43. foreach((array)$this->map as $file => $modules) {
  44. $s = "<?php\r\n";
  45. foreach($modules as $m) {
  46. $method = "_get_$m";
  47. $s .= '$_CACHE[\''.$m.'\'] = '.var_export($this->$method(), TRUE).";\r\n";
  48. }
  49. $s .= "\r\n?>";
  50. @file_put_contents(UC_DATADIR."./cache/$file.php", $s);
  51. }
  52. }
  53. }
  54. function updatetpl() {
  55. }
  56. function _get_badwords() {
  57. $data = $this->db->fetch_all("SELECT * FROM ".UC_DBTABLEPRE."badwords");
  58. $return = array();
  59. if(is_array($data)) {
  60. foreach($data as $k => $v) {
  61. $return['findpattern'][$k] = $v['findpattern'];
  62. $return['replace'][$k] = $v['replacement'];
  63. }
  64. }
  65. return $return;
  66. }
  67. function _get_apps() {
  68. $this->base->load('app');
  69. $apps = $_ENV['app']->get_apps();
  70. $apps2 = array();
  71. if(is_array($apps)) {
  72. foreach($apps as $v) {
  73. $v['extra'] = unserialize($v['extra']);
  74. $apps2[$v['appid']] = $v;
  75. }
  76. }
  77. return $apps2;
  78. }
  79. function _get_settings() {
  80. return $this->base->get_setting();
  81. }
  82. }
  83. ?>