[MozillaBugTrackerBridge] Fix bridge (#1550)
* [MozillaBugTrackerBridge] Fix bridge
This commit is contained in:
parent
36fc4822dd
commit
71745116e1
1 changed files with 26 additions and 33 deletions
|
@ -61,43 +61,44 @@ class MozillaBugTrackerBridge extends BridgeAbstract {
|
||||||
if($html === false)
|
if($html === false)
|
||||||
returnServerError('Failed to load page!');
|
returnServerError('Failed to load page!');
|
||||||
|
|
||||||
|
// Fix relative URLs
|
||||||
|
defaultLinkTo($html, self::URI);
|
||||||
|
|
||||||
// Store header information into private members
|
// Store header information into private members
|
||||||
$this->bugid = $html->find('#bugzilla-body', 0)->find('a', 0)->innertext;
|
$this->bugid = $html->find('#field-value-bug_id', 0)->plaintext;
|
||||||
$this->bugdesc = $html->find('table.bugfields', 0)->find('tr', 0)->find('td', 0)->innertext;
|
$this->bugdesc = $html->find('h1#field-value-short_desc', 0)->plaintext;
|
||||||
|
|
||||||
// Get and limit comments
|
// Get and limit comments
|
||||||
$comments = $html->find('.bz_comment_table div.bz_comment');
|
$comments = $html->find('div.change-set');
|
||||||
|
|
||||||
if($limit > 0 && count($comments) > $limit) {
|
if($limit > 0 && count($comments) > $limit) {
|
||||||
$comments = array_slice($comments, count($comments) - $limit, $limit);
|
$comments = array_slice($comments, count($comments) - $limit, $limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Order comments
|
if ($sorting === 'lf') {
|
||||||
switch($sorting) {
|
$comments = array_reverse($comments, true);
|
||||||
case 'lf': $comments = array_reverse($comments, true);
|
|
||||||
case 'of':
|
|
||||||
default: // Nothing to do, keep original order
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($comments as $comment) {
|
foreach($comments as $comment) {
|
||||||
$comment = $this->inlineStyles($comment);
|
$comment = $this->inlineStyles($comment);
|
||||||
|
|
||||||
$item = array();
|
$item = array();
|
||||||
$item['uri'] = $this->getURI() . '#' . $comment->id;
|
$item['uri'] = $comment->find('h3.change-name', 0)->find('a', 0)->href;
|
||||||
$item['author'] = $comment->find('span.bz_comment_user', 0)->innertext;
|
$item['author'] = $comment->find('td.change-author', 0)->plaintext;
|
||||||
$item['title'] = $comment->find('span.bz_comment_number', 0)->find('a', 0)->innertext;
|
$item['title'] = $comment->find('h3.change-name', 0)->plaintext;
|
||||||
$item['timestamp'] = strtotime($comment->find('span.bz_comment_time', 0)->innertext);
|
$item['timestamp'] = strtotime($comment->find('span.rel-time', 0)->title);
|
||||||
$item['content'] = $comment->find('pre.bz_comment_text', 0)->innertext;
|
$item['content'] = '';
|
||||||
|
|
||||||
// Fix line breaks (they use LF)
|
if ($comment->find('.comment-text', 0)) {
|
||||||
$item['content'] = str_replace("\n", '<br>', $item['content']);
|
$item['content'] = $comment->find('.comment-text', 0)->outertext;
|
||||||
|
}
|
||||||
|
|
||||||
// Fix relative URIs
|
if ($comment->find('div.activity', 0)) {
|
||||||
$item['content'] = $this->replaceRelativeURI($item['content']);
|
$item['content'] .= $comment->find('div.activity', 0)->innertext;
|
||||||
|
}
|
||||||
|
|
||||||
$this->items[] = $item;
|
$this->items[] = $item;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getURI(){
|
public function getURI(){
|
||||||
|
@ -114,9 +115,8 @@ class MozillaBugTrackerBridge extends BridgeAbstract {
|
||||||
public function getName(){
|
public function getName(){
|
||||||
switch($this->queriedContext) {
|
switch($this->queriedContext) {
|
||||||
case 'Bug comments':
|
case 'Bug comments':
|
||||||
return 'Bug '
|
return $this->bugid
|
||||||
. $this->bugid
|
. ' - '
|
||||||
. ' tracker for '
|
|
||||||
. $this->bugdesc
|
. $this->bugdesc
|
||||||
. ' - '
|
. ' - '
|
||||||
. parent::getName();
|
. parent::getName();
|
||||||
|
@ -125,17 +125,6 @@ class MozillaBugTrackerBridge extends BridgeAbstract {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Replaces all relative URIs with absolute ones
|
|
||||||
*
|
|
||||||
* @param string $content The source string
|
|
||||||
* @return string Returns the source string with all relative URIs replaced
|
|
||||||
* by absolute ones.
|
|
||||||
*/
|
|
||||||
private function replaceRelativeURI($content){
|
|
||||||
return preg_replace('/href="(?!http)/', 'href="' . self::URI . '/', $content);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds styles as attributes to tags with known classes
|
* Adds styles as attributes to tags with known classes
|
||||||
*
|
*
|
||||||
|
@ -144,10 +133,14 @@ class MozillaBugTrackerBridge extends BridgeAbstract {
|
||||||
* attributes.
|
* attributes.
|
||||||
*/
|
*/
|
||||||
private function inlineStyles($html){
|
private function inlineStyles($html){
|
||||||
foreach($html->find('.bz_obsolete') as $element) {
|
foreach($html->find('.bz_closed') as $element) {
|
||||||
$element->style = 'text-decoration:line-through;';
|
$element->style = 'text-decoration:line-through;';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach($html->find('pre') as $element) {
|
||||||
|
$element->style = 'white-space: pre-wrap;';
|
||||||
|
}
|
||||||
|
|
||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue