PluginProbe
FeedWordPress / 2020.0118
FeedWordPress v2020.0118
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 2020.0118, at diagnostics-page.php

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