TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Warcarft Project (http://www.talkphp.com/general/5396-warcarft-project.html)

Yanayaya 04-05-2010 09:16 AM

Warcarft Project
 
Hello everyone, tis me, the new guy. ;-)

I have been working on a PHP page that talks to the Warcraft Armory. There are a mountain of scripts out there that do this, but I took one and worked on refining it someone to serve my needs for what I was looking to accomplish. None the less my code is not working and I was wondering if you peeps would be kind enough to have a scan through it and help me identify why it is failing to run.

PHP Code:

function return_class($classid) {
    switch (
$classid) {
        case 
1$class "<img src=\"http://eu.wowarmory.com/_images/icons/class/1.gif\">"; break;
        case 
2$class "<img src=\"http://eu.wowarmory.com/_images/icons/class/2.gif\">"; break;
        case 
3$class "<img src=\"http://eu.wowarmory.com/_images/icons/class/3.gif\">"; break;
        case 
4$class "<img src=\"http://eu.wowarmory.com/_images/icons/class/4.gif\">"; break;
        case 
5$class "<img src=\"http://eu.wowarmory.com/_images/icons/class/5.gif\">"; break;
        case 
6$class "<img src=\"http://eu.wowarmory.com/_images/icons/class/6.gif\">"; break;
        case 
7$class "<img src=\"http://eu.wowarmory.com/_images/icons/class/7.gif\">"; break;
        case 
8$class "<img src=\"http://eu.wowarmory.com/_images/icons/class/8.gif\">"; break;
        case 
9$class "<img src=\"http://eu.wowarmory.com/_images/icons/class/9.gif\">"; break;
        case 
11$class "<img src=\"http://eu.wowarmory.com/_images/icons/class/11.gif\">"; break;
    }
    return 
$class;
}
function 
return_rank($rankid) {        // Adjust the names here for the guild rank names.  0 is always the Guild owner
    
switch ($rankid) {
        case 
0$class "not the Messiah"; break;
        case 
1$class "Black Knight"; break;
        case 
2$class "HolyHandgrenade"; break;
        case 
3$class "Lumberjack"; break;
        case 
4$class "Mr Creosote"; break;
        case 
5$class "Assface"; break;
        case 
6$class "Dead Fish"; break;
    }
    return 
$class;
}  

function 
return_race($raceid$sex) {
    switch (
$raceid) {
        case 
1
            if (
$sex == "0") {$race "<img src=\"http://eu.wowarmory.com/_images/icons/race/1-0.gif\">M";} 
            if (
$sex == "1") {$race "<img src=\"http://eu.wowarmory.com/_images/icons/race/1-1.gif\">F";} 
            break;
        case 
2
            if (
$sex == "0") {$race "<img src=\"http://eu.wowarmory.com/_images/icons/race/2-0.gif\">M";} 
            if (
$sex == "1") {$race "<img src=\"http://eu.wowarmory.com/_images/icons/race/2-1.gif\">F";} 
            break;
        case 
3
            if (
$sex == "0") {$race "<img src=\"http://eu.wowarmory.com/_images/icons/race/3-0.gif\">M";}
            if (
$sex == "1") {$race "<img src=\"http://eu.wowarmory.com/_images/icons/race/3-1.gif\">F";} 
            break;
        case 
4
            if (
$sex == "0") {$race "<img src=\"http://eu.wowarmory.com/_images/icons/race/4-0.gif\">M";} 
            if (
$sex == "1") {$race "<img src=\"http://eu.wowarmory.com/_images/icons/race/4-1.gif\">F";} 
            break;
        case 
5
            if (
$sex == "0") {$race "<img src=\"http://eu.wowarmory.com/_images/icons/race/5-0.gif\">M";} 
            if (
$sex == "1") {$race "<img src=\"http://eu.wowarmory.com/_images/icons/race/5-1.gif\">F";} 
            break;
        case 
6
            if (
$sex == "0") {$race "<img src=\"http://eu.wowarmory.com/_images/icons/race/6-0.gif\">M";} 
            if (
$sex == "1") {$race "<img src=\"http://eu.wowarmory.com/_images/icons/race/6-1.gif\">F";} 
            break;
        case 
7
            if (
$sex == "0") {$race "<img src=\"http://eu.wowarmory.com/_images/icons/race/7-0.gif\">M";} 
            if (
$sex == "1") {$race "<img src=\"http://eu.wowarmory.com/_images/icons/race/7-1.gif\">F";} 
            break;
        case 
8
            if (
$sex == "0") {$race "<img src=\"http://eu.wowarmory.com/_images/icons/race/8-0.gif\">M";} 
            if (
$sex == "1") {$race "<img src=\"http://eu.wowarmory.com/_images/icons/race/8-1.gif\">F";} 
            break;
        case 
10:
            if (
$sex == "0") {$race "<img src=\"http://eu.wowarmory.com/_images/icons/race/10-0.gif\">M";} 
            if (
$sex == "1") {$race "<img src=\"http://eu.wowarmory.com/_images/icons/race/10-1.gif\">F";} 
            break;
        case 
11
            if (
$sex == "0") {$race "<img src=\"http://eu.wowarmory.com/_images/icons/race/11-0.gif\">M";}
            if (
$sex == "1") {$race "<img src=\"http://eu.wowarmory.com/_images/icons/race/11-1.gif\">F";} 
            break;
    }
    return 
$race;
}
    
$url 'http://eu.wowarmory.com/guild-info.xml?r=Agamaggan&gn=Ministry+of+Silly+Walks';
    
$ch curl_init();
    
curl_setopt ($chCURLOPT_URL$url);
    
curl_setopt ($chCURLOPT_RETURNTRANSFERtrue);
    
curl_setopt ($chCURLOPT_USERAGENT,  "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1");
    
$rosterxml curl_exec($ch);  
    if(
$rosterxml != ""){$xml = new SimpleXMLElement($rosterxml);


PHP Code:

    foreach ($xml->guildInfo->guild->members->character as $char) {
    
$toonclass return_class($char['classId']);
    
$toonrace return_race($char['raceId'], $char['genderId']);
    
$toonrank return_rank($char['rank']);
    echo 
"\n<td><a class=\"link\" href=\"http://eu.wowarmory.com/character-sheet.xml?r=Agamaggan&cn={$char['name']}\">{$char['name']}</a></td>";
    echo 
'<td>' $toonclass '</td> ';
    echo 
'<td>' $toonrace '</td> ';
    echo 
'<td>' $char['level'] . '</td> ';
    echo 
"\n<td><a class=\"link\" href=\"http://eu.wowarmory.com/character-achievements.xml?r=Agamaggan&cn={$char['name']}&gn=Ministry+of+Silly+Walks\">{$char['achPoints']}</a></td>";
    echo 
'<td><p>' $toonrank '</p></td></tr>';
    } 

The idea behind this script it to simply get my own guild roster from the armory and display it, with some specific information such as gender and race.

It was working only days ago and today it appears to want to throw up an Internal Server Error 500 and I dont know why so I am hoping to have my code validated. I dont have much control over the server however as it is paid for hosting.

Village Idiot 04-05-2010 05:20 PM

When a script fails after working it means that it is an external issue. In this instace, it appears that your external factors are the server and the warcraft database, this means that one of the two must be throwing an error. Considering it is a 500 and you have no heard similar situations ariasing with the warcraft API, I would guess that it is a server error. Do other PHP scripts work? If they do try to figure out which command is throwing the fit and go form there.


All times are GMT. The time now is 10:46 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0