From ef0b86968c36c2303abe72aebe6388b948ebddb7 Mon Sep 17 00:00:00 2001 From: User123698745 Date: Fri, 7 Jul 2023 08:16:45 +0200 Subject: [PATCH] [PicnobBridge] fix missing images (#3506) * [PicnobBridge] fix missing images * [PicnobBridge] handle invalid relative date (e.g.: 'Just now') * [PicnobBridge] fix code indent --- bridges/PicnobBridge.php | 49 ++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/bridges/PicnobBridge.php b/bridges/PicnobBridge.php index 6e010e64..68241a8c 100644 --- a/bridges/PicnobBridge.php +++ b/bridges/PicnobBridge.php @@ -47,37 +47,36 @@ class PicnobBridge extends BridgeAbstract $html = getSimpleHTMLDOM($this->getURI()); foreach ($html->find('.items') as $part) { foreach ($part->find('.item') as $element) { - $url = urljoin(self::URI, $element->find('a', 0)->href); + $url = urljoin(self::URI, $element->find('a', 0)->href); + $date = date_create(); + $relativeDate = date_interval_create_from_date_string(str_replace(' ago', '', $element->find('.time', 0)->plaintext)); + if ($relativeDate) { + date_sub($date, $relativeDate); + } - $date = date_create(); - $relativeDate = str_replace(' ago', '', $element->find('.time', 0)->plaintext); - date_sub($date, date_interval_create_from_date_string($relativeDate)); + $description = defaultLinkTo(trim($element->find('.sum', 0)->innertext), self::URI); - $description = defaultLinkTo(trim($element->find('.sum', 0)->innertext), self::URI); + $isVideo = (bool) $element->find('.icon_video', 0); + $videoNote = $isVideo ? '

(video)

' : ''; - $isVideo = (bool) $element->find('.icon_video', 0); - $videoNote = $isVideo ? '

(video)

' : ''; + $isTV = (bool) $element->find('.icon_tv', 0); + $tvNote = $isTV ? '

(TV)

' : ''; - $isTV = (bool) $element->find('.icon_tv', 0); - $tvNote = $isTV ? '

(TV)

' : ''; + $isMoreContent = (bool) $element->find('.icon_multi', 0); + $moreContentNote = $isMoreContent ? '

(multiple images and/or videos)

' : ''; - $isMoreContent = (bool) $element->find('.icon_multi', 0); - $moreContentNote = $isMoreContent ? '

(multiple images and/or videos)

' : ''; + $imageUrl = $element->find('.img', 0)->getAttribute('data-src'); - $imageUrl = $element->find('.img', 0)->getAttribute('data-src'); - parse_str(parse_url($imageUrl, PHP_URL_QUERY), $imageVars); - $imageUrl = $imageVars['u']; + $uid = explode('/', parse_url($url, PHP_URL_PATH))[2]; - $uid = explode('/', parse_url($url, PHP_URL_PATH))[2]; - - $this->items[] = [ - 'uri' => $url, - 'timestamp' => date_format($date, 'r'), - 'title' => strlen($description) > 60 ? mb_substr($description, 0, 57) . '...' : $description, - 'thumbnail' => $imageUrl, - 'enclosures' => [$imageUrl], - 'content' => <<items[] = [ + 'uri' => $url, + 'timestamp' => date_format($date, 'r'), + 'title' => strlen($description) > 60 ? mb_substr($description, 0, 57) . '...' : $description, + 'thumbnail' => $imageUrl, + 'enclosures' => [$imageUrl], + 'content' => << @@ -86,8 +85,8 @@ class PicnobBridge extends BridgeAbstract {$moreContentNote}

{$description}

HTML, - 'uid' => $uid - ]; + 'uid' => $uid + ]; } } }