Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 11
Línea 37... Línea 37...
37
 * @copyright  1999 onwards Martin Dougiamas {@link http://moodle.com}
37
 * @copyright  1999 onwards Martin Dougiamas {@link http://moodle.com}
38
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39
 */
39
 */
40
class qtype_calculated extends question_type {
40
class qtype_calculated extends question_type {
41
    /**
41
    /**
42
     * @var string a placeholder is a letter, followed by almost any characters. (This should probably be restricted more.)
42
     * @var string a placeholder is a letter, followed by zero or more alphanum chars (as well as space, - and _ for readability).
43
     */
43
     */
44
    const PLACEHOLDER_REGEX_PART = '[[:alpha:]][^>} <`{"\']*';
44
    const PLACEHOLDER_REGEX_PART = '[[:alpha:]][[:alpha:][:digit:]\-_\s]*';
Línea 45... Línea 45...
45
 
45
 
46
    /**
46
    /**
47
     * @var string REGEXP for a placeholder, wrapped in its {...} delimiters, with capturing brackets around the name.
47
     * @var string REGEXP for a placeholder, wrapped in its {...} delimiters, with capturing brackets around the name.
48
     */
48
     */
Línea 1950... Línea 1950...
1950
    }
1950
    }
Línea 1951... Línea 1951...
1951
 
1951
 
1952
    // Validates the formula submitted from the question edit page.
1952
    // Validates the formula submitted from the question edit page.
1953
    // Returns false if everything is alright
1953
    // Returns false if everything is alright
1954
    // otherwise it constructs an error message.
1954
    // otherwise it constructs an error message.
1955
    // Strip away dataset names. Use 1.0 to catch illegal concatenation like {a}{b}.
1955
    // Strip away dataset names. Use 1.0 to remove valid names, so illegal names can be identified later.
Línea 1956... Línea 1956...
1956
    $formula = preg_replace(qtype_calculated::PLACEHODLER_REGEX, '1.0', $formula);
1956
    $formula = preg_replace(qtype_calculated::PLACEHODLER_REGEX, '1.0', $formula);
1957
 
1957
 
Línea -... Línea 1958...
-
 
1958
    // Strip away empty space and lowercase it.
-
 
1959
    $formula = strtolower(str_replace(' ', '', $formula));
1958
    // Strip away empty space and lowercase it.
1960
 
1959
    $formula = strtolower(str_replace(' ', '', $formula));
1961
    // Only mathematical operators are supported. Bitwise operators are not safe.
Línea -... Línea 1962...
-
 
1962
    // Note: In this context, ^ is a bitwise operator (exponents are represented by **).
1960
 
1963
    $safeoperatorchar = '-+/*%>:\~<?=!';
1961
    $safeoperatorchar = '-+/*%>:^\~<?=&|!'; /* */
1964
    $operatorornumber = "[{$safeoperatorchar}.0-9eE]";
1962
    $operatorornumber = "[{$safeoperatorchar}.0-9eE]";
1965
 
1963
 
1966
    // Validate mathematical functions in formula.
1964
    while (preg_match("~(^|[{$safeoperatorchar},(])([a-z0-9_]*)" .
1967
    while (preg_match("~(^|[{$safeoperatorchar},(])([a-z0-9_]*)" .