Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function clean($str) {
- return preg_replace("'<[\/\!]*?[^<>]*?>'si", "", $str);
- }
- if ($_POST) {
- header('Content-type: text/plain');
- $context = stream_context_create(array("ssl"=>array("verify_peer"=>false,"verify_peer_name"=>false)));
- $correct = explode("\r\n", $_POST['correct']);
- $wrong = explode("\r\n", $_POST['wrong']);
- $data_links = explode("\r\n", $_POST['links_json']);
- foreach ($data_links as $data) {
- list($link, $filename) = explode(' => ', $data);
- //var_dump($link, $filename);continue;
- $json = json_decode(file_get_contents(trim($link), false, $context));
- $questions = $json->data->quiz->info->questions;
- ob_start();
- 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";
- $array_replaces = array (
- '"' => '""',
- ' ' => ' '
- );
- foreach ($questions as $n => $question) {
- if ($question->structure->settings->hasCorrectAnswer === false || count($question->structure->options) > 4) {
- continue;
- }
- if (is_array($question->structure->answer) && !count($question->structure->answer)) {
- continue;
- }
- //var_dump($question);
- $num = $n + 1;
- $query = strtr($question->structure->query->text, $array_replaces);
- if (empty($query) && isset($question->structure->query->media[0])) {
- $query = $question->structure->query->media[0]->url;
- }
- echo $num.',"'.clean($query).'",'.count($question->structure->options).',';
- //if ($num == 2) var_dump($question->structure);
- for($na = 0; $na < 4; $na++) {
- $answer = isset($question->structure->options[$na]) ? $question->structure->options[$na]->text : "";
- echo '"'.str_replace('"', '""', clean($answer)).'",';
- if (is_array($question->structure->answer)) {
- echo in_array($na, $question->structure->answer) ? 'Y' : '';
- } else {
- echo $question->structure->answer == $na ? 'Y' : '';
- }
- echo ',';
- }
- echo $correct[array_rand($correct,1)].',';
- echo $wrong[array_rand($wrong,1)]."\n";
- }
- $content = ob_get_contents();
- ob_end_clean();
- echo $content."\n\n";
- if (file_put_contents(__DIR__.'/'.trim($filename), $content)) {
- echo "File save to ".trim($filename)." succefull\n\n";
- } else {
- echo "Error save file to ".trim($filename)."\n\n";
- }
- }
- exit;
- }
- ?>
- <style>
- table {
- border-collapse: collapse;
- }
- table td {
- padding: 10px;
- }
- textarea {
- width: 800px;
- height: 200px;
- }
- input[type="text"] {
- width: 500px;
- }
- img {
- box-shadow: 0 0 15px rgba(0, 0, 0, 0.3);
- }
- </style>
- <img src="https://i.paste.pics/f29d1dca2fd18c0f0649e00253e8746b.png" />
- <br /><br />
- <form method="post">
- <table border="1">
- <!--//<tr>
- <td>JSON</td>
- <td><textarea name="json"></textarea></td>
- </tr>//-->
- <tr>
- <td>Links JSON</td>
- <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>
- </tr>
- <tr>
- <td>Correct text</td>
- <td><textarea name="correct">Congratulations! Your Answer Is Right.
- Hurray!! Your Answer Is Right.
- Congrats! Your Answer Is Right.
- WOW! Your Answer Is Right.
- Awesome! Your Answer Is Right.</textarea></td>
- </tr>
- <tr>
- <td>Wrong text</td>
- <td><textarea name="wrong">OOPS! Your Answer Is Wrong.
- OUCH! Your Answer Was Wrong.
- SAD! Your Answer Was Wrong.
- OOPS! You Selected Wrong Answer.
- OUCH! You Selected Wrong Answer.</textarea></td>
- </tr>
- <tr>
- <td></td>
- <td><input type="submit" value="Submit" /></td>
- </tr>
- </table>
- </form>
Advertisement
Add Comment
Please, Sign In to add comment