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

233 lines 9.0 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 'diagnostics_box' => __('Diagnostics'),
43 'updates_box' => __('Updates'),
44 );
45
46 foreach ($boxes_by_methods as $method => $title) :
47 add_meta_box(
48 /*id=*/ 'feedwordpress_'.$method,
49 /*title=*/ $title,
50 /*callback=*/ array('FeedWordPressDiagnosticsPage', $method),
51 /*page=*/ $this->meta_box_context(),
52 /*context=*/ $this->meta_box_context()
53 );
54 endforeach;
55 do_action('feedwordpress_admin_page_diagnostics_meta_boxes', $this);
56 ?>
57 <div class="metabox-holder">
58 <?php
59 fwp_do_meta_boxes($this->meta_box_context(), $this->meta_box_context(), $this);
60 ?>
61 </div> <!-- class="metabox-holder" -->
62 </div> <!-- id="post-body" -->
63
64 <?php
65 $this->close_sheet();
66 } /* FeedWordPressDiagnosticsPage::display () */
67
68 function accept_POST ($post) {
69 if (isset($post['submit'])
70 or isset($post['save'])) :
71 update_option('feedwordpress_debug', $post['feedwordpress_debug']);
72
73 if (!isset($post['diagnostics_output'])
74 or !is_array($post['diagnostics_output'])) :
75 $post['diagnostics_output'] = array();
76 endif;
77 update_option('feedwordpress_diagnostics_output', $post['diagnostics_output']);
78
79 if (!isset($post['diagnostics_show'])
80 or !is_array($post['diagnostics_show'])) :
81 $post['diagnostics_show'] = array();
82 endif;
83 update_option('feedwordpress_diagnostics_show', $post['diagnostics_show']);
84
85 if ($post['diagnostics_show']
86 and in_array('updated_feeds:errors:persistent', $post['diagnostics_show'])) :
87 update_option('feedwordpress_diagnostics_persistent_errors_hours', (int) $post['diagnostics_persistent_error_hours']);
88 else :
89 delete_option('feedwordpress_diagnostics_persistent_errors_hours');
90 endif;
91
92 if (in_array('email', $post['diagnostics_output'])) :
93 $ded = $post['diagnostics_email_destination'];
94 if ('mailto'==$ded) :
95 $ded .= ':'.$post['diagnostics_email_destination_address'];
96 endif;
97
98 update_option('feedwordpress_diagnostics_email_destination', $ded);
99 else :
100 delete_option('feedwordpress_diagnostics_email_destination');
101 endif;
102
103 $this->updated = true; // Default update message
104 endif;
105 } /* FeedWordPressDiagnosticsPage::accept_POST () */
106
107 /*static*/ function diagnostics_box ($page, $box = NULL) {
108 $settings = array();
109 $settings['debug'] = (get_option('feedwordpress_debug')=='yes');
110
111 $diagnostics_output = get_option('feedwordpress_diagnostics_output', array());
112
113 $users = fwp_author_list();
114
115 $ded = get_option('feedwordpress_diagnostics_email_destination', 'admins');
116
117 if (preg_match('/^mailto:(.*)$/', $ded, $ref)) :
118 $ded_addy = $ref[1];
119 else :
120 $ded_addy = NULL;
121 endif;
122
123 // Hey ho, let's go...
124 ?>
125 <table class="edit-form">
126 <tr style="vertical-align: top">
127 <th scope="row">Debugging mode:</th>
128 <td><select name="feedwordpress_debug" size="1">
129 <option value="yes"<?php echo ($settings['debug'] ? ' selected="selected"' : ''); ?>>on</option>
130 <option value="no"<?php echo ($settings['debug'] ? '' : ' selected="selected"'); ?>>off</option>
131 </select>
132
133 <p>When debugging mode is <strong>ON</strong>, FeedWordPress displays many
134 diagnostic error messages, warnings, and notices that are ordinarily suppressed,
135 and turns off all caching of feeds. Use with caution: this setting is useful for
136 testing but absolutely inappropriate for a production server.</p>
137
138 </td>
139 </tr>
140 <tr>
141 <th scope="row">Diagnostics output:</th>
142 <td><ul class="options">
143 <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>
144 <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>
145 <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>
146 <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>
147 <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">
148 <option value="admins"<?php if ('admins'==$ded) : ?> selected="selected"<?php endif; ?>>the site administrators</option>
149 <?php foreach ($users as $id => $name) : ?>
150 <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>
151 <?php endforeach; ?>
152 <option value="mailto"<?php if (!is_null($ded_addy)) : ?> selected="selected"<?php endif; ?>>another e-mail address...</option>
153 </select>
154 <input type="email" id="diagnostics-email-destination-address" name="diagnostics_email_destination_address" value="<?php print $ded_addy; ?>" placeholder="email address" /></li>
155 </ul></td>
156 </tr>
157 </table>
158
159 <script type="text/javascript">
160 contextual_appearance(
161 'diagnostics-email-destination',
162 'diagnostics-email-destination-address',
163 'diagnostics-email-destination-default',
164 'mailto',
165 'inline'
166 );
167 jQuery('#diagnostics-email-destination').change ( function () {
168 contextual_appearance(
169 'diagnostics-email-destination',
170 'diagnostics-email-destination-address',
171 'diagnostics-email-destination-default',
172 'mailto',
173 'inline'
174 );
175 } );
176 </script>
177 <?php
178 } /* FeedWordPressDiagnosticsPage::diagnostics_box () */
179
180 /*static*/ function updates_box ($page, $box = NULL) {
181 $hours = get_option('feedwordpress_diagnostics_persistent_errors_hours', 2);
182 $fields = apply_filters('feedwordpress_diagnostics', array(
183 'Update Diagnostics' => array(
184 'updated_feeds' => 'as each feed checked for updates',
185 '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',
186 'updated_feeds:errors' => 'any time FeedWordPress encounters any errors while checking a feed for updates',
187 'syndicated_posts' => 'as each syndicated post is added to the database',
188 'feed_items' => 'as each syndicated item is considered on the feed',
189 'memory_usage' => 'indicating how much memory was used',
190 ),
191 'Syndicated Post Details' => array(
192 'syndicated_posts:meta_data' => 'as syndication meta-data is added on the post',
193 ),
194 ), $page);
195
196 foreach ($fields as $section => $items) :
197 foreach ($items as $key => $label) :
198 $checked[$key] = '';
199 endforeach;
200 endforeach;
201
202 $diagnostics_show = get_option('feedwordpress_diagnostics_show', array());
203 if (is_array($diagnostics_show)) : foreach ($diagnostics_show as $thingy) :
204 $checked[$thingy] = ' checked="checked"';
205 endforeach; endif;
206
207 // Hey ho, let's go...
208 ?>
209 <table class="edit-form">
210 <?php foreach ($fields as $section => $ul) : ?>
211 <tr>
212 <th scope="row"><?php print esc_html($section); ?>:</th>
213 <td><p>Show a diagnostic message...</p>
214 <ul class="options">
215 <?php foreach ($ul as $key => $label) : ?>
216 <li><label><input
217 type="checkbox" name="diagnostics_show[]"
218 value="<?php print esc_html($key); ?>"
219 <?php print $checked[$key]; ?> />
220 <?php print $label; ?></label></li>
221 <?php endforeach; ?>
222 </ul></td>
223 </tr>
224 <?php endforeach; ?>
225 </table>
226 <?php
227 } /* FeedWordPressDiagnosticsPage::updates_box () */
228 } /* class FeedWordPressDiagnosticsPage */
229
230 $diagnosticsPage = new FeedWordPressDiagnosticsPage;
231 $diagnosticsPage->display();
232
233