1<?php
2/**
3 * GeoNav Plugin
4 *
5 *  Provides a google earth map
6 *
7 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
8 * @author  Tom Cafferty <tcafferty@glocalfocal.com>
9 */
10
11// must be run within Dokuwiki
12if(!defined('DOKU_INC')) define('DOKU_INC',(dirname(__FILE__).'/../../').'/');
13if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
14require_once(DOKU_PLUGIN.'syntax.php');
15
16/**
17 * All DokuWiki plugins to extend the parser/rendering mechanism
18 * need to inherit from this class
19 */
20class syntax_plugin_geonav extends DokuWiki_Syntax_Plugin {
21
22    function getInfo() {
23        return array(
24            'author' => 'Tom Cafferty',
25            'email'  => 'tcafferty@glocalfocal.com',
26            'date'   => '2011-12-29',
27            'name'   => 'geonav',
28            'desc'   => 'Integrate google map with dokuwiki for navigation',
29            'url'    => 'http://www.dokuwiki.org/plugin:geonav'
30        );
31    }
32    /**
33     * What kind of syntax are we?
34     */
35  function getType(){
36      return 'substition';
37  }
38
39  function getPType(){
40      return 'block';
41  }
42
43    /**
44     * Where to sort in?
45     */
46  function getSort(){
47      return 160;
48  }
49
50  /**
51   * Connect pattern to lexer
52   */
53  function connectTo($mode) {
54      $this->Lexer->addSpecialPattern('<geonav>.*?</geonav>',$mode,'plugin_geonav');
55  }
56
57  /**
58   * Handle the match
59   */
60  function handle($match, $state, $pos, &$handler){
61      parse_str($match, $return);
62      return $return;
63  }
64
65  /**
66   *  Render output
67   */
68  function render($mode, &$R, $data) {
69      global $INFO;
70      global $conf;
71      require_once(DOKU_PLUGIN.'geonav/lang/en/lang.php');
72
73
74      // store meta info for this page
75      if($mode == 'metadata'){
76        $R->meta['plugin']['geonav'] = true;
77        return true;
78      }
79
80      if($mode != 'xhtml') return false;
81      $path  = $INFO['id'];
82      $topic = str_replace ( ':earth', '', $path);
83
84      $R->info['cache'] = false; // no cache please
85      $R->doc .= '<div id="home"><div id="map3d" class="mymap" ></div>';
86          $R->doc .= '<input id="location" type="text" value=" " class="ui-input-field">';
87          $R->doc .= '<button id="focus-btn" type="button" class="focusBtn">'.$lang['focus_btn'].'</button>';
88          $R->doc .= '<div id="userInput">'.$lang['focus'].'</div>';
89      $R->doc .= '</div>';
90      $R->doc .= $this->_script($topic);
91
92	  return true;
93  }
94
95  function _script($category){
96        $str = '<script type="text/javascript" language="javascript">';
97        $str .= 'var plugin_geonav_category = "'.$category.'";';
98        $str .= '</script>';
99        return $str;
100  }
101
102}
103