summaryrefslogtreecommitdiff
path: root/bridges/GOGBridge.php
blob: 669332f0ea4f7798975c6df47abb2ad35c855804 (plain)
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
<?php
class GOGBridge extends BridgeAbstract {

	const NAME = 'GOGBridge';
	const MAINTAINER = 'teromene';
	const URI = 'https://gog.com';
	const DESCRIPTION = 'Returns the latest releases from GOG.com';

	public function collectData() {

		$values = getContents('https://www.gog.com/games/ajax/filtered?limit=25&sort=new') or
			die('Unable to get the news pages from GOG !');
		$decodedValues = json_decode($values);

		$limit = 0;
		foreach($decodedValues->products as $game) {

			$item = array();
			$item['author'] = $game->developer . ' / ' . $game->publisher;
			$item['title'] = $game->title;
			$item['id'] = $game->id;
			$item['uri'] = self::URI . $game->url;
			$item['content'] = $this->buildGameContentPage($game);
			$item['timestamp'] = $game->globalReleaseDate;

			foreach($game->gallery as $image) {
				$item['enclosures'][] = $image . '.jpg';
			}

			$this->items[] = $item;
			$limit += 1;

			if($limit == 10) break;

		}

	}

	private function buildGameContentPage($game) {

		$gameDescriptionText = getContents('https://api.gog.com/products/' . $game->id . '?expand=description') or
			die('Unable to get game description from GOG !');

		$gameDescriptionValue = json_decode($gameDescriptionText);

		$content = 'Genres: ';
		$content .= implode(', ', $game->genres);

		$content .= '<br />Supported Platforms: ';
		if($game->worksOn->Windows) {
			$content .= 'Windows ';
		}
		if($game->worksOn->Mac) {
			$content .= 'Mac ';
		}
		if($game->worksOn->Linux) {
			$content .= 'Linux ';
		}

		$content .= '<br />' . $gameDescriptionValue->description->full;

		return $content;

	}
}