Skip to content
Open
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
66 changes: 49 additions & 17 deletions bridges/KleinanzeigenBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public function collectData()
if ($this->queriedContext === 'By profile') {
for ($i = 1; $i <= $this->getInput('pages'); $i++) {
$html = getSimpleHTMLDOM($this->getURI() . '/s-bestandsliste.html?userId=' . $this->getInput('userid') . '&pageNum=' . $i . '&sortingField=SORTING_DATE');
$html = defaultLinkTo($html, $this->getURI());

$foundItem = false;
foreach ($html->find('article.aditem') as $element) {
Expand Down Expand Up @@ -120,7 +119,6 @@ public function collectData()
]);

$html = getSimpleHTMLDOM($searchUrl);
$html = defaultLinkTo($html, $this->getURI());

// end of list if returned page is not the expected one
if ($html->find('.pagination-current', 0)->plaintext != $page) {
Expand All @@ -138,22 +136,56 @@ private function addItem($element)
{
$item = [];

$item['content'] = '';

$json = $element->find('.aditem-image > script', 0);
if ($json) {
$data = json_decode($json->innertext, true);
$item['title'] = $data['title'];
$item['content'] .= '<div><p>' . $data['description'] . '</div></p></br>';
} else {
$item['title'] = $element->find('h2', 0)->plaintext;
$item['content'] .= $element->find('.aditem-main--middle--description');
}

if ($element->find('.aditem-main--top', 0)) {
$item['content'] .= $element->find('.aditem-main--top', 0);
}

if ($element->find('.aditem-main--middle--price-shipping', 0)) {
$item['content'] .= preg_replace(
'#(<p\s+class="aditem-main--middle--price-shipping--old-price"[^>]*>.*?</p>)#si',
'<s>$1</s>',
$element->find('.aditem-main--middle--price-shipping', 0)
);
}

if ($element->find('.aditem-main--bottom', 0)) {
$item['content'] .= $element->find('.aditem-main--bottom', 0);
}

$item['content'] = sanitize($item['content']);

$item['uid'] = $element->getAttribute('data-adid');
$item['uri'] = $element->getAttribute('data-href');

$item['title'] = $element->find('h2', 0)->plaintext;
$item['timestamp'] = $element->find('div.aditem-main--top--right', 0)->plaintext;
$imgUrl = str_replace(
'rule=$_2.JPG',
'rule=$_57.JPG',
str_replace(
'rule=$_35.JPG',
'rule=$_57.JPG',
$element->find('img', 0) ? $element->find('img', 0)->getAttribute('src') : ''
)
); //enhance img quality

$item['content'] = '<img src="' . $imgUrl . '"/>' . $element->find('div.aditem-main', 0)->outertext;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would still add the image into the content HTML in addition to the enclosure. Depending on RSS reader, the display of this stuff can vary widely.
If you want, you can add a bridge option to control that.

$item['uri'] = urljoin($this->getURI(), $element->getAttribute('data-href'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could fail if Kleinanzeigen chooses to make the value an absolute URL? Add a small if or ternary operator thin to catch that.


$dateString = trim($element->find('div.aditem-main--top--right', 0)->plaintext);
if ($dateString) {
$dateString = str_ireplace(
['Gestern', 'Heute'],
['yesterday', 'today'],
$dateString
);

$item['timestamp'] = strtotime($dateString);
} else {
$item['timestamp'] = time();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to not include a timestamp if not available/on failure? Otherwise, the timestamp of existing ads could change over time? Not sure here.

}

if ($element->find('img', 0)) {
//enhance img quality. Cannot use convertLazyLoading() here due to non-standard URI suffix in srcset.
$item['enclosures'] = [preg_replace('/rule=\$_\d+\.AUTO/i', 'rule=$_57.AUTO', $element->find('img', 0)->getAttribute('src')) . '#.image'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the . '#.image' part doing at the end?

};

$this->items[] = $item;
}
Expand Down