forked from Wavyzz/dolibarr
Add dol_escape_json method
This commit is contained in:
@@ -984,6 +984,16 @@ function dol_escape_js($stringtoescape, $mode = 0, $noescapebackslashn = 0)
|
|||||||
return strtr($stringtoescape, $substitjs);
|
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.
|
* Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
|
||||||
|
|||||||
@@ -544,8 +544,8 @@ function getStructuredData($type, $data = array())
|
|||||||
$ret .= '{
|
$ret .= '{
|
||||||
"@context": "https://schema.org",
|
"@context": "https://schema.org",
|
||||||
"@type": "SoftwareApplication",
|
"@type": "SoftwareApplication",
|
||||||
"name": "'.$data['name'].'",
|
"name": "'.dol_escape_json($data['name']).'",
|
||||||
"operatingSystem": "'.$data['os'].'",
|
"operatingSystem": "'.dol_escape_json($data['os']).'",
|
||||||
"applicationCategory": "https://schema.org/GameApplication",
|
"applicationCategory": "https://schema.org/GameApplication",
|
||||||
"aggregateRating": {
|
"aggregateRating": {
|
||||||
"@type": "AggregateRating",
|
"@type": "AggregateRating",
|
||||||
@@ -570,6 +570,18 @@ function getStructuredData($type, $data = array())
|
|||||||
|
|
||||||
if ($restmpuser > 0)
|
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 = '<!-- Add structured data for blog post -->'."\n";
|
$ret = '<!-- Add structured data for blog post -->'."\n";
|
||||||
$ret .= '<script type="application/ld+json">'."\n";
|
$ret .= '<script type="application/ld+json">'."\n";
|
||||||
$ret .= '{
|
$ret .= '{
|
||||||
@@ -577,11 +589,11 @@ function getStructuredData($type, $data = array())
|
|||||||
"@type": "NewsArticle",
|
"@type": "NewsArticle",
|
||||||
"mainEntityOfPage": {
|
"mainEntityOfPage": {
|
||||||
"@type": "WebPage",
|
"@type": "WebPage",
|
||||||
"@id": "'.$websitepage->pageurl.'"
|
"@id": "'.dol_escape_json($pageurl).'"
|
||||||
},
|
},
|
||||||
"headline": "'.$websitepage->title.'",
|
"headline": "'.dol_escape_json($title).'",
|
||||||
"image": [
|
"image": [
|
||||||
"'.$websitepage->image.'"
|
"'.dol_escape_json($image).'"
|
||||||
],
|
],
|
||||||
"datePublished": "'.dol_print_date($websitepage->date_creation, 'dayhourrfc').'",
|
"datePublished": "'.dol_print_date($websitepage->date_creation, 'dayhourrfc').'",
|
||||||
"dateModified": "'.dol_print_date($websitepage->date_modification, 'dayhourrfc').'",
|
"dateModified": "'.dol_print_date($websitepage->date_modification, 'dayhourrfc').'",
|
||||||
@@ -591,13 +603,13 @@ function getStructuredData($type, $data = array())
|
|||||||
},
|
},
|
||||||
"publisher": {
|
"publisher": {
|
||||||
"@type": "Organization",
|
"@type": "Organization",
|
||||||
"name": "'.$mysoc->name.'",
|
"name": "'.dol_escape_json($companyname).'",
|
||||||
"logo": {
|
"logo": {
|
||||||
"@type": "ImageObject",
|
"@type": "ImageObject",
|
||||||
"url": "/viewimage.php?modulepart=mycompany&file=logos%2F'.urlencode($mysoc->logo).'"
|
"url": "/viewimage.php?modulepart=mycompany&file=logos%2F'.urlencode($mysoc->logo).'"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"description": "'.$websitepage->description.'"
|
"description": "'.dol_escape_json($description).'"
|
||||||
}'."\n";
|
}'."\n";
|
||||||
$ret .= '</script>'."\n";
|
$ret .= '</script>'."\n";
|
||||||
}
|
}
|
||||||
@@ -610,19 +622,19 @@ function getStructuredData($type, $data = array())
|
|||||||
$ret .= '{
|
$ret .= '{
|
||||||
"@context": "https://schema.org/",
|
"@context": "https://schema.org/",
|
||||||
"@type": "Product",
|
"@type": "Product",
|
||||||
"name": "'.$data['label'].'",
|
"name": "'.dol_escape_json($data['label']).'",
|
||||||
"image": [
|
"image": [
|
||||||
"'.$data['image'].'",
|
"'.dol_escape_json($data['image']).'",
|
||||||
],
|
],
|
||||||
"description": "'.$data['description'].'",
|
"description": "'.dol_escape_json($data['description']).'",
|
||||||
"sku": "'.$data['ref'].'",
|
"sku": "'.dol_escape_json($data['ref']).'",
|
||||||
"brand": {
|
"brand": {
|
||||||
"@type": "Thing",
|
"@type": "Thing",
|
||||||
"name": "'.$data['brand'].'"
|
"name": "'.dol_escape_json($data['brand']).'"
|
||||||
},
|
},
|
||||||
"author": {
|
"author": {
|
||||||
"@type": "Person",
|
"@type": "Person",
|
||||||
"name": "'.$data['author'].'"
|
"name": "'.dol_escape_json($data['author']).'"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"offers": {
|
"offers": {
|
||||||
@@ -634,7 +646,7 @@ function getStructuredData($type, $data = array())
|
|||||||
"availability": "https://schema.org/InStock",
|
"availability": "https://schema.org/InStock",
|
||||||
"seller": {
|
"seller": {
|
||||||
"@type": "Organization",
|
"@type": "Organization",
|
||||||
"name": "'.$mysoc->name.'"
|
"name": "'.dol_escape_json($mysoc->name).'"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}'."\n";
|
}'."\n";
|
||||||
|
|||||||
Reference in New Issue
Block a user