-
Notifications
You must be signed in to change notification settings - Fork 1k
/
KilledbyGoogleBridge.php
81 lines (64 loc) · 2.18 KB
/
KilledbyGoogleBridge.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
class KilledbyGoogleBridge extends BridgeAbstract
{
const NAME = 'Killed by Google Bridge';
const URI = 'https://killedbygoogle.com';
const DESCRIPTION = 'Returns list of recently discontinued Google services, products, devices, and apps.';
const MAINTAINER = 'VerifiedJoseph';
const PARAMETERS = [];
const CACHE_TIMEOUT = 3600;
public function collectData()
{
$json = getContents(self::URI . '/graveyard.json')
or returnServerError('Could not request: ' . self::URI . '/graveyard.json');
$this->handleJson($json);
$this->orderItems();
$this->limitItems();
}
/**
* Handle JSON
*/
private function handleJson($json)
{
$graveyard = json_decode($json, true);
foreach ($graveyard as $tombstone) {
$item = [];
$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['uri'] = $tombstone['link'];
$item['timestamp'] = strtotime($tombstone['dateClose']);
$item['content'] = <<<EOD
<p>{$tombstone['description']}</p><p><a href="{$tombstone['link']}">{$tombstone['link']}</a></p>
EOD;
$item['enclosures'][] = 'https://static.killedbygoogle.com/com/tombstone.svg';
$this->items[] = $item;
}
}
/**
* Order items by timestamp
*/
private function orderItems()
{
$sort = [];
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);
}
}