<?
class XMLcomments{
function XMLcomments($file)
{
$this->file=$file;
}
var $file = "";
function filecheck(){
if(!file_exists($this->file))
{
$f=fopen($this->file,"a+");
fwrite($f,'<?xml version="1.0" encoding="ISO-8859-1" ?>
<comments>
</comments>');
fclose($f);
}
}
function newComment($m,$a,$df="d/m/y h:i:s"){
$this->filecheck();
$x="";
$content=' <comment>
<com>
'.htmlspecialchars($m).'
</com>
<by>
'.htmlspecialchars($a).'
</by>
<date>
'.date($df).'
</date>
</comment>';
$f=file($this->file);
for($i=0;$i<count($f);$i++)
{
if($i==2)
{
$x.=$content."\n";
}
$x.=$f[$i];
}
$f=fopen($this->file,"w");
fwrite($f,$x);
fclose($f);
}
function show(){
$this->filecheck();
$parser = xml_parser_create();
xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
$data = implode("",file($this->file));
xml_parse_into_struct($parser,$data,&$d_ar,&$i_ar) or print_error();
xml_parser_free($parser);
for($i=0;$i<count($i_ar['com']);$i++)
{
?><div class="comment">
<p>
<?=stripslashes($d_ar[$i_ar['com'][$i]]['value'])?>
</p>
<span><?=stripslashes($d_ar[$i_ar['by'][$i]]['value']." ".$d_ar[$i_ar['date'][$i]]['value'])?></span>
</div><?
}
}
}?>