> This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ include_once('head.php'); include_once('db.php'); include_once('rpc.php'); // Get list of federated nodes $peers=Array(DOMAIN); $res=mysqli_query($db, 'select domain from peers where !blacklist'); while($row=mysqli_fetch_row($res)){$peers[]=$row[0];} $perpage=(isset($_GET['perpage'])?(int)$_GET['perpage']:20); $page=(int)(isset($_GET['page'])?$_GET['page']:0); $perpeer=round($perpage/count($peers)); $sortby=(isset($_GET['sort'])?$_GET['sort']:'new'); if($path[1]=='browse'){$sortby=$path[2];} // Handle 'Browse' links $res=rpc_search($peers, 'search/'.urlencode($_GET['q']).'/'.urlencode($sortby).'/'.$perpeer.'/'.($page*$perpage)); // Construct navigation links for pages $pagefull=false; foreach($res as $r){if(count($r)==$perpeer){$pagefull=true;}} $pagenav=''; $getvariables=''; foreach($_GET as $k=>$v) { if($k=='page'){continue;} $getvariables.=urlencode($k).'='.urlencode($v).'&'; } if($page>1){$pagenav.=''._('First page').'';} if($page>0){$pagenav.=''._('Previous page').'';} if($pagefull){$pagenav.=''._('Next page').'';} // Flatten the results into a single array with peer information for each item $results=Array(); foreach($res as $peer=>$res2) { if(isset($res2['error'])) { print('
'.$peer.': '.$res2['error'].'
'); continue; } foreach($res2 as $thing) { $thing['peer']=$peer; $results[]=$thing; } } function sortthings($a, $b) // Re-sort flattened results { global $sortby; // TODO: More sorting options? switch($sortby) { case 'alpha': return ord($a['name'])-ord($b['name']); case 'old': return strtotime($a['date'])-strtotime($b['date']); case 'new': default: return strtotime($b['date'])-strtotime($a['date']); } } usort($results, 'sortthings'); // Construct the results page $things=''; foreach($results as $thing) { $by=htmlentities($thing['by']['name']); $by=''.htmlentities($thing['by']['displayname']).''; $things.='
By '.$by.'
'.htmlentities($thing['name']).'
'; } ?>