summaryrefslogtreecommitdiff
path: root/bridges/NextInpactBridge.php
diff options
context:
space:
mode:
authorJohannes 'josch' Schauer <josch@debian.org>2020-11-10 13:17:03 +0100
committerJohannes 'josch' Schauer <josch@debian.org>2020-11-10 13:17:03 +0100
commitdaeb2c0913653d197fad2a75010cfc6034c6a9e8 (patch)
treed25328f98ca39a5ac8abad156b5e8f5781505a3c /bridges/NextInpactBridge.php
parent432eb165b83d4483780a279b02929b05b3e09fa5 (diff)
New upstream version 2020-11-10+dfsg1
Diffstat (limited to 'bridges/NextInpactBridge.php')
-rw-r--r--bridges/NextInpactBridge.php128
1 files changed, 101 insertions, 27 deletions
diff --git a/bridges/NextInpactBridge.php b/bridges/NextInpactBridge.php
index c6bf2f5..c3cca30 100644
--- a/bridges/NextInpactBridge.php
+++ b/bridges/NextInpactBridge.php
@@ -1,9 +1,10 @@
<?php
class NextInpactBridge extends FeedExpander {
- const MAINTAINER = 'qwertygc';
+ const MAINTAINER = 'qwertygc and ORelio';
const NAME = 'NextInpact Bridge';
const URI = 'https://www.nextinpact.com/';
+ const URI_HARDWARE = 'https://www.inpact-hardware.com/';
const DESCRIPTION = 'Returns the newest articles.';
const PARAMETERS = array( array(
@@ -11,10 +12,30 @@ class NextInpactBridge extends FeedExpander {
'name' => 'Feed',
'type' => 'list',
'values' => array(
- 'Tous nos articles' => 'news',
- 'Nos contenus en accès libre' => 'acces-libre',
- 'Blog' => 'blog',
- 'Bons plans' => 'bonsplans'
+ 'Nos actualités' => array(
+ 'Toutes nos publications' => 'news',
+ 'Toutes nos publications sauf #LeBrief' => 'nobrief',
+ 'Toutes nos publications sauf INpact Hardware' => 'noih',
+ 'Seulement les publications INpact Hardware' => 'hardware:news',
+ 'Seulement les publications Next INpact' => 'nobrief-noih',
+ 'Seulement les publications #LeBrief' => 'lebrief',
+ ),
+ 'Flux spécifiques' => array(
+ 'Le blog' => 'blog',
+ 'Les bons plans' => 'bonsplans',
+ 'Publications INpact Hardware en accès libre' => 'hardware:acces-libre',
+ 'Publications Next INpact en accès libre' => 'acces-libre',
+ ),
+ 'Flux thématiques' => array(
+ 'Tech' => 'category:1',
+ 'Logiciel' => 'category:2',
+ 'Internet' => 'category:3',
+ 'Mobilité' => 'category:4',
+ 'Droit' => 'category:5',
+ 'Économie' => 'category:6',
+ 'Culture numérique' => 'category:7',
+ 'Next INpact' => 'category:8',
+ )
)
),
'filter_premium' => array(
@@ -39,9 +60,27 @@ class NextInpactBridge extends FeedExpander {
public function collectData(){
$feed = $this->getInput('feed');
- if (empty($feed))
+ $base_uri = self::URI;
+ $args = '';
+
+ if (empty($feed)) {
+ // Default to All articles
$feed = 'news';
- $this->collectExpandableDatas(self::URI . 'rss/' . $feed . '.xml');
+ }
+
+ if (strpos($feed, 'hardware:') === 0) {
+ // Feed hosted on Hardware domain
+ $base_uri = self::URI_HARDWARE;
+ $feed = str_replace('hardware:', '', $feed);
+ }
+
+ if (strpos($feed, 'category:') === 0) {
+ // Feed with specific category parameter
+ $args = '?CategoryIds=' . str_replace('category:', '', $feed);
+ $feed = 'params';
+ }
+
+ $this->collectExpandableDatas($base_uri . 'rss/' . $feed . '.xml' . $args);
}
protected function parseItem($newsItem){
@@ -57,9 +96,11 @@ class NextInpactBridge extends FeedExpander {
if (!is_object($html))
return 'Failed to request NextInpact: ' . $url;
+ // Filter premium and brief articles?
+ $brief_selector = 'div.brief-container';
foreach(array(
- 'filter_premium' => 'h2.title_reserve_article',
- 'filter_brief' => 'div.brief-inner-content'
+ 'filter_premium' => 'p.red-msg',
+ 'filter_brief' => $brief_selector
) as $param_name => $selector) {
$param_val = intval($this->getInput($param_name));
if ($param_val != 0) {
@@ -71,38 +112,71 @@ class NextInpactBridge extends FeedExpander {
}
}
- if (is_object($html->find('div[itemprop=articleBody], div.brief-inner-content', 0))) {
+ $article_content = $html->find('div.article-content', 0);
+ if (!is_object($article_content)) {
+ $article_content = $html->find('div.content', 0);
+ }
+ if (is_object($article_content)) {
- $subtitle = trim($html->find('span.sub_title, div.brief-head', 0));
- if(is_object($subtitle) && $subtitle->plaintext !== $item['title']) {
- $subtitle = '<p><em>' . $subtitle->plaintext . '</em></p>';
+ // Subtitle
+ $subtitle = $html->find('small.subtitle', 0);
+ if(!is_object($subtitle) && !is_object($html->find($brief_selector, 0))) {
+ $subtitle = $html->find('small', 0);
+ }
+ if(!is_object($subtitle)) {
+ $content_wrapper = $html->find('div.content-wrapper', 0);
+ if (is_object($content_wrapper)) {
+ $subtitle = $content_wrapper->find('h2.title', 0);
+ }
+ }
+ if(is_object($subtitle) && (!isset($item['title']) || $subtitle->plaintext != $item['title'])) {
+ $subtitle = '<p><em>' . trim($subtitle->plaintext) . '</em></p>';
} else {
$subtitle = '';
}
- $postimg = $html->find(
- 'div.container_main_image_article, div.image-brief-container, div.image-brief-side-container', 0
- );
+ // Image
+ $postimg = $html->find('div.article-image, div.image-container', 0);
if(is_object($postimg)) {
- $postimg = '<p><img src="'
- . $postimg->find('img.dedicated', 0)->src
- . '" alt="-" /></p>';
+ $postimg = $postimg->find('img', 0);
+ if (!empty($postimg->src)) {
+ $postimg = $postimg->src;
+ } else {
+ $postimg = $postimg->srcset; //"url 355w, url 1003w, url 748w"
+ $postimg = explode(', ', $postimg); //split by ', ' to get each url separately
+ $postimg = end($postimg); //Get last item: "url 748w" which is of largest size
+ $postimg = explode(' ', $postimg); //split by ' ' to separate url from res
+ $postimg = array_reverse($postimg); //reverse array content to have url last
+ $postimg = end($postimg); //Get last item of array: "url"
+ }
+ $postimg = '<p><img src="' . $postimg . '" alt="-" /></p>';
} else {
$postimg = '';
}
+ // Paywall
+ $paywall = $html->find('div.paywall-restriction', 0);
+ if (is_object($paywall) && is_object($paywall->find('p.red-msg', 0))) {
+ $paywall = '<p><em>' . $paywall->find('span.head-mention', 0)->innertext . '</em></p>';
+ } else {
+ $paywall = '';
+ }
+
+ // Content
+ $article_content = $article_content->outertext;
+ $article_content = str_replace('>Signaler une erreur</span>', '></span>', $article_content);
+
+ // Result
$text = $subtitle
. $postimg
- . $html->find('div[itemprop=articleBody], div.brief-inner-content', 0)->outertext;
+ . $article_content
+ . $paywall;
} else {
- $text = $item['content']
- . '<p><em>Failed retrieve full article content</em></p>';
- }
-
- $premium_article = $html->find('h2.title_reserve_article', 0);
- if (is_object($premium_article)) {
- $text .= '<p><em>' . $premium_article->innertext . '</em></p>';
+ $text = '<p><em>Failed to retrieve full article content</em></p>';
+ if (isset($item['content'])) {
+ $text = $item['content'] . $text;
+ }
}
return $text;