From 4321043a131e6225f071a2c84b1d5b3a39663ddd Mon Sep 17 00:00:00 2001
From: Joseph
Date: Thu, 24 Mar 2022 19:03:18 +0000
Subject: [PATCH] [KilledbyGoogleBridge] Add bridge (#1373)
---
bridges/KilledbyGoogleBridge.php | 77 ++++++++++++++++++++++++++++++++
1 file changed, 77 insertions(+)
create mode 100644 bridges/KilledbyGoogleBridge.php
diff --git a/bridges/KilledbyGoogleBridge.php b/bridges/KilledbyGoogleBridge.php
new file mode 100644
index 00000000000..217f6095236
--- /dev/null
+++ b/bridges/KilledbyGoogleBridge.php
@@ -0,0 +1,77 @@
+handleJson($json);
+ $this->orderItems();
+ $this->limitItems();
+ }
+
+ /**
+ * Handle JSON
+ */
+ private function handleJson($json) {
+
+ $graveyard = json_decode($json, true);
+
+ foreach($graveyard as $tombstone) {
+ $item = array();
+
+ $openDate = new DateTime($tombstone['dateOpen']);
+ $closeDate = new DateTime($tombstone['dateClose']);
+ $currentDate = new DateTime();
+
+ $yearOpened = $openDate->format('Y');
+ $yearClosed = $closeDate->format('Y');
+
+ if ($closeDate > $currentDate) {
+ continue;
+ }
+
+ $item['title'] = $tombstone['name'] . ' (' . $yearOpened . ' - ' . $yearClosed . ')';
+ $item['uid'] = $tombstone['slug'];
+ $item['timestamp'] = strtotime($tombstone['dateClose']);
+
+ $item['content'] = <<{$tombstone['description']}
{$tombstone['link']}
+EOD;
+
+ $item['enclosures'][] = self::URI . '/assets/tombstone.svg';
+
+ $this->items[] = $item;
+ }
+ }
+
+ /**
+ * Order items by timestamp
+ */
+ private function orderItems() {
+
+ $sort = array();
+
+ foreach ($this->items as $key => $item) {
+ $sort[$key] = $item['timestamp'];
+ }
+
+ array_multisort($sort, SORT_DESC, $this->items);
+ $this->items = array_slice($this->items, 0, 15);
+ }
+
+ /**
+ * Limit items to 15
+ */
+ private function limitItems() {
+ $this->items = array_slice($this->items, 0, 15);
+ }
+}