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