| 1 |
<?php |
| 2 |
/** |
| 3 |
* class FeedWordPressDiagnostic: help to organize some diagnostics output functions. |
| 4 |
*/ |
| 5 |
class FeedWordPressDiagnostic { |
| 6 |
public static function feed_error ($error, $old, $link) { |
| 7 |
$wpError = $error['object']; |
| 8 |
$url = $link->uri(); |
| 9 |
|
| 10 |
// check for effects of an effective-url filter |
| 11 |
$effectiveUrl = $link->uri(array('fetch' => true)); |
| 12 |
if ($url != $effectiveUrl) : $url .= ' | ' . $effectiveUrl; endif; |
| 13 |
|
| 14 |
$mesgs = $wpError->get_error_messages(); |
| 15 |
foreach ($mesgs as $mesg) : |
| 16 |
$mesg = esc_html($mesg); |
| 17 |
FeedWordPress::diagnostic( |
| 18 |
'updated_feeds:errors', |
| 19 |
"Feed Error: [${url}] update returned error: $mesg" |
| 20 |
); |
| 21 |
|
| 22 |
$hours = get_option('feedwordpress_diagnostics_persistent_errors_hours', 2); |
| 23 |
$span = ($error['ts'] - $error['since']); |
| 24 |
|
| 25 |
if ($span >= ($hours * 60 * 60)) : |
| 26 |
$since = date('r', $error['since']); |
| 27 |
$mostRecent = date('r', $error['ts']); |
| 28 |
FeedWordPress::diagnostic( |
| 29 |
'updated_feeds:errors:persistent', |
| 30 |
"Feed Update Error: [${url}] returning errors" |
| 31 |
." since ${since}:<br/><code>$mesg</code>", |
| 32 |
$url, $error['since'], $error['ts'] |
| 33 |
); |
| 34 |
endif; |
| 35 |
endforeach; |
| 36 |
} |
| 37 |
|
| 38 |
public static function admin_emails ($id = '') { |
| 39 |
$users = get_users_of_blog($id); |
| 40 |
$recipients = array(); |
| 41 |
foreach ($users as $user) : |
| 42 |
$user_id = (isset($user->user_id) ? $user->user_id : $user->ID); |
| 43 |
$dude = new WP_User($user_id); |
| 44 |
if ($dude->has_cap('administrator')) : |
| 45 |
if ($dude->user_email) : |
| 46 |
$recipients[] = $dude->user_email; |
| 47 |
endif; |
| 48 |
endif; |
| 49 |
endforeach; |
| 50 |
return $recipients; |
| 51 |
} |
| 52 |
|
| 53 |
public static function noncritical_bug ($varname, $var, $line, $file = NULL) { |
| 54 |
if (FEEDWORDPRESS_DEBUG) : // halt only when we are doing debugging |
| 55 |
self::critical_bug($varname, $var, $line, $file); |
| 56 |
endif; |
| 57 |
} /* FeedWordPressDiagnostic::noncritical_bug () */ |
| 58 |
|
| 59 |
public static function critical_bug ($varname, $var, $line, $file = NULL) { |
| 60 |
global $wp_version; |
| 61 |
|
| 62 |
if (!is_null($file)) : |
| 63 |
$location = "line # ${line} of ".basename($file); |
| 64 |
else : |
| 65 |
$location = "line # ${line}"; |
| 66 |
endif; |
| 67 |
|
| 68 |
print '<p><strong>Critical error:</strong> There may be a bug in FeedWordPress. Please <a href="'.FEEDWORDPRESS_AUTHOR_CONTACT.'">contact the author</a> and paste the following information into your e-mail:</p>'; |
| 69 |
print "\n<plaintext>"; |
| 70 |
print "Triggered at ${location}\n"; |
| 71 |
print "FeedWordPress: ".FEEDWORDPRESS_VERSION."\n"; |
| 72 |
print "WordPress: {$wp_version}\n"; |
| 73 |
print "PHP: ".phpversion()."\n"; |
| 74 |
print "Error data: "; |
| 75 |
print $varname.": "; var_dump($var); echo "\n"; |
| 76 |
die; |
| 77 |
} /* FeedWordPressDiagnostic::critical_bug () */ |
| 78 |
|
| 79 |
public static function is_on ($level) { |
| 80 |
$show = get_option('feedwordpress_diagnostics_show', array()); |
| 81 |
return (in_array($level, $show)); |
| 82 |
} /* FeedWordPressDiagnostic::is_on () */ |
| 83 |
|
| 84 |
} /* class FeedWordPressDiagnostic */ |
| 85 |
|