-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettings.php
More file actions
59 lines (48 loc) · 1.49 KB
/
Settings.php
File metadata and controls
59 lines (48 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/**
* Управление настройками магазина, хранящимися в базе данных
* В отличие от класса Config оперирует настройками доступными админу и хранящимися в базе данных.
*
*
* @copyright 2011 Denis Pikusov
* @link http://simplacms.ru
* @author Denis Pikusov
*
*/
require_once('Simpla.php');
class Settings extends Simpla
{
private $vars = array();
function __construct()
{
parent::__construct();
// Выбираем из базы настройки
$this->db->query('SELECT name, value FROM __settings');
// и записываем их в переменную
foreach($this->db->results() as $result)
if(!($this->vars[$result->name] = @unserialize($result->value)))
$this->vars[$result->name] = $result->value;
}
public function __get($name)
{
if($res = parent::__get($name))
return $res;
if(isset($this->vars[$name]))
return $this->vars[$name];
else
return null;
}
public function __set($name, $value)
{
$this->vars[$name] = $value;
if(is_array($value))
$value = serialize($value);
else
$value = (string) $value;
$this->db->query('SELECT count(*) as count FROM __settings WHERE name=?', $name);
if($this->db->result('count')>0)
$this->db->query('UPDATE __settings SET value=? WHERE name=?', $value, $name);
else
$this->db->query('INSERT INTO __settings SET value=?, name=?', $value, $name);
}
}