Merge pull request #5732 from annando/fix-picture-posts
authorHypolite Petovan <mrpetovan@eml.cc>
Thu, 6 Sep 2018 23:00:44 +0000 (19:00 -0400)
committerGitHub <noreply@github.com>
Thu, 6 Sep 2018 23:00:44 +0000 (19:00 -0400)
Fix: Posts with pictures will now look good again on connector networks

mod/photos.php
src/Content/Text/BBCode.php
src/Util/ParseUrl.php

index 5fb6ba3..16af455 100644 (file)
@@ -1633,7 +1633,7 @@ function photos_content(App $a)
                        '$paginate' => $paginate,
                ]);
 
-               $a->page['htmlhead'] .= "\n" . '<meta name="twitter:card" content="photo" />' . "\n";
+               $a->page['htmlhead'] .= "\n" . '<meta name="twitter:card" content="summary_large_image" />' . "\n";
                $a->page['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
                $a->page['htmlhead'] .= '<meta name="twitter:image" content="' . $photo["href"] . '" />' . "\n";
                $a->page['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
index 55fc242..2dc13ae 100644 (file)
@@ -572,14 +572,17 @@ class BBCode extends BaseObject
                                        $return = sprintf('<div class="type-%s">', $data["type"]);
                                }
 
-                               if (!empty($data["image"])) {
-                                       $return .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-image" /></a><br />', $data["url"], self::proxyUrl($data["image"], $simplehtml), $data["title"]);
-                               } elseif (!empty($data["preview"])) {
-                                       $return .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-preview" /></a><br />', $data["url"], self::proxyUrl($data["preview"], $simplehtml), $data["title"]);
-                               }
-
                                if (!empty($data['title']) && !empty($data['url'])) {
-                                       $return .= sprintf('<h4><a href="%s">%s</a></h4>', $data['url'], $data['title']);
+                                       if (!empty($data["image"]) && empty($data["text"]) && ($data["type"] == "photo")) {
+                                               $return .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-image" /></a>', $data["url"], self::proxyUrl($data["image"], $simplehtml), $data["title"]);
+                                       } else {
+                                               if (!empty($data["image"])) {
+                                                       $return .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-image" /></a><br />', $data["url"], self::proxyUrl($data["image"], $simplehtml), $data["title"]);
+                                               } elseif (!empty($data["preview"])) {
+                                                       $return .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-preview" /></a><br />', $data["url"], self::proxyUrl($data["preview"], $simplehtml), $data["title"]);
+                                               }
+                                               $return .= sprintf('<h4><a href="%s">%s</a></h4>', $data['url'], $data['title']);
+                                       }
                                }
 
                                if (!empty($data["description"]) && $data["description"] != $data["title"]) {
index 2c13454..dd39a05 100644 (file)
@@ -271,11 +271,9 @@ class ParseUrl
                                        $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'];
+                                       // Detect photo pages
+                                       if ($meta_tag['content'] == 'summary_large_image') {
+                                               $siteinfo['type'] = 'photo';
                                        }
                                        break;
                                case 'twitter:description':
@@ -299,10 +297,6 @@ class ParseUrl
                        }
                }
 
-               if ($siteinfo['type'] == 'summary' || $siteinfo['type'] == 'summary_large_image') {
-                       $siteinfo['type'] = 'link';
-               }
-
                if (isset($keywords)) {
                        $siteinfo['keywords'] = [];
                        foreach ($keywords as $keyword) {
@@ -338,6 +332,11 @@ class ParseUrl
                        }
                }
 
+               // Prevent to have a photo type without an image
+               if (empty($siteinfo['image']) && ($siteinfo['type'] == 'photo')) {
+                       $siteinfo['type'] = 'link';
+               }
+
                if ((@$siteinfo['image'] == '') && !$no_guessing) {
                        $list = $xpath->query('//img[@src]');
                        foreach ($list as $node) {