Advertisement
zeroc0d3

ZeroC0d3 JSON Decode Formatter

Jul 13th, 2015
551
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.89 KB | None | 0 0
  1. <?php
  2.  
  3. /* =============== DESCRIPTION FILE ======================================== */
  4. /*                                                                           */
  5. /*   Module  : ZEROC0D3 JSON DECODE FORMATTER                                */
  6. /*   Type    : JSON DECODER TOOLS                                            */
  7. /*   Author  : ZEROC0D3 Team                                                 */
  8. /*   Date    : July 2015                                                     */
  9. /*                                                                           */
  10. /*  __________                  _________ _______       .___________         */
  11. /*  \____    /___________  ____ \_   ___ \\   _  \    __| _/\_____  \ Team   */
  12. /*    /     // __ \_  __ \/  _ \/    \  \//  /_\  \  / __ |   _(__  <        */  
  13. /*   /     /\  ___/|  | \(  <_> )     \___\  \_/   \/ /_/ |  /       \       */
  14. /*  /_______ \___  >__|   \____/ \______  /\_____  /\____ | /______  /       */
  15. /*          \/   \/                     \/       \/      \/        \/        */
  16. /*                                                                           */
  17. /*  ZeroC0d3 Team                                                            */  
  18. /*  [ N0th1ng Imp0ss1bl3, Grey Hat Coder ]                                   */
  19. /*  --------------------------------------------------------                 */
  20. /*  http://pastebin.com/u/zeroc0d3                                           */
  21. /*  https://www.nulled.io/user/123090-zeroc0d3/                              */
  22. /*                                                                           */
  23. /* ========================================================================= */
  24.  
  25. global $zver;
  26. global $snap_date, $start, $end;
  27. global $str_plain;
  28. global $json, $result, $str_format;
  29. global $style1, $style2, $style3;
  30.  
  31. $GLOBALS['zver']  = "ver 1.2.1";
  32.  
  33. date_default_timezone_set('Asia/Jakarta');
  34. error_reporting(0);
  35. @ini_set('display_errors', 'Off');
  36. @ini_set('log_errors', 'Off');
  37. @ini_set('html_errors', 'Off');
  38. @ini_set('safe_mode', 'Off');
  39. @ini_set('register_globals', 'Off');
  40. @ini_set('post_max_size', '128M');
  41. @ini_set('memory_limit', '128M');
  42. @set_time_limit(0);
  43.  
  44. function cssFile()
  45. {
  46.     echo "<style>";
  47.     echo ".block { width: 270px; display: inline-block; height: 170px; padding-left: 30px; padding-bottom: 30px; text-align: center; vertical-align: top; position: relative; }  .block2 { margin: 0 auto; text-align: center; }  textarea, input, select { border: #777 1px solid; padding: 5px 0; }  .hiddenInput { display: inline-block; width: 240px; }  .code { display: none; }  .attn { color: #c00; } .button50 { width: 40%; height: 40px; border-width: 1px; border-color: #000000; font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif; font-size: 11pt; font-weight: bold; font-color: #FFFFFF; color: #FFFFFF; background-color: #000000; vertical-align: middle; }  .button100 { width: 90%; height: 40px; border-width: 1px; border-color: #000000; font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif; font-size: 11pt; font-weight: bold; font-color: #FFFFFF; color: #FFFFFF; background-color: #000000; vertical-align: middle; }  .no-print { display: none; }  .disable { font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif; font-size: 11pt; font-weight: bold; background: #DFDFDF; color: #000000; }  .disable1 { font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif; font-size: 8pt; font-weight: bold; background: #1B1B1B; color: #000000; }  .title { font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif; font-size: 16pt; font-weight: bold; color: #1B1B1B; vertical-align: middle; text-align: center; height: 50px; }  .title1 { font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif; font-size: 14pt; font-weight: bold; font-color: #000000; background-color: #AFAFAF; vertical-align: middle; text-align: center; height: 30px; }  .style0 { font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif; font-size: 9pt; font-weight: bold; color: #1B1B1B; vertical-align: middle; text-align: left; }  .style0:hover { background-color: #FFFF99; }  .style1 { font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif; font-size: 7pt; color: #1B1B1B; padding-left: 5px; padding-right: 5px; vertical-align: middle; text-align: left; }  .style1:hover { background-color: #FFFF99; }  .style2 { font-family: \"Monospace\", \"Ubuntu Mono\", \"Courier New\", Tahoma, Verdana, Arial, Helvetica, sans-serif; font-size: 9pt; font-weight: bold; color: #1B1B1B; vertical-align: middle; text-align: left; }  .style2:hover { background-color: #FFFF99; }";
  48.     echo "</style>";
  49. }
  50.  
  51. function formatJSON($json)
  52. {
  53.     global $snap_date, $start, $end;
  54.     global $str_plain;
  55.     global $json, $result, $str_format;
  56.     global $style1, $style2, $style3;
  57.  
  58.     if (!is_string($json)) {
  59.         if (phpversion() && phpversion() >= 5.4) {
  60.             return json_encode($json, JSON_PRETTY_PRINT);
  61.         }
  62.         $json = json_encode($json);
  63.     }
  64.     $result = '';
  65.     $pos = 0; // indentation level
  66.     $strLen = strlen($json);
  67.     $indentStr = "\t";
  68.     $newLine = "\n";
  69.     $prevChar = '';
  70.     $outOfQuotes = true;
  71.     for ($i = 0; $i < $strLen; $i++) {
  72.         // Speedup: copy blocks of input which don't matter re string detection and formatting.
  73.         $copyLen = strcspn($json, $outOfQuotes ? " \t\r\n\",:[{}]" : "\\\"", $i);
  74.         if ($copyLen >= 1) {
  75.             $copyStr = substr($json, $i, $copyLen);
  76.             // Also reset the tracker for escapes: we won't be hitting any right now
  77.             // and the next round is the first time an 'escape' character can be seen again at the input.
  78.             $prevChar = '';
  79.             $result .= $copyStr;
  80.             $i += $copyLen - 1; // correct for the for(;;) loop
  81.             continue;
  82.         }
  83.         // Grab the next character in the string
  84.         $char = substr($json, $i, 1);
  85.         // Are we inside a quoted string encountering an escape sequence?
  86.         if (!$outOfQuotes && $prevChar === '\\') {
  87.         // Add the escaped character to the result string and ignore it for the string enter/exit detection:
  88.             $result .= $char;
  89.             $prevChar = '';
  90.             continue;
  91.         }
  92.         // Are we entering/exiting a quoted string?
  93.         if ($char === '"' && $prevChar !== '\\') {
  94.             $outOfQuotes = !$outOfQuotes;
  95.         }
  96.         // If this character is the end of an element,
  97.         // output a new line and indent the next line
  98.         else if ($outOfQuotes && ($char === '}' || $char === ']')) {
  99.             $result .= $newLine;
  100.             $pos--;
  101.             for ($j = 0; $j < $pos; $j++) {
  102.                 $result .= $indentStr;
  103.             }
  104.         } // eat all non-essential whitespace in the input as we do our own here and it would only mess up our process
  105.         else if ($outOfQuotes && false !== strpos(" \t\r\n", $char)) {
  106.             continue;
  107.         }
  108.         // Add the character to the result string
  109.         $result .= $char;
  110.         // always add a space after a field colon:
  111.         if ($outOfQuotes && $char === ':') {
  112.             $result .= ' ';
  113.         }
  114.         // If the last character was the beginning of an element,
  115.         // output a new line and indent the next line
  116.         else if ($outOfQuotes && ($char === ',' || $char === '{' || $char === '[')) {
  117.             $result .= $newLine;
  118.             if ($char === '{' || $char === '[') {
  119.                 $pos++;
  120.             }
  121.             for ($j = 0; $j < $pos; $j++) {
  122.                 $result .= $indentStr;
  123.             }
  124.         }
  125.         $prevChar = $char;
  126.     }
  127.     $str_format = $result;
  128.     return $result;
  129. }
  130.  
  131. if ($_GET['action'] == "format_json") {
  132.     if (isset($_POST['json_unformat'])) {
  133.         $json_unformat = $_POST['json_unformat'];
  134.         $start = microtime(true);
  135.         formatJSON($json = $json_unformat);
  136.         $style1 = $str_format;
  137.         $end = microtime(true);
  138.         $snap_date = date("D, Y-m-d H:i");      
  139.     }
  140. }
  141.  
  142. ?>
  143.  
  144. <html>
  145. <head>
  146.     <title>ZeroC0d3 JSON DECODE FORMATER</title>
  147.     <?php echo cssFile(); ?>
  148. </head>
  149. <body>
  150. <table width="780" border="1" align="center">
  151.     <tr>
  152.         <th colspan="3" class="title" scope="col" bgcolor="#AFAFAF">&nbsp;<strong>ZeroC0d3 JSON DECODE FORMATER (<?php echo $GLOBALS['zver']; ?>)</strong></th>
  153.     </tr>
  154.     <form id="form1" name="form1" method="post" action="<?php echo basename($_SERVER['PHP_SELF']); ?>?action=format_json">
  155.         <tr>
  156.             <th scope="row" class="style0" width="250px">&nbsp;JSON (Unformat)&nbsp;</th>
  157.             <td class="style0" style="text-align:center" width="5">
  158.                 <center>&nbsp;:&nbsp;</center>
  159.             </td>
  160.             <td>
  161.                 <textarea name="json_unformat" cols="80" rows="5"><?php if ($start > 0) {
  162.                    echo $json_unformat . "\n"; } ?></textarea>
  163.             </td>
  164.         </tr>
  165.         <tr>
  166.             <th colspan="3" style="text-align:left" scope="row">
  167.                 <center>
  168.                     <input type="submit" name="json_text" id="  " value="FORMAT JSON" class="button100"/>
  169.                 </center>
  170.             </th>
  171.         </tr>
  172.     </form>
  173.     <tr>
  174.         <th colspan="3" class="title1" scope="col">&nbsp;<strong>JSON FORMATED :: RESULTS</strong></th>
  175.     </tr>
  176.     <tr>
  177.         <th scope="row" class="style0" width="250px">&nbsp;Visual Decoded (Style-1)&nbsp;</th>
  178.         <td class="style0" style="text-align:center" width="5">
  179.             <center>&nbsp;:&nbsp;</center>
  180.         </td>
  181.         <td>
  182.             <textarea name="vstyle1" cols="80" rows="30" readonly><?php if ($start > 0) {
  183.                     echo $style1 . "\n";
  184.                 } ?></textarea>
  185.         </td>
  186.     </tr>
  187.     <tr>
  188.         <th scope="row" class="style0" width="250px">&nbsp;Visual Decoded (Style-2)&nbsp;</th>
  189.         <td class="style0" style="text-align:center" width="5">
  190.             <center>&nbsp;:&nbsp;</center>
  191.         </td>
  192.         <td>
  193.             <textarea name="vstyle2" cols="80" rows="10" readonly><?php if ($start > 0) {
  194.                    $style2 = var_dump(json_decode($style1, true));
  195.                    echo $style2 . "\n";
  196.                 } ?></textarea>
  197.         </td>
  198.     </tr>
  199.     <tr>
  200.         <th scope="row" class="style0" width="250px">&nbsp;Visual Decoded (Style-3)&nbsp;</th>
  201.         <td class="style0" style="text-align:center" width="5">
  202.             <center>&nbsp;:&nbsp;</center>
  203.         </td>
  204.         <td>
  205.             <textarea name="vstyle3" cols="80" rows="10" readonly><?php if ($start > 0) {
  206.                     $style3 = var_dump(json_decode($style1, false, 512, JSON_BIGINT_AS_STRING));
  207.                     echo $style3 . "\n";
  208.                 } ?></textarea>
  209.         </td>
  210.     </tr>
  211.     <tr>
  212.         <th colspan="3" class="style1" scope="row">&nbsp;Execution Time (s)
  213.             : <?php echo "<strong>" . ($end - $start) . " | Last Activities : " . $snap_date . " </strong>"; ?></th>
  214.     </tr>
  215. </table>
  216. </body>
  217. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement