ParuVenduImmoBridge.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. class ParuVenduImmoBridge extends BridgeAbstract {
  3. const MAINTAINER = 'polo2ro';
  4. const NAME = 'Paru Vendu Immobilier';
  5. const URI = 'http://www.paruvendu.fr';
  6. const CACHE_TIMEOUT = 10800; // 3h
  7. const DESCRIPTION = 'Returns the ads from the first page of search result.';
  8. const PARAMETERS = array( array(
  9. 'minarea' => array(
  10. 'name' => 'Minimal surface m²',
  11. 'type' => 'number'
  12. ),
  13. 'maxprice' => array(
  14. 'name' => 'Max price',
  15. 'type' => 'number'
  16. ),
  17. 'pa' => array(
  18. 'name' => 'Country code',
  19. 'exampleValue' => 'FR'
  20. ),
  21. 'lo' => array(
  22. 'name' => 'department numbers or postal codes, comma-separated'
  23. )
  24. ));
  25. public function collectData(){
  26. $html = getSimpleHTMLDOM($this->getURI())
  27. or returnServerError('Could not request paruvendu.');
  28. foreach($html->find('div.annonce a') as $element){
  29. if(!$element->title){
  30. continue;
  31. }
  32. $img = '';
  33. foreach($element->find('span.img img') as $img){
  34. if($img->original){
  35. $img = '<img src="' . $img->original . '" />';
  36. }
  37. }
  38. $desc = $element->find('span.desc')[0]->innertext;
  39. $desc = str_replace("voir l'annonce", '', $desc);
  40. $price = $element->find('span.price')[0]->innertext;
  41. list($href) = explode('#', $element->href);
  42. $item = array();
  43. $item['uri'] = self::URI . $href;
  44. $item['title'] = $element->title;
  45. $item['content'] = $img . $desc . $price;
  46. $this->items[] = $item;
  47. }
  48. }
  49. public function getURI(){
  50. $appartment = '&tbApp=1&tbDup=1&tbChb=1&tbLof=1&tbAtl=1&tbPla=1';
  51. $maison = '&tbMai=1&tbVil=1&tbCha=1&tbPro=1&tbHot=1&tbMou=1&tbFer=1';
  52. $link = self::URI
  53. . '/immobilier/annonceimmofo/liste/listeAnnonces?tt=1'
  54. . $appartment
  55. . $maison;
  56. if($this->getInput('minarea')){
  57. $link .= '&sur0=' . urlencode($this->getInput('minarea'));
  58. }
  59. if($this->getInput('maxprice')){
  60. $link .= '&px1=' . urlencode($this->getInput('maxprice'));
  61. }
  62. if($this->getInput('pa')){
  63. $link .= '&pa=' . urlencode($this->getInput('pa'));
  64. }
  65. if($this->getInput('lo')){
  66. $link .= '&lo=' . urlencode($this->getInput('lo'));
  67. }
  68. return $link;
  69. }
  70. public function getName(){
  71. $request = '';
  72. $minarea = $this->getInput('minarea');
  73. if(!empty($minarea)){
  74. $request .= ' ' . $minarea . ' m2';
  75. }
  76. $location = $this->getInput('lo');
  77. if(!empty($location)){
  78. $request .= ' In: ' . $location;
  79. }
  80. return 'Paru Vendu Immobilier' . $request;
  81. }
  82. }