Skip to content

Commit

Permalink
Featured view refactor
Browse files Browse the repository at this point in the history
Almost straight out of phind. Needed some variable name tweaks.
  • Loading branch information
Jason Morris committed Apr 11, 2024
1 parent c31d01f commit 33cd7a7
Showing 1 changed file with 48 additions and 20 deletions.
68 changes: 48 additions & 20 deletions app/Views/featured.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,66 @@
echo $this->include('includes/header'); ?>

<main id="content" class="floor" tabindex="-1">
<div class="wrap">
<div class="wrap">
<h1>News</h1>
</div>
</div>

<div class="wrap">
<?php foreach ($build as $row) :?>
<div class="wrap">
<?php foreach ($build as $row) :?>
<article class="box box--feature">
<h2>
<a href="/sites/<?= $row['site_slug']; ?>"><?= $row['site_name']; ?></a>
<span class="ago--muted"><?php
$time = Time::createFromFormat('Y-m-d H:i:s', $row['site_date_last_post'], 'America/New_York');
echo $time->humanize();
?></span>
<span class="ago--muted"><?= humanizeTime($row['site_date_last_post'], 'America/New_York'); ?></span>
</h2>
<ol class="links">
<?php for ($story = 1; $story < 4; $story++) :?>
<?php $story_num = 'story' . $story; ?>
<?php if (isset($row[$story_num])) :?>
<li><a href="<?= $row[$story_num]['story_permalink']; ?>" rel="noopener noreferrer" data-outgoing="<?= $row[$story_num]['story_hash']; ?>"><?= htmlspecialchars_decode($row[$story_num]['story_title'] ?? '');
if (htmlspecialchars_decode($row[$story_num]['story_title']) === '') {
echo '[missing title]';
} ?></a></li>
<?php endif; ?>
<?php if (! isset($row[$story_num]) && $story === 1) :?>
<li>No recent posts</li>
<?php endif; ?>
<?php $storyNum = 'story' . $story; ?>
<?= displayStory($row, $storyNum); ?>
<?php endfor; ?>
</ol>
</article>
<?php endforeach; ?>
</div>
<?php endforeach; ?>
</div>

</main>

<?= $this->include('includes/footer');

/**
* Humanize the time for a given date.
*
* @param string $date
* @param string $timezone
*
* @return string
*/
function humanizeTime($date, $timezone)
{
$time = Time::createFromFormat('Y-m-d H:i:s', $date, $timezone);

return $time->humanize();
}

/**
* Display a story link if it exists, otherwise display a message.
*
* @param array $row
* @param string $storyNum
*
* @return string
*/
function displayStory($row, $storyNum)
{
if (isset($row[$storyNum])) {
$story = $row[$storyNum];
$title = htmlspecialchars_decode($story['story_title'] ?? '');
$title = $title === '' ? '[missing title]' : $title;

return "<li><a href=\"{$story['story_permalink']}\" rel=\"noopener noreferrer\" data-outgoing=\"{$story['story_hash']}\">{$title}</a></li>";
}
if ($storyNum === 'story1') {
return '<li>No recent posts</li>';
}

return '';
}

0 comments on commit 33cd7a7

Please sign in to comment.