streams/Code/Lib/AbConfig.php

85 lines
2.1 KiB
PHP
Raw Normal View History

2016-06-08 01:17:39 +00:00
<?php
2022-02-16 04:08:28 +00:00
namespace Code\Lib;
2016-06-08 01:17:39 +00:00
2021-12-03 03:01:39 +00:00
class AbConfig
{
2016-06-08 01:17:39 +00:00
2021-12-03 03:01:39 +00:00
public static function Load($chan, $xhash, $family = '')
{
if ($family) {
$where = sprintf(" and cat = '%s' ", dbesc($family));
}
$r = q(
"select * from abconfig where chan = %d and xchan = '%s' $where",
intval($chan),
dbesc($xhash)
);
return $r;
}
2016-06-08 01:17:39 +00:00
2021-12-03 03:01:39 +00:00
public static function Get($chan, $xhash, $family, $key, $default = false)
{
$r = q(
"select * from abconfig where chan = %d and xchan = '%s' and cat = '%s' and k = '%s' limit 1",
intval($chan),
dbesc($xhash),
dbesc($family),
dbesc($key)
);
if ($r) {
return unserialise($r[0]['v']);
}
return $default;
}
2016-06-08 01:17:39 +00:00
2021-12-03 03:01:39 +00:00
public static function Set($chan, $xhash, $family, $key, $value)
{
2016-06-08 01:17:39 +00:00
2021-12-03 03:01:39 +00:00
$dbvalue = ((is_array($value)) ? serialise($value) : $value);
$dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue);
2016-06-08 01:17:39 +00:00
2021-12-03 03:01:39 +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),
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' ",
dbesc($dbvalue),
dbesc($chan),
dbesc($xhash),
dbesc($family),
dbesc($key)
);
}
2016-06-08 01:17:39 +00:00
2021-12-03 03:01:39 +00:00
if ($r) {
return $value;
}
return false;
}
2016-06-08 01:17:39 +00:00
2021-12-03 03:01:39 +00:00
public static function Delete($chan, $xhash, $family, $key)
{
2016-06-08 01:17:39 +00:00
2021-12-03 03:01:39 +00:00
$r = q(
"delete from abconfig where chan = %d and xchan = '%s' and cat = '%s' and k = '%s' ",
intval($chan),
dbesc($xhash),
dbesc($family),
dbesc($key)
);
2016-06-08 01:17:39 +00:00
2021-12-03 03:01:39 +00:00
return $r;
}
}