You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
7.9 KiB
PHP

<?php
$title = "lang_home_title";
require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.php";
require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/header.php";
require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/navigation.php";
global $_PROFILE; global $_USER;
function showPage($item) { ?>
<a href="/<?= $item["_type"] ?>/<?= $item["_id"] ?>" class="list-group-item list-group-item-action">
<p style="margin-bottom: 10px;"><img class="icon" src="/icons/<?= $item["_type"] ?>.svg" style="margin-right:5px;"><span style="vertical-align: middle;"><b><?= getNameFromId($item["_id"]) ?></b> <?= l("lang_home_update") ?> <b><?= timeAgo($item["update"]) ?></b></span></p><?= trim(strip_tags($item["contents"])) !== "" ? substr(trim(strip_tags($item["contents"])), 0, 150) . (strlen(trim(strip_tags($item["contents"]))) > 150 ? "…" : "") : "-" ?>
</a>
<?php } ?>
<div class="container">
<br><br>
<h1><?= l("lang_home_greeting") ?> <?= $_PROFILE["nick_name"] ?? $_PROFILE["first_name"] . " " . $_PROFILE["last_name"] ?></h1>
<?php if (isset($_COOKIE["DeltaHandoffPalette"]) && isset($_GET["debug"])): ?>
<div class="alert alert-primary">
<details>
<summary>This device is using a custom handoff palette.</summary>
<ul>
<?php foreach (explode(",", $_COOKIE['DeltaHandoffPalette']) as $color): ?>
<li><?= $color ?> <span style="background-color:#<?= $color ?>;width:36px;height:36px;display:inline-block;"></span></li>
<?php endforeach; ?>
</ul>
</details>
</div>
<?php endif; ?>
<?php if ($_SERVER["HTTP_HOST"] === "192.168.1.121:81"): ?>
<div class="alert alert-danger">
<b>This is a development environment.</b> All data is reset with data from production every 60 minutes. Run <code style="color: inherit;"><?= $_SERVER['DOCUMENT_ROOT'] ?>/includes/prod.sh</code> to push this release to production.
</div>
<?php endif; ?>
<div class="alert alert-secondary">
<b>Vous utilisez une version expérimentale de Delta.</b> Attendez-vous à rencontrer des bugs et autres problèmes importants. Dans tous les cas, vous pouvez <a href="/support">contacter le support technique</a> pour les signaler.
</div>
<?php
$birthdays = array_values(array_filter(array_map(function ($i) {
$r = json_decode(pf_utf8_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/profiles/$i")), true);
$r["_id"] = substr($i, 0, -5);
return $r;
}, array_values(array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/includes/data/profiles"), function ($i) { return str_ends_with($i, ".json"); }))), function ($i) {
return hasProfileSetting("birth", true, $i) && substr($i["birth"], 5) === date('m-d');
}));
?>
<?php if (count($birthdays) > 0): ?>
<div class="alert alert-primary">
<img class="icon" src="/icons/age-home.svg"><span style="vertical-align: middle; margin-left: 5px;"><?= str_replace("%1", enumerate(array_map(function ($i) {
return str_replace("%1", "<a href='/profile/" . $i["_id"] . "'>" . ($i["nick_name"] ?? $i["first_name"]) . "</a>", l("lang_home_name"));
}, $birthdays), l("lang_home_and")), l("lang_home_birthday")) ?></span>
</div>
<?php else: ?>
<div class="alert alert-secondary">
<img class="icon" src="/icons/events.svg"><span style="vertical-align: middle; margin-left: 5px;"><?= str_replace("%1", formatDate(time()), l("lang_home_date")) ?></span>
</div>
<?php endif; ?>
<?php $results = array_values(array_filter(search($_PROFILE["first_name"] . " " . $_PROFILE["last_name"], true, true), function ($i) use ($_PROFILE) { return str_ends_with($i["value"]["name"], " " . $_PROFILE["last_name"]); })); if (count($results)): ?>
<h3 style="margin-bottom: 15px; margin-top: 30px;"><?= l("lang_home_family") ?></h3>
<div class="list-group">
<?php $index = 0; foreach ($results as $entry): if ($index <= 4): ?>
<a href="<?= $entry["value"]["url"] ?>" class="list-group-item-action list-group-item">
<p style="margin-bottom:.5rem;">
<img class="icon" src="/icons/<?= $entry["value"]["type"] ?>.svg" style="margin-right:5px;"><b style="vertical-align: middle;"><?= $entry["value"]["name"] ?></b>
</p>
<span><?= trim($entry["value"]["extract"]) !== "" ? substr(trim($entry["value"]["extract"]), 0, 150) . (strlen(trim($entry["value"]["extract"])) > 150 ? "…" : "") : $entry["value"]["name"] ?></span>
</a>
<?php $index++; endif; endforeach; ?>
</div>
<?php endif; ?>
<?php if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/history/" . $_USER . ".json")):
$history = json_decode(pf_utf8_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/history/" . $_USER . ".json")), true);
if (count(array_keys($history)) > 0):
uasort($history, function ($a, $b) { return $b - $a; });
$top = array_keys($history)[rand(0, count($history) >= 3 ? 2 : count($history) - 1)];
$topName = getNameFromId($top);
if (count(search($topName, true)) > 0):
?>
<h3 style="margin-bottom: 15px; margin-top: 30px;"><?= str_replace("%1", $topName, l("lang_home_because")) ?></h3>
<div class="list-group">
<?php $index = 0; foreach (search($topName, true) as $entry): if ($index <= 4): ?>
<a href="<?= $entry["value"]["url"] ?>" class="list-group-item-action list-group-item">
<p style="margin-bottom:.5rem;">
<img class="icon" src="/icons/<?= $entry["value"]["type"] ?>.svg" style="margin-right:5px;"><b style="vertical-align: middle;"><?= $entry["value"]["name"] ?></b>
</p>
<span><?= trim($entry["value"]["extract"]) !== "" ? substr(trim($entry["value"]["extract"]), 0, 150) . (strlen(trim($entry["value"]["extract"])) > 150 ? "…" : "") : $entry["value"]["name"] ?></span>
</a>
<?php $index++; endif; endforeach; ?>
</div>
<?php endif; endif; endif; ?>
<h3 style="margin-bottom: 15px; margin-top: 30px;"><?= l("lang_home_recent") ?></h3>
<div class="list-group">
<?php
$list = [];
foreach (array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/includes/data/articles"), function ($i) { return !str_starts_with($i, "."); }) as $id) {
$data = json_decode(pf_utf8_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/articles/$id")), true);
$id = substr($id, 0, -5);
$data["_type"] = "articles";
$data["_id"] = $id;
$list[$id] = $data;
}
foreach (array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/includes/data/gallery"), function ($i) { return !str_starts_with($i, "."); }) as $id) {
$data = json_decode(pf_utf8_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/gallery/$id")), true);
$id = substr($id, 0, -5);
$data["_type"] = "gallery";
$data["_id"] = $id;
$list[$id] = $data;
}
foreach (array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/includes/data/people"), function ($i) { return !str_starts_with($i, "."); }) as $id) {
$data = json_decode(pf_utf8_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/people/$id")), true);
$id = substr($id, 0, -5);
$data["_type"] = "people";
$data["_id"] = $id;
$list[$id] = $data;
}
uasort($list, function ($a, $b) {
return strtotime($a["update"]) - strtotime($b["update"]);
});
$list = array_reverse($list);
$index = 0; foreach ($list as $item): if ($index <= 4): ?>
<?php showPage($item); ?>
<?php $index++; endif; endforeach; ?>
</div>
<br><br><br>
</div>
<?php require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/footer.php"; ?>