Skip to content
index.php 5.55 KiB
Newer Older
klimplant's avatar
klimplant committed
<?php

require 'functions.php';
klimplant's avatar
klimplant committed
require 'cache.php';
klimplant's avatar
klimplant committed
// ---------------------------------------------------------
// Some global definitions that can be reused multiple times
// ---------------------------------------------------------
realitygaps's avatar
realitygaps committed
define('pagetitle', 'libreho.st - the librehosters directory');
klimplant's avatar
klimplant committed
define('debug', false); // may be used during dev, recomended in prod: false
define('useCache', true); // may be used during dev, recomended in prod: true
klimplant's avatar
klimplant committed
// Configuration
$directoryFile = [
    'src' => 'https://libreho.st/directory.json', // either url or path relative to script
    'srcType' => 'url', // path or url
];
// ---------------------------------------------------------

if (debug) {
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);
}
klimplant's avatar
klimplant committed

klimplant's avatar
klimplant committed
$hosts = getCache('hosts');
$recache = !is_array($hosts) || !useCache;

if ($recache) {
klimplant's avatar
klimplant committed

    $directory = getDirFile($directoryFile);
    if (!is_array($directory)) {
        http_response_code(500);
        die();
    }

klimplant's avatar
klimplant committed
    if (debug) {
        echo "recached: " . __FILE__ . ":". __LINE__  . " \n<br>";
    }
    resetCache();

    $hosts = [];
    $cacheData = [];

    foreach ($directory as $librehostJsonUrl) {
        $hostInformation = getHostInformation($librehostJsonUrl);
        $hosts[] = $hostInformation;
    }

    $cacheData['hosts'] = $hosts;
    writeCache($cacheData);
} elseif (debug) {
    echo "Cache is valid";
}

klimplant's avatar
klimplant committed
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>
        <?php echo pagetitle; ?>
    </title>
    <link rel="stylesheet" href="bootstrap.min.css">
    <link rel="stylesheet" href="custom.css">
</head>

<body>
    <div class="container">
realitygaps's avatar
realitygaps committed
        <div id="header-container">      
 	<h1 class="text-center">
klimplant's avatar
klimplant committed
            <?php echo pagetitle; ?>
realitygaps's avatar
realitygaps committed
	</h1>
        </div>
klimplant's avatar
klimplant committed
        <br>
        <div class="row">
                <?php
                shuffle($hosts);
klimplant's avatar
klimplant committed
                foreach ($hosts as $hostInformation) {
klimplant's avatar
klimplant committed
                    ?>
                    <div class="col-sm-12 col-md-4 col-lg-3">
                        <div class="card">
                            <div class="card-header">
                                <h4> <?php echo $hostInformation['name'] ?> </h4>
                                <div class="text-muted"> <?php echo $hostInformation['organizationType'] ?> </div>
                            </div>
                            <div class="card-body">
                                <div class="card-text">
                                    <h5><?php echo $hostInformation['tagLine'] ?></h5>
                                    <?php echo $hostInformation['description'] ?>
                                    <br>
                                    <?php
                                    foreach($hostInformation['communicationLanguages'] as $language) {
                                        ?>

                                        <img src="img/flags/<?php echo $language ?>.svg" alt="<?php echo $language ?>" class="flag">

                                        <?php
                                        }
                                    ?>
                                </div>
                            </div>
                            <div class="card-footer">
                                <a href="<?php echo $hostInformation['homeUrl'] ?>" class="btn btn-primary" target="_blank" rel="noopener noreferrer">
                                    Go to <?php echo $hostInformation['name'] ?> </a> <br>
                                <?php

                                    if (filter_var($hostInformation['contactUrl'], FILTER_VALIDATE_URL)) {
                                        echo '<a href="'.$hostInformation['contactUrl'].'" target="_blank" rel="noopener noreferrer" title="contact">contact</a>';
                                        if (filter_var($hostInformation['privacyPolicyUrl'], FILTER_VALIDATE_URL) || filter_var($hostInformation['termsOfServiceUrl'], FILTER_VALIDATE_URL)) {
                                            echo ' - ';
                                        }
                                    }
                                    if (filter_var($hostInformation['privacyPolicyUrl'], FILTER_VALIDATE_URL)) {
                                        echo '<a href="'.$hostInformation['privacyPolicyUrl'].'" target="_blank" rel="noopener noreferrer" title="privacy policy">privacy</a>';
                                        if (filter_var($hostInformation['termsOfServiceUrl'], FILTER_VALIDATE_URL)) {
                                            echo ' - ';
                                        }
                                    }
                                    if (filter_var($hostInformation['termsOfServiceUrl'], FILTER_VALIDATE_URL)) {
                                        echo '<a href="'.$hostInformation['termsOfServiceUrl'].'" target="_blank" rel="noopener noreferrer" title="terms of service" >tos</a>';
                                    }
                                ?>
                            </div>
                        </div>
                        <br>
                    </div>
                    <br>
                <?php 
                } 
            ?>
        </div>
klimplant's avatar
klimplant committed
        <br>
klimplant's avatar
klimplant committed
    </div>
klimplant's avatar
klimplant committed
        <footer class="bg-light text-center">
        <br>
            <a href="https://lab.libreho.st/librehosters/librelist" target="_blank" rel="noopener noreferrer">source code</a>
klimplant's avatar
klimplant committed
        </footer>
klimplant's avatar
klimplant committed
</body>

</html>