From 2816507545bb7e3da5b0a290692576b8d2ee335f Mon Sep 17 00:00:00 2001 From: Hannes Mannerheim Date: Thu, 11 Feb 2016 17:48:57 +0100 Subject: [PATCH] twitter cards and opengraph --- actions/qvitter.php | 50 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/actions/qvitter.php b/actions/qvitter.php index b7edba9..b01cec8 100644 --- a/actions/qvitter.php +++ b/actions/qvitter.php @@ -174,24 +174,66 @@ class QvitterAction extends ApiAction } } - // oembed discovery for local notices + // oembed discovery for local notices, and twitter cards if(substr($_SERVER['REQUEST_URI'],0,8) == '/notice/' && $this->arg('notice') && array_key_exists('Oembed', StatusNet::getActivePlugins())) { $notice = Notice::getKV('id', $this->arg('notice')); + if($notice instanceof Notice) { - if ($notice->isLocal()) { + $profile = $notice->getProfile(); + if ($notice->isLocal() && $profile instanceof Profile) { + + // maybe get thumbnail url + $embed_thumbnail_url = false; + $attachments = $notice->attachments(); + if (!empty($attachments)) { + foreach ($attachments as $attachment) { + if(is_object($attachment)) { + try { + $thumb = $attachment->getThumbnail(); + } catch (ServerException $e) { + // + } + if(!empty($thumb) && method_exists('File_thumbnail','url')) { + try { + $embed_thumbnail_url = File_thumbnail::url($thumb->filename); + break; // only first one + } catch (ClientException $e) { + // + } + } + } + } + } + try { $notice_url = $notice->getUrl(); - print ''; - print ''; + print ''."\n"; + print ''."\n"; } catch (Exception $e) { // } + + // twitter cards + print ''."\n"; + print ''."\n"; + print ''."\n"; + if($embed_thumbnail_url) { + print ''."\n"; + } + + // opengraph + print ''."\n"; + print ''."\n"; + if($embed_thumbnail_url) { + print ''."\n"; + } } } } + ?>