Newer
Older
pushpullRefactoringExperiments / syntaxhighlighter-3.0.83 / build / ext / packer / example-inline.php
  1. <?php
  2.  
  3. $treat = false;
  4. if (isset($_POST['src'])) {
  5. $script = $_POST['src'];
  6. if (get_magic_quotes_gpc())
  7. $script = stripslashes($script);
  8. $encoding = (int)$_POST['ascii_encoding'];
  9. $fast_decode = isset($_POST['fast_decode']) && $_POST['fast_decode'];
  10. $special_char = isset($_POST['special_char'])&& $_POST['special_char'];
  11.  
  12. require 'class.JavaScriptPacker.php';
  13. $t1 = microtime(true);
  14. $packer = new JavaScriptPacker($script, $encoding, $fast_decode, $special_char);
  15. $packed = $packer->pack();
  16. $t2 = microtime(true);
  17.  
  18. $originalLength = strlen($script);
  19. $packedLength = strlen($packed);
  20. $ratio = number_format($packedLength / $originalLength, 3);
  21. $time = sprintf('%.4f', ($t2 - $t1) );
  22.  
  23. $treat = true;
  24. }
  25. ?>
  26. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  27. "http://www.w3.org/TR/html4/strict.dtd">
  28. <html>
  29. <head>
  30. <title>JavaScript Packer in PHP</title>
  31. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  32. <style type="text/css">
  33. .result {
  34. border: 1px blue dashed;
  35. color: black;
  36. background-color: #e5e5e5;
  37. padding: 0.2em;
  38. }
  39. </style>
  40. <script type="text/javascript">
  41. function decode() {
  42. var packed = document.getElementById('packed');
  43. eval("packed.value=String" + packed.value.slice(4));
  44. }
  45. </script>
  46. </head>
  47. <body>
  48. <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
  49. <div>
  50. <h3>script to pack:</h3>
  51. <textarea name="src" id="src" rows="10" cols="80"><?php if($treat) echo htmlspecialchars($script);?></textarea>
  52. </div>
  53. <!-- <fieldset> -->
  54. <div>
  55. <label for="ascii-encoding">Encoding:</label>
  56. <select name="ascii_encoding" id="ascii-encoding">
  57. <option value="0"<?php if ($treat && $encoding == 0) echo ' selected'?>>None</option>
  58. <option value="10"<?php if ($treat && $encoding == 10) echo ' selected'?>>Numeric</option>
  59. <option value="62"<?php if (!$treat) echo 'selected';if ($treat && $encoding == 62) echo ' selected';?>>Normal</option>
  60. <option value="95"<?php if ($treat && $encoding == 95) echo ' selected'?>>High ASCII</option>
  61. </select>
  62. <label>
  63. Fast Decode:
  64. <input type="checkbox" name="fast_decode" id="fast-decode"<?php if (!$treat || $fast_decode) echo ' checked'?>>
  65. </label>
  66. <label>
  67. Special Characters:
  68. <input type="checkbox" name="special_char" id="special-char"<?php if ($treat && $special_char) echo ' checked'?>>
  69. </label>
  70. <input type="submit" value="Pack">
  71. </div>
  72. <!-- </fieldset> -->
  73. </form>
  74.  
  75. <?php if ($treat) {?>
  76. <div id="result">
  77. <h3>packed result:</h3>
  78. <textarea id="packed" class="result" rows="10" cols="80" readonly="readonly"><?php echo htmlspecialchars($packed);?></textarea>
  79. <p>
  80. compression ratio:
  81. <?php echo $originalLength, '/', $packedLength, ' = ',$ratio; ?>
  82. <br>performed in <?php echo $time; ?> s.
  83. </p>
  84. <p><button type="button" onclick="decode()">decode</button></p>
  85. </div>
  86. <?php };//end if($treat)?>
  87. </body>
  88. </html>