TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
Stats
  • Total Posts: 196,022
  • Total Topics: 21,332
  • Online today: 473
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 250
  • Total: 250

php server query script disabled in tinyportal

Started by botl, September 02, 2008, 03:22:23 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

botl

Hi Guys ,

I installed SMF 1.1.5 with Tinyportal. I have a custom script that works fine when I type it as a standalone file into the browser. However when I paste the code into a new tinyportal left or right bar block to show
it display nothing. As a test I have added ( echo "Hello World"; ) inside the script and it shows "Hello World" in the sidebar ( Which means my paths and file names are correct), but still no custom script is displayed ( not even an error message). The purpose of the custom script is to show the current gamers online by means of server query to external server. Help would be much appreciated in this regard.

I have been playing around for a while this scenario and can not figure out why it will be blocked ? Maybe I am wrong.
I have numerous scripts like these with the same dilemma.

Following is the custom script.

Here is a demo of how it looks outside SMF http://www.101st.co.za/aaotracker.php

<?php


error_reporting
(0); 
$clanid="63573";

function 
startTag($parser, $name, $attrs) {
 global 
$stack;

 
$tag=array("name"=>$name,"attrs"=>$attrs);
 
array_push($stack,$tag);
}

function 
cdata($parser, $cdata) {
 global 
$stack;

 
$stack[count($stack)-1]['cdata'] .= $cdata;
}

function 
endTag($parser, $name) {
 global 
$stack;

 
$stack[count($stack)-2]['children'][] = $stack[count($stack)-1];
 
array_pop($stack);
}


// Parse XML

$stack = array();
$claninfo = array();
$clanstats = array();
$playerstats = array();


$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startTag", "endTag");
xml_set_character_data_handler($xml_parser, "cdata");

//http://aaotracker.com/livefeed/xml_clanprofile.php?clanid=63573
$xmllink="http://aaotracker.com/livefeed/xml_clanprofile.php?clanid=$clanid";
$data = xml_parse($xml_parser,file_get_contents($xmllink));
if(!
$data) die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));

xml_parser_free($xml_parser);


 
// Get Player Data
 
for($i = 0; $i < sizeof($stack[0][children][2][children]); $i++) {
  for(
$x = 0; $x < sizeof($stack[0][children][2][children][$i][children]); $x++) {
   
$valname=$stack[0][children][2][children][$i][children][$x][name];
   
$value=$stack[0][children][2][children][$i][children][$x][cdata];
   if(
$valname=="PLAYERID") $pid=$value;
   
$playerstats[$pid][$valname]=$value;
  }
 }


foreach(
$playerstats as $key => $value) {
 
$playername=$playerstats[$key][PLAYERNAME];
 
//$playerhonor=$playerstats[$key][PLAYERHONOR];
 
$playerurl=$playerstats[$key][PLAYERSTATSURL];

 if(
$playerstats[$key][PLAYERSTATUS]=="1") $statuspic="ponline.gif";
 else 
$statuspic="poffline.gif";

 echo 
"<img border=\"0\" src=\"./images/$statuspic\" width=\"42\" height=\"16\"> <a target=\"_blank\" href=\"$playerurl\"><font size=\"2\" color=\"#000000\">$playername</font></a><br>";
}

;

?>




If the code is successfull inside SMF Tinyportal block it should show playernames.

Thanks in advance

Ben

Zetan

Remove the php tags from the very first line and the very last line and paste it into a PHP block.
The php blocks already have those tags built in as a feature.


Remove the following:

<?php

and

?>

botl


Good day ZTN and thank you for your reply ,

1. I tried the TP php script block " without the <?php ?> tags."Hello World" displayed OK , but no script parsed "
2. I saved the script as a file and used a include statement , "Hello World" displayed OK , but no script parsed "
3. I saved the script as a file and used a require or require_once statement , "Hello World" displayed OK , but no script parsed "

Thanks for the help so far.



G6Cad

You cant put php in a scriptblock, you need to put the code in a PHP block

botl

Good day G6 and thank you for your support.

I tried it in a php block with no success. I have however found a alternative solution that is not excactly what I wanted but will do the trick.

Use iframe tags as follow and paste it into an html block.

Quote<tr class="alt1"><td>
<iframe name="roster" MARGINWIDTH="0" allowtransparency="true" src="aaotracker.php" width="185" height="1000" frameborder="0" style="width: 185px; height: 1000px" ></iframe>
</td><tr>

Thanks guys for the help  ;)

I would still appreciate if I could get some feedback on why my code is blocked via a php script block ?  :up:

botl

IchBin

Just because your echo "hello world"; works, does not mean that your paths are right. That just means the  your hello world works. If you include the code from the script into a block, the paths will have to be set relative to how TP uses them. Which most often means changing paths in the script if you do it this way.

botl

#6
Thank you IchBin |I will keep that in mind,

The mere fact that I got so much support with in day of posting my message will make me stick with tinyportal even if it means wre-writing code to adjust to tp.

Once again , thanks to all you guys for the awesome support. Appreciated and very impressed.

2 THUMBS UP !

botl

IchBin

The best thing you can do if you want to include a script is to use a require or include statement. Instead of actually putting the code from the file into the block.

require_once('path/to/file.php');


Glad we could help. Thanks for the compliments.

Ianedres

Botl,

I've worked on this before; it may something minor that I'm still overlooking, but I can not get the xml_parse function to work correctly once this script is called within TP. My initial guess is that it may be a permissions issue within the server for php blocks (that use the EVAL function) where xml_parse is prohibited from running(??).

I actually took the contents of the xml file for your clan, saved it to my server, and read it directly to avoid cross-site issues. The script works, outside of TP, so the XML parsing is working correctly.

I even took it several steps further, by reading the xml file from the aaotracker site into a string, displaying the string contents, and then using xml_parse with that string. Again, in TP, it does not work, but works unchanged by accessing it directly.

I don't know of anything else to try at this point... other than a kludge to use CRON to run one script to read and write the file at a set interval, then allow TP to display the contents of that file on demand...   there would be some delay issues involved, but might would work.

Ianedres

Try this, until someone comes up with why the original doesn't work...

This will get the xml from aaotracker per your variables, parse it into one complete string, and save it as 'clan_xxxxx.htm' (xxxxx = clan #) to the directory it runs from. Then, run this as a CRON job every xx minutes to update the file automatically.

Just make a php article to include the filename (as stated at the end of the script) and you should have some output now, though it looks like some image paths may need correction.

Again, it will have some delay between the CRON and request... and obviously requires that the directory is writeable by php. There is no error-checking whether the file was written or not.

Here's the new version of the script:

<?php

error_reporting
(0); 
$clanid="63573";

$filename = 'clan_' . $clanid . '.htm';

function 
startTag($parser, $name, $attrs) {
 global 
$stack;

 
$tag=array("name"=>$name,"attrs"=>$attrs);
 
array_push($stack,$tag);
}

function 
cdata($parser, $cdata) {
 global 
$stack;

 
$stack[count($stack)-1]['cdata'] .= $cdata;
}

function 
endTag($parser, $name) {
 global 
$stack;

 
$stack[count($stack)-2]['children'][] = $stack[count($stack)-1];
 
array_pop($stack);
}


// Parse XML

$stack = array();
$claninfo = array();
$clanstats = array();
$playerstats = array();


$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startTag", "endTag");
xml_set_character_data_handler($xml_parser, "cdata");

//http://aaotracker.com/livefeed/xml_clanprofile.php?clanid=63573
$xmllink="http://aaotracker.com/livefeed/xml_clanprofile.php?clanid=$clanid";
$data = xml_parse($xml_parser,file_get_contents($xmllink));
if(!
$data) die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));

xml_parser_free($xml_parser);


 
// Get Player Data
 
for($i = 0; $i < sizeof($stack[0][children][2][children]); $i++) {
  for(
$x = 0; $x < sizeof($stack[0][children][2][children][$i][children]); $x++) {
   
$valname=$stack[0][children][2][children][$i][children][$x][name];
   
$value=$stack[0][children][2][children][$i][children][$x][cdata];
   if(
$valname=="PLAYERID") $pid=$value;
   
$playerstats[$pid][$valname]=$value;
  }
 }


foreach(
$playerstats as $key => $value) {
 
$playername=$playerstats[$key][PLAYERNAME];
 
//$playerhonor=$playerstats[$key][PLAYERHONOR];
 
$playerurl=$playerstats[$key][PLAYERSTATSURL];

 if(
$playerstats[$key][PLAYERSTATUS]=="1") $statuspic="ponline.gif";
 else 
$statuspic="poffline.gif";

 
$html .= "<img border=\"0\" src=\"./images/$statuspic\" width=\"42\" height=\"16\"> <a target=\"_blank\" href=\"$playerurl\"><font size=\"2\" color=\"#000000\">$playername</font></a><br>";
}

$handle = @fopen($filename, 'w');
@
fwrite($handle, $html);
@
fclose($handle);

echo 
'The file was written to the path as : <b>' . getcwd() . '/' . $filename . '</b>';

?>



This website is proudly hosted on Crocweb Cloud Website Hosting.