1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500
| <?php
// SERVER AND GUILD SETTINGS
$config['server_name'] = 'Elune'; // Name of the WoW Realm
$config['guild_name'] = 'Threnody'; // Name of your Guild
// SETTINGS FOR THE GENERAL WEBSITE
$config['base_filename'] = 'roster.php'; // Base script file name
$config['base_url'] = 'http://www.wowps.org/threnody/'; // Base URL
$config['url_prefix_char'] = 'http://www.wowarmory.com/character-sheet.xml?'; // Use for Char links
$config['url_prefix_armory'] = 'http://www.wowarmory.com/'; // URL for the armory
// NOTE: THE BELOW DIRECTORY NEEDS TO HAVE WRITE ACCESS IN ORDER TO CACHE THE XML
$config['DIR_cache'] = 'cache/'; // Directory where the XML cache files are stored
// NOTE: THE ABOVE DIRECTORY NEEDS TO HAVE WRITE ACCESS IN ORDER TO CACHE THE XML
// SETTINGS FOR SQL STATEMENT GENERATION
$config['sql_database'] = 'INSERT_YOUR_SQL_DATABASE_NAME_HERE'; // SQL Database Name
$config['sql_table'] = 'INSERT_YOUR_GUILD_CHARACTER_TABLE_NAME_HERE'; // SQL Table Name
class armory {
const BROWSER="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.2) Gecko/20070319 Firefox/2.0.0.3";
public $query;
public $server;
public $guild;
public $guildie;
public $page;
public function __construct ( $query, $server, $guild, $guildie, $page ) {
$this->query = $query;
$this->server = $server;
$this->guild = $guild;
$this->guildie = $guildie;
$this->page = $page;
} // end of __construct()
public function pull_xml() {
global $config;
// change the first part of the $url to the armory link that you need
if( $this->query === 'roster' ){
$filename_type = 'guild-info';
$url = $config['url_prefix_armory'].$filename_type.'.xml?r=' . urlencode($this->server) . '&n=' . urlencode($this->guild) . '&p=' . $this->page;
}elseif( $this->query === 'character' ){
$filename_type = 'character-sheet';
$url = $config['url_prefix_armory'].$filename_type.'.xml?r=' . urlencode($this->server) . '&n=' . $this->guildie;
}
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt ($ch, CURLOPT_USERAGENT, self::BROWSER);
$url_string = curl_exec($ch);
curl_close($ch);
echo '<b>LIVE XML FEED:</b> <a href="'.$url.'" target="_BLANK">'.$url.'</a><P>';
// Cache the XML Stream
cacheXMLfile($filename_type, $url_string);
// change the first part of the $url to the armory link that you need
if( $this->query === 'roster' ){
// GET LATEST GUILD XML FILE
$dira = "cache";
$dir = opendir ("./".$dira);
$new_file_size = 0;
$new_file_time = 0;
$new_file_name = "";
while (false !== ($file = readdir($dir))) {
if (strpos($file, 'guild-info' ) === false ) {
} else {
$file_size = filesize("$dira/$file");
$file_time = filemtime("$dira/$file");
if ( $file_size > 614 ) {
//echo "COMPARE -> '".$new_file_name."' '".$file."' <br /> ".$new_file_size."<=".$file_size." | ".$new_file_time."<".$file_time." | <br />";
if ( $file_size >= $new_file_size ) {
//echo "larger file<br />";
if ( $file_time >= $new_file_time ) {
//echo "newer file<br />";
$new_file_size = $file_size;
$new_file_time = $file_time;
$new_file_name = $file;
}
} else {
$new_file_size = $file_size;
$new_file_time = $file_time;
$new_file_name = $file;
}
}
}
}
$url = $config['base_url'].$config['DIR_cache'].$new_file_name;
//echo "<P>RESULT -> ".$new_file_name." - ".$new_file_size." - ".$new_file_time." <br /><br /><br /><br />";
}elseif( $this->query === 'character' ){
$url = $config['base_url'].$config['DIR_cache'].'character-sheet.xml';
}
$url_string = simplexml_load_file($url) or die ("ERROR: Unable to load XML file!");
echo '<b>USING CACHED XML FEED:</b> <a href="'.$url.'" target="_BLANK">'.$url.'</a><P>';
return $url_string;
} // end of pull_xml()
} // end class
//------------------------------------------------------------------
// Display a Javascript Alert Box [FOR DEBUG PURPOSES]
function alert($textMessage) {
global $config;
print('<script language="javascript">alert("'.$textMessage.'")</script>');
}
//------------------------------------------------------------------
// Save XML Stream to the cache directory
function cacheXMLfile($filename, $XMLstream) {
global $config;
$XML_filename = $config['DIR_cache'].$filename.'-'.date('Y.m.d-H.i.s').'.xml';
$handle = fopen($XML_filename, "wb");
$numbytes = fwrite($handle, $XMLstream);
fclose($handle);
echo '<b>LIVE XML FEED CACHED TO XML FILE:</b> '.$XML_filename.' - '.$numbytes.' bytes written...<P>';
}
//------------------------------------------------------------------
// Build the Character Array from the supplied XML stream
function buildCharacterArray($XMLstream) {
global $config;
$count_Members = 0;
$char_Array = array();
foreach ($XMLstream->guildInfo->guild->members->character as $char) {
//if ( $char['level'] < 20 ) continue; // Limits display Chars beyond a certain level
//if ( $char['rank'] > 5 ) continue; // Limits display to active members and above (depending on your guild ranks)
$toonrace = return_race($char['raceId'], $char['genderId']); // Maps Race and Sex
$toongender = return_gender($char['genderId']); // Maps Sex
$toonclass = return_class($char['classId']); // Maps class name
$toonrank = return_rank($char['rank']); // Maps guild rank name
$char_info_Array = array(
"name" => (string)$char['name'],
"level" => (string)$char['level'],
"class" => $toonclass,
"gender" => $toongender,
"race" => $toonrace,
"rank" => $char['rank'].' - '.$toonrank,
"achPoints" => (string)$char['achPoints'],
"link" => $config['url_prefix_char'].(string)$char['url'] );
$count_Members++;
$char_Array[] = $char_info_Array;
}
return $char_Array;
}
//------------------------------------------------------------------
// Print the supplied Character Array
function printCharacterArray($charArray, $array_sort_field, $array_sort_direction) {
global $config;
switch($array_sort_direction){
case 'asc' :
$sortDir = 'desc';
break;
case 'desc' :
$sortDir = 'asc';
break;
}
switch($array_sort_field){
case 'name' :
$sortFieldname = ' ['.$array_sort_direction.']';
break;
case 'level' :
$sortFieldlevel = ' ['.$array_sort_direction.']';
break;
case 'class' :
$sortFieldclass = ' ['.$array_sort_direction.']';
break;
case 'gender' :
$sortFieldgender = ' ['.$array_sort_direction.']';
break;
case 'race' :
$sortFieldrace = ' ['.$array_sort_direction.']';
break;
case 'rank' :
$sortFieldrank = ' ['.$array_sort_direction.']';
break;
case 'achPoints' :
$sortFieldachPoints = ' ['.$array_sort_direction.']';
break;
case 'link' :
$sortFieldlink = ' ['.$array_sort_direction.']';
break;
}
echo '<b>DISPLAY GUILD DATA:</b><BR/><table width="100%" border="1">';
echo '<td width=""><a href="'.$config['base_filename'].'?sort=name&direction='.$sortDir.'">NAME'.$sortFieldname.'</a></td>';
echo '<td width=""><a href="'.$config['base_filename'].'?sort=level&direction='.$sortDir.'">LEVEL'.$sortFieldlevel.'</a></td>';
echo '<td width=""><a href="'.$config['base_filename'].'?sort=class&direction='.$sortDir.'">CLASS'.$sortFieldclass.'</a></td>';
echo '<td width=""><a href="'.$config['base_filename'].'?sort=gender&direction='.$sortDir.'">GENDER'.$sortFieldgender.'</a></td>';
echo '<td width=""><a href="'.$config['base_filename'].'?sort=race&direction='.$sortDir.'">RACE'.$sortFieldrace.'</a></td>';
echo '<td width=""><a href="'.$config['base_filename'].'?sort=rank&direction='.$sortDir.'">RANK'.$sortFieldrank.'</a></td>';
echo '<td width=""><a href="'.$config['base_filename'].'?sort=achPoints&direction='.$sortDir.'">POINTS'.$sortFieldachPoints.'</a></td>';
echo '<td width=""><a href="'.$config['base_filename'].'?sort=link&direction='.$sortDir.'">URL'.$sortFieldlink.'</a></td>';
echo '</tr>';
foreach ($charArray as $char) {
echo '<tr id="'.$char['name'].'">';
echo '<td>'.$char['name'].' </td>';
echo '<td>'.$char['level'].' </td>';
echo '<td>'.$char['class'].' </td>';
echo '<td>'.$char['gender'].' </td>';
echo '<td>'.$char['race'].' </td>';
echo '<td>'.$char['rank'].' </td>';
echo '<td>'.$char['achPoints'].' </td>';
echo '<td><a href="'.$char['link'].'" target="_blank">'.$char['link'].'</a></td>';
echo '</tr>';
$count_Members++;
}
echo '</table>';
}
//------------------------------------------------------------------
// Print the supplied Character Array as a SQL import statement
//
// MODIFY THIS FUNCTION TO OUTPUT INTO A DIFFERENT SQL FORMAT
//
function printSQLCharacterArray($charArray) {
global $config;
$sql_string = "USE ".$config['sql_database']."; TRUNCATE TABLE ".$config['sql_table'].";
";
foreach ($charArray as $char) {
$sql_row = "INSERT INTO ".$config['sql_table']." (name, level, gender, class, race, rank, achPoints, url) VALUES ('";
$sql_row .= $char['name'];
$sql_row .= "','".$char['level'];
$sql_row .= "','".$char['gender'];
$sql_row .= "','".$char['class'];
$sql_row .= "','".$char['race'];
$sql_row .= "','".$char['rank'];
$sql_row .= "','".$char['achPoints'];
$sql_row .= "','".$char['link']."');
";
$sql_string .= $sql_row;
}
echo '<b>SQL IMPORT STATEMENT:</b><BR/><textarea rows="30" cols="180" wrap="off">'.$sql_string.'</textarea><P>';
}
//------------------------------------------------------------------
// Sort the supplied Character Array and return the sorted char array
function sortCharacterArray($charArray, $array_sort_field, $array_sort_direction) {
// OBTAIN A LIST OF COLUMNS TO SORT
foreach ($charArray as $key => $row) {
$name[] = $row['name'];
$level[] = $row['level'];
$class[] = $row['class'];
$gender[] = $row['gender'];
$race[] = $row['race'];
$rank[] = $row['rank'];
$achPoints[] = $row['achPoints'];
$link[] = $row['link'];
}
switch($array_sort_field){
case 'name' :
$sortField = $name;
$sortType = SORT_STRING;
break;
case 'level' :
$sortField = $level;
$sortType = SORT_NUMERIC;
break;
case 'class' :
$sortField = $class;
$sortType = SORT_STRING;
break;
case 'gender' :
$sortField = $gender;
$sortType = SORT_STRING;
break;
case 'race' :
$sortField = $race;
$sortType = SORT_STRING;
break;
case 'rank' :
$sortField = $rank;
$sortType = SORT_NUMERIC;
break;
case 'achPoints' :
$sortField = $achPoints;
$sortType = SORT_NUMERIC;
break;
case 'link' :
$sortField = $link;
$sortType = SORT_STRING;
break;
}
switch($array_sort_direction){
case 'asc' :
array_multisort($sortField, SORT_ASC, $sortType, $level, SORT_DESC, SORT_NUMERIC, $name, SORT_ASC, SORT_STRING, $charArray);
break;
case 'desc' :
array_multisort($sortField, SORT_DESC, $sortType, $level, SORT_DESC, SORT_NUMERIC, $name, SORT_ASC, SORT_STRING, $charArray);
break;
}
return $charArray ;
}
// Previously declared functions...
static $browser_user_agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
function return_class($classid) {
switch ($classid) {
case 1:
$class = "Warrior";
break;
case 2:
$class = "Paladin";
break;
case 3:
$class = "Hunter";
break;
case 4:
$class = "Rogue";
break;
case 5:
$class = "Priest";
break;
case 6:
$class = "Death Knight";
break;
case 7:
$class = "Shaman";
break;
case 8:
$class = "Mage";
break;
case 9:
$class = "Warlock";
break;
case 11:
$class = "Druid";
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 = "Den Mother";
break;
case 1:
$class = "Guild Officer";
break;
case 2:
$class = "Epic";
break;
case 3:
$class = "Rare";
break;
case 4:
$class = "Unknown";
break;
case 5:
$class = "Groupie";
break;
case 6:
$class = "Groupie-Alt";
break;
case 7:
$class = "Epic-Alt";
break;
case 8:
$class = "Rare-Alt";
break;
}
return $class;
}
function return_race2($raceid, $sex) {
switch ($raceid) {
case 1:
if ($sex == "0") {$race = "Human Male";}
if ($sex == "1") {$race = "Human Female";}
break;
case 2:
if ($sex == "0") {$race = "Orc Male";}
if ($sex == "1") {$race = "Orc Female";}
break;
case 3:
if ($sex == "0") {$race = "Dwarf Male";}
if ($sex == "1") {$race = "Dwarf Female";}
break;
case 4:
if ($sex == "0") {$race = "Night Elf Male";}
if ($sex == "1") {$race = "Night Elf Female";}
break;
case 5:
if ($sex == "0") {$race = "Undead Male";}
if ($sex == "1") {$race = "Undead Female";}
break;
case 6:
if ($sex == "0") {$race = "Tauren Male";}
if ($sex == "1") {$race = "Tauren Female";}
break;
case 7:
if ($sex == "0") {$race = "Gnome Male";}
if ($sex == "1") {$race = "Gnome Female";}
break;
case 8:
if ($sex == "0") {$race = "Troll Male";}
if ($sex == "1") {$race = "Troll Female";}
break;
case 10:
if ($sex == "0") {$race = "Blood Elf Male";}
if ($sex == "1") {$race = "Blood Elf Female";}
break;
case 11:
if ($sex == "0") {$race = "Draenei Male";}
if ($sex == "1") {$race = "Draenei Female";}
break;
}
return $race;
}
function return_race($raceid, $sex) {
switch ($raceid) {
case 1:
$race = "Human";
break;
case 2:
$race = "Orc";
break;
case 3:
$race = "Dwarf";
break;
case 4:
$race = "Night Elf";
break;
case 5:
$race = "Undead";
break;
case 6:
$race = "Tauren";
break;
case 7:
$race = "Gnome";
break;
case 8:
$race = "Troll";
break;
case 10:
$race = "Blood Elf";
break;
case 11:
$race = "Draenei";
break;
}
return $race;
}
function return_gender($genderid) {
if ($genderid == "0") {$gender = "Male";}
if ($genderid == "1") {$gender = "Female";}
return $gender;
}
?> |
Partager