2016-06-08 01:17:39 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Zotlabs\Lib;
|
|
|
|
|
|
|
|
|
|
|
|
class AbConfig {
|
|
|
|
|
2016-07-14 03:17:40 +00:00
|
|
|
static public function Load($chan,$xhash,$family = '') {
|
|
|
|
if($family)
|
2016-07-20 02:33:48 +00:00
|
|
|
$where = sprintf(" and cat = '%s' ",dbesc($family));
|
2016-07-14 03:17:40 +00:00
|
|
|
$r = q("select * from abconfig where chan = %d and xchan = '%s' $where",
|
2016-06-24 01:12:26 +00:00
|
|
|
intval($chan),
|
2016-06-08 01:17:39 +00:00
|
|
|
dbesc($xhash)
|
|
|
|
);
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-05 22:50:34 +00:00
|
|
|
static public function Get($chan,$xhash,$family,$key, $default = false) {
|
2016-06-24 01:12:26 +00:00
|
|
|
$r = q("select * from abconfig where chan = %d and xchan = '%s' and cat = '%s' and k = '%s' limit 1",
|
|
|
|
intval($chan),
|
2016-06-08 01:17:39 +00:00
|
|
|
dbesc($xhash),
|
|
|
|
dbesc($family),
|
|
|
|
dbesc($key)
|
|
|
|
);
|
|
|
|
if($r) {
|
2018-11-21 03:15:15 +00:00
|
|
|
return unserialise($r[0]['v']);
|
2016-06-08 01:17:39 +00:00
|
|
|
}
|
2016-12-05 22:50:34 +00:00
|
|
|
return $default;
|
2016-06-08 01:17:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-24 01:12:26 +00:00
|
|
|
static public function Set($chan,$xhash,$family,$key,$value) {
|
2016-06-08 01:17:39 +00:00
|
|
|
|
2018-11-21 03:15:15 +00:00
|
|
|
$dbvalue = ((is_array($value)) ? serialise($value) : $value);
|
2016-06-08 01:17:39 +00:00
|
|
|
$dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue);
|
|
|
|
|
2016-06-24 01:12:26 +00:00
|
|
|
if(self::Get($chan,$xhash,$family,$key) === false) {
|
|
|
|
$r = q("insert into abconfig ( chan, xchan, cat, k, v ) values ( %d, '%s', '%s', '%s', '%s' ) ",
|
|
|
|
intval($chan),
|
2016-06-08 01:17:39 +00:00
|
|
|
dbesc($xhash),
|
|
|
|
dbesc($family),
|
|
|
|
dbesc($key),
|
|
|
|
dbesc($dbvalue)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
2016-06-24 01:12:26 +00:00
|
|
|
$r = q("update abconfig set v = '%s' where chan = %d and xchan = '%s' and cat = '%s' and k = '%s' ",
|
2016-06-08 01:17:39 +00:00
|
|
|
dbesc($dbvalue),
|
2016-06-24 01:12:26 +00:00
|
|
|
dbesc($chan),
|
2016-06-08 01:17:39 +00:00
|
|
|
dbesc($xhash),
|
|
|
|
dbesc($family),
|
|
|
|
dbesc($key)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if($r)
|
|
|
|
return $value;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-24 01:12:26 +00:00
|
|
|
static public function Delete($chan,$xhash,$family,$key) {
|
2016-06-08 01:17:39 +00:00
|
|
|
|
2016-06-24 01:12:26 +00:00
|
|
|
$r = q("delete from abconfig where chan = %d and xchan = '%s' and cat = '%s' and k = '%s' ",
|
|
|
|
intval($chan),
|
2016-06-08 01:17:39 +00:00
|
|
|
dbesc($xhash),
|
|
|
|
dbesc($family),
|
|
|
|
dbesc($key)
|
|
|
|
);
|
|
|
|
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
|
2016-06-24 01:12:26 +00:00
|
|
|
}
|