Help making the following PHP into a working PHP Eval Page!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Whitesky
    New Member
    • Dec 2007
    • 16
    • 3.8.x

    [CMS] Help making the following PHP into a working PHP Eval Page!

    Hello, I'm more of a designer/Flash/CSS.. have been trying along with help threads here but just can't get it to work.

    I'm trying to run the following as a PHP Direct Eval page, but getting syntax errors:

    PHP Code:

    <?php

    //use cURL to get the data from TRION  DO NOT EDIT THE LINES BELOW!!! 
    //IF YOU WANT TO EDIT TEXT JUMP TO LINE 28
        
    function fetchXML($url)
        {
            
    $ch curl_init();
            
    $useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
            
    curl_setopt ($chCURLOPT_URL$url);
            
    curl_setopt ($chCURLOPT_RETURNTRANSFER1);
            
    curl_setopt ($chCURLOPT_USERAGENT$useragent);
            
    $data curl_exec($ch);
            
    curl_close($ch);
            return 
    $data;
        }
        
    define("USE_CURL"true);
        
    $url "http://www.riftgame.com/en/status/na-status.xml";
        
    //get xml doc
        
    $data fetchXML($url);
        
    //create a SimpleXML object to parse the xml
        
    $status = new SimpleXmlElement($data);

        
    //Display the Header for shard info table
        
    echo "<h3>Current Shard Status:</h3>";
        echo 
    "<div style=\"width:600px; padding:3px; margin:3px;\">";
        echo 
    "<div style=\"width:125px; float:left; font-weight:bold;\">Shard Name:</div>";
        echo 
    "<div style=\"width:75px; float:left; font-weight:bold;\">Status:</div>";
        echo 
    "<div style=\"width:90px; float:left; font-weight:bold;\">Population:</div>";
        echo 
    "<div style=\"width:90px; float:left; font-weight:bold;\">Server Type:</div>";
        echo 
    "</div>";
        
        
    //Print basic shard info then loop through it  DO NOT EDIT!!!
        
    foreach($status->shard as $result){
              
        
    //Define Variables for Each Attribute  DO NOT EDIT!!!  
        
    $shardname $result->attributes()->name;
        
    $status $result->attributes()->online;
        
    $population $result->attributes()->population;
        
    $pvp $result->attributes()->pvp;
        
    $rp $result->attributes()->rp;
        
    $locked $result->attributes()->locked;
        
    ?>   
        <div style="width: 600px; padding: 3px; margin: 3px;">
        <div style="width: 125px; float: left;"><?php echo $shardname;?></div>
        <div style="width: 75px; float: left;">
            <?php if($status == 'True'){?>
                <img src="../online.png" width="25" height="25" alt="Shard is Currently Online" />
            <?php }else{ ?>
                <img src="../offline.png" width="25" height="25" alt="Shard is Currently Offline" />
            <?php ?>
        </div>
        <div style="width: 90px; float: left;">
            <?php if($locked == 'true'){echo "<img src=\"../locked.png\" height=\"25\" width=\"25\" alt=\"The Shard is currently LOCKED\" />";}else{
                if(
    $population == 'low'){ echo "<img src=\"../low_pop.png\" width=\"25\" height=\"25\" alt=\"Population is currently LOW\" />"; }
                elseif(
    $population == 'medium'){ echo "<img src=\"../med_pop.png\" width=\"25\" height=\"25\" alt=\"Population is currently MEDIUM\" />"; }
                elseif(
    $population == 'high'){ echo "<img src=\"../high_pop.png\" width=\"25\" height=\"25\" alt=\"Population is currently HIGH\" />"; }
                else{ echo 
    "<img src=\"../full_pop.png\" width=\"25\" height=\"25\" alt=\"Population is currently FULL\" />"; }}?>
        </div>
        <div style="width: 90px; float: left;">
            <?php if($pvp =='False' && $rp =='False'){echo "PVE";}
            elseif(
    $pvp =='True' && $rp =='False'){echo "PVP";}
            elseif(
    $pvp =='False' && $rp =='True'){echo "PVE-RP";}
            else{echo 
    "PVP-RP";}
            
    ?>
        </div>
        </div>
    <? ?>
    So I learned a bit about converting echo's, using outputs etc, but just can't manage.

    Could anyone help getting this code into a working CMS page? It should display a nice table form, I'll be applying CSS and correct images to load in.
  • bszopi
    Senior Member
    • Nov 2009
    • 839
    • 4.1.x

    #2
    I'm not super great at PHP, but looking at the requirements in a PHP Eval page, it says you need to use
    Code:
    $output = "Hello World! </br>";
    So basically, you can't use the ECHOs to get the output, but instead you need to built the $output string throughout the PHP, and then output it at the end. You would probably built a different string ($string for example), and append it each time you want to display something ($string .= "print this"), and then at the very end, have $output = $string. I hope that makes some sense...

    Comment

    • Whitesky
      New Member
      • Dec 2007
      • 16
      • 3.8.x

      #3
      I tried replacing the echos with output= but what confuses me is there's also a large chunk of raw HTML below, all the <divs>. Would each of these need an output= as well? Do they all go in one large output?

      And if there's raw HTML in here, what do I need a final output= for?

      Btw I'm not lazy, just hoping if someone could convert this, I'd be able to fully understand the mechanics and take it from there

      Comment

      • bszopi
        Senior Member
        • Nov 2009
        • 839
        • 4.1.x

        #4
        I have to run an errand, but I'll try to convert it when I get back. Like I said, I'll not a super PHP coder, but I think I know what needs to be done to get it to work. We'll see. But, if there is someone else out there reading this, feel free to help out!

        Comment

        • bszopi
          Senior Member
          • Nov 2009
          • 839
          • 4.1.x

          #5
          Ok, well I can't fully test it, but I think this * should * work. Let me know what you get.

          PHP Code:
          //use cURL to get the data from TRION  DO NOT EDIT THE LINES BELOW!!! 
          //IF YOU WANT TO EDIT TEXT JUMP TO LINE 28
              
          function fetchXML($url)
              {
                  
          $ch curl_init();
                  
          $useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
                  
          curl_setopt ($chCURLOPT_URL$url);
                  
          curl_setopt ($chCURLOPT_RETURNTRANSFER1);
                  
          curl_setopt ($chCURLOPT_USERAGENT$useragent);
                  
          $data curl_exec($ch);
                  
          curl_close($ch);
                  return 
          $data;
              }
              
          define("USE_CURL"true);
              
          $url "http://www.riftgame.com/en/status/na-status.xml";
              
          //get xml doc
              
          $data fetchXML($url);
              
          //create a SimpleXML object to parse the xml
              
          $status = new SimpleXmlElement($data);

              
          //Display the Header for shard info table
              
          $string '<h3>Current Shard Status:</h3>';
              
          $string .= '<div style="width:600px; padding:3px; margin:3px;">';
              
          $string .= '<div style="width:125px; float:left; font-weight:bold;">Shard Name:</div>';
              
          $string .= '<div style="width:75px; float:left; font-weight:bold;">Status:</div>';
              
          $string .= '<div style="width:90px; float:left; font-weight:bold;">Population:</div>';
              
          $string .= '<div style="width:90px; float:left; font-weight:bold;">Server Type:</div>';
              
          $string .= '</div>';

              
          //Print basic shard info then loop through it  DO NOT EDIT!!!
              
          foreach($status->shard as $result){
                    
              
          //Define Variables for Each Attribute  DO NOT EDIT!!!  
              
          $shardname $result->attributes()->name;
              
          $status $result->attributes()->online;
              
          $population $result->attributes()->population;
              
          $pvp $result->attributes()->pvp;
              
          $rp $result->attributes()->rp;
              
          $locked $result->attributes()->locked;

              
          $string .= '<div style="width: 600px; padding: 3px; margin: 3px;">';
              
          $string .= '<div style="width: 125px; float: left;">' $shardname '</div>';
              
          $string .= '<div style="width: 75px; float: left;">';

              if(
          $status == 'True'){
                      
          $string .= '<img src="../online.png" width="25" height="25" alt="Shard is Currently Online" />';
              }else{ 
                      
          $string .= '<img src="../offline.png" width="25" height="25" alt="Shard is Currently Offline" />';
              } 
              
          $string .= '<div style="width: 90px; float: left;">';

              if(
          $locked == 'true'){
                      
          $string .='<img src="../locked.png" height="25" width="25" alt="The Shard is currently LOCKED" />';
              }else{
                      if(
          $population == 'low'){ 
                              
          $string .= '<img src="../low_pop.png" width="25" height="25" alt="Population is currently LOW" />'
                      }elseif(
          $population == 'medium'){ 
                              
          $string .= '<img src="../med_pop.png" width="25" height="25" alt="Population is currently MEDIUM" />'
                      }elseif(
          $population == 'high'){ 
                              
          $string .= '<img src="../high_pop.png" width="25" height="25" alt="Population is currently HIGH" />'
                      }else{ 
                              
          $string .= '<img src="../full_pop.png" width="25" height="25" alt="Population is currently FULL" />'
                      }
               }
              
          $string .= '</div>';
              
          $string .= '<div style="width: 90px; float: left;">';
              
              if(
          $pvp =='False' && $rp =='False'){
                     
          $string .= 'PVE';
              }elseif(
          $pvp =='True' && $rp =='False'){
                      
          $string .= 'PVP';
              }elseif(
          $pvp =='False' && $rp =='True'){
                      
          $string .= 'PVE-RP';
              }else{
                      
          $string .= 'PVP-RP';
              }
              
          $string .= '</div>';
              
          $string .= '</div>';
          }

          $output $string
          EDIT: Ok, I was able to test it some and it appears to be working good. The only issue seems to be, since your images are relatively pathed, its showing the ALT text, which seems to be screwing up the DIVs. But other than that, all seems to be good.
          Last edited by bszopi; Fri 15 Apr '11, 5:56pm.

          Comment

          • Whitesky
            New Member
            • Dec 2007
            • 16
            • 3.8.x

            #6
            Got it on and it's working great! However two weird things, at first it was working fine in 'Article View' but on Section View (with article set to "show full article in section) it was giving another syntax error, but after a few loads... it disappeared. At least it's working now :-)

            I loaded the images in but it's still strange alignment, no problem I can fix that easily.

            Thanks so much, you're a life saver!

            Comment

            • bszopi
              Senior Member
              • Nov 2009
              • 839
              • 4.1.x

              #7
              No problem. I was gonna mess with it some more to try to figure out the alignment issues. I think the starting and ending DIVs need to be with the other bits of code, and not separate outside of the IF statements. It'll cause some repetition of code, but I think it will clean it up. I'll try it out with the ALT tags and see what happens, and post back my results.

              Comment

              • bszopi
                Senior Member
                • Nov 2009
                • 839
                • 4.1.x

                #8
                Ok, I got it to work with the ALT text, by adding in some <br /> tags. Take them out as needed to make it work properly with the images.

                PHP Code:
                //use cURL to get the data from TRION  DO NOT EDIT THE LINES BELOW!!! 
                //IF YOU WANT TO EDIT TEXT JUMP TO LINE 28
                    
                function fetchXML($url)
                    {
                        
                $ch curl_init();
                        
                $useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
                        
                curl_setopt ($chCURLOPT_URL$url);
                        
                curl_setopt ($chCURLOPT_RETURNTRANSFER1);
                        
                curl_setopt ($chCURLOPT_USERAGENT$useragent);
                        
                $data curl_exec($ch);
                        
                curl_close($ch);
                        return 
                $data;
                    }
                    
                define("USE_CURL"true);
                    
                $url "http://www.riftgame.com/en/status/na-status.xml";
                    
                //get xml doc
                    
                $data fetchXML($url);
                    
                //create a SimpleXML object to parse the xml
                    
                $status = new SimpleXmlElement($data);

                    
                //Display the Header for shard info table
                    
                $string '<h3>Current Shard Status:</h3>';
                    
                $string .= '<div style="width:600px; padding:3px; margin:3px;">';
                    
                $string .= '<div style="width:125px; float:left; font-weight:bold;">Shard Name:</div>';
                    
                $string .= '<div style="width:75px; float:left; font-weight:bold;">Status:</div>';
                    
                $string .= '<div style="width:90px; float:left; font-weight:bold;">Population:</div>';
                    
                $string .= '<div style="width:90px; float:left; font-weight:bold;">Server Type:</div>';
                    
                $string .= '</div><br />';

                    
                //Print basic shard info then loop through it  DO NOT EDIT!!!
                    
                foreach($status->shard as $result){
                          
                    
                //Define Variables for Each Attribute  DO NOT EDIT!!!  
                    
                $shardname $result->attributes()->name;
                    
                $status $result->attributes()->online;
                    
                $population $result->attributes()->population;
                    
                $pvp $result->attributes()->pvp;
                    
                $rp $result->attributes()->rp;
                    
                $locked $result->attributes()->locked;

                    
                $string .= '<div style="width: 600px; padding: 3px; margin: 3px;">';
                    
                $string .= '<div style="width: 125px; float: left;">' $shardname '</div>';

                    if(
                $status == 'True'){
                            
                $string .= '<div style="width: 75px; float: left;"><img src="../online.png" width="25" height="25" alt="Shard is Currently Online" /></div>';
                    }else{ 
                            
                $string .= '<div style="width: 75px; float: left;"><img src="../offline.png" width="25" height="25" alt="Shard is Currently Offline" /></div>';
                    }

                    if(
                $locked == 'true'){
                            
                $string .='<div style="width: 90px; float: left;"><img src="../locked.png" height="25" width="25" alt="The Shard is currently LOCKED" /></div>';
                    }else{
                            if(
                $population == 'low'){ 
                                    
                $string .= '<div style="width: 90px; float: left;"><img src="../low_pop.png" width="25" height="25" alt="Population is currently LOW" /></div>'
                            }elseif(
                $population == 'medium'){ 
                                    
                $string .= '<div style="width: 90px; float: left;"><img src="../med_pop.png" width="25" height="25" alt="Population is currently MEDIUM" /></div>'
                            }elseif(
                $population == 'high'){ 
                                    
                $string .= '<div style="width: 90px; float: left;"><img src="../high_pop.png" width="25" height="25" alt="Population is currently HIGH" /></div>'
                            }else{ 
                                    
                $string .= '<div style="width: 90px; float: left;"><img src="../full_pop.png" width="25" height="25" alt="Population is currently FULL" /></div>'
                            }
                     }
                    
                    if(
                $pvp =='False' && $rp =='False'){
                           
                $string .= '<div style="width: 90px; float: left;">PVE</div>';
                    }elseif(
                $pvp =='True' && $rp =='False'){
                            
                $string .= '<div style="width: 90px; float: left;">PVP</div>';
                    }elseif(
                $pvp =='False' && $rp =='True'){
                            
                $string .= '<div style="width: 90px; float: left;">PVE-RP</div>';
                    }else{
                            
                $string .= '<div style="width: 90px; float: left;">PVP-RP</div>';
                    }
                    
                $string .= '</div><br /><br /><br />';
                }

                $output $string

                Comment

                • setishock
                  Senior Member
                  • Jun 2005
                  • 1334
                  • 4.2.x

                  #9
                  OK pardon the ignorant question but what does that do?
                  ...

                  Comment

                  • bszopi
                    Senior Member
                    • Nov 2009
                    • 839
                    • 4.1.x

                    #10
                    It displays a table of a list of Shard server, which I assume has to do with a game of some sort.

                    Comment

                    widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                    Working...