PluginProbe
FeedWordPress / 2024.0428
FeedWordPress v2024.0428
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 2024.0428, at diagnostics-page.php

494 lines 19.5 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 require_once(dirname(__FILE__) . '/magpiemocklink.class.php');
4
5 class FeedWordPressDiagnosticsPage extends FeedWordPressAdminPage {
6 public function __construct() {
7 // Set meta-box context name
8 parent::__construct('feedwordpressdiagnosticspage');
9 $this->dispatch = 'feedwordpress_diagnostics';
10 $this->filename = __FILE__;
11
12 $this->test_html = array();
13 add_action('feedwordpress_diagnostics_do_http_test', array($this, 'do_http_test'), 10, 1);
14 }
15
16 function has_link () { return false; }
17
18 function display () {
19 if (FeedWordPress::needs_upgrade()) :
20 fwp_upgrade_page();
21 return;
22 endif;
23
24 // If this is a POST, validate source and user credentials
25 FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_diagnostics', /*capability=*/ 'manage_options');
26
27 if (strtoupper($_SERVER['REQUEST_METHOD'])=='POST') :
28 $this->accept_POST();
29 do_action('feedwordpress_admin_page_diagnostics_save', null, $this);
30 endif;
31
32 ////////////////////////////////////////////////
33 // Prepare settings page ///////////////////////
34 ////////////////////////////////////////////////
35
36 $this->display_update_notice_if_updated('Diagnostics');
37
38 $this->open_sheet('FeedWordPress Diagnostics');
39 ?>
40 <div id="post-body">
41 <?php
42 $boxes_by_methods = array(
43 'info_box' => __('Diagnostic Information'),
44 'diagnostics_box' => __('Display Diagnostics'),
45 'updates_box' => __('Diagnostic Messages'),
46 'tests_box' => __('Diagnostic Tests'),
47 );
48
49 foreach ($boxes_by_methods as $method => $title) :
50 add_meta_box(
51 /*id=*/ 'feedwordpress_'.$method,
52 /*title=*/ $title,
53 /*callback=*/ array('FeedWordPressDiagnosticsPage', $method),
54 /*page=*/ $this->meta_box_context(),
55 /*context=*/ $this->meta_box_context()
56 );
57 endforeach;
58 do_action('feedwordpress_admin_page_diagnostics_meta_boxes', $this);
59 ?>
60 <div class="metabox-holder">
61 <?php
62 do_meta_boxes($this->meta_box_context(), $this->meta_box_context(), $this);
63 ?>
64 </div> <!-- class="metabox-holder" -->
65 </div> <!-- id="post-body" -->
66
67 <?php
68 $this->close_sheet();
69 } /* FeedWordPressDiagnosticsPage::display () */
70
71 public function do_requested () {
72 return ( ! is_null( self::what_requested() ) );
73 }
74
75 public function what_requested () {
76 return FeedWordPress::post( 'feedwordpress_diagnostics_do' );
77 }
78
79 function accept_POST () {
80 if ( self::save_requested() || self::do_requested() ) :
81
82 update_option( 'feedwordpress_debug', FeedWordPress::post( 'feedwordpress_debug' ) );
83 update_option( 'feedwordpress_secret_key', FeedWordPress::post( 'feedwordpress_secret_key' ) );
84
85 update_option( 'feedwordpress_diagnostics_output', FeedWordPress::post( 'diagnostics_output' ) );
86 update_option( 'feedwordpress_diagnostics_show', FeedWordPress::post( 'diagnostics_show' ) );
87
88 if ( FeedWordPress::post( 'diagnostics_show' )
89 and in_array( 'updated_feeds:errors:persistent', FeedWordPress::post( 'diagnostics_show' ) ) ) :
90 update_option('feedwordpress_diagnostics_persistent_errors_hours', (int) FeedWordPress::post( 'diagnostics_persistent_error_hours' ) );
91 else :
92 delete_option( 'feedwordpress_diagnostics_persistent_errors_hours' );
93 endif;
94
95 if ( in_array( 'email', FeedWordPress::post( 'diagnostics_output' ) ) ) :
96 $ded = FeedWordPress::post('diagnostics_email_destination' );
97 if ( 'mailto' == $ded ) :
98 $ded .= ':' . FeedWordPress::post('diagnostics_email_destination_address' );
99 endif;
100
101 update_option( 'feedwordpress_diagnostics_email_destination', $ded );
102 else :
103 delete_option( 'feedwordpress_diagnostics_email_destination' );
104 endif;
105
106 if ( self::do_requested() ) :
107 foreach ( self::what_requested() as $do => $value) :
108 do_action( 'feedwordpress_diagnostics_do_'.$do );
109 endforeach;
110 endif;
111
112 $this->updated = true; // Default update message
113 endif;
114 } /* FeedWordPressDiagnosticsPage::accept_POST () */
115
116 static function info_box ($page, $box = NULL) {
117 global $feedwordpress;
118 global $wp_version;
119 $link_category_id = FeedWordPress::link_category_id();
120 ?>
121 <table class="edit-form narrow">
122 <thead style="display: none">
123 <th scope="col">Topic</th>
124 <th scope="col">Information</th>
125 </thead>
126
127 <tbody>
128 <tr>
129 <th scope="row"><?php esc_html_e( 'Version:' ); ?></th>
130 <td><?php esc_html_e( 'You are using FeedWordPress version' ); ?> <strong><?php print esc_html( FEEDWORDPRESS_VERSION ); ?></strong>.</td>
131 </tr>
132
133 <tr>
134 <th scope="row"><?php esc_html_e( 'Hosting Environment:' ); ?></th>
135 <td><ul style="margin-top: 0; padding-top: 0;">
136 <li><em>WordPress:</em> <?php esc_html_e( 'version' ); ?> <?php print esc_html( $wp_version ); ?></li>
137 <li><em>SimplePie:</em> <?php esc_html_e( 'version' ); ?> <?php print esc_html( SIMPLEPIE_VERSION ); ?></li>
138 <?php if ( function_exists( 'phpversion' ) ) : ?>
139 <li><em><?php esc_html_e( 'PHP:' ); ?></em> <?php esc_html_e( 'version' ); ?> <?php print esc_html( phpversion() ); ?></li>
140 <?php endif; ?>
141 <?php if ( function_exists( 'apache_get_version' ) ) : ?>
142 <li><em><?php esc_html_e( 'Web Server:' ); ?></em> <?php print esc_html( apache_get_version() ); ?></li>
143 <?php endif; ?>
144 <?php if ( ! empty( $_SERVER['SERVER_SIGNATURE'] ) ) : ?>
145 <li><em><?php esc_html_e( 'Web Server signature:' ); ?></em> <?php print esc_html( $_SERVER['SERVER_SIGNATURE'] ); ?></li>
146 <?php endif; ?>
147 <li><em><?php esc_html_e( 'Hosted on:' ); ?></em> <?php print esc_html( php_uname( 'a' ) ); ?></li>
148 </ul>
149 </td>
150 </tr>
151
152 <tr>
153 <th scope="row"><?php esc_html_e( 'Link Category:' ); ?></th>
154 <td><?php if ( ! is_wp_error( $link_category_id ) ) :
155 $term = get_term( $link_category_id, 'link_category' );
156 ?><p><?php esc_html_e( 'Syndicated feeds are kept in link category' ); ?> #<?php print esc_html( $term->term_id ); ?>, <strong><?php print esc_html( $term->name ); ?></strong>.</p>
157 <?php else : ?>
158 <p><strong><?php esc_html_e( 'FeedWordPress has been unable to set up a valid Link Category for syndicated feeds.' ); ?></strong> <?php esc_html_e( 'Attempting to set one up returned an' ); ?>
159 <code><?php $link_category_id->get_error_code(); ?></code> <?php esc_html_e( 'error with this additional data:' ); ?></p>
160 <table>
161 <tbody>
162 <tr>
163 <th scope="row"><?php esc_html_e( 'Message:' ); ?></th>
164 <td><?php print esc_html( $link_category_id->get_error_message() ); ?></td>
165 </tr>
166 <?php $data = $link_category_id->get_error_data(); if ( ! empty( $data ) ) : ?>
167 <tr>
168 <th scope="row"><?php esc_html_e( 'Auxiliary Data:' ); ?></th>
169 <td><pre><?php print esc_html( MyPHP::val( $link_category_id->get_error_data() ) ); ?></pre></td>
170 </tr>
171 <?php endif; ?>
172 </table>
173 <?php endif; ?></td>
174 </tr>
175
176 <tr>
177 <th scope="row"><?php esc_html_e('Secret Key:'); ?></th>
178 <td><input type="text" name="feedwordpress_secret_key" value="<?php print esc_attr( $feedwordpress->secret_key() ); ?>" />
179 <p class="setting-description"><?php esc_html_e( 'This is used to control access to some diagnostic testing functions. You can change it to any string you want, but only tell it to people you trust to help you troubleshoot your FeedWordPress installation. Keep it secret&mdash;keep it safe.' ); ?></p></td>
180 </tr>
181 </table>
182
183 <?php
184 } /* FeedWordPressDiagnosticsPage::info_box () */
185
186 static function diagnostics_box( $page, $box = NULL ) {
187 $settings = array();
188 $settings['debug'] = ( get_option( 'feedwordpress_debug' ) == 'yes' );
189
190 $diagnostics_output = get_option( 'feedwordpress_diagnostics_output', array() );
191
192 $users = fwp_author_list();
193
194 $ded = get_option( 'feedwordpress_diagnostics_email_destination', 'admins' );
195
196 if (preg_match( '/^mailto:(.*)$/', $ded, $ref ) ) :
197 $ded_addy = $ref[1];
198 else :
199 $ded_addy = NULL;
200 endif;
201
202 // Hey ho, let's go...
203 ?>
204 <table class="edit-form">
205 <tr style="vertical-align: top">
206 <th scope="row"><?php esc_html_e( 'Debugging mode:' ); ?></th>
207 <td><select name="feedwordpress_debug" size="1">
208 <option value="yes"<?php echo ( $settings['debug'] ? ' selected="selected"' : '' ); ?>><?php esc_html_e( 'on' ); ?></option>
209 <option value="no"<?php echo ( $settings['debug'] ? '' : ' selected="selected"' ); ?>><?php esc_html_e( 'off' ); ?></option>
210 </select>
211
212 <p><?php esc_html_e( 'When debugging mode is <strong>ON</strong>, FeedWordPress displays many
213 diagnostic error messages, warnings, and notices that are ordinarily suppressed,
214 and turns off all caching of feeds. Use with caution: this setting is useful for
215 testing but absolutely inappropriate for a production server.' ); ?></p>
216
217 </td>
218 </tr>
219 <tr>
220 <th scope="row">Diagnostics output:</th>
221 <td><ul class="options">
222 <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>
223 <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>
224 <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>
225 <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>
226 <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">
227 <option value="admins"<?php if ( 'admins' == $ded ) : ?> selected="selected"<?php endif; ?>>the site administrators</option>
228 <?php foreach ($users as $id => $name) : ?>
229 <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>
230 <?php endforeach; ?>
231 <option value="mailto"<?php if ( !is_null($ded_addy)) : ?> selected="selected"<?php endif; ?>>another e-mail address...</option>
232 </select>
233 <input type="email" id="diagnostics-email-destination-address" name="diagnostics_email_destination_address" value="<?php print esc_attr( $ded_addy ); ?>" placeholder="email address" /></li>
234 </ul></td>
235 </tr>
236 </table>
237
238 <script type="text/javascript">
239 contextual_appearance(
240 'diagnostics-email-destination',
241 'diagnostics-email-destination-address',
242 'diagnostics-email-destination-default',
243 'mailto',
244 'inline'
245 );
246 jQuery( '#diagnostics-email-destination' ).change ( function () {
247 contextual_appearance(
248 'diagnostics-email-destination',
249 'diagnostics-email-destination-address',
250 'diagnostics-email-destination-default',
251 'mailto',
252 'inline'
253 );
254 } );
255 </script>
256 <?php
257 } /* FeedWordPressDiagnosticsPage::diagnostics_box () */
258
259 /**
260 * Shows the box for the many possible update options.
261 *
262 * @param type $page description
263 * @param type $box description
264 *
265 * @return void description
266 */
267 static function updates_box ($page, $box = NULL) {
268 $hours = get_option( 'feedwordpress_diagnostics_persistent_errors_hours', 2 );
269 $fields = apply_filters( 'feedwordpress_diagnostics', array(
270 'Update Diagnostics' => array(
271 'update_schedule:check' => 'whenever a FeedWordPress checks in on the update schedule',
272 'updated_feeds' => 'as each feed is checked for updates',
273 'syndicated_posts' => 'as each syndicated post is added to the database',
274 'feed_items' => 'as each syndicated item is considered on the feed',
275 'memory_usage' => 'indicating how much memory was used',
276 ),
277 // Note: the embedded HTML gets filtered out, so this might require some refactoring. (gwyneth 20230917)
278 'Feed Retrieval' => array(
279 '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',
280 'updated_feeds:errors' => 'any time FeedWordPress encounters any errors while checking a feed for updates',
281 'updated_feeds:http' => "displaying the raw HTTP data passed to and from the feed being checked for updates",
282 ),
283 'Syndicated Post Details' => array(
284 'feed_items:freshness' => 'as FeedWordPress decides whether to treat an item as a new post, an update, or a duplicate of an existing post',
285 'feed_items:rejected' => 'when FeedWordPress rejects a post without syndicating it',
286 'syndicated_posts:categories' => 'as categories, tags, and other terms are added on the post',
287 'syndicated_posts:meta_data' => 'as syndication meta-data is added on the post',
288 'syndicated_posts:do_pings' => 'when FeedWordPress holds or releases the pings WordPress sends out when new posts are created',
289 ),
290 'Advanced Diagnostics' => array(
291 'feed_items:freshness:reasons' => 'explaining the reason that a post was treated as an update to an existing post',
292 'feed_items:freshness:sql' => 'when FeedWordPress issues the SQL query it uses to decide whether to treat items as new, updates, or duplicates',
293 'syndicated_posts:categories:test' => 'as FeedWordPress checks for the familiarity of feed categories and tags',
294 'syndicated_posts:static_meta_data' => 'providing meta-data about syndicated posts in the Edit Posts interface',
295 ),
296 ), $page );
297
298 foreach ( $fields as $section => $items ) :
299 foreach ( $items as $key => $label ) :
300 $checked[$key] = '';
301 endforeach;
302 endforeach;
303
304 $diagnostics_show = get_option( 'feedwordpress_diagnostics_show', array() );
305 if ( is_array( $diagnostics_show ) ) : foreach ( $diagnostics_show as $thingy ) :
306 $checked[$thingy] = ' checked="checked"';
307 endforeach; endif;
308
309 // Hey ho, let's go...
310 ?>
311 <table class="edit-form">
312 <?php foreach ($fields as $section => $ul) : ?>
313 <tr>
314 <th scope="row"><?php print esc_html($section); ?>:</th>
315 <td><p><?php esc_html_e( 'Show a diagnostic message...' ); ?></p>
316 <ul class="options">
317 <?php foreach ($ul as $key => $label) : ?>
318 <li><label><input
319 type="checkbox" name="diagnostics_show[]"
320 value="<?php print esc_html( $key ); ?>"
321 <?php fwp_selected_flag( $checked, $key, "checked" ); ?> />
322 <?php print esc_html( $label ); ?></label></li>
323 <?php endforeach; ?>
324 </ul></td>
325 </tr>
326 <?php endforeach; ?>
327 </table>
328 <?php
329 } /* FeedWordPressDiagnosticsPage::updates_box () */
330
331 static function tests_box ($page, $box = NULL) {
332 $url = FeedWordPress::param( 'http_test_url' );
333 $method = FeedWordPress::param( 'http_test_method' );
334 $xpath = FeedWordPress::param( 'http_test_xpath' );
335
336 $aMethods = array(
337 'wp_remote_request',
338 'FeedWordPie_File',
339 'FeedWordPress::fetch',
340 );
341 ?>
342 <script type="text/javascript">
343 function clone_http_test_args_keyvalue_prototype () {
344 var next = jQuery('#http-test-args').find('.http-test-args-keyvalue').length;
345 var newRow = jQuery('#http-test-args-keyvalue-prototype').clone().attr('id', 'http-test-args-keyvalue-' + next);
346 newRow.find('.http_test_args_key').attr('name', 'http_test_args_key['+next+']').val('');
347 newRow.find('.http_test_args_value').attr('name', 'http_test_args_value['+next+']').val('');
348
349 newRow.appendTo('#http-test-args');
350 return false;
351 }
352 </script>
353
354 <table class="edit-form">
355 <tr>
356 <th scope="row">HTTP:</th>
357 <td><div><input type="url" name="http_test_url" value="<?php print esc_attr($url);?>" placeholder="http://www.example.com/" size="127" style="width: 80%; max-width: 80.0em;" />
358 <input type="submit" name="feedwordpress_diagnostics_do[http_test]" value="Test &raquo;" /></div>
359 <div><select name="http_test_method" size="1">
360 <?php foreach ($aMethods as $sMethod) :?>
361 <option value="<?php
362 print esc_attr($sMethod);
363 ?>"<?php
364 if ($method==$sMethod) :
365 print ' selected="selected"';
366 endif;
367 ?>><?php
368 print esc_html( $sMethod );
369 ?></option>
370 <?php endforeach; ?>
371 </select></div>
372 <table>
373 <tr>
374 <td>
375 <div id="http-test-args">
376 <div id="http-test-args-keyvalue-prototype" class="http-test-args-keyvalue"><label><?php esc_html_e( 'Args' ); ?>:
377 <input type="text" class='http_test_args_key' name="http_test_args_key[0]" value="" placeholder="key" /></label>
378 <label>= <input type="text" class='http_test_args_value' name="http_test_args_value[0]" value="" placeholder="value" /></label>
379 </div>
380 </div>
381 </td>
382 <td><a href="#http-test-args" onclick="return clone_http_test_args_keyvalue_prototype();"><span class="dashicons dashicons-plus fwp-no-underline"></span> <?php esc_html_e( 'Add' ); ?></a></td>
383 </tr>
384 </table>
385 </td>
386 </tr>
387
388 <tr>
389 <th>XPath:</th>
390 <td><div><input type="text" name="http_test_xpath" value="<?php print esc_attr($xpath); ?>" placeholder="xpath-like query" /></div>
391 <div><p><?php esc_html_e( 'Leave blank to test HTTP, fill in to test a query.' ); ?></p></div>
392 </td>
393 </tr>
394
395 <?php if (isset($page->test_html['http_test'])) : ?>
396 <tr>
397 <th scope="row"><?php esc_html_e( 'RESULTS:' ); ?></th>
398 <td>
399 <div>URL: <code><?php print esc_html($page->test_html['url']); ?></code></div>
400 <div style="position: relative">
401 <div style="width: 100%; overflow: scroll; background-color: #eed">
402 <pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -o-pre-wrap;"><?php print esc_html($page->test_html['http_test']); ?></pre>
403 </div>
404 </div>
405 </td>
406 </tr>
407 <?php endif; ?>
408 </table>
409
410 <?php
411 } /* FeedWordPressDiagnosticsPage::tests_box () */
412
413 private $test_html;
414 public function do_http_test () {
415 $url = FeedWordPress::post( 'http_test_url' );
416 $method = FeedWordPress::post( 'http_test_method' );
417 if ( ! ( is_null( $url ) || is_null( $method ) ) ) :
418
419 $args = array();
420 $keys = FeedWordPress::post( 'http_test_args_key' );
421 if ( ! is_null( $keys ) ) :
422 foreach ( $keys as $idx => $name ) :
423 $name = trim($name);
424 if (strlen($name) > 0) :
425 $values = FeedWordPress::post('http_test_args_value', array() );
426
427 $value = null;
428 if ( isset( $values[ $idx ] ) ) :
429 $value = $values[$idx];
430 endif;
431
432 if ( preg_match('/^javascript:(.*)$/i', $value, $refs) ) :
433 if ( function_exists('json_decode') ) :
434 $json_value = json_decode( $refs[1] );
435 if ( ! is_null($json_value) ) :
436 $value = $json_value;
437 endif;
438 endif;
439 endif;
440
441 $args[ $name ] = $value;
442 endif;
443 endforeach;
444 endif;
445
446 switch ( $method ) :
447 case 'wp_remote_request' :
448 $out = wp_remote_request($url, $args);
449 unset( $out[ 'http_response' ] );
450 break;
451 case 'FeedWordPie_File' :
452 $out = new FeedWordPie_File($url);
453 break;
454 case 'FeedWordPress::fetch' :
455 $out = FeedWordPress::fetch($url);
456
457 $s_xpath = FeedWordPress::post( 'http_test_xpath', '' );
458 if ( strlen( $s_xpath ) > 0 ) :
459
460 $xpath = FeedWordPress::post( 'http_test_xpath' );
461
462 if ( !is_wp_error($out) ) :
463 $expr = new FeedWordPressParsedPostMeta($xpath);
464
465 $feed = new MagpieMockLink( $out, $url );
466 $posts = $feed->live_posts();
467
468 $post = new SyndicatedPost($posts[0], $feed);
469 $meta = $expr->do_substitutions($post);
470
471 $out = array(
472 "post_title" => $post->entry->get_title(),
473 "post_link" => $post->permalink(),
474 "guid" => $post->guid(),
475 "expression" => $xpath,
476 "results" => $meta,
477 "pie" => $out,
478 );
479 endif;
480 endif;
481 break;
482 endswitch;
483
484 $this->test_html['url'] = $url;
485 $this->test_html['http_test'] = esc_html( MyPHP::val($out) );
486 endif;
487 } /* FeedWordPressDiagnosticsPage::do_http_test () */
488
489 } /* class FeedWordPressDiagnosticsPage */
490
491 $diagnosticsPage = new FeedWordPressDiagnosticsPage;
492 $diagnosticsPage->display();
493
494