PluginProbe
FeedWordPress / 2012.1212
FeedWordPress v2012.1212
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 2012.1212, at diagnostics-page.php

405 lines 15.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
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 $link_category_id = FeedWordPress::link_category_id();
123 ?>
124 <table class="edit-form narrow">
125 <thead style="display: none">
126 <th scope="col">Topic</th>
127 <th scope="col">Information</th>
128 </thead>
129
130 <tbody>
131 <tr>
132 <th scope="row">Version:</th>
133 <td>You are using FeedWordPress version <strong><?php print FEEDWORDPRESS_VERSION; ?></strong>.</td>
134 </tr>
135
136 <tr>
137 <th scope="row">Link Category:</th>
138 <td><?php if (!is_wp_error($link_category_id)) :
139 $term = get_term($link_category_id, 'link_category');
140 ?><p>Syndicated feeds are
141 kept in link category #<?php print $term->term_id; ?>, <strong><?php print $term->name; ?></strong>.</p>
142 <?php else : ?>
143 <p><strong>FeedWordPress has been unable to set up a valid Link Category
144 for syndicated feeds.</strong> Attempting to set one up returned an
145 <code><?php $link_category_id->get_error_code(); ?></code> error with this
146 additional data:</p>
147 <table>
148 <tbody>
149 <tr>
150 <th scope="row">Message:</th>
151 <td><?php print $link_category_id->get_error_message(); ?></td>
152 </tr>
153 <?php $data = $link_category_id->get_error_data(); if (!empty($data)) : ?>
154 <tr>
155 <th scope="row">Auxiliary Data:</th>
156 <td><pre><?php print esc_html(FeedWordPress::val($link_category_id->get_error_data())); ?></pre></td>
157 </tr>
158 <?php endif; ?>
159 </table>
160 <?php endif; ?></td>
161 </tr>
162
163 <tr>
164 <th scope="row"><?php _e('Secret Key:'); ?></th>
165 <td><input type="text" name="feedwordpress_secret_key" value="<?php print esc_attr($feedwordpress->secret_key()); ?>" />
166 <p class="setting-description">This is used to control access to some diagnostic testing functions. You can change it to any string you want,
167 but only tell it to people you trust to help you troubleshoot your
168 FeedWordPress installation. Keep it secret&#8212;keep it safe.</p></td>
169 </tr>
170 </table>
171
172 <?php
173 } /* FeedWordPressDiagnosticsPage::info_box () */
174
175 function diagnostics_box ($page, $box = NULL) {
176 $settings = array();
177 $settings['debug'] = (get_option('feedwordpress_debug')=='yes');
178
179 $diagnostics_output = get_option('feedwordpress_diagnostics_output', array());
180
181 $users = fwp_author_list();
182
183 $ded = get_option('feedwordpress_diagnostics_email_destination', 'admins');
184
185 if (preg_match('/^mailto:(.*)$/', $ded, $ref)) :
186 $ded_addy = $ref[1];
187 else :
188 $ded_addy = NULL;
189 endif;
190
191 // Hey ho, let's go...
192 ?>
193 <table class="edit-form">
194 <tr style="vertical-align: top">
195 <th scope="row">Debugging mode:</th>
196 <td><select name="feedwordpress_debug" size="1">
197 <option value="yes"<?php echo ($settings['debug'] ? ' selected="selected"' : ''); ?>>on</option>
198 <option value="no"<?php echo ($settings['debug'] ? '' : ' selected="selected"'); ?>>off</option>
199 </select>
200
201 <p>When debugging mode is <strong>ON</strong>, FeedWordPress displays many
202 diagnostic error messages, warnings, and notices that are ordinarily suppressed,
203 and turns off all caching of feeds. Use with caution: this setting is useful for
204 testing but absolutely inappropriate for a production server.</p>
205
206 </td>
207 </tr>
208 <tr>
209 <th scope="row">Diagnostics output:</th>
210 <td><ul class="options">
211 <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>
212 <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>
213 <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>
214 <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>
215 <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">
216 <option value="admins"<?php if ('admins'==$ded) : ?> selected="selected"<?php endif; ?>>the site administrators</option>
217 <?php foreach ($users as $id => $name) : ?>
218 <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>
219 <?php endforeach; ?>
220 <option value="mailto"<?php if (!is_null($ded_addy)) : ?> selected="selected"<?php endif; ?>>another e-mail address...</option>
221 </select>
222 <input type="email" id="diagnostics-email-destination-address" name="diagnostics_email_destination_address" value="<?php print $ded_addy; ?>" placeholder="email address" /></li>
223 </ul></td>
224 </tr>
225 </table>
226
227 <script type="text/javascript">
228 contextual_appearance(
229 'diagnostics-email-destination',
230 'diagnostics-email-destination-address',
231 'diagnostics-email-destination-default',
232 'mailto',
233 'inline'
234 );
235 jQuery('#diagnostics-email-destination').change ( function () {
236 contextual_appearance(
237 'diagnostics-email-destination',
238 'diagnostics-email-destination-address',
239 'diagnostics-email-destination-default',
240 'mailto',
241 'inline'
242 );
243 } );
244 </script>
245 <?php
246 } /* FeedWordPressDiagnosticsPage::diagnostics_box () */
247
248 /*static*/ function updates_box ($page, $box = NULL) {
249 $hours = get_option('feedwordpress_diagnostics_persistent_errors_hours', 2);
250 $fields = apply_filters('feedwordpress_diagnostics', array(
251 'Update Diagnostics' => array(
252 'update_schedule:check' => 'whenever a FeedWordPress checks in on the update schedule',
253 'updated_feeds' => 'as each feed is checked for updates',
254 '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',
255 'updated_feeds:errors' => 'any time FeedWordPress encounters any errors while checking a feed for updates',
256 'updated_feeds:http' => "displaying the raw HTTP data passed to and from the feed being checked for updates",
257 'syndicated_posts' => 'as each syndicated post is added to the database',
258 'feed_items' => 'as each syndicated item is considered on the feed',
259 'memory_usage' => 'indicating how much memory was used',
260 ),
261 'Syndicated Post Details' => array(
262 'feed_items:freshness' => 'as FeedWordPress decides whether to treat an item as a new post, an update, or a duplicate of an existing post',
263 'feed_items:rejected' => 'when FeedWordPress rejects a post without syndicating it',
264 'syndicated_posts:meta_data' => 'as syndication meta-data is added on the post',
265 ),
266 'Advanced Diagnostics' => array(
267 'feed_items:freshness:reasons' => 'explaining the reason that a post was treated as an update to an existing post',
268 'feed_items:freshness:sql' => 'when FeedWordPress issues the SQL query it uses to decide whether to treat items as new, updates, or duplicates',
269 'syndicated_posts:static_meta_data' => 'providing meta-data about syndicated posts in the Edit Posts interface',
270 ),
271 ), $page);
272
273 foreach ($fields as $section => $items) :
274 foreach ($items as $key => $label) :
275 $checked[$key] = '';
276 endforeach;
277 endforeach;
278
279 $diagnostics_show = get_option('feedwordpress_diagnostics_show', array());
280 if (is_array($diagnostics_show)) : foreach ($diagnostics_show as $thingy) :
281 $checked[$thingy] = ' checked="checked"';
282 endforeach; endif;
283
284 // Hey ho, let's go...
285 ?>
286 <table class="edit-form">
287 <?php foreach ($fields as $section => $ul) : ?>
288 <tr>
289 <th scope="row"><?php print esc_html($section); ?>:</th>
290 <td><p>Show a diagnostic message...</p>
291 <ul class="options">
292 <?php foreach ($ul as $key => $label) : ?>
293 <li><label><input
294 type="checkbox" name="diagnostics_show[]"
295 value="<?php print esc_html($key); ?>"
296 <?php print $checked[$key]; ?> />
297 <?php print $label; ?></label></li>
298 <?php endforeach; ?>
299 </ul></td>
300 </tr>
301 <?php endforeach; ?>
302 </table>
303 <?php
304 } /* FeedWordPressDiagnosticsPage::updates_box () */
305
306 function tests_box ($page, $box = NULL) {
307 ?>
308 <script type="text/javascript">
309 function clone_http_test_args_keyvalue_prototype () {
310 var next = jQuery('#http-test-args').find('.http-test-args-keyvalue').length;
311 var newRow = jQuery('#http-test-args-keyvalue-prototype').clone().attr('id', 'http-test-args-keyvalue-' + next);
312 newRow.find('.http_test_args_key').attr('name', 'http_test_args_key['+next+']').val('');
313 newRow.find('.http_test_args_value').attr('name', 'http_test_args_value['+next+']').val('');
314
315 newRow.appendTo('#http-test-args');
316 return false;
317 }
318 </script>
319
320 <table class="edit-form">
321 <tr>
322 <th scope="row">HTTP:</th>
323 <td><div><input type="url" name="http_test_url" value="" placeholder="http://www.example.com/" size="127" style="width: 80%; max-width: 80.0em;" />
324 <input type="submit" name="feedwordpress_diagnostics_do[http_test]" value="Test &raquo;" /></div>
325 <div><select name="http_test_method" size="1">
326 <option value="wp_remote_request">wp_remote_request</option>
327 <option value="FeedWordPress_File">FeedWordPress_File</option>
328 </select></div>
329 <table>
330 <tr>
331 <td>
332 <div id="http-test-args">
333 <div id="http-test-args-keyvalue-prototype" class="http-test-args-keyvalue"><label>Args:
334 <input type="text" class='http_test_args_key' name="http_test_args_key[0]" value="" placeholder="key" /></label>
335 <label>= <input type="text" class='http_test_args_value' name="http_test_args_value[0]" value="" placeholder="value" /></label>
336 </div>
337 </div>
338 </td>
339 <td><a href="#http-test-args" onclick="return clone_http_test_args_keyvalue_prototype();">+ Add</a></td>
340 </tr>
341 </table>
342
343 <?php if (isset($page->test_html['http_test'])) : ?>
344 <div style="position: relative">
345 <div style="width: 100%; overflow: scroll; background-color: #eed">
346 <pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -o-pre-wrap;"><?php print $page->test_html['http_test']; ?></pre>
347 </div>
348 </div>
349 <?php endif; ?>
350 </td>
351 </tr>
352 </table>
353
354 <?php
355 } /* FeedWordPressDiagnosticsPage::tests_box () */
356
357 var $test_html;
358 function do_http_test ($post) {
359 if (isset($post['http_test_url']) and isset($post['http_test_method'])) :
360 $url = $post['http_test_url'];
361
362 $args = array();
363 if (isset($post['http_test_args_key'])) :
364 foreach ($post['http_test_args_key'] as $idx => $name) :
365 $name = trim($name);
366 if (strlen($name) > 0) :
367 $value = NULL;
368 if (isset($post['http_test_args_value'])
369 and isset($post['http_test_args_value'][$idx])) :
370 $value = $post['http_test_args_value'][$idx];
371 endif;
372
373 if (preg_match('/^javascript:(.*)$/i', $value, $refs)) :
374 if (function_exists('json_decode')) :
375 $json_value = json_decode($refs[1]);
376 if (!is_null($json_value)) :
377 $value = $json_value;
378 endif;
379 endif;
380 endif;
381
382 $args[$name] = $value;
383 endif;
384 endforeach;
385 endif;
386
387 switch ($post['http_test_method']) :
388 case 'wp_remote_request' :
389 $out = wp_remote_request($url, $args);
390 break;
391 case 'FeedWordPress_File' :
392 $out = new FeedWordPress_File($url);
393 break;
394 endswitch;
395
396 $this->test_html['http_test'] = esc_html(FeedWordPress::val($out));
397 endif;
398 } /* FeedWordPressDiagnosticsPage::do_http_test () */
399
400 } /* class FeedWordPressDiagnosticsPage */
401
402 $diagnosticsPage = new FeedWordPressDiagnosticsPage;
403 $diagnosticsPage->display();
404
405