From d21f8cebf617aa1f8154b1ec03d5af1b420d489d Mon Sep 17 00:00:00 2001 From: Dag Date: Wed, 11 Oct 2023 18:37:01 +0200 Subject: [PATCH] fix(imgsed): parsing of datetime string (#3738) * refactor * fix(imgsed): parsing of date date_interval_create_from_date_string(): Unknown or bad format (an hour) at position 0 (a) --- bridges/ImgsedBridge.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/bridges/ImgsedBridge.php b/bridges/ImgsedBridge.php index b6385361..e605cf4f 100644 --- a/bridges/ImgsedBridge.php +++ b/bridges/ImgsedBridge.php @@ -43,15 +43,6 @@ class ImgsedBridge extends BridgeAbstract 'https://www.imgsed.com/instagram/' => ['context' => 'Username', 'u' => 'instagram', 'post' => 'on', 'story' => 'on', 'tagged' => 'on'], ]; - public function getURI() - { - if (!is_null($this->getInput('u'))) { - return urljoin(self::URI, '/' . $this->getInput('u') . '/'); - } - - return parent::getURI(); - } - public function collectData() { $username = $this->getInput('u'); @@ -100,9 +91,6 @@ class ImgsedBridge extends BridgeAbstract $isMoreContent = (bool) $post->find('svg', 0); $moreContentNote = $isMoreContent ? '

(multiple images and/or videos)

' : ''; - - - $this->items[] = [ 'uri' => $url, 'author' => $author, @@ -214,15 +202,18 @@ HTML, } } - // Parse date, and transform the date into a timetamp, even in a case of a relative date private function parseDate($content) { + // Parse date, and transform the date into a timetamp, even in a case of a relative date $date = date_create(); $dateString = str_replace(' ago', '', $content); // Special case : 'a day' is not a valid interval in PHP, so replace it with it's PHP equivalenbt : '1 day' if ($dateString == 'a day') { $dateString = '1 day'; } + if ($dateString === 'an hour') { + $dateString = '1 hour'; + } $relativeDate = date_interval_create_from_date_string($dateString); if ($relativeDate) { @@ -235,6 +226,15 @@ HTML, return date_format($date, 'r'); } + public function getURI() + { + if (!is_null($this->getInput('u'))) { + return urljoin(self::URI, '/' . $this->getInput('u') . '/'); + } + + return parent::getURI(); + } + private function convertURLToInstagram($url) { return str_replace(self::URI, self::INSTAGRAMURI, $url);