diff --git a/mod/servers.php b/mod/servers.php index a1e42b04..f2ebda74 100644 --- a/mod/servers.php +++ b/mod/servers.php @@ -5,9 +5,9 @@ use Friendica\Directory\Rendering\View; require_once('include/site-health.php'); function servers_content(&$a) { - + $sites = array(); - + //Find the user count per site. $r = q("SELECT `homepage` FROM `profile`"); if(count($r)) { @@ -15,50 +15,52 @@ function servers_content(&$a) { $site = parse_site_from_url($rr['homepage']); if($site) { if(!isset($sites[$site])) - $sites[$site] = 0; + $sites[$site] = 0; $sites[$site] ++; } } } - + //See if we have a health for them AND they provide SSL. $sites_with_health = array(); $site_healths = array(); - + $r = q("SELECT * FROM `site-health` WHERE `reg_policy`='REGISTER_OPEN' AND `ssl_state` = 1"); if(count($r)) { foreach($r as $rr) { - $sites_with_health[$rr['base_url']] = (($sites[$rr['base_url']] / 100) + 10) * intval($rr['health_score']); - $site_healths[$rr['base_url']] = $rr; + if (isset($sites[$rr['base_url']])) { + $sites_with_health[$rr['base_url']] = (($sites[$rr['base_url']] / 100) + 10) * intval($rr['health_score']); + $site_healths[$rr['base_url']] = $rr; + } } } - + arsort($sites_with_health); $total = 0; $public_sites = array(); foreach($sites_with_health as $k => $v) { - + //Stop at unhealthy sites. $site = $site_healths[$k]; - + if($site['health_score'] <= 20) break; - + //Skip small sites. $users = $sites[$k]; if($users < 5) continue; - + //Add health score name and user count. $site['health_score_name'] = health_score_to_name($site['health_score']); $site['users'] = $users; - + //Figure out what this server supports. $plugins = explode("\r\n", $site['plugins']); $site['plugins'] = $plugins; $hasPlugin = function(array $input)use($plugins){ return !!count(array_intersect($input, $plugins)); }; - + $site['supports'] = array( 'HTTPS' => $site['ssl_state'] == 1, 'Twitter' => $hasPlugin(array('buffer', 'twitter')), @@ -76,7 +78,7 @@ function servers_content(&$a) { 'Insanejournal' => $hasPlugin(array('ijpost')), 'Libertree' => $hasPlugin(array('libertree')) ); - + //Subset of the full support list, to show popular items. $site['popular_supports'] = array( 'HTTPS' => $site['supports']['HTTPS'], @@ -84,10 +86,10 @@ function servers_content(&$a) { 'Google+' => $site['supports']['Google+'], 'Wordpress' => $site['supports']['Wordpress'] ); - + //For practical usage. $site['less_popular_supports'] = array_diff_assoc($site['supports'], $site['popular_supports']); - + //Get the difference. $site['supports_more'] = 0; foreach ($site['supports'] as $key => $value){ @@ -95,31 +97,31 @@ function servers_content(&$a) { $site['supports_more']++; } } - + //Push to results. $public_sites[] = $site; - + //Count the result. $total ++; - + } - + //In case we asked for a surprise, pick a random one from the top 10! :D - if($a->argv[1] == 'surprise'){ + if($a->argc > 1 && $a->argv[1] == 'surprise'){ $max = min(count($public_sites), 10); $i = mt_rand(0, $max-1); $surpriseSite = $public_sites[$i]; header('Location:'.$surpriseSite['base_url'].'/register'); exit; } - - + + //Show results. $view = new View('servers'); - + $view->output(array( 'total' => number_format($total), 'sites' => $public_sites )); - + } diff --git a/src/templates/layout/_searcher.php b/src/templates/layout/_searcher.php index 39f75f0d..a67c1f5e 100644 --- a/src/templates/layout/_searcher.php +++ b/src/templates/layout/_searcher.php @@ -1,6 +1,6 @@
- +