dressingroom.class.php

nimetu, 05/03/2009 12:12 am

Download (1.8 kB)

 
1
<?
2
/*
3
    $armor = DressingRoom::getArmor($xml);
4
    echo 'link <a href="'.DressingRoom::linkUri($armor).'">'.$armor."</a>\n";
5
    echo 'image <img src="'.DressingRoom::imageUri($armor)."\" width='200px' align='right' border=1 />\n";
6
*/
7

8
class DressingRoom {
9
        
10
        function imageUri($armor, $base='http://ballisticmystix.net/api/dressingroom.php'){
11
                if(strpos($base, '?')===false){
12
                        return $base.'?'.$armor;
13
                }else{
14
                        return $base.'&'.$armor;
15
                }
16
        }
17

18
        function linkUri($armor, $base='http://ballisticmystix.net/?p=dressingRoom;'){
19
                if(strpos($base, '?')===false){
20
                        return $base.'?'.$armor;
21
                }else{
22
                        return $base.'&'.$armor;
23
                }
24
        }
25
        
26
        function getArmor(SimpleXMLElement $xml){
27
                $url=array();
28
                
29
                // race
30
                switch(strtolower($xml->race)){
31
                        case 'zorai':
32
                        case 'fyros':
33
                        case 'matis':
34
                        case 'tryker': // fall thru
35
                                $race=strtolower($xml->race);
36
                                break;
37
                        default:
38
                                $race='tryker';
39
                }
40
                $url[]='race='.$race;
41
                // gender
42
                if(strtolower($xml->gender)=='f') $gender='f'; else $gender='m';
43
                $url[]='gender='.$gender;
44
                // hair
45
                $hair_type  = (int)$xml->body->hair_type;
46
                $hair_color = (int)$xml->body->hair_color;
47
                $url[]='hair='.$hair_type.'/'.$hair_color;
48
                // tattoo
49
                $tattoo=(int)$xml->body->tattoo;
50
                $url[]='tattoo='.$tattoo;
51
                // eye color
52
                $eye_color = (int)$xml->body->eyes_color;
53
                $url[]='eyes='.$eye_color;
54
                
55
                // armor
56
                foreach($xml->equipments->item as $node){
57
            // if it's one of armor parts
58
            $part = (string) $node['part'];
59
            if(in_array($part, array('hands', 'chest', 'arms', 'legs','feet','head'))){
60
                $color = (int) $node['c'];
61
                $url[]=$part.'='.(string) $node.'/'.$color;
62
            }
63
        }
64

65
                // join the URL and return it
66
                return join('&',$url);
67
        }
68
    
69

70
}// DressingRoom
71
//eof