From 8a6ae84fb0f9d390a02813ecc3313022d77c02e2 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 17 May 2020 20:02:01 +0200 Subject: [PATCH] Fix getStructuredData for organization --- htdocs/core/lib/website.lib.php | 57 +++++++++++++++++++++++--- htdocs/societe/class/societe.class.php | 7 ++++ 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/htdocs/core/lib/website.lib.php b/htdocs/core/lib/website.lib.php index 9d916a46b38..b3419d2faae 100644 --- a/htdocs/core/lib/website.lib.php +++ b/htdocs/core/lib/website.lib.php @@ -540,7 +540,7 @@ function includeContainer($containerref) */ function getStructuredData($type, $data = array()) { - global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs; // Very important. Required to have var available when running inluded containers. + global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs, $pagelangs; // Very important. Required to have var available when running inluded containers. if ($type == 'software') { @@ -565,6 +565,41 @@ function getStructuredData($type, $data = array()) }'."\n"; $ret .= ''."\n"; } + elseif ($type == 'organization') + { + $companyname = $mysoc->name; + $url = $mysoc->url; + + $ret = ''."\n"; + $ret .= ''."\n"; + } elseif ($type == 'blogpost') { if (!empty($websitepage->author_alias)) @@ -581,7 +616,7 @@ function getStructuredData($type, $data = array()) $pageurl = str_replace('__WEBSITE_KEY__', $website->ref, $pageurl); $title = str_replace('__WEBSITE_KEY__', $website->ref, $title); - $image = str_replace('__WEBSITE_KEY__', $website->ref, $image); + $image = 'medias/'.str_replace('__WEBSITE_KEY__', $website->ref, $image); $companyname = str_replace('__WEBSITE_KEY__', $website->ref, $companyname); $description = str_replace('__WEBSITE_KEY__', $website->ref, $description); @@ -598,6 +633,7 @@ function getStructuredData($type, $data = array()) "image": [ "'.dol_escape_json($image).'" ], + "dateCreated": "'.dol_print_date($websitepage->date_creation, 'dayhourrfc').'", "datePublished": "'.dol_print_date($websitepage->date_creation, 'dayhourrfc').'", "dateModified": "'.dol_print_date($websitepage->date_modification, 'dayhourrfc').'", "author": { @@ -611,9 +647,20 @@ function getStructuredData($type, $data = array()) "@type": "ImageObject", "url": "/wrapper.php?modulepart=mycompany&file=logos%2F'.urlencode($mysoc->logo).'" } - }, - "description": "'.dol_escape_json($description).'" - }'."\n"; + },'."\n"; + if ($websitepage->keywords) { + $ret .= '"keywords": ['; + $i = 0; + $arrayofkeywords = explode(',', $websitepage->keywords); + foreach($arrayofkeywords as $keyword) { + $ret.= '"'.dol_escape_json($keyword).'"'; + $i++; + if ($i < count($arrayofkeywords)) $ret .= ', '; + } + $ret .= '],'."\n"; + } + $ret .= '"description": "'.dol_escape_json($description).'"'; + $ret .= "\n".'}'."\n"; $ret .= ''."\n"; } } diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 62140ba5d89..de65e05d41e 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -3745,6 +3745,13 @@ class Societe extends CommonObject $this->instagram_url = empty($conf->global->MAIN_INFO_SOCIETE_INSTAGRAM_URL) ? '' : $conf->global->MAIN_INFO_SOCIETE_INSTAGRAM_URL; $this->youtube_url = empty($conf->global->MAIN_INFO_SOCIETE_YOUTUBE_URL) ? '' : $conf->global->MAIN_INFO_SOCIETE_YOUTUBE_URL; $this->github_url = empty($conf->global->MAIN_INFO_SOCIETE_GITHUB_URL) ? '' : $conf->global->MAIN_INFO_SOCIETE_GITHUB_URL; + $this->socialnetworks = array(); + if (! empty($this->facebook_url)) $this->socialnetworks['facebook'] = $this->facebook_url; + if (! empty($this->twitter_url)) $this->socialnetworks['twitter'] = $this->twitter_url; + if (! empty($this->linkedin_url)) $this->socialnetworks['linkedin'] = $this->linkedin_url; + if (! empty($this->instagram_url)) $this->socialnetworks['instagram'] = $this->instagram_url; + if (! empty($this->youtube_url)) $this->socialnetworks['youtube'] = $this->youtube_url; + if (! empty($this->github_url)) $this->socialnetworks['github'] = $this->github_url; // Id prof generiques $this->idprof1 = empty($conf->global->MAIN_INFO_SIREN) ? '' : $conf->global->MAIN_INFO_SIREN;