-
Notifications
You must be signed in to change notification settings - Fork 0
/
TraktCommentsBridge.php
49 lines (41 loc) · 1.56 KB
/
TraktCommentsBridge.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
<?php
class TraktCommentsBridge extends BridgeAbstract
{
const MAINTAINER = 'philipp-r';
const NAME = 'Trakt.tv Comments';
const URI = 'https://trakt.tv/';
const CACHE_TIMEOUT = 3600; // 1hrs
const DESCRIPTION = 'Returns comments from a public profile.';
const PARAMETERS = [ [
'u' => [
'type' => 'text',
'name' => 'username',
'exampleValue' => 'johndoe',
'title' => 'The profile must be public (Trakt.tv > Settings > uncheck Private)',
'required' => true,
],
] ];
protected function getFullURI()
{
return $this->getURI()
. 'users/' . urlencode($this->getInput('u')) . '/comments';
}
protected function getItemFromElement($element)
{
$item = [];
$item['uri'] = html_entity_decode($element->find('meta[itemprop="url"]', 0)->content);
$item['uid'] = $item['uri'];
$item['content'] = $element->find('meta[itemprop="description"]', 0)->content;
$item['author'] = urlencode($this->getInput('u'));
$item['timestamp'] = $element->find('meta[itemprop="datePublished"]', 0)->content;
$item['title'] = $element->find('div[class*="comment-wrapper"]',0)->find('meta[itemprop="name"]',1)->content;
return $item;
}
public function collectData()
{
$html = getSimpleHTMLDOMCached( $this->getFullURI() );
foreach ( $html->find('div[class*="comment-with-poster"]') as $element ) {
$this->items[] = $this->getItemFromElement($element);
}
}
}