1<?php
2/**
3 * Timeline Action Plugin
4 *
5 *  Provides a wiki timeline
6 *
7 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
8 * @author     Dan Kreiser <dan.kreiser@gmail.com>
9 * @author     Tom Cafferty <tcafferty@glocalfocal.com>
10 */
11if(!defined('DOKU_INC')) define('DOKU_INC',(dirname(__FILE__).'/../../').'/');
12if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
13require_once(DOKU_PLUGIN.'syntax.php');
14/**
15 * All DokuWiki plugins to extend the parser/rendering mechanism
16 * need to inherit from this class
17 */
18class syntax_plugin_eventline extends DokuWiki_Syntax_Plugin {
19
20    function getInfo() {
21        return array(
22            'author' => 'Tom Cafferty',
23            'email'  => 'tcafferty@glocalfocal.com',
24            'date'   => '2011-12-29',
25            'name'   => 'eventline',
26            'desc'   => 'Integrate simile timeline with dokuwiki',
27            'url'    => 'http://www.dokuwiki.org/plugin:eventline'
28        );
29    }
30    /**
31     * What kind of syntax are we?
32     */
33    function getType(){
34        return 'substition';
35    }
36
37    function getPType(){
38        return 'block';
39    }
40
41    /**
42     * Where to sort in?
43     */
44    function getSort(){
45        return 160;
46    }
47
48    /**
49     * Connect pattern to lexer
50     */
51    function connectTo($mode) {
52      $this->Lexer->addSpecialPattern('<eventline>.*?</eventline>',$mode,'plugin_eventline');
53    }
54
55    /**
56     * Handle the match
57     */
58    function handle($match, $state, $pos, &$handler){
59        parse_str($match, $return);
60        return $return;
61    }
62
63/**
64 *
65 * Create timeline output
66 *
67 * @author   Tom Cafferty <tcafferty@glocalfocal.com>
68 *
69 */
70    function render($mode, &$R, $data) {
71      global $INFO;
72      global $ID;
73      global $conf;
74
75      // store meta info for this page
76      if($mode == 'metadata'){
77        $R->meta['plugin']['eventline'] = true;
78        return true;
79      }
80
81      if($mode != 'xhtml') return false;
82      // Initialize settings from user input or conf file
83      if (isset($data['bubbleMaxHeight']))
84        $bubbleHeight = $data['bubbleMaxHeight'];
85      else
86        $bubbleHeight = $this->getConf('bubbleMaxHeight');
87
88      if (isset($data['bubbleWidth']))
89        $bubbleWidth = $data['bubbleWidth'];
90      else
91        $bubbleWidth = $this->getConf('bubbleWidth');
92
93      if (isset($data['height']))
94        $height = $data['height'];
95      else
96        $height = $this->getConf('height');
97
98      if (isset($data['mouse']))
99        $mouse = $data['mouse'];
100      else
101        $mouse = $this->getConf('mouse');
102
103       if (isset($data['center']))
104        $center = $data['center'];
105      else
106        $center = $this->getConf('center');
107
108       if (isset($data['controls']))
109        $controls = $data['controls'];
110      else
111        $controls = $this->getConf('controls');
112
113       if (isset($data['bandPos']))
114        $bandPos = $data['bandPos'];
115      else
116        $bandPos = $this->getConf('bandPos');
117
118       if (isset($data['detailPercent']))
119        $detailPercent = $data['detailPercent'];
120      else
121        $detailPercent = $this->getConf('detailPercent');
122
123       if (isset($data['overPercent']))
124        $overPercent = $data['overPercent'];
125      else
126        $overPercent = $this->getConf('overPercent');
127
128       if (isset($data['detailPixels']))
129        $detailPixels = $data['detailPixels'];
130      else
131        $detailPixels = $this->getConf('detailPixels');
132
133       if (isset($data['overPixels']))
134        $overPixels = $data['overPixels'];
135      else
136        $overPixels = $this->getConf('overPixels');
137
138       if (isset($data['detailInterval']))
139        $detailInterval = $data['detailInterval'];
140      else
141        $detailInterval = $this->getConf('detailInterval');
142
143       if (isset($data['overInterval']))
144        $overInterval = $data['overInterval'];
145      else
146        $overInterval = $this->getConf('overInterval');
147
148       if (isset($data['hotzone']) && $data['hotzone']=='on')
149        $hotzone = 1;
150       else
151        $hotzone = 0;
152
153       $hzStart = $data['hzStart'];
154       $hzStart2 = $data['hzStart2'];
155       $hzStart3 = $data['hzStart3'];
156       $hzEnd = $data['hzEnd'];
157       $hzEnd2 = $data['hzEnd2'];
158       $hzEnd3 = $data['hzEnd3'];
159       $hzMagnify = $data['hzMagnify'];
160       $hzMagnify2 = $data['hzMagnify2'];
161       $hzMagnify3 = $data['hzMagnify3'];
162       $hzUnit = $data['hzUnit'];
163       $hzUnit2 = $data['hzUnit2'];
164       $hzUnit3 = $data['hzUnit3'];
165
166      // Get file name ($dataFile) and full url path
167      $ns = $INFO['namespace'];
168      if (strpos($ns, ':') == false) $ns = $ns . ':';
169      $dataFile = $ID.':' . $data['file'];
170      $filePath = DOKU_URL . 'lib/plugins/eventline/getData.php?id='.urlencode($dataFile);
171
172      // Set timeline div & class for css styling and jsvascript id
173	  $R->doc .='<div id="eventlineplugin__timeline" class="eventlineplugin__class" style="height:'.$height.';"></div>';
174
175	  // Add a link to the data file for dokuwiki editing (.txt) version if user has write access
176	  $showlink = $this->getConf('showlink');
177      $info_perm     = auth_quickaclcheck($dataFile);
178      $info_filepath = fullpath(wikiFN($dataFile));
179      $info_writable = (is_writable($info_filepath) && ($info_perm >= AUTH_EDIT));
180	  if($info_writable || ($showlink==1))
181	  $R->doc .='<div id="eventlineplugin__data"> Go to <a title="' . $dataFile .'" class="wikilink1" href="' . wl($dataFile) . '">'.$data['file'].'</a> data</div>';
182
183	  // Add a div for timeline filter controls if selected
184	  if ($controls==1){
185		$R->doc .='<div class="eventlineplugin__controls" id="eventlineplugin__controls"></div>';
186	  }
187
188	  // onload invoke timeline javascript
189	  $R->doc .= $this->_script($filePath, $bubbleHeight, $bubbleWidth, $mouse, $center, $controls, $bandPos, $detailPercent, $overPercent, $detailPixels, $overPixels, $detailInterval, $overInterval, $hotzone, $hzStart, $hzEnd, $hzMagnify, $hzUnit, $hzStart2, $hzEnd2, $hzMagnify2, $hzUnit2, $hzStart3, $hzEnd3, $hzMagnify3, $hzUnit3);
190	  return true;
191    }
192
193    function _script($filePath, $bubbleHeight, $bubbleWidth, $mouse, $center, $controls, $bandPos, $detailPercent, $overPercent, $detailPixels, $overPixels, $detailInterval, $overInterval, $hotzone, $hzStart, $hzEnd, $hzMagnify, $hzUnit, $hzStart2, $hzEnd2, $hzMagnify2, $hzUnit2, $hzStart3, $hzEnd3, $hzMagnify3, $hzUnit3){
194        $str = '<script type="text/javascript" language="javascript">';
195        $str .= 'var plugin_eventline_filePath = "'.$filePath.'";';
196        $str .= 'var plugin_eventline_bubbleHeight = '.$bubbleHeight.';';
197        $str .= 'var plugin_eventline_bubbleWidth = '.$bubbleWidth.';';
198        $str .= 'var plugin_eventline_mouse = "'.$mouse.'";';
199        $str .= 'var plugin_eventline_center = "'.$center.'";';
200        $str .= 'var plugin_eventline_controls = "'.$controls.'";';
201        $str .= 'var plugin_eventline_bandPos = "'.$bandPos.'";';
202        $str .= 'var plugin_eventline_detailPercent = "'.$detailPercent.'";';
203        $str .= 'var plugin_eventline_overPercent = "'.$overPercent.'";';
204        $str .= 'var plugin_eventline_detailPixels = "'.$detailPixels.'";';
205        $str .= 'var plugin_eventline_overPixels = "'.$overPixels.'";';
206        $str .= 'var plugin_eventline_detailInterval = "'.$detailInterval.'";';
207        $str .= 'var plugin_eventline_overInterval = "'.$overInterval.'";';
208        $str .= 'var plugin_eventline_hotzone = "'.$hotzone.'";';
209        $str .= 'var plugin_eventline_hzStart = "'.$hzStart.'";';
210        $str .= 'var plugin_eventline_hzEnd = "'.$hzEnd.'";';
211        $str .= 'var plugin_eventline_hzMagnify = "'.$hzMagnify.'";';
212        $str .= 'var plugin_eventline_hzUnit = "'.$hzUnit.'";';
213        $str .= 'var plugin_eventline_hzStart2 = "'.$hzStart2.'";';
214        $str .= 'var plugin_eventline_hzEnd2 = "'.$hzEnd2.'";';
215        $str .= 'var plugin_eventline_hzMagnify2 = "'.$hzMagnify2.'";';
216        $str .= 'var plugin_eventline_hzUnit2 = "'.$hzUnit2.'";';
217        $str .= 'var plugin_eventline_hzStart3 = "'.$hzStart3.'";';
218        $str .= 'var plugin_eventline_hzEnd3 = "'.$hzEnd3.'";';
219        $str .= 'var plugin_eventline_hzMagnify3 = "'.$hzMagnify3.'";';
220        $str .= 'var plugin_eventline_hzUnit3 = "'.$hzUnit3.'";';
221        $str .= "jQuery('#plugin_eventline').bind('load', plugin_eventline());";
222        $str .= "jQuery('#plugin_eventline').bind('resize', plugin_eventline_onResize());";
223        $str .= '</script>';
224        return $str;
225    }
226}
227