mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-01-24 12:03:46 +03:00
refactor(donnons) (#4389)
This commit is contained in:
parent
3fc38c15a3
commit
662e0bfa95
1 changed files with 47 additions and 43 deletions
|
@ -1,5 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retourne les dons d'une recherche filtrée sur le site Donnons.org
|
* Retourne les dons d'une recherche filtrée sur le site Donnons.org
|
||||||
* Example: https://donnons.org/Sport/Ile-de-France
|
* Example: https://donnons.org/Sport/Ile-de-France
|
||||||
|
@ -44,58 +46,60 @@ class DonnonsBridge extends BridgeAbstract
|
||||||
{
|
{
|
||||||
$uri = $this->getPageURI($page);
|
$uri = $this->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)) {
|
if (! $searchDiv) {
|
||||||
$elements = $searchDiv->find('a.lst-annonce');
|
return;
|
||||||
foreach ($elements as $element) {
|
}
|
||||||
$item = [];
|
|
||||||
|
|
||||||
// Lien vers le don
|
$elements = $searchDiv->find('a.lst-annonce');
|
||||||
$item['uri'] = self::URI . $element->href;
|
foreach ($elements as $element) {
|
||||||
// Id de l'objet
|
$item = [];
|
||||||
$item['uid'] = $element->getAttribute('data-id');
|
|
||||||
|
|
||||||
// Grab info from json
|
// Lien vers le don
|
||||||
$jsonString = $element->find('script', 0)->innertext;
|
$item['uri'] = self::URI . $element->href;
|
||||||
$json = json_decode($jsonString, true);
|
// Id de l'objet
|
||||||
|
$item['uid'] = $element->getAttribute('data-id');
|
||||||
|
|
||||||
$name = $json['name'];
|
// Grab info from json
|
||||||
$category = $json['category'];
|
$jsonString = $element->find('script', 0)->innertext;
|
||||||
$date = $json['availabilityStarts'];
|
$json = json_decode($jsonString, true);
|
||||||
$description = $json['description'];
|
|
||||||
$city = $json['availableAtOrFrom']['address']['addressLocality'];
|
|
||||||
$region = $json['availableAtOrFrom']['address']['addressRegion'];
|
|
||||||
|
|
||||||
// Grab info from HTML
|
$name = $json['name'];
|
||||||
$imageSrc = $element->find('img.ima-center', 0)->getAttribute('src');
|
$category = $json['category'];
|
||||||
// Use large image instead of small one
|
$date = $json['availabilityStarts'];
|
||||||
$imageSrc = str_replace('/xs/', '/lg/', $imageSrc);
|
$description = $json['description'];
|
||||||
$image = self::URI . $imageSrc;
|
$city = $json['availableAtOrFrom']['address']['addressLocality'];
|
||||||
$author = $element->find('div.avatar-holder', 0)->plaintext;
|
$region = $json['availableAtOrFrom']['address']['addressRegion'];
|
||||||
|
|
||||||
$content = '
|
// Grab info from HTML
|
||||||
<img style="margin-right:1em;" src="' . $image . '">
|
$imageSrc = $element->find('img.ima-center', 0)->getAttribute('src');
|
||||||
<div>
|
// Use large image instead of small one
|
||||||
<h1>' . $name . '</h1>
|
$imageSrc = str_replace('/xs/', '/lg/', $imageSrc);
|
||||||
<p>' . $description . '</p>
|
$image = self::URI . $imageSrc;
|
||||||
<p>Lieu : <b>' . $city . '</b> - ' . $region . '</p>
|
$author = $element->find('div.avatar-holder', 0)->plaintext;
|
||||||
<p>Par : ' . $author . '</p>
|
|
||||||
<p>Date : ' . $date . '</p>
|
|
||||||
</div>
|
|
||||||
';
|
|
||||||
|
|
||||||
// Titre du don
|
$content = '
|
||||||
$item['title'] = '[' . $category . '] ' . $name;
|
<img style="margin-right:1em;" src="' . $image . '">
|
||||||
$item['timestamp'] = $date;
|
<div>
|
||||||
$item['author'] = $author;
|
<h1>' . $name . '</h1>
|
||||||
$item['content'] = $content;
|
<p>' . $description . '</p>
|
||||||
$item['enclosures'] = [$image];
|
<p>Lieu : <b>' . $city . '</b> - ' . $region . '</p>
|
||||||
|
<p>Par : ' . $author . '</p>
|
||||||
|
<p>Date : ' . $date . '</p>
|
||||||
|
</div>
|
||||||
|
';
|
||||||
|
|
||||||
$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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue