From 33cd7a7174dfa1a2dbc744c4dd41e1adb6ddcada Mon Sep 17 00:00:00 2001 From: Jason Morris Date: Wed, 10 Apr 2024 20:30:25 -0400 Subject: [PATCH] Featured view refactor Almost straight out of phind. Needed some variable name tweaks. --- app/Views/featured.php | 68 +++++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 20 deletions(-) diff --git a/app/Views/featured.php b/app/Views/featured.php index a8ce572..b1a0542 100644 --- a/app/Views/featured.php +++ b/app/Views/featured.php @@ -10,38 +10,66 @@ echo $this->include('includes/header'); ?>
-
+

News

-
+
-
- +
+

- humanize(); - ?> +

- -
+ +
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 "
  • {$title}
  • "; + } + if ($storyNum === 'story1') { + return '
  • No recent posts
  • '; + } + + return ''; +}