diff --git a/bridges/DonnonsBridge.php b/bridges/DonnonsBridge.php index a33a1013..1afdc4f2 100644 --- a/bridges/DonnonsBridge.php +++ b/bridges/DonnonsBridge.php @@ -1,5 +1,7 @@ getPageURI($page); - $html = getSimpleHTMLDOM($uri); + $dom = getSimpleHTMLDOM($uri); - $searchDiv = $html->find('div[id=search]', 0); + $searchDiv = $dom->find('div[id=search]', 0); - if (!is_null($searchDiv)) { - $elements = $searchDiv->find('a.lst-annonce'); - foreach ($elements as $element) { - $item = []; + if (! $searchDiv) { + return; + } - // Lien vers le don - $item['uri'] = self::URI . $element->href; - // Id de l'objet - $item['uid'] = $element->getAttribute('data-id'); + $elements = $searchDiv->find('a.lst-annonce'); + foreach ($elements as $element) { + $item = []; - // Grab info from json - $jsonString = $element->find('script', 0)->innertext; - $json = json_decode($jsonString, true); + // Lien vers le don + $item['uri'] = self::URI . $element->href; + // Id de l'objet + $item['uid'] = $element->getAttribute('data-id'); - $name = $json['name']; - $category = $json['category']; - $date = $json['availabilityStarts']; - $description = $json['description']; - $city = $json['availableAtOrFrom']['address']['addressLocality']; - $region = $json['availableAtOrFrom']['address']['addressRegion']; + // Grab info from json + $jsonString = $element->find('script', 0)->innertext; + $json = json_decode($jsonString, true); - // Grab info from HTML - $imageSrc = $element->find('img.ima-center', 0)->getAttribute('src'); - // Use large image instead of small one - $imageSrc = str_replace('/xs/', '/lg/', $imageSrc); - $image = self::URI . $imageSrc; - $author = $element->find('div.avatar-holder', 0)->plaintext; + $name = $json['name']; + $category = $json['category']; + $date = $json['availabilityStarts']; + $description = $json['description']; + $city = $json['availableAtOrFrom']['address']['addressLocality']; + $region = $json['availableAtOrFrom']['address']['addressRegion']; - $content = ' - -
-

' . $name . '

-

' . $description . '

-

Lieu : ' . $city . ' - ' . $region . '

-

Par : ' . $author . '

-

Date : ' . $date . '

-
- '; + // Grab info from HTML + $imageSrc = $element->find('img.ima-center', 0)->getAttribute('src'); + // Use large image instead of small one + $imageSrc = str_replace('/xs/', '/lg/', $imageSrc); + $image = self::URI . $imageSrc; + $author = $element->find('div.avatar-holder', 0)->plaintext; - // Titre du don - $item['title'] = '[' . $category . '] ' . $name; - $item['timestamp'] = $date; - $item['author'] = $author; - $item['content'] = $content; - $item['enclosures'] = [$image]; + $content = ' + +
+

' . $name . '

+

' . $description . '

+

Lieu : ' . $city . ' - ' . $region . '

+

Par : ' . $author . '

+

Date : ' . $date . '

+
+ '; - $this->items[] = $item; - } + // Titre du don + $item['title'] = '[' . $category . '] ' . $name; + $item['timestamp'] = $date; + $item['author'] = $author; + $item['content'] = $content; + $item['enclosures'] = [$image]; + + $this->items[] = $item; } }