From 7f1fea1e099c4de57613fc291b9ad38d53501778 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 3 Jun 2020 19:23:36 +0200 Subject: [PATCH] Add json-ld structure 'qa' --- htdocs/core/lib/website.lib.php | 47 ++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/htdocs/core/lib/website.lib.php b/htdocs/core/lib/website.lib.php index b158f65c044..8f4886a153b 100644 --- a/htdocs/core/lib/website.lib.php +++ b/htdocs/core/lib/website.lib.php @@ -534,7 +534,7 @@ function includeContainer($containerref) * Return HTML content to add structured data for an article, news or Blog Post. * Use the json-ld format. * - * @param string $type 'blogpost', 'product', 'software', 'organization', ... + * @param string $type 'blogpost', 'product', 'software', 'organization', 'qa', ... * @param array $data Array of data parameters for structured data * @return string HTML content */ @@ -542,6 +542,8 @@ function getStructuredData($type, $data = array()) { global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs, $pagelangs; // Very important. Required to have var available when running inluded containers. + $type = strtolower($type); + if ($type == 'software') { $ret = ''."\n"; @@ -551,12 +553,16 @@ function getStructuredData($type, $data = array()) "@type": "SoftwareApplication", "name": "'.dol_escape_json($data['name']).'", "operatingSystem": "'.dol_escape_json($data['os']).'", - "applicationCategory": "https://schema.org/'.$data['applicationCategory'].'", - "aggregateRating": { - "@type": "AggregateRating", - "ratingValue": "'.$data['ratingvalue'].'", - "ratingCount": "'.$data['ratingcount'].'" - }, + "applicationCategory": "https://schema.org/'.$data['applicationCategory'].'",'; + if (! empty($data['ratingcount'])) { + $ret .= ' + "aggregateRating": { + "@type": "AggregateRating", + "ratingValue": "'.$data['ratingvalue'].'", + "ratingCount": "'.$data['ratingcount'].'" + },'; + } + $ret .= ' "offers": { "@type": "Offer", "price": "'.$data['price'].'", @@ -700,6 +706,33 @@ function getStructuredData($type, $data = array()) } }'."\n"; $ret .= ''."\n"; + } elseif ($type == 'qa') + { + $ret = ''."\n"; + $ret .= ''."\n"; } return $ret; }