Browse Source

Use Symfony's crawler when importing scorm

Angel Fernando Quiroz Campos 6 years ago
parent
commit
16a9195475
1 changed files with 10 additions and 6 deletions
  1. 10 6
      main/lp/scorm.class.php

+ 10 - 6
main/lp/scorm.class.php

@@ -1,6 +1,8 @@
 <?php
 /* For licensing terms, see /license.txt */
 
+use Symfony\Component\DomCrawler\Crawler;
+
 /**
  * Defines the scorm class, which is meant to contain the scorm items (nuclear elements).
  *
@@ -94,9 +96,11 @@ class scorm extends learnpath
 
             // UTF-8 is supported by DOMDocument class, this is for sure.
             $xml = api_utf8_encode_xml($xml, $this->manifest_encoding);
-            $doc = new DOMDocument();
-            $res = @$doc->loadXML($xml);
-            if ($res === false) {
+
+            $crawler = new Crawler();
+            $crawler->addXmlContent($xml);
+
+            if (!empty($xmlErrors)) {
                 if ($this->debug > 0) {
                     error_log('New LP - In scorm::parse_manifest() - Exception thrown when loading '.$file.' in DOMDocument');
                 }
@@ -105,10 +109,11 @@ class scorm extends learnpath
             }
 
             if ($this->debug > 1) {
-                error_log('New LP - Called  (encoding:'.$doc->xmlEncoding.' - saved: '.$this->manifest_encoding.')', 0);
+                error_log('New LP - Called  (encoding:'.$this->manifest_encoding.' - saved: '.$this->manifest_encoding.')', 0);
             }
 
-            $root = $doc->documentElement;
+            $root = $crawler->getNode(0);
+
             if ($root->hasAttributes()) {
                 $attributes = $root->attributes;
                 if ($attributes->length !== 0) {
@@ -220,7 +225,6 @@ class scorm extends learnpath
                     }
                 }
             }
-            unset($doc);
         // End parsing using PHP5 DOMXML methods.
         } else {
             if ($this->debug > 1) {