diff --git a/action.php b/action.php index ee6073f..6998add 100644 --- a/action.php +++ b/action.php @@ -1,4 +1,9 @@ * @@ -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 */ -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'); } @@ -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; @@ -61,45 +64,27 @@ 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, @@ -107,17 +92,11 @@ final public function handleMetaheaderOutput(Doku_Event $event): void * $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]; } } @@ -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: }}']; } /** @@ -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(); diff --git a/conf/default.php b/conf/default.php index 34283b7..ffa7127 100644 --- a/conf/default.php +++ b/conf/default.php @@ -1,4 +1,5 @@ * @@ -21,6 +22,7 @@ * @license BSD license * @author Mark C. Prins */ + $conf['geotag_location_prefix'] = 'GEOTAG: '; $conf['geotag_showlocation'] = 0; $conf['geotag_hide'] = 0; diff --git a/conf/metadata.php b/conf/metadata.php index 00538aa..eda9ece 100644 --- a/conf/metadata.php +++ b/conf/metadata.php @@ -1,4 +1,5 @@ * @@ -21,6 +22,7 @@ * @license BSD license * @author Mark C. Prins */ + $meta ['geotag_location_prefix'] = array('string'); $meta ['geotag_showlocation'] = array('onoff'); $meta ['geotag_hide'] = array('onoff'); diff --git a/syntax/geotag.php b/syntax/geotag.php index 710a52b..9d24369 100644 --- a/syntax/geotag.php +++ b/syntax/geotag.php @@ -1,4 +1,5 @@ * @@ -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; /** @@ -25,7 +26,7 @@ * @license BSD license * @author Mark C. Prins */ -class syntax_plugin_geotag_geotag extends DokuWiki_Syntax_Plugin +class syntax_plugin_geotag_geotag extends SyntaxPlugin { /** * @@ -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; } @@ -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 ""; } @@ -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') . ' ' . $placename; $url = wl( - getID(), array( - 'do' => 'findnearby', - 'lat' => $ddlat, - 'lon' => $ddlon - ) + getID(), + ['do' => 'findnearby', 'lat' => $ddlat, 'lon' => $ddlon] ); $searchPre = ''; $searchPost = '' . $title . ''; @@ -178,7 +166,7 @@ final public function render($format, Doku_Renderer $renderer, $data): bool . $lat . ';'; $renderer->doc .= '' . $lon . ''; - if (!empty ($alt)) { + if (!empty($alt)) { $renderer->doc .= ', ' . $alt . 'm'; } @@ -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(); @@ -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 @@ -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