tabledata.php 7.19 KB
Newer Older
David Morley's avatar
David Morley 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';
David Morley's avatar
David Morley committed
14

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

David Morley's avatar
David Morley committed
17 18
try {
    $pods = R::getAll('
19
        SELECT domain, dnssec, podmin_statement, sslexpire, masterversion, shortversion, softwarename, daysmonitored, monthsmonitored, score, signup, 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
David Morley's avatar
David Morley committed
20
        FROM pods
David Morley's avatar
David Morley committed
21 22
        WHERE status < ? 
        AND score > 0
David Morley's avatar
David Morley committed
23
        ORDER BY weightedscore DESC
David Morley's avatar
David Morley committed
24
    ', [PodStatus::RECHECK]);
David Morley's avatar
David Morley committed
25 26 27 28 29 30 31 32 33 34 35 36
} 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']) {
37
        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>';
David Morley's avatar
David Morley committed
38
    } else {
39
        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>';
David Morley's avatar
David Morley committed
40 41 42 43 44 45 46 47 48 49 50 51 52
    }

    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';
    }

53
    $classver = 'green';
David Morley's avatar
David Morley committed
54
    if (version_compare($pod['shortversion'] ?? '', $pod['masterversion'] ?? '', '=')) {
55
        $classver = 'black';
David Morley's avatar
David Morley committed
56
    } elseif (version_compare($pod['shortversion'] ?? '', $pod['masterversion'] ?? '', '<')) {
57
        $classver = 'text-danger';
David Morley's avatar
David Morley committed
58 59 60 61 62
    }
    echo '<td>' . $pod['name'] . '</td>';
    echo '<td class="' . $classver . '"><div title="' . $pre . ' version: ' . $pod['shortversion'] . ' master version is: ' . ($pod['masterversion'] ?: 'unknown') . '" data-toggle="tooltip">' . $version . '</div></td>';
    echo '<td>' . $pod['softwarename'] . '</td>';
    echo '<td><a href="#" data-featherlight-variant="table-responsive" data-featherlight="podstat-uptime.php?domain=' . $pod['domain'] . '">' . ($pod['uptime_alltime'] > 0 ? $pod['uptime_alltime'] . '%' : '') . '</a></td>';
63
    echo '<td>' . ($pod['ipv6'] ? 'Yes' : 'No') . '</td>';
David Morley's avatar
David Morley committed
64
    echo '<td>' . ($pod['latency'] > 0 ? $pod['latency'] : '') . '</td>';
65
    echo '<td>' . ($pod['signup'] ? 'Yes' : 'No') . '</td>';
David Morley's avatar
David Morley committed
66 67 68 69 70 71 72 73 74
    echo '<td><a href="#" data-featherlight-variant="table-responsive" data-featherlight="podstat-counts.php?domain=' . $pod['domain'] . '">' . ($pod['total_users'] > 0 ? $pod['total_users'] : '') . '</a></td>';
    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>';
75
    echo '<td>' . ($pod['dnssec'] ? 'Yes' : 'No') . '</td>';
David Morley's avatar
David Morley committed
76 77 78
    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 {
79
        echo '<td data-toggle="tooltip" title="Country: ' . ($pod['countryname'] ?? 'n/a') . ' City: ' . ($pod['city'] ?? 'n/a') . ' State: ' . ($pod['state'] ?? 'n/a') . '">' . $pod['country'] . '</td>';
David Morley's avatar
David Morley committed
80 81 82
    }
    echo '<td>' . $pod['city'] . '</td>';
    echo '<td>' . $pod['state'] . '</td>';
83
    echo '<td data-toggle="tooltip" title="' . ($pod['detectedlanguage'] ? $iso->languageByCode1($pod['detectedlanguage']) : '') . '">' . ($pod['detectedlanguage'] ? strtoupper($pod['detectedlanguage']) : '') . '</td>';
84 85 86 87 88 89 90

    $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 = [
91
        'facebook'    => ['fa' => 'fab fa-facebook-f', 'title' => 'Publish to Facebook'],
David Morley's avatar
David Morley committed
92 93
        'twitter'     => ['fa' => 'fab fa-twitter', 'title' => 'Publish to Twitter'],
        'tumblr'      => ['fa' => 'fab fa-tumblr', 'title' => 'Publish to Tumblr'],
David Morley's avatar
David Morley committed
94
        'wordpress'   => ['fa' => 'fab fa-wordpress-simple', 'title' => 'Publish to WordPress'],
95 96 97 98 99 100 101 102 103 104 105
        'xmpp'        => ['fa' => 'fas fa-comments', 'title' => 'XMPP chat server'],
        'appnet'      => ['fa' => 'fas fa-th', 'title' => 'Publish to App.net'],
        'atom1.0'     => ['fa' => 'fas fa-rss', 'title' => 'Publish to Atom'],
        'blogger'     => ['fa' => 'fab fa-blogger-b', 'title' => 'Publish to Blogger'],
        'gnusocial'   => ['fa' => 'fab fa-grunt', 'title' => 'Publish to GNUSocial'],
        'google'      => ['fa' => 'fab fa-google', 'title' => 'Publish to Google+'],
        'libertree'   => ['fa' => 'fas fa-tree', 'title' => 'Publish to Libertree'],
        'linkedin'    => ['fa' => 'fab fa-linkedin-in', 'title' => 'Publish to LinkedIn'],
        'livejournal' => ['fa' => 'fas fa-pencil-alt', 'title' => 'Publish to Live Journal'],
        'pinterest'   => ['fa' => 'fab fa-pinterest-p', 'title' => 'Publish to Pinterest'],
        'pumpio'      => ['fa' => 'fas fa-greater-than', 'title' => 'Publish to Pump.io'],
106 107
    ];

David Morley's avatar
David Morley committed
108
    echo '<td class="text-truncate">';
109 110 111 112 113
    foreach ($services as $service) {
        // Make sure we have this service in the list.
        if (!isset($services_list[$service])) {
            continue;
        }
114

115
        printf(
116 117 118 119
            '<div class="smlogo mr-sm-1"><i class="%1$s" data-toggle="tooltip" title="%2$s"></i><div class="hidden">%3$s</div></div>',
            $services_list[$service]['fa'],
            $services_list[$service]['title'],
            $service
120
        );
121
    }
David Morley's avatar
David Morley committed
122 123 124 125
    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>';
}