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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
<?php
class FiderBridge extends BridgeAbstract
{
const NAME = 'Fider Bridge';
const URI = 'https://fider.io/';
const DESCRIPTION = 'Bridge for any Fider instance';
const MAINTAINER = 'Oliver Nutter';
const PARAMETERS = [
'global' => [
'instance' => [
'name' => 'Instance URL',
'required' => true,
'example' => 'https://feedback.fider.io',
],
],
'Post' => [
'num' => [
'name' => 'Post Number',
'type' => 'number',
'required' => true,
],
'limit' => [
'name' => 'Number of comments to return',
'type' => 'number',
'required' => false,
'title' => 'Specify number of comments to return',
],
],
];
private $instance;
private $posturi;
private $title;
public function getName()
{
return $this->title ?? parent::getName();
}
public function getURI()
{
return $this->posturi ?? parent::getURI();
}
protected function setTitle($title)
{
$html = getSimpleHTMLDOMCached($this->instance);
$name = $html->find('title', 0)->innertext;
$this->title = "$title - $name";
}
protected function getItem($post, $response = false, $first = false)
{
$item = [];
$item['uri'] = $this->getURI();
$item['timestamp'] = $response ? $post->respondedAt : $post->createdAt;
$item['author'] = $post->user->name;
$datetime = new DateTime($item['timestamp']);
if ($response) {
$item['uid'] = 'response';
$item['content'] = $post->text;
$item['title'] = "{$item['author']} marked as $post->status {$datetime->format('M d, Y')}";
} elseif ($first) {
$item['uid'] = 'post';
$item['content'] = $post->description;
$item['title'] = $post->title;
} else {
$item['uid'] = 'comment';
$item['content'] = $post->content;
$item['title'] = "{$item['author']} commented {$datetime->format('M d, Y')}";
}
$item['uid'] .= $item['author'] . $item['timestamp'];
// parse markdown with implicit line breaks
$item['content'] = markdownToHtml($item['content'], ['breaksEnabled' => true]);
if (property_exists($post, 'editedAt')) {
$item['title'] .= ' (edited)';
}
if ($first) {
$item['categories'] = $post->tags;
}
return $item;
}
public function collectData()
{
// collect first post
$this->instance = rtrim($this->getInput('instance'), '/');
$num = $this->getInput('num');
$this->posturi = "$this->instance/posts/$num";
$post_api_uri = "$this->instance/api/v1/posts/$num";
$post = json_decode(getContents($post_api_uri));
$this->setTitle($post->title);
$item = $this->getItem($post, false, true);
$this->items[] = $item;
// collect response to first post
if (property_exists($post, 'response')) {
$response = $post->response;
$response->status = $post->status;
$this->items[] = $this->getItem($response, true);
}
// collect comments
$comment_api_uri = "$post_api_uri/comments";
$comments = json_decode(getContents($comment_api_uri));
foreach ($comments as $post) {
$item = $this->getItem($post);
$this->items[] = $item;
}
usort($this->items, function ($a, $b) {
return $b['timestamp'] <=> $a['timestamp'];
});
if ($this->getInput('limit') ?? 0 > 0) {
$this->items = array_slice($this->items, 0, $this->getInput('limit'));
}
}
}
|