LFSW-PPF; LFSWorld Data, right here, right now.

Discussion in 'LFSW-PPF' started by Anarchi-h, Jul 16, 2005.

  1. Anarchi-h

    Anarchi-h New Member

    Firstly, props to Ian.h for setting up this sub forum for me for LFSW-PPF (LFSWorld Parsing Provider Framework). :thumb3d: Top guy, even if he does like feeding trolls :p

    LFSW-PPF is a modular set of classes written in PHP aimed at amateur web developers who want to get LFSWorld data on their site.

    The basic idea is that the same code base should work for all data sources, with only a change in the provider (parsing) object, and the manipulation code required.

    It comes with several utility classes too, such as Track, car and rule format converters, an additional SQL cache (you'll have to let me know if you want to use this because it is much more complex than a standard cache), and a versatile colour processor for LFS colour encoded strings.

    You will need;

    • PEAR::HTTP_Request.
    • PEAR::Net_URL.
    • PEAR::Cache_lite.
    • Knowledge of PHP Arrays, Objects and References.

    Alternatively, you can send some cash and your requirements my way, and I'd be inclined to do it for you :p

    The original RSC forum thread can be found hnyah http://forum.rscnet.org/showthread.php?t=214865 , where you might find some additional info, but RSC is kinda flakey atm.

    The package includes a couple of samples to get you started, and although I've provided full PHPDocs, there are still some features that have gone undocumented. These will be documented as and when I get time, and the urge.

    LFSW-PPF is totally free for use, modification, whatever. Rip it off if you like; I'll be sure to jab you in the ass when we meet in hell :p. I know I've released it to the world, and that is enough for me, but if you really want to let the world know you are using LFSW-PPF, you can either use the image provided in the 'Media' directory, a simple text link to www.ixulai.co.uk, or just a credit along the lines of "LFSWorld stats powered by LFSW-PPF by Mike Simons". Get creative :p

    Enough bla bla; Here is the package.

    I'll be sure to check back frequently, so if you have questions, feel free to post them here.

    Good luck :)
     

    Attached Files:

  2. Chaz

    Chaz New Member

  3. Anarchi-h

    Anarchi-h New Member

    Excellent stuff, and nicely done :)

    Glad someone is using it...

    Now, I've just got to get the other S2 stuff sorted; Server filter tool, Online IMG indicator, Team online JS syndication, Team servers online JS syndication, Demo server data ... I'm sure that I'm forgetting some though :D
     
  4. Trauma

    Trauma New Member

    Nice Chaz, I think i seriously need to learn some stuff, your site is looking great.

    By the way, what software you need to join from website, i know i have seen it somewere, but cant find it.
     
  5. Ian.H

    Ian.H Administrator Staff Member

  6. Trauma

    Trauma New Member

    Thanks, just what I was looking for.
    Ypu guys will probably find me a pain in the ass soon, but here is another question.

    Code:
    //Go over the racer list checking for racers that weren't found. These chaps / chapettes are offline
    foreach($theTeam as $teamMember)
    {
        if(!isset($racerOutput[$theTeamWithCNames[$teamMember]]))
            echo $colours->process($theTeamWithCNames[$teamMember], 'tohtml') . " is not online<br />\n";
        else
            echo $colours->process($theTeamWithCNames[$teamMember], 'tohtml') . " is on {$racerOutput[$theTeamWithCNames[$teamMember]]}<br />\n";    
    }
    
    
    how do I get this in to a table, I have tried in many ways, and most likely it is simple, but i still could not get it to work.
    I have made tables before, but that is with data from my sql, and that I have figured out.


    Trauma
     
  7. Ian.H

    Ian.H Administrator Staff Member

    Heh.. no pain sir :)

    You'll want something like (untested):

    Code:
    <table>
        <?php
            foreach ($theTeam as $teamMember) {
        ?>
        <tr>
                <?php
                    if (!isset($racerOutput[$theTeamWithCNames[$teamMember]])) {
                        echo '<td>' . $colours->process($theTeamWithCNames[$teamMember], 'tohtml') . '</td>';
                        echo '<td>Offline</td>';
                    } else {
                        echo '<td>' . $colours->process($theTeamWithCNames[$teamMember], 'tohtml') . '</td>';
                        echo '<td>' . {$racerOutput[$theTeamWithCNames[$teamMember]]} . '</td>';
                    }
                ?>
        </tr>
        <?php
            }
        ?>
    </table>

    HTH :drink:



    Regards,

    Ian
     
  8. Anarchi-h

    Anarchi-h New Member

    Works after you drop the curly braces from the hostname echo :)

    PHP:
     echo '<td>' $racerOutput[$theTeamWithCNames[$teamMember]] . '</td>';
     
  9. Ian.H

    Ian.H Administrator Staff Member

    ahah! I missed that as I'm so used to working with Smarty templates :D



    Regards,

    Ian
     
  10. Trauma

    Trauma New Member

    Thanks, just what I wanted.

    More questions to come...... ;)
     
  11. Trauma

    Trauma New Member

    If I was to add track to the hosts, were would I need to put that in the scripts?

    I made a table, and put in the headings.
    But all players get the heading, instead of being only at the top.

    I love this, but I am starting to think I should of started with PHP years ago.

    Code:
    <html>
        <head>
            <title>Team Members Online</title>
            <style type="text/css">
                body
                {
                    background-color: #d8d8d8;
                    font-family: arial, helvetica, verdana, sans-serif;
                    font-size: 9px;
                    font-weight: bold;
                }
            </style>
        </head>
        <body>
    <?php
    require_once('config.php');
    require_once('misc/error.php');
    require_once('lfsworld/lfsworld.php');
    require_once('lfsworld/providers/data-provider.php');
    require_once('lfsworld/providers/hosts.php');
    require_once('lfsworld/caches/lfsworldclbridge.php');
    require_once('lfsworld/utilities/colourproc.php');
    
    //Setup the Cache_lite interface bridge object
    $cacheParams = array('cacheDir'=>CACHE_DIR, 'automaticSerialization'=>true);
    $fileCache = new LFSWorldCacheLiteBridge(new Cache_Lite($cacheParams));
    
    //Init the colour processing object
    $colours =& LFSColourProcessor::singleton();
    
    //Init the LFSWorld object
    $LFSWorld = new LFSWorld($fileCache, $fileCache);
    
    //Init the host list object
    $hostList = new LFSWorldHostsList($cacheParams);
    
    //Get teh hosts list
    $hosts = $LFSWorld->getParsed($hostList, array('racer'));
    
    //Check if the return value is an error, and die if it is
    if(is_a($hosts, 'Error'))
        die($hosts->getMessage());
    
    //Where the output will be stored
    $racerOutput = array();
    
    //Iterate over each host
    foreach($hosts as $host)
    {
        //Make the racer list a more suitable format
        $tmpRacers = array_change_key_case(array_flip($host['racers']), CASE_LOWER);
        
        //Iterate over the racer list to look for
        foreach($theTeam as $teamMember)
        {
            //Check if the racer we are searching for is on this server
            if(isset($tmpRacers[$teamMember]))
            {
                //parse the hostname for colours and store it with the racer
                $racerOutput[$theTeamWithCNames[$teamMember]] = $colours->process($host['hostName'], 'tohtml');
            }
        }
    }
    ?>
      <table bgcolor="d8d8d8" width="230"   colspan="2" cellpadding="1" cellspacing="1">
    
        <?php
            foreach ($theTeam as $teamMember) {
        ?>
      
    
    	
    				 <tr>
        <td width="100"></td>
        <td width="100"></td>
        <td width="30"></td>
        
        
      </tr>
      <tr>
    				
    				<tr>
    	<td valign="top"><? echo "<font size=\"3\"> "; ?>Racer:</font></a></td>
        <td valign="top"><? echo "<font size=\"2\"> "; ?>Status:</font></a></td>
        <td valign="top"><? echo "<font size=\"2\"> "; ?>Join:</font></a></td>
         
    					</tr>
    					<tr>
                <?php  
                    if (!isset($racerOutput[$theTeamWithCNames[$teamMember]])) {
                        echo '<td>' . $colours->process($theTeamWithCNames[$teamMember], 'tohtml') . '</td>';
                        echo '<td>Offline</td>';
    					echo '<td></td>';
                    } else {
                        echo '<td>' . $colours->process($theTeamWithCNames[$teamMember], 'tohtml') . '</td>';
                        echo '<td>' . $racerOutput[$theTeamWithCNames[$teamMember]] . '</td>'; 
    					echo '<td></td>';
    				}
    			
            
            }
    		
        ?>
    		</tr>
    </table>
    
      <p><img src="Media/lfswppf-small.gif" /></p>
        </body>
    </html>
    Also the text size don't work anymore.

    If you take a look at the link you see the problem.

    link


    I probably need to pay ya all soon. ;)
     
    Last edited: Jul 17, 2005
  12. Ian.H

    Ian.H Administrator Staff Member

    Hi Trauma..

    The reason for the headings being displayed per person rather than singularly at the top, is you have the <td> sections for them inside the foreach{} loop :) Move the <tr>...</tr> section with the headings above the foreach() line and they'll only get displayed once, at the top.

    As for the fonts, there's an error in your HTML structure.. notice the closing </a> tag but there's no opening <a href....> within the <td..> area.

    Can I also recommend the W3C HTML Validator. I use this a lot for debugging for situations just like this, where you look over code and can't see the forest for the trees! The validator will highlight the invalid HTML.. which when fixed, normally resolves the issue.. great debugging tool :D



    Regards,

    Ian
     
  13. Anarchi-h

    Anarchi-h New Member

    PHP:
    <html>
        <head>
            <title>Team Members Online</title>
            <style type="text/css">
                body
                {
                    background-color: #d8d8d8;
                    font-family: arial, helvetica, verdana, sans-serif;
                    font-size: 9px;
                    font-weight: bold;
                }
            </style>
        </head>
        <body>
    <?php
    require_once('config.php');
    require_once(
    'misc/error.php');
    require_once(
    'lfsworld/lfsworld.php');
    require_once(
    'lfsworld/providers/data-provider.php');
    require_once(
    'lfsworld/providers/hosts.php');
    require_once(
    'lfsworld/caches/lfsworldclbridge.php');
    require_once(
    'lfsworld/utilities/colourproc.php');

    //Create a track lookup object to convert Integer codes to LFS short track codes
    require_once('lfsworld/lookups/tracks.php');
    $tracks LFSTracks::getLookupArray('int''codes');

    //Setup the Cache_lite interface bridge object
    $cacheParams = array('cacheDir'=>CACHE_DIR'automaticSerialization'=>true);
    $fileCache = new LFSWorldCacheLiteBridge(new Cache_Lite($cacheParams));

    //Init the colour processing object
    $colours =& LFSColourProcessor::singleton();

    //Init the LFSWorld object
    $LFSWorld = new LFSWorld($fileCache$fileCache);

    //Init the host list object
    $hostList = new LFSWorldHostsList($cacheParams);

    //Get teh hosts list
    $hosts $LFSWorld->getParsed($hostList, array('racer'));

    //Check if the return value is an error, and die if it is
    if(is_a($hosts'Error'))
        die(
    $hosts->getMessage());

    //Where the output will be stored
    $racerOutput = array();

    //Iterate over each host
    foreach($hosts as $host)
    {
        
    //Make the racer list a more suitable format
        
    $tmpRacers array_change_key_case(array_flip($host['racers']), CASE_LOWER);
        
        
    //Iterate over the racer list to look for
        
    foreach($theTeam as $teamMember)
        {
            
    //Check if the racer we are searching for is on this server
            
    if(isset($tmpRacers[$teamMember]))
            {
                
    //parse the hostname for colours and store it with the racer
                
    $racerOutput[$theTeamWithCNames[$teamMember]]['host'] = $host['hostName'];
                
    $racerOutput[$theTeamWithCNames[$teamMember]]['track'] = $host['track'];
                
    $racerOutput[$theTeamWithCNames[$teamMember]]['version'] = ($host['majorVersion'] == '0.5') ? ('S2') : ('S1');
            }
        }
    }
    ?>
        <table bgcolor="d8d8d8" width="400" cellpadding="1" cellspacing="1">
            <tr>
                <td valign="top" width="100"><font size="2">Racer</font></td>
                <td valign="top" width="100"><font size="2">Status</font></td>
            </tr>
            <?php
                
    foreach ($theTeam as $teamMember)
                {
                    if (!isset(
    $racerOutput[$theTeamWithCNames[$teamMember]])) {
                        echo 
    '<tr><td>' $colours->process($theTeamWithCNames[$teamMember], 'tohtml') . '</td>';
                        echo 
    '<td>Offline</td>';
                        echo 
    '</tr>';
                    } else {
                        
    $colouredHost $colours->process($racerOutput[$theTeamWithCNames[$teamMember]]['host'], 'tohtml');
                        echo 
    '<tr><td>' $colours->process($theTeamWithCNames[$teamMember], 'tohtml') . '</td>';
                        echo 
    '<td><a href="lfs://|' $racerOutput[$theTeamWithCNames[$teamMember]]['host'] . '|0|' $racerOutput[$theTeamWithCNames[$teamMember]]['version']. '|">' $colouredHost '</a></td>';
                        echo 
    '</tr>';
                    } 
                }        
            
    ?>
        </table>
        <p><img src="Media/lfswppf-small.gif" /></p>
        </body>
    </html>
    Something like that should do the trick :)

    If you want the full track name, instead of just the short one, change "codes" on this line to "words"

    PHP:
    $tracks LFSTracks::getLookupArray('int''codes');
     
    Last edited: Jul 18, 2005
  14. Trauma

    Trauma New Member

    Nice, how do I change the font size, I cant figure that out.
    It wont if i add ordinary
    Code:
    [ SIZE=2]XXXXXXXX[/SIZE]
     
  15. Anarchi-h

    Anarchi-h New Member

    The size of what?

    I've updated the above post, because there was redundant data. Instead of having a separate link for the join, the host name is used now. You can change it back if that isn't what you want, but just make sure to update the link because as it was (how you are using it atm) you wont actually be able to join hosts because I forgot some stuff in the link.
     
  16. Trauma

    Trauma New Member

    I was thinking of the size of the output.

    Code:
     <style type="text/css"> 
                body 
                { 
                    background-color: #d8d8d8; 
                    font-family: arial, helvetica, verdana, sans-serif; 
                    font-size: 9px; 
                    font-weight: bold; 
                } 
            </style> 
    Do not affect the output anymore.
    I wanted smaller fonts, for some reason it is always the same size.
     
  17. Anarchi-h

    Anarchi-h New Member

    Ah, thats because font attributes aren't inherited by tables.
    Try this.

    Code:
    <style type="text/css">
                body
                {
                    background-color: #d8d8d8;
                }
                
                body, td
                {
                    font-family: arial, helvetica, verdana, sans-serif;
                    font-size: 10px;
                    font-weight: bold;
                }
            </style>
     
  18. Trauma

    Trauma New Member

    Thanks alot. :)
     
  19. Trauma

    Trauma New Member

    I know you can get list of pb's from different players.
    But.
    How much work will it be to cache the pb's in to my sql.
    I know you said it is more complex, but I love playing around with things i dont know. ;-)
     
  20. Anarchi-h

    Anarchi-h New Member

    Don't get me wrong, it isn't rocket science, but it certainly isn't for someone who doesn't know SQL.

    You should at the VERY least know how to use INSERT/REPLACE & SELECT queries, and how to write queries using aggregate SQL functions. You'll also need to know how to design your own database tables. On the PHP side, you'll need the additional knowledge of printf/sprintf string formats, how to write a function with referenced arguments and how to connect to a mysql database.

    It's fairly standard stuff if you've got the basics down, but if you have never interacted with a database with the PHP API, or don't have at least moderate SQL skills, I strongly recommend you mess about with a direct interaction before trying to use someone elses code to interact with a database.
    The reason being is that this cache is a really simple one, and you need to be able to grasp at least the basic workings of it before trying to use it :)

    However, the fact that you are planning to use it for PBs makes it more complex, because you need to use a cyclic cache to cache the PBs in turn.
     

Share This Page