Skip to content

Commit

Permalink
use https for schema.org urls, apply some code improvements suggestio…
Browse files Browse the repository at this point in the history
…ns (#33)

* use https for schema.org urls, apply some code improvements suggestions

* apply PSR-12 style, remove debug logging

* copyright updates

* Update composer.json for scrutinizer

scrutinizer builds fail with 8.1 because: `Requested 'openssl >= 1.0.2' but version of OpenSSL is 1.0.1f`
  • Loading branch information
mprins authored Jul 14, 2023
1 parent 89371ce commit a9083e4
Show file tree
Hide file tree
Showing 20 changed files with 132 additions and 124 deletions.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
----
Copyright (c) 2011-2022 Mark C. Prins
Copyright (c) 2011 Mark C. Prins

Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

Expand Down
14 changes: 9 additions & 5 deletions _test/general.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@
* @group plugin_geotag
* @group plugins
*/
class general_plugin_geotag_test extends DokuWikiTest {
class general_plugin_geotag_test extends DokuWikiTest
{

protected $pluginsEnabled = array('geotag');

/**
* Simple test to make sure the plugin.info.txt is in correct format
*/
public function test_plugininfo(): void {
final public function test_plugininfo(): void
{
$file = __DIR__ . '/../plugin.info.txt';
$this->assertFileExists($file);

Expand All @@ -52,10 +54,12 @@ public function test_plugininfo(): void {
/**
* test if plugin is loaded.
*/
public function test_plugin_geotag_isloaded(): void {
final public function test_plugin_geotag_isloaded(): void
{
global $plugin_controller;
$this->assertTrue(
in_array('geotag', $plugin_controller->getList()),
$this->assertContains(
'geotag',
$plugin_controller->getList(),
"geotag plugin is loaded"
);
}
Expand Down
44 changes: 17 additions & 27 deletions _test/syntax.test.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright (c) 2016-2018 Mark C. Prins <mprins@users.sf.net>
* Copyright (c) 2016 Mark C. Prins <mprins@users.sf.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand All @@ -21,24 +21,25 @@
* @group plugin_geotag
* @group plugins
*/
class syntax_plugin_geotag_test extends DokuWikiTest {
class syntax_plugin_geotag_test extends DokuWikiTest
{

protected $pluginsEnabled = array('geotag');

/**
* copy data and add pages to the index.
*/
public static function setUpBeforeClass(): void {
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
global $conf;
$conf['allowdebug'] = 1;

TestUtils::rcopy(TMP_DIR, dirname(__FILE__) . '/data/');

dbglog("\nset up class syntax_plugin_geotag_test");
TestUtils::rcopy(TMP_DIR, __DIR__ . '/data/');
}

public function setUp(): void {
final public function setUp(): void
{
parent::setUp();

global $conf;
Expand All @@ -50,27 +51,13 @@ public function setUp(): void {

$verbose = false;
$force = false;
foreach($data as $val) {
foreach ($data as $val) {
idx_addPage($val['id'], $verbose, $force);
}
if($conf['allowdebug']) {
touch(DOKU_TMP_DATA . 'cache/debug.log');
}
}

public function tearDown(): void {
parent::tearDown();

global $conf;
// try to get the debug log after running the test, print and clear
if($conf['allowdebug']) {
print "\n";
readfile(DOKU_TMP_DATA . 'cache/debug.log');
unlink(DOKU_TMP_DATA . 'cache/debug.log');
}
}

public function test_geotag(): void {
final public function test_geotag(): void
{
$request = new TestRequest();
$response = $request->get(array('id' => 'minimalgeotag'), '/doku.php');

Expand All @@ -93,7 +80,8 @@ public function test_geotag(): void {
);
}

public function test_fullgeotag(): void {
final public function test_fullgeotag(): void
{
$request = new TestRequest();
$response = $request->get(array('id' => 'fullgeotag'), '/doku.php');

Expand All @@ -116,7 +104,8 @@ public function test_fullgeotag(): void {
);
}

public function test_fullgeotagnegativecoords(): void {
final public function test_fullgeotagnegativecoords(): void
{
$request = new TestRequest();
$response = $request->get(array('id' => 'fullgeotagnegativecoords'), '/doku.php');

Expand All @@ -139,7 +128,8 @@ public function test_fullgeotagnegativecoords(): void {
);
}

public function test_nogeotag(): void {
final public function test_nogeotag(): void
{
$request = new TestRequest();
$response = $request->get(array('id' => 'nogeotag'), '/doku.php');

Expand Down
53 changes: 29 additions & 24 deletions action.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright (c) 2011-2016 Mark C. Prins <mprins@users.sf.net>
* Copyright (c) 2011 Mark C. Prins <mprins@users.sf.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand All @@ -21,17 +21,19 @@
* @license BSD license
* @author Mark C. Prins <mprins@users.sf.net>
*/
class action_plugin_geotag extends DokuWiki_Action_Plugin {
class action_plugin_geotag extends DokuWiki_Action_Plugin
{

/**
* Register for events.
*
* @param Doku_Event_Handler $controller
* DokuWiki's event controller object. Also available as global $EVENT_HANDLER
*/
public function register(Doku_Event_Handler $controller) {
final public function register(Doku_Event_Handler $controller): void
{
$controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handleMetaheaderOutput');
if($this->getConf('toolbar_icon')) {
if ($this->getConf('toolbar_icon')) {
$controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'insertButton', array());
}
$controller->register_hook('PLUGIN_POPULARITY_DATA_SETUP', 'AFTER', $this, 'popularity');
Expand All @@ -40,38 +42,39 @@ public function register(Doku_Event_Handler $controller) {
/**
* Retrieve metadata and add to the head of the page using appropriate meta tags.
*
* @param Doku_Event $event
* @param Doku_Event $event
* the DokuWiki event. $event->data is a two-dimensional
* array of all meta headers. The keys are meta, link and script.
*
* @see https://www.dokuwiki.org/devel:event:tpl_metaheader_output
*/
public function handleMetaheaderOutput(Doku_Event $event) {
final public function handleMetaheaderOutput(Doku_Event $event): void
{
global $ID;
$title = p_get_metadata($ID, 'title', METADATA_RENDER_USING_SIMPLE_CACHE);
$geotags = p_get_metadata($ID, 'geo', METADATA_RENDER_USING_SIMPLE_CACHE) ?? array();
$region = $geotags ['region'] ?? NULL;
$lat = $geotags ['lat'] ?? NULL;
$lon = $geotags ['lon'] ?? NULL;
$alt = $geotags ['alt'] ?? NULL;
$country = $geotags ['country'] ?? NULL;
$placename = $geotags ['placename'] ?? NULL;
$geohash = $geotags ['geohash'] ?? NULL;
$region = $geotags ['region'] ?? null;
$lat = $geotags ['lat'] ?? null;
$lon = $geotags ['lon'] ?? null;
$alt = $geotags ['alt'] ?? null;
$country = $geotags ['country'] ?? null;
$placename = $geotags ['placename'] ?? null;
$geohash = $geotags ['geohash'] ?? null;

if(!empty ($region)) {
if (!empty ($region)) {
$event->data ['meta'] [] = array(
'name' => 'geo.region',
'content' => $region
);
}
if(!empty ($placename)) {
if (!empty ($placename)) {
$event->data ['meta'] [] = array(
'name' => 'geo.placename',
'content' => $placename
);
}
if(!(empty ($lat) && empty ($lon))) {
if(!empty ($alt)) {
if (!(empty ($lat) && empty ($lon))) {
if (!empty ($alt)) {
$event->data ['meta'] [] = array(
'name' => 'geo.position',
'content' => $lat . ';' . $lon . ';' . $alt
Expand All @@ -83,24 +86,24 @@ public function handleMetaheaderOutput(Doku_Event $event) {
);
}
}
if(!empty ($country)) {
if (!empty ($country)) {
$event->data ['meta'] [] = array(
'name' => 'geo.country',
'content' => $country
);
}
if(!(empty ($lat) && empty ($lon))) {
if (!(empty ($lat) && empty ($lon))) {
$event->data ['meta'] [] = array(
'name' => "ICBM",
'content' => $lat . ', ' . $lon
);
// icbm is generally useless without a DC.title,
// so we copy that from title unless it's empty...
if(!(empty ($title))) {
if (!(empty ($title))) {
/*
* don't specify the DC namespace as this is incomplete; it should be done at the
* template level as it also needs a 'profile' attribute on the head/container,
* see: http://dublincore.org/documents/dc-html/#sect-3.1.1
* see: https://dublincore.org/documents/dc-html/#sect-3.1.1
* $event->data ['link'] [] = array ('rel' => 'schema.DC',
* 'href' => 'http://purl.org/dc/elements/1.1/');
*/
Expand All @@ -110,7 +113,7 @@ public function handleMetaheaderOutput(Doku_Event $event) {
);
}
}
if(!empty ($geohash)) {
if (!empty ($geohash)) {
$event->data ['meta'] [] = array(
'name' => 'geo.geohash',
'content' => $geohash
Expand All @@ -124,7 +127,8 @@ public function handleMetaheaderOutput(Doku_Event $event) {
* @param Doku_Event $event
* the DokuWiki event
*/
public function insertButton(Doku_Event $event, $param) {
final public function insertButton(Doku_Event $event, array $param): void
{
$event->data [] = array(
'type' => 'format',
'title' => $this->getLang('toolbar_desc'),
Expand All @@ -141,7 +145,8 @@ public function insertButton(Doku_Event $event, $param) {
* @param Doku_Event $event
* the DokuWiki event
*/
final public function popularity(Doku_Event $event): void {
final public function popularity(Doku_Event $event): void
{
global $updateVersion;
$plugin_info = $this->getInfo();
$event->data['geotag']['version'] = $plugin_info['date'];
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
"php": "8.0"
}
}
}
}
2 changes: 1 addition & 1 deletion conf/default.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright (c) 2011-2015 Mark C. Prins <mprins@users.sf.net>
* Copyright (c) 2011 Mark C. Prins <mprins@users.sf.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down
2 changes: 1 addition & 1 deletion conf/metadata.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright (c) 2011-2015 Mark C. Prins <mprins@users.sf.net>
* Copyright (c) 2011 Mark C. Prins <mprins@users.sf.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down
2 changes: 1 addition & 1 deletion lang/de/lang.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright (c) 2011-2014 Mark C. Prins <mprins@users.sf.net>
* Copyright (c) 2011 Mark C. Prins <mprins@users.sf.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down
4 changes: 2 additions & 2 deletions lang/de/settings.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright (c) 2011-2014 Mark C. Prins <mprins@users.sf.net>
* Copyright (c) 2011 Mark C. Prins <mprins@users.sf.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand All @@ -26,5 +26,5 @@
$lang['geotag_hide'] = 'Verstecken Geotag (css)';
$lang['geotag_prevent_microformat_render'] = 'Verhindern Rendering Geotag Mikroformat';
$lang['toolbar_icon'] = 'Toolbar-Symbol anzeigen';
$lang['geotag_showsearch'] = 'Geotag verknüpfen an Suchen in der Nähe (spatialhelper plugin erforderlich)';
$lang['geotag_showsearch'] = 'Geotag verknüpfen an Suchen in der Nähe (spatialhelper plugin erforderlich)';
$lang['displayformat'] = 'Koordinaten Anzeigeformat; Dezimalgrad oder Grad, Minuten, Sekunden ';
2 changes: 1 addition & 1 deletion lang/en/lang.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright (c) 2011-2014 Mark C. Prins <mprins@users.sf.net>
* Copyright (c) 2011 Mark C. Prins <mprins@users.sf.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down
2 changes: 1 addition & 1 deletion lang/en/settings.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright (c) 2011-2014 Mark C. Prins <mprins@users.sf.net>
* Copyright (c) 2011 Mark C. Prins <mprins@users.sf.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down
2 changes: 1 addition & 1 deletion lang/fr/lang.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright (c) 2011-2014 Mark C. Prins <mprins@users.sf.net>
* Copyright (c) 2011 Mark C. Prins <mprins@users.sf.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down
6 changes: 3 additions & 3 deletions lang/fr/settings.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright (c) 2011-2014 Mark C. Prins <mprins@users.sf.net>
* Copyright (c) 2011 Mark C. Prins <mprins@users.sf.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand All @@ -26,5 +26,5 @@
$lang['geotag_hide'] = 'Masquer geotag (css)';
$lang['geotag_prevent_microformat_render'] = 'Prévenir rendu de microformat geotag';
$lang['toolbar_icon'] = 'Voir icône de la barre';
$lang['geotag_showsearch'] = 'Lier le geotag a rechercher aux alentours de (spatialhelper plugin nécessaire)';
$lang['displayformat'] = 'Format d\'affichage des Coordonnées; degrés décimaux ou degrés, minutes, secondes';
$lang['geotag_showsearch'] = 'Lier le geotag a rechercher aux alentours de (spatialhelper plugin nécessaire)';
$lang['displayformat'] = 'Format d\'affichage des Coordonnées; degrés décimaux ou degrés, minutes, secondes';
2 changes: 1 addition & 1 deletion lang/nl/lang.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright (c) 2011-2014 Mark C. Prins <mprins@users.sf.net>
* Copyright (c) 2011 Mark C. Prins <mprins@users.sf.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down
4 changes: 2 additions & 2 deletions lang/nl/settings.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright (c) 2011-2014 Mark C. Prins <mprins@users.sf.net>
* Copyright (c) 2011 Mark C. Prins <mprins@users.sf.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand All @@ -27,4 +27,4 @@
$lang['geotag_prevent_microformat_render'] = 'Voorkom geotag microformat rendering';
$lang['toolbar_icon'] = 'Toon toolbar icon';
$lang['geotag_showsearch'] = 'Link geotag als zoekactie (spatialhelper plugin benodigd)';
$lang['displayformat'] = 'Coördinaten weergave formaat; decimale graden of graden, minuten, seconden';
$lang['displayformat'] = 'Coördinaten weergave formaat; decimale graden of graden, minuten, seconden';
Loading

0 comments on commit a9083e4

Please sign in to comment.