PluginProbe
FeedWordPress / 2011.0721
FeedWordPress v2011.0721
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 2011.0721, at diagnostics-page.php

297 lines 11.7 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
12 function has_link () { return false; }
13
14 function display () {
15 global $wpdb, $wp_db_version, $fwp_path;
16 global $fwp_post;
17
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($fwp_post);
28 do_action('feedwordpress_admin_page_diagnostics_save', $GLOBALS['fwp_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 );
46
47 foreach ($boxes_by_methods as $method => $title) :
48 add_meta_box(
49 /*id=*/ 'feedwordpress_'.$method,
50 /*title=*/ $title,
51 /*callback=*/ array('FeedWordPressDiagnosticsPage', $method),
52 /*page=*/ $this->meta_box_context(),
53 /*context=*/ $this->meta_box_context()
54 );
55 endforeach;
56 do_action('feedwordpress_admin_page_diagnostics_meta_boxes', $this);
57 ?>
58 <div class="metabox-holder">
59 <?php
60 fwp_do_meta_boxes($this->meta_box_context(), $this->meta_box_context(), $this);
61 ?>
62 </div> <!-- class="metabox-holder" -->
63 </div> <!-- id="post-body" -->
64
65 <?php
66 $this->close_sheet();
67 } /* FeedWordPressDiagnosticsPage::display () */
68
69 function accept_POST ($post) {
70 if (isset($post['submit'])
71 or isset($post['save'])) :
72 update_option('feedwordpress_debug', $post['feedwordpress_debug']);
73 update_option('feedwordpress_secret_key', $post['feedwordpress_secret_key']);
74
75 if (!isset($post['diagnostics_output'])
76 or !is_array($post['diagnostics_output'])) :
77 $post['diagnostics_output'] = array();
78 endif;
79 update_option('feedwordpress_diagnostics_output', $post['diagnostics_output']);
80
81 if (!isset($post['diagnostics_show'])
82 or !is_array($post['diagnostics_show'])) :
83 $post['diagnostics_show'] = array();
84 endif;
85 update_option('feedwordpress_diagnostics_show', $post['diagnostics_show']);
86
87 if ($post['diagnostics_show']
88 and in_array('updated_feeds:errors:persistent', $post['diagnostics_show'])) :
89 update_option('feedwordpress_diagnostics_persistent_errors_hours', (int) $post['diagnostics_persistent_error_hours']);
90 else :
91 delete_option('feedwordpress_diagnostics_persistent_errors_hours');
92 endif;
93
94 if (in_array('email', $post['diagnostics_output'])) :
95 $ded = $post['diagnostics_email_destination'];
96 if ('mailto'==$ded) :
97 $ded .= ':'.$post['diagnostics_email_destination_address'];
98 endif;
99
100 update_option('feedwordpress_diagnostics_email_destination', $ded);
101 else :
102 delete_option('feedwordpress_diagnostics_email_destination');
103 endif;
104
105 $this->updated = true; // Default update message
106 endif;
107 } /* FeedWordPressDiagnosticsPage::accept_POST () */
108
109 function info_box ($page, $box = NULL) {
110 global $feedwordpress;
111 $link_category_id = FeedWordPress::link_category_id();
112 ?>
113 <table class="edit-form narrow">
114 <thead style="display: none">
115 <th scope="col">Topic</th>
116 <th scope="col">Information</th>
117 </thead>
118
119 <tbody>
120 <tr>
121 <th scope="row">Version:</th>
122 <td>You are using FeedWordPress version <strong><?php print FEEDWORDPRESS_VERSION; ?></strong>.</td>
123 </tr>
124
125 <tr>
126 <th scope="row">Link Category:</th>
127 <td><?php if (!is_wp_error($link_category_id)) :
128 $term = get_term($link_category_id, 'link_category');
129 ?><p>Syndicated feeds are
130 kept in link category #<?php print $term->term_id; ?>, <strong><?php print $term->name; ?></strong>.</p>
131 <?php else : ?>
132 <p><strong>FeedWordPress has been unable to set up a valid Link Category
133 for syndicated feeds.</strong> Attempting to set one up returned an
134 <code><?php $link_category_id->get_error_code(); ?></code> error with this
135 additional data:</p>
136 <table>
137 <tbody>
138 <tr>
139 <th scope="row">Message:</th>
140 <td><?php print $link_category_id->get_error_message(); ?></td>
141 </tr>
142 <?php $data = $link_category_id->get_error_data(); if (!empty($data)) : ?>
143 <tr>
144 <th scope="row">Auxiliary Data:</th>
145 <td><pre><?php print esc_html(FeedWordPress::val($link_category_id->get_error_data())); ?></pre></td>
146 </tr>
147 <?php endif; ?>
148 </table>
149 <?php endif; ?></td>
150 </tr>
151
152 <tr>
153 <th scope="row"><?php _e('Secret Key:'); ?></th>
154 <td><input type="text" name="feedwordpress_secret_key" value="<?php print esc_attr($feedwordpress->secret_key()); ?>" />
155 <p class="setting-description">This is used to control access to some diagnostic testing functions. You can change it to any string you want,
156 but only tell it to people you trust to help you troubleshoot your
157 FeedWordPress installation. Keep it secret&#8212;keep it safe.</p></td>
158 </tr>
159 </table>
160
161 <?php
162 } /* FeedWordPressDiagnosticsPage::info_box () */
163
164 function diagnostics_box ($page, $box = NULL) {
165 $settings = array();
166 $settings['debug'] = (get_option('feedwordpress_debug')=='yes');
167
168 $diagnostics_output = get_option('feedwordpress_diagnostics_output', array());
169
170 $users = fwp_author_list();
171
172 $ded = get_option('feedwordpress_diagnostics_email_destination', 'admins');
173
174 if (preg_match('/^mailto:(.*)$/', $ded, $ref)) :
175 $ded_addy = $ref[1];
176 else :
177 $ded_addy = NULL;
178 endif;
179
180 // Hey ho, let's go...
181 ?>
182 <table class="edit-form">
183 <tr style="vertical-align: top">
184 <th scope="row">Debugging mode:</th>
185 <td><select name="feedwordpress_debug" size="1">
186 <option value="yes"<?php echo ($settings['debug'] ? ' selected="selected"' : ''); ?>>on</option>
187 <option value="no"<?php echo ($settings['debug'] ? '' : ' selected="selected"'); ?>>off</option>
188 </select>
189
190 <p>When debugging mode is <strong>ON</strong>, FeedWordPress displays many
191 diagnostic error messages, warnings, and notices that are ordinarily suppressed,
192 and turns off all caching of feeds. Use with caution: this setting is useful for
193 testing but absolutely inappropriate for a production server.</p>
194
195 </td>
196 </tr>
197 <tr>
198 <th scope="row">Diagnostics output:</th>
199 <td><ul class="options">
200 <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>
201 <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>
202 <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>
203 <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>
204 <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">
205 <option value="admins"<?php if ('admins'==$ded) : ?> selected="selected"<?php endif; ?>>the site administrators</option>
206 <?php foreach ($users as $id => $name) : ?>
207 <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>
208 <?php endforeach; ?>
209 <option value="mailto"<?php if (!is_null($ded_addy)) : ?> selected="selected"<?php endif; ?>>another e-mail address...</option>
210 </select>
211 <input type="email" id="diagnostics-email-destination-address" name="diagnostics_email_destination_address" value="<?php print $ded_addy; ?>" placeholder="email address" /></li>
212 </ul></td>
213 </tr>
214 </table>
215
216 <script type="text/javascript">
217 contextual_appearance(
218 'diagnostics-email-destination',
219 'diagnostics-email-destination-address',
220 'diagnostics-email-destination-default',
221 'mailto',
222 'inline'
223 );
224 jQuery('#diagnostics-email-destination').change ( function () {
225 contextual_appearance(
226 'diagnostics-email-destination',
227 'diagnostics-email-destination-address',
228 'diagnostics-email-destination-default',
229 'mailto',
230 'inline'
231 );
232 } );
233 </script>
234 <?php
235 } /* FeedWordPressDiagnosticsPage::diagnostics_box () */
236
237 /*static*/ function updates_box ($page, $box = NULL) {
238 $hours = get_option('feedwordpress_diagnostics_persistent_errors_hours', 2);
239 $fields = apply_filters('feedwordpress_diagnostics', array(
240 'Update Diagnostics' => array(
241 'update_schedule:check' => 'whenever a FeedWordPress checks in on the update schedule',
242 'updated_feeds' => 'as each feed is checked for updates',
243 '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',
244 'updated_feeds:errors' => 'any time FeedWordPress encounters any errors while checking a feed for updates',
245 'syndicated_posts' => 'as each syndicated post is added to the database',
246 'feed_items' => 'as each syndicated item is considered on the feed',
247 'memory_usage' => 'indicating how much memory was used',
248 ),
249 'Syndicated Post Details' => array(
250 'feed_items:freshness' => 'as FeedWordPress decides whether to treat an item as a new post, an update, or a duplicate of an existing post',
251 'feed_items:rejected' => 'when FeedWordPress rejects a post without syndicating it',
252 'syndicated_posts:meta_data' => 'as syndication meta-data is added on the post',
253 ),
254 'Advanced Diagnostics' => array(
255 'feed_items:freshness:sql' => 'when FeedWordPress issues the SQL query it uses to decide whether to treat items as new, updates, or duplicates',
256 'syndicated_posts:static_meta_data' => 'providing meta-data about syndicated posts in the Edit Posts interface',
257 ),
258 ), $page);
259
260 foreach ($fields as $section => $items) :
261 foreach ($items as $key => $label) :
262 $checked[$key] = '';
263 endforeach;
264 endforeach;
265
266 $diagnostics_show = get_option('feedwordpress_diagnostics_show', array());
267 if (is_array($diagnostics_show)) : foreach ($diagnostics_show as $thingy) :
268 $checked[$thingy] = ' checked="checked"';
269 endforeach; endif;
270
271 // Hey ho, let's go...
272 ?>
273 <table class="edit-form">
274 <?php foreach ($fields as $section => $ul) : ?>
275 <tr>
276 <th scope="row"><?php print esc_html($section); ?>:</th>
277 <td><p>Show a diagnostic message...</p>
278 <ul class="options">
279 <?php foreach ($ul as $key => $label) : ?>
280 <li><label><input
281 type="checkbox" name="diagnostics_show[]"
282 value="<?php print esc_html($key); ?>"
283 <?php print $checked[$key]; ?> />
284 <?php print $label; ?></label></li>
285 <?php endforeach; ?>
286 </ul></td>
287 </tr>
288 <?php endforeach; ?>
289 </table>
290 <?php
291 } /* FeedWordPressDiagnosticsPage::updates_box () */
292 } /* class FeedWordPressDiagnosticsPage */
293
294 $diagnosticsPage = new FeedWordPressDiagnosticsPage;
295 $diagnosticsPage->display();
296
297