3 // retrieve a "family" of config variables from database to cached storage
5 if(! function_exists('load_config')) {
6 function load_config($family) {
8 $r = q("SELECT * FROM `config` WHERE `cat` = '%s'",
14 if ($rr['cat'] === 'config') {
15 $a->config[$k] = $rr['v'];
17 $a->config[$family][$k] = $rr['v'];
23 // get a particular config variable given the family name
24 // and key. Returns false if not set.
25 // $instore is only used by the set_config function
26 // to determine if the key already exists in the DB
27 // If a key is found in the DB but doesn't exist in
28 // local config cache, pull it into the cache so we don't have
29 // to hit the DB again for this item.
31 if(! function_exists('get_config')) {
32 function get_config($family, $key, $instore = false) {
37 if(isset($a->config[$family][$key])) {
38 if($a->config[$family][$key] === '!<unset>!') {
41 return $a->config[$family][$key];
44 $ret = q("SELECT `v` FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
50 $val = (preg_match("|^a:[0-9]+:{.*}$|", $ret[0]['v'])?unserialize( $ret[0]['v']):$ret[0]['v']);
51 $a->config[$family][$key] = $val;
55 $a->config[$family][$key] = '!<unset>!';
60 // Store a config value ($value) in the category ($family)
61 // under the key ($key)
62 // Return the value, or false if the database update failed
64 if(! function_exists('set_config')) {
65 function set_config($family,$key,$value) {
69 $dbvalue = (is_array($value)?serialize($value):$value);
71 if(get_config($family,$key,true) === false) {
72 $a->config[$family][$key] = $value;
73 $ret = q("INSERT INTO `config` ( `cat`, `k`, `v` ) VALUES ( '%s', '%s', '%s' ) ",
83 $ret = q("UPDATE `config` SET `v` = '%s' WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
89 $a->config[$family][$key] = $value;
97 if(! function_exists('load_pconfig')) {
98 function load_pconfig($uid,$family) {
100 $r = q("SELECT * FROM `pconfig` WHERE `cat` = '%s' AND `uid` = %d",
107 $a->config[$uid][$family][$k] = $rr['v'];
114 if(! function_exists('get_pconfig')) {
115 function get_pconfig($uid,$family, $key, $instore = false) {
120 if(isset($a->config[$uid][$family][$key])) {
121 if($a->config[$uid][$family][$key] === '!<unset>!') {
124 return $a->config[$uid][$family][$key];
128 $ret = q("SELECT `v` FROM `pconfig` WHERE `uid` = %d AND `cat` = '%s' AND `k` = '%s' LIMIT 1",
135 $a->config[$uid][$family][$key] = $ret[0]['v'];
139 $a->config[$uid][$family][$key] = '!<unset>!';
144 if(! function_exists('del_config')) {
145 function del_config($family,$key) {
148 if(x($a->config[$family],$key))
149 unset($a->config[$family][$key]);
150 $ret = q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
159 // Same as above functions except these are for personal config storage and take an
160 // additional $uid argument.
162 if(! function_exists('set_pconfig')) {
163 function set_pconfig($uid,$family,$key,$value) {
167 if(get_pconfig($uid,$family,$key,true) === false) {
168 $a->config[$uid][$family][$key] = $value;
169 $ret = q("INSERT INTO `pconfig` ( `uid`, `cat`, `k`, `v` ) VALUES ( %d, '%s', '%s', '%s' ) ",
179 $ret = q("UPDATE `pconfig` SET `v` = '%s' WHERE `uid` = %d AND `cat` = '%s' AND `k` = '%s' LIMIT 1",
186 $a->config[$uid][$family][$key] = $value;
193 if(! function_exists('del_pconfig')) {
194 function del_pconfig($uid,$family,$key) {
197 if(x($a->config[$uid][$family],$key))
198 unset($a->config[$uid][$family][$key]);
199 $ret = q("DELETE FROM `pconfig` WHERE `uid` = %d AND `cat` = '%s' AND `k` = '%s' LIMIT 1",