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

require 'functions.php';

// ---------------------------------------------------------
// Some global definitions that can be reused multiple times
// ---------------------------------------------------------
define('pagetitle', 'Librehosters');
define('debug', false); // Enable debug or not, will enable error reporting and disable caching
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

$directory = getDirFile($directoryFile);
if (!is_array($directory)) {
    http_response_code(500);
    die();
}
?>
<!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>
    <br>
    <div class="container">
        <h1 class="text-center">
            <?php echo pagetitle; ?>
        </h1>
        <br>
        <div class="row">
            <?php
                foreach ($directory as $librehostJsonUrl) {
                    $hostInformation = getHostInformation($librehostJsonUrl);
                    ?>
                    <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>
            Created by <a href="mailto:klimplant@disroot.org">klimplant</a> | <a href="https://lab.libreho.st/klimplant/librelist" target="_blank" rel="noopener noreferrer">source code</a>
        </footer>
klimplant's avatar
klimplant committed
</body>

</html>