dir/mod/servers.php

130 lines
3.5 KiB
PHP
Raw Permalink Normal View History

<?php
use Friendica\Directory\Rendering\View;
require_once 'include/site-health.php';
2017-08-04 03:42:47 +02:00
function servers_content(&$a) {
$sites = array();
2017-04-21 04:03:34 +02:00
//Find the user count per site.
$r = q("SELECT `homepage` FROM `profile`");
if (count($r)) {
foreach ($r as $rr) {
$site = parse_site_from_url($rr['homepage']);
if ($site) {
2017-08-04 03:42:47 +02:00
if (!isset($sites[$site])) {
2017-04-21 04:03:34 +02:00
$sites[$site] = 0;
2017-08-04 03:42:47 +02:00
}
$sites[$site] ++;
}
}
}
2017-04-21 04:03:34 +02:00
//See if we have a health for them AND they provide SSL.
$sites_with_health = array();
$site_healths = array();
2017-04-21 04:03:34 +02:00
$r = q("SELECT * FROM `site-health` WHERE `reg_policy`='REGISTER_OPEN' AND `ssl_state` = 1");
if (count($r)) {
foreach ($r as $rr) {
2017-04-21 04:03:34 +02:00
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;
}
}
}
2017-04-21 04:03:34 +02:00
arsort($sites_with_health);
$total = 0;
$public_sites = array();
2017-04-21 04:03:34 +02:00
foreach ($sites_with_health as $k => $v) {
//Stop at unhealthy sites.
$site = $site_healths[$k];
2017-04-21 04:03:34 +02:00
if ($site['health_score'] <= 20) {
break;
}
2017-04-21 04:03:34 +02:00
//Skip small sites.
$users = $sites[$k];
if ($users < 5) {
continue;
}
2017-04-21 04:03:34 +02:00
//Add health score name and user count.
$site['health_score_name'] = health_score_to_name($site['health_score']);
$site['users'] = $users;
2017-04-21 04:03:34 +02:00
//Figure out what this server supports.
2018-02-24 16:45:54 +01:00
$addons = explode("\r\n", $site['addons']);
$site['addons'] = $addons;
$hasAddon = function (array $input) use ($addons) {
return !!count(array_intersect($input, $addons));
};
2017-04-21 04:03:34 +02:00
$site['supports'] = array(
'HTTPS' => $site['ssl_state'] == 1,
2018-02-24 16:45:54 +01:00
'Twitter' => $hasAddon(array('buffer', 'twitter')),
'Facebook' => $hasAddon(array('buffer')),
2018-05-04 14:12:08 +02:00
'Google+' => $hasAddon(array('buffer', 'fromgplus')),
'RSS/Atom' => true, //Built-in.
2018-02-24 16:45:54 +01:00
'Diaspora*' => $hasAddon(array('diaspora')),
'pump.io' => $hasAddon(array('pumpio')),
'StatusNet' => $hasAddon(array('statusnet')),
'Tumblr' => $hasAddon(array('tumblr')),
'Blogger' => $hasAddon(array('blogger')),
'Dreamwidth' => $hasAddon(array('dwpost')),
'Wordpress' => $hasAddon(array('wppost')),
'LiveJournal' => $hasAddon(array('ljpost')),
'Insanejournal' => $hasAddon(array('ijpost')),
'Libertree' => $hasAddon(array('libertree'))
);
2017-04-21 04:03:34 +02:00
//Subset of the full support list, to show popular items.
$site['popular_supports'] = array(
'HTTPS' => $site['supports']['HTTPS'],
'Twitter' => $site['supports']['Twitter'],
'Google+' => $site['supports']['Google+'],
'Wordpress' => $site['supports']['Wordpress']
);
2017-04-21 04:03:34 +02:00
//For practical usage.
$site['less_popular_supports'] = array_diff_assoc($site['supports'], $site['popular_supports']);
2017-04-21 04:03:34 +02:00
//Get the difference.
$site['supports_more'] = 0;
foreach ($site['supports'] as $key => $value) {
if ($value && !array_key_exists($key, $site['popular_supports'])) {
$site['supports_more'] ++;
}
}
2017-04-21 04:03:34 +02:00
//Push to results.
$public_sites[] = $site;
2017-04-21 04:03:34 +02:00
//Count the result.
$total ++;
}
2017-04-21 04:03:34 +02:00
//In case we asked for a surprise, pick a random one from the top 10! :D
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;
}
2017-04-21 04:03:34 +02:00
//Show results.
$view = new View('servers');
2017-04-21 04:03:34 +02:00
$view->output(array(
'total' => number_format($total),
'sites' => $public_sites
));
2017-04-21 04:03:34 +02:00
killme();
}