| Dark Severance |
01-08-2009 12:36 AM |
xml Grabber w/ cURL w/ sortableTable?
Using code from this post:
http://www.talkphp.com/show-off/3281...bber-curl.html
I started working with the from the Armory using what was there, combining that with a Sortable Table script so that the roster can be easily organized, filtered depending on what you are looking for.
Here is example of it working fine. Everything works great:
http://wow.guildregister.com/sortableTable/roster2.php
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PoD - Roster Test</title>
<link rel="stylesheet" href="../_common/css/main.css" type="text/css" media="all">
<link href="sortableTable.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../_common/js/mootools.js"></script>
<script type="text/javascript" src="sortableTable.js"></script>
</head>
<body>
<script type="text/javascript" src="wz_tooltip.js"></script>
<?php
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() {
// change the first part of the $url to the armory link that you need
if( $this->query === 'roster' ){
$url = 'http://www.wowarmory.com/guild-info.xml?r=' . urlencode($this->server) . '&n=' . urlencode($this->guild) . '&p=' . $this->page;
}elseif( $this->query === 'character' ){
$url = 'http://www.wowarmory.com/character-sheet.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);
return simplexml_load_string($url_string);
} // end of pull_xml()
} // end class
$armory = new armory('roster', 'Drenden', 'Priests of Discord', NULL, NULL);
$xml = $armory->pull_xml();
?>
<div id="container">
<div id="PoD"><img src="http://wow.guildregister.com/mkportal/templates/wow/images/logo.jpg"></div>
<br />
<div class="nav"><a href="../">home</a></div>
<p class="desc">Description information can go here .. .. ...</p>
<h3 class="Guild">Guild Roster Test</h3>
<div id="example">
<div class="tableFilter">
<form id="tableFilter" onsubmit="myTable.filter(this.id); return false;">Filter:
<select id="column">
<option value="0">Level</option>
<option value="1">Name</option>
<option value="2">Class</option>
<option value="3">Race</option>
<option value="4">Achievement Points</option>
</select>
<input type="text" id="keyword" />
<input type="submit" value="Submit" />
<input type="reset" value="Clear" />
</form>
</div>
<table id="myTable" cellpadding="0" cellpadding="0">
<thead>
<th axis="number">Level</th>
<th axis="string">Name</th>
<th axis="string">Class</th>
<th axis="string">Race</th>
<th axis="number">Achievement Points</th>
</thead>
<tbody>
<?
foreach ($xml->guildInfo->guild->members->character as $char) {
echo "<tr id=\"".$char['name']."\">";
echo "<td>".$char['level']."</td>";
echo "<td>".$char['name']."</td>";
echo "<td>".$char['class']."</td>";
echo "<td>".$char['race']."</td>";
echo "<td>".$char['achPoints']."</td>";
echo "</tr>";
}
?>
</tbody>
<tfoot>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tfoot>
</table>
<script type="text/javascript">
var myTable = {};
window.addEvent('domready', function(){
myTable = new sortableTable('myTable', {overCls: 'over', onClick: function(){alert()}});
});
</script>
</div>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-3333085-1");
pageTracker._initData();
pageTracker._trackPageview();
</script>
</body>
</html>
I wanted to add more to it by making the name linkable to the armory profile and also using icon graphic to represent class, race similar to the armory itself. The good news is I have it working. The bad news is that breaks the filter function, I can't seem to be able search by anything except level.
Here is it with the URL links and graphics working, however if you notice the filters aren't working anymore:
http://wow.guildregister.com/sortableTable/roster.php
The only code that I changed out was the echo for the "foreach" part adding in url and image links based on the variables.
Code:
<?
foreach ($xml->guildInfo->guild->members->character as $char) {
echo "<tr id=\"".$char['name']."\">";
echo "<td>".$char['level']."</td>";
echo "<td>".$char['name']."<a href=\"http://www.wowarmory.com/character-sheet.xml?".$char['url']."\" onclick=\"window.open(this.href); return false\" \">".$char['name']."</a</td>";
echo "<td><img src=\"images/icons/".$char['classId'].".gif\" onmouseover=\"Tip('".$char['class']."')\" onmouseout=\"UnTip()\"></td>";
echo "<td><img src=\"images/icons/".$char['raceId']."-".$char['genderId'].".gif\" onmouseover=\"Tip('".$char['race']." ".$char['gender']."')\" onmouseout=\"UnTip()\"></td>";
echo "<td>".$char['achPoints']."</td>";
echo "</tr>";
}
?>
Any idea on why the search function wouldn't work anymore?
|