highlights.php

Go to the documentation of this file.
00001 <?php
00013 require_once(dirname(__FILE__).'/base.php');    
00014  
00021 class LFSWorldHighlights extends LFSWorldDataProvider
00022 {
00027     var $m_sURL = 'http://www.lfsworld.net/highlight_countries/highlights___COUNTRY__.txt';
00028     
00033     var $m_aSrcMetaData = array('lifeTime' => 60, 'actualTarpit'=>0);
00034     
00039     var $m_sCountry = null;
00040     
00045     var $m_bNoParse = false;
00046     
00051     var $m_aColourReplace = array('<FONT COLOR="#000000"' => '^0',
00052                                   '<FONT COLOR="#FF0000"' => '^1',
00053                                   '<FONT COLOR="#00FF00"' => '^2',
00054                                   '<FONT COLOR="#FFFF00"' => '^3',
00055                                   '<FONT COLOR="#0000FF"' => '^4',
00056                                   '<FONT COLOR="#FF00FF"' => '^5',
00057                                   '<FONT COLOR="#00FFFF"' => '^6',
00058                                   '<FONT COLOR="#FFFFFF"' => '^7');
00059     
00069     function parse($rawList, &$outputList)
00070     {
00071         $rawList = explode("\n", $rawList);
00072         
00073         if($this->m_bNoParse == true)
00074         {
00075             if(is_array($outputList))
00076                 $outputList = array_merge($outputList, $rawList);
00077             else
00078                 $outputList = $rawList;
00079 
00080             return true;
00081         }
00082         
00083         $pbHighs = array();
00084         $wonHighs = array();
00085         $unkHighs = array();
00086 
00087         $colourSrc = array_keys($this->m_aColourReplace);
00088         $colourDst = array_values($this->m_aColourReplace);
00089         foreach($rawList as $line)
00090         {
00091             $idSect = substr($line, 0, 50);
00092             if(stristr($idSect, ' drove a PB: '))
00093             {
00094                 //%name drove a PB: %time on %track with %car
00095                 preg_match("/(.*) drove a PB: ([0-9]{1,}):([0-9]{2})\.([0-9]{3}) on (.*) with (.*)/i", $line, $tmp);                
00096                 list($line, $pb['racer'], $mins, $secs, $msecs, $pb['track'], $pb['car']) = $tmp;
00097                 $pb['time'] = ($msecs/10) + ($secs*100) + (($mins*100)*60);
00098                 $pbHighs[] = array($pb, $line);
00099             }
00100             else if(stristr($idSect, ' won the race held on '))
00101             {
00102                 //%name won the race held on %server                
00103                 $line = str_replace('</FONT>', '', $line);
00104                 $line = str_replace($colourSrc, $colourDst, $line); 
00105                 $won = array();
00106                 $won['name'] = substr($line, 0, strpos($line, ' won the race held on '));
00107                 $offset = strlen($won['name']) + 22;
00108                 $won['server'] = substr($line, $offset);
00109                 $wonHighs[] = $won;
00110             }
00111             else if(trim($line) != '')
00112             {
00113                 $unkHighs[] = $line;
00114             }
00115         }
00116 
00117         $outputList['pbs'] = $pbHighs;
00118         $outputList['won'] = $wonHighs;
00119         $outputList['unknown'] = $unkHighs;
00120         
00121         return true;
00122     }
00123     
00131     function initParams(&$params)
00132     {       
00133         if($params['noParse'] == true)
00134             $this->m_bNoParse = true;
00135 
00136         if(isset($params['country']))
00137         {
00138             $this->m_sCountry = str_replace(' ', '_', $params['country']);
00139             //reinit params since this provider doesn't take any and make sure base::initParams knows we don't want compression
00140             $params = array();
00141             $params['c'] = 0;
00142         }
00143         else
00144         {
00145             return false;
00146         }
00147 
00148         if(!parent::initParams($params))
00149             return false;
00150             
00151         return true;
00152     }
00153 
00163     function getURL()
00164     {
00165         if($this->m_sCountry != null)
00166             return str_replace('__COUNTRY__', $this->m_sCountry, $this->m_oRequest->_url->getURL());
00167         else
00168             return $this->m_oRequest->_url->getURL();
00169     }
00170 }
00171 
00172 ?>

Generated on Wed Oct 25 03:13:32 2006 for LFSWorldParsingProviderFramework by  doxygen 1.4.6