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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
<?php
class MozillaBugTrackerBridge extends BridgeAbstract
{
const NAME = 'Mozilla Bug Tracker';
const URI = 'https://bugzilla.mozilla.org';
const DESCRIPTION = 'DEPRECATED: Use BugzillaBridge instead.
Returns feeds for bug comments';
const MAINTAINER = 'AntoineTurmel';
const PARAMETERS = [
'Bug comments' => [
'id' => [
'name' => 'Bug tracking ID',
'type' => 'number',
'required' => true,
'title' => 'Insert bug tracking ID',
'exampleValue' => 121241
],
'limit' => [
'name' => 'Number of comments to return',
'type' => 'number',
'required' => false,
'title' => 'Specify number of comments to return',
'defaultValue' => -1
],
'sorting' => [
'name' => 'Sorting',
'type' => 'list',
'required' => false,
'title' => 'Defines the sorting order of the comments returned',
'defaultValue' => 'of',
'values' => [
'Oldest first' => 'of',
'Latest first' => 'lf'
]
]
]
];
private $bugid = '';
private $bugdesc = '';
public function getIcon()
{
return self::URI . '/extensions/BMO/web/images/favicon.ico';
}
public function collectData()
{
$limit = $this->getInput('limit');
$sorting = $this->getInput('sorting');
// We use the print preview page for simplicity
$html = getSimpleHTMLDOMCached(
$this->getURI() . '&format=multiple',
86400,
null,
null,
true,
true,
DEFAULT_TARGET_CHARSET,
false, // Do NOT remove line breaks
DEFAULT_BR_TEXT,
DEFAULT_SPAN_TEXT
);
// Fix relative URLs
defaultLinkTo($html, self::URI);
// Store header information into private members
$this->bugid = trim($html->find('#field-value-bug_id', 0)->plaintext);
$this->bugdesc = $html->find('h1#field-value-short_desc', 0)->plaintext;
// Get and limit comments
$comments = $html->find('div.change-set');
if ($limit > 0 && count($comments) > $limit) {
$comments = array_slice($comments, count($comments) - $limit, $limit);
}
if ($sorting === 'lf') {
$comments = array_reverse($comments, true);
}
foreach ($comments as $comment) {
$comment = $this->inlineStyles($comment);
$item = [];
$item['uri'] = $comment->find('h3.change-name', 0)->find('a', 0)->href;
$item['author'] = $comment->find('td.change-author', 0)->plaintext;
$item['title'] = $comment->find('h3.change-name', 0)->plaintext;
$item['timestamp'] = strtotime($comment->find('span.rel-time', 0)->title);
$item['content'] = '';
if ($comment->find('.comment-text', 0)) {
$item['content'] = $comment->find('.comment-text', 0)->outertext;
}
if ($comment->find('div.activity', 0)) {
$item['content'] .= $comment->find('div.activity', 0)->innertext;
}
$this->items[] = $item;
}
}
public function getURI()
{
switch ($this->queriedContext) {
case 'Bug comments':
return parent::getURI()
. '/show_bug.cgi?id='
. $this->getInput('id');
break;
default:
return parent::getURI();
}
}
public function getName()
{
switch ($this->queriedContext) {
case 'Bug comments':
return $this->bugid
. ' - '
. $this->bugdesc
. ' - '
. parent::getName();
break;
default:
return parent::getName();
}
}
/**
* Adds styles as attributes to tags with known classes
*
* @param object $html A simplehtmldom object
* @return object Returns the original object with styles added as
* attributes.
*/
private function inlineStyles($html)
{
foreach ($html->find('.bz_closed') as $element) {
$element->style = 'text-decoration:line-through;';
}
foreach ($html->find('pre') as $element) {
$element->style = 'white-space: pre-wrap;';
}
return $html;
}
}
|