/* * classesxml.php * a Dark Age of Camelot Guild XML data parser that returns a guild roster * sorted by class * 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 November 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 * Feb. 25, 2003 : finally added $param as $_GET['param'] */
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 Destructor (has to be invoked manually as PHP does not support destructors) function destroy() { xml_parser_free($this->xml_parser); }
//Class Members function concat($str) { $this->html .= $str; }
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=='GUILD'){ $current_tag= $name; if (sizeof($attrs)) { while (list($k, $v) = each($attrs)) { if ($k=='GUILDRP'){$this->guildrp=$v;}; if ($k=='TIMESTAMP'){$this->timestamp=$v;}; } } }
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'){$this->chars_array[$i]['name']=$v;}; if ($k=='ID'){$this->chars_array[$i]['id']=$v;}; if ($k=='LASTON') { $this->chars_array[$i]['laston']=$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, $inactiverp, $current_tag, $in_char, $i; //$content_output .= '<br>'.$current_tag.' = '.$data.'<br>'; if (($in_char==1) && ($current_tag=='RACE')){ $this->chars_array[$i]['race'].=$data; } if (($in_char==1) && ($current_tag=='CLASS')){ $this->chars_array[$i]['class'].=$data; } if (($in_char==1) && ($current_tag=='LEVEL')){ $this->chars_array[$i]['level'].=$data; } if (($in_char==1) && ($current_tag=='TOTALRP')){ $this->chars_array[$i]['rp'].=$data;
$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_parser, XML_OPTION_CASE_FOLDING, true);
if (!($fp = fopen($this->xml_file, "r"))) { die("could not open XML input"); } while ($data = fread($fp, 4096)) { if (!xml_parse($this->xml_parser, $data, feof($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;
if ($dir=='up'){ 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 */
function realmlevel ($rp){ $rap =1; for ($i=1; $i<11; $i++){ if ($i!=1){ for ($j=0;$j<10;$j++){ $rp_needed = ((25/3)*(pow($rap,3))) - ((25/2)*(pow($rap,2))) + ((25/6)*$rap);
if ($rp_needed <10) { $rp_needed =0; } if ($rp>=$rp_needed) { $level = 'R'.$i.'L'.$j; } $rap++; } } else { for ($j=1;$j<10;$j++){ $rp_needed = ((25/3)*(pow($rap,3))) - ((25/2)*(pow($rap,2))) + ((25/6)*$rap);
if ($rp_needed <10) { $rp_needed =0; } if ($rp>=$rp_needed) { $level = 'R'.$i.'L'.$j; } $rap++; }
} } return $level; }
/* * returns Realm Title */
function realmtitle($rp){ /* * You start at Rank 1. To rise to Rank 2, you need 7125 realm points. * Rank 3 = 61750, Rank 4 = 213875, Rank 5 = 513500, Rank 6 = 1010625, Rank 7 = 1755250, Rank 8 = 2797375, Rank 9 = 4187000 * and finally Rank 10 = 5974125 * * These ranks are for the Albion Realm. You need to add correct values for Hibernia or Midgard. * The list of ranks per realm can be found at http://www.purpledragons.net/camelot/rp_chart.php */ if ($rp >=0) $title= 'Guardian'; if ($rp > 7125) $title = 'Warder'; if ($rp > 61750) $title = 'Myrmidon'; if ($rp > 213875) $title = 'Gryphon Knight'; if ($rp > 513500) $title = 'Eagle Knight'; if ($rp > 1010625) $title = 'Phoenix Knight'; if ($rp > 1755250) $title = 'Alerion Knight'; if ($rp > 2797375) $title = 'Unicorn Knight'; if ($rp > 4187000) $title = 'Lion Knight'; if ($rp > 5974125) $title = 'Dragon Knight'; return $title; }
// 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
if ($_POST['class']) { // checked vor value passed thru drop down menu // generate list for chosen class $content_output .= outputClassList($_POST['class'],'',0); $content_output .= $form; } else { // generates list for all classes foreach ($classes as $key=>$value){ $content_output .=outputClassList($value[0],$value[1],1); } $content_output .= $form; }
/* For Euro guilds: uncomment the following instructions */
// $content_output = utf8_decode($content_output); // handles UTF8 character encoding