streams/Zotlabs/Lib/AbConfig.php

74 lines
1.5 KiB
PHP
Raw Normal View History

2016-06-08 01:17:39 +00:00
<?php
namespace Zotlabs\Lib;
class AbConfig {
static public function Load($chan,$xhash) {
$r = q("select * from abconfig where chan = %d and xchan = '%s'",
intval($chan),
2016-06-08 01:17:39 +00:00
dbesc($xhash)
);
return $r;
}
static public function Get($chan,$xhash,$family,$key) {
$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) {
return ((preg_match('|^a:[0-9]+:{.*}$|s', $r[0]['v'])) ? unserialize($r[0]['v']) : $r[0]['v']);
}
return false;
}
static public function Set($chan,$xhash,$family,$key,$value) {
2016-06-08 01:17:39 +00:00
$dbvalue = ((is_array($value)) ? serialize($value) : $value);
$dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue);
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 {
$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),
dbesc($chan),
2016-06-08 01:17:39 +00:00
dbesc($xhash),
dbesc($family),
dbesc($key)
);
}
if($r)
return $value;
return false;
}
static public function Delete($chan,$xhash,$family,$key) {
2016-06-08 01:17:39 +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;
}
}