Purple Dragons
An online gaming guild

::Sections
  • Home
  • Forum
  • Lineage II
       
    :: soon!
  • DAoC
        :: screenshots
        :: roster
  • Dragon's Blood
  • Online Store
  • PHP XML modules
        :: Scripts home
        :: What is XML?
        :: PHP/XML forum
        :: Guild roster
        :: Guild hierarchy
        :: Character search
        :: Alliance status
        :: Class listing
        :: Crafter listing
        :: Top 10 RP holders
        :: Italy special!
  •  

    ::Logo
    The Dragon logo is inspired by artwork property of Mythic Entertainment.
    ::PHP/XML Guild hierarchy - DAoC

    This script will generate a guild roster from your guild XML feed.

    ::Source code
    <?php
        
    /*
        *    hierarchyxml.php
        *    a Dark Age of Camelot Guild XML data parser that returns a hierarchy table
        *    for use on Dark Age of Camelot community websites.
        *
        *    Dark Age of Camelot (or DAoC) is a MMORPG
        *    (massively multiplayer online rolepaying game)
        *    developed by Mythic Entertainment (http://www.mythicentertainment.com)
        *
        *    Author: Julien COQUET
        *    a.k.a Glenfiddich Singlemalt on DAoC Merlin/Albion
        *    e-mail glenfiddich@purpledragons.net
        *    http://www.purpledragons.net
        *
        *    Adapted from generic PHP code from http://www.php.net
        *
        *    Developed in September of 2002 under the GNU GPL License.
        *    For more information, visit http://www.gnu.org/licenses/gpl.html
        *
        *    Enjoy and please link to our site
        *    http://www.purpledragons.net
        * 
        *     Changelog:
        *     March 28, 2003 : added UTF8 support for GOA XML - Euro servers only
        */

    class guildXML {

        
    /*
        *    This class takes a Dark Age of Camelot Herald XML guild data file and parses it
        */

            
    var $xml_parser;
            var 
    $xml_file;
            var 
    $html;
            var 
    $open_tag ;
            var 
    $close_tag ;
            var 
    $in_char;
            var 
    $in_alliance;
            var 
    $chars_array;
            var 
    $alliance_array;
            var 
    $current_tag ='';

        
    /*
        *    Class Constructor
        */
            
    function guildXML() {
                
    $this->xml_parser "";
                
    $this->xml_file "";
                
    $this->html "";
            }

        
    /*
        *    Class Destructor
        *    (has to be invoked manually as PHP does not support destructors)
        */
            
    function destroy() {
                
    xml_parser_free($this->xml_parser);
            }

        
    /*
        *    XML Elements - context methods
        *
        *    startElement and endElement are XML context indicators.
        *    XML attributes are handled in startElement
        *    They describe what should be done when in a specific XML tag
        *
        *    characterData handles PCDATA tag content
        */

            
    function startElement($parser$name$attrs) {
                global 
    $totalchars$num_activechars,$num_inactivechars$insideElement$in_char$current_tag$i;

                if ((
    $in_char==1)||($in_alliance==1)){
                    
    $current_tag $name;
                }
                if (
    $name=='CHARACTER'){
                    
    $in_alliance 1;
                }
                if (
    $name=='CHARACTER'){
                    
    $in_char=1;
                    
    $totalchars++;
                    if (
    sizeof($attrs)) {
                        while (list(
    $k$v) = each($attrs)) {
                            if (
    $k=='NAME'){
                                 if (
    $k=='NAME'){ 
                                      
    $this->chars_array[$i]['name']=trim($v); 
                                      
    $this->chars_array[$i]['firstname']= trim (substr($this->chars_array[$i]['name'],0strpos($this->chars_array[$i]['name'],' '))); 
                                      
    $this->chars_array[$i]['lastname']= trim (substr($this->chars_array[$i]['name'], strpos($this->chars_array[$i]['name'],' '))); 
                                 
    // Italian servers with Base64 encoding for last name, comment the above line and uncomment the following line 
                                 //$this->chars_array[$i]['lastname']= base64_decode(trim (substr($this->chars_array[$i]['name'], strpos($this->chars_array[$i]['name'],' ')))); 

                            
    if (!$this->chars_array[$i]['firstname'] && $this->chars_array[$i]['lastname']){ 
                                 
    $this->chars_array[$i]['firstname'] = $this->chars_array[$i]['lastname']; 
                                 
    $this->chars_array[$i]['lastname']=''
                            }            
                        }
                            }
                            if (
    $k=='LASTON') {
                                
    $this->chars_array[$i]['laston']=trim($v);
                                if (
    $v!='Inactive') {
                                    
    $num_activechars++;
                                } elseif (
    $v=='Inactive'){
                                    
    $num_inactivechars++;
                                }
                            }
                         }
                     }
                }

            }

            function 
    endElement($parser$name) {
                global 
    $close_tag$current_tag$in_char$i;
                if (
    $name=='CHARACTER'){$i++; $in_char=0;}
                if (
    $name=='ALLIANCE'){$i++; $in_alliance=0;}
            }

            function 
    characterData($parser$data) {
                global 
    $guildrp$current_tag$in_char$i;
                if ((
    $in_char==1) && ($current_tag=='RACE')){
                    
    $this->chars_array[$i]['race'].=trim($data);
                }
                if ((
    $in_char==1) && ($current_tag=='CLASS')){
                    
    $this->chars_array[$i]['class'].=trim($data);
                }
                if ((
    $in_char==1) && ($current_tag=='LEVEL')){
                    
    $this->chars_array[$i]['level'].=trim($data);
                }
                if ((
    $in_char==1) && ($current_tag=='GUILDRANK')){
                    
    $this->chars_array[$i]['guildrank'].=trim($data);
                }
            }


        
    /*
        *
        *    the parse() method reads the input file line by line
        *    and uses the context method to process tags.
        *
        */
            
    function parse() {

                
    $this->xml_parser xml_parser_create();
                
    xml_set_object($this->xml_parser, &$this);
                
    // use case-folding so we are sure to find the tag in $map_array
                
    xml_parser_set_option($this->xml_parserXML_OPTION_CASE_FOLDINGtrue);

                
    xml_set_element_handler($this->xml_parser"startElement""endElement");
                
    xml_set_character_data_handler($this->xml_parser"characterData");
                
    //xml_set_processing_instruction_handler($this->xml_parser, "PIHandler");

                
    if (!($fp fopen($this->xml_file"r"))) {
                    die(
    "could not open XML input");
                }

                while (
    $data fread($fp4096)) {
                    if (!
    xml_parse($this->xml_parser$datafeof($fp))) {
                        die(
    sprintf("XML error: %s at line %d",
                        
    xml_error_string(xml_get_error_code($this->xml_parser)),
                        
    xml_get_current_line_number($this->xml_parser)));
                    }
                }
            }
        }
    // End of class

    // Support functions

        /*
        *    The function sortItems() is used for sorting, called upon by uksort()
        *    It uses querystring parameter $param as the sorting parameter
        *    querystring parameter $dir indicates ascending or descending order
        */

        
    function sortItems($a$b) {
             global 
    $gu$dir$param;

            
    $val_a = ($gu[$a][$param]);
            
    $val_b = ($gu[$b][$param]);

            if (!
    $param){$param='level';}
            if (!
    $dir){$dir='down';}
            switch (
    $param){
                case 
    'rp':
                
    $val_a $val_a 0;
                
    $val_b $val_b 0;
                break;

                case 
    'level':
                
    $val_a $val_a 0;
                
    $val_b $val_b 0;
                break;
            }

            if (
    $dir=='up'){ // Set forward/reverse sorting order
                
    if ( $val_a $val_b ){return 1;}
                if ( 
    $val_a $val_b ){return -1;}
                if ( 
    $val_a $val_b ){return 0;}
            } else {
                if ( 
    $val_a $val_b ){return 1;}
                if ( 
    $val_a $val_b ){return -1;}
                if ( 
    $val_a $val_b ){return 0;}
            }
        }

        
    /*
        *    returns array with Guild Rank information
        */

        
    function guildrank($rank){
            switch (
    $rank){
                case 
    0$rankname = array('Guildmaster''Description for Guildmaster');
                break;

                case 
    1$rankname = array('Rank 1 Title''Description for Guild Rank 1');
                break;

                case 
    2$rankname = array('Rank 2 Title''Description for Guild Rank 2');
                break;

                case 
    3$rankname = array('Rank 3 Title''Description for Guild Rank 3');
                break;

                case 
    4$rankname = array('Rank 4 Title''Description for Guild Rank 4');
                break;

                case 
    5$rankname = array('Rank 5 Title''Description for Guild Rank 5');
                break;

                case 
    6$rankname = array('Rank 6 Title''Description for Guild Rank 6');
                break;

                case 
    7$rankname = array('Rank 7 Title''Description for Guild Rank 7');
                break;

                case 
    8$rankname = array('Rank 8 Title''Description for Guild Rank 8');
                break;

                case 
    9$rankname = array('Rank 9 Title''Description for Guild Rank 9');
                break;
            }
            return 
    $rankname;
        }


        
    /*
        *    returns Realm Rank Level as function of Realm Points
        */

        
    function realmlevel ($rp){
            
    $rap =1;
            for (
    $i=1$i<11$i++){
                for (
    $j=0;$j<10;$j++){

                    
    $rp_needed = ((25/3)*(pow($rap,3))) - ((25/2)*(pow($rap,2))) + ((25/6)*$rap);
                    
    // formula used to determine Realm Points needed by Realm Level, as function of Realm Ability Points

                    
    if ($rp_needed <10) {
                        
    $rp_needed =0;
                    }
                    if (
    $rp>=$rp_needed) {
                        
    $level 'R'.$i.'L'.$j;
                    }
                    
    $rap++;
                    
    // needs revising for the lucky players to reach R10L10
                
    }
            }
            return 
    $level;
        }

    // Main content

        
    $guild = new guildXML(); // instantiate class
        
    $guild->xml_file "http://www.camelotherald.com/guilds/Merlin/804.xml";
        
    // the xml_file property referes to you guild XML data file.
        // Example given is the Merlin/Albion guild Dragon's Blood

        
    $guild->parse(); // begin parsing

        
    $gu $guild->chars_array// copy guild information array
        
    $guild->destroy(); // destroy the object


        
    uksort($gu"sortItems"); // call upon sortItems() to sort the guild information array
        
    reset($gu);

        
    /*
        *    Creates the output table
        */

        
    $content_output '<!-- DAoC Guild Hierarchy script -->'."\n";
        
    $content_output .= '<table cellspacing="0" cellpadding="5">';
        for (
    $i=0$i<10$i++){
            
    $guildrank guildrank($i);
            
    $content_output .= '
    <tr style="background-color: #CCCCCC;">
        <td colspan="2">
            <span style="font-size:12pt; font-weight:bold;">'
    .$guildrank[0].'</span>&nbsp;
            <span style="font-size:8pt;">'
    .$guildrank[1].'</span>
        </td>
    </tr>'
    ;
            foreach (
    $gu as $key=>$value){
                if ((
    $value['guildrank']==$i) && ($value['laston']!='Inactive')){
                    
    $content_output .= '
    <tr bgcolor="'
    .$color.'">
        <td>&nbsp;&nbsp;&nbsp;<b>'
    .$value['firstname'].' '.$value['lastname'].'</b></td>
        <td>'
    .$value['level'].' '.$value['race'].' '.$value['class'].'</td>
    </tr>'
    ;
                }
            }
        }

        
    $content_output .= "\n".'</table>';

        
    /*
            For Euro guilds: uncomment the following instructions
        */
        
    //    $content_output = utf8_decode($content_output); // handles UTF8 character encoding

        /*
        *    Outputs table; end of script
        */

        
    print $content_output;

    ?>
    ::Contacts
  • Guildmaster: Sir William
  • Webmaster: Glenfiddich
  • ::Good Karma!
    I accept payment through PayPal!, the #1 online payment service!
    feed the webmaster!
    The money will be used for web hosting, raffles, RL events, etc...
    ::Promo
    Support This Site
     
    PHP - PHP Hypertext Processor