PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/logbook/cachevalidator.php

https://gitlab.com/bechemm/opencaching.pl
PHP | 197 lines | 146 code | 37 blank | 14 comment | 13 complexity | 56cbaa8dfed05c3c9e2c554e87e8af0e MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0
  1. <?php
  2. $secret = "dupa231";
  3. include('commons.php');
  4. header('Content-Type: application/xhtml+xml; charset=utf-8');
  5. echo '<?xml version="1.0" encoding="utf-8"?'.">\n";
  6. echo '<?xml-stylesheet type="text/css" href="style.css"?'.">\n";
  7. if (get_magic_quotes_gpc()) {
  8. function stripslashes_deep($value)
  9. {
  10. $value = is_array($value) ?
  11. array_map('stripslashes_deep', $value) :
  12. stripslashes($value);
  13. return $value;
  14. }
  15. $_POST = array_map('stripslashes_deep', $_POST);
  16. $_GET = array_map('stripslashes_deep', $_GET);
  17. $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
  18. $_REQUEST = array_map('stripslashes_deep', $_REQUEST);
  19. }
  20. ?>
  21. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  22. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl">
  23. <head>
  24. <title>Naprawiacz opisu</title>
  25. <script src="ajax.js" type="text/javascript" charset="utf-8"></script>
  26. </head>
  27. <body>
  28. <script type="text/javascript">
  29. //<![CDATA[
  30. var cururl;
  31. var curpage = 1;
  32. var numpages = 1;
  33. function startCallback() {
  34. // make something useful before submit (onStart)
  35. return true;
  36. }
  37. function bindArgument(fn, arg)
  38. {
  39. return function () {
  40. return fn(arg);
  41. };
  42. }
  43. function removeChildrenFromNode(node)
  44. {
  45. var len = node.childNodes.length;
  46. while (node.hasChildNodes()) {
  47. node.removeChild(node.firstChild);
  48. }
  49. }
  50. //]]>
  51. </script>
  52. <div id="logoblock">
  53. <img src="geocaching.jpg" id="logo" />
  54. </div>
  55. <div id="navibar">
  56. <!--<span><a href="">Strona Główna</a></span>-->
  57. <?php
  58. include("menu.inc");
  59. ?>
  60. </div>
  61. <p>
  62. <?php
  63. $options = array("input-encoding" => "utf8", "output-encoding" => "utf8", "output-xhtml" => true, "doctype" => "omit", "show-body-only" => true, "char-encoding" => "utf8", "quote-ampersand" => true, "quote-nbsp" => true);
  64. $text = $_POST['text'];
  65. //$text = preg_replace('~&#([0-9]+);~e', 'chr("\\1")', $text);
  66. #$text = preg_replace('~&#x([0-9a-fA-F]+);~ei', 'chr(hexdec("\\1"))', $text);
  67. //$text = mb_convert_encoding( $text, "utf-8", "HTML-ENTITIES" );
  68. //decode decimal HTML entities added by web browser
  69. $text = preg_replace('/&#\d{2,5};/ue', "utf8_entity_decode('$0')", $text );
  70. //decode hex HTML entities added by web browser
  71. $text = preg_replace('/&#x([a-fA-F0-7]{2,8});/ue', "utf8_entity_decode('&#'.hexdec('$1').';')", $text );
  72. //callback function for the regex
  73. function utf8_entity_decode($entity){
  74. $convmap = array(0x0, 0x10000, 0, 0xfffff);
  75. return "ż";
  76. // return mb_decode_numericentity($entity, $convmap, 'UTF-8');
  77. }
  78. $tidy = tidy_parse_string(html_entity_decode($text, ENT_NOQUOTES, "UTF-8"), $options);
  79. tidy_clean_repair($tidy);
  80. function iterate_over($node)
  81. {
  82. $removed = array();
  83. print "<br />Iterating over " . $node->tagName ."\n";
  84. if($node->tagName == "span") {
  85. print "deleting\n";
  86. array_push($removed, $node);
  87. }
  88. if(!$node)
  89. return;
  90. if($node->hasAttributes()) {
  91. $attributes = $node->attributes;
  92. if(!is_null($attributes))
  93. foreach ($attributes as $index=>$attr)
  94. echo $attr->name ." = " . htmlspecialchars($attr->value) . "\n";
  95. }
  96. if($node->hasChildNodes()) {
  97. $children = $node->childNodes;
  98. foreach($children as $child) {
  99. $removed = array_merge($removed, iterate_over($child, $array));
  100. }
  101. }
  102. return $removed;
  103. }
  104. function appendSibling(DOMNode $newnode, DOMNode $ref)
  105. {
  106. if ($ref->nextSibling) {
  107. // $ref has an immediate brother : insert newnode before this one
  108. return $ref->parentNode->insertBefore($newnode, $ref->nextSibling);
  109. } else {
  110. // $ref has no brother next to him : insert newnode as last child of his parent
  111. return $ref->parentNode->appendChild($newnode);
  112. }
  113. }
  114. function remove_node($domElement)
  115. {
  116. if($domElement->hasChildNodes()) {
  117. $children = $domElement->childNodes;
  118. $toAppend = array();
  119. foreach($children as $child)
  120. array_unshift($toAppend, $child);
  121. foreach($toAppend as $child)
  122. appendSibling($child, $domElement);
  123. }
  124. // $domElement->parentNode->removeChild($domElement);
  125. }
  126. $str = (string)$tidy;
  127. if($str) {
  128. // $str = str_replace("&amp;", "&", $str);
  129. $doc = DOMDocument::loadXML("<cache_description>".$str."</cache_description>");
  130. $doc->encoding = "utf-8";
  131. $main = $doc->documentElement;
  132. if($main) {
  133. $for_removal = iterate_over($main);
  134. foreach($for_removal as $domElement) {
  135. echo "<br/>removing ..\n";
  136. remove_node($domElement);
  137. $domElement->parentNode->removeChild($domElement);
  138. }
  139. }
  140. $str = $doc->saveXML();
  141. $str = str_replace('<?xml version="1.0" encoding="utf-8"?>'."\n", "", $str);
  142. $str = str_replace('<cache_description>', "", $str);
  143. $str = str_replace('</cache_description>', "", $str);
  144. }
  145. ?>
  146. <form method="post" action="index.php?page=cachevalidator">
  147. <textarea name="text" id="validatorarea"><?php
  148. echo htmlspecialchars($str, ENT_NOQUOTES, "UTF-8");
  149. ?></textarea>
  150. <br/>
  151. <input type="submit" name="submit" value="Poprawiaj!" />
  152. </form>
  153. </p>
  154. <div id="textpreview">
  155. <?php
  156. echo $str;
  157. ?>
  158. </div>
  159. </body>
  160. </html>