<commit_before><?PHP  // $Id$ 
///////////////////////////////////////////////////////////////////////////
//                                                                       //
// WebCT FORMAT                                                          //
//                                                                       //
///////////////////////////////////////////////////////////////////////////
//                                                                       //
// NOTICE OF COPYRIGHT                                                   //
//                                                                       //
// Part of Moodle - Modular Object-Oriented Dynamic Learning Environment //
//                  http://moodle.com                                    //
//                                                                       //
// Copyright (C) 2004 ASP Consulting   http://www.asp-consulting.net     //
//                                                                       //
// This program is free software; you can redistribute it and/or modify  //
// it under the terms of the GNU General Public License as published by  //
// the Free Software Foundation; either version 2 of the License, or     //
// (at your option) any later version.                                   //
//                                                                       //
// This program is distributed in the hope that it will be useful,       //
// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
// GNU General Public License for more details:                          //
//                                                                       //
//          http://www.gnu.org/copyleft/gpl.html                         //
//                                                                       //
///////////////////////////////////////////////////////////////////////////

// Based on format.php, included by ../../import.php

function unhtmlentities($string){
    $search = array ("'<script[?>]*?>.*?</script>'si",  // remove javascript
                 "'<[\/\!]*?[^<?>]*?>'si",  // remove HTML tags
                 "'([\r\n])[\s]+'",  // remove spaces
                 "'&(quot|#34);'i",  // remove HTML entites
                 "'&(amp|#38);'i",
                 "'&(lt|#60);'i",
                 "'&(gt|#62);'i",
                 "'&(nbsp|#160);'i",
                 "'&(iexcl|#161);'i",
                 "'&(cent|#162);'i",
                 "'&(pound|#163);'i",
                 "'&(copy|#169);'i",
                 "'&#(\d+);'e");  // Evaluate like PHP
    $replace = array ("",
                  "",
                  "\\1",
                  "\"",
                  "&",
                  "<",
                  "?>",
                  " ",
                  chr(161),
                  chr(162),
                  chr(163),
                  chr(169),
                  "chr(\\1)");
    return preg_replace ($search, $replace, $string);
}

class quiz_file_format extends quiz_default_format {

    function readquestions ($lines) {

        $questions = array();
        $errors = array();
        $warnings = array();
        $webct_options = array();

        $ignore_rest_of_question = FALSE;

        $nLineCounter = 0;
        $nQuestionStartLine = 0;
        $bIsHTMLText = FALSE;
        $lines[] = ":EOF:";    // for an easiest processing of the last line

        foreach ($lines as $line) {
            $nLineCounter++;

            // Processing multiples lines strings

            if (is_string($questiontext)) {
                if (ereg("^:",$line)) {
                    $question->questiontext = addslashes(trim($questiontext));
                    unset($questiontext);
                }
                 else {
                    $questiontext .= $line;
                    continue;
                }
            }

            if (is_string($answertext)) {
                if (ereg("^:",$line)) {
                    if ($bIsHTMLText) {
                    	$answertext = unhtmlentities($answertext); // answer as HTML text not supported by Moddle
                    }
                    $answertext = addslashes(trim($answertext));
                    $question->answer[$currentchoice] = $answertext;
                    unset($answertext);
                }
                 else {
                    $answertext .= $line;
                    continue;
                }
            }

            if (is_string($responstext)) {
                if (ereg("^:",$line)) {
                    if ($bIsHTMLText) {
                    	$responstext = unhtmlentities($responstext); // answer as HTML text not supported by Moddle
                    }
                    $question->subquestions[$currentchoice] = addslashes(trim($responstext));
                    unset($responstext);
                }
                 else {
                    $responstext .= $line;
                    continue;
                }
            }

            if (is_string($feedbacktext)) {
                if (ereg("^:",$line)) {
                    if ($bIsHTMLText) {
                    	$feedbacktext = unhtmlentities($feedbacktext); // feedback as HTML text not supported by Moddle
                    }
                    $question->feedback[$currentchoice] = addslashes(trim($feedbacktext));
                    unset($feedbacktext);
                }
                 else {
                    $feedbacktext .= $line;
                    continue;
                }
            }

            $line = trim($line);

            if (eregi("^:(TYPE|EOF):",$line)) {
                // New Question or End of File
                if (isset($question)) {            // if previous question exists, complete, check and save it

                    // Setup default value of missing fields
                    if (!isset($question->name)) {
                        $question->name = $question->questiontext;
                    }
                    if (strlen($question->name) > 255) {
                        $question->name = substr($question->name,0,250)."...";
                        $warnings[] = get_string("questionnametoolong", "quiz", $nQuestionStartLine);
                    }
                    if (!isset($question->defaultgrade)) {
                        $question->defaultgrade = 1;
                    }
                    if (!isset($question->image)) {
                        $question->image = "";
                    }

                    // Perform sanity checks
                    $QuestionOK = TRUE;
                    if (strlen($question->questiontext) == 0) {
                        $errors[] = get_string("missingquestion", "quiz", $nQuestionStartLine);
                        $QuestionOK = FALSE;
                    }
                    if (sizeof($question->answer) <= 1) {  // a question must have at last 2 answers
                        $errors[] = get_string("missinganswer", "quiz", $nQuestionStartLine);
                        $QuestionOK = FALSE;
                    }
                    else {
                        // Perform string length check
                        foreach ($question->answer as $key => $dataanswer) {
                            if (strlen($dataanswer) > 255) {
                                $question->answer[$key] = substr($dataanswer,0,250)."...";
                                $warnings[] = get_string("answertoolong", "quiz", $nQuestionStartLine);
                            }
                        }
                        $maxfraction = -1;
                        $totalfraction = 0;
                        foreach($question->fraction as $fraction) {
                            if ($fraction > 0) {
                                $totalfraction += $fraction;<commit_msg>WebCT import can now deal with escaped colons in the text   bug 1182<commit_after><?PHP  // $Id$ 
///////////////////////////////////////////////////////////////////////////
//                                                                       //
// WebCT FORMAT                                                          //
//                                                                       //
///////////////////////////////////////////////////////////////////////////
//                                                                       //
// NOTICE OF COPYRIGHT                                                   //
//                                                                       //
// Part of Moodle - Modular Object-Oriented Dynamic Learning Environment //
//                  http://moodle.com                                    //
//                                                                       //
// Copyright (C) 2004 ASP Consulting   http://www.asp-consulting.net     //
//                                                                       //
// This program is free software; you can redistribute it and/or modify  //
// it under the terms of the GNU General Public License as published by  //
// the Free Software Foundation; either version 2 of the License, or     //
// (at your option) any later version.                                   //
//                                                                       //
// This program is distributed in the hope that it will be useful,       //
// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
// GNU General Public License for more details:                          //
//                                                                       //
//          http://www.gnu.org/copyleft/gpl.html                         //
//                                                                       //
///////////////////////////////////////////////////////////////////////////

// Based on format.php, included by ../../import.php

function unhtmlentities($string){
    $search = array ("'<script[?>]*?>.*?</script>'si",  // remove javascript
                 "'<[\/\!]*?[^<?>]*?>'si",  // remove HTML tags
                 "'([\r\n])[\s]+'",  // remove spaces
                 "'&(quot|#34);'i",  // remove HTML entites
                 "'&(amp|#38);'i",
                 "'&(lt|#60);'i",
                 "'&(gt|#62);'i",
                 "'&(nbsp|#160);'i",
                 "'&(iexcl|#161);'i",
                 "'&(cent|#162);'i",
                 "'&(pound|#163);'i",
                 "'&(copy|#169);'i",
                 "'&#(\d+);'e");  // Evaluate like PHP
    $replace = array ("",
                  "",
                  "\\1",
                  "\"",
                  "&",
                  "<",
                  "?>",
                  " ",
                  chr(161),
                  chr(162),
                  chr(163),
                  chr(169),
                  "chr(\\1)");
    return preg_replace ($search, $replace, $string);
}

class quiz_file_format extends quiz_default_format {

    function readquestions ($lines) {

        $questions = array();
        $errors = array();
        $warnings = array();
        $webct_options = array();

        $ignore_rest_of_question = FALSE;

        $nLineCounter = 0;
        $nQuestionStartLine = 0;
        $bIsHTMLText = FALSE;
        $lines[] = ":EOF:";    // for an easiest processing of the last line

        foreach ($lines as $line) {
            $nLineCounter++;

            // Processing multiples lines strings

            if (is_string($questiontext)) {
                if (ereg("^:",$line)) {
                    $question->questiontext = addslashes(trim($questiontext));
                    unset($questiontext);
                }
                 else {
                    $questiontext .= str_replace('\:', ':', $line);
                    continue;
                }
            }

            if (is_string($answertext)) {
                if (ereg("^:",$line)) {
                    $answertext = addslashes(trim($answertext));
                    $question->answer[$currentchoice] = $answertext;
                    unset($answertext);
                }
                 else {
                    $answertext .= str_replace('\:', ':', $line);
                    continue;
                }
            }

            if (is_string($responstext)) {
                if (ereg("^:",$line)) {
                    $question->subquestions[$currentchoice] = addslashes(trim($responstext));
                    unset($responstext);
                }
                 else {
                    $responstext .= str_replace('\:', ':', $line);
                    continue;
                }
            }

            if (is_string($feedbacktext)) {
                if (ereg("^:",$line)) {
                    $question->feedback[$currentchoice] = addslashes(trim($feedbacktext));
                    unset($feedbacktext);
                }
                 else {
                    $feedbacktext .= str_replace('\:', ':', $line);
                    continue;
                }
            }

            $line = trim($line);

            if (eregi("^:(TYPE|EOF):",$line)) {
                // New Question or End of File
                if (isset($question)) {            // if previous question exists, complete, check and save it

                    // Setup default value of missing fields
                    if (!isset($question->name)) {
                        $question->name = $question->questiontext;
                    }
                    if (strlen($question->name) > 255) {
                        $question->name = substr($question->name,0,250)."...";
                        $warnings[] = get_string("questionnametoolong", "quiz", $nQuestionStartLine);
                    }
                    if (!isset($question->defaultgrade)) {
                        $question->defaultgrade = 1;
                    }
                    if (!isset($question->image)) {
                        $question->image = "";
                    }

                    // Perform sanity checks
                    $QuestionOK = TRUE;
                    if (strlen($question->questiontext) == 0) {
                        $errors[] = get_string("missingquestion", "quiz", $nQuestionStartLine);
                        $QuestionOK = FALSE;
                    }
                    if (empty($question->answer)) {  // a question must have at least 1 answer
                       $errors[] = get_string("missinganswer", "quiz", $nQuestionStartLine);
                       $QuestionOK = FALSE;
                    }
                    else {
                        // Perform string length check
                        foreach ($question->answer as $key => $dataanswer) {
                            if (strlen($dataanswer) > 255) {
                                $question->answer[$key] = substr($dataanswer,0,250)."...";
                                $warnings[] = get_string("answertoolong", "quiz", $nQuestionStartLine);
                            }
                        }
                        $maxfraction = -1;
                        $totalfraction = 0;
                        foreach($question->fraction as $fraction) {
                            if ($fraction > 0) {
                                $totalfraction += $fraction;
{'fraction_non_alphanumeric': 0.15075669383003493, 'fraction_numerical': 0.008601733281593584, 'mean_word_length': 0.8545214679779324, 'pattern_counts': {'":': 2, '<': 16, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 66, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3081721', 'n_tokens_mistral': 3551, 'n_tokens_neox': 3248, 'n_words': 746}