From cb490c0eaca27b320339db0074acdd8c990cc3e0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 8 Oct 2021 11:06:28 +0200 Subject: [PATCH] Allow twitter cards per page. --- htdocs/core/lib/website.lib.php | 58 +++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/htdocs/core/lib/website.lib.php b/htdocs/core/lib/website.lib.php index 20380e02aab..dbb4f494e51 100644 --- a/htdocs/core/lib/website.lib.php +++ b/htdocs/core/lib/website.lib.php @@ -734,6 +734,64 @@ function getStructuredData($type, $data = array()) return $ret; } +/** + * Return HTML content to add as header card for an article, news or Blog Post or home page. + * + * @param array $params Array of parameters + * @return string HTML content + */ +function getSocialNetworkHeaderCards($params = null) +{ + global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs; // Very important. Required to have var available when running inluded containers. + + $out = ''; + + if ($website->virtualhost) { + $pageurl = $websitepage->pageurl; + $title = $websitepage->title; + $image = $websitepage->image; + $companyname = $mysoc->name; + $description = $websitepage->description; + + $pageurl = str_replace('__WEBSITE_KEY__', $website->ref, $pageurl); + $title = str_replace('__WEBSITE_KEY__', $website->ref, $title); + $image = '/medias'.(preg_match('/^\//', $image) ? '' : '/').str_replace('__WEBSITE_KEY__', $website->ref, $image); + $companyname = str_replace('__WEBSITE_KEY__', $website->ref, $companyname); + $description = str_replace('__WEBSITE_KEY__', $website->ref, $description); + + $fullurl = $website->virtualhost.'/'.$websitepage->pageurl.'.php'; + $hashtags = trim(join(' #', array_map('trim', explode(',', $websitepage->keywords)))); + + // Twitter + $out .= ''."\n"; + if (!empty($params) && !empty($params['twitter_account'])) { + $out .= ''."\n"; + $out .= ''."\n"; + } + $out .= ''."\n"; + if ($websitepage->description) { + $out .= ''."\n"; + } + if ($websitepage->image) { + $out .= ''."\n"; + } + //$out .= ''; + /* + $out .= ''; + $out .= ''; + $out .= ''; + $out .= ''; + $out .= ''; + $out .= ''; + $out .= ''; + $out .= ''; + $out .= ''; + */ + } + + return $out; +} + /** * Return HTML content to add structured data for an article, news or Blog Post. *