tabledata.php 9.26 KB
Newer Older
dmorley's avatar
dmorley committed
1 2 3 4 5 6 7 8 9 10 11 12
<?php

/**
 * get data for showfull.php calls.
 */

declare(strict_types=1);

use Carbon\Carbon;
use Poduptime\PodStatus;
use RedBeanPHP\R;

13
require_once __DIR__ . '/boot.php';
dmorley's avatar
dmorley committed
14

15 16
$iso = new Matriphe\ISO639\ISO639;

dmorley's avatar
dmorley committed
17 18
$hiddensoftwares = c('hidden-softwares');

dmorley's avatar
dmorley committed
19 20
try {
    $pods = R::getAll('
dmorley's avatar
dmorley committed
21
        SELECT domain, dnssec, podmin_statement, sslexpire, masterversion, shortversion, softwarename, daysmonitored, monthsmonitored, score, signup, protocols, name, country, countryname, city, state, detectedlanguage, uptime_alltime, active_users_halfyear, active_users_monthly, services, service_xmpp, latency, date_updated, ipv6, total_users, local_posts, comment_counts, userrating, status
dmorley's avatar
dmorley committed
22
        FROM pods
dmorley's avatar
dmorley committed
23 24
        WHERE status < ? 
        AND score > 0
dmorley's avatar
dmorley committed
25
        AND softwarename NOT SIMILAR TO ?
dmorley's avatar
dmorley committed
26
        ORDER BY weightedscore DESC
dmorley's avatar
dmorley committed
27
    ', [PodStatus::RECHECK, $hiddensoftwares]);
dmorley's avatar
dmorley committed
28 29 30 31 32 33 34 35 36 37 38 39
} catch (\RedBeanPHP\RedException $e) {
    die('Error in SQL query: ' . $e->getMessage());
}

// CloudFlare country code pull.
$country_code = $_SERVER['HTTP_CF_IPCOUNTRY'] ?? '';

foreach ($pods as $pod) {
    $humanmonitored = Carbon::now()->subDays($pod['daysmonitored'])->diffForHumans(null, true);
    $tip            = "Over the last {$humanmonitored} uptime was {$pod['uptime_alltime']}% and response time from Los Angeles was {$pod['latency']}ms.";

    if (($_COOKIE['domain'] ?? null) === $pod['domain']) {
40
        echo '<tr><td title="This is the last pod you visited from this site. ' . $tip . '" data-placement="right" data-toggle="tooltip" class="bg-blue"><a class="text-white url" target="_pod" href="/go.php?domain=' . $pod['domain'] . '">' . $pod['domain'] . '</a></td>';
dmorley's avatar
dmorley committed
41
    } else {
42
        echo '<tr><td data-placement="right" title="' . $tip . '" data-toggle="tooltip"><a class="url" target="_pod" href="/go.php?domain=' . $pod['domain'] . '">' . $pod['domain'] . '</a></td>';
dmorley's avatar
dmorley committed
43 44 45 46 47 48 49 50 51 52 53 54 55
    }

    if ($pod['shortversion'] > $pod['masterversion']) {
        $version = $pod['shortversion'];
        $pre     = 'This pod runs pre release development code';
    } elseif (!$pod['shortversion']) {
        $version = '';
        $pre     = 'This pod runs unknown code';
    } else {
        $version = $pod['shortversion'];
        $pre     = 'This pod runs production code';
    }

56
    $classver = 'green';
dmorley's avatar
dmorley committed
57
    if (version_compare($pod['shortversion'] ?? '', $pod['masterversion'] ?? '', '=')) {
58
        $classver = 'black';
dmorley's avatar
dmorley committed
59
    } elseif (version_compare($pod['shortversion'] ?? '', $pod['masterversion'] ?? '', '<')) {
60
        $classver = 'text-danger';
dmorley's avatar
dmorley committed
61 62
    }
    echo '<td>' . $pod['name'] . '</td>';
dmorley's avatar
dmorley committed
63 64
    $lastupdated = ($pod['date_updated'] ? Carbon::createFromFormat('Y-m-d H:i:s.u', $pod['date_updated'])->diffForHumans() : 'unknown');
    echo '<td class="' . $classver . '"><div title="' . $pre . ' version: ' . $pod['shortversion'] . ' master version is: ' . ($pod['masterversion'] ?: 'unknown') . ' pod code was last updated: ' . $lastupdated . '" data-toggle="tooltip">' . $version . '</div></td>';
dmorley's avatar
dmorley committed
65
    echo '<td>' . $pod['softwarename'] . '</td>';
dmorley's avatar
dmorley committed
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95

    $protocols = json_decode($pod['protocols'] ?? '[]') ?: [];
    //<i class="fa fa-camera-retro"></i>
    $protocols_list = [
        'diaspora'    => ['class' => 'fa fa-diaspora', 'title' => 'Diaspora'],
        'ostatus'     => ['class' => 'fa fa-genderless', 'title' => 'Ostatus'],
        'activitypub' => ['class' => 'fa fa-activitypub', 'title' => 'Activitypub'],
        'zot'         => ['class' => 'fa fa-hubzilla', 'title' => 'Zot'],
        'dfrn'        => ['class' => 'fa fa-friendica', 'title' => 'dfrn'],
        'matrix'      => ['class' => 'fa fa-matrix-org', 'title' => 'matrix'],
        'webmention'  => ['class' => 'fa fa-wikipedia-w', 'title' => 'webmention'],
        'smtp'        => ['class' => 'fa fa-envelope-o', 'title' => 'smtp'],
        'xmpp'        => ['class' => 'fa fa-xmpp', 'title' => 'xmpp'],
    ];
    echo '<td class="text-truncate">';
    foreach ($protocols as $protocol) {
        // Make sure we have this protocol in the list.
        if (!isset($protocols_list[$protocol])) {
            debugToConsole($protocol);
            continue;
        }

        printf(
            '<div class="smlogo mr-sm-1 %1$s" title="%2$s" data-toggle="tooltip"><div class="hidden">%3$s</div></div>',
            $protocols_list[$protocol]['class'],
            $protocols_list[$protocol]['title'],
            $protocol
        );
    }
    echo '</td>';
dmorley's avatar
dmorley committed
96
    echo '<td><a href="#" class="green" data-featherlight-variant="table-responsive" data-featherlight="podstat-uptime.php?domain=' . $pod['domain'] . '">' . ($pod['uptime_alltime'] > 0 ? $pod['uptime_alltime'] . '%' : '') . '</a></td>';
97
    echo '<td>' . ($pod['ipv6'] ? 'Yes' : 'No') . '</td>';
dmorley's avatar
dmorley committed
98
    echo '<td>' . ($pod['latency'] > 0 ? $pod['latency'] : '') . '</td>';
99
    echo '<td>' . ($pod['signup'] ? 'Yes' : 'No') . '</td>';
dmorley's avatar
dmorley committed
100
    echo '<td><a href="#" class="green" data-featherlight-variant="table-responsive" data-featherlight="podstat-counts.php?domain=' . $pod['domain'] . '">' . ($pod['total_users'] > 0 ? $pod['total_users'] : '') . '</a></td>';
dmorley's avatar
dmorley committed
101 102 103 104 105 106 107 108
    echo '<td>' . ($pod['active_users_halfyear'] > 0 ? $pod['active_users_halfyear'] : '') . '</td>';
    echo '<td>' . ($pod['active_users_monthly'] > 0 ? $pod['active_users_monthly'] : '') . '</td>';
    echo '<td>' . ($pod['local_posts'] > 0 ? $pod['local_posts'] : '') . '</td>';
    echo '<td>' . ($pod['comment_counts'] > 0 ? $pod['comment_counts'] : '') . '</td>';
    echo '<td><div title="This pod has been monitored ' . $humanmonitored . '" data-toggle="tooltip">' . $pod['monthsmonitored'] . '</div></td>';
    echo '<td><a href="#" data-featherlight-variant="table-responsive" data-featherlight="rate.php?domain=' . $pod['domain'] . '">' . $pod['userrating'] . '</a></td>';
    echo '<td><div>' . $pod['score'] . '</div></td>';
    echo '<td><div>' . PodStatus::getKey((int) $pod['status']) . '</div></td>';
109
    echo '<td>' . ($pod['dnssec'] ? 'Yes' : 'No') . '</td>';
dmorley's avatar
dmorley committed
110 111 112
    if ($country_code === $pod['country']) {
        echo '<td class="text-success" data-toggle="tooltip" title="Country: ' . ($pod['countryname'] ?? 'n/a') . ' City: ' . ($pod['city'] ?? 'n/a') . ' State: ' . ($pod['state'] ?? 'n/a') . '"><b>' . $pod['country'] . '</b></td>';
    } else {
noplanman's avatar
noplanman committed
113
        echo '<td data-toggle="tooltip" title="Country: ' . ($pod['countryname'] ?? 'n/a') . ' City: ' . ($pod['city'] ?? 'n/a') . ' State: ' . ($pod['state'] ?? 'n/a') . '">' . $pod['country'] . '</td>';
dmorley's avatar
dmorley committed
114 115 116
    }
    echo '<td>' . $pod['city'] . '</td>';
    echo '<td>' . $pod['state'] . '</td>';
117
    echo '<td data-toggle="tooltip" title="' . ($pod['detectedlanguage'] ? $iso->languageByCode1($pod['detectedlanguage']) : '') . '">' . ($pod['detectedlanguage'] ? strtoupper($pod['detectedlanguage']) : '') . '</td>';
118 119 120 121 122 123 124

    $services = json_decode($pod['services'] ?? '[]') ?: [];

    // Special case for XMPP, which is not an official service, but listed in the same cell.
    ($pod['service_xmpp'] ?? false) && $services[] = 'xmpp';

    $services_list = [
dmorley's avatar
dmorley committed
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
        'facebook'    => ['class' => 'fa fa-facebook', 'title' => 'Publish to Facebook'],
        'twitter'     => ['class' => 'fa fa-twitter', 'title' => 'Publish to Twitter'],
        'tumblr'      => ['class' => 'fa fa-tumblr', 'title' => 'Publish to Tumblr'],
        'wordpress'   => ['class' => 'fa fa-wordpress', 'title' => 'Publish to WordPress'],
        'xmpp'        => ['class' => 'fa fa-xmpp', 'title' => 'XMPP chat server'],
        'atom1.0'     => ['class' => 'fa fa-rss-square', 'title' => 'Publish to Atom'],
        'rss2.0'      => ['class' => 'fa fa-rss', 'title' => 'Publish to RSS'],
        'blogger'     => ['class' => 'fa fa-bold', 'title' => 'Publish to Blogger'],
        'gnusocial'   => ['class' => 'fa fa-gnu-social', 'title' => 'Publish to GNUSocial'],
        'google'      => ['class' => 'fa fa-google-plus', 'title' => 'Publish to Google+'],
        'libertree'   => ['class' => 'fa fa-tree', 'title' => 'Publish to Libertree'],
        'medium'      => ['class' => 'fa fa-medium', 'title' => 'Publish to Medium'],
        'linkedin'    => ['class' => 'fa fa-linkedin', 'title' => 'Publish to LinkedIn'],
        'livejournal' => ['class' => 'fa fa-book', 'title' => 'Publish to Live Journal'],
        'pinterest'   => ['class' => 'fa fa-pinterest', 'title' => 'Publish to Pinterest'],
        'friendica'   => ['class' => 'fa fa-friendica', 'title' => 'Publish to Friendica'],
        'mastodon'    => ['class' => 'fa fa-mastodon', 'title' => 'Publish to Mastodon'],
        'smtp'        => ['class' => 'fa fa-envelope-o', 'title' => 'smtp'],
        'pumpio'      => ['class' => 'fa fa-chevron-circle-right', 'title' => 'Publish to Pump.io'],
144 145
    ];

dmorley's avatar
dmorley committed
146
    echo '<td class="text-truncate">';
147 148 149
    foreach ($services as $service) {
        // Make sure we have this service in the list.
        if (!isset($services_list[$service])) {
dmorley's avatar
dmorley committed
150
            debugToConsole($service);
151 152
            continue;
        }
153

154
        printf(
dmorley's avatar
dmorley committed
155 156
            '<div class="smlogo mr-sm-1 %1$s" data-toggle="tooltip" title="%2$s"><div class="hidden">%3$s</div></div>',
            $services_list[$service]['class'],
157 158
            $services_list[$service]['title'],
            $service
159
        );
160
    }
dmorley's avatar
dmorley committed
161 162 163 164
    echo '</td>';
    $podmin_statement = htmlentities($pod['podmin_statement'] ?? '', ENT_QUOTES);
    echo '<td>' . ($podmin_statement ? '<a href="#" data-featherlight="<p>' . $podmin_statement . '</p>">&#128172;</a>' : '&nbsp;') . '</td></tr>';
}