Просмотр файла includes/wap/builder/page_restore.php

Размер файла: 11.37Kb
  1. <?php
  2. # Чистка и восстановление страницы
  3.  
  4. # Читаем файл
  5. $f=fopen($userpath.$currentdir.$editfile.'.wml','r');
  6. $text=fread($f,16384);
  7. fclose($f);
  8. # Убираем пролог и антикеш
  9. $text=preg_replace("|<\?xml.*\?>|","",$text);
  10. $text=preg_replace("|<!DOCTYPE[^>]+>|","",$text);
  11. $text=preg_replace("|<head.*head>|","",$text);
  12.  
  13. $text=str_replace('&lt;?xml version=&quot;1.0&quot; encoding=&quot;Utf-8&quot;?&gt;','',$text);
  14. $text=str_replace('&quot;&gt;&lt;do name=&quot;back&quot; type=&quot;options&quot; label=&quot;Назад&quot;&gt;&lt;prev/&gt;&lt;/do&gt;','',$text);
  15. $text=str_replace('&lt;card id=&quot;card0&quot; title=&quot;','',$text);
  16. $text=str_replace('&lt;p align=&quot;center&quot;&gt;','',$text);
  17.  
  18. # Убираем начало деки
  19. $text=str_replace('<wml>','',$text);
  20. # Убираем уданенные элементы
  21. $text=str_replace('<!-- delete -->','',$text);
  22. # Убираем конец деки
  23. $text=str_replace('</p></card></wml>','',$text);
  24. # Убираем двойные пробелы
  25. $text=str_replace(' ',' ',$text);
  26. $text=str_replace(' ',' ',$text);
  27. $text=str_replace(' ',' ',$text);
  28. # Убираем двойные \n
  29. $text=str_replace("\r","\n",$text);
  30. $text=str_replace("\n\n\n\n","\n",$text);
  31. $text=str_replace("\n\n\n","\n",$text);
  32. $text=str_replace("\n\n","\n",$text);
  33. # Чистим начало и конец
  34. $text=trim($text);
  35. # Создаем массив для обработки
  36. $tmp=explode("\n",$text);unset($text);
  37. array($tmp_element);
  38. array($tmp_softkey);
  39. for ($i=0;$i<sizeof($tmp);$i++)
  40. {
  41. if (substr(trim($tmp[$i]),0,12)=='<!-- cnt -->') continue;
  42. if (substr(trim($tmp[$i]),0,10)=='<!-- * -->') continue;
  43. if (substr(trim($tmp[$i]),0,12)=='<do name="sk') {$tmp_softkey[]=trim($tmp[$i]); continue;}
  44. $tmp_element[]=trim($tmp[$i]);
  45. }
  46. unset($tmp);
  47. $tmp=$tmp_element;unset($tmp_element);array($tmp_element);
  48.  
  49. # Восстановление начала карты
  50. 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]='';}
  51. 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]='';}
  52. 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]='';}
  53. 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]='';}
  54. 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">';}
  55. for ($i=0;$i<sizeof($tmp);$i++)
  56. {
  57. if ((trim($tmp[$i]))=='') continue;
  58. $tmp_element[]=trim($tmp[$i]);
  59. }
  60. $tmp=$tmp_element;unset($tmp_element);array($tmp_element);
  61.  
  62. # Проверка правильности элементов
  63. $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>';
  64.  
  65. for ($i=0;$i<sizeof($tmp);$i++)
  66. {
  67. $atr='';
  68. $stmp=$tmp[$i];
  69. if (strpos(' '.$stmp,'<i>')) $atr.='.<i>';
  70. if (strpos(' '.$stmp,'<u>')) $atr.='.<u>';
  71. if (strpos(' '.$stmp,'<b>')) $atr.='.<b>';
  72. if (strpos(' '.$stmp,'<big>')) $atr.='.<big>';
  73. if (strpos(' '.$stmp,'<small>')) $atr.='.<small>';
  74. if (strpos(' '.$stmp,'<br/>')) $br='<br/>'; else $br='';
  75. $stmp=str_replace('<i>','',$stmp); $stmp=str_replace('</i>','',$stmp);
  76. $stmp=str_replace('<u>','',$stmp); $stmp=str_replace('</u>','',$stmp);
  77. $stmp=str_replace('<b>','',$stmp); $stmp=str_replace('</b>','',$stmp);
  78. $stmp=str_replace('<big>','',$stmp); $stmp=str_replace('</big>','',$stmp);
  79. $stmp=str_replace('<small>','',$stmp);$stmp=str_replace('</small>','',$stmp);
  80. $stmp=str_replace('<br/>','',$stmp);
  81. if ($i==0)
  82. {
  83. $stra=explode('title="',$tmp[$i]);
  84. $stra=explode('"',$stra[1]);
  85. $title=$stra[0];
  86. $stra=explode('ontimer="',$tmp[$i]);
  87. $stra=explode('"',$stra[1]);
  88. $url=$stra[0];
  89. $stra=explode('value="',$tmp[$i]);
  90. $stra=explode('"',$stra[1]);
  91. $second=$stra[0]+0;
  92. if (($url!='')&&($second>0)) $redirect=' ontimer="'.$url.'"><timer value="'.$second.'"/>'; else $redirect='>';
  93. $tmp_element[]='<card id="card0" title="'.$title.'"'.$redirect.'<do name="back" type="options" label="Назад"><prev/></do>';
  94. for ($j=0;$j<sizeof($tmp_softkey);$j++)
  95. {
  96. $stra=explode('label="',$tmp_softkey[$j]);
  97. $stra=explode('"',$stra[1]);
  98. $caption=$stra[0];
  99. $stra=explode('href="',$tmp_softkey[$j]);
  100. $stra=explode('"',$stra[1]);
  101. $url=$stra[0];
  102. if (($caption!='')&&($url!=''))
  103. {
  104. $tmp_element[]='<do name="sk'.rand(1000,9999).'" type="options" label="'.$caption.'"><go href="'.$url.'"/></do>';
  105. }
  106. }
  107. }
  108. elseif ($i==1)
  109. {
  110. $stra=explode('align="',$tmp[$i]);
  111. $stra=explode('"',$stra[1]);
  112. $algn=$stra[0];
  113. $stra=explode('mode="',$tmp[$i]);
  114. $stra=explode('"',$stra[1]);
  115. $wrp=$stra[0];
  116. if ($algn=='center') $align='center';
  117. elseif ($algn=='right') $align='right';
  118. else $align='left';
  119. if ($wrp=='nowrap') $wrap=' mode="nowrap"';
  120. elseif ($wrp=='wrap') $wrap=' mode="wrap"';
  121. else $wrap='';
  122. $tmp_element[]='<p align="'.$align.'"'.$wrap.'>';
  123. $tmp_element[]='<!-- * -->';
  124. }
  125. elseif (substr($tmp[$i],0,6)=='</p><p')
  126. {
  127. $stra=explode('align="',$tmp[$i]);
  128. $stra=explode('"',$stra[1]);
  129. $algn=$stra[0];
  130. $stra=explode('mode="',$tmp[$i]);
  131. $stra=explode('"',$stra[1]);
  132. $wrp=$stra[0];
  133. if ($algn=='center') $align='center';
  134. elseif ($algn=='right') $align='right';
  135. else $align='left';
  136. if ($wrp=='nowrap') $wrap=' mode="nowrap"';
  137. elseif ($wrp=='wrap') $wrap=' mode="wrap"';
  138. else $wrap='';
  139. $tmp_element[]='</p><p align="'.$align.'"'.$wrap.'>';
  140. }
  141. elseif (substr($tmp[$i],0,3)=='<br')
  142. {
  143. $tmp_element[]='<br/>';
  144. }
  145. elseif (substr($stmp,0,3)=='<a ')
  146. {
  147. $stra=explode('">',$stmp);
  148. $strb=explode(' ',$stra[1]);
  149. if ($strb[0]=='<img')
  150. {
  151. $tmp[$i]=$stmp;
  152. $stra=explode('href="',$tmp[$i]);
  153. $stra=explode('"',$stra[1]);
  154. $link_=$stra[0];
  155. $stra=explode('<img src="',$tmp[$i]);
  156. $stra=explode('"',$stra[1]);
  157. $imgurl=$stra[0];
  158. $stra=explode(' alt="',$tmp[$i]);
  159. $stra=explode('"',$stra[1]);
  160. $alttext=$stra[0];
  161. if (($imgurl!='')&&($link_!=''))
  162. {
  163. $tmp_element[]='<a href="'.$link_.'"><img src="'.$imgurl.'" alt="'.$alttext.'"/></a>'.$br;
  164. }
  165. }
  166. else
  167. {
  168. $tmp[$i]=$stmp;
  169. $stra=explode('href="',$tmp[$i]);
  170. $stra=explode('"',$stra[1]);
  171. $link_=$stra[0];
  172. $stra=explode('">',$tmp[$i]);
  173. $stra=explode('</a>',$stra[1]);
  174. $caption=htmlspecialchars(cyr2utf(utf2cyr(html_entity_decode($stra[0], ENT_QUOTES))), ENT_QUOTES);
  175. if (($caption!='')&&($link_!=''))
  176. {
  177. $tmp[$i]='<a href="'.$link_.'">'.$caption.'</a>';
  178. if (strpos($atr,'<i>')) $tmp[$i]='<i>'.$tmp[$i].'</i>';
  179. if (strpos($atr,'<u>')) $tmp[$i]='<u>'.$tmp[$i].'</u>';
  180. if (strpos($atr,'<b>')) $tmp[$i]='<b>'.$tmp[$i].'</b>';
  181. if (strpos($atr,'<big>')) $tmp[$i]='<big>'.$tmp[$i].'</big>';
  182. if (strpos($atr,'<small>')) $tmp[$i]='<small>'.$tmp[$i].'</small>';
  183. $tmp_element[]=$tmp[$i].$br;
  184. }
  185. }
  186. }
  187. elseif (substr($tmp[$i],0,5)=='<img ')
  188. {
  189. $stra=explode('<img src="',$tmp[$i]);
  190. $stra=explode('"',$stra[1]);
  191. $imgurl=$stra[0];
  192. $stra=explode(' alt="',$tmp[$i]);
  193. $stra=explode('"',$stra[1]);
  194. $alttext=$stra[0];
  195. if ($imgurl!='')
  196. {
  197. $tmp_element[]='<img src="'.$imgurl.'" alt="'.$alttext.'"/>'.$br;
  198. }
  199. }
  200. elseif (substr($tmp[$i],0,7)=='<input ')
  201. {
  202. $stra=explode('name="',$tmp[$i]);
  203. $stra=explode('"',$stra[1]);
  204. $var_=$stra[0];
  205. $stra=explode('maxlength="',$tmp[$i]);
  206. $stra=explode('"',$stra[1]);
  207. $size=$stra[0]+0;
  208. if ($size<1) $size='999';
  209. $stra=explode('value="',$tmp[$i]);
  210. $stra=explode('"',$stra[1]);
  211. $def=$stra[0];
  212. $stra=explode('title="',$tmp[$i]);
  213. $stra=explode('"',$stra[1]);
  214. $caption=$stra[0];
  215. $stra=explode('type="',$tmp[$i]);
  216. $stra=explode('"',$stra[1]);
  217. if ($stra[0]!='password') $type='text'; else $type='password';
  218. if ($var_!='')
  219. {
  220. $tmp_element[]='<input name="'.$var_.'" type="'.$type.'" emptyok="true" title="'.$caption.'" maxlength="'.$size.'" value="'.$def.'"/>'.$br;
  221. }
  222. }
  223. elseif (substr($stmp,0,7)=='<anchor')
  224. {
  225. $tmp[$i]=$stmp;
  226. $stra=explode('href="',$tmp[$i]);
  227. $stra=explode('"',$stra[1]);
  228. $url=$stra[0];
  229. $stra=explode('<anchor >',$tmp[$i]);
  230. $stra=explode('<',$stra[1]);
  231. $caption=htmlspecialchars(cyr2utf(utf2cyr(html_entity_decode($stra[0], ENT_QUOTES))), ENT_QUOTES);
  232. $stra=explode('method="',$tmp[$i]);
  233. $stra=explode('"',$stra[1]);
  234. $method=$stra[0];
  235. if (($url!='')&&($caption!=''))
  236. {
  237. $tmp[$i]='<anchor >'.$caption.'<go href="'.$url.'" method="'.$method.'"></go></anchor>';
  238. if (strpos($atr,'<i>')) $tmp[$i]='<i>'.$tmp[$i].'</i>';
  239. if (strpos($atr,'<u>')) $tmp[$i]='<u>'.$tmp[$i].'</u>';
  240. if (strpos($atr,'<b>')) $tmp[$i]='<b>'.$tmp[$i].'</b>';
  241. if (strpos($atr,'<big>')) $tmp[$i]='<big>'.$tmp[$i].'</big>';
  242. if (strpos($atr,'<small>')) $tmp[$i]='<small>'.$tmp[$i].'</small>';
  243. $tmp_element[]=$tmp[$i].$br;
  244. }
  245. }
  246. elseif (substr($tmp[$i],0,7)=='<!--var')
  247. {
  248. $stra=explode('|',$tmp[$i]);
  249. if (($stra[1]!='')&&($stra[2]!=''))
  250. {
  251. $tmp_element[]='<!--var |'.$stra[1].'|'.$stra[2].'|-->';
  252. }
  253. }
  254. elseif (substr($tmp[$i],0,5)=='<!--r')
  255. {
  256. $str=substr($tmp[$i],9);
  257. if (($str!='') && !(strpos(strtolower($str),'<card') && ($currentdir.$editfile=='./index')))
  258. {
  259. $tmp_element[]='<!--r -->'.$str;
  260. }
  261. }
  262. elseif (substr($tmp[$i],0,9)=='<!-- Copy')
  263. {
  264. $tmp_element[]=$tmp[$i];
  265. }
  266. else
  267. {
  268. $tmp[$i]=$stmp;
  269. if (strpos($atr,'<i>')) $tmp[$i]='<i>'.$tmp[$i].'</i>';
  270. if (strpos($atr,'<u>')) $tmp[$i]='<u>'.$tmp[$i].'</u>';
  271. if (strpos($atr,'<b>')) $tmp[$i]='<b>'.$tmp[$i].'</b>';
  272. if (strpos($atr,'<big>')) $tmp[$i]='<big>'.$tmp[$i].'</big>';
  273. if (strpos($atr,'<small>')) $tmp[$i]='<small>'.$tmp[$i].'</small>';
  274. if ($tmp[$i]!='')
  275. {
  276. $tmp_element[]=$tmp[$i].$br;
  277. }
  278. }
  279. }
  280.  
  281. if ($currentdir.$editfile=='./index') $tmp_element[]='<!-- cnt --><br/><a href="http://top.'.$sitedomain.'.ru/'.$user.'"><img src="http://cnt.'.$sitedomain.'.ru/'.$user.'/'.rand(10000,99999).rand(10000,99999).'" alt="TOP-KMX.Ru"/></a>';
  282. $tmp_element[]='</p></card></wml>';
  283.  
  284. $npage='';
  285. for ($i=0;$i<sizeof($tmp_element);$i++) $npage.=$tmp_element[$i]."\n";
  286.  
  287. $fp = fopen ($userpath.$currentdir.$editfile.'.wml', "w+");
  288. fwrite ($fp, $npage);
  289. fclose ($fp);
  290. ?>