Created
August 29, 2009 23:52
-
-
Save darkhelmet/177772 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
{ | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function(){ | |
jQuery('#einstein-sb').load(window.location.protocol + "//" + window.location.host + "/blog/einstein.php"); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment