Skip to content

Commit

Permalink
🤖 Rector and PHPCS fixes (#36)
Browse files Browse the repository at this point in the history
Co-authored-by: mprins <mprins@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and mprins committed Nov 8, 2023
1 parent f07f2d9 commit d0af229
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 82 deletions.
86 changes: 29 additions & 57 deletions action.php
@@ -1,4 +1,9 @@
<?php

use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\EventHandler;
use dokuwiki\Extension\Event;

/*
* Copyright (c) 2011 Mark C. Prins <mprins@users.sf.net>
*
Expand All @@ -14,27 +19,25 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

/**
* DokuWiki Plugin geotag (Action Component).
*
* @license BSD license
* @author Mark C. Prins <mprins@users.sf.net>
*/
class action_plugin_geotag extends DokuWiki_Action_Plugin
class action_plugin_geotag extends ActionPlugin
{

/**
* Register for events.
*
* @param Doku_Event_Handler $controller
* DokuWiki's event controller object. Also available as global $EVENT_HANDLER
*/
final public function register(Doku_Event_Handler $controller): void
final public function register(EventHandler $controller): void
{
$controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handleMetaheaderOutput');
if ($this->getConf('toolbar_icon')) {
$controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'insertButton', array());
$controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'insertButton', []);
}
$controller->register_hook('PLUGIN_POPULARITY_DATA_SETUP', 'AFTER', $this, 'popularity');
}
Expand All @@ -48,11 +51,11 @@ final public function register(Doku_Event_Handler $controller): void
*
* @see https://www.dokuwiki.org/devel:event:tpl_metaheader_output
*/
final public function handleMetaheaderOutput(Doku_Event $event): void
final public function handleMetaheaderOutput(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();
$geotags = p_get_metadata($ID, 'geo', METADATA_RENDER_USING_SIMPLE_CACHE) ?? [];
$region = $geotags ['region'] ?? null;
$lat = $geotags ['lat'] ?? null;
$lon = $geotags ['lon'] ?? null;
Expand All @@ -61,63 +64,39 @@ final public function handleMetaheaderOutput(Doku_Event $event): void
$placename = $geotags ['placename'] ?? null;
$geohash = $geotags ['geohash'] ?? null;

if (!empty ($region)) {
$event->data ['meta'] [] = array(
'name' => 'geo.region',
'content' => $region
);
if (!empty($region)) {
$event->data ['meta'] [] = ['name' => 'geo.region', 'content' => $region];
}
if (!empty ($placename)) {
$event->data ['meta'] [] = array(
'name' => 'geo.placename',
'content' => $placename
);
if (!empty($placename)) {
$event->data ['meta'] [] = ['name' => 'geo.placename', 'content' => $placename];
}
if (!(empty ($lat) && empty ($lon))) {
if (!empty ($alt)) {
$event->data ['meta'] [] = array(
'name' => 'geo.position',
'content' => $lat . ';' . $lon . ';' . $alt
);
if (!(empty($lat) && empty($lon))) {
if (!empty($alt)) {
$event->data ['meta'] [] = ['name' => 'geo.position', 'content' => $lat . ';' . $lon . ';' . $alt];
} else {
$event->data ['meta'] [] = array(
'name' => 'geo.position',
'content' => $lat . ';' . $lon
);
$event->data ['meta'] [] = ['name' => 'geo.position', 'content' => $lat . ';' . $lon];
}
}
if (!empty ($country)) {
$event->data ['meta'] [] = array(
'name' => 'geo.country',
'content' => $country
);
if (!empty($country)) {
$event->data ['meta'] [] = ['name' => 'geo.country', 'content' => $country];
}
if (!(empty ($lat) && empty ($lon))) {
$event->data ['meta'] [] = array(
'name' => "ICBM",
'content' => $lat . ', ' . $lon
);
if (!(empty($lat) && empty($lon))) {
$event->data ['meta'] [] = ['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: 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/');
*/
$event->data ['meta'] [] = array(
'name' => "DC.title",
'content' => $title
);
$event->data ['meta'] [] = ['name' => "DC.title", 'content' => $title];
}
}
if (!empty ($geohash)) {
$event->data ['meta'] [] = array(
'name' => 'geo.geohash',
'content' => $geohash
);
if (!empty($geohash)) {
$event->data ['meta'] [] = ['name' => 'geo.geohash', 'content' => $geohash];
}
}

Expand All @@ -127,16 +106,9 @@ final public function handleMetaheaderOutput(Doku_Event $event): void
* @param Doku_Event $event
* the DokuWiki event
*/
final public function insertButton(Doku_Event $event, array $param): void
final public function insertButton(Event $event, array $param): void
{
$event->data [] = array(
'type' => 'format',
'title' => $this->getLang('toolbar_desc'),
'icon' => '../../plugins/geotag/images/geotag.png',
'open' => '{{geotag>lat:',
'sample' => '52.2345',
'close' => ', lon:7.521, alt: , placename: , country: , region: }}'
);
$event->data [] = ['type' => 'format', 'title' => $this->getLang('toolbar_desc'), 'icon' => '../../plugins/geotag/images/geotag.png', 'open' => '{{geotag>lat:', 'sample' => '52.2345', 'close' => ', lon:7.521, alt: , placename: , country: , region: }}'];
}

/**
Expand All @@ -145,7 +117,7 @@ final public function insertButton(Doku_Event $event, array $param): void
* @param Doku_Event $event
* the DokuWiki event
*/
final public function popularity(Doku_Event $event): void
final public function popularity(Event $event): void
{
$versionInfo = getVersionData();
$plugin_info = $this->getInfo();
Expand Down
2 changes: 2 additions & 0 deletions conf/default.php
@@ -1,4 +1,5 @@
<?php

/*
* Copyright (c) 2011 Mark C. Prins <mprins@users.sf.net>
*
Expand All @@ -21,6 +22,7 @@
* @license BSD license
* @author Mark C. Prins <mprins@users.sf.net>
*/

$conf['geotag_location_prefix'] = 'GEOTAG: ';
$conf['geotag_showlocation'] = 0;
$conf['geotag_hide'] = 0;
Expand Down
2 changes: 2 additions & 0 deletions conf/metadata.php
@@ -1,4 +1,5 @@
<?php

/*
* Copyright (c) 2011 Mark C. Prins <mprins@users.sf.net>
*
Expand All @@ -21,6 +22,7 @@
* @license BSD license
* @author Mark C. Prins <mprins@users.sf.net>
*/

$meta ['geotag_location_prefix'] = array('string');
$meta ['geotag_showlocation'] = array('onoff');
$meta ['geotag_hide'] = array('onoff');
Expand Down
36 changes: 11 additions & 25 deletions syntax/geotag.php
@@ -1,4 +1,5 @@
<?php

/*
* Copyright (c) 2011 Mark C. Prins <mprins@users.sf.net>
*
Expand All @@ -14,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

use dokuwiki\Extension\SyntaxPlugin;
use geoPHP\Geometry\Point;

/**
Expand All @@ -25,7 +26,7 @@
* @license BSD license
* @author Mark C. Prins <mprins@users.sf.net>
*/
class syntax_plugin_geotag_geotag extends DokuWiki_Syntax_Plugin
class syntax_plugin_geotag_geotag extends SyntaxPlugin
{
/**
*
Expand Down Expand Up @@ -98,17 +99,7 @@ final public function handle($match, $state, $pos, Doku_Handler $handler): array
$style = '';
}

$data = array(
hsc(trim(substr($lat [0], 4))),
hsc(trim(substr($lon [0], 4))),
hsc(trim(substr(($alt[0] ?? ''), 4))),
$this->geohash(substr($lat [0], 4), substr($lon [0], 4)),
hsc(trim(substr(($region[0] ?? ''), 7))),
hsc(trim(substr(($placename[0] ?? ''), 10))),
hsc(trim(substr(($country [0] ?? ''), 8))),
hsc($showlocation),
$style
);
$data = [hsc(trim(substr($lat [0], 4))), hsc(trim(substr($lon [0], 4))), hsc(trim(substr(($alt[0] ?? ''), 4))), $this->geohash(substr($lat [0], 4), substr($lon [0], 4)), hsc(trim(substr(($region[0] ?? ''), 7))), hsc(trim(substr(($placename[0] ?? ''), 10))), hsc(trim(substr(($country [0] ?? ''), 8))), hsc($showlocation), $style];
return $data;
}

Expand All @@ -120,7 +111,7 @@ final public function handle($match, $state, $pos, Doku_Handler $handler): array
*/
private function geohash(float $lat, float $lon)
{
if (!$geophp = plugin_load('helper', 'geophp')) {
if (($geophp = plugin_load('helper', 'geophp')) === null) {
return "";
}

Expand Down Expand Up @@ -154,14 +145,11 @@ final public function render($format, Doku_Renderer $renderer, $data): bool
$searchPre = '';
$searchPost = '';
if ($this->getConf('geotag_showsearch')) {
if ($spHelper = plugin_load('helper', 'spatialhelper_search')) {
if (($spHelper = plugin_load('helper', 'spatialhelper_search')) !== null) {
$title = $this->getLang('findnearby') . '&nbsp;' . $placename;
$url = wl(
getID(), array(
'do' => 'findnearby',
'lat' => $ddlat,
'lon' => $ddlon
)
getID(),
['do' => 'findnearby', 'lat' => $ddlat, 'lon' => $ddlon]
);
$searchPre = '<a href="' . $url . '" title="' . $title . '">';
$searchPost = '<span class="a11y">' . $title . '</span></a>';
Expand All @@ -178,7 +166,7 @@ final public function render($format, Doku_Renderer $renderer, $data): bool
. $lat . '</span>;';
$renderer->doc .= '<span class="p-longitude longitude" itemprop="longitude" data-longitude="' . $ddlon
. '">' . $lon . '</span>';
if (!empty ($alt)) {
if (!empty($alt)) {
$renderer->doc .= ', <span class="p-altitude altitude" itemprop="elevation" data-altitude="' . $alt
. '">' . $alt . 'm</span>';
}
Expand All @@ -192,12 +180,12 @@ final public function render($format, Doku_Renderer $renderer, $data): bool
$renderer->meta ['geo'] ['region'] = $region;
$renderer->meta ['geo'] ['country'] = $country;
$renderer->meta ['geo'] ['geohash'] = $geohash;
if (!empty ($alt)) {
if (!empty($alt)) {
$renderer->meta ['geo'] ['alt'] = $alt;
}
return true;
} elseif ($format === 'odt') {
if (!empty ($alt)) {
if (!empty($alt)) {
$alt = ', ' . $alt . 'm';
}
$renderer->p_open();
Expand All @@ -217,7 +205,6 @@ final public function render($format, Doku_Renderer $renderer, $data): bool
* convert latitude in decimal degrees to DMS+hemisphere.
*
* @param float $decimaldegrees
* @return string
* @todo move this into a shared library
*/
private function convertLat(float $decimaldegrees): string
Expand Down Expand Up @@ -252,7 +239,6 @@ private function convertDDtoDMS(float $decimaldegrees): string
* convert longitude in decimal degrees to DMS+hemisphere.
*
* @param float $decimaldegrees
* @return string
* @todo move this into a shared library
*/
private function convertLon(float $decimaldegrees): string
Expand Down

0 comments on commit d0af229

Please sign in to comment.