00001 <?php
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 require_once('./general.php');
00026
00027 if( function_exists( 'curl_init' ) && function_exists( 'curl_setopt' ) && function_exists( 'curl_exec' ) && function_exists( 'curl_close' ) )
00028 {
00036 function curl_string($url, $proxy){
00037
00038 $ch = curl_init();
00039 curl_setopt( $ch, CURLOPT_PROXY, $proxy );
00040 curl_setopt( $ch, CURLOPT_URL, $url );
00041 curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla 5.0" );
00042 curl_setopt( $ch, CURLOPT_HEADER, 0 );
00043 curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
00044 curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1 );
00045 curl_setopt( $ch, CURLOPT_TIMEOUT, 120 );
00046 $result = curl_exec( $ch );
00047 curl_close($ch);
00048 return $result;
00049 }
00050 }
00051
00052
00053 $oStyle->setTemplate( 'xmlstats.html' );
00054 $oStyle->split_area( 'Stats' );
00055 $oStyle->split_area( 'ScoreTr' );
00056 $oStyle->split_area( 'BarTr' );
00057
00058 if( isset($strProxy) && !empty($strProxy) && function_exists( 'curl_string' ) )
00059 {
00060 @$strData = curl_string( $strServerStats, $strProxy );
00061 }
00062 else
00063 {
00064 @$strData = file_get_contents( $strServerStats );
00065 }
00066
00067 $aParams = MyXmlToArray( $strData );
00068
00069
00070 function &last( &$array )
00071 {
00072 if( !count( $array ) ) return null;
00073 end( $array );
00074 return $array[key( $array )];
00075 }
00076
00077 function myParseXML( &$vals, &$dom, &$lev )
00078 {
00079 do
00080 {
00081 $curr = current( $vals );
00082 $lev = $curr['level'];
00083 switch( $curr['type'] )
00084 {
00085 case 'open':
00086 if( isset( $dom[$curr['tag']] ) )
00087 {
00088 $tmp = $dom[$curr['tag']];
00089 if( empty( $tmp['__multi'] ) )
00090 $dom[$curr['tag']] = array( '__multi' => true, $tmp );
00091 array_push( $dom[$curr['tag']], array() );
00092 $new =& last( $dom[$curr['tag']] );
00093 } else {
00094 $dom[$curr['tag']] = array();
00095 $new =& $dom[$curr['tag']];
00096 }
00097 next( $vals );
00098 myParseXML( &$vals, $new, $lev );
00099 break;
00100 case 'cdata':
00101 break;
00102 case 'complete':
00103 if( !isset( $dom[$curr['tag']] ) )
00104 $dom[$curr['tag']] = $curr['value'];
00105 else
00106 {
00107 if( is_array( $dom[$curr['tag']] ) )
00108 array_push( $dom[$curr['tag']] , $curr['value'] );
00109 else
00110 array_push( $dom[$curr['tag']] = array($dom[$curr['tag']]) , $curr['value'] );
00111 }
00112 break;
00113 case 'close':
00114 return;
00115 }
00116 }
00117 while( next( $vals ) !== false );
00118 }
00119
00120 function MyXMLtoArray($XML)
00121 {
00122 $xml_parser = xml_parser_create();
00123 xml_parser_set_option( $xml_parser, XML_OPTION_SKIP_WHITE, 1 );
00124 xml_parse_into_struct( $xml_parser, $XML, $vals );
00125 xml_parser_free( $xml_parser );
00126 reset( $vals );
00127 $dom = array();
00128 $lev = 0;
00129 myParseXML( $vals, $dom, $lev );
00130 return $dom;
00131 }
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 if( empty( $aParams ) )
00142 {
00143 $strTmpl_inhalt = '<br>Fehler beim XML parsen.';
00144 output();
00145
00146 }
00147
00148 unset( $aParams['STATISTICS']['TOPUSER']['USER']['__multi'] );
00149 unset( $aParams['STATISTICS']['TOPTOWN']['TOWN']['__multi'] );
00150 unset( $aParams['STATISTICS']['RACES']['RACE']['__multi'] );
00151 unset( $aParams['STATISTICS']['TYPES']['TYPE']['__multi'] );
00152 unset( $aParams['STATISTICS']['GUILDS']['GUILD']['__multi'] );
00153
00154 $strUserScores = '';
00155 $strTownScores = '';
00156 $strTypes = '';
00157 $strRaces = '';
00158 $strGuilds = '';
00159
00160
00161 foreach( $aParams['STATISTICS']['TOPUSER']['USER'] AS $aData )
00162 {
00163 $oStyle->addReplacements( array( 'XML_RANK' => $aData['RANK'], 'XML_NAME' => $aData['NAME'], 'XML_SCORE' => $aData['SCORE'] ) );
00164 $strUserScores .= $oStyle->get_area( 'ScoreTr' );
00165 }
00166
00167
00168 foreach($aParams['STATISTICS']['TOPTOWN']['TOWN'] AS $aData)
00169 {
00170 $oStyle->addReplacements( array( 'XML_RANK' => $aData['RANK'], 'XML_NAME' => $aData['NAME'], 'XML_SCORE' => $aData['SCORE'] ) );
00171 $strTownScores .= $oStyle->get_area( 'ScoreTr' );
00172 }
00173
00174
00175 arsort( $aParams['STATISTICS']['RACES']['RACE'] );
00176 foreach( $aParams['STATISTICS']['RACES']['RACE'] AS $aData )
00177 {
00178 $dblPercent = $aData['COUNT'] / $aParams['STATISTICS']['USERS']['REGISTERED'];
00179 $oStyle->addReplacements( array( 'XML_W' => 150,
00180 'XML_W2' => round(150 * $dblPercent),
00181 'XML_W3' => round(150 - 150 * $dblPercent),
00182 'XML_H' => 15,
00183 'XML_NAME' => $aData['NAME'],
00184 'XML_COUNT' => $aData['COUNT'] ) );
00185 $strRaces .= $oStyle->get_area( 'BarTr' );
00186 }
00187
00188
00189 arsort($aParams['STATISTICS']['TYPES']['TYPE']);
00190 foreach($aParams['STATISTICS']['TYPES']['TYPE'] AS $aData )
00191 {
00192 $dblPercent = $aData['COUNT'] / $aParams['STATISTICS']['USERS']['REGISTERED'];
00193 $oStyle->addReplacements( array( 'XML_W' => 150,
00194 'XML_W2' => round(150 * $dblPercent),
00195 'XML_W3' => round(150 - 150 * $dblPercent),
00196 'XML_H' => 15,
00197 'XML_NAME' => $aData['NAME'],
00198 'XML_COUNT' => $aData['COUNT'] ) );
00199 $strTypes .= $oStyle->get_area( 'BarTr' );
00200 }
00201
00202 arsort($aParams['STATISTICS']['GUILDS']['GUILD']);
00203 $intMaxGuilds = 0;
00204 foreach($aParams['STATISTICS']['GUILDS']['GUILD'] AS $aData )
00205 {
00206 $intMaxGuilds += $aData['COUNT'];
00207 }
00208 foreach($aParams['STATISTICS']['GUILDS']['GUILD'] AS $aData)
00209 {
00210 $dblPercent = $aData['COUNT'] / $intMaxGuilds;
00211 $oStyle->addReplacements( array( 'XML_W' => 150,
00212 'XML_W2' => 150 * $dblPercent,
00213 'XML_W3' => 150 - 150 * $dblPercent,
00214 'XML_H' => 15,
00215 'XML_NAME' => $aData['NAME'],
00216 'XML_COUNT' => $aData['COUNT'] ) );
00217 $strGuilds .= $oStyle->get_area( 'BarTr' );
00218 }
00219
00220
00221 $oStyle->addReplacements( array( 'XML_USER' => $strUserScores,
00222 'XML_TOWN' => $strTownScores,
00223 'XML_TYPES' => $strTypes,
00224 'XML_RACES' => $strRaces,
00225 'XML_GUILDS' => $strGuilds,
00226
00227 'XML_ONLINE' => $aParams['STATISTICS']['USERS']['ONLINE'],
00228 'XML_PLAYER' => $aParams['STATISTICS']['USERS']['REGISTERED'],
00229 'XML_MAPSIZE' => $aParams['STATISTICS']['MAP']['SIZE-X'].' x '.$aParams['STATISTICS']['MAP']['SIZE-Y'],
00230 'XML_TOWNCOUNT' => $aParams['STATISTICS']['TOWNS'],
00231 'XML_BATTLE' => $aParams['STATISTICS']['BATTLES'],
00232 'XML_UNIT' => $aParams['STATISTICS']['UNITS']
00233 ) );
00234 $strTmpl_inhalt = $oStyle->get_area( 'Stats' );
00235 output();