Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bridges] Use defaultLinkTo() #1862

Merged
merged 3 commits into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions bridges/BastaBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ public function collectData(){
$item['title'] = $element->find('title', 0)->innertext;
$item['uri'] = $element->find('guid', 0)->plaintext;
$item['timestamp'] = strtotime($element->find('dc:date', 0)->plaintext);
// Replaces all relative image URLs by absolute URLs.
// Relative URLs always start with 'local/'!
$item['content'] = preg_replace(
'/src=["\']{1}([^"\']+)/ims',
'src=\'' . self::URI . '$1\'',
getSimpleHTMLDOM($item['uri'])->find('div.texte', 0)->innertext
);

$html = getSimpleHTMLDOM($item['uri']);
$html = defaultLinkTo($html, self::URI);

$item['content'] = $html->find('div.texte', 0)->innertext;
$this->items[] = $item;
$limit++;
}
Expand Down
15 changes: 3 additions & 12 deletions bridges/KernelBugTrackerBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public function collectData(){
if($html === false)
returnServerError('Failed to load page!');

$html = defaultLinkTo($html, self::URI);

// 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;
Expand Down Expand Up @@ -93,7 +95,7 @@ public function collectData(){
$item['content'] = str_replace("\n", '<br>', $item['content']);

// Fix relative URIs
$item['content'] = $this->replaceRelativeURI($item['content']);
$item['content'] = $item['content'];

$this->items[] = $item;
}
Expand Down Expand Up @@ -125,17 +127,6 @@ public function getName(){
}
}

/**
* 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
*
Expand Down
8 changes: 1 addition & 7 deletions bridges/ReporterreBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class ReporterreBridge extends BridgeAbstract {

private function extractContent($url){
$html2 = getSimpleHTMLDOM($url);
$html2 = defaultLinkTo($html2, self::URI);

foreach($html2->find('div[style=text-align:justify]') as $e) {
$text = $e->outertext;
Expand All @@ -16,13 +17,6 @@ private function extractContent($url){
$html2->clear();
unset($html2);

// Replace all relative urls with absolute ones
$text = preg_replace(
'/(href|src)(\=[\"\'])(?!http)([^"\']+)/ims',
'$1$2' . self::URI . '$3',
$text
);

$text = strip_tags($text, '<p><br><a><img>');
return $text;
}
Expand Down