From 9ad2902addd2cdf17559a1b2927cdf0f5230af63 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Mon, 18 Nov 2019 12:55:02 +0100 Subject: Remove unnecessary brackets --- Zotlabs/Module/Articles.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zotlabs/Module/Articles.php b/Zotlabs/Module/Articles.php index e3ad54be8..f15a15efb 100644 --- a/Zotlabs/Module/Articles.php +++ b/Zotlabs/Module/Articles.php @@ -211,7 +211,7 @@ class Articles extends Controller { } // Add Opengraph markup - opengraph_add_meta(((! empty($items)) ? $r[0] : array()), App::$profile); + opengraph_add_meta((! empty($items) ? $r[0] : array()), App::$profile); $mode = 'articles'; -- cgit v1.2.3 From 5ee133843f166a58e0c6236e543204be8dae70d3 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Mon, 18 Nov 2019 12:55:09 +0100 Subject: Remove base64 decode check on Opengraph tags create --- Zotlabs/Module/Channel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zotlabs/Module/Channel.php b/Zotlabs/Module/Channel.php index 3f617fd18..3bf7ad501 100644 --- a/Zotlabs/Module/Channel.php +++ b/Zotlabs/Module/Channel.php @@ -376,7 +376,7 @@ class Channel extends Controller { } // Add Opengraph markup - opengraph_add_meta((isset($decoded) && (! empty($items)) ? $r[0] : array()), App::$profile); + opengraph_add_meta((! empty($items) ? $r[0] : array()), App::$profile); if((! $update) && (! $load)) { -- cgit v1.2.3 From c7a05264282122162fc43bb680924daf8f22a95f Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Mon, 18 Nov 2019 15:40:51 +0100 Subject: Move back Opengraph markup creation to init stage --- Zotlabs/Module/Channel.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Zotlabs/Module/Channel.php b/Zotlabs/Module/Channel.php index 3bf7ad501..6034bd7da 100644 --- a/Zotlabs/Module/Channel.php +++ b/Zotlabs/Module/Channel.php @@ -110,8 +110,20 @@ class Channel extends Controller { // Run profile_load() here to make sure the theme is set before // we start loading content - profile_load($which,$profile); + + // Add Opengraph markup + $mid = ((x($_REQUEST,'mid')) ? $_REQUEST['mid'] : ''); + if(strpos($mid,'b64.') === 0) + $mid = @base64url_decode(substr($mid,4)); + + if($mid) + $r = q("SELECT * FROM item WHERE mid = '%s' AND uid = %d AND item_private = 0 LIMIT 1", + dbesc($mid), + intval($channel['channel_id']) + ); + + opengraph_add_meta($r ? $r[0] : [], $channel); } function get($update = 0, $load = false) { -- cgit v1.2.3 From dc2f29308959895349ac34b154c14d0f3078bd43 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Mon, 18 Nov 2019 15:42:14 +0100 Subject: Update opengraph.php --- include/opengraph.php | 123 ++++++++++++++++++++++++-------------------------- 1 file changed, 60 insertions(+), 63 deletions(-) diff --git a/include/opengraph.php b/include/opengraph.php index 9de021d54..4c88570d3 100644 --- a/include/opengraph.php +++ b/include/opengraph.php @@ -3,73 +3,70 @@ * @file include/opengraph.php * @brief Add Opengraph metadata and related functions. */ - - + + /** * @brief Adds Opengraph meta tags into HTML head * * @param array $item - * @param array $profile + * @param array $channel * */ - - function opengraph_add_meta($item, $profile) { - - if(! empty($item)) { - - if(! empty($item['title'])) - $ogtitle = $item['title']; - - // find first image if exist - if(preg_match("/\[[zi]mg(=[0-9]+x[0-9]+)?\]([^\[]+)/is", $item['body'], $matches)) { - $ogimage = $matches[2]; - $ogimagetype = guess_image_type($ogimage); - } - - // use summary as description if exist - $ogdesc = (empty($item['summary']) ? $item['body'] : $item['summary'] ); - - $ogdesc = str_replace("#^[", "[", $ogdesc); - - $ogdesc = bbcode($ogdesc, [ 'tryoembed' => false ]); - $ogdesc = trim(html2plain($ogdesc, 0, true)); - $ogdesc = html_entity_decode($ogdesc, ENT_QUOTES, 'UTF-8'); - - // remove all URLs - $ogdesc = preg_replace("/https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,\@]+/", "", $ogdesc); - - // shorten description - $ogdesc = substr($ogdesc, 0, 300); - $ogdesc = str_replace("\n", " ", $ogdesc); - while (strpos($ogdesc, " ") !== false) - $ogdesc = str_replace(" ", " ", $ogdesc); - $ogdesc = (strlen($ogdesc) < 298 ? $ogdesc : rtrim(substr($ogdesc, 0, strrpos($ogdesc, " ")), "?.,:;!-") . "..."); - - $ogtype = "article"; - } - - $channel = channelx_by_n($profile['profile_uid']); - - if(! isset($ogdesc)) { - if($profile['about'] && perm_is_allowed($channel['channel_id'],get_observer_hash(),'view_profile')) { - $ogdesc = $profile['about']; - } - else { - $ogdesc = sprintf( t('This is the home page of %s.'), $channel['channel_name']); - } - } - - if(! isset($ogimage)) { - $ogimage = $channel['xchan_photo_l']; - $ogimagetype = $channel['xchan_photo_mimetype']; - } - - App::$page['htmlhead'] .= '' . "\r\n"; - App::$page['htmlhead'] .= '' . "\r\n"; - App::$page['htmlhead'] .= '' . "\r\n"; - App::$page['htmlhead'] .= '' . "\r\n"; - App::$page['htmlhead'] .= '' . "\r\n"; - - return true; + + function opengraph_add_meta($item, $channel) { + + if(! empty($item)) { + + if(! empty($item['title'])) + $ogtitle = $item['title']; + + // find first image if exist + if(preg_match("/\[[zi]mg(=[0-9]+x[0-9]+)?\]([^\[]+)/is", $item['body'], $matches)) { + $ogimage = $matches[2]; + $ogimagetype = guess_image_type($ogimage); + } + + // use summary as description if exist + $ogdesc = (empty($item['summary']) ? $item['body'] : $item['summary'] ); + + $ogdesc = str_replace("#^[", "[", $ogdesc); + + $ogdesc = bbcode($ogdesc, [ 'tryoembed' => false ]); + $ogdesc = trim(html2plain($ogdesc, 0, true)); + $ogdesc = html_entity_decode($ogdesc, ENT_QUOTES, 'UTF-8'); + + // remove all URLs + $ogdesc = preg_replace("/https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,\@]+/", "", $ogdesc); + + // shorten description + $ogdesc = substr($ogdesc, 0, 300); + $ogdesc = str_replace("\n", " ", $ogdesc); + while (strpos($ogdesc, " ") !== false) + $ogdesc = str_replace(" ", " ", $ogdesc); + $ogdesc = (strlen($ogdesc) < 298 ? $ogdesc : rtrim(substr($ogdesc, 0, strrpos($ogdesc, " ")), "?.,:;!-") . "..."); + + $ogtype = "article"; + } + + 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']); + } + } + + if(! isset($ogimage)) { + $ogimage = $channel['xchan_photo_l']; + $ogimagetype = $channel['xchan_photo_mimetype']; + } + + App::$page['htmlhead'] .= '' . "\r\n"; + App::$page['htmlhead'] .= '' . "\r\n"; + App::$page['htmlhead'] .= '' . "\r\n"; + App::$page['htmlhead'] .= '' . "\r\n"; + App::$page['htmlhead'] .= '' . "\r\n"; + + return true; } - \ No newline at end of file -- cgit v1.2.3 From 78868314a72f529be16504409afdbe071444dcc0 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Mon, 18 Nov 2019 15:47:03 +0100 Subject: Use channelx array on Opengraph markup procedure --- Zotlabs/Module/Articles.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zotlabs/Module/Articles.php b/Zotlabs/Module/Articles.php index f15a15efb..44aa4c1ec 100644 --- a/Zotlabs/Module/Articles.php +++ b/Zotlabs/Module/Articles.php @@ -211,7 +211,7 @@ class Articles extends Controller { } // Add Opengraph markup - opengraph_add_meta((! empty($items) ? $r[0] : array()), App::$profile); + opengraph_add_meta((! empty($items) ? $r[0] : array()), $channel); $mode = 'articles'; -- cgit v1.2.3 From 6f1188f44feca7055e4fad2a902dca1fa1d1914f Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Mon, 18 Nov 2019 15:52:59 +0100 Subject: Update Articles.php --- Zotlabs/Module/Articles.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zotlabs/Module/Articles.php b/Zotlabs/Module/Articles.php index 44aa4c1ec..2c43b4764 100644 --- a/Zotlabs/Module/Articles.php +++ b/Zotlabs/Module/Articles.php @@ -211,7 +211,7 @@ class Articles extends Controller { } // Add Opengraph markup - opengraph_add_meta((! empty($items) ? $r[0] : array()), $channel); + opengraph_add_meta((! empty($items) ? $r[0] : []), $channel); $mode = 'articles'; -- cgit v1.2.3