]> git.mxchange.org Git - friendica-addons.git/blob - curweather/curweather.php
added more weather data, change curtemp to curweather
[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     $curweather = '<div id="curweather-network" class="widget">
44                 <div class="title tool">
45                 <h4>'.t("Current Weather").'</h4></div>';
46
47     $curweather .= "Weather: $weather<br />
48                  Temperature: $temp<br />
49                  Relative Humidity: $rhumid<br />
50                  Pressure: $pressure";
51
52     $curweather .= '</div><div class="clear"></div>';
53
54     $fk_app->page['aside'] = $curweather.$fk_app->page['aside'];
55
56 }
57
58
59 function curweather_plugin_settings_post($a,$post) {
60         if(! local_user() || (! x($_POST,'curweather-settings-submit')))
61                 return;
62         set_pconfig(local_user(),'curweather','curweather_loc',trim($_POST['curweather_loc']));
63         set_pconfig(local_user(),'curweather','curweather_enable',intval($_POST['curweather_enable']));
64
65         info( t('Current Weather settings updated.') . EOL);
66 }
67
68
69 function curweather_plugin_settings(&$a,&$s) {
70
71         if(! local_user())
72                 return;
73
74         /* Add our stylesheet to the curweather so we can make our settings look nice */
75
76         $a->page['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . $a->get_baseurl() . '/addon/curweather/curweather.css' . '" media="all" />' . "\r\n";
77
78         /* Get the current state of our config variable */
79
80         $curweather_loc = get_pconfig(local_user(), 'curweather', 'curweather_loc');
81         $enable = intval(get_pconfig(local_user(),'curweather','curweather_enable'));
82         $enable_checked = (($enable) ? ' checked="checked" ' : '');
83         
84         
85         /* Add some HTML to the existing form */
86
87         $s .= '<div class="settings-block">';
88         $s .= '<h3>' . t('Current Weather Settings') . '</h3>';
89         $s .= '<div id="curweather-settings-wrapper">';
90         $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>';
91         $s .= '<label id="curweather-location-label" for="curweather_loc">' . t('Weather Location: ') . '</label>';
92         $s .= '<input id="curweather-location" type="text" name="curweather_loc" value="' . $curweather_loc . '"/>';
93         $s .= '<div class="clear"></div>';
94         $s .= '<label id="curweather-enable-label" for="curweather_enable">' . t('Enable Current Weather') . '</label>';
95         $s .= '<input id="curweather-enable" type="checkbox" name="curweather_enable" value="1" ' . $enable_checked . '/>';
96         $s .= '<div class="clear"></div>';
97
98         $s .= '</div>';
99
100         /* provide a submit button */
101
102         $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="curweather-settings-submit" class="settings-submit" value="' . t('Submit') . '" /></div></div>';
103
104 }
105
106