3 $textsourcefile_web = "http://meta.wikipedia.org/w/index.php?title=PortalText&action=raw" ;
4 $textsourcefile = "t.txt" ;
5 #$articlecountfile_web = "http://magnusmanske.de/wikipedia/num.txt" ;
6 $articlecountfile_web = "num.txt" ;
7 $articlecountfile = "n.txt" ;
10 if ( isset ( $HTTP_SERVER_VARS["HTTP_ACCEPT_LANGUAGE"] ) )
11 $userlang = $HTTP_SERVER_VARS["HTTP_ACCEPT_LANGUAGE"] ;
15 if ( isset ( $_GET["update"] ) )
17 copy ( $textsourcefile_web , $textsourcefile ) ;
18 copy ( $articlecountfile_web , $articlecountfile ) ;
21 # Reads a file into a string
22 function readafile ( $filename )
24 $handle = fopen($filename, "r");
26 while (!feof($handle))
27 $contents .= fread($handle, 8192);
32 # Parsing statistics file
33 function get_numbers ( $filename )
36 $nt = readafile ( $filename ) ;
37 $nt = explode ( "\n" , $nt ) ;
40 $y = explode ( ":" , $x ) ;
41 if ( count ( $y ) == 2 )
42 $r[strtolower($y[0])] = $y[1] ;
47 # Make shades for pref. language(s)
48 function getshades ( $l )
51 $l = explode ( "," , $l ) ;
54 $y = explode ( ";" , $x ) ;
55 if ( count ( $y ) == 2 ) $weight = array_pop ( explode ( "=" , $y[1] ) ) ;
56 else $weight = "1.0" ;
58 $lang = array_shift ( $y ) ;
59 $lang = explode ( "-" , $lang ) ;
60 $lang = trim ( strtolower ( array_shift ( $lang ) ) ) ;
63 $w = chr ( 70 - $w ) ;
66 if ( !isset ( $r[$lang] ) ||
$r[$lang] < $w )
72 # Parsing text file and generating output
73 $n = get_numbers ( $articlecountfile ) ;
74 $shade = getshades ( $userlang ) ;
75 $l = "<table align=center border=1 width='50%' cellpadding=2>" ;
77 $t = readafile ( $textsourcefile ) ;
78 $t = explode ( "\n" , $t ) ;
81 $y = explode ( ":" , $x , 2 ) ;
82 if ( count ( $y ) == 2 )
84 $language = trim ( strtolower ( $y[0] ) ) ; # language id
85 if ( isset ( $n[$language] ) ) # Only if there's a number to show
87 $ltext = $y[1] ; # Language text
88 $noa = $n[$language] ; # Number of articles
89 $ltext = str_replace ( "###" , "<b>{$noa}</b>" , $ltext ) ;
90 if ( isset ( $shade[$language] ) ) $s = " bgcolor='#" . $shade[$language] . "'" ;
92 $ltext = "<td{$s}>{$ltext}</td>\n" ;
93 if ( $count == 0 ) $l .= "<tr>" ;
95 if ( $count == $perrow-1 )
104 if ( $count != 0 ) $l .= "</tr>" ;
107 print "<html><head></head><body>" ;
109 print "</body></html>" ;