[READ-ONLY] Mirror of https://github.com/andrioid/travian.scrolls.org. Retired project. I got a bit overly engaged in an online game called Travian.
0

Configure Feed

Select the types of activity you want to include in your feed.

travian.scrolls.org / parser.php
2.9 kB 117 lines
1<?php 2 3function ztoxy ($z) { 4/* 5x=-400+(d-1)%801 6y=401-ceil(d/801) 7 8*/ 9 $x = -400+($z-1)%801; 10 $y = 401-ceil($z/801); 11 12// $y=ceil(400-$z/801); 13// $x=z-401-((400-$y)*801); 14 return(array( 15 $x, 16 $y 17 )); 18} 19 20function extract_d ($link) { 21 $f = strpos($link, "karte.php?d=")+strlen("karte.php?d="); 22 $c = strpos($link, "&c="); 23 $d = substr($link, $f, $c-$f); 24 $cd = substr($link, $c+3, strlen($link)-($c+4)); 25 return array( 26 $d, 27 $cd 28 ); 29 //printf("Link (%s) (%s) (%s)<br>", $f, $c, $d); 30} 31 32if (!empty($_POST['pasteregion'])) { 33 $pasteregion = stripslashes($_POST['pasteregion']); 34 #preg_match("/Forkortelse:\t(.+)\ \t/", $_POST['pasteregion'], $tag); 35 #preg_match("/Navn:\t(.+)\n/", $_POST['pasteregion'], $alliance); 36 $len = strlen($pasteregion); 37 #$varray = explode("\n", $pasteregion); 38 /* Find action element */ 39 //$pasteregion = "<table cellspacing=\"1\" cellpadding=\"2\" class=\"tbg\">mamma er foli </td></tr></table></td></table>"; 40 if ($matches = preg_split("~<(/?)([^>]*)>~", $pasteregion,-1,PREG_SPLIT_DELIM_CAPTURE)) { 41 foreach ($matches as $i=>$value) { 42 if ($value == "table cellspacing=\"1\" cellpadding=\"2\" class=\"tbg\"") { 43 $mark = $i; 44/* $townlink = $matches[$i+9]; 45 $town = $matches[$i+13]; 46 $ownlink = $matches[$i+27]; 47 $description = $matches[$i+31]; 48 $timer = $matches[$i+244]; 49 $arrival = $matches[$i+253]; 50*/ 51 list($d,$c) = extract_d($matches[$i+9]); 52 list($x,$y) = ztoxy($d); 53 54 if (!empty($matches[$i+244]) and !empty($matches[$i+253]) and !empty($d)) { 55 $Incoming[] = array( 56 'village' => $matches[$i+13], 57 'x' => $x, 58 'y' => $y, 59 'id' => $d, 60 'c' => $c, 61 // 'townlink' => $townlink, 62 'description' => $matches[$i+31], 63 'timer' => $matches[$i+244], 64 'arrival' => $matches[$i+253] 65 ); 66 } 67 //printf("Incoming %d (%s) (%s)<br>\n", $i, $town, $townlink); 68 } elseif (!empty($value)) { 69 //printf("<pre>[%d] [%d] %s</pre>", $i, $i-$mark, htmlspecialchars($value)); 70 } 71 72 } 73 echo "<pre>"; print_r($Incoming); echo "</pre>\n"; 74 } else { 75 printf("No luck<br><br>\n"); 76 } 77 //printf("String (%s) <br>\n", htmlspecialchars($pasteregion)); 78 #$spos = strpos($pasteregion, "\tSpillere \t"); 79 #$spos = $spos+36; 80 #$epos = strpos($pasteregion, "Landsbyer:"); 81 #$epos = $epos-2; 82 #$plen = $epos-$spos; 83 #$players = substr($pasteregion, $spos, $plen); 84 #$parray = explode("\n", $players); 85 #echo "(".$spos.")"i; 86 #printf("(%d/%d/$d") (%s)", $spos, $epos, $plen, $players); 87} 88 89?> 90 91<HTML> 92<HEAD> 93 <TITLE>Rally Point Parser</TITLE> 94</HEAD> 95<BODY> 96<FORM METHOD=POST> 97<TEXTAREA NAME="pasteregion"></TEXTAREA> 98<INPUT TYPE=SUBMIT value="Submit"> 99</FORM> 100<?PHP 101/* 102foreach ($parray as $p) { 103 $e = explode("\t", $p); 104 echo "Rank: ".$e[0]." Name: ".$e[1]." Pop: ".$e[2]." Towns: ".$e[3]." <br>\n"; 105} 106*/ 107?> 108<PRE> 109<?php 110 111print_r($xml); 112 113?> 114</PRE> 115</BODY> 116</HTML> 117