]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/PhpWeather.php
LANG still broken, working on better locale handling.
[SourceForge/phpwiki.git] / lib / plugin / PhpWeather.php
1 <?php // -*-php-*-
2 rcs_id('$Id PhpWeather.php 2002-08-26 15:30:13 rurban$');
3 /**
4  * This plugin requires a separate program called PHPWeather.
5  * For more information and to download PHPWeather,
6  * See: http://sourceforge.net/projects/phpweather/
7  *
8  * There are still some problems with this plugin.
9  *
10  * Make sure you download the latest CVS version of PHPWeather from
11  * http://phpweather.sourceforge.net/downloads/
12  *
13  * Coming soon: When no ICAO code is provided, a popup of cities will be presented.
14  *
15  * Usage:
16  * <?plugin PhpWeather?>
17  * <?plugin PhpWeather icao=KJFK ?>
18  * <?plugin PhpWeather icao=LOWG lang=en version=1.61 location=Graz-Thalerhof-Flughafen ?>
19  */
20
21 // Name the PHPWeather folder 'phpweather' and put it anywhere inside
22 // phpwiki, such as the plugin folder
23 if (!defined('PHPWEATHER_FOLDER')) {
24     if (ereg('/sourcefourge\.net/', SERVER_NAME)) {
25         define('PHPWEATHER_FOLDER', '/home/groups/p/ph/phpwiki/htdocs/demo/lib/plugin/phpweather');
26         define('PHPWEATHER_VERSION', 1.92);
27     } elseif (isWindows()) {
28         //define('PHPWEATHER_FOLDER', 'V:/home/rurban/phpweather-1.61');
29         //define('PHPWEATHER_VERSION', 1.61);
30         define('PHPWEATHER_FOLDER', 'V:/home/rurban/phpweather');
31         define('PHPWEATHER_VERSION', 1.92);
32     } else { // defaults to a parallel dir to phpwiki
33         define('PHPWEATHER_VERSION', 1.92);
34         define('PHPWEATHER_FOLDER', PHPWIKI_DIR . '../phpweather');
35     }
36 }
37
38 class WikiPlugin_PhpWeather
39 extends WikiPlugin
40 {
41     function getName () {
42         return _("PhpWeather");
43     }
44     function getDescription () {
45         return _("The PhpWeather plugin provides weather reports from the Internet.");
46     }
47     function getDefaultArguments() {
48         global $LANG;
49         return array('icao' => 'KJFK',
50                      'language' => $LANG == 'C' ? 'en' : $LANG,
51                      'version'  => PHPWEATHER_VERSION,
52                      'location' => '', // needed for version < 1.9
53                      'popups' => 0
54                      );
55     }
56     function run($dbi, $argstr, $request) {
57         extract($this->getArgs($argstr, $request));
58         $html = HTML::form(array('action' => $request->getURLtoSelf(),
59                                  'method' => "POST"));
60         if ($version > 1.7) { // The newer version as class
61             require_once(PHPWEATHER_FOLDER . '/phpweather.php');
62             $w = new phpweather(array() /*$properties*/);
63         } else { // The old and latest stable release (currently 1.61)
64             @include(PHPWEATHER_FOLDER . "/locale_$language.inc");
65             @include(PHPWEATHER_FOLDER . '/config-dist.inc');
66             @include(PHPWEATHER_FOLDER . '/config.inc');
67             include(PHPWEATHER_FOLDER . '/phpweather.inc');
68             $cities = array(
69                             'BGTL' => 'Thule A. B., Greenland',
70                             'EGKK' => 'London / Gatwick Airport, United Kingdom',
71                             'EKCH' => 'Copenhagen / Kastrup, Denmark',
72                             'ENGM' => 'Oslo / Gardermoen, Norway',
73                             'ESSA' => 'Stockholm / Arlanda, Sweden',
74                             'FCBB' => 'Brazzaville / Maya-Maya, Congo',
75                             'LEMD' => 'Madrid / Barajas, Spain',
76                             'LFPB' => 'Paris / Le Bourget, France',
77                             'LHBP' => 'Budapest / Ferihegy, Hungary',
78                             'LIRA' => 'Roma / Ciampino, Italy',
79                             'LMML' => 'Luqa International Airport, Malta',
80                             'KNYC' => 'New York City, Central Park, NY, United States',
81                             'NZCM' => 'Williams Field, Antarctic',
82                             'UUEE' => 'Moscow / Sheremet\'Ye , Russian Federation',
83                             'RKSS' => 'Seoul / Kimp\'O International Airport, Korea',
84                             'YSSY' => 'Sydney Airport, Australia',
85                             'ZBAA' => 'Beijing, China'
86                             );
87         }
88         if (!$icao) $icao = $request->getArg('icao');
89         if ($icao) {
90             if ($version > 1.7) { // The newer version as class
91                 $w->set_icao($icao);
92                 if (!in_array($language,explode(',','en,da,de,hu,no'))) $language = 'en';
93                 $w->set_language($language);
94                 $m = $w->print_pretty();
95             } else {
96                 $metar = get_metar($icao);
97                 $data = process_metar($metar);
98                 // catch output into buffer and return it as string
99                 ob_start();
100                 pretty_print_metar($metar, $location);
101                 $m = ob_get_contents();
102                 ob_end_clean();
103             }
104             $html->pushContent(new RawXml($m));
105         }
106         $popups = $popups || !$icao;
107         if ($popups) {
108             // display the popups: cc and stations
109             $options = HTML();
110             if ($version > 1.7) {
111                 $countries = $GLOBALS['obj']->db->get_countries();
112                 $selected_cc = $request->getArg('cc');
113                 while (list($cc, $country) = each($countries)) {
114                     if ($cc == $selected_cc) {
115                         $options->pushContent(HTML::option(array('value' => $cc, 'selected' => 'selected'), 
116                                                            ($country ? $country : $cc) . "\n"));
117                     } else {
118                         $options->pushContent(HTML::option(array('value' => $cc),
119                                                            ($country ? $country : $cc) . "\n"));
120                     }
121                 }
122                 if ($selected_cc) $html->pushContent(HTML::input(array('type' => "hidden", 'name' => "old_cc", 'value' => $selected_cc))); 
123                 $html->pushContent(HTML::select(array('name' => "cc", 'id' => 'cc'),
124                                                 $options));
125             }
126             if ($selected_cc or $version < 1.7) {
127                 $options = HTML();
128                 $country = '';
129                 if ($version > 1.7)
130                     $cities = $GLOBALS['obj']->db->get_icaos($selected_cc, $country); 
131                 $selected_icao = $request->getArg('icao');
132                 while (list($icao, $name) = each($cities)) { 
133                     if ($icao == $selected_icao) {
134                         $options->pushContent(HTML::option(array('value' => $icao, 'selected' => 'selected'), 
135                                                            ($name ? $name : $icao) . "\n"));
136                     } else {
137                         $options->pushContent(HTML::option(array('value' => $icao), 
138                                                            ($name ? $name : $icao) . "\n"));
139                     }
140                 }
141                 if ($selected_icao) $html->pushContent(HTML::input(array('type' => "hidden",'name' => "old_icao",'value' => $selected_icao))); 
142                 $html->pushContent(HTML::select(array('name' => "icao", 'id' => 'icao'),
143                                                 $options));
144             }
145             $html->pushContent(HTML::input(array('type' => "submit")));
146         }
147         // trigger_error("required argument 'icao' missing");
148         return $html;
149     }
150 }
151
152 // For emacs users
153 // Local Variables:
154 // mode: php
155 // tab-width: 8
156 // c-basic-offset: 4
157 // c-hanging-comment-ender-p: nil
158 // indent-tabs-mode: nil
159 // End:
160 ?>