Fix yet more PHP Notices

This commit is contained in:
Hypolite Petovan 2017-04-20 22:03:34 -04:00
parent 783c15c207
commit 280d55f183
2 changed files with 29 additions and 27 deletions

View file

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

View file

@ -1,6 +1,6 @@
<form action="/search" method="get" class="search-form"> <form action="/search" method="get" class="search-form">
<div class="search-wrapper"> <div class="search-wrapper">
<input class="search-field" type="text" name="query" placeholder="Search your friends" tabindex="1" value="<?php echo $query; ?>" /> <input class="search-field" type="text" name="query" placeholder="Search your friends" tabindex="1" value="<?php echo isset($query)? $query : ''; ?>" />
<input class="reset" type="reset" value="&#xf00d;" tabindex="3" /> <input class="reset" type="reset" value="&#xf00d;" tabindex="3" />
<input class="search" type="submit" value="Search" tabindex="2" /> <input class="search" type="submit" value="Search" tabindex="2" />
</div> </div>