PluginProbe
wp-forecast / 9.6
wp-forecast v9.6
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.6, at wpf-setup.php

235 lines 8.2 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 ipstack apikey to use by WordPress only for wp-forecast.
81 $wp_ipstack = get_option( 'wp-forecast-ipstackapikey' );
82
83 if ( '' == $wp_ipstack ) {
84 wpf_add_option( 'wp-forecast-ipstackapikey', $wp_ipstack );
85 };
86
87 for ( $i = 0;$i < $count;$i++ ) {
88 $wpfcid = get_widget_id( $i );
89
90 // get all widget options.
91 $av = get_wpf_opts( $wpfcid );
92 $weather = get_option( 'wp-forecast-cache' . $wpfcid );
93 $expire = get_option( 'wp-forecast-expire' . $wpfcid );
94
95 // if the options dont exists, add the defaults.
96 if ( empty( $av['service'] ) || '' == $av['service'] ) {
97 $av = array();
98
99 $av['service'] = 'openmeteo'; // specify the weatherservice to use.
100 $av['apikey1'] = ''; // Partner ID or API Code for openweathermap.
101 $av['location'] = 'Frankfurt am Main'; // location code.
102 $av['loclatitude'] = '50.11552'; // coord of location.
103 $av['loclongitude'] = '8.68417'; // coord of location.
104 $av['locname'] = 'Frankfurt am Main'; // user defined location name.
105 $av['refresh'] = '1800'; // the intervall the local weather data is renewed.
106 $av['metric'] = '1'; // 1 if you want to use metric scheme, else 0.
107 $av['wpf_language'] = 'en_US'; // language code for this widget.
108 $av['daytime'] = '000000000'; // Switches for Daytime forecast.
109 $av['nighttime'] = '000000000'; // Switches for Nighttime forecast.
110 $av['currtime'] = '1'; // 1 if you want to use current time, else 0.
111 $av['timeoffset'] = '0'; // offset to correct wrong weather time e.g. half-timezones.
112 $av['title'] = __( 'The Weather', 'wp-forecast' ); // the widget title.
113 // Displayconfigurationmatrix.
114 // CC FC Day FC Night.
115 // Icon 0 10 14.
116 // Datum 18 - -.
117 // Zeit 1 - -.
118 // Shorttext 2 11 15.
119 // Temperatur 3 12 16.
120 // gef. Temp 4 - -.
121 // Luftdruck 5 - -.
122 // Luftfeuchte 6 - -.
123 // Wind 7 13 17.
124 // Windboen 22 23 24.
125 // Sonnenaufgang 8 - -.
126 // Sonnenuntergang 9 - -.
127 // Copyright 21 - -.
128 // provider link 25 - -.
129 // open in new window 26 - -.
130 // uvindex 27 28 29.
131 // precipitation 30 31 32.
132 //
133 $av['dispconfig'] = str_repeat( '1', 32 );
134 $av['windunit'] = 'ms'; // Choose between ms, kmh, mph or kts.
135 $av['pdforecast'] = '0'; // pulldown forecast 0=No, 1=Yes.
136 $av['pdfirstday'] = '0'; // day to start pulldown with.
137 $av['windicon'] = '0'; // show windicon 0=No 1=Yes.
138 $av['csssprites'] = '0'; // use csssprites to display icons 0=No 1=Yes.
139
140 $av['ouv_apikey'] = ''; // APIkey to access openuv.io data.
141 $av['ouv_uv'] = '0'; // show uv index from openuv.
142 $av['ouv_uvmax'] = '0'; // show max uv index from openuv.
143 $av['ouv_ozone'] = '0'; // show ozone from openuv.
144 $av['ouv_safetime'] = '0'; // show safetimes as tooltip from openuv.
145
146 wpf_add_option( 'wp-forecast-opts' . $wpfcid, serialize( $av ) );
147 }
148
149 if ( '' == $weather ) {
150 $weather = '';
151 wpf_add_option( 'wp-forecast-cache' . $wpfcid, $weather );
152 };
153
154 if ( '' == $expire ) {
155 $expire = '0';
156 wpf_add_option( 'wp-forecast-expire' . $wpfcid, $expire );
157 };
158 } // end of for
159
160 global $blog_id;
161 if ( function_exists( 'is_multisite' ) && is_multisite() && 1 != $blog_id ) {
162 // add options for super admin on multisites.
163 $wpf_sa_defaults = get_option( 'wpf_sa_defaults' );
164 $wpf_sa_allowed = get_option( 'wpf_sa_allowed' );
165
166 $allallowed = array(
167 'ue_wp-forecast-count' => 1,
168 'ue_wp-forecast-timeout' => 1,
169 'ue_wp-forecast-delopt' => 1,
170 'ue_service' => 1,
171 'ue_apikey1' => 1,
172 'ue_location' => 1,
173 'ue_locname' => 1,
174 'ue_refresh' => 1,
175 'ue_metric' => 1,
176 'ue_currtime' => 1,
177 'ue_timeoffset' => 1,
178 'ue_windunit' => 1,
179 'ue_wpf_language' => 1,
180 'ue_pdforecast' => 1,
181 'ue_pdfirstday' => 1,
182 'ue_dispconfig' => 1,
183 'ue_forecast' => 1,
184 'ue_daytime' => 1,
185 'ue_nighttime' => 1,
186 'ue_windicon' => 1,
187 'ue_csssprites' => 1,
188 );
189
190 if ( ! $wpf_sa_defaults ) {
191 $wpf_sa_defaults = serialize( array() );
192 add_blog_option( 1, 'wpf_sa_defaults', $wpf_sa_defaults );
193 }
194
195 if ( ! $wpf_sa_allowed ) {
196 $wpf_sa_allowed = serialize( $allallowed );
197 add_blog_option( 1, 'wpf_sa_allowed', $wpf_sa_allowed );
198 }
199 }
200 }
201
202 /**
203 * Is called when plugin is deactivated and removes all.
204 * the wp-forecast options from the database.
205 *
206 * @param string $wpfcid The Widget ID.
207 */
208 function wp_forecast_deactivate( $wpfcid ) {
209 global $wpf_maxwidgets;
210
211 $delopt = get_option( 'wp-forecast-delopt' );
212
213 // only delete options when switch is set.
214 if ( 1 == $delopt ) {
215 $count = $wpf_maxwidgets; // get_option('wp-forecast-count');.
216
217 for ( $i = 0;$i < $count;$i++ ) {
218 $wpfcid = get_widget_id( $i );
219
220 delete_option( 'wp-forecast-opts' . $wpfcid );
221 delete_option( 'wp-forecast-cache' . $wpfcid );
222 delete_option( 'wp-forecast-expire' . $wpfcid );
223 }
224 delete_option( 'wp-forecast-timeout' );
225 delete_option( 'wp-forecast-count' );
226 delete_option( 'wp-forecast-delopt' );
227 delete_option( 'wp-forecast-pre-transport' );
228 delete_option( 'wp-forecast-wp-transport' );
229 // delete options for superadmin on multisites.
230 delete_option( 'wpf_sa_defaults' );
231 delete_option( 'wpf_sa_allowed' );
232 }
233 }
234
235