2016-12-24 15:55:46 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class KernelBugTrackerBridge extends BridgeAbstract
|
2022-07-01 16:10:30 +03:00
|
|
|
{
|
2016-12-24 15:55:46 +03:00
|
|
|
const NAME = 'Kernel Bug Tracker';
|
|
|
|
const URI = 'https://bugzilla.kernel.org';
|
2022-06-24 12:04:49 +03:00
|
|
|
const DESCRIPTION = 'DEPRECATED: Use BugzillaBridge instead.
|
|
|
|
Returns feeds for bug comments';
|
2016-12-24 15:55:46 +03:00
|
|
|
const MAINTAINER = 'logmanoriginal';
|
|
|
|
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'
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
2016-12-24 15:55:46 +03:00
|
|
|
];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-12-24 15:55:46 +03:00
|
|
|
private $bugid = '';
|
|
|
|
private $bugdesc = '';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-10-26 19:07:34 +03:00
|
|
|
public function getIcon()
|
|
|
|
{
|
|
|
|
return self::URI . '/images/favicon.ico';
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-12-24 15:55:46 +03:00
|
|
|
public function collectData()
|
|
|
|
{
|
|
|
|
$limit = $this->getInput('limit');
|
|
|
|
$sorting = $this->getInput('sorting');
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-12-24 15:55:46 +03:00
|
|
|
// We use the print preview page for simplicity
|
2017-02-14 19:28:07 +03:00
|
|
|
$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
|
|
|
|
);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-12-24 15:55:46 +03:00
|
|
|
if ($html === false) {
|
|
|
|
returnServerError('Failed to load page!');
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
|
2020-11-23 21:49:25 +03:00
|
|
|
$html = defaultLinkTo($html, self::URI);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-12-24 15:55:46 +03:00
|
|
|
// Store header information into private members
|
|
|
|
$this->bugid = $html->find('#bugzilla-body', 0)->find('a', 0)->innertext;
|
|
|
|
$this->bugdesc = $html->find('table.bugfields', 0)->find('tr', 0)->find('td', 0)->innertext;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-12-24 15:55:46 +03:00
|
|
|
// Get and limit comments
|
|
|
|
$comments = $html->find('div.bz_comment');
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2017-07-29 20:28:00 +03:00
|
|
|
if ($limit > 0 && count($comments) > $limit) {
|
2016-12-24 15:55:46 +03:00
|
|
|
$comments = array_slice($comments, count($comments) - $limit, $limit);
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-12-24 15:55:46 +03:00
|
|
|
// Order comments
|
2017-07-29 20:28:00 +03:00
|
|
|
switch ($sorting) {
|
2016-12-24 15:55:46 +03:00
|
|
|
case 'lf':
|
|
|
|
$comments = array_reverse($comments, true);
|
2022-06-24 19:29:35 +03:00
|
|
|
// fall-through
|
2016-12-24 15:55:46 +03:00
|
|
|
case 'of':
|
2022-06-24 19:29:35 +03:00
|
|
|
// fall-through
|
2016-12-24 15:55:46 +03:00
|
|
|
default: // Nothing to do, keep original order
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2017-07-29 20:28:00 +03:00
|
|
|
foreach ($comments as $comment) {
|
2016-12-24 15:55:46 +03:00
|
|
|
$comment = $this->inlineStyles($comment);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-12-24 15:55:46 +03:00
|
|
|
$item = [];
|
|
|
|
$item['uri'] = $this->getURI() . '#' . $comment->id;
|
|
|
|
$item['author'] = $comment->find('span.bz_comment_user', 0)->innertext;
|
|
|
|
$item['title'] = $comment->find('span.bz_comment_number', 0)->find('a', 0)->innertext;
|
|
|
|
$item['timestamp'] = strtotime($comment->find('span.bz_comment_time', 0)->innertext);
|
|
|
|
$item['content'] = $comment->find('pre.bz_comment_text', 0)->innertext;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-12-24 15:55:46 +03:00
|
|
|
// Fix line breaks (they use LF)
|
|
|
|
$item['content'] = str_replace("\n", '<br>', $item['content']);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-12-24 15:55:46 +03:00
|
|
|
// Fix relative URIs
|
2020-11-23 21:49:25 +03:00
|
|
|
$item['content'] = $item['content'];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-12-24 15:55:46 +03:00
|
|
|
$this->items[] = $item;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2016-12-24 15:55:46 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-12-24 15:55:46 +03:00
|
|
|
public function getURI()
|
|
|
|
{
|
2017-07-29 20:28:00 +03:00
|
|
|
switch ($this->queriedContext) {
|
2016-12-24 15:55:46 +03:00
|
|
|
case 'Bug comments':
|
|
|
|
return parent::getURI()
|
|
|
|
. '/show_bug.cgi?id='
|
|
|
|
. $this->getInput('id');
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return parent::getURI();
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2016-12-24 15:55:46 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-12-24 15:55:46 +03:00
|
|
|
public function getName()
|
|
|
|
{
|
2017-07-29 20:28:00 +03:00
|
|
|
switch ($this->queriedContext) {
|
2016-12-24 15:55:46 +03:00
|
|
|
case 'Bug comments':
|
|
|
|
return 'Bug '
|
|
|
|
. $this->bugid
|
|
|
|
. ' tracker for '
|
|
|
|
. $this->bugdesc
|
|
|
|
. ' - '
|
|
|
|
. parent::getName();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return parent::getName();
|
|
|
|
}
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-12-24 15:55:46 +03:00
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2017-07-29 20:28:00 +03:00
|
|
|
foreach ($html->find('.bz_obsolete') as $element) {
|
2016-12-24 15:55:46 +03:00
|
|
|
$element->style = 'text-decoration:line-through;';
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-12-24 15:55:46 +03:00
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
}
|