3 * Name: Current Weather
4 * Description: Shows current weather conditions for user's location on their network page.<br />Find the location code for the station or airport nearest you <a href="http://en.wikipedia.org/wiki/International_Air_Transport_Association_airport_code" target="_blank">here</a>.
6 * Author: Tony Baldwin <http://friendica.tonybaldwin.info/u/t0ny>
7 * Author: Fabio Comuni <http://kirkgroup.com/u/fabrixxm>
10 require_once('addon/curweather/getweather.php');
12 function curweather_install() {
13 register_hook('network_mod_init', 'addon/curweather/curweather.php', 'curweather_network_mod_init');
14 register_hook('plugin_settings', 'addon/curweather/curweather.php', 'curweather_plugin_settings');
15 register_hook('plugin_settings_post', 'addon/curweather/curweather.php', 'curweather_plugin_settings_post');
19 function curweather_uninstall() {
20 unregister_hook('network_mod_init', 'addon/curweather/curweather.php', 'curweather_network_mod_init');
21 unregister_hook('plugin_settings', 'addon/curweather/curweather.php', 'curweather_plugin_settings');
22 unregister_hook('plugin_settings_post', 'addon/curweather/curweather.php', 'curweather_plugin_settings_post');
27 function curweather_network_mod_init(&$fk_app,&$b) {
29 if(! intval(get_pconfig(local_user(),'curweather','curweather_enable')))
32 $fk_app->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $fk_app->get_baseurl() . '/addon/curweather/curweather.css' . '" media="all" />' . "\r\n";
34 // the getweather file does all the work here
35 // the $rpt value is needed for location
36 // which getweather uses to fetch the weather data for weather and temp
37 $rpt = get_pconfig(local_user(), 'curweather', 'curweather_loc');
38 $wxdata = GetWeather::get($rpt);
39 $temp = $wxdata['TEMPERATURE_STRING'];
40 $weather = $wxdata['WEATHER'];
41 $rhumid = $wxdata['RELATIVE_HUMIDITY'];
42 $pressure = $wxdata['PRESSURE_STRING'];
43 $wind = $wxdata['WIND_STRING'];
44 $curweather = '<div id="curweather-network" class="widget">
45 <div class="title tool">
46 <h4>'.t("Current Weather").'</h4></div>';
48 $curweather .= "Weather: $weather<br />
49 Temperature: $temp<br />
50 Relative Humidity: $rhumid<br />
51 Pressure: $pressure<br />
54 $curweather .= '</div><div class="clear"></div>';
56 $fk_app->page['aside'] = $curweather.$fk_app->page['aside'];
61 function curweather_plugin_settings_post($a,$post) {
62 if(! local_user() || (! x($_POST,'curweather-settings-submit')))
64 set_pconfig(local_user(),'curweather','curweather_loc',trim($_POST['curweather_loc']));
65 set_pconfig(local_user(),'curweather','curweather_enable',intval($_POST['curweather_enable']));
67 info( t('Current Weather settings updated.') . EOL);
71 function curweather_plugin_settings(&$a,&$s) {
76 /* Add our stylesheet to the curweather so we can make our settings look nice */
78 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/curweather/curweather.css' . '" media="all" />' . "\r\n";
80 /* Get the current state of our config variable */
82 $curweather_loc = get_pconfig(local_user(), 'curweather', 'curweather_loc');
83 $enable = intval(get_pconfig(local_user(),'curweather','curweather_enable'));
84 $enable_checked = (($enable) ? ' checked="checked" ' : '');
87 /* Add some HTML to the existing form */
89 $s .= '<div class="settings-block">';
90 $s .= '<h3>' . t('Current Weather Settings') . '</h3>';
91 $s .= '<div id="curweather-settings-wrapper">';
92 $s .= '<p>Find the location code for the airport/weather station nearest you <a href="http://en.wikipedia.org/wiki/International_Air_Transport_Association_airport_code" target="_blank">here</a>.</p>';
93 $s .= '<label id="curweather-location-label" for="curweather_loc">' . t('Weather Location: ') . '</label>';
94 $s .= '<input id="curweather-location" type="text" name="curweather_loc" value="' . $curweather_loc . '"/>';
95 $s .= '<div class="clear"></div>';
96 $s .= '<label id="curweather-enable-label" for="curweather_enable">' . t('Enable Current Weather') . '</label>';
97 $s .= '<input id="curweather-enable" type="checkbox" name="curweather_enable" value="1" ' . $enable_checked . '/>';
98 $s .= '<div class="clear"></div>';
102 /* provide a submit button */
104 $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="curweather-settings-submit" class="settings-submit" value="' . t('Save Settings') . '" /></div></div>';