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