cache.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. 'plugins' => array('plugins'),
  29. 'apps' => array('apps'),
  30. );
  31. }
  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. $tpl = dir(UC_DATADIR.'view');
  57. while($entry = $tpl->read()) {
  58. if(preg_match("/\.php$/", $entry)) {
  59. @unlink(UC_DATADIR.'view/'.$entry);
  60. }
  61. }
  62. $tpl->close();
  63. }
  64. function _get_badwords() {
  65. $data = $this->db->fetch_all("SELECT * FROM ".UC_DBTABLEPRE."badwords");
  66. $return = array();
  67. if(is_array($data)) {
  68. foreach($data as $k => $v) {
  69. $return['findpattern'][$k] = $v['findpattern'];
  70. $return['replace'][$k] = $v['replacement'];
  71. }
  72. }
  73. return $return;
  74. }
  75. function _get_apps() {
  76. $this->base->load('app');
  77. $apps = $_ENV['app']->get_apps();
  78. $apps2 = array();
  79. if(is_array($apps)) {
  80. foreach($apps as $v) {
  81. $apps2[$v['appid']] = $v;
  82. }
  83. }
  84. return $apps2;
  85. }
  86. function _get_settings() {
  87. return $this->base->get_setting();
  88. }
  89. function _get_plugins() {
  90. $this->base->load('plugin');
  91. return $_ENV['plugin']->get_plugins();
  92. }
  93. }
  94. ?>