This repository has been archived on 2026-03-25. You can view files and clone it, but cannot push or open issues or pull requests.
league-search/index.php
2015-06-30 01:06:38 -07:00

573 lines
21 KiB
PHP
Executable file

<?php
/**
* League Of Legends Summoner Search
*
* This is League Of Legends Summoner Search Description
*
* @author Juyoung Lee
* @copyright 2015 lolsearch.tk
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version 1.0
*/
// quora.com/How-do-I-use-the-League-of-Legends-API-What-langauge-do-I-need-to-know-to-make-something-that-looks-up-summoners-like-LoLKing-or-LoLNexus
class Summoner {
/**
* The League of Legends API Key
*
* @var string
*/
const API_KEY = '66ea8d47-903a-4d41-ad8a-93ac89964ceb';
/**
* The API Base URL
*
* @var string
*/
const API_URL = 'https://na.api.pvp.net/api/lol/';
}
/**
* get summoner name by summoner id
*
* @param $summonerId summoner id
* @return mixed summonerName
*/
function getSummonerName($summonerId)
{
$apiKey = Summoner::API_KEY;
$json = file_get_contents('https://na.api.pvp.net/api/lol/static-data/na/v1.2/champion/'. $summonerId .'?api_key=' . $apiKey);
$link = json_decode($json);
return $link->key;
}
/**
* get item name and description by item id
*
* @param $itemId item id
* @return $item item name and description
*/
function getItemText($itemId) {
$json = file_get_contents(Summoner::API_URL.'static-data/na/v1.2/item/'.$itemId.'?api_key='.Summoner::API_KEY);
$link = json_decode($json);
$item = $link->name . '
'.$link->description;
$item = str_replace("<br>", '
', $item);
$item = strip_tags($item);
return $item;
}
function itemDescription($itemId)
{
$itemId_json = file_get_contents('https://na.api.pvp.net/api/lol/static-data/na/v1.2/item/'.$itemId.'?api_key='.Summoner::API_KEY);
$itemId_result = json_decode($itemId_json);
$first_result = $itemId_result->name . '
'.$itemId_result->description;
$replace_breakline = str_replace(array("<br>"), '
', $first_result);
$replace_space = strip_tags($replace_breakline);
return $replace_space;
}
$apiKey = Summoner::API_KEY;
$inputSummonerName = $_GET['userName'];
$inputSummonerName = str_replace(" ", "", $inputSummonerName);
$summonerName = strtolower($inputSummonerName);
$summonerId = 0;
$summonerJson = file_get_contents('https://na.api.pvp.net/api/lol/na/v1.4/summoner/by-name/' . $summonerName . '?api_key=' . $apiKey, true);
$summoner = json_decode($summonerJson)->$summonerName;
$summonerId = $summoner->id;
$summonerName = $summoner->name;
$summonerRevisionDate = $summoner->revisionDate;
$summonerLevel = $summoner->summonerLevel;
$profileId = $summoner->profileIconId;
?>
<?php
$read = file("./txt/counter.txt");
$count = trim($read[0]);
$sum_count = $count + 1;
$fp = fopen("./txt/counter.txt", "w");
fwrite($fp, $sum_count);
fclose($fp);
$count_collected = $sum_count;
$ip_collected = $_SERVER['REMOTE_ADDR'];
$date_collected = date('YmdHis', time());
$summonerName_collected = $summonerName;
if(!$summonerName_collected)
{
$summonerName_collected = 'NULL';
}
$result_collected = $count_collected . '-' . $summonerName_collected . '-' . $date_collected . '-' . $ip_collected . PHP_EOL;
$fp = fopen("./txt/track.txt", "a");
fputs($fp, $result_collected);
fclose($fp);
?>
<html>
<head>
<title>Summoner <?php if($summonerName){ echo '- ' . $summonerName;} ?> - urgo.tk</title>
<meta http-equiv="Content-Type" content="text/html; utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script src="./js/jquery-1.10.2.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script src="./js/nprogress.js"></script>
<script src="./js/summoner.js"></script>
<link rel="shortcut icon" href="./img/favicon.ico"/>
<link rel="stylesheet" href="./css/nprogress.css"/>
<link rel="stylesheet" href="./css/summoner.css"/>
</head>
<body style="background-image: url('http://ddragon.leagueoflegends.com/cdn/img/champion/splash/<?php include('bgImage.php'); echo '\')'; ?>">
<?php
/* if you want specific background,
<body style="background-image: url('http://ddragon.leagueoflegends.com/cdn/img/champion/splash/<?php echo 'Heimerdinger_0.jpg\')'; ?>">
IF NOT,
<body style="background-image: url('http://ddragon.leagueoflegends.com/cdn/img/champion/splash/<?php include('bgImage.php'); echo '\')'; ?>">
*/
?>
<script>
NProgress.start();var interval=setInterval(function(){NProgress.inc()},7e3);jQuery(window).load(function(){clearInterval(interval),NProgress.done()}),jQuery(window).unload(function(){NProgress.start()});
</script>
<div class="input-form" style="<?php
if(!$summonerName){
echo "margin:20% auto 0;";
}
else{
echo "margin:0% auto 0;";
}
?>">
<div class="title" style="font-size:12px;"><a class="title" href="./">URGO.TK</a> for NA</div>
<form action="./">
<label for="name">Summoner Name</label>
<input type="text" name="userName" tabindex="1" id="name" class="input-form-name" placeholder="Summoner Name" value="<?php echo $summonerName; ?>" maxlength="25"></input>
&nbsp;&nbsp;&nbsp; <!-- [TAB] -->
<label for="region">Region</label>
<select name="region" tabindex="2" id="region" class="input-form-region">
<option value="BR" disabled>Brazil</option>
<option value="EUNE" disabled>EU Nordic &amp; East</option>
<option value="EUW" disabled>EU West</option>
<option value="KR" disabled>Korea</option>
<option value="LAN" disabled>Latin America North</option>
<option value="LAS" disabled>Latin America South</option>
<option value="NA" selected="selected">North America</option>
<option value="OCE" disabled>Oceania</option>
<option value="RU" disabled>Russia</option>
<option value="TR" disabled>Turkey</option>
</select>
<input type="submit" value="Submit" id="submit" class="input-form-submit" onclick="summonerLookUp();" >
<form>
</div>
<?php
if(!$summonerName && strlen($inputSummonerName) > 0){
echo '<div class="result">SORRY, ERROR OCCURRED DUE TO ONE OR MORE FOLLOWING REASONS
<span style="color:#FF1C1C; font-size:15px; "><br/>:Bad request<br/>:Unauthorized<br/>:No summoner data found for any specified inputs<br/>:Rate limit exceeded<br/>:Internal server error<br/>:Service unavailable<br/>:You are special <span style="font-size:12px;">&hearts;</span></span>
</div>
</body>
</html>';
exit;
} else if($summonerName){
?>
<?php
// calculate reivison date
$epoch = microtime(true);
$epochDiffSeconds = $epoch - ($summonerRevisionDate / 1000);
$epochMinutes = floor( ($epochDiffSeconds / 60) % 60 );
$epochHours = floor( ($epochDiffSeconds / 3600) );
$epochDays = floor( $epochHours / 24 );
$statusDotColor = "00A500"; // 00A500 green
$epochString = " active ";
if($epochDays > (365 * 2))
{
$epochString .= "several years ";
$statusDotColor = "272727"; // 272727 gray
}
else if($epochDays > 365)
{
$epochString .= "over a year ";
$statusDotColor = "272727"; // 272727 gray
}
else if($epochDays > 180)
{
$epochString .= "over 6 months ";
$statusDotColor = "272727";
}
else if($epochDays > 90)
{
$epochString .= "over 3 months ";
$statusDotColor = "f00";
}
else if($epochDays > 30)
{
$epochString .= "over a month ";
$statusDotColor = "f00";
}
else if($epochDays > 1)
{
$epochString .= $epochDays . " days ";
$statusDotColor = "E5AE00";
}
else if($epochDays == 1)
{
$epochString .= " a day ";
$statusDotColor = "E5AE00"; //e76000 orange
}
if($epochDays < 2 && $epochHours > 1)
{
$epochString .= $epochHours . " hrs ";
//$statusDotColor = "E5AE00"; //e5ae00 yellow
}
else if($epochDays < 2 && $epochHours == 1)
{
$epochString .= " an hr ";
}
if($epochDays == 0 && $epochMinutes > 1)
{
$epochString .= $epochMinutes . " mins ";
}
else if($epochDays == 0 && $epochMinutes == 1)
{
$epochString .= " one min ";
}
$epochString .= "ago";
if($epochDiffSeconds < (60 * 5) )
{
$epochString = "active now";
}
?>
<div class="result">
<!-- // http://ddragon.leagueoflegends.com/cdn/4.21.1/img/profileicon/0.png -->
<image height="90" width="90" src="http://ddragon.leagueoflegends.com/cdn/5.6.1/img/profileicon/<?php print $profileId; ?>.png" onerror="imgError(this);" class="summoner-icon" />
<span class="summoner-name"><?php print $summonerName . '<span style="cursor:default;">&nbsp;</span><span id="status_dot" style="color:#' . $statusDotColor . '";>&#8226;</span>' ?></span>
<span class="summoner-level"><?php print $summonerLevel; ?></span>
<span title="" id="active-text">
<?php
echo $epochString;
?>
</span>
<?php
$json_tier = file_get_contents('https://na.api.pvp.net/api/lol/na/v2.5/league/by-summoner/'. $summonerId .'/entry?api_key=' . $apiKey);
$tier_result = json_decode($json_tier) -> $summonerId;
$summonerTier = $tier_result[0]->tier;
$summonerDivision = $tier_result[0]->entries[0]->division;
if (!$summonerTier){ $summonerTier = 'UNRANKED'; }
/*
if($summonerId == "36821462")
{
$summonerTier = 'CHALLENGER';
$summonerDivision = '';
}
*/
$summonerTier = ucfirst(strtolower($summonerTier));
?>
<a title="<?php echo $summonerTier. ' '. $summonerDivision; ?>" class="tier"><span style="float:right;" title=""><img src="./img/tier/<?php echo $summonerTier; ?>.png" height=100 /></span></a>
<br/>
<?php
// items/spells guide: https://developer.riotgames.com/discussion/riot-games-api/show/I0Al5bbl
$result_recent = file_get_contents('https://na.api.pvp.net/api/lol/na/v1.3/game/by-summoner/'. $summonerId .'/recent?api_key=' . $apiKey);
$recent = json_decode($result_recent);
// foreach( $recent->games as $recentSummary){ var_dump($recentSummary->stats->championsKilled); }
foreach( $recent->games as $recentSummary){
$FINAL_STATS_WIN = $recentSummary->stats->win;
$FINAL_CHAMPIONID = $recentSummary->championId;
$FINAL_STATS_WIN == 1 ? $letterWin = 'VICTORY' : $letterWin ='DEFEAT';
$subType = str_replace(array('_','1x1','2x2','3x3','5x5','6x6'), ' ', ucfirst(strtolower($recentSummary->subType)));
if($recentSummary->subType == 'NONE'){
$subType = 'Custom';
}
$result_champ_name_static_data = file_get_contents('https://na.api.pvp.net/api/lol/static-data/na/v1.2/champion/'. $FINAL_CHAMPIONID .'?api_key=' . $apiKey);
$champName = json_decode($result_champ_name_static_data);
?>
<?php
$timePlayedMinute = gmdate('i', $recentSummary->stats->timePlayed );
$timePlayedSecond = gmdate('s', $recentSummary->stats->timePlayed );
?>
<div class="summoner-recent_belt" style="background-color:<?php if ($letterWin == 'VICTORY' ){echo '#54AAE2';}else{ echo '#EA6358';} ?>;"><?php echo $subType . '&nbsp;<span style="font-size:11px;">'; echo date('M j Y g:s A', $recentSummary->createDate / 1000); echo '</span><span style="float:right"><span style="font-size:11px;vertical-align:center;">' . $timePlayedMinute. 'm ' . $timePlayedSecond . 's' .'</span>&nbsp;'. $letterWin . '&nbsp;</span>'; ?></div>
<div class="summoner-recent" style="background-color:<?php if ($letterWin == 'VICTORY' ){echo 'rgba(140, 237, 253, 0.4)';}else{ echo 'rgba(255, 202, 202, 0.4)';} ?>;">
<a title="<?php print $champName->name.': '.$champName->title; ?> " ><img class="summoner-champion_pic" src="http://ddragon.leagueoflegends.com/cdn/5.6.1/img/champion/<?php echo $champName->key; ?>.png" onerror="imgError(this);" title=""/></a>
<?php
$json_spell1 = file_get_contents('https://na.api.pvp.net/api/lol/static-data/na/v1.2/summoner-spell/'. $recentSummary->spell1 .'?api_key=' . $apiKey);
$summonerSpell1 = json_decode($json_spell1) ;
$json_spell2 = file_get_contents('https://na.api.pvp.net/api/lol/static-data/na/v1.2/summoner-spell/'. $recentSummary->spell2 .'?api_key=' . $apiKey);
$summonerSpell2 = json_decode($json_spell2) ;
$spell1Name = $summonerSpell1 -> name;
$spell2Name = $summonerSpell2 -> name;
$spell1Key = $summonerSpell1 -> key;
$spell2Key = $summonerSpell2 -> key;
$spell1Description = $summonerSpell1 -> description;
$spell2Description = $summonerSpell2 -> description;
?>
<a title="<?php print $spell1Name; ?>
<?php print $spell1Description; ?>" class="spell1"><img class="summoner-spell1" onerror="imgError(this);" src="http://ddragon.leagueoflegends.com/cdn/5.6.1/img/spell/<?php print $spell1Key; ?>.png" title=""/></a>
<a title="<?php print $spell2Name; ?>
<?php print $spell2Description; ?>" class="spell2" ><img class="summoner-spell2" onerror="imgError(this);" src="http://ddragon.leagueoflegends.com/cdn/5.6.1/img/spell/<?php print $spell2Key; ?>.png" title=""/></a>
<?php
$recentSummary->stats->championsKilled ? $championsKilled = $recentSummary->stats->championsKilled : $championKilled = 0;
$recentSummary->stats->numDeaths ? $numDeaths = $recentSummary->stats->numDeaths : $numDeaths = 0;
$recentSummary->stats->assists ? $assists = $recentSummary->stats->assists : $assists = 0;
echo '<div class="table-col0">
<div class="table-col0-kda">
<span id="table-col0-kill">'.$championsKilled.' </span>
<span class="table-col0-slash">/</span>
<span id="table-col0-death">'.$numDeaths.'</span>
<span class="table-col0-slash"> /</span>
<span id="table-col0-assist">'.$assists.'</span>
</div>'
.'<div class="table-col0-kda_ratio">';
if($championsKilled > 0 && $numDeaths == 0)
{
echo 'Perfect ';
}
else if($numDeaths > 0)
{
echo number_format( (($championsKilled + $assists) / $numDeaths), 2).':1 ';
}
else
{
echo $championsKilled + $assists . '.00:0 ';
}
echo 'KDA</div>';
$killTitle = '';
if($recentSummary->stats->firstBlood > 0) $killTitle = 'First Blood';
if($recentSummary->stats->doubleKills > 0) $killTitle = 'Double Kill';
if($recentSummary->stats->tripleKills > 0) $killTitle = 'Triple Kill';
if($recentSummary->stats->quadraKills > 0) $killTitle = 'Quadra Kill';
if($recentSummary->stats->pentaKills > 0) $killTitle = 'Penta Kill';
echo '<div class="table-col0-kill_title" title="">'. $killTitle . '</div></div><div class="table-col1">
<div class="table-col1-level">Level '.$recentSummary->stats->level.'</div>';
$recentSummary->stats->neutralMinionsKilledYourJungle ? $inTeamJungle = $recentSummary->stats->neutralMinionsKilledYourJungle : $inTeamJungle = 0;
$recentSummary->stats->neutralMinionsKilledEnemyJungle ? $inEnemyJungle = $recentSummary->stats->neutralMinionsKilledEnemyJungle : $inEnemyJungle = 0;
$recentSummary->stats->minionsKilled ? $minionsKilled = $recentSummary->stats->minionsKilled : $minionsKilled = 0;
$recentSummary->stats->goldEarned ? $goldEarned = $recentSummary->stats->goldEarned : $goldEarned = 0;
echo '<a style="line-height:120%;" title="total gold: '.number_format($goldEarned) .'
minions ';
if($minionsKilled) {
echo $minionsKilled;
}
else {
echo '0';
}
echo' + monsters ';
$neutralMinionsKilled = $recentSummary->stats->neutralMinionsKilled;
if($neutralMinionsKilled)
{
echo $neutralMinionsKilled.'
'. $inTeamJungle . ' (in Team\'s Jungle)
' . $inEnemyJungle . ' (in Enemy Jungle)
';
}
else
{
echo '0';
}
$minionGoldEarned = 0;
$minionGoldEarned = $minionsKilled + $neutralMinionsKilled;
echo 'CS/min: ' . number_format(($minionGoldEarned) / ($recentSummary->stats->timePlayed / 60), 2).'
" class="gold_a">
<div class="gold" title=""><img width=20 src="./img/gold.png" onerror="imgError(this);" style="vertical-align:middle;cursor:default;" title=""/>'.number_format(($goldEarned / 100), 1) .'k ('. ($minionGoldEarned) . ')</div></a>
<div id="ward">
<a class="ward" title="ward placed:';
$wardPlaced = 0;
$wardKilled = 0;
$wardPlaced = $recentSummary->stats->wardPlaced;
$wardKilled = $recentSummary->stats->wardKilled;
if($wardPlaced)
{
echo number_format($wardPlaced);
}
else{
echo 0;
}
echo '
ward killed:';
if($wardKilled)
{
echo number_format($wardKilled).'">';
}
else{
echo '0">';
}
echo '<span title="">Ward ' . number_format($wardPlaced). ' / ' . number_format($wardKilled).'
</span>
</a>
</div>
</div>';
?>
<div style="position:absolute;">
<a class="item" title="<?php if($recentSummary->stats->item0){echo itemDescription($recentSummary->stats->item0);} ?>" style="position:absolute;margin-top:-55px;margin-left:300px;">
<?php if($recentSummary->stats->item0){ ?><img width=34 height=34 title="" src=" <?php echo 'http://ddragon.leagueoflegends.com/cdn/5.6.1/img/item/'.$recentSummary->stats->item0.'.png'; ?>" onerror="imgError(this);" style="border-radius:5px;border:1px solid #404040;" /><?php } ?>
</a>
<a class="item" title="<?php if($recentSummary->stats->item1){echo itemDescription($recentSummary->stats->item1);}?>" style="position:absolute;margin-top:-55px;margin-left:340px;">
<?php if($recentSummary->stats->item1){ ?><img width=34 height=34 title="" src=" <?php echo 'http://ddragon.leagueoflegends.com/cdn/5.6.1/img/item/'.$recentSummary->stats->item1.'.png'; ?>" onerror="imgError(this);" style="border-radius:5px;border:1px solid #404040;" /><?php } ?>
</a>
<a class="item" title="<?php if($recentSummary->stats->item2){echo itemDescription($recentSummary->stats->item2);} ?>" style="position:absolute;margin-top:-55px;margin-left:380px;">
<?php if($recentSummary->stats->item2){ ?><img width=34 height=34 title="" src=" <?php echo 'http://ddragon.leagueoflegends.com/cdn/5.6.1/img/item/'.$recentSummary->stats->item2.'.png'; ?>" onerror="imgError(this);" style="border-radius:5px;border:1px solid #404040;" /><?php } ?>
</a>
<a class="item" title="<?php if($recentSummary->stats->item3){echo itemDescription($recentSummary->stats->item3);} ?>" style="position:absolute;margin-top:-55px;margin-left:420px;">
<?php if($recentSummary->stats->item3){ ?><img width=34 height=34 title="" src=" <?php echo 'http://ddragon.leagueoflegends.com/cdn/5.6.1/img/item/'.$recentSummary->stats->item3.'.png'; ?>" onerror="imgError(this);" style="border-radius:5px;border:1px solid #404040;" /><?php } ?>
</a>
<a class="item" title="<?php if($recentSummary->stats->item4){echo itemDescription($recentSummary->stats->item4);} ?>" style="position:absolute;margin-top:-55px;margin-left:460px;">
<?php if($recentSummary->stats->item4){ ?><img width=34 height=34 title="" src=" <?php echo 'http://ddragon.leagueoflegends.com/cdn/5.6.1/img/item/'.$recentSummary->stats->item4.'.png'; ?>" onerror="imgError(this);" style="border-radius:5px;border:1px solid #404040;" /><?php } ?>
</a>
<a class="item" title="<?php if($recentSummary->stats->item5){echo itemDescription($recentSummary->stats->item5);} ?>" style="position:absolute;margin-top:-55px;margin-left:500px;">
<?php if($recentSummary->stats->item5){ ?><img width=34 height=34 title="" src=" <?php echo 'http://ddragon.leagueoflegends.com/cdn/5.6.1/img/item/'.$recentSummary->stats->item5.'.png'; ?>" onerror="imgError(this);" style="border-radius:5px;border:1px solid #404040;" /><?php } ?>
</a>
<a class="item" title="<?php if($recentSummary->stats->item6){echo itemDescription($recentSummary->stats->item6);} ?>" style="position:absolute;margin-top:-55px;margin-left:540px;">
<?php if($recentSummary->stats->item6){ ?><img width=34 height=34 title="" src=" <?php echo 'http://ddragon.leagueoflegends.com/cdn/5.6.1/img/item/'.$recentSummary->stats->item6.'.png'; ?>" onerror="imgError(this);" style="border-radius:5px;border:1px solid #404040;" /><?php } ?>
</a>
</div>
<?php
$recentSummary->stats->totalDamageDealtToChampions? $totalDealToChamp = $recentSummary->stats->totalDamageDealtToChampions : $totalDealToChamp = 0;
$recentSummary->stats->totalDamageDealt ? $totalDeal = $recentSummary->stats->totalDamageDealt : $totalDeal = 0;
echo'
<div class="total_damage">
<a class="damage" title="total damage to champions:'.number_format($totalDealToChamp).'
total damage:'.number_format($totalDeal).'"><span title="" id="damage-text">Damage</span><br/>
<span title="">'.number_format($totalDealToChamp).'
<br/>
'.number_format($totalDeal).'
</span>
</a></div>';
$recentSummary->ipEarned? $ipEarned = $recentSummary->ipEarned : $ipEarned = 0;
echo '<div class="ip_earned">+' . $ipEarned . ' IP</div>'; ?>
</div>
<?php
}
?>
<div style="text-align:right;font-size:10px;color:#202020;"><?php echo date('M j Y g:s A') . ' Last Updated&nbsp;&nbsp;'; ?></div>
<!-- Create cookies to save summoner names submitted -->
<?php } // end brace of no error result ?>
<!--<button onClick="window.print()">Print this page</button>-->
<!--<p style="text-align:center;">Print Completed <?php //echo date('m/d/Y h:i:s a', time()); ?></p> -->
</div>
</div>
<div class="footer">
<?php
$statusJson = file_get_contents('http://status.leagueoflegends.com/shards/na');
$statusLink = json_decode($statusJson);
$status = $statusLink->services[0]->status;
echo '<div id="status">current status: NA1 '.$status.'</div>';
?>
<div>interested in League Of Legends? <a id="signup" href="http://signup.leagueoflegends.com/?ref=518b51965e02a423691390" target="_blank">Sign up</a></div>
<div><a id="t_and_c" href="https://developer.riotgames.com/terms#statement" target="_blank">API Terms & Conditions</a></div>
<div><br/>
<div id="copyright">&copy; 2015 <a id="developer_name" href="https://www.facebook.com/profile.php?id=100008396495978" target="_blank" style="">Juyoung Lee</a> & League Of Legends API</div>
</body>
</html>