1
0

LeBonCoinBridge.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * RssBridgeLeBonCoin
  4. * Search LeBonCoin for most recent ads in a specific region and topic.
  5. * Returns the most recent classified ads in results, sorting by date (most recent first).
  6. * Region identifiers : alsace, aquitaine, auvergne, basse_normandie, bourgogne, bretagne, centre,
  7. * champagne_ardenne, corse, franche_comte, haute_normandie, ile_de_france, languedoc_roussillon,
  8. * limousin, lorraine, midi_pyrenees, nord_pas_de_calais, pays_de_la_loire, picardie,
  9. * poitou_charentes, provence_alpes_cote_d_azur, rhone_alpes, guadeloupe, martinique, guyane, reunion.
  10. * 2014-07-22
  11. *
  12. * @name LeBonCoin
  13. * @homepage http://www.leboncoin.fr
  14. * @description Returns most recent results from LeBonCoin for a region and a keyword.
  15. * @maintainer 16mhz
  16. * @use1(r="Region identifier", k="Keyword")
  17. */
  18. class LeBonCoinBridge extends BridgeAbstract{
  19. public function collectData(array $param){
  20. $html = '';
  21. $link = 'http://www.leboncoin.fr/annonces/offres/' . $param[r] . '/?f=a&th=1&q=' . $param[k];
  22. $html = file_get_html($link) or $this->returnError('Could not request LeBonCoin.', 404);
  23. $list = $html->find('.list-lbc', 0);
  24. if($list === NULL) {
  25. return;
  26. }
  27. $tags = $list->find('a');
  28. foreach($tags as $element) {
  29. $item = new \Item();
  30. $item->uri = $element->href;
  31. $title = $element->getAttribute('title');
  32. $content_image = $element->find('div.image', 0)->find('img', 0);
  33. if($content_image !== NULL) {
  34. $content = '<img src="' . $element->find('div.image', 0)->find('img', 0)->getAttribute('src') . '" alt="thumbnail">';
  35. }
  36. $date = $element->find('div.date', 0)->find('div', 0) . $element->find('div.date', 0)->find('div', 1) . '<br/>';
  37. $detailsList = $element->find('div.detail', 0);
  38. for ($i = 1; $i < 4; $i++) {
  39. $line = $detailsList->find('div', $i);
  40. $content .= $line;
  41. }
  42. $item->title = $title . ' - ' . $detailsList->find('div', 3);
  43. $item->content = $content . $date;
  44. $this->items[] = $item;
  45. }
  46. }
  47. public function getName(){
  48. return 'LeBonCoin';
  49. }
  50. public function getURI(){
  51. return 'http://www.leboncoin.fr';
  52. }
  53. public function getCacheDuration(){
  54. return 3600; // 1 hour
  55. }
  56. }