2 rcs_id('$Id PhpWeather.php 2002-08-26 15:30:13 rurban$');
4 * This plugin requires a separate program called PHPWeather.
5 * For more information and to download PHPWeather,
6 * See: http://sourceforge.net/projects/phpweather/
8 * There are still some problems with this plugin.
10 * Make sure you download the latest CVS version of PHPWeather from
11 * http://phpweather.sourceforge.net/downloads/
13 * Coming soon: When no ICAO code is provided, a popup of cities will be presented.
16 * <?plugin PhpWeather?>
17 * <?plugin PhpWeather icao=KJFK ?>
18 * <?plugin PhpWeather icao=LOWG lang=en version=1.61 location=Graz-Thalerhof-Flughafen ?>
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');
38 class WikiPlugin_PhpWeather
42 return _("PhpWeather");
44 function getDescription () {
45 return _("The PhpWeather plugin provides weather reports from the Internet.");
47 function getDefaultArguments() {
49 return array('icao' => 'KJFK',
50 'language' => $LANG == 'C' ? 'en' : $LANG,
51 'version' => PHPWEATHER_VERSION,
52 'location' => '', // needed for version < 1.9
56 function run($dbi, $argstr, $request) {
57 extract($this->getArgs($argstr, $request));
58 $html = HTML::form(array('action' => $request->getURLtoSelf(),
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');
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'
88 if (!$icao) $icao = $request->getArg('icao');
90 if ($version > 1.7) { // The newer version as class
92 if (!in_array($language,explode(',','en,da,de,hu,no'))) $language = 'en';
93 $w->set_language($language);
94 $m = $w->print_pretty();
96 $metar = get_metar($icao);
97 $data = process_metar($metar);
98 // catch output into buffer and return it as string
100 pretty_print_metar($metar, $location);
101 $m = ob_get_contents();
104 $html->pushContent(new RawXml($m));
106 $popups = $popups || !$icao;
108 // display the popups: cc and stations
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"));
118 $options->pushContent(HTML::option(array('value' => $cc),
119 ($country ? $country : $cc) . "\n"));
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'),
126 if ($selected_cc or $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"));
137 $options->pushContent(HTML::option(array('value' => $icao),
138 ($name ? $name : $icao) . "\n"));
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'),
145 $html->pushContent(HTML::input(array('type' => "submit")));
147 // trigger_error("required argument 'icao' missing");
157 // c-hanging-comment-ender-p: nil
158 // indent-tabs-mode: nil