Skip to content

Commit

Permalink
Added inLanguage and Keywords support for Structured Data
Browse files Browse the repository at this point in the history
For feature #902
  • Loading branch information
eSilverStrike committed Feb 8, 2019
1 parent 87a6af4 commit 550975f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 11 deletions.
33 changes: 25 additions & 8 deletions plugins/staticpages/functions.inc
Expand Up @@ -574,14 +574,17 @@ function SP_displayPage($page, $A, $comment_order = 'ASC', $comment_mode = 'nest
$breadcrumbs = TOPIC_breadcrumbs('staticpages', $page);
}

$parameters['headline'] = $A['sp_title'];
$parameters['url'] = $sp_url;
$parameters['datePublished'] = $A['created'];
$parameters['dateModified'] = $A['modified'];
$parameters['description'] = $A['meta_description'];
$parameters['commentCount'] = CMT_commentCount($page, 'staticpages');
$_STRUCT_DATA->add_type('staticpages', $page, $A['structured_data_type'], $parameters);

$properties['headline'] = $A['sp_title'];
$properties['url'] = $sp_url;
$properties['datePublished'] = $A['created'];
$properties['dateModified'] = $A['modified'];
$properties['description'] = $A['meta_description'];
$properties['keywords'] = $A['meta_keywords'];
$properties['commentCount'] = CMT_commentCount($page, 'staticpages');
$_STRUCT_DATA->add_type('staticpages', $page, $A['structured_data_type'], $properties);
$_STRUCT_DATA->set_author_item('staticpages', $page, $author_name);


$retval = COM_createHTMLDocument($retval, array('what' => $what, 'pagetitle' => $page_title, 'breadcrumbs' => $breadcrumbs, 'headercode' => $headerCode, 'rightblock' => $rightblock));
}
Expand Down Expand Up @@ -1999,7 +2002,21 @@ function SP_render_content($sp_id, $sp_title, $sp_content, $sp_php, $cache_time
}

$sp_content = stripslashes($sp_content);


/*
// Since staticpage can be cached and autotags within content may insert structured data properties need to insert it now before cache file is written.
$properties['headline'] = $A['sp_title'];
$properties['url'] = $sp_url;
$properties['datePublished'] = $A['created'];
$properties['dateModified'] = $A['modified'];
$properties['description'] = $A['meta_description'];
$properties['keywords'] = $A['meta_keywords'];
$properties['commentCount'] = CMT_commentCount($page, 'staticpages');
$_STRUCT_DATA->add_type('staticpages', $page, $A['structured_data_type'], $properties);
$_STRUCT_DATA->set_author_item('staticpages', $page, $author_name);
$sp_content = $_STRUCT_DATA->toScript('staticpages', $page) . $sp_content;
*/

if (($cache_time > 0 || $cache_time == -1) && $sp_php == 0) {
CACHE_create_instance($cacheInstance, $sp_content);
}
Expand Down
1 change: 1 addition & 0 deletions public_html/article.php
Expand Up @@ -525,6 +525,7 @@ function extractExternalLinks($text) {
$properties['dateModified'] = $article->displayElements('modified');
}
$properties['description'] = $article->DisplayElements('meta_description');
$properties['keywords'] = $article->DisplayElements('meta_keywords');
$properties['commentCount'] = CMT_commentCount($article->getSid(), 'article');
$_STRUCT_DATA->add_type('article', $article->getSid(), $article->displayElements('structured_data_type'), $properties);
$_STRUCT_DATA->set_author_item('article', $article->getSid(), $article->DisplayElements('username'));
Expand Down
24 changes: 21 additions & 3 deletions system/classes/structureddata.class.php
Expand Up @@ -93,6 +93,12 @@ public function add_type($type, $id, $sd_type, $properties = array())
// Create structured data name
$sd_name = $this->create_name($type, $id);

// Remove any empty properties
foreach($properties as $key => $value) {
if(empty($value))
unset($properties[$key]);
}

// 0 = None
if ($sd_type > 0 AND $sd_type < 5) {
$this->items[$sd_name]['@context'] = "https://schema.org";
Expand Down Expand Up @@ -120,16 +126,28 @@ public function add_type($type, $id, $sd_type, $properties = array())
$this->items[$sd_name]['commentCount'] = $properties['commentCount'];
}

// inLanguage
// keywords // Meta Keywords or Topic List
$lang_id = '';
if (COM_isMultiLanguageEnabled()) {
$lang_id = COM_getLanguageIdForObject($id);
}
if (empty($lang_id)) {
// Assume default language of site
$lang_id = COM_getLanguageId($_CONF['language_site_default']);
}
$this->items[$sd_name]['inLanguage'] = $lang_id;

// keywords // Meta Keywords or Topic List (needs to be a comma delimited list)
if (isset($properties['keywords'])) {
$this->items[$sd_name]['keywords'] = $properties['keywords'];
}

// image
// thumbnailUrl

// video

// Can be set by autotag which can be executed first so do not overwrite if set
if (!isset($this->items[$sd_name]['description'])) {
if (isset($properties['description']) && !isset($this->items[$sd_name]['description'])) {
$this->items[$sd_name]['description'] = $properties['description'];
}

Expand Down

0 comments on commit 550975f

Please sign in to comment.