2018-09-13 12:05:07 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class AutoJMBridge extends BridgeAbstract {
|
|
|
|
|
|
|
|
const NAME = 'AutoJM';
|
2019-04-04 23:39:39 +03:00
|
|
|
const URI = 'https://www.autojm.fr/';
|
2018-09-13 12:05:07 +03:00
|
|
|
const DESCRIPTION = 'Suivre les offres de véhicules proposés par AutoJM en fonction des critères de filtrages';
|
|
|
|
const MAINTAINER = 'sysadminstory';
|
|
|
|
const PARAMETERS = array(
|
|
|
|
'Afficher les offres de véhicules disponible en fonction des critères du site AutoJM' => array(
|
|
|
|
'url' => array(
|
2019-04-04 23:39:39 +03:00
|
|
|
'name' => 'URL du modèle',
|
2018-09-13 12:05:07 +03:00
|
|
|
'type' => 'text',
|
|
|
|
'required' => true,
|
|
|
|
'title' => 'URL d\'une recherche avec filtre de véhicules sans le http://www.autojm.fr/',
|
2019-04-04 23:39:39 +03:00
|
|
|
'exampleValue' => 'achat-voitures-neuves-peugeot-nouvelle-308-5p'
|
|
|
|
),
|
|
|
|
'energy' => array(
|
|
|
|
'name' => 'Carburant',
|
|
|
|
'type' => 'list',
|
|
|
|
'values' => array(
|
|
|
|
'-' => '',
|
|
|
|
'Diesel' => 1,
|
|
|
|
'Essence' => 3,
|
|
|
|
'Hybride' => 5
|
|
|
|
),
|
|
|
|
'title' => 'Carburant'
|
|
|
|
),
|
|
|
|
'transmission' => array(
|
|
|
|
'name' => 'Transmission',
|
|
|
|
'type' => 'list',
|
|
|
|
'values' => array(
|
|
|
|
'-' => '',
|
|
|
|
'Automatique' => 1,
|
|
|
|
'Manuelle' => 2
|
|
|
|
),
|
|
|
|
'title' => 'Transmission'
|
|
|
|
),
|
|
|
|
'priceMin' => array(
|
|
|
|
'name' => 'Prix minimum',
|
|
|
|
'type' => 'number',
|
|
|
|
'required' => false,
|
|
|
|
'title' => 'Prix minimum du véhicule',
|
|
|
|
'exampleValue' => '10000',
|
|
|
|
'defaultValue' => '0'
|
|
|
|
),
|
|
|
|
'priceMax' => array(
|
|
|
|
'name' => 'Prix maximum',
|
|
|
|
'type' => 'number',
|
|
|
|
'required' => false,
|
|
|
|
'title' => 'Prix maximum du véhicule',
|
|
|
|
'exampleValue' => '15000',
|
|
|
|
'defaultValue' => '150000'
|
2018-09-13 12:05:07 +03:00
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
const CACHE_TIMEOUT = 3600;
|
|
|
|
|
2018-10-26 19:07:34 +03:00
|
|
|
public function getIcon() {
|
2019-04-04 23:39:39 +03:00
|
|
|
return self::URI . 'favicon.ico';
|
2018-10-26 19:07:34 +03:00
|
|
|
}
|
|
|
|
|
2019-04-20 23:22:06 +03:00
|
|
|
public function getName() {
|
|
|
|
switch($this->queriedContext) {
|
|
|
|
case 'Afficher les offres de véhicules disponible en fonction des critères du site AutoJM':
|
|
|
|
$html = getSimpleHTMLDOMCached(self::URI . $this->getInput('url'), 86400);
|
|
|
|
$name = html_entity_decode($html->find('title', 0)->plaintext);
|
|
|
|
return $name;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return parent::getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-09-13 12:05:07 +03:00
|
|
|
public function collectData() {
|
2019-04-04 23:39:39 +03:00
|
|
|
|
|
|
|
$model_url = self::URI . $this->getInput('url');
|
|
|
|
|
2020-05-17 21:05:04 +03:00
|
|
|
// Build the GET data
|
|
|
|
$get_data = 'form[energy]=' . $this->getInput('energy') .
|
|
|
|
'&form[transmission]=' . $this->getInput('transmission') .
|
|
|
|
'&form[priceMin]=' . $this->getInput('priceMin') .
|
|
|
|
'&form[priceMin]=' . $this->getInput('priceMin');
|
2019-04-04 23:39:39 +03:00
|
|
|
|
2020-05-17 21:05:04 +03:00
|
|
|
// Set the header 'X-Requested-With' like the website does it
|
2019-04-04 23:39:39 +03:00
|
|
|
$header = array(
|
2020-05-17 21:05:04 +03:00
|
|
|
'X-Requested-With: XMLHttpRequest'
|
2019-04-04 23:39:39 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
// Get the JSON content of the form
|
2020-05-17 21:05:04 +03:00
|
|
|
$json = getContents($model_url . '?' . $get_data, $header)
|
2018-09-13 12:05:07 +03:00
|
|
|
or returnServerError('Could not request AutoJM.');
|
2019-04-04 23:39:39 +03:00
|
|
|
|
|
|
|
// Extract the HTML content from the JSON result
|
|
|
|
$data = json_decode($json);
|
2020-05-17 21:05:04 +03:00
|
|
|
$html = str_get_html($data->results);
|
|
|
|
|
|
|
|
// Go through every car of the model
|
|
|
|
$list = $html->find('div[class=car-card]');
|
|
|
|
foreach ($list as $car) {
|
|
|
|
|
|
|
|
// Get the Finish name if this car is the first of a new finish
|
|
|
|
$prev_tag = $car->prev_sibling();
|
|
|
|
if($prev_tag->tag == 'div' && $prev_tag->class == 'results-title') {
|
|
|
|
$finish_name = $prev_tag->plaintext;
|
2019-04-04 23:39:39 +03:00
|
|
|
}
|
|
|
|
|
2020-05-17 21:05:04 +03:00
|
|
|
// Get the info about the car offer
|
|
|
|
$image = $car->find('div[class=car-card__visual]', 0)->find('img', 0)->src;
|
|
|
|
$serie = $car->find('div[class=car-card__title]', 0)->plaintext;
|
|
|
|
$url = $car->find('a', 0)->href;
|
|
|
|
// Check if the car model is in stock or available only on order
|
|
|
|
if($car->find('span[class*=tag--dispo]', 0) != null) {
|
|
|
|
$availability = 'En Stock';
|
|
|
|
} else {
|
|
|
|
$availability = 'Sur commande';
|
2018-09-13 12:05:07 +03:00
|
|
|
}
|
2020-05-17 21:05:04 +03:00
|
|
|
$discount_html = $car->find('span[class=promo]', 0);
|
|
|
|
// Check if there is any discount dsiplayed
|
|
|
|
if ($discount_html != null) {
|
|
|
|
$discount = $discount_html->plaintext;
|
|
|
|
} else {
|
|
|
|
$discount = 'inconnue';
|
|
|
|
}
|
|
|
|
$price = $car->find('span[class=price]', 0)->plaintext;
|
|
|
|
|
|
|
|
// Construct the new item
|
|
|
|
$item = array();
|
|
|
|
$item['title'] = $finish_name . ' ' . $serie;
|
|
|
|
$item['content'] = '<p><img style="vertical-align:middle ; padding: 10px" src="' . $image . '" />'
|
|
|
|
. $finish_name . ' ' . $serie . '</p>';
|
|
|
|
$item['content'] .= '<ul><li>Disponibilité : ' . $availability . '</li>';
|
|
|
|
$item['content'] .= '<li>Série : ' . $serie . '</li>';
|
|
|
|
$item['content'] .= '<li>Remise : ' . $discount . '</li>';
|
|
|
|
$item['content'] .= '<li>Prix : ' . $price . '</li></ul>';
|
|
|
|
|
|
|
|
// Add a fictionnal anchor to the RSS element URL, based on the item content ;
|
|
|
|
// As the URL could be identical even if the price change, some RSS reader will not show those offers as new items
|
|
|
|
$item['uri'] = $url . '#' . md5($item['content']);
|
|
|
|
|
|
|
|
$this->items[] = $item;
|
2018-09-13 12:05:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|