denverkurt

form_csv

Feb 21st, 2021 (edited)
1,117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.67 KB | None | 0 0
  1. <?php
  2.  
  3. function clean($str) {
  4.     return preg_replace("'<[\/\!]*?[^<>]*?>'si", "", $str);
  5. }
  6.  
  7. if ($_POST) {
  8.     header('Content-type: text/plain');
  9.    
  10.     $context = stream_context_create(array("ssl"=>array("verify_peer"=>false,"verify_peer_name"=>false)));
  11.    
  12.     $correct = explode("\r\n", $_POST['correct']);
  13.     $wrong = explode("\r\n", $_POST['wrong']);
  14.    
  15.     $data_links = explode("\r\n", $_POST['links_json']);
  16.     foreach ($data_links as $data) {
  17.         list($link, $filename) = explode(' => ', $data);
  18.         //var_dump($link, $filename);continue;
  19.         $json = json_decode(file_get_contents(trim($link), false, $context));
  20.         $questions = $json->data->quiz->info->questions;
  21.         ob_start();
  22.         echo "#,Question,No of answers,Answer 1,Correct 1,Answer 2,Correct 2,Answer 3,Correct 3,Answer 4,Correct 4,Correct Text,Wrong Text\n";
  23.         $array_replaces = array (
  24.             '"' => '""',
  25.             '&nbsp;' => ' '
  26.         );
  27.         foreach ($questions as $n => $question) {
  28.             if ($question->structure->settings->hasCorrectAnswer === false || count($question->structure->options) > 4) {
  29.                 continue;
  30.             }
  31.             if (is_array($question->structure->answer) && !count($question->structure->answer)) {
  32.                 continue;
  33.             }
  34.            
  35.             //var_dump($question);
  36.             $num = $n + 1;
  37.             $query = strtr($question->structure->query->text, $array_replaces);
  38.             if (empty($query) && isset($question->structure->query->media[0])) {
  39.                 $query = $question->structure->query->media[0]->url;
  40.             }
  41.             echo $num.',"'.clean($query).'",'.count($question->structure->options).',';
  42.             //if ($num == 2) var_dump($question->structure);
  43.            
  44.             for($na = 0; $na < 4; $na++) {
  45.                 $answer = isset($question->structure->options[$na]) ? $question->structure->options[$na]->text : "";
  46.                 echo '"'.str_replace('"', '""', clean($answer)).'",';
  47.                 if (is_array($question->structure->answer)) {
  48.                     echo in_array($na, $question->structure->answer) ? 'Y' : '';
  49.                 } else {
  50.                     echo $question->structure->answer == $na ? 'Y' : '';
  51.                 }
  52.                 echo ',';
  53.             }
  54.             echo $correct[array_rand($correct,1)].',';
  55.             echo $wrong[array_rand($wrong,1)]."\n";
  56.         }
  57.         $content = ob_get_contents();
  58.         ob_end_clean();
  59.         echo $content."\n\n";
  60.         if (file_put_contents(__DIR__.'/'.trim($filename), $content)) {
  61.             echo "File save to ".trim($filename)." succefull\n\n";
  62.         } else {
  63.             echo "Error save file to ".trim($filename)."\n\n";
  64.         }
  65.     }
  66.    
  67.     exit;
  68. }
  69.  
  70. ?>
  71. <style>
  72. table {
  73.     border-collapse: collapse;
  74. }
  75. table td {
  76.     padding: 10px;
  77. }
  78. textarea {
  79.     width: 800px;
  80.     height: 200px;
  81. }
  82. input[type="text"] {
  83.     width: 500px;
  84. }
  85. img {
  86.     box-shadow: 0 0 15px rgba(0, 0, 0, 0.3);
  87. }
  88. </style>
  89. <img src="https://i.paste.pics/f29d1dca2fd18c0f0649e00253e8746b.png" />
  90. <br /><br />
  91. <form method="post">
  92.     <table border="1">
  93.         <!--//<tr>
  94.             <td>JSON</td>
  95.             <td><textarea name="json"></textarea></td>
  96.         </tr>//-->
  97.         <tr>
  98.             <td>Links JSON</td>
  99.             <td><textarea name="links_json" placeholder="https://quizizz.com/api/main/quiz/56e61ebd08c764eb3262f31a?cached=true&_=1613924620641 => quiz.csv">https://quizizz.com/api/main/quiz/56e61ebd08c764eb3262f31a?cached=true&_=1613924620641 => quiz.csv</textarea></td>
  100.         </tr>
  101.         <tr>
  102.             <td>Correct text</td>
  103.             <td><textarea name="correct">Congratulations! Your Answer Is Right.
  104. Hurray!! Your Answer Is Right.
  105. Congrats! Your Answer Is Right.
  106. WOW! Your Answer Is Right.
  107. Awesome! Your Answer Is Right.</textarea></td>
  108.         </tr>
  109.         <tr>
  110.             <td>Wrong text</td>
  111.             <td><textarea name="wrong">OOPS! Your Answer Is Wrong.
  112. OUCH! Your Answer Was Wrong.
  113. SAD! Your Answer Was Wrong.
  114. OOPS! You Selected Wrong Answer.
  115. OUCH! You Selected Wrong Answer.</textarea></td>
  116.         </tr>
  117.         <tr>
  118.             <td></td>
  119.             <td><input type="submit" value="Submit" /></td>
  120.         </tr>
  121.     </table>
  122. </form>
  123.  
Advertisement
Add Comment
Please, Sign In to add comment