<?php
#header('Content-Type:text/plain');
header('Content-Type:text/vnd.wap.wml');
# Чистка и восстановление страницы
include("/home/kmx/includes/function.inc");
# Читаем файл
if ($f=@fopen('http://'.stripslashes($HTTP_GET_VARS['url']),'r'))
{
$text='';
while ((!feof($f))&&(strlen($text)<16384)) {$text.=fread($f,256);}
fclose($f);
}
# Убираем пролог и антикеш
$text=preg_replace("|<\?xml.*\?>|","",$text);
$text=preg_replace("|<!DOCTYPE[^>]+>|","",$text);
$text=preg_replace("|<!--[^>]+-->|","",$text);
#$text=preg_replace("|<head>[^<]+</head>|","",$text);
$text=preg_replace("|<head.*head>|","",$text);
# Убираем спецсимволы
$text=str_replace("\t"," ",$text);
$text=str_replace("\r","",$text);
$text=str_replace("\n","",$text);
# Убираем двойные пробелы
$text=str_replace(' ',' ',$text);
$text=str_replace(' ',' ',$text);
$text=str_replace(' ',' ',$text);
# Разделяем теги
$text=str_replace(">",">\n",$text);
$text=str_replace("<","\n<",$text);
# Убираем начало деки
$text=str_replace('<wml>','',$text);
# Преобразуем старые теги
$text=str_replace('<strong>',"<b>",$text);
$text=str_replace('</strong>',"</b>",$text);
$text=str_replace('<em>',"<i>",$text);
$text=str_replace('</em>',"</i>",$text);
# Убираем двойные \n
$text=str_replace("\n\n\n\n","\n",$text);
$text=str_replace("\n\n\n","\n",$text);
$text=str_replace("\n\n","\n",$text);
# Собираем элементы
$text=str_replace("<small>\n","<small>",$text);
$text=str_replace("<big>\n","<big>",$text);
$text=str_replace("<b>\n","<b>",$text);
$text=str_replace("<i>\n","<i>",$text);
$text=str_replace("<u>\n","<u>",$text);
$text=str_replace("\n</small>","</small>",$text);
$text=str_replace("\n</big>","</big>",$text);
$text=str_replace("\n</b>","</b>",$text);
$text=str_replace("\n</i>","</i>",$text);
$text=str_replace("\n</u>","</u>",$text);
$text=str_replace("\n</a>","</a>",$text);
$text=str_replace("</p>\n<p",'</p><p',$text);
$text=preg_replace("|(<a [^>]+>)\n|","\\1",$text);
$text=str_replace("\n</a>","</a>",$text);
$text=preg_replace("|(<anchor [^>]+>)\n|","\\1",$text);
$text=str_replace("\n</anchor>","</anchor>",$text);
$text=preg_replace("|(<do [^>]+>)\n|","\\1",$text);
$text=str_replace("\n</do>","</do>",$text);
$text=preg_replace("|(<go [^>]+>)\n|","\\1",$text);
$text=preg_replace("|\n(<go [^>]+>)|","\\1",$text);
$text=str_replace("\n</go>","</go>",$text);
$text=str_replace("</go>\n","</go>",$text);
$text=preg_replace("|(<postvar [^>]+>)\n|","\\1",$text);
$text=preg_replace("|\n(<postvar [^>]+>)|","\\1",$text);
$text=preg_replace("|(<setvar [^>]+>)\n|","\\1",$text);
$text=preg_replace("|\n(<setvar [^>]+>)|","\\1",$text);
# Собираем и удаляем конец деки
$text=str_replace("\n</wml>",'</wml>',$text);
$text=str_replace("\n</card></wml>",'</card></wml>',$text);
$text=str_replace('</p></card></wml>','',$text);
# Чистим начало и конец
$text=trim($text);
#die($text);
# Создаем массив для обработки
$tmp=explode("\n",$text);unset($text);
array($tmp_element);
array($tmp_softkey);
for ($i=0;$i<sizeof($tmp);$i++)
{
if (substr(trim($tmp[$i]),0,12)=='<!-- cnt -->') continue;
if (substr(trim($tmp[$i]),0,10)=='<!-- * -->') continue;
if (substr(trim($tmp[$i]),0,4)=='<do ') {$tmp_softkey[]=trim($tmp[$i]); continue;}
if (trim($tmp[$i])!='') $tmp_element[]=trim($tmp[$i]);
}
unset($tmp);
$tmp=$tmp_element;unset($tmp_element);array($tmp_element);
# Восстановление начала карты
if ((substr(trim($tmp[0]),0,10)=='<card id="')&&(substr(trim($tmp[1]),0,2)=='<p')) {$tmp_element[]=trim($tmp[0]);$tmp_element[]=trim($tmp[1]);$tmp[0]=$tmp[1]='';}
elseif ((substr(trim($tmp[0]),0,10)=='<card id="')&&(substr(trim($tmp[1]),0,2)!='<p')) {$tmp_element[]=trim($tmp[0]);$tmp_element[]='<p align="center">';$tmp[0]='';}
elseif (substr(trim($tmp[0]),0,2 )=='<p') {$tmp_element[]='<card id="card0" title="Page"><do name="back" type="options" label="Назад"><prev/></do>';$tmp_element[]=trim($tmp[0]);$tmp[0]='';}
elseif ((substr(trim($tmp[0]),0,10)!='<card id="')&&(substr(trim($tmp[1]),0,2)=='<p')) {$tmp_element[]='<card id="card0" title="Page"><do name="back" type="options" label="Назад"><prev/></do>';$tmp_element[]=trim($tmp[1]);$tmp[0]=$tmp[1]='';}
elseif ((substr(trim($tmp[0]),0,10)!='<card id="')&&(substr(trim($tmp[1]),0,2)!='<p')) {$tmp_element[]='<card id="card0" title="Page"><do name="back" type="options" label="Назад"><prev/></do>';$tmp_element[]='<p align="center">';}
for ($i=0;$i<sizeof($tmp);$i++)
{
if ((trim($tmp[$i]))=='') continue;
$tmp_element[]=trim($tmp[$i]);
}
$tmp=$tmp_element;unset($tmp_element);array($tmp_element);
# Проверка правильности элементов
$tmp_element[]='<?xml version="1.0" encoding="Utf-8"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml12.dtd"><wml><head><meta forua="true" http-equiv="Cache-Control" content="max-age=0,proxy-revalidate,must-revalidate"/></head>';
for ($i=0;$i<sizeof($tmp);$i++)
{
if ($propusk) $i++;
$propusk=false;
$atr='';
$stmp=$tmp[$i];
if (strpos(' '.$stmp,'<i>')) $atr.='.<i>';
if (strpos(' '.$stmp,'<u>')) $atr.='.<u>';
if (strpos(' '.$stmp,'<b>')) $atr.='.<b>';
if (strpos(' '.$stmp,'<big>')) $atr.='.<big>';
if (strpos(' '.$stmp,'<small>')) $atr.='.<small>';
if (strpos(' '.$stmp,'</i>')) $atr.='.<i>';
if (strpos(' '.$stmp,'</u>')) $atr.='.<u>';
if (strpos(' '.$stmp,'</b>')) $atr.='.<b>';
if (strpos(' '.$stmp,'</big>')) $atr.='.<big>';
if (strpos(' '.$stmp,'</small>')) $atr.='.<small>';
if (strpos(' '.$stmp,'<br/>')) $br='<br/>'; else $br='';
$stmp=str_replace('<i>','',$stmp); $stmp=str_replace('</i>','',$stmp);
$stmp=str_replace('<u>','',$stmp); $stmp=str_replace('</u>','',$stmp);
$stmp=str_replace('<b>','',$stmp); $stmp=str_replace('</b>','',$stmp);
$stmp=str_replace('<big>','',$stmp); $stmp=str_replace('</big>','',$stmp);
$stmp=str_replace('<small>','',$stmp);$stmp=str_replace('</small>','',$stmp);
$stmp=str_replace('<br/>','',$stmp);
if ($i==0)
{
$stra=explode('title="',$tmp[$i]);
$stra=explode('"',$stra[1]);
$title=$stra[0];
$stra=explode('ontimer="',$tmp[$i]);
$stra=explode('"',$stra[1]);
$url=$stra[0];
$stra=explode('value="',$tmp[$i]);
$stra=explode('"',$stra[1]);
$second=$stra[0]+0;
if (($url!='')&&($second>0)) $redirect=' ontimer="'.$url.'"><timer value="'.$second.'"/>'; else $redirect='>';
$tmp_element[]='<card id="card0" title="'.$title.'"'.$redirect.'<do name="back" type="options" label="Назад"><prev/></do>';
for ($j=0;$j<sizeof($tmp_softkey);$j++)
{
$stra=explode('label="',$tmp_softkey[$j]);
$stra=explode('"',$stra[1]);
$caption=$stra[0];
$stra=explode('href="',$tmp_softkey[$j]);
$stra=explode('"',$stra[1]);
$url=$stra[0];
if (($caption!='')&&($url!=''))
{
$tmp_element[]='<do name="sk'.rand(1000,9999).'" type="options" label="'.$caption.'"><go href="'.$url.'"/></do>';
}
}
}
elseif ($i==1)
{
$stra=explode('align="',$tmp[$i]);
$stra=explode('"',$stra[1]);
$algn=$stra[0];
$stra=explode('mode="',$tmp[$i]);
$stra=explode('"',$stra[1]);
$wrp=$stra[0];
if ($algn=='center') $align='center';
elseif ($algn=='right') $align='right';
else $align='left';
if ($wrp=='nowrap') $wrap=' mode="nowrap"';
elseif ($wrp=='wrap') $wrap=' mode="wrap"';
else $wrap='';
$tmp_element[]='<p align="'.$align.'"'.$wrap.'>';
$tmp_element[]='<!-- * -->';
}
elseif (substr($tmp[$i],0,6)=='</p><p')
{
$stra=explode('align="',$tmp[$i]);
$stra=explode('"',$stra[1]);
$algn=$stra[0];
$stra=explode('mode="',$tmp[$i]);
$stra=explode('"',$stra[1]);
$wrp=$stra[0];
if ($algn=='center') $align='center';
elseif ($algn=='right') $align='right';
else $align='left';
if ($wrp=='nowrap') $wrap=' mode="nowrap"';
elseif ($wrp=='wrap') $wrap=' mode="wrap"';
else $wrap='';
$tmp_element[]='</p><p align="'.$align.'"'.$wrap.'>';
}
elseif (substr($tmp[$i],0,3)=='<br')
{
$tmp_element[]='<br/>';
}
elseif (substr($stmp,0,3)=='<a ')
{
$stra=explode('">',$stmp);
$strb=explode(' ',$stra[1]);
if ($strb[0]=='<img')
{
$tmp[$i]=$stmp;
$stra=explode('href="',$tmp[$i]);
$stra=explode('"',$stra[1]);
$link_=$stra[0];
$stra=explode('<img src="',$tmp[$i]);
$stra=explode('"',$stra[1]);
$imgurl=$stra[0];
$stra=explode(' alt="',$tmp[$i]);
$stra=explode('"',$stra[1]);
$alttext=$stra[0];
if (($br=='')&&(trim($tmp[$i+1])=='<br/>')) {$propusk=true; $br='<br/>';}
if (($imgurl!='')&&($link_!=''))
if (!(strpos($imgurl,'top.wab.ru/count')||strpos($imgurl,'top.nash-kovcheg.ru')||strpos($imgurl,'oz.beeonglyuk.ru/rating')||strpos($imgurl,'wwap.ru/exban')||strpos($imgurl,'playfon')||strpos($imgurl,'cnt.kmx.ru')||strpos($link_,'bodr.net')||strpos($link_,'rating.samsungi')))
{
$tmp_element[]='<a href="'.$link_.'"><img src="'.$imgurl.'" alt="'.$alttext.'"/></a>'.$br;
}
}
else
{
$tmp[$i]=$stmp;
$stra=explode('href="',$tmp[$i]);
$stra=explode('"',$stra[1]);
$link_=$stra[0];
$stra=explode('">',$tmp[$i]);
$stra=explode('</a>',$stra[1]);
$caption=$stra[0];
if (($br=='')&&(trim($tmp[$i+1])=='<br/>')) {$propusk=true; $br='<br/>';}
if (($caption!='')&&($link_!=''))
if (!(strpos($link_,'playmobile')||strpos($link_,'mag.su/game')||strpos($link_,'mag.su/poly')||strpos($link_,'mag.su/java')||strpos($link_,'playfon')||strpos($link_,'javagames')||strpos($link_,'wapix')))
{
$tmp[$i]='<a href="'.$link_.'">'.$caption.'</a>';
if (strpos($atr,'<i>')) $tmp[$i]='<i>'.$tmp[$i].'</i>';
if (strpos($atr,'<u>')) $tmp[$i]='<u>'.$tmp[$i].'</u>';
if (strpos($atr,'<b>')) $tmp[$i]='<b>'.$tmp[$i].'</b>';
if (strpos($atr,'<big>')) $tmp[$i]='<big>'.$tmp[$i].'</big>';
if (strpos($atr,'<small>')) $tmp[$i]='<small>'.$tmp[$i].'</small>';
$tmp_element[]=$tmp[$i].$br;
}
}
}
elseif (substr($tmp[$i],0,5)=='<img ')
{
$stra=explode('<img src="',$tmp[$i]);
$stra=explode('"',$stra[1]);
$imgurl=$stra[0];
$stra=explode(' alt="',$tmp[$i]);
$stra=explode('"',$stra[1]);
$alttext=$stra[0];
if ($imgurl!='')
{
if (($br=='')&&(trim($tmp[$i+1])=='<br/>')) {$propusk=true; $br='<br/>';}
$tmp_element[]='<img src="'.$imgurl.'" alt="'.$alttext.'"/>'.$br;
}
}
elseif (substr($tmp[$i],0,7)=='<input ')
{
$stra=explode('name="',$tmp[$i]);
$stra=explode('"',$stra[1]);
$var_=$stra[0];
$stra=explode('maxlength="',$tmp[$i]);
$stra=explode('"',$stra[1]);
$size=$stra[0]+0;
if ($size<1) $size='999';
$stra=explode('value="',$tmp[$i]);
$stra=explode('"',$stra[1]);
$def=$stra[0];
$stra=explode('title="',$tmp[$i]);
$stra=explode('"',$stra[1]);
$caption=$stra[0];
$stra=explode('type="',$tmp[$i]);
$stra=explode('"',$stra[1]);
if ($stra[0]!='password') $type='text'; else $type='password';
if ($var_!='')
{
if (($br=='')&&(trim($tmp[$i+1])=='<br/>')) {$propusk=true; $br='<br/>';}
$tmp_element[]='<input name="'.$var_.'" type="'.$type.'" emptyok="true" title="'.$caption.'" maxlength="'.$size.'" value="'.$def.'"/>'.$br;
}
}
elseif (substr($stmp,0,7)=='<anchor')
{
$tmp[$i]=$stmp;
$stra=explode('href="',$tmp[$i]);
$stra=explode('"',$stra[1]);
$url=$stra[0];
$stra=explode('<anchor >',$tmp[$i]);
$stra=explode('<',$stra[1]);
$caption=$stra[0];
$stra=explode('method="',$tmp[$i]);
$stra=explode('"',$stra[1]);
$method=$stra[0];
if (($url!='')&&($caption!=''))
{
$tmp[$i]='<anchor >'.$caption.'<go href="'.$url.'" method="'.$method.'"></go></anchor>';
if (strpos($atr,'<i>')) $tmp[$i]='<i>'.$tmp[$i].'</i>';
if (strpos($atr,'<u>')) $tmp[$i]='<u>'.$tmp[$i].'</u>';
if (strpos($atr,'<b>')) $tmp[$i]='<b>'.$tmp[$i].'</b>';
if (strpos($atr,'<big>')) $tmp[$i]='<big>'.$tmp[$i].'</big>';
if (strpos($atr,'<small>')) $tmp[$i]='<small>'.$tmp[$i].'</small>';
if (($br=='')&&(trim($tmp[$i+1])=='<br/>')) {$propusk=true; $br='<br/>';}
$tmp_element[]=$tmp[$i].$br;
}
}
elseif (substr($tmp[$i],0,7)=='<!--var')
{
$stra=explode('|',$tmp[$i]);
if (($stra[1]!='')&&($stra[2]!=''))
{
$tmp_element[]='<!--var |'.$stra[1].'|'.$stra[2].'|-->';
}
}
elseif (substr($tmp[$i],0,5)=='<!--r')
{
$str=substr($tmp[$i],9);
if (($str!='') && !(strpos(strtolower($str),'<card') && ($currentdir.$editfile=='./index')))
{
$tmp_element[]='<!--r -->'.$str;
}
}
elseif (strpos($stmp,'<')||strpos($stmp,'>'))
{
if ($tmp[$i]!='')
{
$tmp_element[]='<!--r -->'.$tmp[$i].$br;
}
}
else
{
$tmp[$i]=$stmp;
if (strpos($atr,'<i>')) $tmp[$i]='<i>'.$tmp[$i].'</i>';
if (strpos($atr,'<u>')) $tmp[$i]='<u>'.$tmp[$i].'</u>';
if (strpos($atr,'<b>')) $tmp[$i]='<b>'.$tmp[$i].'</b>';
if (strpos($atr,'<big>')) $tmp[$i]='<big>'.$tmp[$i].'</big>';
if (strpos($atr,'<small>')) $tmp[$i]='<small>'.$tmp[$i].'</small>';
if ($tmp[$i]!='')
{
if (($br=='')&&(trim($tmp[$i+1])=='<br/>')) {$propusk=true; $br='<br/>';}
$tmp_element[]=$tmp[$i].$br;
}
}
}
$tmp_element[]='</p></card></wml>';
for ($i=0;$i<sizeof($tmp_element);$i++) print $tmp_element[$i]."\n";
?>