<?php
class theme{
protected $name;
protected $_vars = array();
protected $_need_save = false;

var $runame;
var $content;
var $browser;
var $img_width_max = 300;

function __construct($name)
{
$this->name = $name;

if ($data=@parse_ini_file(H.'/sys/themes/'.$this->name.'/config.ini',true))
{
$this->runame = empty($data['CONFIG']['name'])?$name:$data['CONFIG']['name'];
$this->content = empty($data['CONFIG']['content'])?'html':$data['CONFIG']['content'];
$this->browser = empty($data['CONFIG']['browser'])?'web':$data['CONFIG']['browser'];
$this->img_width_max = empty($data['CONFIG']['img_width_max'])?'300':$data['CONFIG']['img_width_max'];

$this->_vars = &$data['VARS'];

}


}


function __get($n)
{
return isset($this->_vars[$n])?$this->_vars[$n]:false;
}

function __set($n,$v)
{
$this->_vars[$n] = $v;
$this->_need_save = true;
}

function __destruct()
{
if ($this->_need_save)
{
$ini = array();
$ini[]='[CONFIG]';
$ini[]='name = "'.for_value($this->runame).'"';
$ini[]='content = "'.for_value($this->content).'"';
$ini[]='browser = "'.for_value($this->browser).'"';
$ini[]='img_width_max = "'.for_value($this->img_width_max).'"';
$ini[]='[VARS]';
foreach ($this -> _vars as $key=>$value) {
	$ini[] = "$key = \"".for_value($value)."\";";
}
@file_put_contents(H.'/sys/themes/'.$this->name.'/config.ini', implode("\r\n",$ini));
}
}

}
?>
