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. Try some default directories.
47 // Better define PHPWEATHER_BASE_DIR to the directory on your server:
48 if (!defined('PHPWEATHER_BASE_DIR')) {
49 /* PhpWeather has not been loaded before. We include the base
50 * class from PhpWeather, adjust this to match the location of
51 * PhpWeather on your server: */
53 $_SERVER =& $GLOBALS['HTTP_SERVER_VARS'];
54 @include_once($_SERVER['DOCUMENT_ROOT'] . '/phpweather-2.2.1/phpweather.php');
55 if (!defined('PHPWEATHER_BASE_DIR'))
56 @include_once($_SERVER['DOCUMENT_ROOT'] . '/phpweather/phpweather.php');
59 class WikiPlugin_PhpWeather
63 return _("PhpWeather");
66 function getDescription () {
67 return _("The PhpWeather plugin provides weather reports from the Internet.");
70 function getVersion() {
71 return preg_replace("/[Revision: $]/", '',
72 "\$Revision: 1.12 $");
75 function getDefaultArguments() {
77 return array('icao' => 'EKAH',
81 'units' => 'both_metric');
84 function run($dbi, $argstr, &$request, $basepage) {
85 // When 'phpweather/phpweather.php' is not installed then
86 // PHPWEATHER_BASE_DIR will be undefined.
87 if (!defined('PHPWEATHER_BASE_DIR'))
88 return $this->error(_("You have to define PHPWEATHER_BASE_DIR before use. (config/config.ini)")); //early return
90 require_once(PHPWEATHER_BASE_DIR . '/output/pw_images.php');
91 require_once(PHPWEATHER_BASE_DIR . '/pw_utilities.php');
93 extract($this->getArgs($argstr, $request));
96 $w = new phpweather(); // Our weather object
99 /* We assign the ICAO to the weather object: */
101 if (!$w->get_country_code()) {
102 /* The country code couldn't be resolved, so we
103 * shouldn't use the ICAO: */
104 trigger_error(sprintf(_("The ICAO '%s' wasn't recognized."),
105 $icao), E_USER_NOTICE);
112 /* We check and correct the language if necessary: */
113 //if (!in_array($language, array_keys($w->get_languages('text')))) {
114 if (!in_array($language, array_keys(get_languages('text')))) {
115 trigger_error(sprintf(_("%s does not know about the language '%s', using 'en' instead."),
116 $this->getName(), $language),
121 $class = "pw_text_$language";
122 require_once(PHPWEATHER_BASE_DIR . "/output/$class.php");
125 $t->set_pref_units($units);
126 $i = new pw_images($w);
128 $i_temp = HTML::img(array('src' => $i->get_temp_image()));
129 $i_wind = HTML::img(array('src' => $i->get_winddir_image()));
130 $i_sky = HTML::img(array('src' => $i->get_sky_image()));
132 $m = $t->print_pretty();
134 $m_td = HTML::td(HTML::p(new RawXml($m)));
137 $i_tr->pushContent(HTML::td($i_temp));
138 $i_tr->pushContent(HTML::td($i_wind));
140 $i_table = HTML::table($i_tr);
141 $i_table->pushContent(HTML::tr(HTML::td(array('colspan' => '2'),
145 $tr->pushContent($m_td);
146 $tr->pushContent(HTML::td($i_table));
148 $html->pushContent(HTML::table($tr));
152 /* We make a menu if asked to, or if $icao is empty: */
153 if ($menu || empty($icao)) {
155 $form_arg = array('action' => $request->getURLtoSelf(),
158 /* The country box is always part of the menu: */
159 $p1 = HTML::p(new RawXml(get_countries_select($w, $cc)));
161 /* We want to save the language: */
162 $p1->pushContent(HTML::input(array('type' => 'hidden',
163 'name' => 'language',
164 'value' => $language)));
165 /* And also the ICAO: */
166 $p1->pushContent(HTML::input(array('type' => 'hidden',
170 $caption = (empty($cc) ? _("Submit country") : _("Change country"));
171 $p1->pushContent(HTML::input(array('type' => 'submit',
172 'value' => $caption)));
174 $html->pushContent(HTML::form($form_arg, $p1));
177 /* We have selected a country, now display a list with
178 * the available stations in that country: */
181 /* We need the country code after the form is submitted: */
182 $p2->pushContent(HTML::input(array('type' => 'hidden',
186 $p2->pushContent(new RawXml(get_stations_select($w, $cc, $icao)));
187 $p2->pushContent(new RawXml(get_languages_select($language)));
188 $p2->pushContent(HTML::input(array('type' => 'submit',
189 'value' => _("Submit location"))));
191 $html->pushContent(HTML::form($form_arg, $p2));
201 // $Log: not supported by cvs2svn $
202 // Revision 1.11 2004/05/01 15:59:29 rurban
203 // more php-4.0.6 compatibility: superglobals
205 // Revision 1.10 2004/02/17 12:11:36 rurban
206 // added missing 4th basepage arg at plugin->run() to almost all plugins. This caused no harm so far, because it was silently dropped on normal usage. However on plugin internal ->run invocations it failed. (InterWikiSearch, IncludeSiteMap, ...)
208 // Revision 1.9 2003/01/28 21:10:38 zorloc
209 // Better error messages from PhpWeather Plugin -- Martin Geisler
211 // Revision 1.8 2003/01/18 22:01:43 carstenklapp
213 // Reformatting & tabs to spaces;
214 // Added copyleft, getVersion, getDescription, rcs_id.
216 // Revision 1.7 2002/12/31 20:53:40 carstenklapp
217 // Bugfixes: Fixed menu language selection (incorrect parameters to
218 // $w->get_languages_select() & form input 'language' instead of 'lang').
225 // c-hanging-comment-ender-p: nil
226 // indent-tabs-mode: nil