LeBonCoinBridge.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. class LeBonCoinBridge extends BridgeAbstract {
  3. const MAINTAINER = 'jacknumber';
  4. const NAME = 'LeBonCoin';
  5. const URI = 'https://www.leboncoin.fr/';
  6. const DESCRIPTION = 'Returns most recent results from LeBonCoin';
  7. const PARAMETERS = array(
  8. array(
  9. 'k' => array('name' => 'Mot Clé'),
  10. 'r' => array(
  11. 'name' => 'Région',
  12. 'type' => 'list',
  13. 'values' => array(
  14. 'Toute la France' => '',
  15. 'Alsace' => '1',
  16. 'Aquitaine' => '2',
  17. 'Auvergne' => '3',
  18. 'Basse Normandie' => '4',
  19. 'Bourgogne' => '5',
  20. 'Bretagne' => '6',
  21. 'Centre' => '7',
  22. 'Champagne Ardenne' => '8',
  23. 'Corse' => '9',
  24. 'Franche Comté' => '10',
  25. 'Haute Normandie' => '11',
  26. 'Ile de France' => '12',
  27. 'Languedoc Roussillon' => '13',
  28. 'Limousin' => '14',
  29. 'Lorraine' => '15',
  30. 'Midi Pyrénées' => '16',
  31. 'Nord Pas De Calais' => '17',
  32. 'Pays de la Loire' => '18',
  33. 'Picardie' => '19',
  34. 'Poitou Charentes' => '20',
  35. 'Provence Alpes Côte d\'Azur' => '21',
  36. 'Rhône-Alpes' => '22',
  37. 'Guadeloupe' => '23',
  38. 'Martinique' => '24',
  39. 'Guyane' => '25',
  40. 'Réunion' => '26'
  41. )
  42. ),
  43. 'c' => array(
  44. 'name' => 'Catégorie',
  45. 'type' => 'list',
  46. 'values' => array(
  47. 'Toutes catégories' => '',
  48. 'EMPLOI' => array(
  49. 'Emploi et recrutement' => '71',
  50. 'Offres d\'emploi et jobs' => '33'
  51. ),
  52. 'VEHICULES' => array(
  53. 'Tous' => '1',
  54. 'Voitures' => '2',
  55. 'Motos' => '3',
  56. 'Caravaning' => '4',
  57. 'Utilitaires' => '5',
  58. 'Equipement Auto' => '6',
  59. 'Equipement Moto' => '44',
  60. 'Equipement Caravaning' => '50',
  61. 'Nautisme' => '7',
  62. 'Equipement Nautisme' => '51'
  63. ),
  64. 'IMMOBILIER' => array(
  65. 'Tous' => '8',
  66. 'Ventes immobilières' => '9',
  67. 'Locations' => '10',
  68. 'Colocations' => '11',
  69. 'Bureaux & Commerces' => '13'
  70. ),
  71. 'VACANCES' => array(
  72. 'Tous' => '66',
  73. 'Locations & Gîtes' => '12',
  74. 'Chambres d\'hôtes' => '67',
  75. 'Campings' => '68',
  76. 'Hôtels' => '69',
  77. 'Hébergements insolites' => '70'
  78. ),
  79. 'MULTIMEDIA' => array(
  80. 'Tous' => '14',
  81. 'Informatique' => '15',
  82. 'Consoles & Jeux vidéo' => '43',
  83. 'Image & Son' => '16',
  84. 'Téléphonie' => '17'
  85. ),
  86. 'LOISIRS' => array(
  87. 'Tous' => '24',
  88. 'DVD / Films' => '25',
  89. 'CD / Musique' => '26',
  90. 'Livres' => '27',
  91. 'Animaux' => '28',
  92. 'Vélos' => '55',
  93. 'Sports & Hobbies' => '29',
  94. 'Instruments de musique' => '30',
  95. 'Collection' => '40',
  96. 'Jeux & Jouets' => '41',
  97. 'Vins & Gastronomie' => '48'
  98. ),
  99. 'MATERIEL PROFESSIONNEL' => array(
  100. 'Tous' => '56',
  101. 'Matériel Agricole' => '57',
  102. 'Transport - Manutention' => '58',
  103. 'BTP - Chantier Gros-oeuvre' => '59',
  104. 'Outillage - Matériaux 2nd-oeuvre' => '60',
  105. 'Équipements Industriels' => '32',
  106. 'Restauration - Hôtellerie' => '61',
  107. 'Fournitures de Bureau' => '62',
  108. 'Commerces & Marchés' => '63',
  109. 'Matériel Médical' => '64'
  110. ),
  111. 'SERVICES' => array(
  112. 'Tous' => '31',
  113. 'Prestations de services' => '34',
  114. 'Billetterie' => '35',
  115. 'Evénements' => '49',
  116. 'Cours particuliers' => '36',
  117. 'Covoiturage' => '65'
  118. ),
  119. 'MAISON' => array(
  120. 'Tous' => '18',
  121. 'Ameublement' => '19',
  122. 'Electroménager' => '20',
  123. 'Arts de la table' => '45',
  124. 'Décoration' => '39',
  125. 'Linge de maison' => '46',
  126. 'Bricolage' => '21',
  127. 'Jardinage' => '52',
  128. 'Vêtements' => '22',
  129. 'Chaussures' => '53',
  130. 'Accessoires & Bagagerie' => '47',
  131. 'Montres & Bijoux' => '42',
  132. 'Equipement bébé' => '23',
  133. 'Vêtements bébé' => '54',
  134. ),
  135. 'AUTRES' => '37'
  136. )
  137. ),
  138. 'o' => array(
  139. 'name' => 'Vendeur',
  140. 'type' => 'list',
  141. 'values' => array(
  142. 'Tous' => '',
  143. 'Particuliers' => 'private',
  144. 'Professionnels' => 'pro',
  145. )
  146. )
  147. )
  148. );
  149. public function collectData(){
  150. $params = array(
  151. 'text' => $this->getInput('k'),
  152. 'region' => $this->getInput('r'),
  153. 'category' => $this->getInput('c'),
  154. 'owner_type' => $this->getInput('o'),
  155. );
  156. $url = self::URI . 'recherche/?' . http_build_query($params);
  157. $html = getContents($url)
  158. or returnServerError('Could not request LeBonCoin. Tried: ' . $url);
  159. if(!preg_match('/^<script>window.FLUX_STATE[^\r\n]*/m', $html, $matches)) {
  160. returnServerError('Could not parse JSON in page content.');
  161. }
  162. $clean_match = str_replace(
  163. array('</script>', '<script>window.FLUX_STATE = '),
  164. array('', ''),
  165. $matches[0]
  166. );
  167. $json = json_decode($clean_match);
  168. if($json->adSearch->data->total === 0) {
  169. return;
  170. }
  171. foreach($json->adSearch->data->ads as $element) {
  172. $item['title'] = $element->subject;
  173. $item['content'] = $element->body;
  174. $item['date'] = $element->index_date;
  175. $item['timestamp'] = strtotime($element->index_date);
  176. $item['uri'] = $element->url;
  177. $item['ad_type'] = $element->ad_type;
  178. $item['author'] = $element->owner->name;
  179. if(isset($element->location->city)) {
  180. $item['city'] = $element->location->city;
  181. $item['content'] .= ' -- ' . $element->location->city;
  182. }
  183. if(isset($element->location->zipcode)) {
  184. $item['zipcode'] = $element->location->zipcode;
  185. }
  186. if(isset($element->price)) {
  187. $item['price'] = $element->price[0];
  188. $item['content'] .= ' -- ' . current($element->price) . '€';
  189. }
  190. if(isset($element->images->urls)) {
  191. $item['thumbnail'] = $element->images->thumb_url;
  192. $item['enclosures'] = array();
  193. foreach($element->images->urls as $image) {
  194. $item['enclosures'][] = $image;
  195. }
  196. }
  197. $this->items[] = $item;
  198. }
  199. }
  200. }