From 648a876d77a7591eac6c4ad5f14b30988e18ce20 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 9 Oct 2022 15:43:30 +0200 Subject: Add support for custom XPath date/time format (#4703) * Add support for custom XPath date/time format #fix https://github.com/FreshRSS/FreshRSS/issues/4701 Improvement of https://github.com/FreshRSS/FreshRSS/pull/4220 * Format is not XPath * Remove TODOs in en-GB --- app/Models/Feed.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'app/Models') diff --git a/app/Models/Feed.php b/app/Models/Feed.php index a81f1c561..5efe55006 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -612,6 +612,7 @@ class FreshRSS_Feed extends Minz_Model { $xPathItemUri = $xPathSettings['itemUri'] ?? ''; $xPathItemAuthor = $xPathSettings['itemAuthor'] ?? ''; $xPathItemTimestamp = $xPathSettings['itemTimestamp'] ?? ''; + $xPathItemTimeFormat = $xPathSettings['itemTimeFormat'] ?? ''; $xPathItemThumbnail = $xPathSettings['itemThumbnail'] ?? ''; $xPathItemCategories = $xPathSettings['itemCategories'] ?? ''; $xPathItemUid = $xPathSettings['itemUid'] ?? ''; @@ -652,6 +653,12 @@ class FreshRSS_Feed extends Minz_Model { $item['link'] = $xPathItemUri == '' ? '' : @$xpath->evaluate('normalize-space(' . $xPathItemUri . ')', $node); $item['author'] = $xPathItemAuthor == '' ? '' : @$xpath->evaluate('normalize-space(' . $xPathItemAuthor . ')', $node); $item['timestamp'] = $xPathItemTimestamp == '' ? '' : @$xpath->evaluate('normalize-space(' . $xPathItemTimestamp . ')', $node); + if ($xPathItemTimeFormat != '') { + $dateTime = DateTime::createFromFormat($xPathItemTimeFormat, $item['timestamp'] ?? ''); + if ($dateTime != false) { + $item['timestamp'] = $dateTime->format(DateTime::ATOM); + } + } $item['thumbnail'] = $xPathItemThumbnail == '' ? '' : @$xpath->evaluate('normalize-space(' . $xPathItemThumbnail . ')', $node); if ($xPathItemCategories != '') { $itemCategories = @$xpath->query($xPathItemCategories, $node); -- cgit v1.2.3