1
0
Fork 0

Initial commit

This commit is contained in:
Andrew Tomaka 2014-07-30 00:49:13 -04:00
commit 7104c57cd2
10 changed files with 1528 additions and 0 deletions

18
contact.php Normal file
View File

@ -0,0 +1,18 @@
<?php
$email_to = 'atomaka@gmail.com';
$name = 'sc2mmr Site';
$email = $_POST['contactemail'];
$subject = 'sc2mmr Feedback';
$message = $_POST['contactcomment'];
$headers = 'From: ' . $email . "\r\n";
$headers .= 'Reply-To: ' . $email . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
if(mail($email_to, $subject, $message, $headers)) {
echo 'sent';
} else {
echo 'failed';
}
?>

266
css/main.css Normal file
View File

@ -0,0 +1,266 @@
body
{
padding: 0px;
margin: 0px;
text-align: center;
background-color: #2A4480;/*#74aa81;*/
color: #000000;
}
body, div, td
{
font-family: Verdana, Arial, Helvetica, sans-serif;
}
img
{
border: 0;
}
a
{
color: #000000;
}
h1
{
font-size: 48px;
font-weight: bold;
}
h2
{
font-size: 21px;
font-weight: bold;
padding: 0px;
margin: 0px;
border: 0px;
margin-bottom: 8px;
font-family: Verdana, Arial, Helvetica, sans-serif;
color: #06266F; /*#9bc1a4;*/
}
h3
{
visibility: hidden;
display: none;
}
table
{
font-size: 11px;
color: #000000;
}
div#header
{
width: 979px;
text-align: right;
color: #6C8CD5;
margin: 0px auto;
}
div#content
{
background-color: #6C8CD5; /*#216332;*/
text-align: left;
width: 979px;
margin: 0px auto;
padding-top: 8px;
padding-bottom: 8px;
}
div#column1a
{
width: 313px;
float: left;
padding-left: 10px;
}
div#column1b
{
width: 636px;
float: left;
padding-left: 10px;
}
div#contact
{
font-size: 24px;
}
div#contactme
{
position:relative;
}
div#benchmark
{
font-size: 11px;
color: #6C8CD5;
}
div#copyright
{
font-size: 11px;
color: #6C8CD5;
}
.box
{
padding: 5px;
margin: 5px;
background-color: #ffffff;
font-size: 11px;
color: #000000;
}
.box a
{
color: #6C8CD5;
}
.box a:hover
{
color: #06266F;
}
.tweet
{
font-size: 16px;
}
.right
{
float: right;
text-align:right;
}
.center
{
text-align: center;
}
.justify
{
text-align: justify;
}
.clear
{
clear: both;
}
input.text {
font-family: Verdana, Arial, Helvetica, sans-serif;
background-color: #F0F0F0;
color: #06266F;
border: 2px solid #2A4480;
height:2em;
line-height:2em;
font-size:18px;
width: 90%;
text-align: center;
}
input.optionaltext {
font-family: Verdana, Arial, Helvetica, sans-serif;
background-color: #F0F0F0;
color: #06266F;
border: 2px solid #2A4480;
height:2em;
line-height:2em;
font-size:18px;
width: 10%;
text-align: center;
}
input.button {
font-family: Verdana, Arial, Helvetica, sans-serif;
background-color: #F0F0F0;
color: #06266F;
border: 2px solid #2A4480;
height:2em;
line-height:2em;
font-size:18px;
}
input.contacttext {
font-family: Verdana, Arial, Helvetica, sans-serif;
background-color: #F0F0F0;
color: #06266F;
border: 2px solid #2A4480;
height:1em;
line-height:1em;
font-size:14px;
width: 90%;
}
textarea.contactcomment {
font-family: Verdana, Arial, Helvetica, sans-serif;
background-color: #F0F0F0;
color: #06266F;
border: 2px solid #2A4480;
height:5em;
line-height:1em;
font-size:14px;
width: 90%;
}
input.contactbutton {
font-family: Verdana, Arial, Helvetica, sans-serif;
background-color: #F0F0F0;
color: #06266F;
border: 2px solid #2A4480;
height:1.5em;
line-height:1em;
font-size:14px;
}
.error {
margin-left:10px;
display: none; /* hide the errors */
/* add some styling */
padding:5px;
color: #D8000C;
font-size:12px;
background-color: #FFBABA;
width:90%;
/*position:absolute;*/
}
.success {
margin-left:10px;
display: none; /* hide the sucess div */
/* add some styling */
padding:5px;
color: #044406;
font-size:12px;
background-color: #B7FBB9;
width:90%;
/*position:absolute;*/
}
table.mmr {
border: 0;
width: 100%;
}
td.mmrHeading {
text-align: center;
font-weight: bold;
font-size: 18px;
}
td.mmrData {
text-align: center;
font-weight: bold;
font-size: 42px;
}
table.formula,td.formulaData {
border-color: #2A4489;
border-style: solid;
}
table.formula {
width:100%;
border-spacing: 0;
border-width: 0 0 2px 2px;
}
td.formulaData {
border-width: 2px 2px 0 0;
}

35
css/niftyCorners.css Normal file
View File

@ -0,0 +1,35 @@
/*Nifty Corners Cube CSS by Alessandro Fulciniti
The following classes are added dinamically by javascript,
and their use should be avoided in the markup */
b.niftycorners,b.niftyfill{display:block}
b.niftycorners *{display:block;height: 1px;line-height:1px;font-size: 1px;
overflow:hidden;border-style:solid;border-width: 0 1px}
/*normal*/
b.r1{margin: 0 3px;border-width: 0 2px}
b.r2{margin: 0 2px}
b.r3{margin: 0 1px}
b.r4{height: 2px}
b.rb1{margin: 0 8px;border-width:0 2px}
b.rb2{margin: 0 6px;border-width:0 2px}
b.rb3{margin: 0 5px}
b.rb4{margin: 0 4px}
b.rb5{margin: 0 3px}
b.rb6{margin: 0 2px}
b.rb7{margin: 0 1px;height:2px}
b.rb8{margin: 0;height:2px}
b.rs1{margin: 0 1px}
/*transparent inside*/
b.t1{border-width: 0 5px}
b.t2{border-width: 0 3px}
b.t3{border-width: 0 2px}
b.t4{height: 2px}
b.tb1{border-width: 0 10px}
b.tb2{border-width: 0 8px}
b.tb3{border-width: 0 6px}
b.tb4{border-width: 0 5px}
b.tb5{border-width: 0 4px}
b.tb6{border-width: 0 3px}
b.tb7{border-width: 0 2px;height:2px}
b.tb8{border-width: 0 1px;height:2px}
b.ts1{border-width: 0 2px}

14
index.html Normal file
View File

@ -0,0 +1,14 @@
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!doctype html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
Currently not available.
</body>
</html>

311
index.php.old Normal file
View File

@ -0,0 +1,311 @@
<?php
$benchmark = array(
'total' => 0,
'index' => 0,
'includes' => 0,
'twitter' => 0,
'lastfm' => 0,
'hulu' => 0,
'sc2ranks' => 0,
'wow' => 0,
'steam' => 0,
'links' => 0,
);
$benchmark_start = microtime(true);
include_once('lib/misc.php');
$db_config = json_decode(file_get_contents('conf/database.conf'));
include_once('lib/database.php');
$db = new Database($db_config->hostname,$db_config->username,$db_config->password,$db_config->table);
$benchmark['includes'] = microtime(true) - $benchmark_start;
$benchmark_start = microtime(true);
include_once('lib/twitter.php');
$twt = new Twitter;
$latest_tweet = $twt->get_latest_tweet('atomaka');
$latest_tweet_since = time_since(strtotime($latest_tweet['created_at']));
$benchmark['twitter'] = microtime(true) - $benchmark_start;
$benchmark_start = microtime(true);
include_once('lib/lastfm.php');
$lfm = new Lastfm;
$latest_song = $lfm->get_latest_song('atomaka');
$latest_song_since = ($latest_song['@attributes']['nowplaying']) ? 'Listening now' : time_since(strtotime($latest_song['date'] . ' UTC')) . ' ago';
$latest_song_image = (is_array($latest_song['image'][1])) ? 'img/lastfm/blank_album64.png' : $latest_song['image'][1];
$benchmark['lastfm'] = microtime(true) - $benchmark_start;
$benchmark_start = microtime(true);
include_once('lib/hulu.php');
$hul = new Hulu;
$latest_hulu = $hul->get_latest_show('atomaka');
$latest_hulu_since = time_since(strtotime($latest_hulu['pubdate']));
preg_match('/<img src="(.*)" border="0"/',$latest_hulu['description'],$latest_hulu_thumb);
$latest_hulu_thumb = $latest_hulu_thumb[1];
$benchmark['hulu'] = microtime(true) - $benchmark_start;
$benchmark_start = microtime(true);
include_once('lib/sc2ranks.php');
$sc2 = new Sc2ranks;
$team = $sc2->get_team('Gaffer',888,1);
$benchmark['sc2ranks'] = microtime(true) - $benchmark_start;
$benchmark_start = microtime(true);
//$latest_achievement = $wow->get_latest_achievement('gaffer','crushridge');
$benchmark['wow'] = microtime(true) - $benchmark_start;
$benchmark_start = microtime(true);
include_once('lib/steamclass.php');
$stm = new Steam('76561197993725971');
$steam = $stm->profile();
$steam_games = $stm->recentgames();
$benchmark['steam'] = microtime(true) - $benchmark_start;
$benchmark_start = microtime(true);
include_once('lib/links.php');
$lnk = new Links($db);
$links = $lnk->get_latest_links(15);
$benchmark['links'] = microtime(true) - $benchmark_start;
$benchmark_start = microtime(true);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Who is Andrew?</title>
<link rel="stylesheet" type="text/css" href="css/main.css" />
<link rel="stylesheet" type="text/css" href="css/niftyCorners.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="js/jquery.qtip-1.0.0-rc3.min.js"></script>
<script type="text/javascript" src="js/niftycube.js"></script>
<script type="text/javascript" src="js/niftylayout.js"></script>
<link rel="shortcut icon" href="favicon.ico" />
<script type="text/javascript">
$(document).ready(function()
{
//not doing what I want yet. need to limit to images in contacts div. $('#contacts img').each(function() { });
$('img[title]').qtip({
style: {
tip: true,
border: {
width: 0,
radius: 5,
color: '#74aa81'
},
color: '#216332'
}
})
});
</script>
</head>
<body>
<!--<div id="header"><h1>who is andrew?</h1></div>-->
<br/><br/>
<div id="content">
<div id="column1a">
<!--<h2>about</h2>
<div id="about" class="box justify">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent mollis sodales lacus eu interdum. Phasellus a mi sit amet leo feugiat gravida eu quis arcu. Aliquam mauris libero, blandit egestas adipiscing sagittis, luctus in nisi. Morbi nec metus vel dui sagittis scelerisque sed vitae magna. Sed et lobortis felis. Nunc.
</div>
<br/>-->
<h2>contact</h2>
<div id="contacts" class="box center">
<img src="img/badges/email.png" border="0" alt="Email" title="atomaka@gmail.com" />
<img src="img/badges/aim.png" border="0" alt="AIM" title="atomaka" />
<img src="img/badges/yahoo.png" border="0" alt="Yahoo!" title="atomaka" />
<img src="img/badges/msn.png" border="0" alt="MSN" title="atomaka@hotmail.com" />
<img src="img/badges/icq.png" border="0" alt="ICQ" title="12534325" />
<img src="img/badges/google.png" border="0" alt="Google Messaging" title="atomaka@gmail.com" />
<img src="img/badges/skype.png" border="0" alt="Skype" title="andrewtomaka" />
<div id="contact"></div>
</div>
<br/>
<h2>twitter</h2>
<div id="twitter" class="box">
<span class="right"><a href="http://www.twitter.com/atomaka"><img src="img/badges/twitter.png" border="0" alt="Follow me on Twitter"/></a></span>
<span class="tweet"><?php echo $latest_tweet['text'] ?></span><br/>
<?php echo $latest_tweet_since ?> ago
</div>
<br/>
<h2>projects</h2>
<h3>project 1</h3>
<div id="projects">
<div id ="sc2mmr" class="box">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td valign="top" width="68">
<img src="img/projects/sc2mmr.jpg" width="64" alt="sc2mmr" />
</td>
<td valign="top">
<a href="projects/sc2mmr">sc2mmr</a><br/><br/>
Predicts how many more games you will need to play to receive a league
promotion in Starcraft 2.
</td>
</tr>
</table>
</div>
<h3>project 2</h3>
<p class="box">
content
</p>
<h3>project 3</h3>
<p class="box">
content
</p>
</div>
</div>
<div id="column1b">
<h2>random</h2>
<div id="random">
<?php
foreach($links as $link)
{
$link_text = $link->text;
$link_text = preg_replace('/\[/','<a href="' . htmlentities($link->url) . '">',$link_text);
$link_text = preg_replace('/\]/','</a>',$link_text);
echo ' <p class="box">' . $link_text . '</p>' . "\n";
}
?>
</div>
</div>
<div id="column1c">
<h2>media</h2>
<div id="lastfm" class="box">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td valign="top" width="68">
<img src="<?php echo $latest_song_image; ?>" width="64" alt="<?php echo $latest_song['artist'] ?> - <?php echo $latest_song['name'] ?>"/>
</td>
<td valign="top">
<span class="right"><a href="http://last.fm/user/atomaka"><img src="img/badges/lastfm.png" border="0" alt="Last.fm" /></a></span>
<a href="<?php echo $latest_song['link'] ?>"><?php echo $latest_song['name'] ?></a><br/>
by <?php echo $latest_song['artist'] ?><br/><br/>
<?php echo $latest_song_since ?><br/>
</td>
</tr>
</table>
</div>
<div id="hulu" class="box">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td valign="top" width="68">
<img src="<?php echo $latest_hulu_thumb ?>" width="64" alt="<?php echo $latest_hulu['hulu']['show-name'] ?> - <?php echo $latest_hulu['hulu']['video-title'] ?>" />
</td>
<td valign="top">
<span class="right"><a href="http://www.hulu.com/profiles/atomaka"><img src="img/badges/hulu.png" border="0" alt="Hulu" /></a></span>
<a href="<?php echo $latest_hulu['link'] ?>"><?php echo $latest_hulu['hulu']['video-title'] ?></a><br/>
from <?php echo $latest_hulu['hulu']['show-name'] ?><br/><br/>
<?php echo $latest_hulu_since ?> ago<br/>
</td>
</tr>
</table>
</div>
<br/>
<h2>games</h2>
<h3>World of Warcraft</h3>
<div id="wow" class="box">
<table width="100%">
<tr>
<td valign="top" width="58"><a href="http://battle.net/wow"><img src="img/badges/wow.jpg" width="48" alt="World of Warcraft" /></a></td>
<td valign="top">
<a href="http://us.battle.net/wow/en/character/crushridge/gaffer/simple">Gaffer @ Crushridge</a><br/>
<a href="http://us.battle.net/wow/en/character/crushridge/veincane/simple">Veincane @ Crushridge</a><br/>
<a href="http://us.battle.net/wow/en/character/crushridge/ttg/simple">Ttg @ Crushridge</a><br/>
Guild: <a href="http://www.nca-guild.com">No Chicks Allowed</a><br/>
</td>
</tr>
</table>
</div>
<h3>Starcraft 2</h3>
<div id="sc2" class="box">
<table width="100%">
<tr>
<td valign="top" width="58"><a href="http://battle.net/sc2"><img src="img/badges/sc2.jpg" alt="Starcraft 2" /></a></td>
<td valign="top">
<a href="http://us.battle.net/sc2/en/profile/1680730/1/Gaffer/">Gaffer.888</a><br/>
<?php
if(!isset($team['error']))
{
$league_image = $team['league'];
?>
<?php echo $team['division'] ?><br/>
<?php echo $team['points'] ?> points, Rank <?php echo $team['division_rank'] ?><br/>
<?php echo $team['wins'] ?> wins <!---<?php echo $team['losses'] ?> (<?php echo $team['ratio'] * 100; ?>%)--><br/>
<?php
}
else
{
$league_image = 'error';
echo 'Information not currently available.';
}
?>
</td>
<td class="right" valign="top"><img src="img/sc2/<?php echo $league_image ?>.png" alt="<?php echo ucfirst($team['league']) ?> League" /></td>
</tr>
</table>
</div>
<h3>Steam</h3>
<div id="steam" class="box">
<table width="100%">
<tr>
<td valign="top" width="58"><a href="http://steamcommunity.com/"><img src="img/badges/steam.jpg" width= "48" alt="Steam" /></a></td>
<td valign="top">
<a href="http://steamcommunity.com/id/toppazz">Toppazz</a><br/>
<?php echo $steam['hoursPlayed2Wk']; ?> hours in the last two weeks.<br/>
<?php
foreach($steam_games as $game)
{
?>
<a href="<?php echo $game['gameLink']; ?>"><?php echo $game['gameName']; ?></a>: <?php echo $game['hoursPlayed']; ?> hours.<br/>
<?
}
?>
</td>
</tr>
</table>
</div>
</div>
<div class="clear">&nbsp;</div>
</div>
<br/>
<?php
$benchmark['index'] = microtime(true) - $benchmark_start;
$max = array('part' => 'none','time' => 0);
foreach($benchmark as $part=>$time)
{
if($time > $max['time'])
{
$max['time'] = $time;
$max['part'] = $part;
}
$benchmark['total'] += $time;
}
?>
<div id="benchmark">Prepared in <?php printf('%.1f',$benchmark['total']); ?>s. Damn you, <?php echo $max['part'] ?> (<?php printf('%.1f',$max['time']); ?>s)</div>
<div id="copyright">&copy; Andrew Tomaka 2010-2011. [ <a href="admin">admin</a> ]</div>
<br/><br/>
</body>
</html>
<?php
echo '<!--';
print_r($benchmark);
echo '-->';
?>

319
js/niftycube.js Normal file
View File

@ -0,0 +1,319 @@
/* Nifty Corners Cube - rounded corners with CSS and Javascript
Copyright 2006 Alessandro Fulciniti (a.fulciniti@html.it)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
var niftyOk=(document.getElementById && document.createElement && Array.prototype.push);
var niftyCss=false;
String.prototype.find=function(what){
return(this.indexOf(what)>=0 ? true : false);
}
var oldonload=window.onload;
if(typeof(NiftyLoad)!='function') NiftyLoad=function(){};
if(typeof(oldonload)=='function')
window.onload=function(){oldonload();AddCss();NiftyLoad()};
else window.onload=function(){AddCss();NiftyLoad()};
//commented out who knows if this was bad.
function AddCss(){
niftyCss=true;
//var l=CreateEl("link");
//l.setAttribute("type","text/css");
//l.setAttribute("rel","stylesheet");
//l.setAttribute("href","niftyCorners.css");
//l.setAttribute("media","screen");
//document.getElementsByTagName("head")[0].appendChild(l);
}
function Nifty(selector,options){
if(niftyOk==false) return;
if(niftyCss==false) AddCss();
var i,v=selector.split(","),h=0;
if(options==null) options="";
if(options.find("fixed-height"))
h=getElementsBySelector(v[0])[0].offsetHeight;
for(i=0;i<v.length;i++)
Rounded(v[i],options);
if(options.find("height")) SameHeight(selector,h);
}
function Rounded(selector,options){
var i,top="",bottom="",v=new Array();
if(options!=""){
options=options.replace("left","tl bl");
options=options.replace("right","tr br");
options=options.replace("top","tr tl");
options=options.replace("bottom","br bl");
options=options.replace("transparent","alias");
if(options.find("tl")){
top="both";
if(!options.find("tr")) top="left";
}
else if(options.find("tr")) top="right";
if(options.find("bl")){
bottom="both";
if(!options.find("br")) bottom="left";
}
else if(options.find("br")) bottom="right";
}
if(top=="" && bottom=="" && !options.find("none")){top="both";bottom="both";}
v=getElementsBySelector(selector);
for(i=0;i<v.length;i++){
FixIE(v[i]);
if(top!="") AddTop(v[i],top,options);
if(bottom!="") AddBottom(v[i],bottom,options);
}
}
function AddTop(el,side,options){
var d=CreateEl("b"),lim=4,border="",p,i,btype="r",bk,color;
d.style.marginLeft="-"+getPadding(el,"Left")+"px";
d.style.marginRight="-"+getPadding(el,"Right")+"px";
if(options.find("alias") || (color=getBk(el))=="transparent"){
color="transparent";bk="transparent"; border=getParentBk(el);btype="t";
}
else{
bk=getParentBk(el); border=Mix(color,bk);
}
d.style.background=bk;
d.className="niftycorners";
p=getPadding(el,"Top");
if(options.find("small")){
d.style.marginBottom=(p-2)+"px";
btype+="s"; lim=2;
}
else if(options.find("big")){
d.style.marginBottom=(p-10)+"px";
btype+="b"; lim=8;
}
else d.style.marginBottom=(p-5)+"px";
for(i=1;i<=lim;i++)
d.appendChild(CreateStrip(i,side,color,border,btype));
el.style.paddingTop="0";
el.insertBefore(d,el.firstChild);
}
function AddBottom(el,side,options){
var d=CreateEl("b"),lim=4,border="",p,i,btype="r",bk,color;
d.style.marginLeft="-"+getPadding(el,"Left")+"px";
d.style.marginRight="-"+getPadding(el,"Right")+"px";
if(options.find("alias") || (color=getBk(el))=="transparent"){
color="transparent";bk="transparent"; border=getParentBk(el);btype="t";
}
else{
bk=getParentBk(el); border=Mix(color,bk);
}
d.style.background=bk;
d.className="niftycorners";
p=getPadding(el,"Bottom");
if(options.find("small")){
d.style.marginTop=(p-2)+"px";
btype+="s"; lim=2;
}
else if(options.find("big")){
d.style.marginTop=(p-10)+"px";
btype+="b"; lim=8;
}
else d.style.marginTop=(p-5)+"px";
for(i=lim;i>0;i--)
d.appendChild(CreateStrip(i,side,color,border,btype));
el.style.paddingBottom=0;
el.appendChild(d);
}
function CreateStrip(index,side,color,border,btype){
var x=CreateEl("b");
x.className=btype+index;
x.style.backgroundColor=color;
x.style.borderColor=border;
if(side=="left"){
x.style.borderRightWidth="0";
x.style.marginRight="0";
}
else if(side=="right"){
x.style.borderLeftWidth="0";
x.style.marginLeft="0";
}
return(x);
}
function CreateEl(x){
return(document.createElement(x));
}
//added to fix ie8 width problem
function getIeVersion() {
var rv = -1;
if (navigator.appName == 'Microsoft Internet Explorer') {
var ua = navigator.userAgent;
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null) {
rv = parseFloat(RegExp.$1);
}
}
return rv;
}
//end add
function FixIE(el){
if(el.currentStyle!=null && el.currentStyle.hasLayout!=null && el.currentStyle.hasLayout==false)
//el.style.display="inline-block"; //removed to fix ie8 width problem
//added to fix ie8 width problem
var ver = getIeVersion();
if (ver < 8) {
el.style.display="inline-block";
}
//end add
}
function SameHeight(selector,maxh){
var i,v=selector.split(","),t,j,els=[],gap;
for(i=0;i<v.length;i++){
t=getElementsBySelector(v[i]);
els=els.concat(t);
}
for(i=0;i<els.length;i++){
if(els[i].offsetHeight>maxh) maxh=els[i].offsetHeight;
els[i].style.height="auto";
}
for(i=0;i<els.length;i++){
gap=maxh-els[i].offsetHeight;
if(gap>0){
t=CreateEl("b");t.className="niftyfill";t.style.height=gap+"px";
nc=els[i].lastChild;
if(nc.className=="niftycorners")
els[i].insertBefore(t,nc);
else els[i].appendChild(t);
}
}
}
function getElementsBySelector(selector){
var i,j,selid="",selclass="",tag=selector,tag2="",v2,k,f,a,s=[],objlist=[],c;
if(selector.find("#")){ //id selector like "tag#id"
if(selector.find(" ")){ //descendant selector like "tag#id tag"
s=selector.split(" ");
var fs=s[0].split("#");
if(fs.length==1) return(objlist);
f=document.getElementById(fs[1]);
if(f){
v=f.getElementsByTagName(s[1]);
for(i=0;i<v.length;i++) objlist.push(v[i]);
}
return(objlist);
}
else{
s=selector.split("#");
tag=s[0];
selid=s[1];
if(selid!=""){
f=document.getElementById(selid);
if(f) objlist.push(f);
return(objlist);
}
}
}
if(selector.find(".")){ //class selector like "tag.class"
s=selector.split(".");
tag=s[0];
selclass=s[1];
if(selclass.find(" ")){ //descendant selector like tag1.classname tag2
s=selclass.split(" ");
selclass=s[0];
tag2=s[1];
}
}
var v=document.getElementsByTagName(tag); // tag selector like "tag"
if(selclass==""){
for(i=0;i<v.length;i++) objlist.push(v[i]);
return(objlist);
}
for(i=0;i<v.length;i++){
c=v[i].className.split(" ");
for(j=0;j<c.length;j++){
if(c[j]==selclass){
if(tag2=="") objlist.push(v[i]);
else{
v2=v[i].getElementsByTagName(tag2);
for(k=0;k<v2.length;k++) objlist.push(v2[k]);
}
}
}
}
return(objlist);
}
function getParentBk(x){
var el=x.parentNode,c;
while(el.tagName.toUpperCase()!="HTML" && (c=getBk(el))=="transparent")
el=el.parentNode;
if(c=="transparent") c="#FFFFFF";
return(c);
}
function getBk(x){
var c=getStyleProp(x,"backgroundColor");
if(c==null || c=="transparent" || c.find("rgba(0, 0, 0, 0)"))
return("transparent");
if(c.find("rgb")) c=rgb2hex(c);
return(c);
}
function getPadding(x,side){
var p=getStyleProp(x,"padding"+side);
if(p==null || !p.find("px")) return(0);
return(parseInt(p));
}
function getStyleProp(x,prop){
if(x.currentStyle)
return(x.currentStyle[prop]);
if(document.defaultView.getComputedStyle)
return(document.defaultView.getComputedStyle(x,'')[prop]);
return(null);
}
function rgb2hex(value){
var hex="",v,h,i;
var regexp=/([0-9]+)[, ]+([0-9]+)[, ]+([0-9]+)/;
var h=regexp.exec(value);
for(i=1;i<4;i++){
v=parseInt(h[i]).toString(16);
if(v.length==1) hex+="0"+v;
else hex+=v;
}
return("#"+hex);
}
function Mix(c1,c2){
var i,step1,step2,x,y,r=new Array(3);
if(c1.length==4)step1=1;
else step1=2;
if(c2.length==4) step2=1;
else step2=2;
for(i=0;i<3;i++){
x=parseInt(c1.substr(1+step1*i,step1),16);
if(step1==1) x=16*x+x;
y=parseInt(c2.substr(1+step2*i,step2),16);
if(step2==1) y=16*y+y;
r[i]=Math.floor((x*50+y*50)/100);
r[i]=r[i].toString(16);
if(r[i].length==1) r[i]="0"+r[i];
}
return("#"+r[0]+r[1]+r[2]);
}

5
js/niftylayout.js Normal file
View File

@ -0,0 +1,5 @@
window.onload=function()
{
Nifty("div#content","big");
Nifty("div#information,div#form,div#contactme,div#prediction,div#error");
}

View File

@ -0,0 +1,54 @@
$rowTemplate = <<<ROWTEMPLATE
<tr>
<td class="align-center" style="width: 15px" onmouseover="Tooltip.show\(this, 'Joined Division: (.*)'\);">
<img src="/sc2/static/images/icons/ladder/arrow-up.gif" alt="" />
</td>
<td class="align-center" style="width: 40px">(.*)</td>
<td>
<a href="/sc2/en/profile/1457748/1/(.*)/"
class="race-zerg"
onmouseover="Tooltip.show\(this, '#player-info-1457748'\);">
SpacePenguin
</a>
<div id="player-info-1457748" style="display: none">
<div class="tooltip-title">SpacePenguin</div>
<strong>Highest Rank:</strong> 1<br />
<strong>Previous Rank:</strong> 3<br />
<strong>Favorite Race:</strong> Zerg
</div>
</td>
<td class="align-center">(.*)</td>
<td class="align-center">(.*)</td>
<td class="align-center">(.*)</td>
</tr>
ROWTEMPLATE;
$rowPattern = '{' . trim($rowTemplate) . '}m';
preg_match_all($rowPattern,$divisionHtml,$divisionMatches);

182
lib/sc2profile.php Normal file
View File

@ -0,0 +1,182 @@
<?php
class sc2profile {
private $profileFound = true;
private $bnetProfileLink;
private $divisonLink;
private $divisionStandings = array();
private $matchHistory = array();
private $characterName;
private $characterRating;
private $characterLeague;
private $gamesPlayed;
private $gamesWon;
private $bonusPool;
public function __construct($profile) {
if(preg_match('{/^}',$profile)) $this->bnetProfileLink = $profile;
else $this->bnetProfileLink = $profile . '/';
$this->parseProfile();
if($this->profileFound) {
$this->parseDivision();
$this->parseMatchHistory();
}
}
public function getDivisionLink() {
return $this->divisionLink;
}
public function getCharacterName() {
return $this->characterName;
}
public function getCharacterLeague() {
return $this->characterLeague;
}
public function getGamesPlayed() {
return $this->gamesPlayed;
}
public function getGamesWon() {
return $this->gamesWon;
}
public function getBonusPool() {
return $this->bonusPool;
}
public function getDivisionStandings() {
return $this->divisionStandings;
}
public function getMatchHistory($count = 0) {
if($count == 0) $count = count($this->matchHistory);
return array_slice($this->matchHistory,0,$count);
}
public function getMaxBonusPool() {
return $this->maxBonusPool;
}
public function getCharacterRating() {
return $this->characterRating;
}
public function getProfileFound() {
return $this->profileFound;
}
private function parseProfile() {
$profileHtml = @file($this->bnetProfileLink);
if(!$profileHtml) {
$this->profileFound = false;
return;
}
$onesFound = false;
$divisionFound = false;
$characterFound = false;
foreach($profileHtml as $profileLine) {
if(!$characterFound) {
if(preg_match('{<a href="/sc2/.*/profile/.*/.*/(.*)/" rel="np">}',$profileLine,$characterMatch)) $characterFound = true;
}
if(preg_match('/#best-team-1/',$profileLine)) $onesFound = true;
if(!$onesFound) continue;
if(!$divisionFound) {
if(preg_match('{a href="(.*)#current-rank"><img src="/sc2/static/images/icons/league/(.*)-medium.png" alt=}',$profileLine,$divisionMatch)) $divisionFound = true;
}
if(!preg_match('{<strong>Record:</strong> (.*) - (.*)}',$profileLine,$recordMatch)) continue;
break;
}
preg_match('{(http://.*.battle.net)}',$this->bnetProfileLink,$regionMatch);
$this->divisionLink = $regionMatch[1] . $divisionMatch[1];
$this->gamesPlayed = $recordMatch[1] + $recordMatch[2];
$this->gamesWon = $recordMatch[1];
$this->characterName = $characterMatch[1];
$this->characterLeague = $divisionMatch[2];
}
private function parseDivision() {
$divisionStandings = array();
$divisionHtml = file($this->divisionLink);
$standingsHtml = array();
$standingsCount = 0;
$standingsFound = false;
$bonusFound = false;
foreach($divisionHtml as $divisionLine) {
if(!$bonusFound) {
if(preg_match('{Bonus Pool: <span>(.*)</span></span>}',$divisionLine,$bonusMatch)) $bonusFound = true;
}
if(preg_match('/<table class="data-table">/',$divisionLine)) $standingsFound = true;
if(!$standingsFound) continue;
if(preg_match('{</table>}',$divisionLine)) break;
if(preg_match('{<tr>}',$divisionLine)) $standingsCount++;
$standingsHtml[$standingsCount] .= $divisionLine;
}
$rankTemplate = <<<RANKTEMPLATE
{<tr.*><tdclass="align-center"style="width:15px"data-tooltip="JoinedDivision:(.*)">.*</td><tdclass="align-center"style="width:40px">.*</td><td><ahref="/sc2/en/profile/.*/"class="race-.*"data-tooltip="#player-info-.*">(.*)</a><divid="player-info-.*"style="display:none"><divclass="tooltip-title">.*</div><strong>HighestRank:</strong>.*<br/><strong>PreviousRank:</strong>.*<br/><strong>FavoriteRace:</strong>.*</div></td><tdclass="align-center">(.*)</td><tdclass="align-center">(.*)</td><tdclass="align-center">(.*)</td></tr>}
RANKTEMPLATE;
foreach($standingsHtml as $standingsLine) {
$standingsLine = preg_replace('/[\s]+/m','',$standingsLine);
preg_match($rankTemplate,$standingsLine,$standingMatch);
array_shift($standingMatch);
$divisionStandings[] = $standingMatch;
if($standingMatch[1] == $this->characterName) $this->characterRating = $standingMatch[2];
}
$this->divisionStandings = $divisionStandings;
$this->bonusPool = $bonusMatch[1];
}
private function parseMatchHistory() {
$matches = array();
$matchHistoryHtml = file($this->bnetProfileLink . 'matches');
$matchHtml = array();
$matchesFound = false;
$matchCount = 0;
foreach($matchHistoryHtml as $matchHistoryLine) {
if(preg_match('/<table class="data-table">/',$matchHistoryLine)) $matchesFound = true;
if(!$matchesFound) continue;
if(preg_match('{</table>}',$matchHistoryLine)) break;
if(preg_match('{<tr class="(.*)">}',$matchHistoryLine)) $matchCount++;
$matchHtml[$matchCount] .= $matchHistoryLine;
}
array_shift($matchHtml);
array_shift($matchHtml);
$matchTemplate = <<<MATCHTEMPLATE
{<trclass="match-rowsolo"><tdstyle="width:15px"data-tooltip="#match-mode-.*"><imgsrc="/sc2/static/images/icons/ladder/view-more.gif"alt="\+"/><divid="match-mode-.*"style="display:none"><strong>Type:</strong>1v1<br/><strong>Speed:</strong>Faster</div></td><td>.*</td><tdclass="align-center">1v1</td><td><spanclass=".*">.*</span>\(<spanclass=".*">(.*)</span>\)</td><tdclass="align-right">.*</td></tr>}
MATCHTEMPLATE;
foreach($matchHtml as $matchLine) {
$matchLine = preg_replace('/[\s]+/m','',$matchLine);
preg_match($matchTemplate,$matchLine,$matchMatch);
if($matchMatch[1] != '') $matches[] = $matchMatch[1];
}
$this->matchHistory = $matches;
}
}
?>

324
predict.php Normal file
View File

@ -0,0 +1,324 @@
<?php
$benchmark = array(
'total' => 0,
'index' => 0,
'start' => 0,
'profile_load' => 0,
'calculations' => 0,
);
$benchmark_start = microtime(true);
$profile = $_POST['profile'];
$w = $_POST['W'];
$k = $_POST['K'];
$c = $_POST['C'];
$constantsDefined = false;
if(($w == 'W' || $k == 'K' || $c == 'C')&&($w != 'W' || $k != 'K' || $c != 'C')) {
//die ('if one constant is filled all constants need to be filled.');
$error = array('Constants','Entering one of the W, K, or C constants requires you to enter all of them.');
require 'index.php';
exit();
} elseif($w != 'W' && $k != 'K' && $c != 'C') {
$constantsDefined = true;
}
//require valid battle.net profile.
if(!preg_match('{^http://us|eu|tw|sea.battle.net}',$profile)) {
//die('throw error, not valid profile or region cannot be checked.');
$error = array('Battle.net Profile','You did not enter a valid Battle.net profile URL.');
require 'index.php';
exit();
}
$MAGIC_NUMBERS = array(
'bronze' => 500,
'silver' => 250,
'gold' => 250,
'platinum' => 250,
'diamond' => 475,
);
$MMR_NUMBERS = array(
'bronze' => 0,
'silver' => 1000,
'gold' => 1250,
'platinum' => 1500,
'diamond' => 1750,
'master' => 2225,
);
include_once 'lib/sc2profile.php';
$benchmark['start'] = microtime(true) - $benchmark_start;
$benchmark_start = microtime(true);
$sc2 = new sc2profile($profile);
$benchmark['profile_load'] = microtime(true) - $benchmark_start;
$benchmark_start = microtime(true);
if($sc2->getProfileFound()) {
$winPercent = $sc2->getGamesWon() / $sc2->getGamesPlayed();
$rankPointDifferential = 0;
if($constantsDefined) {
$rankPointDifferential = $sc2->getCharacterRating() + ($sc2->getBonusPool() * $w * 2) - findMaxBonusPool();
$matchMakingRating = $rankPointDifferential + $k + $c;
} else {
$rankPointDifferential = $sc2->getCharacterRating() + ($sc2->getBonusPool() * $winPercent * 2) - findMaxBonusPool();
$matchMakingRating = $rankPointDifferential + $MMR_NUMBERS[$sc2->getCharacterLeague()];
}
//only if we have a game history (require 10 minumum)
if(count($sc2->getMatchHistory()) >= 10) {
$averageWin = calculateAverageWin($sc2->getMatchHistory());
$averageLoss = calculateAverageLoss($sc2->getMatchHistory());
$gamesToPromotion = 5 + ($MAGIC_NUMBERS[$sc2->getCharacterLeague()] - $rankPointDifferential) / ($winPercent * $averageWin + ($winPercent - 1) * $averageLoss);
}
$obsGamesToPromotion = 5 + ($MAGIC_NUMBERS[$sc2->getCharacterLeague()] - $rankPointDifferential) / (24 * $winPercent - 11);
} else {
//die('profile not found or could not be read.');
$error = array('Profile','The profile you entered could not be read. Please recheck your Battle.net profile URL or try again later.');
require 'index.php';
exit();
}
$benchmark['calculations'] = microtime(true) - $benchmark_start;
$benchmark_start = microtime(true);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Starcraft II Promotion Prediction</title>
<link rel="stylesheet" type="text/css" href="css/main.css" />
<link rel="stylesheet" type="text/css" href="css/niftyCorners.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="js/niftycube.js"></script>
<script type="text/javascript" src="js/niftylayout.js"></script>
<link rel="shortcut icon" href="favicon.ico" />
<script type="text/javascript">
$(document).ready(function() {
$('.default').each(function() {
var default_value = this.value;
$(this).focus(function() {
if(this.value == default_value) {
this.value = '';
}
});
$(this).blur(function() {
if(this.value == '') {
this.value = default_value;
}
});
});
//contact form
$('#contactsubmit').click(function(e){
e.preventDefault();
var error = false;
var email = $('#contactemail').val();
var message = $('#contactcomment').val();
if(email.length == 0 || email.indexOf('@') == '-1'){
var error = true;
$('#email_error').fadeIn(500);
}else{
$('#email_error').fadeOut(500);
}
if(message.length == 0 || message == 'Enter your comment here.'){
var error = true;
$('#message_error').fadeIn(500);
}else{
$('#message_error').fadeOut(500);
}
if(error == false){
$('#contactsubmit').attr({'disabled' : 'true', 'value' : 'Sending...' });
$.post("contact.php", {"contactemail":$('#contactemail').val(),"contactcomment":$('#contactcomment').val()},function(result){
if(result == 'sent'){
$('#formRemove').remove();
$('#mail_success').fadeIn(500);
}else{
$('#mail_fail').fadeIn(500);
$('#contactsubmit').removeAttr('disabled').attr('value', 'Send The Message');
}
});
}
});
});
</script>
</head>
<body>
<br/><br/>
<div id="content">
<div id="column1a">
<h2>about</h2>
<div id="information" class="box">
<p>These results currently assume that you are playing in an average league. If your league strength differs,
your results will be inaccurate.</p>
<p>Currently, two predictions are displayed. The first prediction is based on an average of observed wins and
loss point values and assumes you will win 13 points and lose 11 points. The second is made using your played
games history. This can only be made if your Battle.net profile recently played history has enough games.</p>
</div>
<h2>contact</h2>
<div id="contactme" class="box center">
<br/>
<form id="contactForm">
<span id="formRemove">
<div id="email_error" class="error">Please enter a valid email.</div>
<input id="contactemail" type="text" name="email" value="Enter your email here." class="contacttext default"/><br/><br/>
<div id="message_error" class="error">Please enter a comment.</div>
<textarea id="contactcomment" name="comment" class="contactcomment default">Enter your comment here.</textarea><br/>
<div id="mail_fail" class="error">Please try again later.</div>
<p id="contactsubmit_p"><input id="contactsubmit" type="submit" value="Contact Me" class="contactbutton" /></p>
</span>
<div id="mail_success" class="success">Thank your for your feedback.</div>
</form>
</div>
</div>
<div id="column1b">
<h2>your promotion</h2>
<div id="prediction" class="box">
<table class="mmr">
<tr>
<td class="mmrHeading">Rank Point Differential</td>
<td class="mmrHeading">Match Making Rating</td>
</tr>
<tr>
<td class="mmrData"><?php printf('%.2f',$rankPointDifferential); ?></td>
<td class="mmrData"><?php printf('%.2f',$matchMakingRating); ?></td>
</tr>
</table><br/><br/>
Estimated games to promotion:<br/>
<?php
if($sc2->getCharacterLeague() == 'master') {
?>
You can not be promoted any further.
<?php
} else {
?>
Based on observed win/loss averages: <?php echo ceil($obsGamesToPromotion) ?> games to be promoted.<br/>
Based on your recently played trends:
<?php
if($gamesToPromotion != 0) {
?>
<?php echo ceil($gamesToPromotion) ?> games to be promoted.<br/>
<?php
} else {
?>
Not enough data to predict.
<?php
}
}
?>
<br/><br/>Your MMR was calculated using <b>MMR = P + U*W*2 - B + K + C</b> with the following values:
<table class="formula">
<tr>
<td class="formulaData">P</td>
<td class="formulaData">Rank Points</td>
<td class="formulaData"><?php echo $sc2->getCharacterRating(); ?></td>
</tr>
<tr>
<td class="formulaData">U</td>
<td class="formulaData">Unspent Bonus Pool</td>
<td class="formulaData"><?php echo $sc2->getBonusPool(); ?></td>
</tr>
<tr>
<td class="formulaData">W</td>
<td class="formulaData">Win Percentage</td>
<td class="formulaData"><?php echo ($w == 'W') ? $winPercent : $w ?></td>
</tr>
<tr>
<td class="formulaData">B</td>
<td class="formulaData">Total Bonus Pool</td>
<td class="formulaData"><?php echo findMaxBonusPool(); ?></td>
</tr>
<tr>
<td class="formulaData">K</td>
<td class="formulaData">Divison Modifier</td>
<td class="formulaData"><?php echo ($k == 'K') ? 0 : $k ?></td>
</tr>
<tr>
<td class="formulaData">C</td>
<td class="formulaData">League Conversion Constant</td>
<td class="formulaData"><?php echo ($c == 'C') ? $MMR_NUMBERS[$sc2->getCharacterLeague()] : $c ?></td>
</tr>
</table>
</div>
<h2>predict again</h2>
<div id="form" class="box center">
<form action="predict.php" method="POST">
<br/>
<input type="text" id="profile" name="profile" value="Enter Your Battle.net Profile URL Here" class="text default"/> <br/><br/>
Enter the following values only if you know what you are doing:<br/><br/>
<input type="text" id="W" value="W" name="W" class="optionaltext default"/>
<input type="text" id="K" value="K" name="K" class="optionaltext default"/>
<input type="text" id="C" value="C" name="C" class="optionaltext default"/><br/><br/>
<input type="submit" disabled="disabled" class="button" value="Make the Prediction!" />
</form><br/>
</div>
</div>
<div class="clear">&nbsp;</div>
</div>
<br/>
<?php
$benchmark['index'] = microtime(true) - $benchmark_start;
$max = array('part' => 'none','time' => 0);
foreach($benchmark as $part=>$time)
{
if($time > $max['time'])
{
$max['time'] = $time;
$max['part'] = $part;
}
$benchmark['total'] += $time;
}
?>
<div id="benchmark">Prepared in <?php printf('%.1f',$benchmark['total']); ?>s.</div>
<div id="copyright">&copy; Andrew Tomaka 2011.</div>
<br/><br/>
</body>
</html>
<!--Array
<?php
print_r($benchmark);
?>
--><?php
//find the max bonus pool based on time assuming 2677 points at 1297620086
function findMaxBonusPool() {
$minutesPassed = (time() - 1297620086) / 60;
return 2677 + ($minutesPassed / 112);
}
function calculateAverageWin($matches) {
$wins = 0;
$winsTotal = 0;
foreach($matches as $match) {
if($match > 0) {
$wins++;
$winsTotal += ($match / 2);
}
}
return $winsTotal / $wins;
}
function calculateAverageLoss($matches) {
$losses = 0;
$lossesTotal = 0;
foreach($matches as $match) {
if($match < 0) {
$losses++;
$lossesTotal += $match;
}
}
return abs($lossesTotal) / $losses;
}
?>