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

282 lines 10.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
74 if (!isset($post['diagnostics_output'])
75 or !is_array($post['diagnostics_output'])) :
76 $post['diagnostics_output'] = array();
77 endif;
78 update_option('feedwordpress_diagnostics_output', $post['diagnostics_output']);
79
80 if (!isset($post['diagnostics_show'])
81 or !is_array($post['diagnostics_show'])) :
82 $post['diagnostics_show'] = array();
83 endif;
84 update_option('feedwordpress_diagnostics_show', $post['diagnostics_show']);
85
86 if ($post['diagnostics_show']
87 and in_array('updated_feeds:errors:persistent', $post['diagnostics_show'])) :
88 update_option('feedwordpress_diagnostics_persistent_errors_hours', (int) $post['diagnostics_persistent_error_hours']);
89 else :
90 delete_option('feedwordpress_diagnostics_persistent_errors_hours');
91 endif;
92
93 if (in_array('email', $post['diagnostics_output'])) :
94 $ded = $post['diagnostics_email_destination'];
95 if ('mailto'==$ded) :
96 $ded .= ':'.$post['diagnostics_email_destination_address'];
97 endif;
98
99 update_option('feedwordpress_diagnostics_email_destination', $ded);
100 else :
101 delete_option('feedwordpress_diagnostics_email_destination');
102 endif;
103
104 $this->updated = true; // Default update message
105 endif;
106 } /* FeedWordPressDiagnosticsPage::accept_POST () */
107
108 function info_box ($page, $box = NULL) {
109 $link_category_id = FeedWordPress::link_category_id();
110 ?>
111 <table class="edit-form narrow">
112 <thead style="display: none">
113 <th scope="col">Topic</th>
114 <th scope="col">Information</th>
115 </thead>
116
117 <tbody>
118 <tr>
119 <th scope="row">Version:</th>
120 <td>You are using FeedWordPress version <strong><?php print FEEDWORDPRESS_VERSION; ?></strong>.</td>
121 </tr>
122
123 <tr>
124 <th scope="row">Link Category:</th>
125 <td><?php if (!is_wp_error($link_category_id)) :
126 $term = get_term($link_category_id, 'link_category');
127 ?><p>Syndicated feeds are
128 kept in link category #<?php print $term->term_id; ?>, <strong><?php print $term->name; ?></strong>.</p>
129 <?php else : ?>
130 <p><strong>FeedWordPress has been unable to set up a valid Link Category
131 for syndicated feeds.</strong> Attempting to set one up returned an
132 <code><?php $link_category_id->get_error_code(); ?></code> error with this
133 additional data:</p>
134 <table>
135 <tbody>
136 <tr>
137 <th scope="row">Message:</th>
138 <td><?php print $link_category_id->get_error_message(); ?></td>
139 </tr>
140 <?php $data = $link_category_id->get_error_data(); if (!empty($data)) : ?>
141 <tr>
142 <th scope="row">Auxiliary Data:</th>
143 <td><pre><?php print esc_html(FeedWordPress::val($link_category_id->get_error_data())); ?></pre></td>
144 </tr>
145 <?php endif; ?>
146 </table>
147 <?php endif; ?></td>
148 </tr>
149 </table>
150
151 <?php
152 } /* FeedWordPressDiagnosticsPage::info_box () */
153
154 function diagnostics_box ($page, $box = NULL) {
155 $settings = array();
156 $settings['debug'] = (get_option('feedwordpress_debug')=='yes');
157
158 $diagnostics_output = get_option('feedwordpress_diagnostics_output', array());
159
160 $users = fwp_author_list();
161
162 $ded = get_option('feedwordpress_diagnostics_email_destination', 'admins');
163
164 if (preg_match('/^mailto:(.*)$/', $ded, $ref)) :
165 $ded_addy = $ref[1];
166 else :
167 $ded_addy = NULL;
168 endif;
169
170 // Hey ho, let's go...
171 ?>
172 <table class="edit-form">
173 <tr style="vertical-align: top">
174 <th scope="row">Debugging mode:</th>
175 <td><select name="feedwordpress_debug" size="1">
176 <option value="yes"<?php echo ($settings['debug'] ? ' selected="selected"' : ''); ?>>on</option>
177 <option value="no"<?php echo ($settings['debug'] ? '' : ' selected="selected"'); ?>>off</option>
178 </select>
179
180 <p>When debugging mode is <strong>ON</strong>, FeedWordPress displays many
181 diagnostic error messages, warnings, and notices that are ordinarily suppressed,
182 and turns off all caching of feeds. Use with caution: this setting is useful for
183 testing but absolutely inappropriate for a production server.</p>
184
185 </td>
186 </tr>
187 <tr>
188 <th scope="row">Diagnostics output:</th>
189 <td><ul class="options">
190 <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>
191 <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>
192 <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>
193 <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>
194 <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">
195 <option value="admins"<?php if ('admins'==$ded) : ?> selected="selected"<?php endif; ?>>the site administrators</option>
196 <?php foreach ($users as $id => $name) : ?>
197 <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>
198 <?php endforeach; ?>
199 <option value="mailto"<?php if (!is_null($ded_addy)) : ?> selected="selected"<?php endif; ?>>another e-mail address...</option>
200 </select>
201 <input type="email" id="diagnostics-email-destination-address" name="diagnostics_email_destination_address" value="<?php print $ded_addy; ?>" placeholder="email address" /></li>
202 </ul></td>
203 </tr>
204 </table>
205
206 <script type="text/javascript">
207 contextual_appearance(
208 'diagnostics-email-destination',
209 'diagnostics-email-destination-address',
210 'diagnostics-email-destination-default',
211 'mailto',
212 'inline'
213 );
214 jQuery('#diagnostics-email-destination').change ( function () {
215 contextual_appearance(
216 'diagnostics-email-destination',
217 'diagnostics-email-destination-address',
218 'diagnostics-email-destination-default',
219 'mailto',
220 'inline'
221 );
222 } );
223 </script>
224 <?php
225 } /* FeedWordPressDiagnosticsPage::diagnostics_box () */
226
227 /*static*/ function updates_box ($page, $box = NULL) {
228 $hours = get_option('feedwordpress_diagnostics_persistent_errors_hours', 2);
229 $fields = apply_filters('feedwordpress_diagnostics', array(
230 'Update Diagnostics' => array(
231 'updated_feeds' => 'as each feed is checked for updates',
232 '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',
233 'updated_feeds:errors' => 'any time FeedWordPress encounters any errors while checking a feed for updates',
234 'syndicated_posts' => 'as each syndicated post is added to the database',
235 'feed_items' => 'as each syndicated item is considered on the feed',
236 'memory_usage' => 'indicating how much memory was used',
237 ),
238 'Syndicated Post Details' => array(
239 'feed_items:freshness' => 'as FeedWordPress decides whether to treat an item as a new post, an update, or a duplicate of an existing post',
240 'feed_items:rejected' => 'when FeedWordPress rejects a post without syndicating it',
241 'syndicated_posts:meta_data' => 'as syndication meta-data is added on the post',
242 ),
243 ), $page);
244
245 foreach ($fields as $section => $items) :
246 foreach ($items as $key => $label) :
247 $checked[$key] = '';
248 endforeach;
249 endforeach;
250
251 $diagnostics_show = get_option('feedwordpress_diagnostics_show', array());
252 if (is_array($diagnostics_show)) : foreach ($diagnostics_show as $thingy) :
253 $checked[$thingy] = ' checked="checked"';
254 endforeach; endif;
255
256 // Hey ho, let's go...
257 ?>
258 <table class="edit-form">
259 <?php foreach ($fields as $section => $ul) : ?>
260 <tr>
261 <th scope="row"><?php print esc_html($section); ?>:</th>
262 <td><p>Show a diagnostic message...</p>
263 <ul class="options">
264 <?php foreach ($ul as $key => $label) : ?>
265 <li><label><input
266 type="checkbox" name="diagnostics_show[]"
267 value="<?php print esc_html($key); ?>"
268 <?php print $checked[$key]; ?> />
269 <?php print $label; ?></label></li>
270 <?php endforeach; ?>
271 </ul></td>
272 </tr>
273 <?php endforeach; ?>
274 </table>
275 <?php
276 } /* FeedWordPressDiagnosticsPage::updates_box () */
277 } /* class FeedWordPressDiagnosticsPage */
278
279 $diagnosticsPage = new FeedWordPressDiagnosticsPage;
280 $diagnosticsPage->display();
281
282