Fork me on GitHub

Help with Conversion  Bottom

  • Hi all,

    I have a block that was written for PHP but would like to convert it and use it with Postnuke! I`m desperately been trying to get this up and running, but with no luck whatsoever!

    I would be most grateful if someone could take a look at this for me and let know what I need to change/alter/add to make this Postnuke compatible:

    Code

    <?PHP


    if (eregi("block-TWL_Schedule.php", $PHP_SELF)) {
    header("Location: index.php");
    die();
    }

    //This is to keep those annoying parsing errors to ourselves
    error_reporting(0);
    //added by [STAB]-Ravenstone

    //Copy and paste your clan TWL XML URL below.
    $file = "http://www.teamwarfare.com/xml/viewteam_v2.asp?team=The+Weekend+Warriors";
    //Comment out this line to test what happens to your script when there is no file available same as if TWL xml stream is down.

    class LadderInfo {

        var $ladder;
        var $ladderhtmllink;
        var $ladderxmllink;
        var $rank;
        var $wins;
        var $losses;
        var $forfeits;
        var $status;
        var $opponent;
        var $opponenthtmllink;
        var $opponentxmllink;
        var $date;
        var $maps;
        var $sides;

    function LadderInfo() {
        $maps = array();
        $sides = array();
    }
    }

    class LeagueInfo {
        var $league;
        var $leaguehtmllink;
        var $leaguexmllink;
        var $conference;
        var $division;
        var $status;
        var $opponent;
        var $opponenthtmllink;
        var $opponentxmllink;
        var $date;
        var $maps;

    function LeagueInfo() {
        $maps = array();
    }
    }

    class Team {
        var $name;
        var $URL;
        var $email;
        var $founder;
        var $description;
        var $ircserver;
        var $channel;
        var $status;
        var $ladderinfo;
        var $leagueinfo;

    function Team() {
        $this->ladderinfo = array();
        $this->leagueinfo = array();
    }
    }

        $team = new Team();

    function formatDate($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 formatDate1($datetime) {
    $timestamp = (int)strtotime($datetime);
    putenv("TZ=EST5EDT");
    $datetime = strftime("%A, %B %d", $timestamp);

    return $datetime;
    }

    function xml_get_children($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_children($vals, $i),
    );
    break;

    case 'close':
    return $children;
    }
    }
    }

    function xml_get_tree($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_children($vals, $i = 0),
    );
    }

    $tree = xml_get_tree($file);

    foreach ($tree['children'] as $children) {
    if ($children['tag'] == "teaminformation") {
    $team->name = $tree['children'][0]['children'][0]['value'];
    $team->URL = $tree['children'][0]['children'][1]['value'];
    $team->email = $tree['children'][0]['children'][2]['value'];
    $team->founder = $tree['children'][0]['children'][5]['value'];
    $team->description = $tree['children'][0]['children'][6]['value'];
    $team->ircserver = $tree['children'][0]['children'][3]['value'];
    $team->channel = $tree['children'][0]['children'][3]['attributes']['channel'];
    $team->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($team->ladderinfo);
    $team->ladderinfo[$lil] = new LadderInfo();
    $team->ladderinfo[$lil]->ladder = $comp['attributes']['name'];
    $team->ladderinfo[$lil]->ladderhttplink = $comp['children'][0]['children'][0]['value'];
    $team->ladderinfo[$lil]->ladderxmllink = $comp['children'][0]['children'][1]['value'];
    $team->ladderinfo[$lil]->rank = $comp['children'][1]['value'];
    $team->ladderinfo[$lil]->wins = $comp['children'][2]['value'];
    $team->ladderinfo[$lil]->losses = $comp['children'][3]['value'];
    $team->ladderinfo[$lil]->forfeits = $comp['children'][4]['value'];
    $team->ladderinfo[$lil]->status = $comp['children'][5]['attributes']['status'];

    if (array_key_exists("children", $comp['children'][5])) {
    $team->ladderinfo[$lil]->opponent = $comp['children'][5]['children'][0]['value'];
    $team->ladderinfo[$lil]->opponenthtmllink = $comp['children'][5]['children'][1]['children'][0]['value'];
    $team->ladderinfo[$lil]->opponentxmllink = $comp['children'][5]['children'][1]['children'][1]['value'];
    $team->ladderinfo[$lil]->date = $comp['children'][5]['children'][2]['value'];
    $team->ladderinfo[$lil]->maps[0] = $comp['children'][5]['children'][3]['attributes']['name'];
    if (array_key_exists("children", $comp['children'][5]['children'][3])) $team->ladderinfo[$lil]->sides[0] = $comp['children'][5]['children'][3]['children'][0]['children'][0]['value'];
    $team->ladderinfo[$lil]->maps[1] = $comp['children'][5]['children'][4]['attributes']['name'];
    $team->ladderinfo[$lil]->maps[2] = $comp['children'][5]['children'][5]['attributes']['name'];
    }
    } else if ($comp['tag'] == "league") {
    $lil = count($team->leagueinfo);
    $team->leagueinfo[$lil] = new LeagueInfo();
    $team->leagueinfo[$lil]->league = $comp['attributes']['name'];
    $team->leagueinfo[$lil]->leaguehttplink = $comp['children'][0]['children'][0]['value'];
    $team->leagueinfo[$lil]->leaguexmllink = $comp['children'][0]['children'][1]['value'];
    $team->leagueinfo[$lil]->conference = $comp['children'][1]['value'];
    $team->leagueinfo[$lil]->division = $comp['children'][2]['value'];
    $team->leagueinfo[$lil]->status = $comp['children'][3]['children'][0]['attributes']['status'];

    if (array_key_exists("children", $comp['children'][3])) {
    $team->leagueinfo[$lil]->opponent = $comp['children'][3]['children'][0]['children'][0]['value'];
    $team->leagueinfo[$lil]->opponenthtmllink = $comp['children'][3]['children'][0]['children'][1]['children'][0]['value'];
    $team->leagueinfo[$lil]->opponentxmllink = $comp['children'][3]['children'][0]['children'][1]['children'][1]['value'];
    $team->leagueinfo[$lil]->date = formatDate1($comp['children'][3]['children'][0]['children'][3]['value'])." 9:30 PM EST";
    $team->leagueinfo[$lil]->maps[0] = $comp['children'][3]['children'][0]['children'][2]['attributes']['name'];
    $team->leagueinfo[$lil]->maps[1] = $comp['children'][3]['children'][0]['children'][3]['attributes']['name'];
    $team->leagueinfo[$lil]->maps[2] = $comp['children'][3]['children'][0]['children'][4]['attributes']['name'];
    }
    }
    }
    }
    }
    }




    $HTML = "
    <table bgcolor=\""
    .$bgcolor1."\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\">
    <td align=\"center\" colspan=\"5\"><font color=red><h3><u>Ladders</u></h3></font color>&nbsp;</td>
    <tr>
    <td align=\"middle\" colspan=\"5\">
    </td>
    </tr>"
    ;



    for ($i = 0; $i < count($team->ladderinfo); $i++) {
    $HTML .= "
    <table bgcolor=\""
    .$bgcolor1."\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\">

    <tr>
    <td align=\"middle\" colspan=\"1\"><h4><b><u><font color=grey><a href=\""
    .$team->ladderinfo[$i]->ladderhttplink."\">".$team->ladderinfo[$i]->ladder."</font color></b></u></h4></a></td></tr>
    <td align=\"middle\" colspan=\"1\">Current Rung: <b><font color=yellow>"
    .$team->ladderinfo[$i]->rank."</font color></b> </tr>
    <tr>
    </td></tr>
    "
    ;

    if (isset($team->ladderinfo[$i]->opponent)) {
    $HTML .= "
    <table bgcolor=\""
    .$bgcolor1."\" width=\"100%\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" colspan=\"1\">
    <td align=\"middle\" colspan=\"1\" width=\"25%\"><u>Date</u></td>
    <td align=\"middle\" colspan=\"1\" width=\"15%\"><u>Current Status</u></td>
    <td align=\"middle\" colspan=\"1\" width=\"15%\"><u>Side</u></td>
    <td align=\"middle\" colspan=\"1\" width=\"20%\"><u>Opponent</u></td>
    <td align=\"middle\" colspan=\"1\" width=\"20%\"><u>Map</u></td></tr>
    <tr>
    <td align=\"middle\" colspan=\"1\" width=\"25%\">"
    .$team->ladderinfo[$i]->date."</td>
    <td align=\"middle\" colspan=\"1\" width=\"15%\">"
    .$team->ladderinfo[$i]->status."</td>
    <td align=\"middle\" colspan=\"1\" width=\"15%\">"
    .$team->ladderinfo[$i]->sides[0]."</td>
    <td align=\"middle\" colspan=\"1\" width=\"20%\"><a href=\""
    .$team->ladderinfo[$i]->opponenthtmllink."\">".$team->ladderinfo[$i]->opponent."</a> </td>
    <td align=\"middle\" colspan=\"1\" width=\"20%\">"
    .$team->ladderinfo[$i]->maps[0]."</td>
    </tr></td>
    "
    ;
    } else {
    $HTML .= "
    <tr>
    <td align=\"center\" colspan=\"1\">
    No Match Scheduled
    </td>
    </tr>"
    ;
    }
    $HTML .= "
    <tr>
    <td align=\"center\" colspan=\"1\">&nbsp;</td>
    </tr>
    "
    ;
    }
    for ($i = 0; $i < count($team->leagueinfo); $i++) {
    $HTML .= "
    <table bgcolor=\""
    .$bgcolor1."\" width=\"100%\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" colspan=\"3\">
    <td align=\"center\" colspan=\"5\"><font color=red><h3><u>Leagues</u></h3></font color=red>&nbsp;</td>
    <tr>
    <td align=\"middle\" colspan=\"5\"><b><u><h4><a href=\""
    .$team->leagueinfo[$i]->leaguehttplink."\">".$team->leagueinfo[$i]->league."</h4></b></u></a></td>
    </tr>
    <tr>
    <td align=\"middle\" colspan=\"5\">Conference: "
    .$team->leagueinfo[$i]->conference."</tr></td>
    <tr>
    <td align=\"middle\" colspan=\"5\">Division: "
    .$team->leagueinfo[$i]->division."</td>
    <tr>
    <td align=\"middle\" colspan=\"1\" width=\"25%\"><u>Date</u>
    <td align=\"middle\" colspan=\"1\" width=\"15%\"><u>Current Status</u>
    <td align=\"middle\" colspan=\"1\" width=\"15%\"><u>x</u>
    <td align=\"middle\" colspan=\"1\" width=\"20%\"><u>Opponent</u>
    <td align=\"middle\" colspan=\"1\" width=\"20%\"><u>Map</u>
    </tr>
    <tr>
    <td align=\"middle\" colspan=\"1\" width=\"20%\">"
    .$team->leagueinfo[$i]->date."
    <td align=\"middle\" colspan=\"1\" width=\"15%\">"
    .$team->leagueinfo[$i]->status."
    <td align=\"middle\" colspan=\"1\" width=\"15%\">
    <td align=\"middle\" colspan=\"1\" width=\"20%\"><a href=\""
    .$team->leagueinfo[$i]->opponenthtmllink."\">".$team->leagueinfo[$i]->opponent."</a>
    <td align=\"middle\" colspan=\"1\" width=\"20%\">"
    .$team->leagueinfo[$i]->maps[0]."</td>
    </tr>

    </td>
    </tr>
    "
    ;

    if (isset($team->leagueinfo[$i]->opponent)) {
    $HTML .= "
    <tr>
    <tr>
    </td>
    </tr>
    <tr>
    <td align=\"middle\" colspan=\"3\">
    </tr>
    "
    ;
    } else {
    $HTML .= "
    <tr>
    <td align=\"center\" colspan=\"3\">
    No Match Scheduled
    </td>
    </tr>"
    ;
    }
    $HTML .= "
    <tr>
    <td align=\"center\" colspan=\"3\">
    </td>
    <tr>"
    ;

    }


    $HTML .= "</table>";

    //Added by [STAB]-Ravenstone to switch between normal scrolling Ladder information and unavailable when not there...

    if($team->name == null)
    {
        $content .="</Marquee><table bgcolor=\"".$bgcolor1."\" width=\"100%\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" colspan=\"3\">
        <td align=\"center\" colspan=\"5\">TWL Service Currently Unavailable.</tr></table>"
    ;
    }
    else
    {
    $content = "<Marquee Behavior=\"Scroll\" Direction=\"Up\" Height=\"110\" ScrollAmount=\"2\" ScrollDelay=\"50\" onMouseOver=\"this.stop()\" onMouseOut=\"this.start()\"><br>";
    $content .= $HTML;
    $content .= "</Marquee><br>";
    }
     
    //Added by [STAB]-Ravenstone to switch between normal scrolling Ladder information and unavailable when not there...

    $content .="
    <table bgcolor=\""
    .$bgcolor1."\" width=\"100%\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" colspan=\"3\">
    <tr>
    <td align=\"middle\" colspan=\"5\" width=\"100%\">__________________________________________</tr></td><tr>
    <td align=\"middle\" colspan=\"5\" width=\"100%\">Click to view</tr>
    <tr>


    <td align=\"middle\" colspan=\"5\" width=\"100%\"><font color=red><h4>--><A HREF='http://www.teamwarfare.com/viewteam.asp?team=The+Weekend+Warriors'>Weekend Warriors</a><--</h4></td>
    </table>"
    ; //Change the address in this link above to point to your Clan's normal page on TWL's website
    $content .="";


    ?>


    Quite a bit there but there must be a way to get this working.

    Thanks in advance for anyone that takes up this challenge :D

    Regards

    Spank
  • Give us the executive summary - what does this code do, how will it integrate with PostNuke, is it intended to be a module, block, hook, other? What's the problem integrating it? Why is it cool? That will put the code into some context. Otherwise it's too hard to decipher.

    Frank

This list is based on users active over the last 60 minutes.