Code:<?php
if (eregi("block-TWL.php", $PHP_SELF)) {
Header("Location: index.php");
die();
}
//Let keep those pesky little parsing errors to ourselves.
error_reporting(0);
//Added by [STAB]-Ravenstone
//Enter your clan TWL XML URL here.
$file = "http://www.teamwarfare.com/xml/viewteam_v2.asp?team=Armed+Insanity";
//Comment out this file line to see how your script reacts to TWL's XML feed being out.
class LadderInfo1 {
var $ladder;
var $ladderhtmllink;
var $ladderxmllink;
var $rank;
var $wins;
var $losses;
var $forfeits;
var $status;
var $opponentname;
var $opponenthtmllink;
var $opponentxmllink;
var $date;
var $maps;
var $sides;
function LadderInfo1() {
$maps = array();
$sides = array();
}
}
class LeagueInfo1 {
var $league;
var $leaguehtmllink;
var $leaguexmllink;
var $conference;
var $division;
var $status;
var $opponentname;
var $opponenthtmllink;
var $opponentxmllink;
var $date;
var $maps;
function LeagueInfo1() {
$maps = array();
}
}
class Team1 {
var $name;
var $url;
var $email;
var $founder;
var $description;
var $ircserver;
var $channel;
var $status;
var $LadderInfo1;
var $LeagueInfo1;
function Team1() {
$this->LadderInfo1 = array();
$this->LeagueInfo1 = array();
}
}
$Team1 = new Team1();
function formatDate2($datetime) {
$splitDate = split(" ", $datetime);
array_splice($splitDate, 3, 0, date("Y"));
if (count($splitDate) > 0) {
$datetime = $splitdate[0];
for ($j = 0; $j < count($splitDate); $j++) {
$datetime = $datetime." ".$splitDate[$j];
}
$timestamp = (int)strtotime($datetime);
putenv("TZ=EST5EDT");
$datetime = strftime("%D %r %Z", $timestamp);
}
return $datetime;
}
function formatDate3($datetime) {
$timestamp = (int)strtotime($datetime);
putenv("TZ=EST5EDT");
$datetime = strftime("%A, %B %d", $timestamp);
return $datetime;
}
function xml_get_children1($vals, &$i) {
$children = array();
if (isset($vals[$i]['value'])) $children[] = $vals[$i]['value'];
while (++$i < count($vals)) {
switch ($vals[$i]['type']) {
case 'cdata':
$children[] = $vals[$i]['value'];
break;
case 'complete':
$children[] = array(
'tag' => $vals[$i]['tag'],
'attributes' => isset($vals[$i]['attributes'])? $vals[$i]['attributes'] : null,
'value' => $vals[$i]['value'],
);
break;
case 'open':
$children[] = array(
'tag' => $vals[$i]['tag'],
'attributes' => isset($vals[$i]['attributes'])? $vals[$i]['attributes'] : null,
'children' => xml_get_children1($vals, $i),
);
break;
case 'close':
return $children;
}
}
}
function xml_get_tree1($file) {
$data = join('', file($file));
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, $data, $vals, $index);
xml_parser_free($parser);
return array(
'tag' => $vals[0]['tag'],
'attributes' => isset($vals[0]['attributes'])? $vals[0]['attributes'] : null,
'children' => xml_get_children1($vals, $i = 0),
);
}
$tree = xml_get_tree1($file);
foreach ($tree['children'] as $children) {
if ($children['tag'] == "teaminformation") {
$Team1->name = $tree['children'][0]['children'][0]['value'];
$Team1->url = $tree['children'][0]['children'][1]['value'];
$Team1->email = $tree['children'][0]['children'][2]['value'];
$Team1->founder = $tree['children'][0]['children'][5]['value'];
$Team1->description = $tree['children'][0]['children'][6]['value'];
$Team1->ircserver = $tree['children'][0]['children'][3]['value'];
$Team1->channel = $tree['children'][0]['children'][3]['attributes']['channel'];
$Team1->status = $tree['children'][0]['children'][4]['value'];
} else if ($children['tag'] == "competitioninformation") {
if (array_key_exists("children", $children)) {
foreach ($children['children'] as $comp) {
if ($comp['tag'] == "ladder") {
$lil = count($Team1->LadderInfo1);
$Team1->LadderInfo1[$lil] = new LadderInfo1();
$Team1->LadderInfo1[$lil]->ladder = $comp['attributes']['name'];
$Team1->LadderInfo1[$lil]->ladderhtmllink = $comp['children'][0]['children'][0]['value'];
$Team1->LadderInfo1[$lil]->ladderxmllink = $comp['children'][0]['children'][1]['value'];
$Team1->LadderInfo1[$lil]->rank = $comp['children'][1]['value'];
$Team1->LadderInfo1[$lil]->wins = $comp['children'][2]['value'];
$Team1->LadderInfo1[$lil]->losses = $comp['children'][3]['value'];
$Team1->LadderInfo1[$lil]->forfeits = $comp['children'][4]['value'];
$Team1->LadderInfo1[$lil]->status = $comp['children'][5]['attributes']['status'];
} else if ($comp['tag'] == "league") {
$lil = count($Team1->LeagueInfo1);
$Team1->LeagueInfo1[$lil] = new LeagueInfo1();
$Team1->LeagueInfo1[$lil]->league = $comp['attributes']['name'];
$Team1->LeagueInfo1[$lil]->leaguehtmllink = $comp['children'][0]['children'][0]['value'];
$Team1->LeagueInfo1[$lil]->leaguexmllink = $comp['children'][0]['children'][1]['value'];
$Team1->LeagueInfo1[$lil]->conference = $comp['children'][1]['value'];
$Team1->LeagueInfo1[$lil]->division = $comp['children'][2]['value'];
$Team1->LeagueInfo1[$lil]->status = $comp['children'][3]['children'][0]['attributes']['status'];
if (array_key_exists("children", $comp['children'][3])) {
$Team1->LeagueInfo1[$lil]->opponent = $comp['children'][3]['children'][0]['children'][0]['value'];
$Team1->LeagueInfo1[$lil]->opponenthtmllink = $comp['children'][3]['children'][0]['children'][1]['children'][0]['value'];
$Team1->LeagueInfo1[$lil]->opponentxmllink = $comp['children'][3]['children'][0]['children'][1]['children'][1]['value'];
$Team1->LeagueInfo1[$lil]->date = formatDate2($comp['children'][3]['children'][0]['children'][5]['value'])." 10:00 PM EST";
$Team1->LeagueInfo1[$lil]->maps[0] = $comp['children'][3]['children'][0]['children'][2]['attributes']['name'];
$Team1->LeagueInfo1[$lil]->maps[1] = $comp['children'][3]['children'][0]['children'][3]['attributes']['name'];
$Team1->LeagueInfo1[$lil]->maps[2] = $comp['children'][3]['children'][0]['children'][4]['attributes']['name'];
}
}
}
}
}
}
$html = "
<table bgcolor=\"".$bgcolor1."\" width=\"100%\" cellspacing=\"0\" cellpadding=\"1\">
<tr>
<td align=\"center\" colspan=\"3\">
</td>
</tr>";
for ($i = 0; $i < count($Team1->LadderInfo1); $i++) {
$html .= "
<tr>
<td align=\"center\" colspan=\"3\"><b><a href=\"".$Team1->LadderInfo1[$i]->ladderhtmllink."\">".$Team1->LadderInfo1[$i]->ladder."</a></b></td>
</tr>
<tr>
<td align=\"center\" colspan=\"3\">
Current Rung: <font color=yellow>".$Team1->LadderInfo1[$i]->rank."</font color></td>
</tr>
<tr>
<td align=\"center\" colspan=\"3\">
Record: <b><font color=green>".$Team1->LadderInfo1[$i]->wins."W </font color><font color=red>".$Team1->LadderInfo1[$i]->losses."L </font color><font color=orange>".$Team1->LadderInfo1[$i]->forfeits."F </font color></b>
</td>
</tr>";
$html .= "
<tr>
<td align=\"center\" colspan=\"3\"> </td>
</tr>";
}
for ($i = 0; $i < count($Team1->LeagueInfo1); $i++) {
$html .= "
<tr>
<td align=\"center\" colspan=\"3\"><b><a href=\"".$Team1->LeagueInfo1[$i]->leaguehtmllink."\">".$Team1->LeagueInfo1[$i]->league."</a></b></td>
</tr>
<tr>
<td align=\"center\" colspan=\"3\">
Conference: ".$Team1->LeagueInfo1[$i]->conference." Division: ".$Team1->LeagueInfo1[$i]->division."
</td>
</tr>";
}
$html .= "</table>";
//Added by [STAB]-Ravenstone to display xml data if availabe and a message if not. ravenstone@stabclan.com
if($Team1->name == NULL)
{
$content .= "<center><b> XML Service Unavailable</b></center>";
}
else
{
$content = $html;
}
//I only take credit for the code in between the comments nothing more.
//If you wrote this code and feel I am taking credit for it please email me so I can add your name to the file I have
//with the due credit it deserves ravenstone@stabclan.com
?>
|