Website-fabianschieder/includes/views/projects_section.php

92 lines
3.6 KiB
PHP

<?php
/**
* Erwartet Variablen:
* - $category (string)
* - $items (array)
* - $serverStatusByUrl (array)
*/
?>
<section>
<h2 class="category-title">
<?= htmlspecialchars(category_title((string)$category), ENT_QUOTES) ?>
</h2>
<div class="cards">
<?php foreach ($items as $project): ?>
<?php
// Optional: Status für dieses Projekt erkennen
$status = null;
$statusKey = null;
// 1) Externe absolute URL direkt matchen
if (!empty($project['url']) && isset($serverStatusByUrl[$project['url']])) {
$statusKey = $project['url'];
}
// 2) Interne Pfade (/git, /nextcloud) auf Domain mappen
if ($statusKey === null && !empty($project['url']) && is_string($project['url']) && substr($project['url'], 0, 1) === '/') {
$statusKeyCandidate = 'https://fabianschieder.com' . $project['url'];
if (isset($serverStatusByUrl[$statusKeyCandidate])) {
$statusKey = $statusKeyCandidate;
}
}
if ($statusKey !== null) {
$status = $serverStatusByUrl[$statusKey];
}
$state = $status ? (string)($status['state'] ?? 'unknown') : null;
$detail = $status && !empty($status['detail']) ? (string)$status['detail'] : '';
$badgeText = null;
if ($state !== null) {
$badgeText = 'Unbekannt';
if ($state === 'up') $badgeText = 'Online';
elseif ($state === 'down') $badgeText = 'Offline';
}
?>
<a
href="<?= htmlspecialchars((string)$project['url'], ENT_QUOTES) ?>"
class="card"
<?= !empty($project['external']) ? 'target="_blank" rel="noopener noreferrer"' : '' ?>
style="--accent: <?= htmlspecialchars((string)($project['color'] ?? '#6366f1'), ENT_QUOTES) ?>;"
>
<div class="card-icon">
<?php if (!empty($project['logo'])): ?>
<img
src="<?= htmlspecialchars((string)$project['logo'], ENT_QUOTES) ?>"
alt="<?= htmlspecialchars((string)$project['title'], ENT_QUOTES) ?> Logo"
class="card-logo"
loading="lazy"
decoding="async"
>
<?php else: ?>
<span aria-hidden="true">📁</span>
<?php endif; ?>
</div>
<div class="card-body">
<h3><?= htmlspecialchars((string)$project['title'], ENT_QUOTES) ?></h3>
<p>
<?= htmlspecialchars((string)$project['description'], ENT_QUOTES) ?>
</p>
</div>
<?php if ($badgeText !== null): ?>
<div class="status-right">
<span class="status-badge status-badge--<?= htmlspecialchars((string)$state, ENT_QUOTES) ?>"
title="<?= htmlspecialchars($detail !== '' ? $detail : (string)$badgeText, ENT_QUOTES) ?>">
<?= htmlspecialchars((string)$badgeText, ENT_QUOTES) ?>
</span>
</div>
<?php else: ?>
<div class="card-arrow" aria-hidden="true">→</div>
<?php endif; ?>
</a>
<?php endforeach; ?>
</div>
</section>