You are here

function qformat_qti2::xml_entitize in Quiz 6.5

Same name and namespace in other branches
  1. 6.6 includes/moodle/question/format/qti2/format.php \qformat_qti2::xml_entitize()

calls htmlspecialchars for each string field, to convert, for example, & to &

collections are processed recursively

Parameters

array $collection - an array or object or string:

3 calls to qformat_qti2::xml_entitize()
qformat_qti2::export_quiz in includes/moodle/question/format/qti2/format.php
exports a quiz (as opposed to exporting a category of questions)
qformat_qti2::get_cloze_answers_array in includes/moodle/question/format/qti2/format.php
gets a question's cloze answer objects as arrays containing only arrays and basic data types
qformat_qti2::writequestion in includes/moodle/question/format/qti2/format.php
Creates the export text for a question

File

includes/moodle/question/format/qti2/format.php, line 453

Class

qformat_qti2

Code

function xml_entitize(&$collection) {
  if (is_array($collection)) {
    foreach ($collection as $key => $var) {
      if (is_string($var)) {
        $collection[$key] = htmlspecialchars($var, ENT_COMPAT, 'UTF-8');
      }
      else {
        if (is_array($var) || is_object($var)) {
          $this
            ->xml_entitize($collection[$key]);
        }
      }
    }
  }
  else {
    if (is_object($collection)) {
      $vars = get_object_vars($collection);
      foreach ($vars as $key => $var) {
        if (is_string($var)) {
          $collection->{$key} = htmlspecialchars($var, ENT_COMPAT, 'UTF-8');
        }
        else {
          if (is_array($var) || is_object($var)) {
            $this
              ->xml_entitize($collection->{$key});
          }
        }
      }
    }
    else {
      if (is_string($collection)) {
        $collection = htmlspecialchars($collection, ENT_COMPAT, 'UTF-8');
      }
    }
  }
}