Skip to content

Instantly share code, notes, and snippets.

@KeanePW
Created October 17, 2015 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KeanePW/71048d8fbd09598891fc to your computer and use it in GitHub Desktop.
Save KeanePW/71048d8fbd09598891fc to your computer and use it in GitHub Desktop.
Replaced the echo with return to stop the output from appearing at the top of the page
<?php defined('ABSPATH') or die("No script kiddies please!");
function uptime_robot_nh_widget( $atts ) {
$data = "<div class='table-responsive'><table width=\"100%\" class=\"table table-hover\"><tr>
<th style=\"text-align: left;\">". __('Monitor', 'uptime-robot-nh')."</th>";
if(get_option('uptime_robot_nh_columns_status') == 1){
$data .= "<th style=\"text-align: left;\">". __('Status', 'uptime-robot-nh')."</th>";
} if(get_option('uptime_robot_nh_columns_type') == 1){
$data .= "<th style=\"text-align: left;\">". __('Type', 'uptime-robot-nh')."</th>";
} $GetUptimes = ""; if(get_option('uptime_robot_nh_days_one') == 1){ $GetUptimes = $GetUptimes."1-";
$data .= "<th style=\"text-align: left;\">". __('Today', 'uptime-robot-nh')."</th>";
} if(get_option('uptime_robot_nh_days_week') == 1){ $GetUptimes = $GetUptimes."7-";
$data .= "<th style=\"text-align: left;\">". __('7 days', 'uptime-robot-nh')."</th>";
} if(get_option('uptime_robot_nh_days_month') == 1){ $GetUptimes = $GetUptimes."30-";
$data .= "<th style=\"text-align: left;\">". __('30 days', 'uptime-robot-nh')."</th>";
} if(get_option('uptime_robot_nh_days_year') == 1){ $GetUptimes = $GetUptimes."365-";
$data .= "<th style=\"text-align: left;\">". __('Last', 'uptime-robot-nh')." ". __('year', 'uptime-robot-nh')."</th>";
}
$data .= "</tr>";
if(get_option('uptime_robot_nh_api','m775657602-b342a2e5f04a0e7707981fe8') == ""){
$apiKey = "m775657602-b342a2e5f04a0e7707981fe8";
}else{
$apiKey = get_option('uptime_robot_nh_api','m775657602-b342a2e5f04a0e7707981fe8');
}
$atts = shortcode_atts( array( 'id' => 'all'), $atts);
if($atts['id'] == 'all'){ $monitorids = get_option('uptime_robot_nh_monitors'); }else{ $monitorids = $atts['id']; }
$url = "http://api.uptimerobot.com/getMonitors?apiKey=". $apiKey . "&customUptimeRatio=".substr($GetUptimes, 0, -1)."&format=xml&monitors=".$monitorids;
$xml = file_get_contents($url);
$xml = new SimpleXMLElement ($xml);
foreach($xml->monitor as $monitor) {
$data .= "<tr>";
$data .= "<td style=\"color: ".get_option('uptime_robot_nh_colors_font','#6B6B6B').";\">";
$data .= $monitor['friendlyname'];
$data .= "</td>";
if(get_option('uptime_robot_nh_columns_status') == 1){
$data .= "</td><td>";
if ($monitor['status'] == 2) {
$data .= "<div style=\"color: ".get_option('uptime_robot_nh_colors_online','#006600')."; font-weight:bold;\">". __('Online', 'uptime-robot-nh'). "</div>";
}
elseif ($monitor['status'] == 9) {
$data .= "<div style=\"color: ".get_option('uptime_robot_nh_colors_offline','#FF0000')."; font-weight:bold;\">". __('Offline', 'uptime-robot-nh'). "</div>";
}
elseif ($monitor['status'] == 0) {
_e('Paused', 'uptime-robot-nh');
}
else {
_e('n&#47a', 'uptime-robot-nh');
}
} if(get_option('uptime_robot_nh_columns_type') == 1){
$data .= "<td style=\"color: ".get_option('uptime_robot_nh_colors_font','#6B6B6B').";\">";
if ($monitor['type'] == 1) {
$data .= __('HTTP(s)', 'uptime-robot-nh'); $data .= "</td>";
}elseif ($monitor['type'] == 2) {
$data .= __('Keyword', 'uptime-robot-nh'); $data .= "</td>";
}elseif ($monitor['type'] == 3) {
$data .= __('PING', 'uptime-robot-nh'); $data .= "</td>";
}elseif ($monitor['subtype'] == 1) {
$data .= __('SSL', 'uptime-robot-nh'); $data .= " (80)</td>";
}elseif ($monitor['subtype'] == 2) {
$data .= __('PORT', 'uptime-robot-nh'); $data .= " (443)</td>";
}elseif ($monitor['subtype'] == 3) {
$data .= __('FTP', 'uptime-robot-nh'); $data .= " (21)</td>";
}elseif ($monitor['subtype'] == 4) {
$data .= __('MAIL', 'uptime-robot-nh'); $data .= " (25)</td>";
}elseif ($monitor['subtype'] == 5) {
$data .= __('POP', 'uptime-robot-nh'); $data .= " (110)</td>";
}elseif ($monitor['subtype'] == 5) {
$data .= __('IMAP', 'uptime-robot-nh'); $data .= " (143)</td>";
}elseif ($monitor['port'] == 2222) {
$data .= __('PORT', 'uptime-robot-nh'); $data .= " (2222)</td>";
}else{
$data .= __('PORT', 'uptime-robot-nh'); $data .= "(".$monitor['port'].")</td>";
}
}
if($GetUptimes != ""){
$uptimes = explode("-", $monitor['customuptimeratio']);
foreach ($uptimes as $uptime) {
$data .= "</td><td>";
if ($uptime == 100) {
$data .= "<div style=\"color: ".get_option('uptime_robot_nh_colors_100','#006600')."; font-weight:bold;\">100%</div></td>";
}elseif ($uptime > 99.9) {
$data .= "<div style=\"color: ".get_option('uptime_robot_nh_colors_999','#009933')."; font-weight:bold;\">" . $uptime . "%</div></td>";
}elseif($uptime > 99.5) {
$data .= "<div style=\"color: ".get_option('uptime_robot_nh_colors_995','#FF8C00')."; font-weight:bold;\">" . $uptime . "%</div></td>";
}else{
$data .= "<div style=\"color: ".get_option('uptime_robot_nh_colors_0','#FF0000')."; font-weight:bold;\">" . $uptime . "%</div></td>";
}
}
}
}
$data .= "</table></div>";
$data .= '<p style="text-align: right;">';
if(get_option('uptime_robot_nh_thanks_1') == "0"){ _e('Realtime monitoring by <a href="http://uptimerobot.com/" target="_blank" title="Uptime Robot Free Website Monitor Service">Uptime Robot</a>', 'uptime-robot-nh'); }
if(get_option('uptime_robot_nh_thanks_2') == "0"){ _e(' Plugin by <a href="https://wordpress.org/plugins/uptime-robot-monitor/" target="_blank" title="Show your uptime stats and logs from Uptime Robot on your wordpress pages, posts or in a widget.">Niels Hoogenhout.eu</a>', 'uptime-robot-nh'); }
$data .= '</p>';
return $data;
}
function uptime_robot_nh_widget_control() {
return "<p>". __('You can change the settings for this widget on the plugin', 'uptime-robot-nh')." <a href='options-general.php?page=uptime-robot-nh'>". __('settings page', 'uptime-robot-nh')."</a>.</p>";
}
function init_sidebar_widget_uptime_robot_nh() {
wp_register_sidebar_widget('uptime-robot-nh', 'Uptime Robot Widget', 'uptime_robot_nh_widget', array("description" => "Show your uptime monitors from Uptime Robot."));
wp_register_widget_control('uptime-robot-nh', 'Uptime Robot Widget', 'uptime_robot_nh_widget_control');
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment