Newer
Older
// ---------------------------------------------------------
// Some global definitions that can be reused multiple times
// ---------------------------------------------------------
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);
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="custom.css">
</head>
<body>
<div class="container">
?>
<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">
<h5><?php echo $hostInformation['tagLine'] ?></h5>
<?php echo $hostInformation['description'] ?>
<br>
<?php
foreach($hostInformation['communicationLanguages'] as $language) {
?>
<?php
}
?>
</div>
</div>
<div class="card-footer">
<a href="<?php echo $hostInformation['homeUrl'] ?>" class="btn" 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>