* @package BcWe core * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version $Id$ */ class datacache { var $data = array(); var $expires = array(); function __construct(){ global $config, $db; $res=$db->query('SELECT `cache`,`content`,`expire` FROM `' . $config['prefix'] . 'datacache`'); while($row=$db->fetch_object($res)){ $this->data[$row->cache]=@unserialize(base64_decode($row->content)); $this->expires[$row->cache]=$row->expire; } } //Fetch userdata function read($cache){ global $config, $db; if(isset($this->data[$cache]) && $this->data[$cache]){ return $this->data[$cache]; }else{ $res=$db->query('SELECT `cache`,`content` FROM `' . $config['prefix'] . 'datacache` WHERE `cache`=\''.$db->escape($cache).'\' LIMIT 1') or die($db->error()); $row=$db->fetch_row($res); if(!$row[0]){ $data=false; }else{ $data = @unserialize(base64_decode($row[1])); } return $data; } } function set($name,$data,$expires=0){ global $db,$config; $data=base64_encode(serialize($data)); $test=$this->read($name); if($test){ $res=$db->query('UPDATE `' . $config['prefix'] . 'datacache` SET `content`=\''.$data.'\',`expire`=\''.$expires.'\' WHERE `cache`=\''.$db->escape($name).'\''); if($res){ return true; } }else{ $res=$db->query('INSERT INTO `' . $config['prefix'] . 'datacache` (`cache`,`content`,`expire`) VALUES (\''.$db->escape($name).'\',\''.$data.'\',\''.$expires.'\')'); if($res){ return true; } } return false; } function is_expired($name){ global $db,$config; if(isset($this->expires[$name])){ if($this->expires[$name]expires[$name]!=0){ return true; }else{ return false; } } $res=$db->query('SELECT `cache` FROM `' . $config['prefix'] . 'datacache` WHERE `cache`=\''.$db->escape($name).'\' AND `expire`< \''.time().'\' AND `expire`<>\'0\' LIMIT 1'); $row=$db->fetch_row($res); if($row[0]){ return true; } return false; } function update_sidebars(){ global $db,$config; $res = $db->query('SELECT `name`, `content`, `file` FROM `' . $config['prefix'] . 'navigation` WHERE `side`=\'l\' ORDER BY `sort`'); while ($row=$db->fetch_row($res)){ $nav['l'][]=array('name'=>$row[0],'content'=>$row[1],'file'=>$row[2]); } $res = $db->query('SELECT `name`, `content`, `file` FROM `' . $config['prefix'] . 'navigation` WHERE `side`=\'r\' ORDER BY `sort`'); while ($row=$db->fetch_row($res)){ $nav['r'][]=array('name'=>$row[0],'content'=>$row[1],'file'=>$row[2]); } $this->set('sidebar',$nav); } } ?>