2 rcs_id('$Id PhpWeather.php 2002-08-26 15:30:13 rurban$');
4 Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
6 This file is part of PhpWiki.
8 PhpWiki is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 PhpWiki is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with PhpWiki; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * This plugin requires a separate program called PhpWeather. For more
25 * information and to download PhpWeather, see:
27 * http://sourceforge.net/projects/phpweather/
31 * <?plugin PhpWeather ?>
32 * <?plugin PhpWeather menu=true ?>
33 * <?plugin PhpWeather icao=KJFK ?>
34 * <?plugin PhpWeather language=en ?>
35 * <?plugin PhpWeather units=only_metric ?>
36 * <?plugin PhpWeather icao||=CYYZ cc||=CA language||=en menu=true ?>
38 * If you want a menu, and you also want to change the default station
39 * or language, then you have to use the ||= form, or else the user
40 * wont be able to change the station or language.
42 * The units argument should be one of only_metric, only_imperial,
43 * both_metric, or both_imperial.
46 // We require the base class from PHP Weather, adjust this to match
47 // the location of PhpWeather on your server:
48 $WEATHER = $_SERVER['DOCUMENT_ROOT'] . '/phpweather/phpweather.php';
49 if(! @include_once($WEATHER)) {
50 if(!in_array($WEATHER, get_included_files()) ) {
51 $error = sprintf(_("Could not open file %s."), "'$WEATHER'") . " ";
52 $error .= sprintf(_("Make sure %s is installed and properly configured."),
54 trigger_error($error);
58 class WikiPlugin_PhpWeather
62 return _("PhpWeather");
65 function getDescription () {
66 return _("The PhpWeather plugin provides weather reports from the Internet.");
69 function getVersion() {
70 return preg_replace("/[Revision: $]/", '',
74 function getDefaultArguments() {
76 return array('icao' => 'EKAH',
80 'units' => 'both_metric');
83 function run($dbi, $argstr, $request) {
84 // When 'phpweather/phpweather.php' is not installed then
85 // PHPWEATHER_BASE_DIR will be undefined
86 if (!defined('PHPWEATHER_BASE_DIR'))
87 return fmt("Plugin %s failed.", $this->getName()); //early return
89 require_once(PHPWEATHER_BASE_DIR . '/output/pw_images.php');
90 require_once(PHPWEATHER_BASE_DIR . '/pw_utilities.php');
92 extract($this->getArgs($argstr, $request));
95 $w = new phpweather(); // Our weather object
98 /* We assign the ICAO to the weather object: */
100 if (!$w->get_country_code()) {
101 /* The country code couldn't be resolved, so we
102 * shouldn't use the ICAO: */
103 trigger_error(sprintf(_("The ICAO '%s' wasn't recognized."),
104 $icao), E_USER_NOTICE);
111 /* We check and correct the language if necessary: */
112 //if (!in_array($language, array_keys($w->get_languages('text')))) {
113 if (!in_array($language, array_keys(get_languages('text')))) {
114 trigger_error(sprintf(_("%s does not know about the language '%s', using 'en' instead."),
115 $this->getName(), $language),
120 $class = "pw_text_$language";
121 require_once(PHPWEATHER_BASE_DIR . "/output/$class.php");
124 $t->set_pref_units($units);
125 $i = new pw_images($w);
127 $i_temp = HTML::img(array('src' => $i->get_temp_image()));
128 $i_wind = HTML::img(array('src' => $i->get_winddir_image()));
129 $i_sky = HTML::img(array('src' => $i->get_sky_image()));
131 $m = $t->print_pretty();
133 $m_td = HTML::td(HTML::p(new RawXml($m)));
136 $i_tr->pushContent(HTML::td($i_temp));
137 $i_tr->pushContent(HTML::td($i_wind));
139 $i_table = HTML::table($i_tr);
140 $i_table->pushContent(HTML::tr(HTML::td(array('colspan' => '2'),
144 $tr->pushContent($m_td);
145 $tr->pushContent(HTML::td($i_table));
147 $html->pushContent(HTML::table($tr));
151 /* We make a menu if asked to, or if $icao is empty: */
152 if ($menu || empty($icao)) {
154 $form_arg = array('action' => $request->getURLtoSelf(),
157 /* The country box is always part of the menu: */
158 $p1 = HTML::p(new RawXml(get_countries_select($w, $cc)));
160 /* We want to save the language: */
161 $p1->pushContent(HTML::input(array('type' => 'hidden',
162 'name' => 'language',
163 'value' => $language)));
164 /* And also the ICAO: */
165 $p1->pushContent(HTML::input(array('type' => 'hidden',
169 $caption = (empty($cc) ? _("Submit country") : _("Change country"));
170 $p1->pushContent(HTML::input(array('type' => 'submit',
171 'value' => $caption)));
173 $html->pushContent(HTML::form($form_arg, $p1));
176 /* We have selected a country, now display a list with
177 * the available stations in that country: */
180 /* We need the country code after the form is submitted: */
181 $p2->pushContent(HTML::input(array('type' => 'hidden',
185 $p2->pushContent(new RawXml(get_stations_select($w, $cc, $icao)));
186 $p2->pushContent(new RawXml(get_languages_select($language)));
187 $p2->pushContent(HTML::input(array('type' => 'submit',
188 'value' => _("Submit location"))));
190 $html->pushContent(HTML::form($form_arg, $p2));
200 // $Log: not supported by cvs2svn $
201 // Revision 1.7 2002/12/31 20:53:40 carstenklapp
202 // Bugfixes: Fixed menu language selection (incorrect parameters to
203 // $w->get_languages_select() & form input 'language' instead of 'lang').
210 // c-hanging-comment-ender-p: nil
211 // indent-tabs-mode: nil