PluginProbe
wp-forecast / 2.6
wp-forecast v2.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 / wp-forecast-check.php

wp-forecast-check.php in wp-forecast 2.6, at wp-forecast-check.php

192 lines 6.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /* This file is part of the wp-forecast plugin for wordpress */
3
4 /* Copyright 2009 Hans Matzen (email : webmaster at tuxlog dot 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 // include wordpress stuff
22 require_once("../../../wp-config.php");
23 require_once("funclib.php");
24
25 function checkURL($url)
26 {
27 $erg = array();
28
29 // switch to wp-forecast transport
30 switch_wpf_transport(true);
31
32 $wprr_args = array(
33 'timeout' => 30,
34 'headers' => array('Connection' => 'Close','Accept' => '*/*')
35 );
36
37 // use generic wordpress function to retrieve data
38 $s = time();
39 $resp = wp_remote_request($url, $wprr_args);
40 $e = time();
41
42 // switch to wordpress transport
43 switch_wpf_transport(false);
44
45 $erg['duration'] = (int) ($e-$s);
46
47 if ( is_wp_error($resp) ) {
48 $errcode = $resp->get_error_code();
49 $errmesg = $resp->get_error_message($errcode);
50
51 $erg['error'] = $errcode . " " . $errmesg;
52 $erg['body'] = "";
53 $erg['len'] = "-1";
54 } else {
55 $erg['error'] = "";
56 $erg['body'] = $resp['body'];
57 $erg['len'] = strlen( $resp['body'] );
58 }
59 return $erg;
60 }
61
62 function showCheckResult($erg)
63 {
64 $out = "";
65 $space = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
66 if ($erg['error'] == "") {
67 $out .= $space . "Test was successfull.". "<br/>";
68 $out .= $space . "Fetched " . $erg['len'] . " Bytes in ";
69 $out .= $erg['duration'] . " seconds."."<br/>";
70 } else {
71 $out .= $space . "Test ends in error.". "<br/>";
72 $out .= $space . "Error-Message was " . $erg['error'] ."<br/>";
73 }
74 return $out;
75 }
76
77
78 $wpf_vars=get_wpf_opts("A");
79 $locale = $wpf_vars['wpf_language'];
80
81 // get translations
82 if(function_exists('load_textdomain')) {
83 global $l10n;
84 if (!isset($l10n["wp-forecast_".$locale]))
85 load_textdomain("wp-forecast_".$locale, ABSPATH . "wp-content/plugins/wp-forecast/lang/".$locale.".mo");
86 }
87
88 if (!empty($_POST)) {
89 $out = "";
90 $out .= "Checking for Weatherprovider " . $_POST['wprovider'] . "<br />";
91
92 $transports = get_wp_transports();
93
94 if ( $_POST['wprovider'] == "Accuweather")
95 $url = $wpf_vars["ACCU_BASE_URI"] . "metric=1&location=EUR|DE|GM007|FRANKFURT AM MAIN";
96 if ( $_POST['wprovider'] == "WeatherBug") {
97 if ( !isset($wpf_vars['apikey1'])) {
98 $out .= "You have to set the API-Key to test WeatherBug.";
99 echo $out;
100 die();
101 }
102 $url = $wpf_vars["BUG_BASE_URI"] . "58738&UnitType=1&OutputType=1";
103 $url = str_replace('#apicode#',$wpf_vars['apikey1'],$url);
104 }
105
106 if ( $_POST['wprovider'] == "Weather.com")
107 $url="";
108
109
110 // remember selected transport
111 $wp_transport = get_option("wp-forecast-wp-transport");
112
113 // checking for standard connection method
114 $out .= "Checking default transport"."<br />";
115 update_option("wp-forecast-wp-transport","default");
116 $erg = checkURL($url);
117 $out .= showCheckResult($erg);
118
119 // checking fsockopen
120 $out .= "Checking fsockopen transport"."<br />";
121 update_option("wp-forecast-wp-transport","fsockopen");
122 $erg = checkURL($url);
123 $out .= showCheckResult($erg);
124
125 // checking exthttp
126 $out .= "Checking exthttp transport"."<br />";
127 update_option("wp-forecast-wp-transport","exthttp");
128 $erg = checkURL($url);
129 $out .= showCheckResult($erg);
130
131
132 // checking streams
133 $out .= "Checking streams transport"."<br />";
134 update_option("wp-forecast-wp-transport","streams");
135 $erg = checkURL($url);
136 $out .= showCheckResult($erg);
137
138
139 // checking curl
140 $out .= "Checking curl transport"."<br />";
141 update_option("wp-forecast-wp-transport","curl");
142 $erg = checkURL($url);
143 $out .= showCheckResult($erg);
144
145
146 // write back selected transport
147 update_option("wp-forecast-wp-transport",$wp_transport);
148
149
150 echo $out;
151 // you must end here to stop the displaying of the html below
152 exit (0);
153 }
154
155 //
156 // import formular aufbauen ===================================================
157 //
158 $out = "";
159 // add function to submit form data by adrian callaghan
160 $out .= '<script type="text/javascript" src="'.site_url('/wp-content/plugins/wp-forecast').'/wp-forecast-check.js" ></script>';
161 // add log area style
162 $out .= "<style>#message {margin:20px; padding:20px; background:#cccccc; color:#cc0000;}</style>";
163
164 $out .= '<div id="checkorm" class="wrap" >';
165 $out .= '<h2>wp-forecast '.__('Connection-check',"wp-forecast_".$locale).'</h2>';
166 $out .= '<table class="editform" cellspacing="5" cellpadding="5">';
167 $out .= '<tr>';
168 $out .= '<th scope="row" valign="top"><label for="wprovider">'.__('Select weatherprovider','wp-forecast_'.$locale).':</label></th>'."\n";
169 $out .= '<td><select name="wprovider" id="wprovider">'."\n";
170
171 $out .= "<option value='Accuweather'>Accuweather</option>\n";
172 $out .= "<option value='WeatherBug'>WeatherBug</option>\n";
173 //$out .= "<option value='Weather.com'>Weather.com</option>\n";
174 $out .= "</select></td>\n";
175
176 // add submit button to form
177 $href= site_url("wp-admin") . "/admin.php?page=wp-forecast-admin.php";
178 $out .= '<tr><td><p class="submit">';
179 $out .= '<input type="submit" name="startcheck" id="startcheck" value="'.
180 __('Start check','wp-forecast_'.$locale).' &raquo;" onclick="submit_this()" />';
181 $out .= '<td><p class="submit">';
182 $out .= '<input type="submit" name="cancel" id="cancel" value="'.
183 __('Close','wpml').'" onclick="tb_remove();" /></p></td>';
184 $out .= '</p></td></tr>'."\n";
185 $out .= '</table><hr />'."\n";
186 // div container fuer das verarbeitungs log
187 $out .= '<div id="message">Check log</div>';
188 $out .= "</div>\n";
189
190 echo $out;
191 ?>
192