Back to Syahjordan.com

WoW Progress Widget

This is a widget I made that pulls data from WoWProgress.com. It displays the top 10 ranked guilds based on region, tier, and group size. The nice people at WoW Progress have a json api that we can use to get ranking information for an individual guild. They also allow you to download information for all guilds on a realm at one time. Unfortunately, neither of these options worked for me. This widget reads directly from the html tables on the WoW Progress webpage. The page that the data pulls from is determined by the parameters passed to the widget.

Loading

I'm not sure why I didn't have wprankings.php just return json or html, but whatever. Maybe I'll go do that one day? It would certainly make it easier on me for updates, (i.e. better handling for tiers 15 and 16). Below I've included the files that serve the widget as direct output. Feel free to copy/paste them and use them anywhere. Some more future work could be to update the options list to dynamically pull the list of tiers and regions available from WoW Progress.

wprankings.php
<?php function wprankings($region, $tier, $groupSize) { $returnString = ""; class Guild { public $name; public $rank; public $server; public $groupSize; public $faction; public $link; } class Server { public $name; public $region; } $topten[] = array(); $regionPath = $region == "" ? "" : "/".strtolower($region); $tierPath = $tier == "" ? "" : "/rating.tier".$tier; $groupPath = $groupSize == "" || $tier == "" ? "" : "_".$groupSize; $url = "http://www.wowprogress.com/pve".$regionPath.$tierPath.$groupPath; $file = file_get_contents ($url); $gStart = strpos($file, "id=\"rating_container\""); $start = strpos($file, "<table class=\"rating\">", $gStart); $end = strpos($file, "</table>", $start); $table = substr($file, $start, $end - $start); $rowstart = strpos($table, "<tr>"); $rowend = strrpos($table, "</tr>"); $tablerows = substr($table, $rowstart, $rowend - $rowstart); $rows = explode("<tr>", $tablerows); for($i = 2; $i < min(12, count($rows)); $i++) { $cells = explode("<td>", $rows[$i]); //$cells is now [empty, rank, name, realm, progress, criteria] $guild = new Guild(); $guild->rank = $i-1; $nameStart = strpos($cells[2], "<nobr>") + 6; $nameEnd = strpos($cells[2], "</nobr>"); $guild->name = substr($cells[2], $nameStart, $nameEnd - $nameStart); $factionStart = strpos($cells[2], "class=\"guild ") + 13; $factionEnd = strpos($cells[2], "e", $factionStart) +1; $guild->faction = substr($cells[2], $factionStart, $factionEnd - $factionStart); $guild->server = new Server(); $groupSizeStart = strpos($cells[2], "(") + 1; $guild->groupSize = ($tier >= 17 || $tier == "") ? ("") : ($groupSize == "" ? substr($cells[2], $groupSizeStart, 2) : $groupSize); $guildLinkStart = strpos($cells[2], "href=") + 6; $guildLinkEnd = strpos($cells[2], "\"", $guildLinkStart); $guild->link = substr($cells[2], $guildLinkStart, $guildLinkEnd - $guildLinkStart); $serverStart = strpos($cells[3], ">") + 1; $serverEnd = strpos($cells[3], "<", $serverStart); $server = substr($cells[3], $serverStart, $serverEnd - $serverStart); if($region == "") { $guild->server->name = substr($server, 3); $guild->server->region = substr($server, 0, 2); } else { $guild->server->name = $server; $guild->server->region = $region; } $topten[$i-2] = $guild; } $returnString .= "<div class=\"wprankings\">\n" ."<div class=\"wprankings_head\">\n" ."<div><a href=\"$url\"><span>WoW</span> " ."<span>Progress.com</span></a></div>\n" ."<div><span class=\"wprankings_region\">" .($region == "" ? "World" : $region)."</span> " ."<span class=\"wprankings_groupSize\">" .(($tier == "") || ($tier >= 17) ? "Mythic Difficulty" : ($groupSize == "" ? "10 &amp; 25 Man Raid" : $groupSize." Man Raid")) ."</span></div>\n" ."</div>\n" ."<ul>\n"; for($i = 0; $i < count($topten); $i++) { $returnString .= "<li>\n" ."<span class=\"".($topten[$i]->rank <= 10 ? "legendary" : "epic")."\">" .$topten[$i]->rank ."</span>\n" ."<a href=\"http://www.wowprogress.com".$topten[$i]->link ."\" class=\"".$topten[$i]->faction."\">".$topten[$i]->name."</a>\n" .($groupSize == "" ? "<span class=\"wprankings_groupSize\">" .$topten[$i]->groupSize."</span>\n" : "") .($region == "" ? "<span>".$topten[$i]->server->region." - " .$topten[$i]->server->name."</span>" : "<span>".$topten[$i]->server->name."</span>") ."\n" ."</li>\n"; } $returnString .= "</ul>\n</div>\n"; return $returnString; } ?>
ajaxwprankings.php
<?php include_once 'wprankings.php'; $region = ""; $tier = ""; $groupSize = ""; if(isset($_GET['region'])) $region = strtoupper($_GET['region']); if(isset($_GET['tier'])) $tier= strtoupper($_GET['tier']); if(isset($_GET['groupSize'])) $groupSize = strtoupper($_GET['groupSize']); echo wprankings($region, $tier, $groupSize); ?>
wprankings_options.php
<div class="wprankingsAjax"> <label for="tier">Tier</label> <select class="wpFilter" id="tier"> <option value="">Current</option> <option value="17">17</option> <option value="16">16</option> <option value="15">15</option> <option value="14">14</option> <option value="13">13</option> <option value="12">12</option> <option value="11">11</option> <option value="10">10</option> <option value="9">9</option> <option value="8">8</option> <option value="7">7</option> </select> <label for="region">Region</label> <select class="wpFilter" id="region"> <option value="">Any</option> <option value="US">US</option> <option value="EU">EU</option> <option value="DE">DE</option> <option value="EN">EU (EN)</option> <option value="FR">FR</option> <option value="ES">ES</option> <option value="RU">RU</option> <option value="TW">TW</option> <option value="KR">KR</option> <option value="CN">CN</option> </select> <label for="groupSize">Group Size</label> <select class="wpFilter" id="groupSize"> <option value="">Any</option> <option value="10">10</option> <option value="25">25</option> </select> </div> <div class="wprankings_container" id="ajaxwp"> <div style="width:285px;height:260px;text-align:center;"> <img src="/images/ajax-loader-large.gif" title="Loading" alt="Loading" /> </div> </div>
wprankings.css
.wprankings .horde { color: #CD2B00; } .wprankings .alliance { color: #0C81CE; } .wprankings .legendary { color: #FF8000; } .wprankings .epic { color: #A335EE; } .wprankings { width:275px; height:250px; background-color:#222222; font-size:12px; color:#ffffff; padding:5px; -moz-border-radius: 15px; border-radius: 15px; text-align: left; } .wprankings > ul { list-style-type:none; margin:0; padding:0; width:100%; } .wprankings > ul > li { width:100%; float:left; } .wprankings > ul > li > a, .wprankings > ul > li > span { float:left; font-weight:bold; } .wprankings > ul > li > span.wprankings_groupSize { font-weight:normal; margin-left:5px; } .wprankings > ul > li > span:first-child { width:20px; font-weight:normal; } .wprankings > ul > li > span:last-child { float:right; font-weight:normal; } .wprankings_head { font-size: 14px; } .wprankings_head > div { text-align:center; } .wprankings_head > div:last-child { margin-top:20px; margin-bottom:10px; } .wprankings_head a:link, .wprankings_head a:visited, .wprankings_head a:hover, .wprankings_head a:active { text-decoration:none; color: #ffffff; } .wprankings_head a > span { font-size:20px; } .wprankings_head a > span:first-child { color: #0C81CE; } .wprankings a:hover { color: #ffffff; } .wprankingsAjax { text-align: center; }
wp.js
(function ($) { $(function() { $('.wpFilter').change(function() { if(parseInt($('#tier').val()) >= 17) { $('#groupSize').val(''); } else if(parseInt($('#tier').val()) > 14) { if($('#groupSize').val() == '') { $('#groupSize').val(25); } } var ajaxUrl = '/ajaxwprankings.php' if($('#tier').val() != 'default') ajaxUrl += (ajaxUrl == '/ajaxwprankings.php' ? '?' : '&') + 'tier=' + $('#tier').val(); if($('#region').val() != 'default') ajaxUrl += (ajaxUrl == '/ajaxwprankings.php' ? '?' : '&') + 'region=' +$('#region').val(); if($('#groupSize').val() != 'default') ajaxUrl += (ajaxUrl == '/ajaxwprankings.php' ? '?' : '&') + 'groupSize=' + $('#groupSize').val(); $.ajax({ url: ajaxUrl, method: 'GET', dataType: 'html', success: function(data) { $('#ajaxwp').html(data); }, error: function() { $('#ajaxwp').html('Error loading widget via ajax.'); } }); }).trigger('change'); }); })(jQuery);