summaryrefslogtreecommitdiff
path: root/bridges/StoriesIGBridge.php
blob: 9b5f7cbfaa72ed278c5dfa2e1fad48617951418f (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
<?php
class StoriesIGBridge extends BridgeAbstract {

	const NAME = 'Instagram Stories';
	const URI = 'https://storiesig.com';
	const DESCRIPTION = 'Display Instagram Stories';
	const MAINTAINER = 'antoineturmel';
	const PARAMETERS = array(
		array(
			'username' => array(
				'name' => 'Instagram username',
				'type' => 'text',
				'required' => true,
				'title' => 'Insert the username here'
			),
		)
	);

	public function collectData(){
		$html = getSimpleHTMLDOM($this->getURI())
			or returnServerError('Failed to receive ' . $this->getURI());

		$results = $html->find('article');

		foreach($results as $result) {

			$item = array();

			$item['title'] = $this->getInput('username') . ' story';
			$item['uri'] = $result->find('div.download', 0)->find('a', 0)->href;
			$item['author'] = $this->getInput('username');
			$item['timestamp'] = strtotime($result->find('time', 0)->datetime);
			$item['uid'] = $result->find('time', 0)->datetime;

			$item['content'] = $result;

			$this->items[] = $item;
		}
	}

	public function getURI(){
		$uri = self::URI . '/stories/';
		$uri .= urlencode($this->getInput('username'));
		return $uri;

		return parent::getURI();
	}

	public function getName() {

		if (!is_null($this->getInput('username'))) {
			return $this->getInput('username') . ' - ' . self::NAME;
		}

		return parent::getName();
	}
}