Author |
Message |
pacslim
New Member


Joined: Jun 24, 2006
Posts: 7
|
Posted:
Sat Jun 24, 2006 12:10 pm |
|
First off keep up the good work, I like nuke sentinel and all other stuff ya'll do !
now my problem, (I hope i placed this in the right section, I'm a noob so bare with me plz,):
I'm re-making a simple shoutcast script for a block that shows last tracks now playing and other stats on my phpnuke site,
all works well except when i installed NukeSentinel_242pl9_70-79
after that a strange error comes up each time i'm playing a track with a songtitle that has a ' in it. I think it sees the ' as a command because it says as error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' ...
so it cant write the songtitle good to the my sql database with a ' in the songtitle (it uses the my sql database's in its caching progress of the playlist it gets from my shoutcast radio stream)
and this problem hasn't to do with mysql database because without sentinel it runs fine (also its a fresh clean install)
I think it has todo with the parser file that gets the data from my stream in combination with sentinel, it reads the variable for the songtitle but it does this wrong because of the ' sign in it ....
hope u can help me out and tell me how i can solve this thanks allready and if u need the code here it is: this is the block file:
Code:<?php
if (eregi("block-SHOUTcast.php",$PHP_SELF)){Header("Location: index.php");die();}$servers=array('servers'=>array('81.169.180.23'),'ports'=>array(8050,8051),'passwords'=>array('*****'),'hbw'=> 'http://81.169.180.23:8050/listen.pls','lasttracks'=>5);$stationname='2PacRadio';$refreshtime=22*3;$content="$stationname will be right back";require_once('includes/scxml.php');
require_once('config.php');
global $prefix,$dbi;
function getInfo($servers)
{$server=new SCXML;
$listeners=0;
$nowplaying='Nothing';
$peak=0;
$max=0;
while( $host=each($servers['servers']) )
{$port=each($servers['ports']);
$password=each($servers['passwords']);
$server->set_host($host[1]);
$server->set_port($port[1]);
$server->set_password($password[1]);
if($server->retrieveXML())
{$nowplaying=urldecode($server->fetchMatchingTag("SONGTITLE"));
$listeners+=$server->fetchMatchingTag("CURRENTLISTENERS");
$peak+=$server->fetchMatchingTag("PEAKLISTENERS");
$max+=$server->fetchMatchingTag("MAXLISTENERS");
$lasttracks=$server->fetchMatchingArray("TITLE");}}
$content.='<center><b>Now Playing:</b><br><marquee width="91" scrolldelay="100" scrollamount="5"><i>'.$nowplaying.'</i></marquee><br><b>Listeners:</b> ';
$content.="<i>$listeners/$max</i><br><b>Peak:</b> <i>$peak</i><br><br>";
$content.="<a href=".$servers['hbw'].">Tune In</a><br>";
if($servers['lasttracks']>0) {
$max=$servers['lasttracks'];
if( count($lasttracks) < $max ) $max=count($lasttracks);
$content .="<br><b>Last $max tracks:</b><br>";
for( $i=0; $i < $max; $i++ ) {
$content .=($i + 1).". $lasttracks[$i]<br>";}}
return $content;}
function cacheInfo($content,$title)
{global $dbi,$prefix;
$now=time();
$sql="UPDATE ".$prefix."_blocks SET content='".$content."',time=".$now
." WHERE title='".$title."'";
sql_query($sql,$dbi);}
$sql="SELECT content,time FROM ".$prefix."_blocks WHERE title='".$title."'";$result=sql_query($sql,$dbi);$roottime=time()-$refreshtime;if($result){$row=sql_fetch_array($result,$dbi);if($row[1]<$roottime){$content=getInfo($servers);cacheInfo($content,$title);}else{$content=$row[0];}}else{$content=getInfo($servers);cacheInfo($content,$title);}?>
|
file 2:
Code:<?php
class SCXML {var $host="YOURIP";var $port=YOURPORT;var $password="YOURPASS";var $depth=0;var $lastelem=array();var $xmlelem=array();var $xmldata=array();var $stackloc=0;var $parser;function set_password($password) {$this->password=$password;}function set_host($host) {$this->host=$host;}function set_port($port) {$this->port=$port;}function startElement($parser, $name, $attrs) {$this->stackloc++;$this->lastelem[$this->stackloc]=$name;$this->depth++;}function endElement($parser, $name) {unset($this->lastelem[$this->stackloc]);$this->stackloc--;}function characterData($parser, $data) {$data=trim($data);if ($data) {$this->xmlelem[$this->depth]=$this->lastelem[$this->stackloc];$this->xmldata[$this->depth].=$data;}}function retrieveXML() {$rval=1;$sp=fsockopen($this->host,$this->port,&$errno,&$errstr,10);if (!$sp) $rval=0;else {set_socket_blocking($sp,false);fputs($sp,"GET /admin.cgi?pass=$this->password&mode=viewxml HTTP/1.1\nUser-Agent:Mozilla\n\n");for($i=0; $i<30; $i++) {if(feof($sp)) break; $sp_data.=fread($sp,31337);usleep(500000);}$sp_data=ereg_replace("^.*<!DOCTYPE","<!DOCTYPE",$sp_data);$this->parser = xml_parser_create();xml_set_object($this->parser,&$this);xml_set_element_handler($this->parser, "startElement", "endElement");xml_set_character_data_handler($this->parser, "characterData");if (!xml_parse($this->parser, $sp_data, 1)) {$rval=-1;}xml_parser_free($this->parser);}return $rval;}function debugDump(){reset($this->xmlelem);while (list($key,$val) = each($this->xmlelem)) {echo "$key. $val -> ".$this->xmldata[$key]."\n";}}function fetchMatchingArray($tag){reset($this->xmlelem);$rval = array();while (list($key,$val) = each($this->xmlelem)) {if ($val==$tag) $rval[]=$this->xmldata[$key];}return $rval;}function fetchMatchingTag($tag){reset($this->xmlelem);$rval = "";while (list($key,$val) = each($this->xmlelem)) {if ($val==$tag) $rval=$this->xmldata[$key];}return $rval;}}?>
|
the block file goes into my blocks folder the other in my includes see if u can find the error i made also if u see other errors hollah im a noobie  |
Last edited by pacslim on Sat Jun 24, 2006 3:04 pm; edited 1 time in total |
|
|
 |
montego
Site Admin

Joined: Aug 29, 2004
Posts: 9457
Location: Arizona
|
Posted:
Sat Jun 24, 2006 2:03 pm |
|
Sounds to me like magic quotes are not turned on, so you need to use "addslashes()" function on the fields that could have the quote in them BEFORE you use them in the sql call. |
_________________ Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! |
|
|
 |
pacslim

|
Posted:
Sat Jun 24, 2006 3:12 pm |
|
montego wrote: | Sounds to me like magic quotes are not turned on, so you need to use "addslashes()" function on the fields that could have the quote in them BEFORE you use them in the sql call. | well i treid what u said i changed
Code:
if($server->retrieveXML())
{$nowplaying=urldecode($server->fetchMatchingTag("SONGTITLE"));
$listeners+=$server->fetchMatchingTag("CURRENTLISTENERS");
$peak+=$server->fetchMatchingTag("PEAKLISTENERS");
$max+=$server->fetchMatchingTag("MAXLISTENERS");
$lasttracks=$server->fetchMatchingArray("TITLE");}}
|
to:
Code:
if($server->retrieveXML())
{$nowplaying=urldecode($server->fetchMatchingTag("addslashes(SONGTITLE)"));
$listeners+=$server->fetchMatchingTag("CURRENTLISTENERS");
$peak+=$server->fetchMatchingTag("PEAKLISTENERS");
$max+=$server->fetchMatchingTag("MAXLISTENERS");
$lasttracks=$server->fetchMatchingArray("addslashes(TITLE)");}}
|
but when i changed that part of code of da block and upload it it doesnt show anything anymore just blank lol but also no error message lol all blank them stats also plz explain this noob what magic quotes are and what should this newbi do now to get this working plz show example ???? thanks again allready ! |
|
|
|
 |
montego

|
Posted:
Sat Jun 24, 2006 4:28 pm |
|
You have not done that correctly. You had introduced a parse error. Try this for your last line:
$lasttracks=addslashes($server->fetchMatchingArray("TITLE"));}}
But, I don't think that is even where you want to do this. What I was trying to say is when you are building your SQL strings, you will need to take care of this.
For example, like this:
Code:
$sql="UPDATE ".$prefix."_blocks SET content='".addslashes($content)."',time=".$now
." WHERE title='".addslashes($title)."'";
|
P.S. you may want to consider indenting this code better so that it is more readable. I found it extremely difficult to follow...  |
|
|
|
 |
pacslim

|
Posted:
Sat Jun 24, 2006 7:07 pm |
|
Thanks now it works good, I changed the block file to this:
Code:
<?php
if (eregi("block-SHOUTcast2.php",$PHP_SELF)){Header("Location: index.php");die();}$servers=array('servers'=>array('81.169.180.23'),'ports'=>array(8050,8051),'passwords'=>array('*****'),'hbw'=> 'http://81.169.180.23:8050/listen.pls','lasttracks'=>5);$stationname='2PacRadio';$refreshtime=22*3;$content="$stationname will be right back";require_once('includes/scxml.php');
require_once('config.php');
global $prefix,$dbi;
function getInfo($servers)
{$server=new SCXML;
$listeners=0;
$nowplaying='Nothing';
$peak=0;
$max=0;
while( $host=each($servers['servers']) )
{$port=each($servers['ports']);
$password=each($servers['passwords']);
$server->set_host($host[1]);
$server->set_port($port[1]);
$server->set_password($password[1]);
if($server->retrieveXML())
{$nowplaying=urldecode($server->fetchMatchingTag("SONGTITLE"));
$listeners+=$server->fetchMatchingTag("CURRENTLISTENERS");
$peak+=$server->fetchMatchingTag("PEAKLISTENERS");
$max+=$server->fetchMatchingTag("MAXLISTENERS");
$lasttracks=$server->fetchMatchingArray("TITLE");}}
$content.='<center><b>Now Playing:</b><br><marquee width="91" scrolldelay="100" scrollamount="5"><i>'.$nowplaying.'</i></marquee><br><b>Listeners:</b> ';
$content.="<i>$listeners/$max</i><br><b>Peak:</b> <i>$peak</i><br><br>";
$content.="<a href=".$servers['hbw'].">Tune In</a><br>";
if($servers['lasttracks']>0) {
$max=$servers['lasttracks'];
if( count($lasttracks) < $max ) $max=count($lasttracks);
$content .="<br><b>Last $max tracks:</b><br>";
for( $i=0; $i < $max; $i++ ) {
$content .=($i + 1).'.'.$lasttracks[$i].'<br>';}}
return $content;}
/* Function to cache the string $content */
function cacheInfo ($content,$title)
{
global $dbi, $prefix;
$now = time();
$sql = "UPDATE ".$prefix."_blocks SET content='".addslashes($content)."', time=".$now
." WHERE title='".addslashes($title)."'";
sql_query($sql,$dbi);
}
/* Get Cached Content: */
$sql = "SELECT content,time FROM ".$prefix."_blocks WHERE title='".$title."'";
$result = sql_query($sql,$dbi);
$roottime = time() - $refreshtime;
if($result)
{
$row = sql_fetch_array($result, $dbi);
/* Check time! */
if( $row[1] < $roottime )
{
$content = getInfo($servers);
cacheInfo($content,$title);
}
else
{
$content = $row[0];
}
}
/* Otherwise, we have to fetch, and cache the details */
else
{
$content = getInfo($servers);
cacheInfo($content,$title);
}
?>
|
thanks for helping this noob also if anyone sees anymore errors in this script please hollah ! shoutout and big thanks again to all who repleid ! |
|
|
|
 |
montego

|
Posted:
Sat Jun 24, 2006 7:22 pm |
|
Fine job. Glad I could help. |
|
|
|
 |
|