Merge branch 'develop'

This commit is contained in:
Giuseppe Di Terlizzi 2023-02-03 00:04:17 +01:00
commit a97af226e4
7 changed files with 63 additions and 73 deletions

View file

@ -8,10 +8,6 @@ php:
env: env:
- DOKUWIKI=master - DOKUWIKI=master
- DOKUWIKI=stable - DOKUWIKI=stable
matrix:
include:
- php: "5.6"
env: DOKUWIKI=old-stable
before_install: wget https://raw.github.com/splitbrain/dokuwiki-travis/master/travis.sh before_install: wget https://raw.github.com/splitbrain/dokuwiki-travis/master/travis.sh
install: sh travis.sh install: sh travis.sh
script: cd _test && ./phpunit.phar --stderr --group plugin_semantic script: cd _test && ./phpunit.phar --stderr --group plugin_semantic

View file

@ -6,13 +6,15 @@
* @group plugin_semantic * @group plugin_semantic
* @group plugins * @group plugins
*/ */
class general_plugin_semantic_test extends DokuWikiTest { class general_plugin_semantic_test extends DokuWikiTest
{
/** /**
* Simple test to make sure the plugin.info.txt is in correct format * Simple test to make sure the plugin.info.txt is in correct format
*/ */
public function test_plugininfo() { public function test_plugininfo()
$file = __DIR__.'/../plugin.info.txt'; {
$file = __DIR__ . '/../plugin.info.txt';
$this->assertFileExists($file); $this->assertFileExists($file);
$info = confToHash($file); $info = confToHash($file);
@ -32,4 +34,3 @@ class general_plugin_semantic_test extends DokuWikiTest {
$this->assertTrue(false !== strtotime($info['date'])); $this->assertTrue(false !== strtotime($info['date']));
} }
} }

View file

@ -4,13 +4,9 @@
* *
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com> * @author Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com>
* @copyright (C) 2015-2019, Giuseppe Di Terlizzi * @copyright (C) 2015-2023, Giuseppe Di Terlizzi
*/ */
// must be run within Dokuwiki
if (!defined('DOKU_INC')) {
die();
}
/** /**
* Class Semantic Action Plugin * Class Semantic Action Plugin
@ -108,10 +104,8 @@ class action_plugin_semantic extends DokuWiki_Action_Plugin
$this->helper->getMetadata($id); $this->helper->getMetadata($id);
$json_ld = $this->helper->getJsonLD(); $json_ld = $this->helper->getJsonLD();
$json = new JSON();
header('Content-Type: application/ld+json'); header('Content-Type: application/ld+json');
print $json->encode($json_ld); print json_encode($json_ld);
return true; return true;
} }

View file

@ -12,5 +12,5 @@ $conf['useMetaDescription'] = 1;
$conf['useMetaAuthor'] = 1; $conf['useMetaAuthor'] = 1;
$conf['useDublinCore'] = 0; $conf['useDublinCore'] = 0;
$conf['useOpenGraph'] = 0; $conf['useOpenGraph'] = 0;
$conf['excludedPages'] = '(wiki|playground)'; $conf['excludedPages'] = '(wiki)';
$conf['hideMail'] = 0; $conf['hideMail'] = 0;

View file

@ -11,6 +11,6 @@ $meta['useDublinCore'] = array('onoff');
$meta['useOpenGraph'] = array('onoff'); $meta['useOpenGraph'] = array('onoff');
$meta['useJSONLD'] = array('onoff'); $meta['useJSONLD'] = array('onoff');
$meta['exposeWebService'] = array('onoff'); $meta['exposeWebService'] = array('onoff');
$meta['defaultSchemaOrgType'] = array('multichoice','_choices' => array('Article', 'NewsArticle', 'TechArticle', 'BlogPosting', 'Recipe')); $meta['defaultSchemaOrgType'] = array('multichoice', '_choices' => array('Article', 'NewsArticle', 'TechArticle', 'BlogPosting', 'Recipe'));
$meta['excludedPages'] = array('regex'); $meta['excludedPages'] = array('regex');
$meta['hideMail'] = array('onoff'); $meta['hideMail'] = array('onoff');

View file

@ -4,14 +4,9 @@
* *
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com> * @author Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com>
* @copyright (C) 2015-2019, Giuseppe Di Terlizzi * @copyright (C) 2015-2022, Giuseppe Di Terlizzi
*/ */
// must be run within Dokuwiki
if (!defined('DOKU_INC')) {
die();
}
class helper_plugin_semantic extends DokuWiki_Plugin class helper_plugin_semantic extends DokuWiki_Plugin
{ {
@ -29,7 +24,7 @@ class helper_plugin_semantic extends DokuWiki_Plugin
global $conf; global $conf;
$json_ld = array( $json_ld = array(
'@context' => 'http://schema.org', '@context' => 'http://schema.org/',
'@type' => 'WebSite', '@type' => 'WebSite',
'url' => DOKU_URL, 'url' => DOKU_URL,
'name' => $conf['title'], 'name' => $conf['title'],
@ -106,7 +101,7 @@ class helper_plugin_semantic extends DokuWiki_Plugin
*/ */
public function getFirstImage() public function getFirstImage()
{ {
return ((@$this->meta['relation']['firstimage']) ? $this->meta['relation']['firstimage'] : null); return (isset($this->meta['relation']['firstimage']) ? $this->meta['relation']['firstimage'] : null);
} }
/** /**
@ -126,7 +121,7 @@ class helper_plugin_semantic extends DokuWiki_Plugin
*/ */
public function getDescription() public function getDescription()
{ {
return (@$this->meta['description']['abstract'] ? $this->meta['description']['abstract'] : $this->getTitle()); return (isset($this->meta['description']['abstract']) ? $this->meta['description']['abstract'] : $this->getTitle());
} }
/** /**
@ -156,7 +151,7 @@ class helper_plugin_semantic extends DokuWiki_Plugin
*/ */
public function getTitle() public function getTitle()
{ {
return (@$this->meta['title'] ? $this->meta['title'] : null); return (isset($this->meta['title']) ? $this->meta['title'] : null);
} }
/** /**
@ -166,7 +161,7 @@ class helper_plugin_semantic extends DokuWiki_Plugin
*/ */
public function getCreatedDate() public function getCreatedDate()
{ {
return ((@$this->meta['date']['created']) ? $this->meta['date']['created'] : -1); return (isset($this->meta['date']['created']) ? $this->meta['date']['created'] : -1);
} }
/** /**
@ -176,7 +171,7 @@ class helper_plugin_semantic extends DokuWiki_Plugin
*/ */
public function getModifiedDate() public function getModifiedDate()
{ {
return ((@$this->meta['date']['modified']) ? $this->meta['date']['modified'] : -1); return (isset($this->meta['date']['modified']) ? $this->meta['date']['modified'] : -1);
} }
/** /**
@ -188,7 +183,8 @@ class helper_plugin_semantic extends DokuWiki_Plugin
{ {
global $license; global $license;
global $conf; global $conf;
return @$license[$conf['license']];
return (isset($license[$conf['license']]) ? $license[$conf['license']] : null);
} }
/** /**
@ -219,7 +215,7 @@ class helper_plugin_semantic extends DokuWiki_Plugin
$wiki_logo = tpl_getMediaFile(array(':wiki:logo.png', ':logo.png', 'images/logo.png'), true, $wiki_logo_info); $wiki_logo = tpl_getMediaFile(array(':wiki:logo.png', ':logo.png', 'images/logo.png'), true, $wiki_logo_info);
$json_ld = array( $json_ld = array(
'@context' => 'http://schema.org', '@context' => 'http://schema.org/',
'@type' => $type, '@type' => $type,
'headline' => $title, 'headline' => $title,
'name' => $title, 'name' => $title,
@ -268,7 +264,7 @@ class helper_plugin_semantic extends DokuWiki_Plugin
if ($author = $this->getAuthor()) { if ($author = $this->getAuthor()) {
$json_ld['author'] = array( $json_ld['author'] = array(
'@context' => 'http://schema.org', '@context' => 'http://schema.org/',
'@type' => 'Person', '@type' => 'Person',
'name' => $author, 'name' => $author,
'email' => $user_data['mail'], 'email' => $user_data['mail'],
@ -280,7 +276,7 @@ class helper_plugin_semantic extends DokuWiki_Plugin
$contributor_data = ($this->getConf('hideMail') ? array('mail' => null) : $auth->getUserData($uid)); $contributor_data = ($this->getConf('hideMail') ? array('mail' => null) : $auth->getUserData($uid));
$json_ld['contributor'][] = array( $json_ld['contributor'][] = array(
'@context' => 'http://schema.org', '@context' => 'http://schema.org/',
'@type' => 'Person', '@type' => 'Person',
'name' => $fullname, 'name' => $fullname,
'email' => $contributor_data['mail'], 'email' => $contributor_data['mail'],
@ -319,7 +315,7 @@ class helper_plugin_semantic extends DokuWiki_Plugin
} }
$json_ld_webpage = array( $json_ld_webpage = array(
'@context' => 'http://schema.org', '@context' => 'http://schema.org/',
'@type' => 'WebPage', '@type' => 'WebPage',
); );

View file

@ -1,54 +1,57 @@
<?php <?php
/** /**
* Semantic plugin: Add Schema.org News Article using JSON-LD * Semantic plugin: Add Schema.org News Article using JSON-LD
* *
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com> * @author Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com>
* @copyright (C) 2015-2023, Giuseppe Di Terlizzi
*/ */
// must be run within Dokuwiki
if (!defined('DOKU_INC')) die();
if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); class syntax_plugin_semantic extends DokuWiki_Syntax_Plugin
{
class syntax_plugin_semantic extends DokuWiki_Syntax_Plugin { private $macros = array(
'~~NewsArticle~~', '~~Article~~', '~~TechArticle~~',
'~~BlogPosting~~', '~~Recipe~~', '~~NOSEMANTIC~~',
);
private $macros = array( public function getType()
'~~NewsArticle~~', '~~Article~~', '~~TechArticle~~', {return 'substition';}
'~~BlogPosting~~', '~~Recipe~~', '~~NOSEMANTIC~~' public function getSort()
); {return 99;}
function getType() { return 'substition'; } public function connectTo($mode)
function getSort() { return 99; } {
function connectTo($mode) { foreach ($this->macros as $macro) {
$this->Lexer->addSpecialPattern($macro, $mode, 'plugin_semantic');
foreach ($this->macros as $macro) { }
$this->Lexer->addSpecialPattern($macro, $mode, 'plugin_semantic');
}
}
function handle($match, $state, $pos, Doku_Handler $handler) {
return array($match, $state, $pos);
}
function render($mode, Doku_Renderer $renderer, $data) {
if ($mode == 'metadata') {
list($match, $state, $pos) = $data;
if ($match == '~~NOSEMANTIC~~') {
$renderer->meta['plugin']['semantic']['enabled'] = false;
} else {
$renderer->meta['plugin']['semantic']['schema.org']['type'] = trim(str_replace('Schema.org/', '', $match), '~~');
$renderer->meta['plugin']['semantic']['enabled'] = true;
}
} }
return false; public function handle($match, $state, $pos, Doku_Handler $handler)
{
return array($match, $state, $pos);
}
} public function render($mode, Doku_Renderer $renderer, $data)
{
if ($mode == 'metadata') {
list($match, $state, $pos) = $data;
if ($match == '~~NOSEMANTIC~~') {
$renderer->meta['plugin']['semantic']['enabled'] = false;
} else {
$renderer->meta['plugin']['semantic']['schema.org']['type'] = trim(str_replace('Schema.org/', '', $match), '~~');
$renderer->meta['plugin']['semantic']['enabled'] = true;
}
}
return false;
}
} }