<html>

<head>
  <title>STEP-0</title>
</head>

<body>

<?php
require "./dirs.inc";
require "./params.inc";
require "./settings.inc";
require "./translit.php";

@unlink("./sitemap.txt");
$ff=0;
$file="./products.xml";
//save_get_file("https://monacor.pl/api/categories.xml/en","./categories.xml");
//save_get_file("https://monacor.pl/api/products.xml/en","./products.xml");


echo "<pre><strong>PREPARE $file ...</strong>\n";
//Категории

$dir=".";
$st2="";
$new=$file;

$f=fopen($file,"rt");
$f2=fopen($dir."/".$new.".dom","w");
$i=0;
while(!feof($f)) {
$i++;
$st=fgets($f);

preparexml("offer",$st,$f2);
}
fclose($f2);
fclose($f);
echo "<strong>PREPARE OK</strong>\n\n";
exit;
echo "<strong>PARSING SIMPLEXML STRING ...</strong>\n";
$translate=Array();
$par=Array();
$f=fopen($dir."/".$new.".dom","rt");
$f2=fopen($dir."/".$new.".txt","w");
$imfp=fopen("./images.txt","w");
$sefp=fopen("./sert.txt","w");
$filt=Array();
$classes=Array();
$units=Array();
while(!feof($f)) {
$st=str_replace("<![CDATA[","", str_replace("]]>", "",fgets($f)));
$st=trim($st);
if($st!="") {
$st=parsexmlstr("offer",$st,$imfp,$sefp);
fputs($f2, str_replace("&quot;","\"",str_replace("&gt;",">",str_replace("&lt;","<",utf8win1251($st)."\n"))));
}
}

fclose($imfp);
fclose($sefp);
fclose($f2);
fclose($f);
if(count($classes)>0) {
foreach ($classes as $key => $val) {
unset($out);
$out=explode("|",$val);
if(isset($filt[$key])) {
if(strlen($out[0])>200) {$out[0]=md5($out[0]); }
$fp=fopen("./cc/cc_".$out[0].".inc","w");
foreach ($filt[$key] as $k => $v) {
unset($o);
$o=explode("|",$v);

//echo "./cc/cc_".$out[0].".inc<br>";
fputs($fp,$o[0]."|".$o[0]."|".$o[2]."|||\n");
}
fclose($fp);
}
}
}
$fp=fopen("./translate.txt","w");
fputs($fp,implode("\n",$translate));
fclose($fp);
$fp=fopen("./parameters.txt","w");
fputs($fp,implode("\n",$par));
fclose($fp);
echo "\n<h2>CLASSES</h2>";
var_dump($classes);
echo "<h2>UNITS</h2>";
var_dump($units);
echo "<h2>FILTER</h2>";
var_dump($filt);
echo "<strong>PARSE OK</strong></pre>";
?>
<h1>OK</h1>
</body>

</html>