Skip to content

Commit

Permalink
[HinduTamilBridge] fix image (#4237)
Browse files Browse the repository at this point in the history
  • Loading branch information
tillcash authored Aug 28, 2024
1 parent d51cc8f commit e010fd4
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions bridges/HinduTamilBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class HinduTamilBridge extends FeedExpander
{
const NAME = 'HinduTamil';
const URI = 'https://www.hindutamil.in';
const FEED_BASE_URL = 'https://feeds.feedburner.com/Hindu_Tamil_';
const DESCRIPTION = 'Retrieve full articles from hindutamil.in feeds';
const MAINTAINER = 'tillcash';
const PARAMETERS = [
Expand Down Expand Up @@ -45,8 +46,6 @@ class HinduTamilBridge extends FeedExpander
],
];

const FEED_BASE_URL = 'https://feeds.feedburner.com/Hindu_Tamil_';

public function getName()
{
$topic = $this->getKey('topic');
Expand All @@ -69,34 +68,30 @@ protected function parseItem($item)
return $item;
}

$date = $dom->find('p span.date', 1);
if ($date) {
$item['timestamp'] = $this->toRFC3339($date->plaintext);
}

$image = $dom->find('#LoadArticle figure', 0) ?? '';
$item['content'] = $image . $this->cleanContent($content);
$item['timestamp'] = $this->getTimestamp($dom) ?? $item['timestamp'];
$item['content'] = $this->getImage($dom) . $this->cleanContent($content);

return $item;
}

private function cleanContent($content)
private function cleanContent($content): string
{
foreach ($content->find('div[align="center"], script') as $remove) {
foreach ($content->find('div[align="center"], script, .adsplacement') as $remove) {
$remove->outertext = '';
}

return $content;
return $content->innertext;
}

private function toRFC3339($dateString)
private function getTimestamp($dom): ?string
{
$timestamp = strtotime(trim($dateString));

if ($timestamp === false) {
return null;
}
$date = $dom->find('meta[property="article:published_time"]', 0);
return $date ? $date->getAttribute('content') : null;
}

return date('Y-m-d\TH:i:s', $timestamp) . '+05:30';
private function getImage($dom): string
{
$image = $dom->find('meta[property="og:image"]', 0);
return $image ? sprintf('<p><img src="%s"></p>', $image->getAttribute('content')) : '';
}
}

0 comments on commit e010fd4

Please sign in to comment.