Support ⇒ Gamers Modules & Blocks ⇒ Battletracker Clan Stats for DF ⇒ Community Forums ⇒ CPG Dragonfly™ CMS
Forum Index Modules & Blocks Gamers Modules & Blocks

Battletracker Clan Stats for DF Reply to topic


Just a headsup that I have added some "modules" to our site that pull your clans stats from battletracker into Dragonfly.

This is code that was originally made for DF by jzky, I simply tweaked it a little, and created a template for it as well.

Examples here.

www.junglewraiths.net/...2142_Stats

www.junglewraiths.net/...=Bf2_Stats

www.junglewraiths.net/...=Bc2_Stats

Index.php

<?php // php script - small mod by jzky to work with DragonflyCMS // if (!defined('CPG_NUKE')) { exit; } require_once('header.php'); // enter your Clan ID - Hope to get this into an admin part.. // $clanid="9544"; // note to self - remove if used with xml parser block function startTag($parser, $name, $attrs) { global $stack; $tag=array("name"=>$name,"attrs"=>$attrs); array_push($stack,$tag); } function cdata($parser, $cdataf) { global $stack, $cdata; $stack[count($stack)-1]['cdata'] = $cdataf; $cdata .= $cdataf; return $cdata; } function endTag($parser, $name) { global $stack; $stack[count($stack)-2]['children'][] = $stack[count($stack)-1]; array_pop($stack); } // Added for images global $module_name; // Parse XML $stack = array(); $claninfo = array(); $clanstats = array(); $playerstats = array(); $xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, 'startTag', 'endTag'); xml_set_character_data_handler($xml_parser, 'cdata'); // $xmllink='http://bf2tracker.com/livefeed/xml_clanprofile.php?clanid='.$clanid; $xmllink='http://battletracker.com/clanfeed/bc2/9544/claninfo.xml'; $data = xml_parse($xml_parser,file_get_contents($xmllink)); if(!$data) die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); xml_parser_free($xml_parser); // Get Data // Get Clan Profile Data for($i = 0; $i < sizeof($stack[0]['children'][0]['children']); $i++) { $valname=$stack[0]['children'][0]['children'][$i]['name']; $claninfo[$valname]=$stack[0]['children'][0]['children'][$i]['cdata']; } // Get Clan Stats Data for($i = 0; $i < sizeof($stack[0]['children'][1]['children']); $i++) { $valname=$stack[0]['children'][1]['children'][$i]['name']; $clanstats[$valname]=$stack[0]['children'][1]['children'][$i]['cdata']; } // Get Player Data for($i = 0; $i < sizeof($stack[0]['children'][2]['children']); $i++) { for($x = 0; $x < sizeof($stack[0]['children'][2]['children'][$i]['children']); $x++) { $valname=$stack[0]['children'][2]['children'][$i]['children'][$x]['name']; $value=$stack[0]['children'][2]['children'][$i]['children'][$x]['cdata']; if($valname=='PLAYERID') {$pid=$value;} $playerstats[$pid][$valname]=$value; } } // Now we have 3 arrays with all stats and infos // print_r($claninfo); //print_r($clanstats); // print_r($playerstats); // Prepare table for info/stats //get clan info foreach($claninfo as $key => $value) { $clanname=$claninfo['CLANNAME']; $clanid=$claninfo['CLANID']; $clanurl=$claninfo['CLANSTATSURL']; $clantag=$claninfo['CLANTAG']; $clanCO=$claninfo['CLANCOUNTRY']; } // get Clan Stats foreach($clanstats as $key => $value) { $clanK=$clanstats['KILLS']; $clanKA=$clanstats['KILLASS']; $clanD=$clanstats['DEATHS']; $clanGS=$clanstats['SCORE']; $clanRATIO=$clanstats['KDRATIO']; $clanMA=$clanstats['MATCHES']; $clanWI=$clanstats['WINS']; $clanLO=$clanstats['LOSS']; } //show in table $cpgtpl->assign_vars(array( 'S_HEAD' => 'Clan info/statistics', 'S_ID' => 'ID', 'S_NAME' => 'Name', 'S_TAG' => 'Tag', 'S_CO' => '', 'S_SCORE' => 'Score', 'S_TM' => 'TM', 'S_WM' => 'WM', 'S_LM' => 'LM', 'S_KILLS' => 'Kills', 'S_KILLAS' => 'KillAs', 'S_DEATHS' => 'Deaths', 'S_RATIO' => 'Ratio', 'S_CLANID' => $clanid, 'L_CLANURL' => $clanurl, 'S_CLANNAME' => $clanname, 'S_CLANTAG' => $clantag, 'S_CLANCO' => $clanCO, 'S_CLANGS' => $clanGS, 'S_CLANMA' => $clanMA, 'S_CLANWI' => $clanWI, 'S_CLANLO' => $clanLO, 'S_CLANK' => $clanK, 'S_CLANKA' => $clanKA, 'S_CLAND' => $clanD, 'S_CLANRATIO' => $clanRATIO, 'S_PLAYSTAT' => 'Player Stats', 'S_RANK' => 'Rank', 'S_STATUS' => 'Status', 'S_GS' => 'GS', 'S_TT' => 'TT', 'S_SM' => 'SM', 'S_SH' => 'SH', )); // remove/add pictures depending how many members you have in your clan. // Also change the rowspan to suit. remove the first cell if you dont want the pics at all $row="row2"; //sorting by global score function sort_by_gscore($a, $b) {return strnatcmp($b["PLAYERGLOBALSCORE"],$a["PLAYERGLOBALSCORE"]);} usort($playerstats,'sort_by_gscore'); // get player stats foreach($playerstats as $key => $value) { $playername=$playerstats[$key]['PLAYERNAME']; $playerurl=$playerstats[$key]['PLAYERSTATSURL']; $playerid=$playerstats[$key]['PLAYERID']; $playerGS=$playerstats[$key]['PLAYERGLOBALSCORE']; $playerCO=$playerstats[$key]['PLAYERCOUNTRY']; $playerMA=$playerstats[$key]['PLAYERMATCHES']; $playerWI=$playerstats[$key]['PLAYERWINS']; $playerLO=$playerstats[$key]['PLAYERLOSS']; $playerTI=$playerstats[$key]['PLAYERTIME']; // average score/match if ($playerGS>0) $avescore=round($playerGS/$playerMA, 1); else $avescore="N/A"; // playing time in hrs if ($playerstats[$key]['PLAYERTIME']> 0) $playerTI=round(($playerstats[$key]['PLAYERTIME'])/3600, 1); else $playerTI=0.0; // average score/hr if (($playerGS>0) and ($playerTI>0)) $hrscore=round($playerGS/$playerTI, 1); else $hrscore="N/A"; if($playerstats[$key]['PLAYERRANK']!="") $playerrank=$playerstats[$key]['PLAYERRANK']; else $playerrank=0; if($playerstats[$key]['PLAYERCOUNTRY']!="-") $playerCO=$playerstats[$key]['PLAYERCOUNTRY']; else $playerCO="unknown"; if($playerstats[$key]['PLAYERSTATUS']=="1") $statuspic="ponline.gif"; else $statuspic="poffline.gif"; //change the row color if ($row=='row2') { $row='row1'; } else { $row='row2'; } // print player stats $cpgtpl->assign_block_vars('stat', array( 'ROW' => $row, 'I_RANKSML' => 'modules/'.$module_name.'/images/ranksmall_'.$playerrank.'.gif', 'I_STATUS' => 'modules/'.$module_name.'/images/'.$statuspic, 'I_CO' => 'modules/'.$module_name.'/images/flags/'.$playerCO.'.gif', 'L_PLAYER_URL' => $playerurl, 'S_PLAYERNAME' => $playername, 'S_GS' => $playerGS, 'S_MA' => $playerMA, 'S_WI' => $playerWI, 'S_LO' => $playerLO, 'S_TI' => $playerTI, 'S_AVSCORE' => $avescore, 'S_HSCORE' => $hrscore, )); } $cpgtpl->assign_vars(array( 'S_FOOTER1' => 'CO = Country | GS = Global Score | TM = Total Matches | WM = Won Matches | LM = Lost Matches <br> SM = Average Score/Match | SH = Average Score/hr', 'S_FOOTER2' => 'Click the player name to get more detailed stats @ bf2tracker.com', )); $cpgtpl->set_filenames(array('bf2' => 'bf2_stats/index.html')); $cpgtpl->display('bf2');

Index.html

<table align="center" cellpadding="2" cellspacing="0" class="forumline" width="100%"> <tr class="gen"> <td class="catstats" align="center" colspan="11">Clan info/statistics</th> </tr><tr> <th width="5%">ID</th> <th width="15%">Name</th> <th width="5%">Tag</th> <th width="10%">Score</th> <th width="10%">Matches</th> <th width="10%">Wins</th> <th width="10%">Losses</th> <th width="10%">Kills</th> <th width="10%">KillAssists</th> <th width="10%">Deaths</th> <th width="5%">Ratio</th> </tr><tr class="gen"> <td align="center" class="row1">{S_CLANID}</a></td> <td class="row1" align="center"><a target="_blank" href="{L_CLANURL}">{S_CLANNAME}</a></td> <td class="row1" align="center">{S_CLANTAG}</td> <td class="row1" align="center">{S_CLANGS}</td> <td align="center" class="row1">{S_CLANMA}</td> <td align="center" class="row1">{S_CLANWI}</td> <td align="center" class="row1">{S_CLANLO}</td> <td align="center" class="row1">{S_CLANK}</td> <td align="center" class="row1">{S_CLANKA}</td> <td align="center" class="row1">{S_CLAND}</td> <td align="center" class="row1">{S_CLANRATIO}</td> </tr> </table> <br /> <table align="center" cellpadding="2" cellspacing="0" class="forumline" width="100%"> <tr class="gen"> <td class="catstats" align="center" colspan="11">Player Stats</th> </tr><tr> <th width="5%">Rank</th> <th width="5%">Flag</th> <th width="5%">Status</th> <th width="15%">Name</th> <th width="10%">Score</th> <th width="10%">Matches</th> <th width="10%">Wins</th> <th width="10%">Losses</th> <th width="10%">Time</th> <th width="10%">S/M</th> <th width="10%">S/H</th> </tr> <!-- BEGIN stat --> <tr class="gen"> <td align="center" class="{stat.ROW}"><img border="0" src="{stat.I_RANKSML}" width="16" height="16"></td> <td align="center" class="{stat.ROW}"><img border="0" src="{stat.I_CO}" width="18" height="12"></td> <td align="center" class="{stat.ROW}"><img border="0" src="{stat.I_STATUS}" width="42" height="16"></td> <td align="center" class="{stat.ROW}"><a target="_blank" href="{stat.L_PLAYER_URL}"/>{stat.S_PLAYERNAME}</a></td> <td align="center" class="{stat.ROW}">{stat.S_GS}</td> <td align="center" class="{stat.ROW}">{stat.S_MA}</td> <td align="center" class="{stat.ROW}">{stat.S_WI}</td> <td align="center" class="{stat.ROW}">{stat.S_LO}</td> <td align="center" class="{stat.ROW}">{stat.S_TI}</td> <td align="center" class="{stat.ROW}">{stat.S_AVSCORE}</td> <td align="center" class="{stat.ROW}">{stat.S_HSCORE}</td> </tr> <!-- END stat --> <tr class="gen"> <td class="row3" colspan="12" align="center">GS = Global Score | TM = Total Matches | WM = Won Matches |LM = Lost Matches <br> TT = Total Time | S/M = Average Score/Match | S/H = Average Score/hr</td> </tr><tr class="genmed"> <td class="row2" colspan="12" align="center">Click the player name to get more detailed stats @ bf2tracker.com</td> </tr> </table></td></tr></table>

Enjoy. Very Happy

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
2.6.18-164.11.1.el5xen/2.2.13/5.0.89-community-log/5.2.11/9.3.3.0


Hi have you any instructions for nooooobs so that i can get this on my site plz m8 Smile

Thanx In Advance To All That Help Me

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
9.2.1


It only works if you have a battletracker clan, if you want BC2 stats then better off using the BC2 Stats module available here.

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
2.6.18-164.11.1.el5xen/2.2.13/5.0.89-community-log/5.2.11/9.3.3.0

All times are UTC


Jump to: