TinyPortal

Development => Support => Topic started by: Storm2 on May 23, 2008, 06:46:48 PM

Title: phpbox issue
Post by: Storm2 on May 23, 2008, 06:46:48 PM
Using SMF 1.1.5 and TinyPortal v1.0.5 beta 1

When I try to place this code in a phpbox it won`t work but when it is just a php page it is working fine.

$clanid="64736";
$clanid2="68296";

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);
}



$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");

$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);



for($i = 0; $i < sizeof($stack[0][children][0][children]); $i++) {
  $valname=$stack[0][children][0][children][$i][name];
  $claninfo[$valname]=$stack[0][children][0][children][$i][cdata];
}

for($i = 0; $i < sizeof($stack[0][children][1][children]); $i++) {
  $valname=$stack[0][children][1][children][$i][name];
  $clanstats[$valname]=$stack[0][children][1][children][$i][cdata];
}

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;
  }
}

echo "<body bgcolor=\"#000000\">";


echo "<font color=#ffffff size=1><b>TRACKER STATUS<br>MAIN SQUAD:</b></font><br>\n";

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=\"$statuspic\"><a target=\"_blank\" href=\"$playerurl\"><font size=\"2\" color=\"#FFFFFF\">$playername</font></a><br>";
}
echo "</body>";


$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");

$xmllink="http://aaotracker.com/livefeed/xml_clanprofile.php?clanid=$clanid2";
$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);


for($i = 0; $i < sizeof($stack[0][children][0][children]); $i++) {
  $valname=$stack[0][children][0][children][$i][name];
  $claninfo[$valname]=$stack[0][children][0][children][$i][cdata];
}

for($i = 0; $i < sizeof($stack[0][children][1][children]); $i++) {
  $valname=$stack[0][children][1][children][$i][name];
  $clanstats[$valname]=$stack[0][children][1][children][$i][cdata];
}

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;
  }
}

echo "<font color=#ffffff size=1><br><b>TRACKER STATUS<br>BETA SQUAD:</b></font><br>\n";

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=\"$statuspic\"><a target=\"_blank\" href=\"$playerurl\"><font size=\"2\" color=\"#FFFFFF\">$playername</font></a><br>";
}
echo "</body>";


http://www.teamcp.com/forum/tracker/test.php

Anyone an idea what is wrong with it?
Title: Re: phpbox issue
Post by: Crip on May 23, 2008, 06:55:37 PM
Kinda large for a phpbox ant it?
Title: Re: phpbox issue
Post by: Storm2 on May 23, 2008, 06:57:13 PM
No idea, is there a max size for?
Title: Re: phpbox issue
Post by: Crip on May 23, 2008, 07:03:37 PM
Not sure, but it does work in an article and there more advanced than a regular phpbox -- but I mat be wrong ?
Title: Re: phpbox issue
Post by: JPDeni on May 23, 2008, 07:09:56 PM
QuoteWhen I try to place this code in a phpbox it won`t work
How does it not work? What happens? Error message? Blank page? Wrong printout? Let me know what I'm looking for.

I've got some awfully long php boxes, so I don't think the length of code is the problem. It could be just the fact that he's got html tags in there that don't belong:


<body...


and


</body>


I don't know that it would cause a problem, but it certainly isn't necessary in either a php block or php article.
Title: Re: phpbox issue
Post by: Storm2 on May 23, 2008, 07:11:52 PM
Blank page(box) it just stays blank, no error message.

Sorry it is showing the

echo "<font color=#ffffff size=1><b>TRACKER STATUS<br>MAIN SQUAD:</b></font><br>\n";

TRACKER STATUS
MAIN SQUAD:


echo "<font color=#ffffff size=1><br><b>TRACKER STATUS<br>BETA SQUAD:</b></font><br>\n";

TRACKER STATUS
BETA SQUAD:

correct, but it is not parsing the rest somehow.
(I also removed all body tags.)
Title: Re: phpbox issue
Post by: Ianedres on May 23, 2008, 07:39:07 PM
Is the XML extension disabled in your server configuration?

Scratch that - didn't see the link.
Title: Re: phpbox issue
Post by: Storm2 on May 23, 2008, 07:44:54 PM
You mean in the apache server?
Np  ;)
Title: Re: phpbox issue
Post by: Storm2 on May 23, 2008, 07:48:19 PM
After trying the same code (without the body tags) in an php article I get an error message:
Quote
Fatal error: Cannot redeclare starttag() (previously declared in /home/public_html/forum/Sources/Load.php(1818) : eval()'d code(52) : eval()'d code:6) in /home/public_html/forum/Sources/Load.php(1818) : eval()'d code(1331) : eval()'d code on line 10
Title: Re: phpbox issue
Post by: JPDeni on May 23, 2008, 08:14:13 PM
Do you want this in a box or an article?
Title: Re: phpbox issue
Post by: Storm2 on May 23, 2008, 08:15:23 PM
In a box would be nice since we want to use it on the left blocks.
Title: Re: phpbox issue
Post by: JPDeni on May 23, 2008, 08:23:30 PM
If you're getting the headings, but not the data, it's obviously not picking up the data.

The stuff on your test.php file is what you want to print out?

The problem isn't obvious, I'm afraid, and I'm not familiar with that programming style, so I find it very difficult to follow.

You might be able to use an iframe in your block. I've never used one, but a lot of people seem to get them to work very well.
Title: Re: phpbox issue
Post by: Ianedres on May 23, 2008, 08:27:57 PM
Other than renaming $startTag and $endTag throughout the script to try to clear the redeclare error...  XML parsing has caused some profane language when I've tried to work with it.
Title: Re: phpbox issue
Post by: efe on May 23, 2008, 08:46:32 PM
Thanks You ;)
Title: Re: phpbox issue
Post by: Storm2 on May 23, 2008, 09:05:27 PM
Yes the errors are gone now but the xml parsing is not working somehow.
Title: Re: phpbox issue
Post by: Storm2 on May 24, 2008, 11:34:47 AM
When I import it as an article ( http://www.teamcp.com/forum/tracker/test.php ) it is showing correct on the frontpage (Last article on bottom http://teamcp.com/forum/index.php ), but when i try to display that same imported article in a block(left or right) it shows nothing.
Title: Re: phpbox issue
Post by: JPDeni on May 24, 2008, 02:14:24 PM
I really don't know why it makes a difference. You could try using an articlebox and see if that works.

It's all trial and error. :)
Title: Re: phpbox issue
Post by: vdesai on May 25, 2008, 08:10:48 AM
1. I think you may know this already but dont include the <? when you are creating a phpbox (but do include the ?>, maybe not i maybe forgetting try both but i know for a fact u dont need the <?)
2. If nothing works just include the php file in the box include './tracker/test.php';
should do it for ya
Title: Re: phpbox issue
Post by: Genie on May 25, 2008, 11:32:46 AM
I have an rss feed being run through a php script.  I am using the phpbox and did NOT use either the opening or closing php declaration - no problem.


<?php

?>



These were NOT needed in my case.
Title: Re: phpbox issue
Post by: Storm2 on May 25, 2008, 02:58:25 PM
Tried all so far but without luck yet.

The include './tracker/test.php'; is also not working.

The only time when it is working is when the imported article option is used.
But when I try to display that in a block again it only shows the headings.
So there must be a difference in plain import article and displaying the same imported article in a block.
Title: Re: phpbox issue
Post by: Genie on May 25, 2008, 03:12:41 PM
My only thought is that you now have a different pathing from the front of your site to your forum area.  You have probably dropped by at least one directory level lower.

If the script is being called from something installed in your home directory, you might want to check out the pathing.
You may be needing something like this to start your script

require_once '/home/site-root-name/public_html/script-directory/scriptname.php';
Title: Re: phpbox issue
Post by: Storm2 on May 25, 2008, 03:37:01 PM
Tried that too with the same result that only the headings where displayed.
So the paths are correct I guess.
Title: Re: phpbox issue
Post by: vdesai on May 25, 2008, 09:53:03 PM
Quote from: Genie on May 25, 2008, 03:12:41 PM
My only thought is that you now have a different pathing from the front of your site to your forum area.  You have probably dropped by at least one directory level lower.

If the script is being called from something installed in your home directory, you might want to check out the pathing.
You may be needing something like this to start your script

require_once '/home/site-root-name/public_html/script-directory/scriptname.php';


include '../tracker/test.php';


You could try that if that does not work iframe would be your best bet

I didn't notice they were different directories :P