diff --git a/mod/imscp/locallib.php b/mod/imscp/locallib.php index 69206b10a5380..eed37bf3dadbf 100644 --- a/mod/imscp/locallib.php +++ b/mod/imscp/locallib.php @@ -117,11 +117,11 @@ function imscp_parse_structure($imscp, $context) { */ function imscp_parse_manifestfile($manifestfilecontents, $imscp, $context) { $doc = new DOMDocument(); - $oldentities = libxml_disable_entity_loader(true); + $oldentities = imscp_libxml_disable_entity_loader(true); if (!$doc->loadXML($manifestfilecontents, LIBXML_NONET)) { return null; } - libxml_disable_entity_loader($oldentities); + imscp_libxml_disable_entity_loader($oldentities); // We put this fake URL as base in order to detect path changes caused by xml:base attributes. $doc->documentURI = 'http://grrr/'; @@ -221,11 +221,11 @@ function imscp_recursive_href($manifestfilename, $imscp, $context) { } $doc = new DOMDocument(); - $oldentities = libxml_disable_entity_loader(true); + $oldentities = imscp_libxml_disable_entity_loader(true); if (!$doc->loadXML($manifestfile->get_content(), LIBXML_NONET)) { return null; } - libxml_disable_entity_loader($oldentities); + imscp_libxml_disable_entity_loader($oldentities); $xmlresources = $doc->getElementsByTagName('resource'); foreach ($xmlresources as $res) { @@ -274,6 +274,23 @@ function imscp_recursive_item($xmlitem, $level, $resources) { ); } +/** + * Wrapper for function libxml_disable_entity_loader() deprecated in PHP 8 + * + * Method was deprecated in PHP 8 and it shows deprecation message. However it is still + * required in the previous versions on PHP. While Moodle supports both PHP 7 and 8 we need to keep it. + * @see https://php.watch/versions/8.0/libxml_disable_entity_loader-deprecation + * + * @param bool $value + * @return bool + */ +function imscp_libxml_disable_entity_loader(bool $value): bool { + if (PHP_VERSION_ID < 80000) { + return (bool)libxml_disable_entity_loader($value); + } + return true; +} + /** * File browsing support class * diff --git a/mod/lti/locallib.php b/mod/lti/locallib.php index 6b1a16aef589b..8182d98407960 100644 --- a/mod/lti/locallib.php +++ b/mod/lti/locallib.php @@ -4384,7 +4384,7 @@ function lti_load_cartridge($url, $map, $propertiesmap = array()) { // TODO MDL-46023 Replace this code with a call to the new library. $origerrors = libxml_use_internal_errors(true); - $origentity = libxml_disable_entity_loader(true); + $origentity = lti_libxml_disable_entity_loader(true); libxml_clear_errors(); $document = new DOMDocument(); @@ -4396,7 +4396,7 @@ function lti_load_cartridge($url, $map, $propertiesmap = array()) { libxml_clear_errors(); libxml_use_internal_errors($origerrors); - libxml_disable_entity_loader($origentity); + lti_libxml_disable_entity_loader($origentity); if (count($errors) > 0) { $message = 'Failed to load cartridge.'; @@ -4481,3 +4481,20 @@ function lti_new_access_token($typeid, $scopes) { } + +/** + * Wrapper for function libxml_disable_entity_loader() deprecated in PHP 8 + * + * Method was deprecated in PHP 8 and it shows deprecation message. However it is still + * required in the previous versions on PHP. While Moodle supports both PHP 7 and 8 we need to keep it. + * @see https://php.watch/versions/8.0/libxml_disable_entity_loader-deprecation + * + * @param bool $value + * @return bool + */ +function lti_libxml_disable_entity_loader(bool $value): bool { + if (PHP_VERSION_ID < 80000) { + return (bool)libxml_disable_entity_loader($value); + } + return true; +} diff --git a/mod/lti/service.php b/mod/lti/service.php index d10e57d324e28..cc94023083465 100644 --- a/mod/lti/service.php +++ b/mod/lti/service.php @@ -70,13 +70,13 @@ } // TODO MDL-46023 Replace this code with a call to the new library. -$origentity = libxml_disable_entity_loader(true); +$origentity = lti_libxml_disable_entity_loader(true); $xml = simplexml_load_string($rawbody); if (!$xml) { - libxml_disable_entity_loader($origentity); + lti_libxml_disable_entity_loader($origentity); throw new Exception('Invalid XML content'); } -libxml_disable_entity_loader($origentity); +lti_libxml_disable_entity_loader($origentity); $body = $xml->imsx_POXBody; foreach ($body->children() as $child) {