From: Fabio Comuni Date: Tue, 3 Jan 2012 20:14:48 +0000 (+0100) Subject: Merge remote-tracking branch 'friendica/master' X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=93563370c96848948d28ed39e13284ebaf7f430a;p=friendica.git Merge remote-tracking branch 'friendica/master' --- 93563370c96848948d28ed39e13284ebaf7f430a diff --cc include/conversation.php index f4dd01ddeb,f4432bfd97..26430d645c --- a/include/conversation.php +++ b/include/conversation.php @@@ -892,3 -884,63 +892,63 @@@ function status_editor($a,$x, $notes_ci 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; -} ++}