Task #1765 - newscorm/scorm.class.php: A new private static method detect_manifest_encoding() has been added. The purpose of this method is to determine the encoding of the input XML text (the manifest). Detection tries to resolve cases of missing encoding declaration or wrongly declared encoding.

skala
Ivan Tcholakov 14 years ago
parent c78a569a03
commit 6e5058467c
  1. 39
      main/newscorm/scorm.class.php

@ -215,6 +215,45 @@ class scorm extends learnpath {
return $this->manifest;
}
/**
* Detects the encoding of a given manifest (a xml-text).
* It is possible the encoding of the manifest to be wrongly declared or
* not to be declared at all. The proposed method tries to resolve these problems.
* @param string $xml The input xml-text.
* @return string The detected value of the input xml.
*/
private function detect_manifest_encoding(& $xml) {
if (api_is_valid_utf8($string)) {
return 'UTF-8';
}
if (preg_match(_PCRE_XML_ENCODING, $xml, $matches)) {
$declared_encoding = api_refine_encoding_id($matches[1]);
} else {
$declared_encoding = '';
}
if (!empty($declared_encoding) && !api_is_utf8($declared_encoding)) {
return $declared_encoding;
}
$test_string = '';
if (preg_match_all('/<langstring[^>]*>(.*)<\/langstring>/m', $xml, $matches)) {
$test_string = implode("\n", $matches[1]);
unset($matches);
}
if (preg_match_all('/<title[^>]*>(.*)<\/title>/m', $xml, $matches)) {
$test_string .= "\n".implode("\n", $matches[1]);
unset($matches);
}
if (empty($test_string)) {
$test_string = $xml;
}
return api_detect_encoding($test_string);
}
/**
* Import the scorm object (as a result from the parse_manifest function) into the database structure
* @param string Unique course code

Loading…
Cancel
Save