Skip to content

Instantly share code, notes, and snippets.

@darkhelmet
Created August 29, 2009 23:52
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 darkhelmet/177772 to your computer and use it in GitHub Desktop.
Save darkhelmet/177772 to your computer and use it in GitHub Desktop.
var theElement = "einstein-sb";
var req = false;
getEinsteinInfo();
function loadXMLDoc(url, method, async) {
try
{
if (window.XMLHttpRequest)
{
req = new XMLHttpRequest();
req.onreadystatechange = processReqChange;
req.open(method, url, async);
req.send(null);
}
else if (window.ActiveXObject)
{
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req)
{
req.onreadystatechange = processReqChange;
req.open(method, url, async);
req.send();
}
}
}
catch(e)
{
req = false;
}
}
function getEinsteinInfo()
{
var url = window.location.protocol + "//" + window.location.host + "/blog/einstein.php";
loadXMLDoc(url, "GET", true);
}
function processReqChange()
{
if (req && req.readyState == 4 && req.status == 200 && document.getElementById)
{
try
{
var element = document.getElementById(theElement);
element.innerHTML = req.responseText;
}
catch(e)
{
}
}
}
$(document).ready(function(){
jQuery('#einstein-sb').load(window.location.protocol + "//" + window.location.host + "/blog/einstein.php");
});
<?php
function get_einstein_team($url)
{
$content = file_get_contents($url);
$xml = new SimpleXMLElement($content);
return $xml->name;
}
function get_einstein_stat_info()
{
try
{
$authkey = "auth-key-goes-here";
$url = "http://einstein.phys.uwm.edu/";
$content = file_get_contents($url . "show_user.php?auth=$authkey&format=xml");
$xml = new SimpleXMLElement($content);
$username = $xml->name;
$credit = number_format($xml->total_credit, 3);
$team = get_einstein_team($url . "team_lookup.php?team_id=$xml->teamid");
$link = $url . "show_user.php?userid=$xml->id";
$html = "<ul>\n";
$html .= "<li><a href=\"$link\" target=\"_blank\"><b>Username:</b> $username</a></li>\n";
$html .= "<li><a href=\"$link\" target=\"_blank\"><b>Team:</b> $team</a></li>\n";
$html .= "<li><a href=\"$link\" target=\"_blank\"><b>Total Credit:</b> $credit</a></li>\n";
$html .= "</ul>";
return $html;
}
catch (Exception $e)
{
return "<ul><li><a>Error getting stats</a></li></ul>\n";
}
}
echo get_einstein_stat_info();
?>
<script src="<?php echo get_option('siteurl') . "/wp-includes/js/jquery.js"; ?>" type="text/javascript"></script>
<script src="<?php echo get_option('siteurl') . "/wp-includes/js/einstein.js"; ?>" type="text/javascript"></script>
<li id="Einstein">
<h2>Einstein@Home</h2>
<div id="einstein-sb">
<ul>
<li><a>Loading stats...</a></li>
</ul>
</div>
</li>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment