<commit_before><?php  
require_once("$CFG->dirroot/question/format/qti2/qt_common.php");
////////////////////////////////////////////////////////////////////////////
/// IMS QTI 2.0 FORMAT
///
/// HISTORY: created 28.01.2005      <EMAIL>
////////////////////////////////////////////////////////////////////////////

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

define('CLOZE_TRAILING_TEXT_ID', 9999999);

class qformat_qti2 extends qformat_default {
    
    var $lang;

    function provide_export() {
       return true;
    }
    
    function indent_xhtml($source, $indenter = ' ') { 
        // xml tidier-upper
        // (c) <NAME> http://ventionline.com
        
        // Remove all pre-existing formatting. 
        // Remove all newlines. 
        $source = str_replace("\n", '', $source); 
        $source = str_replace("\r", '', $source); 
        // Remove all tabs. 
        $source = str_replace("\t", '', $source); 
        // Remove all space after ">" and before "<". 
        $source = ereg_replace(">( )*", ">", $source); 
        $source = ereg_replace("( )*<", "<", $source); 
    
        // Iterate through the source. 
        $level = 0; 
        $source_len = strlen($source); 
        $pt = 0; 
        while ($pt < $source_len) { 
            if ($source{$pt} === '<') { 
                // We have entered a tag. 
                // Remember the point where the tag starts. 
                $started_at = $pt; 
                $tag_level = 1; 
                // If the second letter of the tag is "/", assume its an ending tag. 
                if ($source{$pt+1} === '/') { 
                    $tag_level = -1; 
                } 
                // If the second letter of the tag is "!", assume its an "invisible" tag. 
                if ($source{$pt+1} === '!') { 
                    $tag_level = 0; 
                } 
                // Iterate throught the source until the end of tag. 
                while ($source{$pt} !== '>') { 
                    $pt++; 
                } 
                // If the second last letter is "/", assume its a self ending tag. 
                if ($source{$pt-1} === '/') { 
                    $tag_level = 0; 
                } 
                $tag_lenght = $pt+1-$started_at; 
                 
                // Decide the level of indention for this tag. 
                // If this was an ending tag, decrease indent level for this tag.. 
                if ($tag_level === -1) { 
                    $level--; 
                } 
                // Place the tag in an array with proper indention. 
                $array[] = str_repeat($indenter, $level).substr($source, $started_at, $tag_lenght); 
                // If this was a starting tag, increase the indent level after this tag. 
                if ($tag_level === 1) { 
                    $level++; 
                } 
                // if it was a self closing tag, dont do shit. 
            } 
            // Were out of the tag. 
            // If next letter exists... 
            if (($pt+1) < $source_len) { 
                // ... and its not an "<". 
                if ($source{$pt+1} !== '<') { 
                    $started_at = $pt+1; 
                    // Iterate through the source until the start of new tag or until we reach the end of file. 
                    while ($source{$pt} !== '<' && $pt < $source_len) { 
                        $pt++; 
                    } 
                    // If we found a "<" (we didnt find the end of file) 
                    if ($source{$pt} === '<') { 
                        $tag_lenght = $pt-$started_at; 
                        // Place the stuff in an array with proper indention. 
                        $array[] = str_repeat($indenter, $level).substr($source, $started_at, $tag_lenght); 
                    } 
                // If the next tag is "<", just advance pointer and let the tag indenter take care of it. 
                } else { 
                    $pt++; 
                } 
            // If the next letter doesnt exist... Were done... well, almost.. 
            } else { 
                break; 
            } 
        } 
        // Replace old source with the new one we just collected into our array. 
        $source = implode($array, "\n"); 
        return $source; 
    } 
    
    function importpreprocess($category) {
        global $CFG;

        error("Sorry, importing this format is not yet implemented!", 
            "$CFG->wwwroot/mod/quiz/import.php?category=$category->id");
    }

    function exportpreprocess($category, $course, $lang = null) {
        global $CFG;
        
        require_once("{$CFG->libdir}/smarty/Smarty.class.php");
        
        // assign the language for the export: by parameter, SESSION, USER, or the default of 'en'
        if (is_null($lang)) {
            global $SESSION, $USER;
            $lang = empty($SESSION->lang) ? (empty($USER->lang) ? 'en' : $USER->lang) : $SESSION->lang;
        }
        $this->lang = $lang;
        
        return parent::exportpreprocess($category, $course);
    }
    
    
    function export_file_extension() {
        // override default type so extension is .xml
        
        return ".zip";
    }
    
    function get_qtype( $type_id ) {
        // translates question type code number into actual name
       <commit_msg>updated language detection<commit_after><?php  // $Id$
require_once("$CFG->dirroot/question/format/qti2/qt_common.php");
////////////////////////////////////////////////////////////////////////////
/// IMS QTI 2.0 FORMAT
///
/// HISTORY: created 28.01.2005      <EMAIL>
////////////////////////////////////////////////////////////////////////////

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

define('CLOZE_TRAILING_TEXT_ID', 9999999);

class qformat_qti2 extends qformat_default {
    
    var $lang;

    function provide_export() {
       return true;
    }
    
    function indent_xhtml($source, $indenter = ' ') { 
        // xml tidier-upper
        // (c) <NAME> http://ventionline.com
        
        // Remove all pre-existing formatting. 
        // Remove all newlines. 
        $source = str_replace("\n", '', $source); 
        $source = str_replace("\r", '', $source); 
        // Remove all tabs. 
        $source = str_replace("\t", '', $source); 
        // Remove all space after ">" and before "<". 
        $source = ereg_replace(">( )*", ">", $source); 
        $source = ereg_replace("( )*<", "<", $source); 
    
        // Iterate through the source. 
        $level = 0; 
        $source_len = strlen($source); 
        $pt = 0; 
        while ($pt < $source_len) { 
            if ($source{$pt} === '<') { 
                // We have entered a tag. 
                // Remember the point where the tag starts. 
                $started_at = $pt; 
                $tag_level = 1; 
                // If the second letter of the tag is "/", assume its an ending tag. 
                if ($source{$pt+1} === '/') { 
                    $tag_level = -1; 
                } 
                // If the second letter of the tag is "!", assume its an "invisible" tag. 
                if ($source{$pt+1} === '!') { 
                    $tag_level = 0; 
                } 
                // Iterate throught the source until the end of tag. 
                while ($source{$pt} !== '>') { 
                    $pt++; 
                } 
                // If the second last letter is "/", assume its a self ending tag. 
                if ($source{$pt-1} === '/') { 
                    $tag_level = 0; 
                } 
                $tag_lenght = $pt+1-$started_at; 
                 
                // Decide the level of indention for this tag. 
                // If this was an ending tag, decrease indent level for this tag.. 
                if ($tag_level === -1) { 
                    $level--; 
                } 
                // Place the tag in an array with proper indention. 
                $array[] = str_repeat($indenter, $level).substr($source, $started_at, $tag_lenght); 
                // If this was a starting tag, increase the indent level after this tag. 
                if ($tag_level === 1) { 
                    $level++; 
                } 
                // if it was a self closing tag, dont do shit. 
            } 
            // Were out of the tag. 
            // If next letter exists... 
            if (($pt+1) < $source_len) { 
                // ... and its not an "<". 
                if ($source{$pt+1} !== '<') { 
                    $started_at = $pt+1; 
                    // Iterate through the source until the start of new tag or until we reach the end of file. 
                    while ($source{$pt} !== '<' && $pt < $source_len) { 
                        $pt++; 
                    } 
                    // If we found a "<" (we didnt find the end of file) 
                    if ($source{$pt} === '<') { 
                        $tag_lenght = $pt-$started_at; 
                        // Place the stuff in an array with proper indention. 
                        $array[] = str_repeat($indenter, $level).substr($source, $started_at, $tag_lenght); 
                    } 
                // If the next tag is "<", just advance pointer and let the tag indenter take care of it. 
                } else { 
                    $pt++; 
                } 
            // If the next letter doesnt exist... Were done... well, almost.. 
            } else { 
                break; 
            } 
        } 
        // Replace old source with the new one we just collected into our array. 
        $source = implode($array, "\n"); 
        return $source; 
    } 
    
    function importpreprocess($category) {
        global $CFG;

        error("Sorry, importing this format is not yet implemented!", 
            "$CFG->wwwroot/mod/quiz/import.php?category=$category->id");
    }

    function exportpreprocess($category, $course, $lang = null) {
        global $CFG;
        
        require_once("{$CFG->libdir}/smarty/Smarty.class.php");
        
        // assign the language for the export: by parameter, SESSION, USER, or the default of 'en'
        if (is_null($lang)) {
            $lang = current_language();
        }
        $this->lang = $lang;
        
        return parent::exportpreprocess($category, $course);
    }
    
    
    function export_file_extension() {
        // override default type so extension is .xml
        
        return ".zip";
    }
    
    function get_qtype( $type_id ) {
        // translates question type code number into actual name
       
{'fraction_non_alphanumeric': 0.15494278746951792, 'fraction_numerical': 0.006377790283248921, 'mean_word_length': 1.2035544533994627, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3080202', 'n_tokens_mistral': 3040, 'n_tokens_neox': 2709, 'n_words': 840}