1<?php
2
3if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
4if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
5require_once(DOKU_PLUGIN.'syntax.php');
6
7/**
8 * All DokuWiki plugins to extend the parser/rendering mechanism
9 * need to inherit from this class
10 */
11class syntax_plugin_routenplaner_routenplaner extends DokuWiki_Syntax_Plugin {
12
13var $l2s_country_names = array(
14'Belgien' =>  'BEL',
15'Dänemark' => 'DNK',
16'Deutschland' => 'DEU',
17'Frankreich' => 'FRA',
18'Großbritannien' => 'GBR',
19'Italien' => 'ITA',
20'Liechtenstein' => 'LIE',
21'Luxemburg' => 'LUX',
22'Niederlande' => 'NLD',
23'Norwegen' => 'NOR',
24'Österreich' => 'AUT',
25'Portugal' => 'PRT',
26'Schweden' => 'SWE',
27'Schweiz' => 'CHE',
28'Spanien' => 'ESP',
29'Albanien' =>"ALB",
30'Andorra' =>"AND",
31'Armenien'=>"ARM",
32'Aserbaidschan'=>"AZE",
33'Bosnien-Herzegowina'=>"BIH",
34'Bulgarien'=>"BGR",
35'Estland'=>"EST",
36'Faroer Inseln'=>"FRO",
37'Finnland'=>"FIN",
38'Georgien'=>"GEO",
39'Gibraltar'=>"GIB",
40'Griechenland'=>"GRC",
41'Irland'=>"IRL",
42'Island'=>"ISL",
43'Kroatien'=>"HRV",
44'Lettland'=>"LVA",
45'Litauen'=>"LTU",
46'Malta'=>"MLT",
47'Makedonien'=>"MKD",
48'Moldawien'=>"MDA",
49'Monaco'=>"MCO",
50'Polen'=>"POL",
51'Rumänien'=>"ROM",
52'Russland'=>"RUS",
53'San Marino'=>"SMR",
54'Serbien und Montenegro'=>"SCG",
55'Slowakische Republik'=>"SVK",
56'Slowenien'=>"SVN",
57'Tschechische Republik'=>"CZE",
58'Türkei'=>"TUR",
59'Ukraine'=>"UKR",
60'Ungarn'=>"HUN",
61'Vatikanstadt'=>"VAT",
62'Weißrussland'=>"BLR",
63'Zypern'=>"CYP"
64);
65    /**
66     * return some info
67     */
68    function getInfo(){
69        return array(
70            'author' => 'Deshi, Jaloma',
71            'email'  => 'deshi@web.de, jaloma.ac@googlemail.com',
72            'date'   => '17/10/2008',
73            'name'   => 'Routenplaner Plugin',
74            'desc'   => 'plan your route using lycos or web.de',
75		 'url'    => 'http://jaloma.ac.googlepages.com/plugin:routenplaner'
76        );
77    }
78
79    /**
80     * Syntax-Beispiel: {{routeplaner> Hubert Meier, Mustergasse 3, 80756, München, Deutschland}}
81     */
82
83
84/**
85 * Plugin Type
86 */
87
88 	function getType(){ return 'substition'; }
89 	function getSort(){ return 314; }
90 	function connectTo($mode) { $this->Lexer->addSpecialPattern("\{\{routenplaner>.*?\}\}",$mode,'plugin_routenplaner_routenplaner'); }
91
92
93function matchLength() {
94 return 15;
95 }
96
97/**
98 * Handle the match
99 */
100
101    function handle($match, $state, $pos, &$handler){
102
103        // strip markup
104		//12345678901234567890123
105		//{{routenplaner>
106		//{{routenplaner_webde>
107		//{{routenplaner_lycosde>
108        $match = html_entity_decode(substr($match,$this->matchLength(),-2));
109
110        // split into pieces
111        list($company,$street,$zip, $town, $country) = explode(',',$match,5);
112
113        // beautify strings
114        if (trim($company, " \t\n") != '') {
115        	$company = trim($company, " \t\n");
116        } else {
117        	$company = 'Firma';
118        }
119        if (trim($street, " \t\n") != '') {
120        	$street = trim($street, " \t\n");
121        } else {
122        	$street = ' ';//missing street';
123        }
124        if (trim($zip, " \t\n") != '') {
125        	$zip = trim($zip, " \t\n");
126        } else {
127        	$zip = ' ';//'missing zip';
128        }
129        if (trim($town, " \t\n") != '') {
130        	$town = trim($town, " \t\n");
131        } else {
132        	$town = ' ';//'missing town';
133        }
134        if (trim($country, " \t\n") != '') {
135        	$country = trim($country, " \t\n");
136        } else {
137        	$country = ' ';//'missing country';
138        }
139
140        return array($company,$street,$zip,$town,$country);
141    }
142
143
144/**
145 * Create output
146 */
147    function render($mode, &$renderer, $data) {
148        if($mode == 'xhtml'){
149            $renderer->doc .= $this->_contact($data);
150            return true;
151        }
152        return false;
153    }
154
155/**
156 * Does the contact form xhtml creation. Adds some javascript to validate the form
157 * and creates the input form.
158 */
159
160
161    /**
162     * Does the contact form xhtml creation. Adds some javascript to validate the form
163     * and creates the input form.
164     */
165    function _contact($data){
166    	if ($this->getConf('modus') == 'lycosde') {
167    		return $this->lycosDeFormular($data);
168    	} elseif ($this->getConf('modus') == 'webde') {
169    		return $this->webDeFormular($data);
170    	} else {
171        return 'Modus nicht unterstützt';
172      }
173    }
174
175	function lycosDeFormular($data) {
176		$company = $data[0];
177		@$street = $data[1];
178		@$zip = $data[2];
179		@$town = $data[3];
180		@$country = $data[4];
181        $ret = '';
182
183//        $ret .= '<script type="text/javascript"></script>';
184        $ret .= '<div class="columns1">';
185        $ret .= '<form name="routenplaner2" method="get" target="_blank" action="http://www.lycos.de/routenplaner/index.html">';
186        $ret .= '<input type="hidden" name="tocountry" value="'.$this->l2s_country_names[$country].'" />';
187        $ret .= '<input type="hidden" name="tostreet" value="'.$street.'" />';
188        $ret .= '<input type="hidden" name="toplz" value="'.$zip.'" />';
189        $ret .= '<input type="hidden" name="tocity" value="'.$town.'" />';
190        $ret .= '<table border="0" cellpadding="0" cellspacing="0" style="background-image:url(http://www.lycos.de/i/c/reise/routenplaner/box_partner.gif);background-repeat:no-repeat;width:379px;height:176px;"><tr><td><br>';
191        $ret .= '<table border="0" cellpadding="0" cellspacing="0" style="margin-left:15px;padding: 0px 0px 0px 0px;font: 12px "Trebuchet MS", Tahoma, Geneva, Arial, Helvetica, sans-serif;color: #000;">';
192        $ret .= '<tr>';
193        $ret .= '<td width="47%"> </td>';
194        $ret .= '<td width="6%"> </td>';
195        $ret .= '<td width="47%"><strong>Ziel:</strong></td>';
196        $ret .= '</tr>';
197        $ret .= '<tr>';
198        $ret .= '<td width="47%"><strong>Start:</strong></td>';
199        $ret .= '<td width="6%"> </td>';
200        $ret .= '<td width="47%"><input type="text" name="toname_" value="'.$company.'" disabled="disabled" style="width:155px;" /></td>';
201        $ret .= '</tr>';
202        $ret .= '<tr>';
203        $ret .= '<td><input type="TEXT" name="fromstreet" value="Straße" size="12" style="width: 155px;" tabindex="1" onfocus="javascript:if (document.routenplaner.fromstreet.value == '."'".'Straße'."'".') document.routenplaner.fromstreet.value = '."''".';"></td>';
204        $ret .= '<td> </td>';
205        $ret .= '<td><input type="TEXT" name="tostreet_" value="'.$street.'" size="12" style="width: 155px;" tabindex="5" disabled="disabled" /></td>';
206        $ret .= '</tr>';
207        $ret .= '<tr>';
208        $ret .= '<td><input type="TEXT" name="fromplz" value="PLZ" size="5" style="width: 45px;"  maxlength="10" tabindex="2" onfocus="javascript:if (document.routenplaner.fromplz.value == '."'".'PLZ'."'".') document.routenplaner.fromplz.value = '."''".';"> ';
209        $ret .= '<input type="TEXT" name="fromcity" value="Ort" size="8" style="width: 101px;" tabindex="3" onfocus="javascript:if (document.routenplaner.fromcity.value == '."'".'Ort'."'".') document.routenplaner.fromcity.value = '."''".';"></td>';
210        $ret .= '<td></td>';
211        $ret .= '<td><input type="TEXT" name="toplz_" value="'.$zip.'" tabindex="6" size="5" style="width: 45px;"  maxlength="10" disabled="disabled" /> ';
212        $ret .= '<input type="TEXT" name="tocity_" value="'.$town.'" tabindex="7" size="8" style="width: 101px;" disabled="disabled" /></td>';
213        $ret .= '</tr>';
214        $ret .= '<tr>';
215        $ret .= '<td><select name="fromcountry" tabindex="4" style="width:155px;">';
216        $ret .= '	<option value="---">Bitte wählen...</option>';
217        $ret .= '	<option value="BEL">Belgien</option>';
218        $ret .= '	<option value="DNK">Dänemark</option>';
219        $ret .= '	<option value="DEU" selected="selected">Deutschland</option>';
220        $ret .= '	<option value="FRA">Frankreich</option>';
221        $ret .= '	<option value="GBR">Großbritannien</option>';
222        $ret .= '	<option value="ITA">Italien</option>';
223        $ret .= '	<option value="LIE">Liechtenstein</option>';
224        $ret .= '	<option value="LUX">Luxemburg</option>';
225        $ret .= '	<option value="NLD">Niederlande</option>';
226        $ret .= '	<option value="NOR">Norwegen</option>';
227        $ret .= '	<option value="AUT">Österreich</option>';
228        $ret .= '	<option value="PRT">Portugal</option>';
229        $ret .= '	<option value="SWE">Schweden</option>';
230        $ret .= '	<option value="CHE">Schweiz</option>';
231        $ret .= '	<option value="ESP">Spanien</option>';
232        $ret .= '</select>';
233        $ret .= '</td>';
234        $ret .= '<td></td>';
235        $ret .= '<td><input type="text" name="tocountry_" value="'.$country.'" disabled="disabled" style="width:155px;" /></td>';
236        $ret .= '</tr>';
237        $ret .= '<tr>';
238        $ret .= '	<td colspan="3" align="right" style="float:right;"><div class="button" style="width:110px;text-align:center;float:right;margin-top:5px;"><div class="btnleft"></div><div class="btncenter" style="width:90px;text-align:center;"><input type="Submit" value="Berechnen"></div><div class="btnright"></div><div class="breaker"></div></div></td>';
239        $ret .= '</tr>';
240        $ret .= '</table>';
241        $ret .= '</td></tr></table></form>';
242        $ret .= '<div class="breaker"></div>';
243        $ret .= '</div>';
244
245        return $ret;
246    }
247
248    function webDeFormular($data) {
249		@$company = $data[0];
250		@$street = $data[1];
251		@$zip = $data[2];
252		@$town = $data[3];
253		@$country = $data[4];
254		$txt .='<form id="route" method="get" target="_blank" action="http://iww.web.de/de/themen/auto/routenplaner/">';
255		$txt .='<table cellpadding="0" cellspacing="0" style="background: #FFF url(http://iww.web.de/de/themen/auto/routenplaner/img/webde_rp_hg.gif) bottom left no-repeat; width: 461px;">';
256		$txt .='<tr>';
257		$txt .='<td style="vertical-align: top;"><img src="http://iww.web.de/de/themen/auto/routenplaner/img/webde_rp_oben.gif" alt="" style="margin: 0;"></td>';
258		$txt .='</tr>';
259		$txt .='<tr>';
260		$txt .='<td style="vertical-align: top;"><img src="http://iww.web.de/de/themen/auto/routenplaner/img/webde_rp_balkon_icon.gif" alt="" style="margin: 0;"></td>';
261		$txt .='</tr>';
262		$txt .='<tr>';
263		$txt .='<td>';
264		$txt .='<table style="border: 1px solid #D8DFE5; border-top: none; border-bottom: none; margin-bottom: 3px; width: 100%;">';
265		$txt .='<tr>';
266		$txt .='<td style="width: 50%;">';
267		$txt .='<input id="fromstreet" name="fromstreet" value="Straße" size="12" style="font-size: 12px; width: 206px; margin: 5px 5px 0 10px;" tabindex="1" onfocus="if (this.value == '."'Straße'".') this.value = '."''".';" type="text" /><br/>';
268		$txt .='<input id="fromplz" name="fromplz" value="PLZ" size="2" style="font-size: 12px; vertical-align: top; width: 47px; margin: 5px 5px 0 10px;" maxlength="10" tabindex="2" onfocus="if (this.value == '."'PLZ'".') this.value = '."''".';" type="text" />';
269		$txt .='<input id="fromcity" name="fromcity" value="Ort" size="8" style="font-size: 12px; width: 144px; margin-top: 5px;" tabindex="3" onfocus="if (this.value == '."'Ort'".') this.value = '."''".';" type="text" /><br/>';
270		$txt .='<select id="fromcountry" name="fromcountry" tabindex="4" style="font-size: 12px; width: 212px; margin: 5px 9px 0 10px;">';
271		$txt .='<option value="---">Bitte wählen...</option>';
272		$txt .='<option value="ALB">Albanien</option>';
273		$txt .='<option value="AND">Andorra</option>';
274		$txt .=' 			<option value="ARM">Armenien</option>';
275		$txt .=' 			<option value="AZE">Aserbaidschan</option>';
276		$txt .=' 			<option value="BEL">Belgien</option>';
277		$txt .=' 			<option value="BIH">Bosnien-Herzegowina</option>';
278		$txt .=' 			<option value="BGR">Bulgarien</option>';
279		$txt .=' 			<option value="DNK">Dänemark</option>';
280		$txt .=' 			<option value="DEU" selected="selected">Deutschland</option>';
281		$txt .=' 			<option value="EST">Estland</option>';
282		$txt .=' 			<option value="FRO">Faroer Inseln</option>';
283		$txt .=' 			<option value="FIN">Finnland</option>';
284		$txt .=' 			<option value="FRA">Frankreich</option>';
285		$txt .=' 			<option value="GEO">Georgien</option>';
286		$txt .=' 			<option value="GIB">Gibraltar</option>';
287		$txt .=' 			<option value="GRC">Griechenland</option>';
288		$txt .=' 			<option value="GBR">Großbritannien</option>';
289		$txt .=' 			<option value="IRL">Irland</option>';
290		$txt .=' 			<option value="ISL">Island</option>';
291		$txt .=' 			<option value="ITA">Italien</option>';
292		$txt .=' 			<option value="HRV">Kroatien</option>';
293		$txt .=' 			<option value="LVA">Lettland</option>';
294		$txt .=' 			<option value="LIE">Liechtenstein</option>';
295		$txt .=' 			<option value="LTU">Litauen</option>';
296		$txt .=' 			<option value="LUX">Luxemburg</option>';
297		$txt .=' 			<option value="MLT">Malta</option>';
298		$txt .=' 			<option value="MKD">Makedonien</option>';
299		$txt .=' 			<option value="MDA">Moldawien</option>';
300		$txt .=' 			<option value="MCO">Monaco</option>';
301		$txt .=' 			<option value="NLD">Niederlande</option>';
302		$txt .=' 			<option value="NOR">Norwegen</option>';
303		$txt .=' 			<option value="AUT">Österreich</option>';
304		$txt .=' 			<option value="POL">Polen</option>';
305		$txt .=' 			<option value="PRT">Portugal</option>';
306		$txt .=' 			<option value="ROM">Rumänien</option>';
307		$txt .=' 			<option value="RUS">Russland</option>';
308		$txt .=' 			<option value="SMR">San Marino</option>';
309		$txt .=' 			<option value="SWE">Schweden</option>';
310		$txt .=' 			<option value="CHE">Schweiz</option>';
311		$txt .=' 			<option value="SCG">Serbien und Montenegro</option>';
312		$txt .=' 			<option value="SVK">Slowakische Republik</option>';
313		$txt .=' 			<option value="SVN">Slowenien</option>';
314		$txt .=' 			<option value="ESP">Spanien</option>';
315		$txt .=' 			<option value="CZE">Tschechische Republik</option>';
316		$txt .=' 			<option value="TUR">Türkei</option>';
317		$txt .=' 			<option value="UKR">Ukraine</option>';
318		$txt .=' 			<option value="HUN">Ungarn</option>';
319		$txt .=' 			<option value="VAT">Vatikanstadt</option>';
320		$txt .=' 			<option value="BLR">Weißrussland</option>';
321		$txt .=' 			<option value="CYP">Zypern</option>';
322		$txt .=' 		</select>';
323		$txt .=' 	</td>';
324		$txt .=' 	<td>';
325		$txt .='';
326		$txt .=' 		<input id="tostreet" name="tostreet" value="'.$street.'" type="hidden">';
327		$txt .=' 		<input id="toplz" name="toplz" value="'.$zip.'" size="3" type="hidden">';
328		$txt .=' 		<input id="tocity" name="tocity" value="'.$town.'" size="8" type="hidden">';
329		$txt .=' 		<input id="tocountry" name="tocountry" type="hidden" value="'.$this->l2s_country_names[$country].'">';
330		$txt .=' 		<p style="font-size: 12px; font-weight: 700; margin: 0 5px !important;"></p>';
331		$txt .=' 		<p style="font-size: 12px; margin: 8px 5px !important;">'.$street.'</p>';
332		$txt .=' 		<p style="font-size: 12px; margin: 0 5px !important;">'.$country.' - '.$zip.' '.$town.'</p>';
333		$txt .='';
334		$txt .=' 	</td>';
335		$txt .=' </tr>';
336		$txt .=' <tr>';
337		$txt .=' 	<td colspan="2"><input id="planer" type="hidden" value="" /></td>';
338		$txt .=' </tr>';
339		$txt .=' <tr>';
340		$txt .=' 	<td colspan="2" style="text-align: center;"><input type="submit" value="Route berechnen" style="margin: 5px 0; font-size: 11px !important;" /></td>';
341		$txt .=' </tr>';
342		if ($this->getConf('showwebdefooter') == true) {
343		$txt .=' <tr>';
344		$txt .=' 	<td colspan="2" style="font-size: 11px;">Der WEB.DE <a href="http://iww.web.de/de/themen/auto/routenplaner/index.wjsp">Routenplaner</a> auch auf Ihrer <a href="http://iww.web.de/de/themen/auto/routenplaner/freiesrouting.wjsp">Homepage</a></td>';
345		$txt .=' </tr>';
346		}
347		$txt .='	</table>';
348		$txt .='  </td>';
349		$txt .='</tr>';
350		$txt .='</table>';
351		$txt .='</form>';
352        return $txt;
353} // Function
354
355} // CLASS
356
357