Advertisement
Guest User

7D2D recipes sorter script

a guest
Nov 25th, 2014
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.05 KB | None | 0 0
  1. <!doctype html>
  2. <html>
  3.     <head>
  4.         <meta charset="utf-8" />
  5.         <style>
  6.             .{
  7.                 font-family: arial;
  8.             }
  9.             body, h1, p, form{
  10.                 margin: 0px;
  11.                 padding: 0px;
  12.             }
  13.             h1, p{
  14.                 text-align: right;
  15.                 padding-right: 10px;
  16.             }
  17.             body{
  18.                 background: gray;
  19.             }
  20.             textarea{
  21.                 border: 1px solid white;
  22.                 background-color: silver;
  23.             }
  24.             form{
  25.                 position: absolute;
  26.                 top: 60px;
  27.                 bottom: 10px;
  28.                 left: 10px;
  29.                 right: 10px;
  30.                 width: auto;
  31.                 height: auto;
  32.                 display: block;
  33.             }
  34.             input{
  35.                 position: absolute;
  36.                 bottom: 0px;
  37.                 background-color: red;
  38.                 border: 4px solid black;
  39.                 font-weight: bold;
  40.                 font-size: 16px;
  41.             }
  42.             textarea{
  43.                 position: absolute;
  44.                 top: 0px;
  45.                 bottom: 40px;
  46.                 height: auto;
  47.                 display: block;
  48.                 margin: 0px;
  49.                 padding: 20px;
  50.             }
  51.         </style>
  52.     </head>
  53.     <body> 
  54.         <h1>7D2D recipes sorter</h1>
  55.         <p>Paste the content of your recipes.xml into the left textarea and submit the form. The recipes will be sorted by name in alphabetical order. In the right textarea you will see a list with all recipes craftable.</p>
  56.         <form method="post">
  57.             <input type="submit">
  58.             <textarea name="file" style="left: 0px; width: 70%"><?php
  59.                 $lines=array();
  60.                 $lines[]='<?xml version="1.0" encoding="UTF-8"?>';
  61.                 $lines[]='<recipes>';
  62.                 $file = "";
  63.                 if (isset($_REQUEST["file"])) $file = $_REQUEST["file"];
  64.                 $out = array();
  65.                 preg_match_all("/<recipe .*recipe>/simU",$file,$recipes);
  66.                 foreach ($recipes[0] as $recipe){
  67.                     preg_match("/<recipe name=\"([^\"]+)\"/simU",$recipe,$hit);
  68.                     $name = $hit[1];
  69.                     if (!isset($out[$name])) $out[$name]="\t";
  70.                     $out[$name] .= trim($recipe)."\r\n\t";
  71.                 }
  72.                 ksort($out);
  73.                 $lines[]=implode("\r\n",$out);
  74.                 $lines[]='</recipes>';
  75.                 echo htmlspecialchars(str_replace("    ","\t",implode($lines,"\r\n")));
  76.             ?></textarea>
  77.             <textarea name="index" style="right: 0px; width: 20%"><?php
  78.                 echo implode("\r\n",array_keys($out));
  79.             ?></textarea>
  80.         </form>
  81.     </body>
  82. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement