-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[KleinanzeigenBridge] random improvements and fixes #4821
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) { | ||
|
|
@@ -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) { | ||
|
|
@@ -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; | ||
| $item['uri'] = urljoin($this->getURI(), $element->getAttribute('data-href')); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
|
||
| $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(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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']; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the |
||
| }; | ||
|
|
||
| $this->items[] = $item; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
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.