| 1 |
<?php |
| 2 |
/* This file is part of the wp-forecast plugin for wordpress */ |
| 3 |
|
| 4 |
/* Copyright 2006,2007,2008 Hans Matzen (email : webmaster at tuxlog.de) |
| 5 |
|
| 6 |
This program is free software; you can redistribute it and/or modify |
| 7 |
it under the terms of the GNU General Public License as published by |
| 8 |
the Free Software Foundation; either version 2 of the License, or |
| 9 |
(at your option) any later version. |
| 10 |
|
| 11 |
This program is distributed in the hope that it will be useful, |
| 12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
GNU General Public License for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU General Public License |
| 17 |
along with this program; if not, write to the Free Software |
| 18 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 |
*/ |
| 20 |
|
| 21 |
// |
| 22 |
// setting up the default options in table wp-options during |
| 23 |
// plugin activation from the plugins page |
| 24 |
// |
| 25 |
function wp_forecast_activate() |
| 26 |
{ |
| 27 |
global $wpf_debug; |
| 28 |
|
| 29 |
if ($wpf_debug > 0) |
| 30 |
pdebug("Start of wp_forecast_activate ()"); |
| 31 |
|
| 32 |
// add number of widgets, default: 1 |
| 33 |
$count=get_option("wp-forecast-count"); |
| 34 |
|
| 35 |
if ($count == "") { |
| 36 |
$count="1"; |
| 37 |
add_option("wp-forecast-count",$count, |
| 38 |
"Contains the number of wp-widgets","yes"); |
| 39 |
}; |
| 40 |
|
| 41 |
// add timeout for accuweather connections, default: 30 |
| 42 |
$timeout=get_option("wp-forecast-timeout"); |
| 43 |
|
| 44 |
if ($timeout == "") { |
| 45 |
$timeout="30"; |
| 46 |
add_option("wp-forecast-timeout",$timeout, |
| 47 |
"Timeout in seconds for accuweather connections","yes"); |
| 48 |
}; |
| 49 |
|
| 50 |
// add switch to control option deletion during plugin deactivation |
| 51 |
$delopt=get_option("wp-forecast-delopt"); |
| 52 |
|
| 53 |
if ($delopt == "") { |
| 54 |
$delopt="0"; |
| 55 |
add_option("wp-forecast-delopt",$delopt, |
| 56 |
"Switch to control option deletion","yes"); |
| 57 |
}; |
| 58 |
|
| 59 |
for ($i=0;$i<$count;$i++) { |
| 60 |
$wpfcid = get_widget_id( $i ); |
| 61 |
|
| 62 |
// get options just in case |
| 63 |
$location=get_option("wp-forecast-location".$wpfcid); |
| 64 |
$locname=get_option("wp-forecast-locname".$wpfcid); |
| 65 |
$refresh=get_option("wp-forecast-refresh".$wpfcid); |
| 66 |
$metric=get_option("wp-forecast-metric".$wpfcid); |
| 67 |
$wpf_language=get_option("wp-forecast-language".$wpfcid); |
| 68 |
$daytime=get_option("wp-forecast-daytime".$wpfcid); |
| 69 |
$nighttime=get_option("wp-forecast-nighttime".$wpfcid); |
| 70 |
$dispconfig=get_option("wp-forecast-dispconfig".$wpfcid); |
| 71 |
$windunit = get_option("wp-forecast-windunit".$wpfcid); |
| 72 |
$weather = get_option("wp-forecast-cache".$wpfcid); |
| 73 |
$expire = get_option("wp-forecast-expire".$wpfcid); |
| 74 |
$currtime = get_option("wp-forecast-currtime".$wpfcid); |
| 75 |
$title = get_option("wp-forecast-title".$wpfcid); |
| 76 |
|
| 77 |
// if the options dont exists, add the defaults |
| 78 |
if ($location == "") { |
| 79 |
$location="EUR|DE|GM007|FRANKFURT AM MAIN"; |
| 80 |
add_option("wp-forecast-location".$wpfcid,$location, |
| 81 |
"Contains the location code from accuweather","yes"); |
| 82 |
}; |
| 83 |
|
| 84 |
if ($locname == "") { |
| 85 |
$locname="Frankfurt am Main"; |
| 86 |
add_option("wp-forecast-location".$wpfcid,$locname, |
| 87 |
"Contains the location name to show","yes"); |
| 88 |
}; |
| 89 |
|
| 90 |
if ($refresh == "") { |
| 91 |
$refresh="600"; |
| 92 |
add_option("wp-forecast-refresh".$wpfcid,$refresh, |
| 93 |
"Contains the intervall the local weather data is renewed", |
| 94 |
"yes"); |
| 95 |
}; |
| 96 |
|
| 97 |
if ($metric == "") { |
| 98 |
$metric="1"; |
| 99 |
add_option("wp-forecast-metric".$wpfcid,$metric, |
| 100 |
"1 if you want to use metric scheme, else 0","yes"); |
| 101 |
}; |
| 102 |
|
| 103 |
if ($wpf_language == "") { |
| 104 |
$wpf_language="en_US"; |
| 105 |
add_option("wp-forecast-language".$wpfcid,$wpf_language, |
| 106 |
"The lanugage code","yes"); |
| 107 |
}; |
| 108 |
|
| 109 |
|
| 110 |
if ($weather == "") { |
| 111 |
$weather=""; |
| 112 |
add_option("wp-forecast-cache".$wpfcid,$weather, |
| 113 |
"The weather cache","yes"); |
| 114 |
}; |
| 115 |
|
| 116 |
if ($expire == "") { |
| 117 |
$expire="0"; |
| 118 |
add_option("wp-forecast-expire".$wpfcid,$expire, |
| 119 |
"when weather cache expires","yes"); |
| 120 |
}; |
| 121 |
if ($daytime == "") { |
| 122 |
$daytime="000000000"; |
| 123 |
add_option("wp-forecast-daytime".$wpfcid,$daytime, |
| 124 |
"Switches for Daytime forecast","yes"); |
| 125 |
}; |
| 126 |
|
| 127 |
if ($nighttime == "") { |
| 128 |
$nighttime="000000000"; |
| 129 |
add_option("wp-forecast-nighttime".$wpfcid,$nighttime, |
| 130 |
"Switches for Nighttime forecast","yes"); |
| 131 |
}; |
| 132 |
|
| 133 |
if ($currtime == "") { |
| 134 |
$currtime="1"; |
| 135 |
add_option("wp-forecast-currtime".$wpfcid,$currtime, |
| 136 |
"1 if you want to use current time, else 0","yes"); |
| 137 |
}; |
| 138 |
|
| 139 |
if ($title == "") { |
| 140 |
$title=__("The Weather","wp-forecast_".$wpf_language); |
| 141 |
add_option("wp-forecast-title".$wpfcid,$title, |
| 142 |
"Contains the widget title","yes"); |
| 143 |
}; |
| 144 |
|
| 145 |
// Displayconfigurationmatrix |
| 146 |
// CC FC Day FC Night |
| 147 |
// Icon 0 10 14 |
| 148 |
// Datum 18 - - |
| 149 |
// Zeit 1 - - |
| 150 |
// Shorttext 2 11 15 |
| 151 |
// Temperatur 3 12 16 |
| 152 |
// gef. Temp 4 - - |
| 153 |
// Luftdruck 5 - - |
| 154 |
// Luftfeuchte 6 - - |
| 155 |
// Wind 7 13 17 |
| 156 |
// Windboen 22 23 24 |
| 157 |
// Sonnenaufgang 8 - - |
| 158 |
// Sonnenuntergang 9 - - |
| 159 |
// Copyright 21 - - |
| 160 |
// accuweather link 25 - - |
| 161 |
// |
| 162 |
|
| 163 |
if ($dispconfig == "") { |
| 164 |
$dispconfig="11111111111111111111111111"; |
| 165 |
add_option("wp-forecast-dispconfig".$wpfcid,$dispconfig, |
| 166 |
"Switches for shown Information","yes"); |
| 167 |
} |
| 168 |
|
| 169 |
if ($windunit == "") { |
| 170 |
$windunit="ms"; |
| 171 |
add_option("wp-forecast-windunit".$wpfcid,$windunit, |
| 172 |
"Choose between ms, kmh, mph or kts","yes"); |
| 173 |
} |
| 174 |
} // end of for |
| 175 |
|
| 176 |
if ($wpf_debug > 0) |
| 177 |
pdebug("End of wp_forecast_activate ()"); |
| 178 |
} |
| 179 |
|
| 180 |
// |
| 181 |
// is called when plugin is deactivated and removes all |
| 182 |
// the wp-forecast options from the database |
| 183 |
// |
| 184 |
function wp_forecast_deactivate($wpfcid) |
| 185 |
{ |
| 186 |
global $wpf_debug; |
| 187 |
|
| 188 |
if ($wpf_debug > 0) |
| 189 |
pdebug("Start of wp_forecast_deactivate ()"); |
| 190 |
|
| 191 |
$delopt=get_option('wp-forecast-delopt'); |
| 192 |
|
| 193 |
// only delete options when sitch is set |
| 194 |
if ($delopt == 1) { |
| 195 |
$count=get_option('wp-forecast-count'); |
| 196 |
|
| 197 |
for ($i=0;$i<$count;$i++) { |
| 198 |
$wpfcid = get_widget_id( $i ); |
| 199 |
|
| 200 |
delete_option("wp-forecast-location".$wpfcid); |
| 201 |
delete_option("wp-forecast-locname".$wpfcid); |
| 202 |
delete_option("wp-forecast-refresh".$wpfcid); |
| 203 |
delete_option("wp-forecast-metric".$wpfcid); |
| 204 |
delete_option("wp-forecast-language".$wpfcid); |
| 205 |
delete_option("wp-forecast-daytime".$wpfcid); |
| 206 |
delete_option("wp-forecast-nighttime".$wpfcid); |
| 207 |
delete_option("wp-forecast-dispconfig".$wpfcid); |
| 208 |
delete_option("wp-forecast-windunit".$wpfcid); |
| 209 |
delete_option("wp-forecast-cache".$wpfcid); |
| 210 |
delete_option("wp-forecast-expire".$wpfcid); |
| 211 |
delete_option("wp-forecast-currtime".$wpfcid); |
| 212 |
delete_option("wp-forecast-title".$wpfcid); |
| 213 |
} |
| 214 |
delete_option('wp-forecast-timeout'); |
| 215 |
delete_option('wp-forecast-count'); |
| 216 |
delete_option('wp-forecast-delopt'); |
| 217 |
} |
| 218 |
if ($wpf_debug > 0) |
| 219 |
pdebug("End of wp_forecast_deactivate ()"); |
| 220 |
} |
| 221 |
?> |