aboutsummaryrefslogtreecommitdiffstats
path: root/include/conversation.php
diff options
context:
space:
mode:
authorFabio Comuni <fabrix.xm@gmail.com>2012-01-03 21:14:48 +0100
committerFabio Comuni <fabrix.xm@gmail.com>2012-01-03 21:14:48 +0100
commit93563370c96848948d28ed39e13284ebaf7f430a (patch)
tree701c29133372625f54a098026d8570f191727a24 /include/conversation.php
parentbe2fd56aae51ee02b6e40dedd4383e1ebddc752e (diff)
parent184230e06826117b1d87241e3acdf19935470e8f (diff)
downloadvolse-hubzilla-93563370c96848948d28ed39e13284ebaf7f430a.tar.gz
volse-hubzilla-93563370c96848948d28ed39e13284ebaf7f430a.tar.bz2
volse-hubzilla-93563370c96848948d28ed39e13284ebaf7f430a.zip
Merge remote-tracking branch 'friendica/master'
Diffstat (limited to 'include/conversation.php')
-rw-r--r--include/conversation.php60
1 files changed, 60 insertions, 0 deletions
diff --git a/include/conversation.php b/include/conversation.php
index f4dd01dde..26430d645 100644
--- a/include/conversation.php
+++ b/include/conversation.php
@@ -892,3 +892,63 @@ function status_editor($a,$x, $notes_cid = 0) {
return $o;
}
+
+
+function conv_sort($arr,$order) {
+
+ if((!(is_array($arr) && count($arr))))
+ return array();
+
+ $parents = array();
+
+ foreach($arr as $x)
+ if($x['id'] == $x['parent'])
+ $parents[] = $x;
+
+ if(stristr($order,'created'))
+ usort($parents,'sort_thr_created');
+ elseif(stristr($order,'commented'))
+ usort($parents,'sort_thr_commented');
+
+ foreach($parents as $x)
+ $x['children'] = array();
+
+ foreach($arr as $x) {
+ if($x['id'] != $x['parent']) {
+ $p = find_thread_parent_index($parents,$x);
+ $parents[$p]['children'][] = $x;
+ }
+ }
+ foreach($parents as $x)
+ if(count($x['children']))
+ usort($x['children'],'sort_thr_created_rev');
+
+ $ret = array();
+ foreach($parents as $x) {
+ $ret[] = $x;
+ if(count($x['children']))
+ foreach($x['children'] as $y)
+ $ret[] = $y;
+ }
+
+ return $ret;
+}
+
+
+function sort_thr_created($a,$b) {
+ return strcmp($b['created'],$a['created']);
+}
+
+function sort_thr_created_rev($a,$b) {
+ return strcmp($a['created'],$b['created']);
+}
+
+function sort_thr_commented($a,$b) {
+ return strcmp($b['commented'],$a['commented']);
+}
+
+function find_thread_parent_index($arr,$x) {
+ foreach($arr as $k => $v)
+ if($v['id'] == $x['parent'])
+ return $k;
+}