From eba98d57e998ec22eab105dd6d087a10a3d4c0d2 Mon Sep 17 00:00:00 2001 From: Thomas Portelange Date: Thu, 26 Jan 2017 10:48:02 +0100 Subject: [PATCH 1/2] get main og image if getOGImage returns an array, handle it gracefully --- code/ShareCare.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/code/ShareCare.php b/code/ShareCare.php index d704062..33ae759 100755 --- a/code/ShareCare.php +++ b/code/ShareCare.php @@ -154,7 +154,7 @@ public function GooglePlusShareLink() */ public function PinterestShareLink() { - $pinImage = ($this->owner->hasMethod('getPinterestImage')) ? $this->owner->getPinterestImage() : $this->owner->getOGImage(); + $pinImage = ($this->owner->hasMethod('getPinterestImage')) ? $this->owner->getPinterestImage() : $this->owner->getMainOGImage(); if ($pinImage) { // OGImage may be an Image object or an absolute URL $imageURL = rawurlencode((is_string($pinImage)) ? $pinImage : $pinImage->getAbsoluteURL()); @@ -198,7 +198,7 @@ public function getTwitterMetaTags() ."\n"; // If we have a big enough image, include an image tag. - $image = $this->owner->getOGImage(); + $image = $this->owner->getMainOGImage(); // $image may be a string - don't generate a specific twitter tag // in that case as it is probably the default resource. if ($image instanceof Image && $image->getWidth() >= 280) { @@ -236,6 +236,20 @@ public function getDefaultOGTitle() return $this->owner->getTitle(); } + /** + * Get the main OG image (even if it's an array of images) + * + * @return string + */ + public function getMainOGImage() + { + $image = $this->owner->getOGImage(); + if (is_array($image)) { + $image = $image[0]; + } + return $image; + } + /** * The default/fallback Image object or absolute URL to be used in the 'og:image' open graph tag. * From 0e232e564f079dae1ee8ee4f3fabf19233f2bdcf Mon Sep 17 00:00:00 2001 From: Thomas Portelange Date: Thu, 26 Jan 2017 10:48:53 +0100 Subject: [PATCH 2/2] update template --- templates/ShareCarePreview.ss | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/templates/ShareCarePreview.ss b/templates/ShareCarePreview.ss index c39f3f6..0d59aeb 100644 --- a/templates/ShareCarePreview.ss +++ b/templates/ShareCarePreview.ss @@ -45,22 +45,22 @@
- + <% if $IncludePinterest %>