2014-07-22 17:20:43 +02:00
|
|
|
<?php
|
2017-02-11 16:16:56 +01:00
|
|
|
class LeBonCoinBridge extends BridgeAbstract {
|
2014-07-22 17:20:43 +02:00
|
|
|
|
2018-07-16 20:13:08 +02:00
|
|
|
const MAINTAINER = 'jacknumber';
|
2017-02-11 16:16:56 +01:00
|
|
|
const NAME = 'LeBonCoin';
|
2017-03-21 21:27:12 +01:00
|
|
|
const URI = 'https://www.leboncoin.fr/';
|
2018-07-16 20:13:08 +02:00
|
|
|
const DESCRIPTION = 'Returns most recent results from LeBonCoin';
|
2015-11-05 16:50:18 +01:00
|
|
|
|
2017-02-11 16:16:56 +01:00
|
|
|
const PARAMETERS = array(
|
|
|
|
array(
|
|
|
|
'k' => array('name' => 'Mot Clé'),
|
|
|
|
'r' => array(
|
|
|
|
'name' => 'Région',
|
|
|
|
'type' => 'list',
|
|
|
|
'values' => array(
|
2018-07-16 20:13:08 +02:00
|
|
|
'Toute la France' => '',
|
|
|
|
'Alsace' => '1',
|
|
|
|
'Aquitaine' => '2',
|
|
|
|
'Auvergne' => '3',
|
|
|
|
'Basse Normandie' => '4',
|
|
|
|
'Bourgogne' => '5',
|
|
|
|
'Bretagne' => '6',
|
|
|
|
'Centre' => '7',
|
|
|
|
'Champagne Ardenne' => '8',
|
|
|
|
'Corse' => '9',
|
|
|
|
'Franche Comté' => '10',
|
|
|
|
'Haute Normandie' => '11',
|
|
|
|
'Ile de France' => '12',
|
|
|
|
'Languedoc Roussillon' => '13',
|
|
|
|
'Limousin' => '14',
|
|
|
|
'Lorraine' => '15',
|
|
|
|
'Midi Pyrénées' => '16',
|
|
|
|
'Nord Pas De Calais' => '17',
|
|
|
|
'Pays de la Loire' => '18',
|
|
|
|
'Picardie' => '19',
|
|
|
|
'Poitou Charentes' => '20',
|
|
|
|
'Provence Alpes Côte d\'Azur' => '21',
|
|
|
|
'Rhône-Alpes' => '22',
|
|
|
|
'Guadeloupe' => '23',
|
|
|
|
'Martinique' => '24',
|
|
|
|
'Guyane' => '25',
|
|
|
|
'Réunion' => '26'
|
2017-02-11 16:16:56 +01:00
|
|
|
)
|
|
|
|
),
|
2018-08-01 17:25:18 +02:00
|
|
|
'cities' => array('name' => 'Ville'),
|
2017-02-11 16:16:56 +01:00
|
|
|
'c' => array(
|
|
|
|
'name' => 'Catégorie',
|
|
|
|
'type' => 'list',
|
|
|
|
'values' => array(
|
2018-07-16 20:13:08 +02:00
|
|
|
'Toutes catégories' => '',
|
|
|
|
'EMPLOI' => array(
|
|
|
|
'Emploi et recrutement' => '71',
|
|
|
|
'Offres d\'emploi et jobs' => '33'
|
|
|
|
),
|
2017-02-11 16:16:56 +01:00
|
|
|
'VEHICULES' => array(
|
2018-07-16 20:13:08 +02:00
|
|
|
'Tous' => '1',
|
|
|
|
'Voitures' => '2',
|
|
|
|
'Motos' => '3',
|
|
|
|
'Caravaning' => '4',
|
|
|
|
'Utilitaires' => '5',
|
|
|
|
'Equipement Auto' => '6',
|
|
|
|
'Equipement Moto' => '44',
|
|
|
|
'Equipement Caravaning' => '50',
|
|
|
|
'Nautisme' => '7',
|
|
|
|
'Equipement Nautisme' => '51'
|
2017-02-11 16:16:56 +01:00
|
|
|
),
|
|
|
|
'IMMOBILIER' => array(
|
2018-07-16 20:13:08 +02:00
|
|
|
'Tous' => '8',
|
|
|
|
'Ventes immobilières' => '9',
|
|
|
|
'Locations' => '10',
|
|
|
|
'Colocations' => '11',
|
|
|
|
'Bureaux & Commerces' => '13'
|
2017-02-11 16:16:56 +01:00
|
|
|
),
|
|
|
|
'VACANCES' => array(
|
2018-07-16 20:13:08 +02:00
|
|
|
'Tous' => '66',
|
|
|
|
'Locations & Gîtes' => '12',
|
|
|
|
'Chambres d\'hôtes' => '67',
|
|
|
|
'Campings' => '68',
|
|
|
|
'Hôtels' => '69',
|
|
|
|
'Hébergements insolites' => '70'
|
2017-02-11 16:16:56 +01:00
|
|
|
),
|
|
|
|
'MULTIMEDIA' => array(
|
2018-07-16 20:13:08 +02:00
|
|
|
'Tous' => '14',
|
|
|
|
'Informatique' => '15',
|
|
|
|
'Consoles & Jeux vidéo' => '43',
|
|
|
|
'Image & Son' => '16',
|
|
|
|
'Téléphonie' => '17'
|
2017-02-11 16:16:56 +01:00
|
|
|
),
|
|
|
|
'LOISIRS' => array(
|
2018-07-16 20:13:08 +02:00
|
|
|
'Tous' => '24',
|
|
|
|
'DVD / Films' => '25',
|
|
|
|
'CD / Musique' => '26',
|
|
|
|
'Livres' => '27',
|
|
|
|
'Animaux' => '28',
|
|
|
|
'Vélos' => '55',
|
|
|
|
'Sports & Hobbies' => '29',
|
|
|
|
'Instruments de musique' => '30',
|
|
|
|
'Collection' => '40',
|
|
|
|
'Jeux & Jouets' => '41',
|
|
|
|
'Vins & Gastronomie' => '48'
|
2017-02-11 16:16:56 +01:00
|
|
|
),
|
2018-07-16 20:13:08 +02:00
|
|
|
'MATERIEL PROFESSIONNEL' => array(
|
|
|
|
'Tous' => '56',
|
|
|
|
'Matériel Agricole' => '57',
|
|
|
|
'Transport - Manutention' => '58',
|
|
|
|
'BTP - Chantier Gros-oeuvre' => '59',
|
|
|
|
'Outillage - Matériaux 2nd-oeuvre' => '60',
|
|
|
|
'Équipements Industriels' => '32',
|
|
|
|
'Restauration - Hôtellerie' => '61',
|
|
|
|
'Fournitures de Bureau' => '62',
|
|
|
|
'Commerces & Marchés' => '63',
|
|
|
|
'Matériel Médical' => '64'
|
2017-02-11 16:16:56 +01:00
|
|
|
),
|
|
|
|
'SERVICES' => array(
|
2018-07-16 20:13:08 +02:00
|
|
|
'Tous' => '31',
|
|
|
|
'Prestations de services' => '34',
|
|
|
|
'Billetterie' => '35',
|
|
|
|
'Evénements' => '49',
|
|
|
|
'Cours particuliers' => '36',
|
|
|
|
'Covoiturage' => '65'
|
2017-02-11 16:16:56 +01:00
|
|
|
),
|
|
|
|
'MAISON' => array(
|
2018-07-16 20:13:08 +02:00
|
|
|
'Tous' => '18',
|
|
|
|
'Ameublement' => '19',
|
|
|
|
'Electroménager' => '20',
|
|
|
|
'Arts de la table' => '45',
|
|
|
|
'Décoration' => '39',
|
|
|
|
'Linge de maison' => '46',
|
|
|
|
'Bricolage' => '21',
|
|
|
|
'Jardinage' => '52',
|
|
|
|
'Vêtements' => '22',
|
|
|
|
'Chaussures' => '53',
|
|
|
|
'Accessoires & Bagagerie' => '47',
|
|
|
|
'Montres & Bijoux' => '42',
|
|
|
|
'Equipement bébé' => '23',
|
|
|
|
'Vêtements bébé' => '54',
|
2017-02-11 16:16:56 +01:00
|
|
|
),
|
2018-07-16 20:13:08 +02:00
|
|
|
'AUTRES' => '37'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'o' => array(
|
|
|
|
'name' => 'Vendeur',
|
|
|
|
'type' => 'list',
|
|
|
|
'values' => array(
|
|
|
|
'Tous' => '',
|
|
|
|
'Particuliers' => 'private',
|
|
|
|
'Professionnels' => 'pro',
|
2017-02-11 16:16:56 +01:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2015-11-05 16:50:18 +01:00
|
|
|
|
2016-08-25 01:24:53 +02:00
|
|
|
public function collectData(){
|
2016-05-02 00:55:22 +02:00
|
|
|
|
2018-07-16 20:13:08 +02:00
|
|
|
$params = array(
|
|
|
|
'text' => $this->getInput('k'),
|
|
|
|
'region' => $this->getInput('r'),
|
2018-08-01 17:25:18 +02:00
|
|
|
'cities' => $this->getInput('cities'),
|
2018-07-16 20:13:08 +02:00
|
|
|
'category' => $this->getInput('c'),
|
|
|
|
'owner_type' => $this->getInput('o'),
|
|
|
|
);
|
|
|
|
|
|
|
|
$url = self::URI . 'recherche/?' . http_build_query($params);
|
2018-07-17 10:50:30 +02:00
|
|
|
$html = getContents($url)
|
2018-07-16 20:13:08 +02:00
|
|
|
or returnServerError('Could not request LeBonCoin. Tried: ' . $url);
|
|
|
|
|
|
|
|
if(!preg_match('/^<script>window.FLUX_STATE[^\r\n]*/m', $html, $matches)) {
|
|
|
|
returnServerError('Could not parse JSON in page content.');
|
2017-02-11 16:16:56 +01:00
|
|
|
}
|
2016-08-29 12:42:34 +02:00
|
|
|
|
2018-07-16 20:13:08 +02:00
|
|
|
$clean_match = str_replace(
|
|
|
|
array('</script>', '<script>window.FLUX_STATE = '),
|
|
|
|
array('', ''),
|
|
|
|
$matches[0]
|
|
|
|
);
|
|
|
|
$json = json_decode($clean_match);
|
2016-05-02 00:55:22 +02:00
|
|
|
|
2018-07-16 20:13:08 +02:00
|
|
|
if($json->adSearch->data->total === 0) {
|
2016-05-02 00:55:22 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-16 20:13:08 +02:00
|
|
|
foreach($json->adSearch->data->ads as $element) {
|
|
|
|
|
|
|
|
$item['title'] = $element->subject;
|
|
|
|
$item['content'] = $element->body;
|
|
|
|
$item['date'] = $element->index_date;
|
|
|
|
$item['timestamp'] = strtotime($element->index_date);
|
|
|
|
$item['uri'] = $element->url;
|
|
|
|
$item['ad_type'] = $element->ad_type;
|
|
|
|
$item['author'] = $element->owner->name;
|
2016-05-02 00:55:22 +02:00
|
|
|
|
2018-07-16 20:13:08 +02:00
|
|
|
if(isset($element->location->city)) {
|
2016-05-02 00:55:22 +02:00
|
|
|
|
2018-07-16 20:13:08 +02:00
|
|
|
$item['city'] = $element->location->city;
|
|
|
|
$item['content'] .= ' -- ' . $element->location->city;
|
2016-05-02 00:55:22 +02:00
|
|
|
|
2018-07-16 20:13:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(isset($element->location->zipcode)) {
|
|
|
|
$item['zipcode'] = $element->location->zipcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isset($element->price)) {
|
|
|
|
|
|
|
|
$item['price'] = $element->price[0];
|
|
|
|
$item['content'] .= ' -- ' . current($element->price) . '€';
|
2016-05-02 00:55:22 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-07-16 20:13:08 +02:00
|
|
|
if(isset($element->images->urls)) {
|
|
|
|
|
|
|
|
$item['thumbnail'] = $element->images->thumb_url;
|
|
|
|
$item['enclosures'] = array();
|
2016-05-02 00:55:22 +02:00
|
|
|
|
2018-07-16 20:13:08 +02:00
|
|
|
foreach($element->images->urls as $image) {
|
|
|
|
$item['enclosures'][] = $image;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2016-05-02 00:55:22 +02:00
|
|
|
|
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
2016-07-08 19:06:35 +02:00
|
|
|
}
|