diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 9c7d64a6494..35462fcb2d9 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -984,6 +984,16 @@ function dol_escape_js($stringtoescape, $mode = 0, $noescapebackslashn = 0) return strtr($stringtoescape, $substitjs); } +/** + * Returns text escaped for inclusion into javascript code + * + * @param string $stringtoescape String to escape + * @return string Escaped string for json content. + */ +function dol_escape_json($stringtoescape) +{ + return str_replace('"', '\"', $stringtoescape); +} /** * Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields. diff --git a/htdocs/core/lib/website.lib.php b/htdocs/core/lib/website.lib.php index 22c26b10b9b..0d51f779afc 100644 --- a/htdocs/core/lib/website.lib.php +++ b/htdocs/core/lib/website.lib.php @@ -544,8 +544,8 @@ function getStructuredData($type, $data = array()) $ret .= '{ "@context": "https://schema.org", "@type": "SoftwareApplication", - "name": "'.$data['name'].'", - "operatingSystem": "'.$data['os'].'", + "name": "'.dol_escape_json($data['name']).'", + "operatingSystem": "'.dol_escape_json($data['os']).'", "applicationCategory": "https://schema.org/GameApplication", "aggregateRating": { "@type": "AggregateRating", @@ -570,6 +570,18 @@ function getStructuredData($type, $data = array()) if ($restmpuser > 0) { + $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 = str_replace('__WEBSITE_KEY__', $website->ref, $image); + $companyname = str_replace('__WEBSITE_KEY__', $website->ref, $companyname); + $description = str_replace('__WEBSITE_KEY__', $website->ref, $description); + $ret = ''."\n"; $ret .= ''."\n"; } @@ -610,19 +622,19 @@ function getStructuredData($type, $data = array()) $ret .= '{ "@context": "https://schema.org/", "@type": "Product", - "name": "'.$data['label'].'", + "name": "'.dol_escape_json($data['label']).'", "image": [ - "'.$data['image'].'", + "'.dol_escape_json($data['image']).'", ], - "description": "'.$data['description'].'", - "sku": "'.$data['ref'].'", + "description": "'.dol_escape_json($data['description']).'", + "sku": "'.dol_escape_json($data['ref']).'", "brand": { "@type": "Thing", - "name": "'.$data['brand'].'" + "name": "'.dol_escape_json($data['brand']).'" }, "author": { "@type": "Person", - "name": "'.$data['author'].'" + "name": "'.dol_escape_json($data['author']).'" } }, "offers": { @@ -634,7 +646,7 @@ function getStructuredData($type, $data = array()) "availability": "https://schema.org/InStock", "seller": { "@type": "Organization", - "name": "'.$mysoc->name.'" + "name": "'.dol_escape_json($mysoc->name).'" } } }'."\n";