2007-04-16 11:58:25 +00:00
|
|
|
<?php
|
|
|
|
class Config {
|
2007-05-01 13:40:48 +00:00
|
|
|
var $values = array();
|
2007-04-16 11:58:25 +00:00
|
|
|
var $defaults = array(
|
|
|
|
'title' => 'Shimmie', # setup
|
2007-07-16 12:17:43 +00:00
|
|
|
'version' => 'Shimmie2-2.0.3', // internal
|
2007-04-16 11:58:25 +00:00
|
|
|
'base_href' => './index.php?q=', # setup
|
|
|
|
'data_href' => './', # setup
|
|
|
|
'image_ilink' => '$base/image/$id.$ext', # view
|
|
|
|
'image_slink' => '', # view
|
|
|
|
'image_tlink' => '$base/thumb/$id.jpg', # view
|
|
|
|
'image_tip' => '$tags // $size // $filesize' # view
|
|
|
|
);
|
|
|
|
|
|
|
|
public function Config() {
|
|
|
|
global $database;
|
|
|
|
$this->values = $database->db->GetAssoc("SELECT name, value FROM config");
|
|
|
|
}
|
|
|
|
public function save($name=null) {
|
|
|
|
global $database;
|
|
|
|
|
|
|
|
if(is_null($name)) {
|
|
|
|
foreach($this->values as $name => $value) {
|
|
|
|
// does "or update" work with sqlite / postgres?
|
|
|
|
$database->db->StartTrans();
|
2007-05-23 22:19:12 +00:00
|
|
|
$database->Execute("DELETE FROM config WHERE name = ?", array($name));
|
|
|
|
$database->Execute("INSERT INTO config VALUES (?, ?)", array($name, $value));
|
2007-04-16 11:58:25 +00:00
|
|
|
$database->db->CommitTrans();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$database->db->StartTrans();
|
2007-05-23 22:19:12 +00:00
|
|
|
$database->Execute("DELETE FROM config WHERE name = ?", array($name));
|
|
|
|
$database->Execute("INSERT INTO config VALUES (?, ?)", array($name, $this->values[$name]));
|
2007-04-16 11:58:25 +00:00
|
|
|
$database->db->CommitTrans();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function set_int($name, $value) {
|
|
|
|
$this->values[$name] = parse_shorthand_int($value);
|
|
|
|
$this->save($name);
|
|
|
|
}
|
|
|
|
public function set_string($name, $value) {
|
|
|
|
$this->values[$name] = $value;
|
|
|
|
$this->save($name);
|
|
|
|
}
|
|
|
|
public function set_bool($name, $value) {
|
|
|
|
$this->values[$name] = (($value == 'on' || $value === true) ? 'Y' : 'N');
|
|
|
|
$this->save($name);
|
|
|
|
}
|
2007-07-16 13:15:56 +00:00
|
|
|
|
|
|
|
public function set_default_int($name, $value) {
|
|
|
|
if(is_null($this->get($name))) {
|
|
|
|
$this->values[$name] = parse_shorthand_int($value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function set_default_string($name, $value) {
|
2007-07-16 12:40:44 +00:00
|
|
|
if(is_null($this->get($name))) {
|
|
|
|
$this->values[$name] = $value;
|
|
|
|
}
|
|
|
|
}
|
2007-07-16 13:15:56 +00:00
|
|
|
public function set_default_bool($name, $value) {
|
|
|
|
if(is_null($this->get($name))) {
|
|
|
|
$this->values[$name] = (($value == 'on' || $value === true) ? 'Y' : 'N');
|
|
|
|
}
|
|
|
|
}
|
2007-04-16 11:58:25 +00:00
|
|
|
|
2007-05-01 13:40:48 +00:00
|
|
|
public function get_int($name, $default=null) {
|
2007-04-16 11:58:25 +00:00
|
|
|
// deprecated -- ints should be stored as ints now
|
2007-05-01 13:40:48 +00:00
|
|
|
return parse_shorthand_int($this->get($name, $default));
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
2007-05-01 13:40:48 +00:00
|
|
|
public function get_string($name, $default=null) {
|
|
|
|
return $this->get($name, $default);
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
2007-05-01 13:40:48 +00:00
|
|
|
public function get_bool($name, $default=null) {
|
2007-04-16 11:58:25 +00:00
|
|
|
// deprecated -- bools should be stored as Y/N now
|
2007-07-16 13:15:56 +00:00
|
|
|
return (
|
|
|
|
$this->get($name, $default) == 'Y' ||
|
|
|
|
$this->get($name, $default) == '1' ||
|
|
|
|
$this->get($name, $default) === true
|
|
|
|
);
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
|
|
|
|
2007-07-12 07:50:08 +00:00
|
|
|
private function get($name, $default=null) {
|
2007-04-16 11:58:25 +00:00
|
|
|
if(isset($this->values[$name])) {
|
|
|
|
return $this->values[$name];
|
|
|
|
}
|
|
|
|
else if(isset($this->defaults[$name])) {
|
|
|
|
return $this->defaults[$name];
|
|
|
|
}
|
|
|
|
else {
|
2007-05-01 13:40:48 +00:00
|
|
|
return $default;
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|