mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-04-23 15:06:53 +00:00
Dealabs : fix the no results case
Dealabs shows some random deals if there is no result under the no result message : the no result message is now detected and does not show any result in case of none. To conform the policy and make the code more readable, some CSS Selector have been rewritten.
This commit is contained in:
parent
41781fe3e7
commit
e1994fb656
@ -140,49 +140,107 @@ class DealabsBridge extends BridgeAbstract {
|
|||||||
$html = getSimpleHTMLDOM($url)
|
$html = getSimpleHTMLDOM($url)
|
||||||
or returnServerError('Could not request Dealabs.');
|
or returnServerError('Could not request Dealabs.');
|
||||||
$list = $html->find('article');
|
$list = $html->find('article');
|
||||||
if($list === null) {
|
|
||||||
returnClientError('Your combination of parameters returned no results');
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($list as $deal) {
|
// Deal Image Link CSS Selector
|
||||||
$item = array();
|
$selectorImageLink = implode(
|
||||||
$item['uri'] = $deal->find('div[class=threadGrid-title]', 0)->find('a', 0)->href;
|
' ', /* Notice this is a space! */
|
||||||
$item['title'] = $deal->find(
|
array(
|
||||||
'a[class=cept-tt thread-link linkPlain space--r-1 size--all-s size--fromW3-m]', 0
|
'cept-thread-image-link',
|
||||||
)->plaintext;
|
'imgFrame',
|
||||||
$item['author'] = $deal->find('span.thread-username', 0)->plaintext;
|
'imgFrame--noBorder',
|
||||||
$item['content'] = '<table><tr><td><a href="'
|
'box--all-i',
|
||||||
. $deal->find(
|
'thread-listImgCell',
|
||||||
'a[class*=cept-thread-image-link imgFrame imgFrame--noBorder box--all-i thread-listImgCell]', 0)->href
|
)
|
||||||
. '"><img src="'
|
);
|
||||||
. $this->getImage($deal)
|
|
||||||
. '"/></td><td><h2><a href="'
|
// Deal Link CSS Selector
|
||||||
. $deal->find('a[class=cept-tt thread-link linkPlain space--r-1 size--all-s size--fromW3-m]', 0)->href
|
$selectorLink = implode(
|
||||||
. '">'
|
' ', /* Notice this is a space! */
|
||||||
. $deal->find('a[class=cept-tt thread-link linkPlain space--r-1 size--all-s size--fromW3-m]', 0)->innertext
|
array(
|
||||||
. '</a></h2>'
|
'cept-tt',
|
||||||
. $this->getPrix($deal)
|
'thread-link',
|
||||||
. $this->getReduction($deal)
|
'linkPlain',
|
||||||
. $this->getExpedition($deal)
|
'space--r-1',
|
||||||
. $this->getLivraison($deal)
|
'size--all-s',
|
||||||
. $this->getOrigine($deal)
|
'size--fromW3-m',
|
||||||
. $deal->find(
|
)
|
||||||
'div[class=cept-description-container overflow--wrap-break size--all-s size--fromW3-m]', 0
|
);
|
||||||
)->innertext
|
|
||||||
. '</td><td>'
|
// Deal Hotness CSS Selector
|
||||||
. $deal->find('div[class=flex flex--align-c flex--justify-space-between space--b-2]', 0)->children(0)->outertext
|
$selectorHot = implode(
|
||||||
. '</td></table>';
|
' ', /* Notice this is a space! */
|
||||||
$dealDateDiv = $deal->find('div[class=size--all-s flex flex--wrap flex--justify-e flex--grow-1]', 0)
|
array(
|
||||||
->find('span[class=hide--toW3]');
|
'flex',
|
||||||
$itemDate = end($dealDateDiv)->plaintext;
|
'flex--align-c',
|
||||||
if(substr( $itemDate, 0, 6 ) === 'il y a') {
|
'flex--justify-space-between',
|
||||||
$item['timestamp'] = $this->relativeDateToTimestamp($itemDate);
|
'space--b-2',
|
||||||
} else {
|
)
|
||||||
$item['timestamp'] = $this->parseDate($itemDate);
|
);
|
||||||
|
|
||||||
|
// Deal Description CSS Selector
|
||||||
|
$selectorDescription = implode(
|
||||||
|
' ', /* Notice this is a space! */
|
||||||
|
array(
|
||||||
|
'cept-description-container',
|
||||||
|
'overflow--wrap-break',
|
||||||
|
'size--all-s',
|
||||||
|
'size--fromW3-m',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Deal Date CSS Selector
|
||||||
|
$selectorDate = implode(
|
||||||
|
' ', /* Notice this is a space! */
|
||||||
|
array(
|
||||||
|
'size--all-s',
|
||||||
|
'flex',
|
||||||
|
'flex--wrap',
|
||||||
|
'flex--justify-e',
|
||||||
|
'flex--grow-1',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// If there is no results, we don't parse the content because it display some random deals
|
||||||
|
$noresult = $html->find('h3[class=size--all-l size--fromW2-xl size--fromW3-xxl]',0);
|
||||||
|
if($noresult != null && $noresult->plaintext == 'Il n'y a rien à afficher pour le moment :(') {
|
||||||
|
$this->items = array();
|
||||||
|
} else {
|
||||||
|
foreach($list as $deal) {
|
||||||
|
$item = array();
|
||||||
|
$item['uri'] = $deal->find('div[class=threadGrid-title]', 0)->find('a', 0)->href;
|
||||||
|
$item['title'] = $deal->find('a[class='. $selectorLink .']', 0
|
||||||
|
)->plaintext;
|
||||||
|
$item['author'] = $deal->find('span.thread-username', 0)->plaintext;
|
||||||
|
$item['content'] = '<table><tr><td><a href="'
|
||||||
|
. $deal->find(
|
||||||
|
'a[class*='. $selectorImageLink .']', 0)->href
|
||||||
|
. '"><img src="'
|
||||||
|
. $this->getImage($deal)
|
||||||
|
. '"/></td><td><h2><a href="'
|
||||||
|
. $deal->find('a[class='. $selectorLink .']', 0)->href
|
||||||
|
. '">'
|
||||||
|
. $deal->find('a[class='. $selectorLink .']', 0)->innertext
|
||||||
|
. '</a></h2>'
|
||||||
|
. $this->getPrix($deal)
|
||||||
|
. $this->getReduction($deal)
|
||||||
|
. $this->getExpedition($deal)
|
||||||
|
. $this->getLivraison($deal)
|
||||||
|
. $this->getOrigine($deal)
|
||||||
|
. $deal->find('div[class='. $selectorDescription .']', 0)->innertext
|
||||||
|
. '</td><td>'
|
||||||
|
. $deal->find('div[class='. $selectorHot .']', 0)->children(0)->outertext
|
||||||
|
. '</td></table>';
|
||||||
|
$dealDateDiv = $deal->find('div[class='. $selectorDate .']', 0)
|
||||||
|
->find('span[class=hide--toW3]');
|
||||||
|
$itemDate = end($dealDateDiv)->plaintext;
|
||||||
|
if(substr( $itemDate, 0, 6 ) === 'il y a') {
|
||||||
|
$item['timestamp'] = $this->relativeDateToTimestamp($itemDate);
|
||||||
|
} else {
|
||||||
|
$item['timestamp'] = $this->parseDate($itemDate);
|
||||||
|
}
|
||||||
|
$this->items[] = $item;
|
||||||
}
|
}
|
||||||
$this->items[] = $item;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user