Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Blocks
Author Message
gollum65
New Member
New Member



Joined: Jan 24, 2005
Posts: 7

PostPosted: Tue Jan 25, 2005 6:17 pm Reply with quote

Can someone please give me some guidance. I'm barely versed in php and I'm brand new to nuke.

I have a php script that was sent to me. I'd like to make a block out of the script, but I don't know how and I can't find anything that seems to work.

Below is the code snipet I'm trying to make a block out of. Please note the code you see on lines 3 and 9 are generic variables as the real ones refer to a site that isn't mine. Wink Here's the code:

Code:


<?php
$num = 0;
       $fp = fopen("http://www.some_url.com/some-data.txt", "r");
       print '<table class="peopleOnline">';
       while (!feof($fp))
         {
           $line = fgets($fp, 999);
           if
(preg_match('/^(VARIABLE|VARIABLE|VARIABLE)/', $line))
           {
                  list($position, $cid, $name) = split(":", $line, 6);

                          print '<tr>';
                          print '<td><b>' . $position . '</b></td>';
                          print '<td>' .  $name . '</td></tr>';
                          $num = $num+1;
           }
     }
         print '</table>';
         print $num . ' people online';
?>


Thanks a TON in advance!

Paul B
 
View user's profile Send private message
sixonetonoffun
Spouse Contemplates Divorce



Joined: Jan 02, 2003
Posts: 2496

PostPosted: Tue Jan 25, 2005 6:27 pm Reply with quote

Try something like this.
Change block-Blockfilesname.php to the actual block files name.
Code:


<?php
if (stristr("block-Blockfilesname.php", $_SERVER['SCRIPT_NAME'])) { Header("Location: index.php"); }
$content="";
$num = 0;
       $fp = fopen("http://www.some_url.com/some-data.txt", "r");
       $content ."<table class="peopleOnline">"
       while (!feof($fp))
         {
           $line = fgets($fp, 999);
           if
(preg_match('/^(VARIABLE|VARIABLE|VARIABLE)/', $line))
           {
                  list($position, $cid, $name) = split(":", $line, 6);

                          $content ."<tr>"
                          $content ."<td><b>' . $position . '</b></td>"
                          $content ."<td>' .  $name . '</td></tr>"
                          $num = $num+1;
           }
     }
         $content ."</table>"
         $content ."$num . ' people online";
?>

_________________
[b][size=5]openSUSE 11.4-x86 | Linux 2.6.37.1-1.2desktop i686 | KDE: 4.6.41>=4.7 | XFCE 4.8 | AMD Athlon(tm) XP 3000+ | MSI K7N2 Delta-L | 3GB Black Diamond DDR
| GeForce 6200@433Mhz 512MB | Xorg 1.9.3 | NVIDIA 270.30[/size:2b8 
View user's profile Send private message
sixonetonoffun







PostPosted: Tue Jan 25, 2005 6:30 pm Reply with quote

Have to change these variables
' . $position . '
to just
$position
too I didn't notice those until after I posted.
 
gollum65







PostPosted: Tue Jan 25, 2005 6:48 pm Reply with quote

Hrmmm.

I'm probably still not doing it right.

First, I created a block with this code:

Code:


<?php
if (stristr("block-myfilename.php", $_SERVER['SCRIPT_NAME'])) { Header("Location: index.php"); }
$content="";
?>


Then I created a file called block-myfilename.php and saved it to my blocks folder with the following:

Code:


<?php
$num = 0;
       $fp = fopen("http://www.someurl.com/some-data.txt", "r");
       $content ."<table class="peopleOnline">"
       while (!feof($fp))
         {
           $line = fgets($fp, 999);
           if
(preg_match('/^(VARIABLE|VARIABLE|VARIABLE)/', $line))
           {
                  list($position, $cid, $name) = split(":", $line, 6);

                          $content ."<tr>"
                          $content ."<td><b>$position</b></td>"
                          $content ."<td>' .  $name . '</td></tr>"
                          $num = $num+1;
           }
     }
         $content ."</table>"
         $content ."$num . ' people online";
?>


All I get is a blank, empty block when I know it should be outputting data.

If I include the entire contents of sixonetonoffun's reply into the block creation form instead of a .php file, the block shows the actual php code, so I assumed that wasn't correct.

Think I'm getting closer, and thanks sixonetonoffun for the help so far. Mr. Green
 
sixonetonoffun







PostPosted: Tue Jan 25, 2005 7:11 pm Reply with quote

Try this I made some error before and there was an extra if in your code.

Code:


<?php
if (stristr("block-zabatc.php", $_SERVER['SCRIPT_NAME'])) { Header("Location: index.php"); }
$content="";
$num = 0;
       $fp = fopen("http://www./satnet-data.txt", "r");
       $content .= "<table class=\"peopleOnline\">\n";
       while (!feof($fp))
         {
           $line = fgets($fp, 999);
         
if(preg_match('/^(PHX|ABQ|TUS|ELP|AMA|TUS|SDL|ABQ1|PHX1|PRC|IWA|INW|YUM)_[A-Z0-9]*_*(DEL|GND|TWR|APP|DEP|CTR)/', $line))
           {
                  list($position, $cid, $name) = split(":", $line, 6);

                          $content .= "<tr>\n";
                          $content .= "<td><b>$position</b></td>\n";

                          $content .= "<td>$name</td></tr>\n";
                          $num = $num+1;
           }
     }
         $content.= "</table>\n";
         $content.= "$num people online";
?>


Last edited by sixonetonoffun on Tue Jan 25, 2005 8:15 pm; edited 1 time in total 
gollum65







PostPosted: Tue Jan 25, 2005 7:32 pm Reply with quote

You da man sixonetonoffun!

Now I understand it. I just created a block-filename.php, saved it in my blocks folder, then called it in the dropdown menu in the blocks admin menu.

Great job, and thanks again!

Ooops. So much for keeping those site variables private. Confused Can someone at least edit the line: that has "http://www...." in his post so the url isn't showing. Again, that isn't my site is the only reason I'm concerned.

Anywho, I'm starting to like Nuke now. Mr. Green
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Blocks

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©