2014-07-22 14:55:22 +02:00
|
|
|
<?php
|
|
|
|
|
2017-02-11 16:16:56 +01:00
|
|
|
class MondeDiploBridge extends BridgeAbstract
|
2022-07-01 15:10:30 +02:00
|
|
|
{
|
2017-02-11 16:16:56 +01:00
|
|
|
const MAINTAINER = 'Pitchoule';
|
2016-08-30 11:23:55 +02:00
|
|
|
const NAME = 'Monde Diplomatique';
|
2020-08-27 07:28:59 +02:00
|
|
|
const URI = 'https://www.monde-diplomatique.fr';
|
2016-09-25 17:04:28 +02:00
|
|
|
const CACHE_TIMEOUT = 21600; //6h
|
2017-02-11 16:16:56 +01:00
|
|
|
const DESCRIPTION = 'Returns most recent results from MondeDiplo.';
|
2015-11-04 09:47:21 +00:00
|
|
|
|
2020-10-15 12:53:19 +05:00
|
|
|
private function cleanText($text)
|
|
|
|
{
|
|
|
|
return trim(str_replace([' ', ' '], ' ', $text));
|
|
|
|
}
|
2020-08-27 07:28:59 +02:00
|
|
|
|
2016-08-25 01:24:53 +02:00
|
|
|
public function collectData()
|
|
|
|
{
|
2022-01-02 14:36:09 +05:00
|
|
|
$html = getSimpleHTMLDOM(self::URI);
|
2016-08-03 21:08:35 +02:00
|
|
|
|
2017-07-29 19:28:00 +02:00
|
|
|
foreach ($html->find('div.unarticle') as $article) {
|
2016-08-03 21:08:35 +02:00
|
|
|
$element = $article->parent();
|
2025-01-15 20:50:56 +01:00
|
|
|
$titleElement = $element->find('h3', 0);
|
|
|
|
if (!$titleElement) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$title = $titleElement->plaintext;
|
|
|
|
$datesAuteursElement = $element->find('div.dates_auteurs', 0);
|
|
|
|
$datesAuteurs = is_null($datesAuteursElement) ? '' : $element->find('div.dates_auteurs', 0)->plaintext;
|
2016-08-22 18:55:59 +02:00
|
|
|
$item = [];
|
2021-03-25 18:15:02 +01:00
|
|
|
$item['uri'] = urljoin(self::URI, $element->href);
|
2025-01-15 20:50:56 +01:00
|
|
|
$item['title'] = $this->getItemTitle($title, $datesAuteurs);
|
2020-10-15 12:53:19 +05:00
|
|
|
$item['content'] = $this->cleanText(str_replace([$title, $datesAuteurs], '', $element->plaintext));
|
2017-02-11 16:16:56 +01:00
|
|
|
|
2016-08-03 21:08:35 +02:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
2025-01-15 20:50:56 +01:00
|
|
|
|
|
|
|
private function getItemTitle($title, $datesAuteurs)
|
|
|
|
{
|
|
|
|
$itemTitle = $this->cleanText($title);
|
|
|
|
if (strlen($datesAuteurs) > 0) {
|
|
|
|
$itemTitle .= ' - ' . $this->cleanText($datesAuteurs);
|
|
|
|
}
|
|
|
|
return $itemTitle;
|
|
|
|
}
|
2014-07-22 14:55:22 +02:00
|
|
|
}
|