From 9744f0e7809873bf3bed76b72bcef25e34ebcdd6 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 2 Sep 2018 17:50:27 -0400 Subject: [PATCH] Update ParseUrl::getSiteinfo type recognition - Added obsolete twitter card type provision --- src/Util/ParseUrl.php | 96 +++++++++++++++++++++++-------------------- 1 file changed, 51 insertions(+), 45 deletions(-) diff --git a/src/Util/ParseUrl.php b/src/Util/ParseUrl.php index b897c54ee7..2c134542a0 100644 --- a/src/Util/ParseUrl.php +++ b/src/Util/ParseUrl.php @@ -248,55 +248,61 @@ class ParseUrl } } - if (!empty($meta_tag['content'])) { - $meta_tag['content'] = trim(html_entity_decode($meta_tag['content'], ENT_QUOTES, 'UTF-8')); - - switch (strtolower($meta_tag['name'])) { - case 'fulltitle': - $siteinfo['title'] = trim($meta_tag['content']); - break; - case 'description': - $siteinfo['text'] = trim($meta_tag['content']); - break; - case 'thumbnail': - $siteinfo['image'] = $meta_tag['content']; - break; - case 'twitter:image': - $siteinfo['image'] = $meta_tag['content']; - break; - case 'twitter:image:src': - $siteinfo['image'] = $meta_tag['content']; - break; - case 'twitter:card': - if (($siteinfo['type'] == '') || ($meta_tag['content'] == 'photo')) { - $siteinfo['type'] = $meta_tag['content']; - } - break; - case 'twitter:description': - $siteinfo['text'] = trim($meta_tag['content']); - break; - case 'twitter:title': - $siteinfo['title'] = trim($meta_tag['content']); - break; - case 'dc.title': - $siteinfo['title'] = trim($meta_tag['content']); - break; - case 'dc.description': - $siteinfo['text'] = trim($meta_tag['content']); - break; - case 'keywords': - $keywords = explode(',', $meta_tag['content']); - break; - case 'news_keywords': - $keywords = explode(',', $meta_tag['content']); - break; - } + if (empty($meta_tag['content'])) { + continue; } - if ($siteinfo['type'] == 'summary') { - $siteinfo['type'] = 'link'; + + $meta_tag['content'] = trim(html_entity_decode($meta_tag['content'], ENT_QUOTES, 'UTF-8')); + + switch (strtolower($meta_tag['name'])) { + case 'fulltitle': + $siteinfo['title'] = trim($meta_tag['content']); + break; + case 'description': + $siteinfo['text'] = trim($meta_tag['content']); + break; + case 'thumbnail': + $siteinfo['image'] = $meta_tag['content']; + break; + case 'twitter:image': + $siteinfo['image'] = $meta_tag['content']; + break; + case 'twitter:image:src': + $siteinfo['image'] = $meta_tag['content']; + break; + case 'twitter:card': + // Obsolete card type + if ($meta_tag['content'] == 'photo') { + $siteinfo['type'] = 'summary_large_image'; + } else { + $siteinfo['type'] = $meta_tag['content']; + } + break; + case 'twitter:description': + $siteinfo['text'] = trim($meta_tag['content']); + break; + case 'twitter:title': + $siteinfo['title'] = trim($meta_tag['content']); + break; + case 'dc.title': + $siteinfo['title'] = trim($meta_tag['content']); + break; + case 'dc.description': + $siteinfo['text'] = trim($meta_tag['content']); + break; + case 'keywords': + $keywords = explode(',', $meta_tag['content']); + break; + case 'news_keywords': + $keywords = explode(',', $meta_tag['content']); + break; } } + if ($siteinfo['type'] == 'summary' || $siteinfo['type'] == 'summary_large_image') { + $siteinfo['type'] = 'link'; + } + if (isset($keywords)) { $siteinfo['keywords'] = []; foreach ($keywords as $keyword) { -- 2.39.5