2017-09-05 21:03:21 +02:00
|
|
|
<?php
|
2018-07-13 01:35:13 +02:00
|
|
|
class DealabsBridge extends PepperBridgeAbstract {
|
|
|
|
|
|
|
|
const NAME = 'Dealabs Bridge';
|
2017-09-05 21:03:21 +02:00
|
|
|
const URI = 'https://www.dealabs.com/';
|
2018-07-13 01:35:13 +02:00
|
|
|
const DESCRIPTION = 'Affiche les Deals de Dealabs';
|
2017-09-05 21:03:21 +02:00
|
|
|
const MAINTAINER = 'sysadminstory';
|
2018-03-01 18:10:34 +01:00
|
|
|
const PARAMETERS = array(
|
|
|
|
'Recherche par Mot(s) clé(s)' => array (
|
|
|
|
'q' => array(
|
|
|
|
'name' => 'Mot(s) clé(s)',
|
|
|
|
'type' => 'text',
|
|
|
|
'required' => true
|
|
|
|
),
|
|
|
|
'hide_expired' => array(
|
|
|
|
'name' => 'Masquer les éléments expirés',
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'required' => 'true'
|
|
|
|
),
|
|
|
|
'hide_local' => array(
|
|
|
|
'name' => 'Masquer les deals locaux',
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'title' => 'Masquer les deals en magasins physiques',
|
|
|
|
'required' => 'true'
|
|
|
|
),
|
|
|
|
'priceFrom' => array(
|
|
|
|
'name' => 'Prix minimum',
|
|
|
|
'type' => 'text',
|
|
|
|
'title' => 'Prix mnimum en euros',
|
|
|
|
'required' => 'false',
|
|
|
|
'defaultValue' => ''
|
|
|
|
),
|
|
|
|
'priceTo' => array(
|
|
|
|
'name' => 'Prix maximum',
|
|
|
|
'type' => 'text',
|
|
|
|
'title' => 'Prix maximum en euros',
|
|
|
|
'required' => 'false',
|
|
|
|
'defaultValue' => ''
|
|
|
|
),
|
2017-09-19 02:08:22 +02:00
|
|
|
),
|
2018-03-01 18:10:34 +01:00
|
|
|
|
|
|
|
'Deals par groupe' => array(
|
2018-07-13 01:35:13 +02:00
|
|
|
'group' => array(
|
2018-03-01 18:10:34 +01:00
|
|
|
'name' => 'Groupe',
|
|
|
|
'type' => 'list',
|
|
|
|
'required' => 'true',
|
|
|
|
'title' => 'Groupe dont il faut afficher les deals',
|
|
|
|
'values' => array(
|
|
|
|
'Accessoires & gadgets' => 'accessoires-gadgets',
|
|
|
|
'Alimentation & boissons' => 'alimentation-boissons',
|
|
|
|
'Animaux' => 'animaux',
|
|
|
|
'Applis & logiciels' => 'applis-logiciels',
|
|
|
|
'Consoles & jeux vidéo' => 'consoles-jeux-video',
|
|
|
|
'Culture & divertissement' => 'culture-divertissement',
|
|
|
|
'Gratuit' => 'gratuit',
|
|
|
|
'Image, son & vidéo' => 'image-son-video',
|
|
|
|
'Informatique' => 'informatique',
|
|
|
|
'Jeux & jouets' => 'jeux-jouets',
|
|
|
|
'Maison & jardin' => 'maison-jardin',
|
|
|
|
'Mode & accessoires' => 'mode-accessoires',
|
|
|
|
'Santé & cosmétiques' => 'hygiene-sante-cosmetiques',
|
|
|
|
'Services divers' => 'services-divers',
|
|
|
|
'Sports & plein air' => 'sports-plein-air',
|
|
|
|
'Téléphonie' => 'telephonie',
|
2018-07-13 01:35:13 +02:00
|
|
|
'Voyages & sorties' => 'voyages-sorties-restaurants',
|
2018-03-01 18:10:34 +01:00
|
|
|
)
|
|
|
|
),
|
2018-07-13 01:35:13 +02:00
|
|
|
'order' => array(
|
2018-03-01 18:10:34 +01:00
|
|
|
'name' => 'Trier par',
|
|
|
|
'type' => 'list',
|
|
|
|
'required' => 'true',
|
|
|
|
'title' => 'Ordre de tri des deals',
|
|
|
|
'values' => array(
|
|
|
|
'Du deal le plus Hot au moins Hot' => '',
|
|
|
|
'Du deal le plus récent au plus ancien' => '-nouveaux',
|
|
|
|
'Du deal le plus commentés au moins commentés' => '-commentes'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2017-10-17 23:37:09 +02:00
|
|
|
|
2018-07-13 01:35:13 +02:00
|
|
|
public $lang = array(
|
|
|
|
'bridge-uri' => SELF::URI,
|
|
|
|
'bridge-name' => SELF::NAME,
|
|
|
|
'context-keyword' => 'Recherche par Mot(s) clé(s)',
|
|
|
|
'context-group' => 'Deals par groupe',
|
|
|
|
'uri-group' => '/groupe/',
|
|
|
|
'request-error' => 'Could not request Dealabs',
|
|
|
|
'no-results' => 'Il n'y a rien à afficher pour le moment :(',
|
|
|
|
'relative-date-indicator' => array(
|
|
|
|
'il y a',
|
|
|
|
),
|
|
|
|
'price' => 'Prix',
|
|
|
|
'shipping' => 'Livraison',
|
|
|
|
'origin' => 'Origine',
|
|
|
|
'discount' => 'Réduction',
|
|
|
|
'title-keyword' => 'Recherche',
|
|
|
|
'title-group' => 'Groupe',
|
|
|
|
'local-months' => array(
|
|
|
|
'janvier',
|
|
|
|
'février',
|
|
|
|
'mars',
|
|
|
|
'avril',
|
|
|
|
'mai',
|
|
|
|
'juin',
|
|
|
|
'juillet',
|
|
|
|
'août',
|
|
|
|
'septembre',
|
|
|
|
'octobre',
|
|
|
|
'novembre',
|
|
|
|
'décembre'
|
|
|
|
),
|
|
|
|
'local-time-relative' => array(
|
|
|
|
'il y a ',
|
|
|
|
'min',
|
|
|
|
'h',
|
|
|
|
'jour',
|
|
|
|
'jours',
|
|
|
|
'mois',
|
|
|
|
'ans',
|
|
|
|
'et '
|
|
|
|
),
|
|
|
|
'date-prefixes' => array(
|
|
|
|
'Actualisé ',
|
|
|
|
),
|
|
|
|
'relative-date-alt-prefixes' => array(
|
|
|
|
'Actualisé ',
|
|
|
|
),
|
|
|
|
'relative-date-ignore-suffix' => array(
|
|
|
|
),
|
|
|
|
|
|
|
|
'localdeal' => array(
|
|
|
|
'Local',
|
|
|
|
'Pays d\'expédition'
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class PepperBridgeAbstract extends BridgeAbstract {
|
|
|
|
|
2017-09-05 21:03:21 +02:00
|
|
|
const CACHE_TIMEOUT = 3600;
|
|
|
|
|
|
|
|
public function collectData(){
|
2018-03-01 18:10:34 +01:00
|
|
|
switch($this->queriedContext) {
|
2018-07-13 01:35:13 +02:00
|
|
|
case $this->i8n('context-keyword'):
|
|
|
|
return $this->collectDataKeywords();
|
2018-03-01 18:10:34 +01:00
|
|
|
break;
|
2018-07-13 01:35:13 +02:00
|
|
|
case $this->i8n('context-group'):
|
|
|
|
return $this->collectDataGroup();
|
2018-03-01 18:10:34 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-13 01:35:13 +02:00
|
|
|
* Get the Deal data from the choosen group in the choosed order
|
2018-03-01 18:10:34 +01:00
|
|
|
*/
|
2018-08-05 15:53:45 +02:00
|
|
|
protected function collectDataGroup()
|
2018-03-01 18:10:34 +01:00
|
|
|
{
|
|
|
|
|
2018-07-13 01:35:13 +02:00
|
|
|
$group = $this->getInput('group');
|
|
|
|
$order = $this->getInput('order');
|
2018-03-01 18:10:34 +01:00
|
|
|
|
2018-07-13 01:35:13 +02:00
|
|
|
$url = $this->i8n('bridge-uri')
|
|
|
|
. $this->i8n('uri-group') . $group . $order;
|
2018-03-01 18:10:34 +01:00
|
|
|
$this->collectDeals($url);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Deal data from the choosen keywords and parameters
|
|
|
|
*/
|
2018-08-05 15:53:45 +02:00
|
|
|
protected function collectDataKeywords()
|
2018-03-01 18:10:34 +01:00
|
|
|
{
|
2017-09-05 21:03:21 +02:00
|
|
|
$q = $this->getInput('q');
|
2018-02-14 12:03:44 +01:00
|
|
|
$hide_expired = $this->getInput('hide_expired');
|
|
|
|
$hide_local = $this->getInput('hide_local');
|
|
|
|
$priceFrom = $this->getInput('priceFrom');
|
|
|
|
$priceTo = $this->getInput('priceFrom');
|
2017-09-05 21:03:21 +02:00
|
|
|
|
2018-03-01 18:10:34 +01:00
|
|
|
/* Even if the original website uses POST with the search page, GET works too */
|
2018-07-13 01:35:13 +02:00
|
|
|
$url = $this->i8n('bridge-uri')
|
2018-02-14 12:03:44 +01:00
|
|
|
. '/search/advanced?q='
|
2017-09-05 21:03:21 +02:00
|
|
|
. urlencode($q)
|
2018-02-14 12:03:44 +01:00
|
|
|
. '&hide_expired='. $hide_expired
|
|
|
|
. '&hide_local='. $hide_local
|
|
|
|
. '&priceFrom='. $priceFrom
|
|
|
|
. '&priceTo='. $priceTo
|
|
|
|
/* Some default parameters
|
|
|
|
* search_fields : Search in Titres & Descriptions & Codes
|
|
|
|
* sort_by : Sort the search by new deals
|
|
|
|
* time_frame : Search will not be on a limited timeframe
|
|
|
|
*/
|
2018-03-01 18:10:34 +01:00
|
|
|
. '&search_fields[]=1&search_fields[]=2&search_fields[]=3&sort_by=new&time_frame=0';
|
|
|
|
$this->collectDeals($url);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Deal data using the given URL
|
|
|
|
*/
|
2018-08-05 15:53:45 +02:00
|
|
|
protected function collectDeals($url){
|
2018-03-01 18:10:34 +01:00
|
|
|
$html = getSimpleHTMLDOM($url)
|
2018-07-13 01:35:13 +02:00
|
|
|
or returnServerError($this->i8n('request-error'));
|
|
|
|
$list = $html->find('article[id]');
|
2017-09-05 21:03:21 +02:00
|
|
|
|
2018-03-01 18:10:34 +01:00
|
|
|
// Deal Image Link CSS Selector
|
|
|
|
$selectorImageLink = implode(
|
|
|
|
' ', /* Notice this is a space! */
|
|
|
|
array(
|
|
|
|
'cept-thread-image-link',
|
|
|
|
'imgFrame',
|
|
|
|
'imgFrame--noBorder',
|
|
|
|
'thread-listImgCell',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Deal Link CSS Selector
|
|
|
|
$selectorLink = implode(
|
|
|
|
' ', /* Notice this is a space! */
|
|
|
|
array(
|
|
|
|
'cept-tt',
|
|
|
|
'thread-link',
|
|
|
|
'linkPlain',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Deal Hotness CSS Selector
|
|
|
|
$selectorHot = implode(
|
|
|
|
' ', /* Notice this is a space! */
|
|
|
|
array(
|
|
|
|
'flex',
|
|
|
|
'flex--align-c',
|
|
|
|
'flex--justify-space-between',
|
|
|
|
'space--b-2',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Deal Description CSS Selector
|
|
|
|
$selectorDescription = implode(
|
|
|
|
' ', /* Notice this is a space! */
|
|
|
|
array(
|
|
|
|
'cept-description-container',
|
2018-07-25 20:02:31 +02:00
|
|
|
'overflow--wrap-break'
|
2018-03-01 18:10:34 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Deal Date CSS Selector
|
|
|
|
$selectorDate = implode(
|
|
|
|
' ', /* Notice this is a space! */
|
|
|
|
array(
|
|
|
|
'size--all-s',
|
|
|
|
'flex',
|
|
|
|
'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);
|
2018-07-13 01:35:13 +02:00
|
|
|
if ($noresult != null && strpos($noresult->plaintext, $this->i8n('no-results')) !== false) {
|
2018-03-01 18:10:34 +01:00
|
|
|
$this->items = array();
|
|
|
|
} else {
|
2018-07-13 01:35:13 +02:00
|
|
|
foreach ($list as $deal) {
|
2018-03-01 18:10:34 +01:00
|
|
|
$item = array();
|
|
|
|
$item['uri'] = $deal->find('div[class=threadGrid-title]', 0)->find('a', 0)->href;
|
2018-04-06 21:25:41 +02:00
|
|
|
$item['title'] = $deal->find('a[class*='. $selectorLink .']', 0
|
2018-07-13 01:35:13 +02:00
|
|
|
)->plaintext;
|
2018-03-01 18:10:34 +01:00
|
|
|
$item['author'] = $deal->find('span.thread-username', 0)->plaintext;
|
|
|
|
$item['content'] = '<table><tr><td><a href="'
|
|
|
|
. $deal->find(
|
|
|
|
'a[class*='. $selectorImageLink .']', 0)->href
|
2018-07-13 01:35:13 +02:00
|
|
|
. '"><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->getPrice($deal)
|
|
|
|
. $this->getDiscount($deal)
|
|
|
|
. $this->getShipsFrom($deal)
|
|
|
|
. $this->getShippingCost($deal)
|
|
|
|
. $this->GetSource($deal)
|
|
|
|
. $deal->find('div[class*='. $selectorDescription .']', 0)->innertext
|
|
|
|
. '</td><td>'
|
|
|
|
. $deal->find('div[class='. $selectorHot .']', 0)->children(0)->outertext
|
|
|
|
. '</td></table>';
|
2018-06-21 14:14:59 +02:00
|
|
|
$dealDateDiv = $deal->find('div[class*='. $selectorDate .']', 0)
|
2018-03-01 18:10:34 +01:00
|
|
|
->find('span[class=hide--toW3]');
|
|
|
|
$itemDate = end($dealDateDiv)->plaintext;
|
2018-07-13 01:35:13 +02:00
|
|
|
// In case of a Local deal, there is no date, but we can use
|
|
|
|
// this case for other reason (like date not in the last field)
|
|
|
|
if ($this->contains($itemDate, $this->i8n('localdeal'))) {
|
|
|
|
$item['timestamp'] = time();
|
|
|
|
} else if ($this->contains($itemDate, $this->i8n('relative-date-indicator'))) {
|
2018-03-01 18:10:34 +01:00
|
|
|
$item['timestamp'] = $this->relativeDateToTimestamp($itemDate);
|
2018-07-13 01:35:13 +02:00
|
|
|
} else {
|
2018-03-01 18:10:34 +01:00
|
|
|
$item['timestamp'] = $this->parseDate($itemDate);
|
|
|
|
}
|
|
|
|
$this->items[] = $item;
|
2018-02-14 12:03:44 +01:00
|
|
|
}
|
2017-09-05 21:03:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-13 01:35:13 +02:00
|
|
|
/**
|
|
|
|
* Check if the string $str contains any of the string of the array $arr
|
|
|
|
* @return boolean true if the string matched anything otherwise false
|
|
|
|
*/
|
|
|
|
private function contains($str, array $arr)
|
|
|
|
{
|
|
|
|
foreach ($arr as $a) {
|
|
|
|
if (stripos($str, $a) !== false) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-02-14 12:03:44 +01:00
|
|
|
/**
|
|
|
|
* Get the Price from a Deal if it exists
|
|
|
|
* @return string String of the deal price
|
|
|
|
*/
|
2018-07-13 01:35:13 +02:00
|
|
|
private function getPrice($deal)
|
2018-02-14 12:03:44 +01:00
|
|
|
{
|
2018-07-13 01:35:13 +02:00
|
|
|
if ($deal->find(
|
2018-02-14 12:03:44 +01:00
|
|
|
'span[class*=thread-price]', 0) != null) {
|
2018-07-13 01:35:13 +02:00
|
|
|
return '<div>'.$this->i8n('price') .' : '
|
2018-02-14 12:03:44 +01:00
|
|
|
. $deal->find(
|
|
|
|
'span[class*=thread-price]', 0
|
|
|
|
)->plaintext
|
|
|
|
. '</div>';
|
|
|
|
} else {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Shipping costs from a Deal if it exists
|
|
|
|
* @return string String of the deal shipping Cost
|
|
|
|
*/
|
2018-07-13 01:35:13 +02:00
|
|
|
private function getShippingCost($deal)
|
2018-02-14 12:03:44 +01:00
|
|
|
{
|
2018-07-13 01:35:13 +02:00
|
|
|
if ($deal->find('span[class*=cept-shipping-price]', 0) != null) {
|
|
|
|
if ($deal->find('span[class*=cept-shipping-price]', 0)->children(0) != null) {
|
|
|
|
return '<div>'. $this->i8n('shipping') .' : '
|
|
|
|
. $deal->find('span[class*=cept-shipping-price]', 0)->children(0)->innertext
|
|
|
|
. '</div>';
|
2018-02-14 12:03:44 +01:00
|
|
|
} else {
|
2018-07-13 01:35:13 +02:00
|
|
|
return '<div>'. $this->i8n('shipping') .' : '
|
|
|
|
. $deal->find('span[class*=cept-shipping-price]', 0)->innertext
|
|
|
|
. '</div>';
|
2018-02-14 12:03:44 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the source of a Deal if it exists
|
|
|
|
* @return string String of the deal source
|
|
|
|
*/
|
2018-07-13 01:35:13 +02:00
|
|
|
private function GetSource($deal)
|
2018-02-14 12:03:44 +01:00
|
|
|
{
|
2018-07-13 01:35:13 +02:00
|
|
|
if ($deal->find('a[class=text--color-greyShade]', 0) != null) {
|
|
|
|
return '<div>'. $this->i8n('origin') .' : '
|
2018-02-14 12:03:44 +01:00
|
|
|
. $deal->find('a[class=text--color-greyShade]', 0)->outertext
|
|
|
|
. '</div>';
|
|
|
|
} else {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the original Price and discout from a Deal if it exists
|
|
|
|
* @return string String of the deal original price and discount
|
|
|
|
*/
|
2018-07-13 01:35:13 +02:00
|
|
|
private function getDiscount($deal)
|
2018-02-14 12:03:44 +01:00
|
|
|
{
|
2018-07-13 01:35:13 +02:00
|
|
|
if ($deal->find('span[class*=mute--text text--lineThrough]', 0) != null) {
|
2018-05-29 10:52:13 +02:00
|
|
|
$discountHtml = $deal->find('span[class=space--ml-1 size--all-l size--fromW3-xl]', 0);
|
2018-07-13 01:35:13 +02:00
|
|
|
if ($discountHtml != null) {
|
2018-05-29 10:52:13 +02:00
|
|
|
$discount = $discountHtml->plaintext;
|
|
|
|
} else {
|
|
|
|
$discount = '';
|
|
|
|
}
|
2018-07-13 01:35:13 +02:00
|
|
|
return '<div>'. $this->i8n('discount') .' : <span style="text-decoration: line-through;">'
|
2018-02-14 12:03:44 +01:00
|
|
|
. $deal->find(
|
|
|
|
'span[class*=mute--text text--lineThrough]', 0
|
2018-07-13 01:35:13 +02:00
|
|
|
)->plaintext
|
2018-02-14 12:03:44 +01:00
|
|
|
. '</span> '
|
2018-05-29 10:52:13 +02:00
|
|
|
. $discount
|
2018-02-14 12:03:44 +01:00
|
|
|
. '</div>';
|
|
|
|
} else {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Picture URL from a Deal if it exists
|
|
|
|
* @return string String of the deal Picture URL
|
|
|
|
*/
|
|
|
|
private function getImage($deal)
|
|
|
|
{
|
|
|
|
$selectorLazy = implode(
|
|
|
|
' ', /* Notice this is a space! */
|
|
|
|
array(
|
|
|
|
'thread-image',
|
|
|
|
'width--all-auto',
|
|
|
|
'height--all-auto',
|
|
|
|
'imgFrame-img',
|
|
|
|
'cept-thread-img',
|
|
|
|
'img--dummy',
|
|
|
|
'js-lazy-img'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2018-07-13 01:35:13 +02:00
|
|
|
$selectorPlain = implode(
|
2018-02-14 12:03:44 +01:00
|
|
|
' ', /* Notice this is a space! */
|
|
|
|
array(
|
|
|
|
'thread-image',
|
|
|
|
'width--all-auto',
|
|
|
|
'height--all-auto',
|
|
|
|
'imgFrame-img',
|
|
|
|
'cept-thread-img'
|
|
|
|
)
|
|
|
|
);
|
2018-07-13 01:35:13 +02:00
|
|
|
if ($deal->find('img[class='. $selectorLazy .']', 0) != null) {
|
2018-02-14 12:03:44 +01:00
|
|
|
return json_decode(
|
|
|
|
html_entity_decode(
|
|
|
|
$deal->find('img[class='. $selectorLazy .']', 0)
|
2018-07-13 01:35:13 +02:00
|
|
|
->getAttribute('data-lazy-img')))->{'src'};
|
2018-02-14 12:03:44 +01:00
|
|
|
} else {
|
2018-07-13 01:35:13 +02:00
|
|
|
return $deal->find('img[class*='. $selectorPlain .']', 0 )->src;
|
2018-02-14 12:03:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-13 01:35:13 +02:00
|
|
|
* Get the originating country from a Deal if it exists
|
2018-02-14 12:03:44 +01:00
|
|
|
* @return string String of the deal originating country
|
|
|
|
*/
|
2018-07-13 01:35:13 +02:00
|
|
|
private function getShipsFrom($deal)
|
2018-02-14 12:03:44 +01:00
|
|
|
{
|
|
|
|
$selector = implode(
|
|
|
|
' ', /* Notice this is a space! */
|
|
|
|
array(
|
|
|
|
'meta-ribbon',
|
|
|
|
'overflow--wrap-off',
|
|
|
|
'space--l-3',
|
|
|
|
'text--color-greyShade'
|
|
|
|
)
|
|
|
|
);
|
2018-07-13 01:35:13 +02:00
|
|
|
if ($deal->find('span[class='. $selector .']', 0) != null) {
|
2018-02-14 12:03:44 +01:00
|
|
|
return '<div>'
|
|
|
|
. $deal->find('span[class='. $selector .']', 0)->children(2)->plaintext
|
|
|
|
. '</div>';
|
|
|
|
} else {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-13 01:35:13 +02:00
|
|
|
* Transforms a local date into a timestamp
|
2018-02-14 12:03:44 +01:00
|
|
|
* @return int timestamp of the input date
|
|
|
|
*/
|
|
|
|
private function parseDate($string)
|
|
|
|
{
|
2018-07-13 01:35:13 +02:00
|
|
|
$month_local = $this->i8n('local-months');
|
2018-02-14 12:03:44 +01:00
|
|
|
$month_en = array(
|
|
|
|
'January',
|
|
|
|
'February',
|
|
|
|
'March',
|
|
|
|
'April',
|
|
|
|
'May',
|
|
|
|
'June',
|
|
|
|
'July',
|
|
|
|
'August',
|
|
|
|
'September',
|
|
|
|
'October',
|
|
|
|
'November',
|
|
|
|
'December'
|
|
|
|
);
|
|
|
|
|
2018-07-13 01:35:13 +02:00
|
|
|
// A date can be prfixed with some words, we remove theme
|
|
|
|
$string = $this->removeDatePrefixes($string);
|
|
|
|
// We translate the local months name in the english one
|
|
|
|
$date_str = trim(str_replace($month_local, $month_en, $string));
|
|
|
|
|
|
|
|
// If the date does not contain any year, we add the current year
|
|
|
|
if (!preg_match('/[0-9]{4}/', $string)) {
|
2018-02-14 12:03:44 +01:00
|
|
|
$date_str .= ' ' . date('Y');
|
|
|
|
}
|
2018-07-13 01:35:13 +02:00
|
|
|
|
|
|
|
// Add the Hour and minutes
|
2018-02-14 12:03:44 +01:00
|
|
|
$date_str .= ' 00:00';
|
|
|
|
|
|
|
|
$date = DateTime::createFromFormat('j F Y H:i', $date_str);
|
|
|
|
return $date->getTimestamp();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-13 01:35:13 +02:00
|
|
|
* Remove the prefix of a date if it has one
|
|
|
|
* @return the date without prefiux
|
|
|
|
*/
|
|
|
|
private function removeDatePrefixes($string)
|
|
|
|
{
|
|
|
|
$string = str_replace($this->i8n('date-prefixes'), array(), $string);
|
|
|
|
return $string;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the suffix of a relative date if it has one
|
|
|
|
* @return the relative date without suffixes
|
|
|
|
*/
|
|
|
|
private function removeRelativeDateSuffixes($string)
|
|
|
|
{
|
|
|
|
if (count($this->i8n('relative-date-ignore-suffix')) > 0) {
|
|
|
|
$string = preg_replace($this->i8n('relative-date-ignore-suffix'), '', $string);
|
|
|
|
}
|
|
|
|
return $string;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transforms a relative local date into a timestamp
|
2018-02-14 12:03:44 +01:00
|
|
|
* @return int timestamp of the input date
|
|
|
|
*/
|
2017-09-05 21:03:21 +02:00
|
|
|
private function relativeDateToTimestamp($str) {
|
|
|
|
$date = new DateTime();
|
2018-07-13 01:35:13 +02:00
|
|
|
|
|
|
|
// In case of update date, replace it by the regular relative date first word
|
|
|
|
$str = str_replace($this->i8n('relative-date-alt-prefixes'), $this->i8n('local-time-relative')[0], $str);
|
|
|
|
|
|
|
|
$str = $this->removeRelativeDateSuffixes($str);
|
|
|
|
|
|
|
|
$search = $this->i8n('local-time-relative');
|
|
|
|
|
2017-09-19 02:08:22 +02:00
|
|
|
$replace = array(
|
|
|
|
'-',
|
|
|
|
'minute',
|
|
|
|
'hour',
|
|
|
|
'day',
|
|
|
|
'month',
|
2018-02-14 12:03:44 +01:00
|
|
|
'year',
|
|
|
|
''
|
2017-09-19 02:08:22 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$date->modify(str_replace($search, $replace, $str));
|
2017-09-05 21:03:21 +02:00
|
|
|
return $date->getTimestamp();
|
|
|
|
}
|
|
|
|
|
2018-07-13 01:35:13 +02:00
|
|
|
/**
|
|
|
|
* Returns the RSS Feed title according to the parameters
|
|
|
|
* @return string the RSS feed Tiyle
|
|
|
|
*/
|
2018-03-01 18:10:34 +01:00
|
|
|
public function getName(){
|
|
|
|
switch($this->queriedContext) {
|
2018-07-13 01:35:13 +02:00
|
|
|
case $this->i8n('context-keyword'):
|
|
|
|
return $this->i8n('bridge-name') . ' - '. $this->i8n('title-keyword') .' : '. $this->getInput('q');
|
2018-03-01 18:10:34 +01:00
|
|
|
break;
|
2018-07-13 01:35:13 +02:00
|
|
|
case $this->i8n('context-group'):
|
|
|
|
$values = $this->getParameters()[$this->i8n('context-group')]['group']['values'];
|
|
|
|
$group = array_search($this->getInput('group'), $values);
|
|
|
|
return $this->i8n('bridge-name') . ' - '. $this->i8n('title-group'). ' : '. $group;
|
2018-03-01 18:10:34 +01:00
|
|
|
break;
|
|
|
|
default: // Return default value
|
2018-07-13 01:35:13 +02:00
|
|
|
return static::NAME;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is some "localisation" function that returns the needed content using
|
|
|
|
* the "$lang" class variable in the local class
|
|
|
|
* @return various the local content needed
|
|
|
|
*/
|
2018-08-05 15:53:45 +02:00
|
|
|
protected function i8n($key)
|
2018-07-13 01:35:13 +02:00
|
|
|
{
|
|
|
|
if (array_key_exists($key, $this->lang)) {
|
|
|
|
return $this->lang[$key];
|
|
|
|
} else {
|
|
|
|
return null;
|
2018-03-01 18:10:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-05 21:03:21 +02:00
|
|
|
}
|