Commit c4b1792b authored by Francesco Iannuzzelli's avatar Francesco Iannuzzelli

#24 Fix structured data JSON encoding

parent 593ab8d5
......@@ -2231,9 +2231,11 @@ class Layout
private function CurrentPage($type,$is_global)
{
$current_page = array();
$page_array = array();
$this->Urlify($page_array,$type,$this->current_page_params,$is_global);
return array('url'=>$page_array['url'],'url_encoded'=>urlencode($page_array['url']));
$current_page = array('url'=>$page_array['url'],'url_encoded'=>urlencode($page_array['url']));
return $current_page;
}
private function Day($id_topic,$id_group,$ts)
......@@ -6080,6 +6082,9 @@ class Layout
if($id_type!="15" && $id_type!="17" && $id_type!="19" && $type!="ebook")
{
$pagetype['page'] = $this->CurrentPage($type,$this->current_page_global);
if($this->conf->Get("ui")) {
$this->StructuredData($pagetype);
}
}
$pagetype['feedback'] = $this->FeedBack();
return $this->xh->Array2Xml($pagetype);
......@@ -6178,6 +6183,9 @@ class Layout
break;
}
$pagetype['page'] = $this->CurrentPage(array_search($id_type,$this->pt->gtypes),true);
if($this->conf->Get("ui")) {
$this->StructuredData($pagetype);
}
$pagetype['feedback'] = $this->FeedBack();
return $this->xh->Array2Xml($pagetype);
}
......@@ -6850,6 +6858,7 @@ class Layout
private function PollWrapper($params)
{
$pagetype = array();
$topic = ($params['id_topic']>0)? $topic = $this->TopicCommon() : array();
if ($this->subtype=="" )
$this->subtype = ($params['subtype']!="")? $params['subtype'] : ($params['id']>0?"info":"list");
......@@ -6998,7 +7007,7 @@ class Layout
if(($row['submit_questions']=="1" && $user['auth']!="1") || ($row['submit_questions']=="2" && !$user['id']>0) )
{
$poll['login'] = $this->LoginFirst($row['id_topic']);
}
}
}
$poll['submit'] = $this->pub_web . "/" . $this->ini->Get("poll_path") . "/actions.php";
$pagetype['poll'] = $poll;
......@@ -7632,6 +7641,74 @@ class Layout
exit;
}
private function StructuredData(&$pagetype) {
$cdn = $this->conf->Get("cdn");
$ld = array();
$ld['@context'] = 'https://schema.org';
$org = array();
$org['@type'] = 'Organization';
$org['address'] = array('@type'=>'PostalAddress','addressLocality'=>'Taranto','postalCode'=>'74100','streetAddress'=>'CP 2009','addressRegion'=>'TA','addressCountry'=>'IT');
$org['name'] = 'PeaceLink';
$org['url'] = 'https://www.peacelink.it';
$org['logo'] = array('@type'=>'ImageObject','url'=>"$cdn/graphics/peacelink_amp.png?format=png",'width'=>'200','height'=>'60');
$org['email'] = 'mailto:[email protected]';
$org['image'] = "$cdn/css/i/peacelink.svg";
$org['description'] = "Telematica per la Pace, associazione di volontariato dell'informazione che dal 1992 offre una alternativa ai grandi gruppi editoriali e televisivi.";
$org['sameAs'] = array('https://www.facebook.com/retepeacelink','https://twitter.com/peacelink','https://www.youtube.com/c/peacelinkvideo');
if(!$this->global && $this->id_type==$this->pt->types['article']) { //article
$article = $pagetype['article'];
$ld['@type'] = 'NewsArticle';
$ld['mainEntityOfPage'] = array('@type'=>'WebPage','@id'=>$pagetype['page']['url']);
$ld['headline'] = $article['headline']['xvalue'];
if(isset($article['images']) && is_array($article['images']) && count($article['images'])>0) {
$associated_image = array();
foreach($article['images'] as $image) {
if(isset($image['xname']) && $image['xname']=='image') {
if((isset($image['associated']) && $image['associated']=='1') || count($associated_image)==0) {
$ld['image'] = $image['og_image']['url'];
}
}
}
}
$ld['datePublished'] = $article['date_iso8601'];
$ld['dateModified'] = $article['date_iso8601'];
if($article['show_author']=='1' && isset($article['author']['name']) && $article['author']['name']!='') {
$ld['author'] = array('@type'=>'Person','name'=>$article['author']['name']);
}
$ld['publisher'] = $org;
if($article['subhead']['xvalue']!='') {
$ld['description'] = $article['subhead']['xvalue'];
}
} else if(!$this->global && $this->id_type==$this->pt->types['events'] && $this->subtype=='event') { // event
$event = $pagetype['event'];
$ld['@type'] = 'Event';
$ld['name'] = $event['title'];
$ld['startDate'] = $event['start_iso8601'];
$ld['endDate'] = $event['end_iso8601'];
if(isset($event['image'])) {
$ld['image'] = $event['image']['image_zoom']['url'];
}
if($event['description_text']!='') {
$ld['description'] = $event['description_text'];
}
$location = array();
$location['@type'] = 'Place';
$location['name'] = $event['place'];
$location['address'] = array('@type'=>'PostalAddress','addressLocality'=>$event['place']);
if(isset($event['geo_name'])) {
$location['address']['addressRegion'] = $event['geo_name'];
$location['address']['addressCountry'] = 'IT';
}
if($event['place_details']['xvalue']!='') {
$location['streetAddress'] = $event['place_details']['xvalue'];
}
$ld['location'] = $location;
} else {
$ld = array_merge($ld,$org);
}
$pagetype['structured_data'] = json_encode($ld);
}
public function Subtopic($id_subtopic,$params=array())
{
$subtopic_pages = array();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment