From 3881ebcce062b6857d13f98212c50cdcd6b8b49d Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Fri, 11 Oct 2019 00:46:02 +0200 Subject: Better Opengraph markup for channel --- Zotlabs/Module/Channel.php | 49 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 11 deletions(-) (limited to 'Zotlabs/Module/Channel.php') diff --git a/Zotlabs/Module/Channel.php b/Zotlabs/Module/Channel.php index b1639b213..e83b42d67 100644 --- a/Zotlabs/Module/Channel.php +++ b/Zotlabs/Module/Channel.php @@ -111,17 +111,6 @@ class Channel extends Controller { // we start loading content profile_load($which,$profile); - - App::$page['htmlhead'] .= '' . "\r\n"; - App::$page['htmlhead'] .= '' . "\r\n"; - - if(App::$profile['about'] && perm_is_allowed($channel['channel_id'],get_observer_hash(),'view_profile')) { - App::$page['htmlhead'] .= '' . "\r\n"; - } - else { - App::$page['htmlhead'] .= '' . "\r\n"; - } - } function get($update = 0, $load = false) { @@ -385,6 +374,44 @@ class Channel extends Controller { $items = array(); } + // Add Opengraph markup + // + if(! empty($items) && isset($decoded)) { + // get post data + if(! empty($r[0]['title'])) + $ogtitle = $r[0]['title']; + + if(preg_match("/\[[zi]mg(=[0-9]+x[0-9]+)?\]([^\[]+)/is", $r[0]['body'], $matches)) + $ogimage = $matches[2]; + + $ogdesc = bbcode($r[0]['body'], [ 'tryoembed' => false ]); + $ogdesc = trim(html2plain($ogdesc, 0, true)); + $ogdesc = html_entity_decode($ogdesc, ENT_QUOTES, 'UTF-8'); + $ogdesc = preg_replace("/https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,\@]+/", "", $ogdesc); + $ogdesc = substr($ogdesc, 0, 280); + $ogdesc = str_replace("\n", " ", $ogdesc); + while (strpos($ogdesc, " ") !== false) + $ogdesc = str_replace(" ", " ", $ogdesc); + if (substr($ogdesc, -1) != "\n") + $ogdesc = rtrim(substr($ogdesc, 0, strrpos($ogdesc, " ")), "?.,:;!-") . "..."; + } + + $channel = channelx_by_n(App::$profile['profile_uid']); + + if(! isset($ogdesc)) { + if(App::$profile['about'] && perm_is_allowed($channel['channel_id'],get_observer_hash(),'view_profile')) { + $ogdesc = App::$profile['about']; + } + else { + $ogdesc = sprintf( t('This is the home page of %s.'), $channel['channel_name']); + } + } + + App::$page['htmlhead'] .= '' . "\r\n"; + App::$page['htmlhead'] .= '' . "\r\n"; + App::$page['htmlhead'] .= '' . "\r\n"; + + if((! $update) && (! $load)) { if($decoded) -- cgit v1.2.3