NationStates Jolt Archive


PHP Scripts for Region Sites

Wargoul
30-06-2006, 05:54
Well I noticed quite a few sites based on regions are on the web. I thought it would be cool if there were PHP scripts for these sites to display content. I decided to write a serious of scripts.

Heres the first that will let you see the top 10 in your region and I will eventually fix it to display everyone in pagenation. All thought I haven't finished it yet.

Working demo: http://goodvillain.com/ns/

<?
//Script by Brad "GoodVillain" Metcalf of the Wargoul Nation
//goodvillain.com

//Edit the below with your region name
$region = "allied_union_of_nations";

//Dont edit below unless you know what your doing

$rname = ereg_replace("[^A-Za-z0-9]", " ", $region);
$rname = ucwords($rname);
$rname = ucwords(strtolower($rname));
echo "Top 10 Nations in the $rname Region<br>";
set_time_limit(0);
$reg = '/.<\/td><td><a href=\"nation=(.*?)\"><img src=\"\/images\/flags\/(.*?)\"/i';
$page = join("", file("http://www.nationstates.net/page=display_region/region=$region"));
$page = ereg_replace("\n", "", $page);
preg_match_all($reg, $page, $matches);
$cnt = count($matches[0]);
for($x=0;$x<$cnt;$x++){
$url = $matches[1][$x];
$flag = $matches[2][$x];
$name = ereg_replace("[^A-Za-z0-9]", " ", $url);
$name = ucwords($name);
$name = ucwords(strtolower($name));
echo "<a href=\"http://nationstates.net/$url\"><img src=\"http://nationstates.net/images/flags/$flag\" alt=\"Flag\" hspace=\"6\" align=\"absmiddle\" height=\"26\" width=\"40\" border=\"0\"> $name</a><br>";
}
?>

Now PHP coders are thinking oh wooo thats simple. I know it is. My goal is to write a full portal that gets a lot more information of the region and nations in that region. But have it save to MySQL so the portals load faster. I was wondering if anyone would like to join the project and help me design the portals and choose what goes in them. Just so its not a complete rip of the region pages on this site I would also like to add content to make it a bit different, possibly doc management and ect for laws. I am actually very knowledgable in PHP so I am not looking for some slave, Ill do my fair share of the work too. :)
Mac Anu
30-06-2006, 19:36
I'm actually working on a PHP script that scrapes some of the information that ISN'T in the XML feed currently and dumps it into a modified XML (or RDF) feed.

I'll gladly donate the code to your cause when it's primarily complete. It's still undergoing maintenance and development (especially on the RDF feed end, as I work on a suitable schema), but you can check it out at:

http://www.pipian.com/nationstates/xml2rdf.php?nation=<your-nation-here>

for RDF, and appending "&xml=1" for the XML feed (backwards compatible with the standard feeds)

Likewise, for regions:

http://www.pipian.com/nationstates/xml2rdf.php?region=<your-nation-here>

and for the world:

http://www.pipian.com/nationstates/xml2rdf.php?world=1

Remembering that by appending "&xml=1" you will get an XML feed backwards compatible with the existing Nationstates feed.

No generated figures (e.g. GDP) are included. Only figures straight from the game.

Currently, data added includes:

For Nation Feeds:

Number of UN Endorsements
List of countries Endorsing the country (in the same colon-delimited format as the region's nation-list
Regional Influence
Daily UN Ranking (including Topic, Regional, and World ranking)


For Region Feeds:

Regional Power
How long ago the delegate was elected


The new World Feed:

Number of nations
Number of regions
Number of UN members
Number of UN delegates
Current resolution info including Title, Category, Strength, Proposer, Text, Votes for and agains, and the ending date of the vote


Things still to be added or fixed (potentially):

For Region Feeds:

HTML version of the factbook (could be difficult)
Top 10 UN ranked nations
Handling of HTML entities should be fixed.


For the World Feed:

Top 10 UN ranked nations
Information on the last UN resolution
Handling of HTML entities should be fixed and carriage-returns in the text should display properly.
Wargoul
30-06-2006, 22:45
Pretty nice. I was unaware of xml feeds. I heard there was some but I couldn't find any feed links.

Thanks for the help. I am now writing some of the easier parts that don't take information from NS. This is news posting for selected members, document management with voting for members, a members system for members only areas. And several other things. I think all these will be useful that NS doesn't provide. All though you can do this with forums the boards weren't created for such a purpose so this allows it to be easier organized I think.
Mac Anu
01-07-2006, 00:39
Yeah, I don't have the free time to work on the nitty gritty stuff like that but I'll contribute little things here and there if I can.

For example, I do have all the code for the old Coroboland website (region now defunct, so the website, which depends on some of the variables from the XML feeds isn't completely operational) at http://www.pipian.com/coroboland/ and would be willing to contribute some of it (mostly having to do with how the regions/nations display in a factbook like format.)