⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 format.php

📁 很棒的在线教学系统
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php  // $Id: format.php,v 1.16.2.1 2007/11/02 16:20:52 tjhunt Exp $/////////////////////////////////////////////////////////////////////////////                                                                       //// 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/** * @package questionbank * @subpackage importexport */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);}function qformat_webct_convert_formula($formula) {    // Remove empty space, as it would cause problems otherwise:    $formula = str_replace(' ', '', $formula);    // Remove paranthesis after e,E and *10**:    while (ereg('[0-9.](e|E|\\*10\\*\\*)\\([+-]?[0-9]+\\)', $formula, $regs)) {        $formula = str_replace(                $regs[0], ereg_replace('[)(]', '', $regs[0]), $formula);    }    // Replace *10** with e where possible    while (ereg(            '(^[+-]?|[^eE][+-]|[^0-9eE+-])[0-9.]+\\*10\\*\\*[+-]?[0-9]+([^0-9.eE]|$)',            $formula, $regs)) {        $formula = str_replace(                $regs[0], str_replace('*10**', 'e', $regs[0]), $formula);    }    // Replace other 10** with 1e where possible    while (ereg('(^|[^0-9.eE])10\\*\\*[+-]?[0-9]+([^0-9.eE]|$)', $formula, $regs)) {        $formula = str_replace(                $regs[0], str_replace('10**', '1e', $regs[0]), $formula);    }    // Replace all other base**exp with the PHP equivalent function pow(base,exp)    // (Pretty tricky to exchange an operator with a function)    while (2 == count($splits = explode('**', $formula, 2))) {        // Find $base        if (ereg('^(.*[^0-9.eE])?(([0-9]+(\\.[0-9]*)?|\\.[0-9]+)([eE][+-]?[0-9]+)?|\\{[^}]*\\})$',                $splits[0], $regs)) {            // The simple cases            $base = $regs[2];            $splits[0] = $regs[1];        } else if (ereg('\\)$', $splits[0])) {            // Find the start of this parenthesis            $deep = 1;            for ($i = 1 ; $deep ; ++$i) {                if (!ereg('^(.*[^[:alnum:]_])?([[:alnum:]_]*([)(])([^)(]*[)(]){'.$i.'})$',                        $splits[0], $regs)) {                    error("Parenthesis before ** is not properly started in $splits[0]**");                }                if ('(' == $regs[3]) {                    --$deep;                } else if (')' == $regs[3]) {                    ++$deep;                } else {                    error("Impossible character $regs[3] detected as parenthesis character");                }            }            $base = $regs[2];            $splits[0] = $regs[1];        } else {            error("Bad base before **: $splits[0]**");        }        // Find $exp (similar to above but a little easier)        if (ereg('^([+-]?(\\{[^}]\\}|([0-9]+(\\.[0-9]*)?|\\.[0-9]+)([eE][+-]?[0-9]+)?))(.*)',                $splits[1], $regs)) {            // The simple case            $exp = $regs[1];            $splits[1] = $regs[6];        } else if (ereg('^[+-]?[[:alnum:]_]*\\(', $splits[1])) {            // Find the end of the parenthesis            $deep = 1;            for ($i = 1 ; $deep ; ++$i) {                if (!ereg('^([+-]?[[:alnum:]_]*([)(][^)(]*){'.$i.'}([)(]))(.*)',                        $splits[1], $regs)) {                    error("Parenthesis after ** is not properly closed in **$splits[1]");                }                if (')' == $regs[3]) {                    --$deep;                } else if ('(' == $regs[3]) {                    ++$deep;                } else {                    error("Impossible character $regs[3] detected as parenthesis character");                }            }            $exp = $regs[1];            $splits[1] = $regs[4];        }        // Replace it!        $formula = "$splits[0]pow($base,$exp)$splits[1]";    }    // Nothing more is known to need to be converted    return $formula;}class qformat_webct extends qformat_default {    function provide_import() {      return true;    }    function readquestions ($lines) {        global $QTYPES ;        //  $qtypecalculated = new qformat_webct_modified_calculated_qtype();        $webctnumberregex =                '[+-]?([0-9]+(\\.[0-9]*)?|\\.[0-9]+)((e|E|\\*10\\*\\*)([+-]?[0-9]+|\\([+-]?[0-9]+\\)))?';        $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    //    $question = $this->defaultquestion();        foreach ($lines as $line) {            $nLineCounter++;            $line = iconv("Windows-1252","UTF-8",$line);            // Processing multiples lines strings            if (isset($questiontext) and is_string($questiontext)) {                if (ereg("^:",$line)) {                    $question->questiontext = addslashes(trim($questiontext));                    unset($questiontext);                }                 else {                    $questiontext .= str_replace('\:', ':', $line);                    continue;                }            }            if (isset($answertext) and is_string($answertext)) {                if (ereg("^:",$line)) {                    $answertext = addslashes(trim($answertext));                    $question->answer[$currentchoice] = $answertext;                    $question->subanswers[$currentchoice] = $answertext;                    unset($answertext);                }                 else {                    $answertext .= str_replace('\:', ':', $line);                    continue;                }            }            if (isset($responsetext) and is_string($responsetext)) {                if (ereg("^:",$line)) {                    $question->subquestions[$currentchoice] = addslashes(trim($responsetext));                    unset($responsetext);                }                 else {                    $responsetext .= str_replace('\:', ':', $line);                    continue;                }            }            if (isset($feedbacktext) and is_string($feedbacktext)) {                if (ereg("^:",$line)) {                   $question->feedback[$currentchoice] = addslashes(trim($feedbacktext));                    unset($feedbacktext);                }                 else {                    $feedbacktext .= str_replace('\:', ':', $line);                    continue;                }            }            if (isset($generalfeedbacktext) and is_string($generalfeedbacktext)) {                if (ereg("^:",$line)) {                   $question->tempgeneralfeedback= addslashes(trim($generalfeedbacktext));                    unset($generalfeedbacktext);                }                 else {                    $generalfeedbacktext .= 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) {                        $warnings[] = get_string("missingquestion", "quiz", $nQuestionStartLine);                        $QuestionOK = FALSE;                    }                    if (sizeof($question->answer) < 1) {  // a question must have at least 1 answer                       $errors[] = get_string("missinganswer", "quiz", $nQuestionStartLine);                       $QuestionOK = FALSE;                    }                    else {                        // Create empty feedback array                                              foreach ($question->answer as $key => $dataanswer) {                            if(!isset( $question->feedback[$key])){                                $question->feedback[$key] = '';                            }                        }                        // this tempgeneralfeedback allows the code to work with versions from 1.6 to 1.9                        // when question->generalfeedback is undefined, the webct feedback is added to each answer feedback                        if (isset($question->tempgeneralfeedback)){                            if (isset($question->generalfeedback)) {                                $question->generalfeedback = $question->tempgeneralfeedback;                            } else {                                  foreach ($question->answer as $key => $dataanswer) {                                    if ($question->tempgeneralfeedback !=''){                                        $question->feedback[$key] = $question->tempgeneralfeedback.'<br/>'.$question->feedback[$key];                                    }                                }                            }                            unset($question->tempgeneralfeedback);                           }                           $maxfraction = -1;                        $totalfraction = 0;                        foreach($question->fraction as $fraction) {                            if ($fraction > 0) {                                $totalfraction += $fraction;                            }                            if ($fraction > $maxfraction) {                                $maxfraction = $fraction;                            }                        }                        switch ($question->qtype) {                            case SHORTANSWER:                                if ($maxfraction != 1) {                                    $maxfraction = $maxfraction * 100;                                    $errors[] = "'$question->name': ".get_string("wronggrade", "quiz", $nLineCounter).' '.get_string("fractionsnomax", "quiz", $maxfraction);                                    $QuestionOK = FALSE;                                }                                break;                            case MULTICHOICE:                                if ($question->single) {                                    if ($maxfraction != 1) {                                        $maxfraction = $maxfraction * 100;                                        $errors[] = "'$question->name': ".get_string("wronggrade", "quiz", $nLineCounter).' '.get_string("fractionsnomax", "quiz", $maxfraction);                                        $QuestionOK = FALSE;                                    }                                } else {                                    $totalfraction = round($totalfraction,2);                                    if ($totalfraction != 1) {                                                                       $totalfraction = $totalfraction * 100;                                        $errors[] = "'$question->name': ".get_string("wronggrade", "quiz", $nLineCounter).' '.get_string("fractionsaddwrong", "quiz", $totalfraction);                                        $QuestionOK = FALSE;                                    }                                }                                break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -