Skip to content
Permalink
Browse files

Improved JSON-LD and OpenGraph support

  • Loading branch information...
LotarProject committed Jan 17, 2018
1 parent bd1a021 commit d67a5144093ddd906e657e580f046d3235738851
Showing with 56 additions and 31 deletions.
  1. +55 −30 helper.php
  2. +1 −1 plugin.info.txt
@@ -121,15 +121,18 @@ public function getStructuredData() {
if (! count($this->meta)) return false;
$license = $this->getLicense();
$type = $this->getSchemaOrgType();
$user_data = $auth->getUserData($this->getAuthorID());
$license_url = $license['url'];
$page_url = wl($this->page, '', true);
$description = $this->getDescription();
$created = date(DATE_W3C, $this->getCreatedDate());
$modified = date(DATE_W3C, $this->getModifiedDate());
$title = (isset($this->meta['title']) ? $this->meta['title'] : $this->page);
$license = $this->getLicense();
$type = $this->getSchemaOrgType();
$user_data = $auth->getUserData($this->getAuthorID());
$license_url = $license['url'];
$page_url = wl($this->page, '', true);
$description = $this->getDescription();
$created = date(DATE_W3C, $this->getCreatedDate());
$modified = date(DATE_W3C, $this->getModifiedDate());
$title = (isset($this->meta['title']) ? $this->meta['title'] : $this->page);
$wiki_logo_info = array();
$wiki_logo = tpl_getMediaFile(array(':wiki:logo.png', ':logo.png', 'images/logo.png'), true, $wiki_logo_info);
$json_ld = array(
'@context' => 'http://schema.org',
@@ -142,46 +145,51 @@ public function getStructuredData() {
'description' => $description,
'license' => $license_url,
'url' => $page_url,
'mainEntityOfPage' => array(
'@type' => 'WebPage',
'@id' => $page_url,
),
'publisher' => array(
'@type' => 'Organization',
'name' => $conf['title'],
'logo' => array(
'@type' => 'ImageObject',
'url' => $wiki_logo,
),
)
);
if ($image_url = $this->getFirstImageURL()) {
$image_info = array();
$article_image = tpl_getMediaFile(array($this->getFirstImage()), true, $logo_info);
$article_image = tpl_getMediaFile(array(':' . $this->getFirstImage()), true, $image_info);
$json_ld['image'] = array(
'@type' => 'ImageObject',
'url' => $image_url,
'width' => 0,
'height' => 0,
'width' => $image_info[0],
'height' => $image_info[1],
);
} else {
// Fallback
$json_ld['image'] = $json_ld['publisher']['logo'];
}
if ($author = $this->getAuthor()) {
$json_ld['creator'] = array(
$json_ld['author'] = array(
'@context' => 'http://schema.org',
'@type' => 'Person',
'name' => $author,
'email' => $user_data['mail']
);
$logo_info = array();
$wiki_logo = tpl_getMediaFile(array(':wiki:logo.png', ':logo.png', 'images/logo.png'), true, $logo_info);
$json_ld['author'] = $json_ld['creator'];
$json_ld['publisher'] = $json_ld['creator'];
$json_ld['publisher']['logo'] = array(
'@type' => 'ImageObject',
'url' => $wiki_logo,
'width' => $logo_info[0],
'height' => $logo_info[1],
);
if (isset($this->meta['contributor'])) {
foreach ($this->meta['contributor'] as $uid => $fullname) {
$contributor_data = $auth->getUserData($uid);
@@ -275,12 +283,29 @@ public function getOpenGraph() {
if (! $this->meta) return array();
$locale = $conf['lang'];
if ($locale == 'en') {
$locale = 'en_GB';
} else {
$locale .= '_' . strtoupper($locale);
}
$open_graph = array(
'og:title' => $this->getTitle(),
'og:description' => str_replace("\n", ' ', $this->getDescription()),
'og:url' => wl($this->page, '', true),
'og:type' => 'website',
'og:image' => $this->getFirstImageURL(),
'og:title' => $this->getTitle(),
'og:description' => str_replace("\n", ' ', $this->getDescription()),
'og:url' => wl($this->page, '', true),
'og:type' => 'article',
'og:image' => $this->getFirstImageURL(),
'og:locale' => $locale,
'og:site_name' => $conf['title'],
'article:published_time' => date(DATE_W3C, $this->getCreatedDate()),
'article:modified_time' => date(DATE_W3C, $this->getModifiedDate()),
'article:section' => date(DATE_W3C, $this->getModifiedDate()),
'article:author' => $this->getAuthor(),
);
return $open_graph;
@@ -1,7 +1,7 @@
base semantic
author Giuseppe Di Terlizzi
email giuseppe.diterlizzi@gmail.com
date 2017-05-23
date 2018-01-17
name Semantic Plugin
desc Add Semantic Data in DokuWiki
url http://www.dokuwiki.org/plugin:semantic

0 comments on commit d67a514

Please sign in to comment.
You can’t perform that action at this time.