]> git.mxchange.org Git - friendica-addons.git/blob - curweather/curweather.php
bd0d6c7507dcdedc33e1b352d69ed9943acb1ca1
[friendica-addons.git] / curweather / curweather.php
1         <?php
2 /**
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>.
5  * Version: 1.0
6  * Author: Tony Baldwin <http://friendica.tonybaldwin.info/u/t0ny>
7  * Author: Fabio Comuni <http://kirkgroup.com/u/fabrixxm>
8  *
9  */
10 require_once('addon/curweather/getweather.php');
11
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');
16
17 }
18
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');
23
24 }
25
26
27 function curweather_network_mod_init(&$fk_app,&$b) {
28
29     if(! intval(get_pconfig(local_user(),'curweather','curweather_enable')))
30         return;
31
32     $fk_app->page['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . $fk_app->get_baseurl() . '/addon/curweather/curweather.css' . '" media="all" />' . "\r\n";
33
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>';
47
48     $curweather .= "Weather: $weather<br />
49                  Temperature: $temp<br />
50                  Relative Humidity: $rhumid<br />
51                  Pressure: $pressure<br />
52                  Wind: $wind";
53
54     $curweather .= '</div><div class="clear"></div>';
55
56     $fk_app->page['aside'] = $curweather.$fk_app->page['aside'];
57
58 }
59
60
61 function curweather_plugin_settings_post($a,$post) {
62         if(! local_user() || (! x($_POST,'curweather-settings-submit')))
63                 return;
64         set_pconfig(local_user(),'curweather','curweather_loc',trim($_POST['curweather_loc']));
65         set_pconfig(local_user(),'curweather','curweather_enable',intval($_POST['curweather_enable']));
66
67         info( t('Current Weather settings updated.') . EOL);
68 }
69
70
71 function curweather_plugin_settings(&$a,&$s) {
72
73         if(! local_user())
74                 return;
75
76         /* Add our stylesheet to the curweather so we can make our settings look nice */
77
78         $a->page['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . $a->get_baseurl() . '/addon/curweather/curweather.css' . '" media="all" />' . "\r\n";
79
80         /* Get the current state of our config variable */
81
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" ' : '');
85         
86         
87         /* Add some HTML to the existing form */
88
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>';
99
100         $s .= '</div>';
101
102         /* provide a submit button */
103
104         $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="curweather-settings-submit" class="settings-submit" value="' . t('Save Settings') . '" /></div></div>';
105
106 }
107
108