PluginProbe
FeedWordPress / 2013.0503
FeedWordPress v2013.0503
trunk 0.8 0.9 0.91 0.95 0.96 0.97 0.98 0.981 0.99 0.991 0.992 0.993 2008.1030 2008.1101 2008.1105 2008.1214 2009.0612 2009.0613 2009.0618 2009.0707 2009.1111 2009.1112 2010.0127 2010.0528 All 65 releases
feedwordpress / diagnostics-page.php

diagnostics-page.php in FeedWordPress 2013.0503, at diagnostics-page.php

420 lines 16.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 require_once(dirname(__FILE__) . '/admin-ui.php');
3
4 class FeedWordPressDiagnosticsPage extends FeedWordPressAdminPage {
5 function FeedWordPressDiagnosticsPage () {
6 // Set meta-box context name
7 FeedWordPressAdminPage::FeedWordPressAdminPage('feedwordpressdiagnosticspage');
8 $this->dispatch = 'feedwordpress_diagnostics';
9 $this->filename = __FILE__;
10
11 $this->test_html = array();
12 add_action('feedwordpress_diagnostics_do_http_test', array($this, 'do_http_test'), 10, 1);
13 }
14
15 function has_link () { return false; }
16
17 function display () {
18 global $wpdb, $wp_db_version, $fwp_path;
19 global $fwp_post;
20
21 if (FeedWordPress::needs_upgrade()) :
22 fwp_upgrade_page();
23 return;
24 endif;
25
26 // If this is a POST, validate source and user credentials
27 FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_diagnostics', /*capability=*/ 'manage_options');
28
29 if (strtoupper($_SERVER['REQUEST_METHOD'])=='POST') :
30 $this->accept_POST($fwp_post);
31 do_action('feedwordpress_admin_page_diagnostics_save', $GLOBALS['fwp_post'], $this);
32 endif;
33
34 ////////////////////////////////////////////////
35 // Prepare settings page ///////////////////////
36 ////////////////////////////////////////////////
37
38 $this->display_update_notice_if_updated('Diagnostics');
39
40 $this->open_sheet('FeedWordPress Diagnostics');
41 ?>
42 <div id="post-body">
43 <?php
44 $boxes_by_methods = array(
45 'info_box' => __('Diagnostic Information'),
46 'diagnostics_box' => __('Display Diagnostics'),
47 'updates_box' => __('Updates'),
48 'tests_box' => __('Diagnostic Tests'),
49 );
50
51 foreach ($boxes_by_methods as $method => $title) :
52 add_meta_box(
53 /*id=*/ 'feedwordpress_'.$method,
54 /*title=*/ $title,
55 /*callback=*/ array('FeedWordPressDiagnosticsPage', $method),
56 /*page=*/ $this->meta_box_context(),
57 /*context=*/ $this->meta_box_context()
58 );
59 endforeach;
60 do_action('feedwordpress_admin_page_diagnostics_meta_boxes', $this);
61 ?>
62 <div class="metabox-holder">
63 <?php
64 fwp_do_meta_boxes($this->meta_box_context(), $this->meta_box_context(), $this);
65 ?>
66 </div> <!-- class="metabox-holder" -->
67 </div> <!-- id="post-body" -->
68
69 <?php
70 $this->close_sheet();
71 } /* FeedWordPressDiagnosticsPage::display () */
72
73 function accept_POST ($post) {
74 if (isset($post['submit'])
75 or isset($post['save'])
76 or isset($post['feedwordpress_diagnostics_do'])) :
77 update_option('feedwordpress_debug', $post['feedwordpress_debug']);
78 update_option('feedwordpress_secret_key', $post['feedwordpress_secret_key']);
79
80 if (!isset($post['diagnostics_output'])
81 or !is_array($post['diagnostics_output'])) :
82 $post['diagnostics_output'] = array();
83 endif;
84 update_option('feedwordpress_diagnostics_output', $post['diagnostics_output']);
85
86 if (!isset($post['diagnostics_show'])
87 or !is_array($post['diagnostics_show'])) :
88 $post['diagnostics_show'] = array();
89 endif;
90 update_option('feedwordpress_diagnostics_show', $post['diagnostics_show']);
91
92 if ($post['diagnostics_show']
93 and in_array('updated_feeds:errors:persistent', $post['diagnostics_show'])) :
94 update_option('feedwordpress_diagnostics_persistent_errors_hours', (int) $post['diagnostics_persistent_error_hours']);
95 else :
96 delete_option('feedwordpress_diagnostics_persistent_errors_hours');
97 endif;
98
99 if (in_array('email', $post['diagnostics_output'])) :
100 $ded = $post['diagnostics_email_destination'];
101 if ('mailto'==$ded) :
102 $ded .= ':'.$post['diagnostics_email_destination_address'];
103 endif;
104
105 update_option('feedwordpress_diagnostics_email_destination', $ded);
106 else :
107 delete_option('feedwordpress_diagnostics_email_destination');
108 endif;
109
110 if (isset($post['feedwordpress_diagnostics_do'])) :
111 foreach ($post['feedwordpress_diagnostics_do'] as $do => $value) :
112 do_action('feedwordpress_diagnostics_do_'.$do, $post);
113 endforeach;
114 endif;
115
116 $this->updated = true; // Default update message
117 endif;
118 } /* FeedWordPressDiagnosticsPage::accept_POST () */
119
120 function info_box ($page, $box = NULL) {
121 global $feedwordpress;
122 global $wp_version;
123 $link_category_id = FeedWordPress::link_category_id();
124 ?>
125 <table class="edit-form narrow">
126 <thead style="display: none">
127 <th scope="col">Topic</th>
128 <th scope="col">Information</th>
129 </thead>
130
131 <tbody>
132 <tr>
133 <th scope="row">Version:</th>
134 <td>You are using FeedWordPress version <strong><?php print FEEDWORDPRESS_VERSION; ?></strong>.</td>
135 </tr>
136
137 <tr>
138 <th scope="row">Hosting Environment:</th>
139 <td><ul style="margin-top: 0; padding-top: 0;">
140 <li><em>WordPress:</em> version <?php print $wp_version; ?></li>
141 <?php if (function_exists('phpversion')) : ?>
142 <li><em>PHP:</em> version <?php print phpversion(); ?></li>
143 <?php endif; ?>
144 <?php if (function_exists('apache_get_version')) : ?>
145 <li><sem>Web Server:</em> <?php print apache_get_version(); ?></li>
146 <?php endif; ?>
147 </ul>
148 </td>
149 </tr>
150
151 <tr>
152 <th scope="row">Link Category:</th>
153 <td><?php if (!is_wp_error($link_category_id)) :
154 $term = get_term($link_category_id, 'link_category');
155 ?><p>Syndicated feeds are
156 kept in link category #<?php print $term->term_id; ?>, <strong><?php print $term->name; ?></strong>.</p>
157 <?php else : ?>
158 <p><strong>FeedWordPress has been unable to set up a valid Link Category
159 for syndicated feeds.</strong> Attempting to set one up returned an
160 <code><?php $link_category_id->get_error_code(); ?></code> error with this
161 additional data:</p>
162 <table>
163 <tbody>
164 <tr>
165 <th scope="row">Message:</th>
166 <td><?php print $link_category_id->get_error_message(); ?></td>
167 </tr>
168 <?php $data = $link_category_id->get_error_data(); if (!empty($data)) : ?>
169 <tr>
170 <th scope="row">Auxiliary Data:</th>
171 <td><pre><?php print esc_html(FeedWordPress::val($link_category_id->get_error_data())); ?></pre></td>
172 </tr>
173 <?php endif; ?>
174 </table>
175 <?php endif; ?></td>
176 </tr>
177
178 <tr>
179 <th scope="row"><?php _e('Secret Key:'); ?></th>
180 <td><input type="text" name="feedwordpress_secret_key" value="<?php print esc_attr($feedwordpress->secret_key()); ?>" />
181 <p class="setting-description">This is used to control access to some diagnostic testing functions. You can change it to any string you want,
182 but only tell it to people you trust to help you troubleshoot your
183 FeedWordPress installation. Keep it secret&#8212;keep it safe.</p></td>
184 </tr>
185 </table>
186
187 <?php
188 } /* FeedWordPressDiagnosticsPage::info_box () */
189
190 function diagnostics_box ($page, $box = NULL) {
191 $settings = array();
192 $settings['debug'] = (get_option('feedwordpress_debug')=='yes');
193
194 $diagnostics_output = get_option('feedwordpress_diagnostics_output', array());
195
196 $users = fwp_author_list();
197
198 $ded = get_option('feedwordpress_diagnostics_email_destination', 'admins');
199
200 if (preg_match('/^mailto:(.*)$/', $ded, $ref)) :
201 $ded_addy = $ref[1];
202 else :
203 $ded_addy = NULL;
204 endif;
205
206 // Hey ho, let's go...
207 ?>
208 <table class="edit-form">
209 <tr style="vertical-align: top">
210 <th scope="row">Debugging mode:</th>
211 <td><select name="feedwordpress_debug" size="1">
212 <option value="yes"<?php echo ($settings['debug'] ? ' selected="selected"' : ''); ?>>on</option>
213 <option value="no"<?php echo ($settings['debug'] ? '' : ' selected="selected"'); ?>>off</option>
214 </select>
215
216 <p>When debugging mode is <strong>ON</strong>, FeedWordPress displays many
217 diagnostic error messages, warnings, and notices that are ordinarily suppressed,
218 and turns off all caching of feeds. Use with caution: this setting is useful for
219 testing but absolutely inappropriate for a production server.</p>
220
221 </td>
222 </tr>
223 <tr>
224 <th scope="row">Diagnostics output:</th>
225 <td><ul class="options">
226 <li><input type="checkbox" name="diagnostics_output[]" value="error_log" <?php print (in_array('error_log', $diagnostics_output) ? ' checked="checked"' : ''); ?> /> Log in PHP error logs</label></li>
227 <li><input type="checkbox" name="diagnostics_output[]" value="admin_footer" <?php print (in_array('admin_footer', $diagnostics_output) ? ' checked="checked"' : ''); ?> /> Display in WordPress admin footer</label></li>
228 <li><input type="checkbox" name="diagnostics_output[]" value="echo" <?php print (in_array('echo', $diagnostics_output) ? ' checked="checked"' : ''); ?> /> Echo in web browser as they are issued</label></li>
229 <li><input type="checkbox" name="diagnostics_output[]" value="echo_in_cronjob" <?php print (in_array('echo_in_cronjob', $diagnostics_output) ? ' checked="checked"' : ''); ?> /> Echo to output when they are issued during an update cron job</label></li>
230 <li><input type="checkbox" name="diagnostics_output[]" value="email" <?php print (in_array('email', $diagnostics_output) ? ' checked="checked"' : ''); ?> /> Send a daily email digest to:</label> <select name="diagnostics_email_destination" id="diagnostics-email-destination" size="1">
231 <option value="admins"<?php if ('admins'==$ded) : ?> selected="selected"<?php endif; ?>>the site administrators</option>
232 <?php foreach ($users as $id => $name) : ?>
233 <option value="user:<?php print (int) $id; ?>"<?php if (sprintf('user:%d', (int) $id)==$ded) : ?> selected="selected"<?php endif; ?>><?php print esc_html($name); ?></option>
234 <?php endforeach; ?>
235 <option value="mailto"<?php if (!is_null($ded_addy)) : ?> selected="selected"<?php endif; ?>>another e-mail address...</option>
236 </select>
237 <input type="email" id="diagnostics-email-destination-address" name="diagnostics_email_destination_address" value="<?php print $ded_addy; ?>" placeholder="email address" /></li>
238 </ul></td>
239 </tr>
240 </table>
241
242 <script type="text/javascript">
243 contextual_appearance(
244 'diagnostics-email-destination',
245 'diagnostics-email-destination-address',
246 'diagnostics-email-destination-default',
247 'mailto',
248 'inline'
249 );
250 jQuery('#diagnostics-email-destination').change ( function () {
251 contextual_appearance(
252 'diagnostics-email-destination',
253 'diagnostics-email-destination-address',
254 'diagnostics-email-destination-default',
255 'mailto',
256 'inline'
257 );
258 } );
259 </script>
260 <?php
261 } /* FeedWordPressDiagnosticsPage::diagnostics_box () */
262
263 /*static*/ function updates_box ($page, $box = NULL) {
264 $hours = get_option('feedwordpress_diagnostics_persistent_errors_hours', 2);
265 $fields = apply_filters('feedwordpress_diagnostics', array(
266 'Update Diagnostics' => array(
267 'update_schedule:check' => 'whenever a FeedWordPress checks in on the update schedule',
268 'updated_feeds' => 'as each feed is checked for updates',
269 'updated_feeds:errors:persistent' => 'when attempts to update a feed have resulted in errors</label> <label>for at least <input type="number" min="1" max="360" step="1" name="diagnostics_persistent_error_hours" value="'.$hours.'" /> hours',
270 'updated_feeds:errors' => 'any time FeedWordPress encounters any errors while checking a feed for updates',
271 'updated_feeds:http' => "displaying the raw HTTP data passed to and from the feed being checked for updates",
272 'syndicated_posts' => 'as each syndicated post is added to the database',
273 'feed_items' => 'as each syndicated item is considered on the feed',
274 'memory_usage' => 'indicating how much memory was used',
275 ),
276 'Syndicated Post Details' => array(
277 'feed_items:freshness' => 'as FeedWordPress decides whether to treat an item as a new post, an update, or a duplicate of an existing post',
278 'feed_items:rejected' => 'when FeedWordPress rejects a post without syndicating it',
279 'syndicated_posts:meta_data' => 'as syndication meta-data is added on the post',
280 ),
281 'Advanced Diagnostics' => array(
282 'feed_items:freshness:reasons' => 'explaining the reason that a post was treated as an update to an existing post',
283 'feed_items:freshness:sql' => 'when FeedWordPress issues the SQL query it uses to decide whether to treat items as new, updates, or duplicates',
284 'syndicated_posts:static_meta_data' => 'providing meta-data about syndicated posts in the Edit Posts interface',
285 ),
286 ), $page);
287
288 foreach ($fields as $section => $items) :
289 foreach ($items as $key => $label) :
290 $checked[$key] = '';
291 endforeach;
292 endforeach;
293
294 $diagnostics_show = get_option('feedwordpress_diagnostics_show', array());
295 if (is_array($diagnostics_show)) : foreach ($diagnostics_show as $thingy) :
296 $checked[$thingy] = ' checked="checked"';
297 endforeach; endif;
298
299 // Hey ho, let's go...
300 ?>
301 <table class="edit-form">
302 <?php foreach ($fields as $section => $ul) : ?>
303 <tr>
304 <th scope="row"><?php print esc_html($section); ?>:</th>
305 <td><p>Show a diagnostic message...</p>
306 <ul class="options">
307 <?php foreach ($ul as $key => $label) : ?>
308 <li><label><input
309 type="checkbox" name="diagnostics_show[]"
310 value="<?php print esc_html($key); ?>"
311 <?php print $checked[$key]; ?> />
312 <?php print $label; ?></label></li>
313 <?php endforeach; ?>
314 </ul></td>
315 </tr>
316 <?php endforeach; ?>
317 </table>
318 <?php
319 } /* FeedWordPressDiagnosticsPage::updates_box () */
320
321 function tests_box ($page, $box = NULL) {
322 ?>
323 <script type="text/javascript">
324 function clone_http_test_args_keyvalue_prototype () {
325 var next = jQuery('#http-test-args').find('.http-test-args-keyvalue').length;
326 var newRow = jQuery('#http-test-args-keyvalue-prototype').clone().attr('id', 'http-test-args-keyvalue-' + next);
327 newRow.find('.http_test_args_key').attr('name', 'http_test_args_key['+next+']').val('');
328 newRow.find('.http_test_args_value').attr('name', 'http_test_args_value['+next+']').val('');
329
330 newRow.appendTo('#http-test-args');
331 return false;
332 }
333 </script>
334
335 <table class="edit-form">
336 <tr>
337 <th scope="row">HTTP:</th>
338 <td><div><input type="url" name="http_test_url" value="" placeholder="http://www.example.com/" size="127" style="width: 80%; max-width: 80.0em;" />
339 <input type="submit" name="feedwordpress_diagnostics_do[http_test]" value="Test &raquo;" /></div>
340 <div><select name="http_test_method" size="1">
341 <option value="wp_remote_request">wp_remote_request</option>
342 <option value="FeedWordPress_File">FeedWordPress_File</option>
343 </select></div>
344 <table>
345 <tr>
346 <td>
347 <div id="http-test-args">
348 <div id="http-test-args-keyvalue-prototype" class="http-test-args-keyvalue"><label>Args:
349 <input type="text" class='http_test_args_key' name="http_test_args_key[0]" value="" placeholder="key" /></label>
350 <label>= <input type="text" class='http_test_args_value' name="http_test_args_value[0]" value="" placeholder="value" /></label>
351 </div>
352 </div>
353 </td>
354 <td><a href="#http-test-args" onclick="return clone_http_test_args_keyvalue_prototype();">+ Add</a></td>
355 </tr>
356 </table>
357
358 <?php if (isset($page->test_html['http_test'])) : ?>
359 <div style="position: relative">
360 <div style="width: 100%; overflow: scroll; background-color: #eed">
361 <pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -o-pre-wrap;"><?php print $page->test_html['http_test']; ?></pre>
362 </div>
363 </div>
364 <?php endif; ?>
365 </td>
366 </tr>
367 </table>
368
369 <?php
370 } /* FeedWordPressDiagnosticsPage::tests_box () */
371
372 var $test_html;
373 function do_http_test ($post) {
374 if (isset($post['http_test_url']) and isset($post['http_test_method'])) :
375 $url = $post['http_test_url'];
376
377 $args = array();
378 if (isset($post['http_test_args_key'])) :
379 foreach ($post['http_test_args_key'] as $idx => $name) :
380 $name = trim($name);
381 if (strlen($name) > 0) :
382 $value = NULL;
383 if (isset($post['http_test_args_value'])
384 and isset($post['http_test_args_value'][$idx])) :
385 $value = $post['http_test_args_value'][$idx];
386 endif;
387
388 if (preg_match('/^javascript:(.*)$/i', $value, $refs)) :
389 if (function_exists('json_decode')) :
390 $json_value = json_decode($refs[1]);
391 if (!is_null($json_value)) :
392 $value = $json_value;
393 endif;
394 endif;
395 endif;
396
397 $args[$name] = $value;
398 endif;
399 endforeach;
400 endif;
401
402 switch ($post['http_test_method']) :
403 case 'wp_remote_request' :
404 $out = wp_remote_request($url, $args);
405 break;
406 case 'FeedWordPress_File' :
407 $out = new FeedWordPress_File($url);
408 break;
409 endswitch;
410
411 $this->test_html['http_test'] = esc_html(FeedWordPress::val($out));
412 endif;
413 } /* FeedWordPressDiagnosticsPage::do_http_test () */
414
415 } /* class FeedWordPressDiagnosticsPage */
416
417 $diagnosticsPage = new FeedWordPressDiagnosticsPage;
418 $diagnosticsPage->display();
419
420