2014-05-26 02:30:46 +04:00
|
|
|
<?php
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2024-01-20 12:32:30 +03:00
|
|
|
class NextInkBridge extends FeedExpander
|
2022-07-01 16:10:30 +03:00
|
|
|
{
|
2024-01-20 12:32:30 +03:00
|
|
|
const MAINTAINER = 'ORelio';
|
|
|
|
const NAME = 'Next.Ink Bridge';
|
|
|
|
const URI = 'https://www.next.ink/';
|
2022-07-01 16:10:30 +03:00
|
|
|
const DESCRIPTION = 'Returns the newest articles.';
|
|
|
|
|
|
|
|
const PARAMETERS = [ [
|
|
|
|
'feed' => [
|
|
|
|
'name' => 'Feed',
|
|
|
|
'type' => 'list',
|
|
|
|
'values' => [
|
2024-01-20 12:32:30 +03:00
|
|
|
'Publications' => [
|
2022-07-01 16:10:30 +03:00
|
|
|
'Toutes nos publications' => 'news',
|
2024-01-20 12:32:30 +03:00
|
|
|
'Droit' => 'news:3',
|
|
|
|
'Économie' => 'news:4',
|
|
|
|
'Flock' => 'news:13',
|
|
|
|
'Hardware' => 'news:9',
|
|
|
|
'IA et algorithmes' => 'news:6',
|
|
|
|
'Internet' => 'news:7',
|
|
|
|
'Logiciel' => 'news:8',
|
|
|
|
'Next' => 'news:14',
|
|
|
|
'Réseaux sociaux' => 'news:5',
|
|
|
|
'Sciences et escpace' => 'news:10',
|
|
|
|
'Sécurité' => 'news:12',
|
|
|
|
'Société numérique' => 'news:11',
|
2022-07-01 16:10:30 +03:00
|
|
|
],
|
2024-01-20 12:32:30 +03:00
|
|
|
'Flux Gratuit' => [
|
|
|
|
'Publications en accès libre' => 'free',
|
2022-07-01 16:10:30 +03:00
|
|
|
],
|
2024-01-20 12:32:30 +03:00
|
|
|
],
|
|
|
|
'title' => <<<EOT
|
|
|
|
To obtain individual #LeBrief articles in your feed reader, generate two feeds:
|
|
|
|
1. "Publications" with "Hide brief": Everything except #LeBrief
|
|
|
|
2. "Flux Gratuit" with "Only Brief": Individual #LeBrief articles
|
|
|
|
There may be a lot of #LeBrief entries at once, increase limit of "Flux Gratuit" to 20.
|
|
|
|
EOT,
|
2022-07-01 16:10:30 +03:00
|
|
|
],
|
|
|
|
'filter_premium' => [
|
|
|
|
'name' => 'Premium',
|
|
|
|
'type' => 'list',
|
|
|
|
'values' => [
|
|
|
|
'No filter' => '0',
|
|
|
|
'Hide Premium' => '1',
|
|
|
|
'Only Premium' => '2'
|
2024-01-20 12:32:30 +03:00
|
|
|
],
|
|
|
|
'title' => 'Note: "Flux Gratuit" already excludes Premium articles.',
|
2022-07-01 16:10:30 +03:00
|
|
|
],
|
|
|
|
'filter_brief' => [
|
|
|
|
'name' => 'Brief',
|
|
|
|
'type' => 'list',
|
|
|
|
'values' => [
|
|
|
|
'No filter' => '0',
|
|
|
|
'Hide Brief' => '1',
|
|
|
|
'Only Brief' => '2'
|
2024-01-20 12:32:30 +03:00
|
|
|
],
|
|
|
|
'title' => 'Note: "Publications" has only one #LeBrief entry each day.',
|
2022-07-01 16:10:30 +03:00
|
|
|
],
|
|
|
|
'limit' => self::LIMIT,
|
|
|
|
]];
|
|
|
|
|
|
|
|
public function collectData()
|
|
|
|
{
|
2024-01-20 12:32:30 +03:00
|
|
|
$limit = $this->getInput('limit') ?? 10;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2024-01-20 12:32:30 +03:00
|
|
|
$feed = explode(':', $this->getInput('feed'));
|
|
|
|
$category = '';
|
|
|
|
if (count($feed) > 1) {
|
|
|
|
$category = $feed[1];
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2024-01-20 12:32:30 +03:00
|
|
|
$feed = $feed[0];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2024-01-20 12:32:30 +03:00
|
|
|
if ($feed === 'news') {
|
|
|
|
// Scrap HTML listing to build list of articles
|
|
|
|
$url = self::URI;
|
|
|
|
if ($category !== '') {
|
|
|
|
$url = $url . '?category=' . $category;
|
|
|
|
}
|
|
|
|
$this->collectArticlesFromHtmlListing($url, $limit);
|
|
|
|
} else if ($feed === 'free') {
|
|
|
|
// Expand Free RSS feed
|
|
|
|
$url = self::URI . 'feed/free';
|
|
|
|
$this->collectExpandableDatas($url, $limit);
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-20 12:32:30 +03:00
|
|
|
protected function collectArticlesFromHtmlListing($url, $limit)
|
2022-07-01 16:10:30 +03:00
|
|
|
{
|
2024-01-20 12:32:30 +03:00
|
|
|
$html = getSimpleHTMLDOM($url);
|
|
|
|
$html = convertLazyLoading($html);
|
|
|
|
foreach ($html->find('.block-article') as $article) {
|
|
|
|
$author = $article->find('.author', 0);
|
|
|
|
$subtitle = $article->find('h3', 0);
|
|
|
|
$item = [
|
|
|
|
'uri' => trim($article->find('a', 0)->href),
|
|
|
|
'title' => trim($article->find('h2', 0)->plaintext),
|
|
|
|
'author' => is_object($author) ? trim($author->plaintext) : '',
|
|
|
|
'enclosures' => [ $article->find('img', 0)->src ],
|
|
|
|
'content' => is_object($subtitle) ? trim($subtitle->plaintext) : '',
|
|
|
|
];
|
|
|
|
$item = $this->parseItem($item);
|
|
|
|
if ($item !== null) {
|
|
|
|
$this->items[] = $item;
|
|
|
|
if (--$limit == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-20 12:32:30 +03:00
|
|
|
protected function parseItem(array $item)
|
2022-07-01 16:10:30 +03:00
|
|
|
{
|
2024-01-20 12:32:30 +03:00
|
|
|
$html = getSimpleHTMLDOMCached($item['uri']);
|
|
|
|
$html = convertLazyLoading($html);
|
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
if (!is_object($html)) {
|
2024-01-20 12:32:30 +03:00
|
|
|
$item['content'] = $item['content']
|
|
|
|
. '<p><em>Failed to request Next.ink: ' . $item['uri'] . '</em></p>';
|
|
|
|
return $item;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Filter premium and brief articles?
|
2024-01-20 12:32:30 +03:00
|
|
|
$paywall_selector = 'div#paywall';
|
|
|
|
$brief_selector = 'div.brief-article';
|
2022-07-01 16:10:30 +03:00
|
|
|
foreach (
|
|
|
|
[
|
2024-01-20 12:32:30 +03:00
|
|
|
'filter_premium' => $paywall_selector,
|
|
|
|
'filter_brief' => $brief_selector,
|
2022-07-01 16:10:30 +03:00
|
|
|
] as $param_name => $selector
|
|
|
|
) {
|
|
|
|
$param_val = intval($this->getInput($param_name));
|
|
|
|
if ($param_val != 0) {
|
|
|
|
$element_present = is_object($html->find($selector, 0));
|
|
|
|
$element_wanted = ($param_val == 2);
|
|
|
|
if ($element_present != $element_wanted) {
|
|
|
|
return null; //Filter article
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-20 12:32:30 +03:00
|
|
|
$article_content = $html->find('div.article-contenu, ' . $brief_selector, 0);
|
2022-07-01 16:10:30 +03:00
|
|
|
if (is_object($article_content)) {
|
2024-01-20 12:32:30 +03:00
|
|
|
// Clean article content
|
|
|
|
foreach (
|
|
|
|
[
|
|
|
|
'h1',
|
|
|
|
'div.author',
|
|
|
|
'p.brief-categories',
|
|
|
|
'div.thumbnail-mobile',
|
|
|
|
'div#share-bottom',
|
|
|
|
'div.author-info',
|
|
|
|
'div.other-article',
|
|
|
|
'script',
|
|
|
|
] as $item_to_remove
|
|
|
|
) {
|
|
|
|
foreach ($article_content->find($item_to_remove) as $dom_node) {
|
|
|
|
$dom_node->outertext = '';
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Image
|
2024-01-20 12:32:30 +03:00
|
|
|
$postimg = $article_content->find('div.thumbnail', 0);
|
|
|
|
if (empty($item['enclosures']) && is_object($postimg)) {
|
2022-07-01 16:10:30 +03:00
|
|
|
$postimg = $postimg->find('img', 0);
|
|
|
|
if (!empty($postimg->src)) {
|
2024-01-20 12:32:30 +03:00
|
|
|
$item['enclosures'] = [ $postimg->src ];
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
}
|
2024-01-20 12:32:30 +03:00
|
|
|
// Timestamp
|
|
|
|
$published_time = $html->find('meta[property=article:published_time]', 0);
|
|
|
|
if (!isset($item['timestamp']) && is_object($published_time)) {
|
|
|
|
$item['timestamp'] = strtotime($published_time->content);
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
// Paywall
|
2024-01-20 12:32:30 +03:00
|
|
|
$paywall = $article_content->find($paywall_selector, 0);
|
|
|
|
if (is_object($paywall) && is_object($paywall->find('h3', 0))) {
|
|
|
|
$paywall->outertext = '<p><em>' . $paywall->find('h3', 0)->innertext . '</em></p>';
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
// Content
|
2024-01-20 12:32:30 +03:00
|
|
|
$item['content'] = $article_content->outertext;
|
2022-07-01 16:10:30 +03:00
|
|
|
} else {
|
2024-01-20 12:32:30 +03:00
|
|
|
$item['content'] = $item['content'] . '<p><em>Failed to retrieve full article content</em></p>';
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
|
2024-01-20 12:32:30 +03:00
|
|
|
return $item;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2014-05-26 02:30:46 +04:00
|
|
|
}
|