aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorredmatrix <git@macgirvin.com>2016-02-16 18:15:19 -0800
committerredmatrix <git@macgirvin.com>2016-02-16 18:15:19 -0800
commit64f5d80ff2497edc5d201e9124cb6d98f72efe00 (patch)
tree58c0a693e64bdd70878ed157e0db6ab491bea5a6
parent679fb7d0d2ce56d1e67c9aa08441c95828d96463 (diff)
downloadvolse-hubzilla-64f5d80ff2497edc5d201e9124cb6d98f72efe00.tar.gz
volse-hubzilla-64f5d80ff2497edc5d201e9124cb6d98f72efe00.tar.bz2
volse-hubzilla-64f5d80ff2497edc5d201e9124cb6d98f72efe00.zip
some iconfig basics
-rwxr-xr-xinclude/items.php137
1 files changed, 137 insertions, 0 deletions
diff --git a/include/items.php b/include/items.php
index ab859bebd..3deb11640 100755
--- a/include/items.php
+++ b/include/items.php
@@ -4675,6 +4675,10 @@ function fetch_post_tags($items,$link = false) {
dbesc($tag_finder_str),
intval(TERM_OBJ_POST)
);
+ $imeta = q("select * from iconfig where iid in ( %s )",
+ dbesc($tag_finger_str)
+ );
+
}
for($x = 0; $x < count($items); $x ++) {
@@ -4698,6 +4702,26 @@ function fetch_post_tags($items,$link = false) {
}
}
}
+ if($imeta) {
+ foreach($imeta as $i) {
+ if(array_key_exists('item_id',$items[$x])) {
+ if($i['iid'] == $items[$x]['item_id']) {
+ if(! is_array($items[$x]['iconfig']))
+ $items[$x]['iconfig'] = array();
+ $i['v'] = ((preg_match('|^a:[0-9]+:{.*}$|s',$i['v'])) ? unserialize($i['v']) : $i['v']);
+ $items[$x]['iconfig'][] = $i;
+ }
+ }
+ else {
+ if($i['iid'] == $items[$x]['id']) {
+ if(! is_array($items[$x]['iconfig']))
+ $items[$x]['iconfig'] = array();
+ $i['v'] = ((preg_match('|^a:[0-9]+:{.*}$|s',$i['v'])) ? unserialize($i['v']) : $i['v']);
+ $items[$x]['iconfig'][] = $i;
+ }
+ }
+ }
+ }
}
return $items;
@@ -5360,3 +5384,116 @@ function send_profile_photo_activity($channel,$photo,$profile) {
}
+
+
+
+
+function get_iconfig(&$item, $family, $key) {
+
+ $is_item = false;
+ if(is_array($item)) {
+ $is_item = true;
+ if((! array_key_exists('iconfig',$item)) || (! is_array($item['iconfig'])))
+ $item['iconfig'] = array();
+
+ if(array_key_exists('item_id',$item))
+ $iid = $item['item_id'];
+ else
+ $iid = $item['id'];
+ }
+ elseif(intval($item))
+ $iid = $item;
+
+ if(! $iid)
+ return false;
+
+ if(is_array($item) && array_key_exists('iconfig',$item) && is_array($item['iconfig'])) {
+ foreach($item['iconfig'] as $c) {
+ if($c['iid'] == $iid && $c['cat'] == $family && $c['k'] == $key)
+ return $c['v'];
+ }
+ }
+
+ $r = q("select * from iconfig where iid = %d and cat = '%s' and k = '%s' limit 1",
+ intval($iid),
+ dbesc($family),
+ dbesc($key)
+ );
+ if($r) {
+ $v = ((preg_match('|^a:[0-9]+:{.*}$|s',$r[0]['v'])) ? unserialize($r[0]['v']) : $r[0]['v']);
+ if($is_item)
+ $item['iconfig'][] = $r[0];
+ return $v;
+ }
+ return false;
+
+}
+
+
+function set_iconfig(&$item, $family, $key, $value) {
+
+ $dbvalue = ((is_array($value)) ? serialize($value) : $value);
+ $dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue);
+
+ $is_item = false;
+ $idx = null;
+
+ if(is_array($item)) {
+ $is_item = true;
+ if((! array_key_exists('iconfig',$item)) || (! is_array($item['iconfig'])))
+ $item['iconfig'] = array();
+ elseif($item['iconfig']) {
+ for($x = 0; $x < count($item['iconfig']); $x ++) {
+ if($item['iconfig'][$x]['cat'] == $family && $item['iconfig']['k'] == $key) {
+ $idx = $x;
+ }
+ }
+ }
+ if(array_key_exists('item_id',$item))
+ $iid = $item['item_id'];
+ else
+ $iid = $item['id'];
+ }
+ elseif(intval($item))
+ $iid = $item;
+
+ if(! $iid)
+ return false;
+
+ if(get_iconfig($item, $family, $key) === false) {
+ $r = q("insert into iconfig( iid, cat, k, v ) values ( %d, '%s', '%s', '%s' ) ",
+ intval($iid),
+ dbesc($family),
+ dbesc($key),
+ dbesc($dbvalue)
+ );
+ }
+ else {
+ $r = q("update iconfig set v = '%s' where iid = %d and cat = '%s' and k = '%s' ",
+ dbesc($dbvalue),
+ intval($iid),
+ dbesc($family),
+ dbesc($key)
+ );
+ }
+
+ $y = q("select * from iconfig where iid = %d and cat = '%s' and k = '%s' limit 1",
+ intval($iid),
+ dbesc($family),
+ dbesc($key)
+ );
+ if(! $y)
+ return false;
+
+ $y[0]['v'] = $value;
+
+ if($is_item) {
+ if(is_null($idx))
+ $item['iconfig'][] = $y[0];
+ else
+ $item['iconfig'][$idx] = $y[0];
+ }
+
+ return $value;
+}
+