Newer
Older
// ---------------------------------------------------------
// Some global definitions that can be reused multiple times
// ---------------------------------------------------------
define('pagetitle', 'libreho.st - the librehosters directory');
define('debug', false); // may be used during dev, recomended in prod: false
define('useCache', true); // may be used during dev, recomended in prod: true
// 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);
}
$hosts = getCache('hosts');
$recache = !is_array($hosts) || !useCache;
if ($recache) {
$directory = getDirFile($directoryFile);
if (!is_array($directory)) {
http_response_code(500);
die();
}
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";
}
?>
<!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">
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
?>
<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>
<a href="https://lab.libreho.st/librehosters/librelist" target="_blank" rel="noopener noreferrer">source code</a>