diff options
author | Wave <wave72@users.noreply.github.com> | 2016-07-22 10:55:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-22 10:55:02 +0200 |
commit | 744ad84714fe0f7a3d90250a4ff02dc4327b9061 (patch) | |
tree | 595fb74ec9ea0bc7130d18bd7993d719a222d343 /Zotlabs/Lib/AbConfig.php | |
parent | c38c79d71c8ef70ef649f83e322f1984b75ee2dd (diff) | |
parent | 7d897a3f03bd57ed556433eb84a41963ba44e02e (diff) | |
download | volse-hubzilla-744ad84714fe0f7a3d90250a4ff02dc4327b9061.tar.gz volse-hubzilla-744ad84714fe0f7a3d90250a4ff02dc4327b9061.tar.bz2 volse-hubzilla-744ad84714fe0f7a3d90250a4ff02dc4327b9061.zip |
Merge pull request #6 from redmatrix/dev
Dev
Diffstat (limited to 'Zotlabs/Lib/AbConfig.php')
-rw-r--r-- | Zotlabs/Lib/AbConfig.php | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/Zotlabs/Lib/AbConfig.php b/Zotlabs/Lib/AbConfig.php new file mode 100644 index 000000000..cb5d96951 --- /dev/null +++ b/Zotlabs/Lib/AbConfig.php @@ -0,0 +1,75 @@ +<?php + +namespace Zotlabs\Lib; + + +class AbConfig { + + static public 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; + } + + + 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), + 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) { + + $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), + 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) + ); + } + + if($r) + return $value; + return false; + } + + + static public function Delete($chan,$xhash,$family,$key) { + + $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) + ); + + return $r; + } + +} |