DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:maplink

maplink Plugin

Compatible with DokuWiki

Adora Belle, Weatherwax, Binky

plugin Links an address or other search text directly to Google maps

Last updated on
2013-12-26
Provides
Syntax

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Similar to anchor

Tagged with links, maps

By chlw

This plugin links an address or any other string directly to Google maps. This can be helpful if you want to provide a link to Google maps without embedding the map.

This plugin is based on the Plugins anchor and iCalendar. I just took parts of those plugins an merged them together. So all the kudos go to those authors!

Installation

This plugin is very simple (contains only one file) and I'm not familiar with the repository-stuff (git etc.). Therefore I'm just going to include the source code here as well (e.g. in case the link to the download is broken etc.).

The following code should be copied in the file “lib/plugins/maplink/syntax.php”, that means:

  1. Create a directory “maplink” in the “/lib/plugins”-Directory of your Dokuwiki Installation
  2. Create a file containing the code below and name it “syntax.php”
  3. Put this file in the directory, you created in step 1 (lib/plugins/maplink/)
lib/plugins/maplink/syntax.php
<?php
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');  
 
class syntax_plugin_maplink extends DokuWiki_Syntax_Plugin {
    function getType() {return 'substition';}
    function getPType() {return 'block';}
    function getSort() {return 167;}
    function getInfo() {return array('author' => 'chlw; based on work by Eli Fenton (Anchor Plugin) and J. Drost-Tenfelde (iCalendar Plugin)', 'name' => 'maplink', 'url' => 'http://dokuwiki.org/plugin:maplink');}
    function connectTo($mode){
        $this->Lexer->addSpecialPattern('\{\{maplink:[^}]*\}\}', $mode, 'plugin_maplink');
    }
 
    function handle($match, $state, $pos, &$handler) {
        return explode(':', substr($match, strlen('{{maplink:'), -2));
    }
 
    function render($mode, &$renderer, $data) {
      //  $renderer->doc .= '<a href="' .htmlspecialchars($data[0]) . '">' .htmlspecialchars($data[1]) . '</a>';
 
        $renderer->doc .= '<a href="http://maps.google.com/maps?q='.str_replace(' ', '+', str_replace(',', ' ', $data[0])). '"target="_blank">' .htmlspecialchars($data[1]) . '</a>';
    }
}

You might want to delete the code

"target="_blank"

if the map should open in the same window.

Examples/Usage

Here's how you create a link:

{{maplink:string_to_search:text_to_display}}

The string_to_search part is what Google maps should search for (can be an address or any other string, see examples below). The text_to_display part is what the user sees as the clickable text.

Examples

The following code genereates a clickable link with text:

{{maplink:15010 NE 36th Street, Microsoft Campus, Redmond, WA 98052:This is a link to the Microsoft Visitor Center}}



The same link with the address as text:

{{maplink:15010 NE 36th Street, Microsoft Campus, Redmond, WA 98052:15010 NE 36th Street, Microsoft Campus, Redmond, WA 98052}}



You might want to search for other strings (e.g. names of places, hotels, attractions etc.) than plain addresses:

{{maplink:The Peninsula Hotel, Bangkok:Five Star Hotel in Thailand}}

Screenshots

Link in Action

Example Code



Configuration and Settings

The plugin has no configuration or settings. You might want to delete the code

"target="_blank"

if you want the map to open in the same window (instead of a new one).

Development

This is my first plugin and I'm not really familiar with programming, so I'm quite sure someone can improve it.

Change Log

  • 2013-12-26
    • Initial release

Known Bugs and Issues

None, so far.

ToDo/Wish List

  • Could this be coded in a more clever way?
  • Does this code really cover all possible cases? I tried it with some Thai text and, no surprise, it did not work.

Discussion

Please discuss the plugin here.

plugin/maplink.txt · Last modified: 2013-12-26 15:44 by chlw