| 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 |
$this->updated = true; // Default update message |
| 86 |
endif; |
| 87 |
} /* FeedWordPressDiagnosticsPage::accept_POST () */ |
| 88 |
|
| 89 |
/*static*/ function diagnostics_box ($page, $box = NULL) { |
| 90 |
$settings = array(); |
| 91 |
$settings['debug'] = (get_option('feedwordpress_debug')=='yes'); |
| 92 |
|
| 93 |
$diagnostics_output = get_option('feedwordpress_diagnostics_output', array()); |
| 94 |
|
| 95 |
// Hey ho, let's go... |
| 96 |
?> |
| 97 |
<table class="edit-form"> |
| 98 |
<tr style="vertical-align: top"> |
| 99 |
<th scope="row">Debugging mode:</th> |
| 100 |
<td><select name="feedwordpress_debug" size="1"> |
| 101 |
<option value="yes"<?php echo ($settings['debug'] ? ' selected="selected"' : ''); ?>>on</option> |
| 102 |
<option value="no"<?php echo ($settings['debug'] ? '' : ' selected="selected"'); ?>>off</option> |
| 103 |
</select> |
| 104 |
|
| 105 |
<p>When debugging mode is <strong>ON</strong>, FeedWordPress displays many |
| 106 |
diagnostic error messages, warnings, and notices that are ordinarily suppressed, |
| 107 |
and turns off all caching of feeds. Use with caution: this setting is useful for |
| 108 |
testing but absolutely inappropriate for a production server.</p> |
| 109 |
|
| 110 |
</td> |
| 111 |
</tr> |
| 112 |
<tr> |
| 113 |
<th scope="row">Diagnostics output:</th> |
| 114 |
<td><ul class="options"> |
| 115 |
<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> |
| 116 |
<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> |
| 117 |
<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> |
| 118 |
<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> |
| 119 |
<li><input type="checkbox" name="diagnostics_output[]" value="email" <?php print (in_array('email', $diagnostics_output) ? ' checked="checked"' : ''); ?> /> Send a daily email digest to the site administrator</label></li> |
| 120 |
</ul></td> |
| 121 |
</tr> |
| 122 |
</table> |
| 123 |
<?php |
| 124 |
} /* FeedWordPressDiagnosticsPage::diagnostics_box () */ |
| 125 |
|
| 126 |
/*static*/ function updates_box ($page, $box = NULL) { |
| 127 |
$checked = array( |
| 128 |
'updated_feeds' => '', 'updated_feeds:errors' => '', |
| 129 |
'updated_feeds:errors:persistent' => '', |
| 130 |
"syndicated_posts" => '', 'syndicated_posts:meta_data' => '', |
| 131 |
'feed_items' => '', |
| 132 |
'memory_usage' => '', |
| 133 |
); |
| 134 |
|
| 135 |
$diagnostics_show = get_option('feedwordpress_diagnostics_show', array()); |
| 136 |
if (is_array($diagnostics_show)) : foreach ($diagnostics_show as $thingy) : |
| 137 |
$checked[$thingy] = ' checked="checked"'; |
| 138 |
endforeach; endif; |
| 139 |
|
| 140 |
// Hey ho, let's go... |
| 141 |
?> |
| 142 |
<table class="edit-form"> |
| 143 |
<tr> |
| 144 |
<th scope="row">Update diagnostics:</th> |
| 145 |
<td><p>Show a diagnostic message...</p> |
| 146 |
<ul class="options"> |
| 147 |
<li><label><input type="checkbox" name="diagnostics_show[]" value="updated_feeds" <?php print $checked['updated_feeds']; ?> /> as each feed checked for updates</label></li> |
| 148 |
<li><label><input type="checkbox" name="diagnostics_show[]" value="updated_feeds:errors:persistent" <?php print $checked['updated_feeds:errors:persistent'] ?> /> when FeedWordPress encounters repeated errors while checking a feed for updates</label></li> |
| 149 |
<li><label><input type="checkbox" name="diagnostics_show[]" value="updated_feeds:errors" <?php print $checked['updated_feeds:errors']; ?> /> any time FeedWordPress encounters any errors while checking a feed for updates</label></li> |
| 150 |
<li><label><input type="checkbox" name="diagnostics_show[]" value="syndicated_posts" <?php print $checked['syndicated_posts']; ?> /> as each syndicated post is added to the database</label></li> |
| 151 |
<li><label><input type="checkbox" name="diagnostics_show[]" value="feed_items" <?php print $checked['feed_items']; ?> /> as each syndicated item is considered on the feed</label></li> |
| 152 |
<li><label><input type="checkbox" name="diagnostics_show[]" value="memory_usage" <?php print $checked['memory_usage']; ?> /> indicating how much memory was used</label></li> |
| 153 |
</ul></td> |
| 154 |
</tr> |
| 155 |
<tr> |
| 156 |
<th>Syndicated post details:</th> |
| 157 |
<td><p>Show a diagnostic message...</p> |
| 158 |
<ul class="options"> |
| 159 |
<li><label><input type="checkbox" name="diagnostics_show[]" value="syndicated_posts:meta_data" <?php print $checked['syndicated_posts:meta_data']; ?> /> as syndication meta-data is added on the post</label></li> |
| 160 |
</ul></td> |
| 161 |
</tr> |
| 162 |
</table> |
| 163 |
<?php |
| 164 |
} /* FeedWordPressDiagnosticsPage::updates_box () */ |
| 165 |
} /* class FeedWordPressDiagnosticsPage */ |
| 166 |
|
| 167 |
$diagnosticsPage = new FeedWordPressDiagnosticsPage; |
| 168 |
$diagnosticsPage->display(); |
| 169 |
|
| 170 |
|