PluginProbe
wp-forecast / 9.3
wp-forecast v9.3
10.0 trunk 1.4 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3..5 3..8 3.0 3.1 3.2 3.3 3.4 3.6 All 86 releases
wp-forecast / wpf-setup.php

wpf-setup.php in wp-forecast 9.3, at wpf-setup.php

252 lines 8.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * This file is part of the wp-forecast plugin for WordPress.
4 *
5 * Copyright 2006-2023 Hans Matzen (email : webmaster at tuxlog dot de)
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 * @package wp-forecast
22 */
23
24 /**
25 * Setting up the default options in table wp-options during
26 * plugin activation from the plugins page.
27 */
28 function wp_forecast_activate() {
29 // add number of widgets, default: 1.
30 $count = get_option( 'wp-forecast-count' );
31
32 // migrating from accuweather to OpenMeteo.
33 if ( $count > 0 ) {
34 for ( $i = 0;$i < $count;$i++ ) {
35 $wpfcid = get_widget_id( $i );
36
37 // get all widget options.
38 $av = get_wpf_opts( $wpfcid );
39
40 if ( isset( $av['service'] ) && 'accu' == $av['service'] ) {
41 $weather = get_option( 'wp-forecast-cache' . $wpfcid );
42 $expire = get_option( 'wp-forecast-expire' . $wpfcid );
43
44 if ( $av['loclatitude'] > 0 && $av['loclongitude'] > 0 ) { // we have got coords and can switch to openmeteo.
45 $av['service'] = 'openmeteo';
46 $av['location'] = $av['locname'];
47 } else { // we do not have coords.
48 $av['service'] = '';
49 }
50 wpf_update_option( 'wp-forecast-opts' . $wpfcid, $av );
51 }
52
53 // delete cache.
54 wpf_update_option( 'wp-forecast-cache' . $wpfcid, '' );
55 wpf_update_option( 'wp-forecast-expire' . $wpfcid, '0' );
56 }
57 }
58
59 if ( '' == $count ) {
60 $count = '1';
61 wpf_add_option( 'wp-forecast-count', $count );
62 };
63
64 // add timeout for weather connections, default: 30.
65 $timeout = get_option( 'wp-forecast-timeout' );
66
67 if ( '' == $timeout ) {
68 $timeout = '10';
69 wpf_add_option( 'wp-forecast-timeout', $timeout );
70 };
71
72 // add switch to control option deletion during plugin deactivation.
73 $delopt = get_option( 'wp-forecast-delopt' );
74
75 if ( '' == $delopt ) {
76 $delopt = '0';
77 wpf_add_option( 'wp-forecast-delopt', $delopt );
78 };
79
80 // add preselected transport method for wp-forecast.
81 $pre_trans = get_option( 'wp-forecast-pre-transport' );
82
83 if ( '' == $pre_trans ) {
84 $pre_trans = 'default';
85 wpf_add_option( 'wp-forecast-pre-transport', $pre_trans );
86 };
87
88 // add transport to use by WordPress only for wp-forecast.
89 $wp_trans = get_option( 'wp-forecast-wp-transport' );
90
91 if ( '' == $wp_trans ) {
92 $wp_trans = 'default';
93 wpf_add_option( 'wp-forecast-wp-transport', $wp_trans );
94 };
95
96 // add ipstack apikey to use by WordPress only for wp-forecast.
97 $wp_ipstack = get_option( 'wp-forecast-ipstackapikey' );
98
99 if ( '' == $wp_ipstack ) {
100 wpf_add_option( 'wp-forecast-ipstackapikey', $wp_ipstack );
101 };
102
103 for ( $i = 0;$i < $count;$i++ ) {
104 $wpfcid = get_widget_id( $i );
105
106 // get all widget options.
107 $av = get_wpf_opts( $wpfcid );
108 $weather = get_option( 'wp-forecast-cache' . $wpfcid );
109 $expire = get_option( 'wp-forecast-expire' . $wpfcid );
110
111 // if the options dont exists, add the defaults.
112 if ( empty( $av['service'] ) || '' == $av['service'] ) {
113 $av = array();
114
115 $av['service'] = 'openmeteo'; // specify the weatherservice to use.
116 $av['apikey1'] = ''; // Partner ID or API Code for openweathermap.
117 $av['location'] = 'Frankfurt am Main'; // location code.
118 $av['loclatitude'] = '50.11552'; // coord of location.
119 $av['loclongitude'] = '8.68417'; // coord of location.
120 $av['locname'] = 'Frankfurt am Main'; // user defined location name.
121 $av['refresh'] = '1800'; // the intervall the local weather data is renewed.
122 $av['metric'] = '1'; // 1 if you want to use metric scheme, else 0.
123 $av['wpf_language'] = 'en_US'; // language code for this widget.
124 $av['daytime'] = '000000000'; // Switches for Daytime forecast.
125 $av['nighttime'] = '000000000'; // Switches for Nighttime forecast.
126 $av['currtime'] = '1'; // 1 if you want to use current time, else 0.
127 $av['timeoffset'] = '0'; // offset to correct wrong weather time e.g. half-timezones.
128 $av['title'] = __( 'The Weather', 'wp-forecast' ); // the widget title.
129 // Displayconfigurationmatrix.
130 // CC FC Day FC Night.
131 // Icon 0 10 14.
132 // Datum 18 - -.
133 // Zeit 1 - -.
134 // Shorttext 2 11 15.
135 // Temperatur 3 12 16.
136 // gef. Temp 4 - -.
137 // Luftdruck 5 - -.
138 // Luftfeuchte 6 - -.
139 // Wind 7 13 17.
140 // Windboen 22 23 24.
141 // Sonnenaufgang 8 - -.
142 // Sonnenuntergang 9 - -.
143 // Copyright 21 - -.
144 // provider link 25 - -.
145 // open in new window 26 - -.
146 // uvindex 27 28 29.
147 // precipitation 30 31 32.
148 //
149 $av['dispconfig'] = str_repeat( '1', 32 );
150 $av['windunit'] = 'ms'; // Choose between ms, kmh, mph or kts.
151 $av['pdforecast'] = '0'; // pulldown forecast 0=No, 1=Yes.
152 $av['pdfirstday'] = '0'; // day to start pulldown with.
153 $av['windicon'] = '0'; // show windicon 0=No 1=Yes.
154 $av['csssprites'] = '0'; // use csssprites to display icons 0=No 1=Yes.
155
156 $av['ouv_apikey'] = ''; // APIkey to access openuv.io data.
157 $av['ouv_uv'] = '0'; // show uv index from openuv.
158 $av['ouv_uvmax'] = '0'; // show max uv index from openuv.
159 $av['ouv_ozone'] = '0'; // show ozone from openuv.
160 $av['ouv_safetime'] = '0'; // show safetimes as tooltip from openuv.
161
162 wpf_add_option( 'wp-forecast-opts' . $wpfcid, serialize( $av ) );
163 }
164
165 if ( '' == $weather ) {
166 $weather = '';
167 wpf_add_option( 'wp-forecast-cache' . $wpfcid, $weather );
168 };
169
170 if ( '' == $expire ) {
171 $expire = '0';
172 wpf_add_option( 'wp-forecast-expire' . $wpfcid, $expire );
173 };
174 } // end of for
175
176 global $blog_id;
177 if ( function_exists( 'is_multisite' ) && is_multisite() && 1 != $blog_id ) {
178 // add options for super admin on multisites.
179 $wpf_sa_defaults = get_option( 'wpf_sa_defaults' );
180 $wpf_sa_allowed = get_option( 'wpf_sa_allowed' );
181
182 $allallowed = array(
183 'ue_wp-forecast-count' => 1,
184 'ue_wp-forecast-timeout' => 1,
185 'ue_wp-forecast-pre-transport' => 1,
186 'ue_wp-forecast-delopt' => 1,
187 'ue_service' => 1,
188 'ue_apikey1' => 1,
189 'ue_location' => 1,
190 'ue_locname' => 1,
191 'ue_refresh' => 1,
192 'ue_metric' => 1,
193 'ue_currtime' => 1,
194 'ue_timeoffset' => 1,
195 'ue_windunit' => 1,
196 'ue_wpf_language' => 1,
197 'ue_pdforecast' => 1,
198 'ue_pdfirstday' => 1,
199 'ue_dispconfig' => 1,
200 'ue_forecast' => 1,
201 'ue_daytime' => 1,
202 'ue_nighttime' => 1,
203 'ue_windicon' => 1,
204 'ue_csssprites' => 1,
205 );
206
207 if ( ! $wpf_sa_defaults ) {
208 $wpf_sa_defaults = serialize( array() );
209 add_blog_option( 1, 'wpf_sa_defaults', $wpf_sa_defaults );
210 }
211
212 if ( ! $wpf_sa_allowed ) {
213 $wpf_sa_allowed = serialize( $allallowed );
214 add_blog_option( 1, 'wpf_sa_allowed', $wpf_sa_allowed );
215 }
216 }
217 }
218
219 /**
220 * Is called when plugin is deactivated and removes all.
221 * the wp-forecast options from the database.
222 *
223 * @param string $wpfcid The Widget ID.
224 */
225 function wp_forecast_deactivate( $wpfcid ) {
226 global $wpf_maxwidgets;
227
228 $delopt = get_option( 'wp-forecast-delopt' );
229
230 // only delete options when switch is set.
231 if ( 1 == $delopt ) {
232 $count = $wpf_maxwidgets; // get_option('wp-forecast-count');.
233
234 for ( $i = 0;$i < $count;$i++ ) {
235 $wpfcid = get_widget_id( $i );
236
237 delete_option( 'wp-forecast-opts' . $wpfcid );
238 delete_option( 'wp-forecast-cache' . $wpfcid );
239 delete_option( 'wp-forecast-expire' . $wpfcid );
240 }
241 delete_option( 'wp-forecast-timeout' );
242 delete_option( 'wp-forecast-count' );
243 delete_option( 'wp-forecast-delopt' );
244 delete_option( 'wp-forecast-pre-transport' );
245 delete_option( 'wp-forecast-wp-transport' );
246 // delete options for superadmin on multisites.
247 delete_option( 'wpf_sa_defaults' );
248 delete_option( 'wpf_sa_allowed' );
249 }
250 }
251
252