Dragonfly CMS v9 ⇒ Gamers Modules & Blocks :: Archives ⇒ BF2 and BF 2142 Stats feed :: Archived ⇒ Community Forums ⇒ CPG Dragonfly™ CMS
Forum Index Modules & Blocks Gamers Modules & Blocks ⇒ Archives

Archived ⇒ BF2 and BF 2142 Stats feed


I have these scripts:
BF2=<?php $clanid="5350"; function startTag($parser, $name, $attrs) { global $stack; $tag=array("name"=>$name,"attrs"=>$attrs); array_push($stack,$tag); } function cdata($parser, $cdata) { global $stack; $stack[count($stack)-1]['cdata'] .= $cdata; } function endTag($parser, $name) { global $stack; $stack[count($stack)-2]['children'][] = $stack[count($stack)-1]; array_pop($stack); } // 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"; $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; if($valname=="PLAYERNAME") $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 echo "<table align="center" cellpadding="2" cellspacing="0">\n <tr><th colspan="12">Battlefield 2</td></tr>\n <tr><th colspan="12">Clan info/statistics</td></tr>\n <tr><th>ID</td>\n <th>Name</td>\n <th>Tag</td>\n <th>CO</td>\n <th>Score</td>\n <th>TM</td>\n <th>WM</td>\n <th>LM</td>\n <th>Kills</td>\n <th>KillAs.</td>\n <th>Deaths</td>\n <th>Ratio</td>\n </tr>\n"; //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 echo "<tr class="gen">\n <td align="center" class="row1">$clanid</a></td>\n <td class="row1"><a target="_blank" href="$clanurl">$clanname</a></td>\n <td class="row1">$clantag</td>\n <td class="row1"><img border="0" src="./images/flags/$clanCO.png" width="18" height="12"></td>\n <td align="right" class="row1">$clanGS</td>\n <td align="right" class="row1">$clanMA</td>\n <td align="right" class="row1">$clanWI</td>\n <td align="right" class="row1">$clanLO</td>\n <td align="right" class="row1">$clanK</td>\n <td align="right" class="row1">$clanKA</td>\n <td align="right" class="row1">$clanD</td>\n <td align="right" class="row1">$clanRATIO</td>\n </tr>\n </table>"; // Prepare Player Stats table echo "<table align="center" cellpadding="2" cellspacing="0">\n <tr><th colspan="12">Player Stats</td></tr>\n <tr>\n"; echo " <th>Rank</td>\n <th>Status</td>\n <th>Name</td>\n <th>CO</td>\n <th>GS</td>\n <th>TM</td>\n <th>WM</td>\n <th>LM</td>\n <th>TT</td>\n <th>SM</td>\n <th>SH</td>\n </tr>\n"; $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 if($playername!="") echo "<tr class="gen">\n <td align="center" class=$row><img border="0" src="./images/ranksmall_$playerrank.gif" width="16" height="16"></td>\n <td class=$row><img border="0" src="./images/$statuspic" width="42" height="16"></td>\n <td class=$row><a target="_blank" href="$playerurl">$playername</a></td>\n <td class=$row><img border="0" src="./images/flags/$playerCO.png" width="18" height="12"></td>\n <td align="right" class=$row>$playerGS</td>\n <td align="right" class=$row>$playerMA</td>\n <td align="right" class=$row>$playerWI</td>\n <td align="right" class=$row>$playerLO</td>\n <td align="right" class=$row>$playerTI</td>\n <td align="right" class=$row>$avescore</td>\n <td align="right" class=$row>$hrscore</td>\n </tr>\n"; } echo "<tr class="gensmall"><td class="row1" colspan="12" align="center">CO = Country | GS = Global Score | TM = Total Matches | WM = Won Matches | LM = Lost Matches <br> SM = Average Score/Match | SH = Average Score/hr</td></tr>\n <tr class="gensmall"><td class="row2" colspan="12" align="center">Click the player name to get more detailed stats @ bf2tracker.com</td></tr>\n </table>\n"; ?>

2142=<?php $clanid="145"; function startTag($parser, $name, $attrs) { global $stack; $tag=array("name"=>$name,"attrs"=>$attrs); array_push($stack,$tag); } function cdata($parser, $cdata) { global $stack; $stack[count($stack)-1]['cdata'] .= $cdata; } function endTag($parser, $name) { global $stack; $stack[count($stack)-2]['children'][] = $stack[count($stack)-1]; array_pop($stack); } // 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://bf2142tracker.com/livefeed/xml_clanprofile.php?clanid=$clanid"; $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; if($valname=="PLAYERNAME") $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 echo "<table align="center" cellpadding="2" cellspacing="0">\n <tr><th colspan="12">Battlefield 2142</td></tr>\n <tr><th colspan="12">Clan info/statistics</td></tr>\n <tr><th>ID</td>\n <th>Name</td>\n <th>Tag</td>\n <th>CO</td>\n </tr>\n"; //get clan info foreach($claninfo as $key => $value) { $clanname=$claninfo[CLANNAME]; $clanid=$claninfo[CLANID]; $clanurl=$claninfo[CLANSTATSURL]; $clantag=$claninfo[CLANTAG]; $clanCO=$claninfo[CLANCOUNTRY]; } //show in table echo "<tr class="gen">\n <td align="center" class="row1">$clanid</a></td>\n <td class="row1"><a target="_blank" href="$clanurl">$clanname</a></td>\n <td class="row1">$clantag</td>\n <td class="row1"><img border="0" src="./images/flags/$clanCO.png" width="18" height="12"></td>\n </tr>\n </table>"; // Prepare Player Stats table echo "<table align="center" cellpadding="2" cellspacing="0">\n <tr><th colspan="12">Player Stats</td></tr>\n <tr>\n"; echo " <th>Rank</td>\n <th>Status</td>\n <th>Name</td>\n <th>CO</td>\n </tr>\n"; $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]; $playerCO=$playerstats[$key][PLAYERCOUNTRY]; // 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 if($playername!="") echo "<tr class="gen">\n <td align="center" class=$row><img border="0" src="./images/ranksmall_$playerrank.png" width="16" height="16"></td>\n <td class=$row><img border="0" src="./images/$statuspic" width="42" height="16"></td>\n <td class=$row><a target="_blank" href="$playerurl">$playername</a></td>\n <td class=$row><img border="0" src="./images/flags/$playerCO.png" width="18" height="12"></td>\n </tr>\n"; } echo "<tr class="gensmall"><td class="row1" colspan="12" align="center">Click the player name to get <br>more detailed stats @ bf2142tracker.com</td></tr>\n </table>\n"; ?>
This is what they look like real world:
BF2 STATS
BF2142 STATS

How do I get them integrated into my website www.cripplemilitia.com? Thank you.

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux / Apache / 4.1.22-standard / 4.4.6/ 9.1.2.1


Do you want them as modules, or blocks, or both?

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


Modules would be cool

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux / Apache / 4.1.22-standard / 4.4.6/ 9.1.2.1


O.k. I will try to get them put together for you as soon as I have time. It will probably be a few days. Maybe weeks if my daughter is born Wink

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


I do appreciate your effort. Many thanks and bigger congratulations on the upcoming new family member!!!

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux / Apache / 4.1.22-standard / 4.4.6/ 9.1.2.1


Thanks for the congrats. I didn't have alot of time, so I pretty much just dropped your code into a module framework. There's no admin for changing the clan or anything, but it'll do what you wanted. The only other thing I changed was so it pulls the images from the bf2142 server. I figured you found a BF2 module, but if you decide you want it i can do that one too. Just uzip the file and ftp the bf2142 directory into the modules directory on your server.

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


Cool man I will check it out! Dude it looks good! However the tracker rank images suck can I get it using the standard images I have. I would like the BF2 one as well but like the 2142 with out the extra stats. Just the rank online/offline and country of the player. Nice work!

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux / Apache / 4.1.22-standard / 4.4.6/ 9.1.2.1


Never mind I figured it out with your first module. Thank you for your help! I understand how to incorporate it into my site now.

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux / Apache / 4.1.22-standard / 4.4.6/ 9.1.2.1


Glad it worked for you and you were able to figure out the rest on your own!

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

All times are UTC