From 3bd4b0d6ab1e03f1849b4c0154558e7c1b70d9e8 Mon Sep 17 00:00:00 2001
From: csisoap <33269526+csisoap@users.noreply.github.com>
Date: Wed, 2 Mar 2022 11:50:02 +0700
Subject: [PATCH] [ReutersBridge] Fix unexpected behaviour with article (#2478)
Sometimes, there are some articles that redirected to another site,
cause the bridge to fail.
Also about disable UID, Reuters frequently updated their article and my
feed reader don't update, I think it's maybe its UID.
---
bridges/ReutersBridge.php | 40 +++++++++++++++++++++++++++++----------
1 file changed, 30 insertions(+), 10 deletions(-)
diff --git a/bridges/ReutersBridge.php b/bridges/ReutersBridge.php
index 1dd8269b..5e6bbffc 100644
--- a/bridges/ReutersBridge.php
+++ b/bridges/ReutersBridge.php
@@ -305,7 +305,13 @@ class ReutersBridge extends BridgeAbstract
foreach($images as $image) { // Add more image to article.
$image_url = $image['url'];
$image_caption = $image['caption'];
- $img = "
";
+ $image_alt_text = '';
+ if(isset($image['alt_text'])) {
+ $image_alt_text = $image['alt_text'];
+ } else {
+ $image_alt_text = $image_caption;
+ }
+ $img = "
";
$img_caption = "$image_caption";
$figure = "$img \t $img_caption";
$img_placeholder = $img_placeholder . $figure;
@@ -482,6 +488,7 @@ EOD;
$timestamp = '';
$url = '';
$article_uri = '';
+ $source_type = '';
if($this->useWireAPI) {
$uid = $story['story']['usn'];
$article_uri = $story['template_action']['api_path'];
@@ -492,18 +499,31 @@ EOD;
$url = self::URI . $story['canonical_url'];
$title = $story['title'];
$article_uri = $story['canonical_url'];
+ $source_type = $story['source']['name'];
}
- $content_detail = $this->getArticle($article_uri);
- $description = $content_detail['content'];
- $description = defaultLinkTo($description, $this->getURI());
- $author = $content_detail['author'];
- $images = $content_detail['images'];
- $category = $content_detail['category'];
- $content = "$description $images";
- $timestamp = $content_detail['published_at'];
+ // Some article cause unexpected behaviour like redirect to another site not API.
+ // Attempt to check article source type to avoid this.
+ if($source_type == 'composer') { // Only Reuters PF api have this, Wire don't.
+ $author = $this->handleAuthorName($story['authors']);
+ $timestamp = $story['published_time'];
+ $image_placeholder = '';
+ if (isset($story['thumbnail'])) {
+ $image_placeholder = $this->handleImage(array($story['thumbnail']));
+ }
+ $content = $story['description'] . $image_placeholder;
+ } else {
+ $content_detail = $this->getArticle($article_uri);
+ $description = $content_detail['content'];
+ $description = defaultLinkTo($description, $this->getURI());
+
+ $author = $content_detail['author'];
+ $images = $content_detail['images'];
+ $category = $content_detail['category'];
+ $content = "$description $images";
+ $timestamp = $content_detail['published_at'];
+ }
- $item['uid'] = $uid;
$item['categories'] = $category;
$item['author'] = $author;
$item['content'] = $content;