Sfoglia il codice sorgente

Task #1765 - LP tool, cleaning files (12). Removing PHP4 specific, obsolete code.

Ivan Tcholakov 14 anni fa
parent
commit
aadc0c6271

+ 65 - 193
main/newscorm/scorm.class.php

@@ -77,57 +77,59 @@ class scorm extends learnpath {
 		if (empty($file)) {
 			// Get the path of the imsmanifest file.
 		}
-		if (is_file($file) and is_readable($file)) {
-			$v = substr(phpversion(), 0, 1);
-			if ($v == 4) {
-				if ($this->debug > 0) { error_log('In scorm::parse_manifest() - Parsing using PHP4 method', 0); }
-				$var = file_get_contents($file);
-				// Quick ugly hack to remove xml:id attributes from the file (break the system if xslt not installed).
-				$var = preg_replace('/xml:id=["\']id_\d{1,4}["\']/i', '', $var);
-				$doc = xmldoc($var);
-				//error_reporting(E_ALL);
-				//$doc = xmldocfile($file);
-				if (!empty($doc->encoding)) {
-					$this->manifest_encoding = strtoupper($doc->encoding);
-				}
-				if ($this->debug > 1) { error_log('New LP - Called xmldoc() (encoding:'.strtoupper($doc->encoding).' - saved: '.$this->manifest_encoding.')', 0); }
-				if (!$doc) {
-					if ($this->debug > 1) { error_log('New LP - File '.$file.' is not an XML file', 0); }
-					//$this->set_error_msg("File $file is not an XML file");
-					return null;
-				} else {
-					if ($this->debug > 1) { error_log('New LP - File '.$file.' is XML', 0); }
-					$root = $doc->root();
-					$attributes = $root->attributes();
-					for ($a = 0; $a < sizeof($attributes); $a++) {
+		if (is_file($file) && is_readable($file)) {
+
+			// Parsing using PHP5 DOMXML methods.
+
+			if ($this->debug > 0) { error_log('In scorm::parse_manifest() - Parsing using PHP5 method', 0); }
+			$doc = new DOMDocument();
+			$res = $doc->load($file);
+			if ($res === false) {
+				if ($this->debug > 0) { error_log('New LP - In scorm::parse_manifest() - Exception thrown when loading '.$file.' in DOMDocument', 0); }
+				// Throw exception?
+				return null;
+			}
+
+			if (!empty($doc->xmlEncoding)) {
+				$this->manifest_encoding = strtoupper($doc->xmlEncoding);
+			}
+			if ($this->debug > 1) { error_log('New LP - Called  (encoding:'.$doc->xmlEncoding.' - saved: '.$this->manifest_encoding.')', 0); }
+
+			$root = $doc->documentElement;
+			if ($root->hasAttributes()) {
+				$attributes = $root->attributes;
+				if ($attributes->length !== 0) {
+					foreach ($attributes as $attrib) {
 						// <manifest> element attributes
-						if ($attributes[$a]->type == XML_ATTRIBUTE_NODE) {
-							$this->manifest[$attributes[$a]->name] = $attributes[$a]->value;
-						}
+						$this->manifest[$attrib->name] = $attrib->value;
 					}
-					$this->manifest['name'] = $root->name;
-					$children = $root->children();
-					for($b = 0; $b < sizeof($children); $b++) {
+				}
+			}
+			$this->manifest['name'] = $root->tagName;
+			if ($root->hasChildNodes()) {
+				$children = $root->childNodes;
+				if ($children->length !== 0) {
+					foreach ($children as $child) {
 						// <manifest> element children (can be <metadata>, <organizations> or <resources> )
-						if ($children[$b]->type == XML_ELEMENT_NODE) {
-							switch($children[$b]->tagname) {
+						if ($child->nodeType == XML_ELEMENT_NODE) {
+							switch($child->tagName) {
 								case 'metadata':
 									// Parse items from inside the <metadata> element.
-									$this->metadata = new scormMetadata('manifest',$children[$b]);
+									$this->metadata = new scormMetadata('manifest',$child);
 									break;
 								case 'organizations':
 									// Contains the course structure - this element appears 1 and only 1 time in a package imsmanifest. It contains at least one 'organization' sub-element.
-									$orgs_attribs = $children[$b]->attributes();
-									for($c = 0; $c < sizeof($orgs_attribs); $c++) {
+									$orgs_attribs = $child->attributes;
+									foreach ($orgs_attribs as $orgs_attrib) {
 										// Attributes of the <organizations> element.
-										if ($orgs_attribs[$c]->type == XML_ATTRIBUTE_NODE) {
-											$this->manifest['organizations'][$orgs_attribs[$c]->name] = $orgs_attribs[$c]->value;
+										if ($orgs_attrib->nodeType == XML_ATTRIBUTE_NODE) {
+											$this->manifest['organizations'][$orgs_attrib->name] = $orgs_attrib->value;
 										}
 									}
-									$orgs_nodes = $children[$b]->children();
+									$orgs_nodes = $child->childNodes;
 									$i = 0;
 									$found_an_org = false;
-									foreach ($orgs_nodes as $c => $dummy) {
+									foreach ($orgs_nodes as $orgnode) {
 										// <organization> elements - can contain <item>, <metadata> and <title>
 										// Here we are at the 'organization' level. There might be several organization tags but
 										// there is generally only one.
@@ -136,24 +138,21 @@ class scorm extends learnpath {
 										// -item (may contain other item tags or may appear several times inside organization)
 										// -metadata (relative to the organization)
 										$found_an_org = false;
-										$orgnode =& $orgs_nodes[$c];
-										switch ($orgnode->type) {
+										switch ($orgnode->nodeType) {
 											case XML_TEXT_NODE:
 												// Ignore here.
 												break;
 											case XML_ATTRIBUTE_NODE:
-												// just in case ther would be interesting attributes inside the organization tag. There shouldn't
+												// Just in case there would be interesting attributes inside the organization tag. There shouldn't
 												// as this is a node-level, not a data level.
 												//$manifest['organizations'][$i][$orgnode->name] = $orgnode->value;
 												//$found_an_org = true;
 												break;
 											case XML_ELEMENT_NODE:
 												// <item>, <metadata> or <title> (or attributes)
-												$organizations_attributes = $orgnode->attributes();
-												foreach($organizations_attributes as $d1 => $dummy) {
-													//$manifest['organizations'][$i]['attributes'][$organizations_attributes[$d1]->name] = $organizations_attributes[$d1]->value;
-													//$found_an_org = true;
-													$this->organizations_att[$organizations_attributes[$d1]->name] = $organizations_attributes[$d1]->value;
+												$organizations_attributes = $orgnode->attributes;
+												foreach ($organizations_attributes as $orgs_attr) {
+													$this->organizations_att[$orgs_attr->name] = $orgs_attr->value;
 												}
 												$oOrganization = new scormOrganization('manifest', $orgnode, $this->manifest_encoding);
 												if ($oOrganization->identifier != '') {
@@ -174,26 +173,23 @@ class scorm extends learnpath {
 									}
 									break;
 								case 'resources':
-									$resources_attribs = $children[$b]->attributes();
-									for ($c = 0; $c < sizeof($resources_attribs); $c++) {
-										if ($resources_attribs[$c]->type == XML_ATTRIBUTE_NODE) {
-											$this->manifest['resources'][$resources_attribs[$c]->name] = $resources_attribs[$c]->value;
+									if ($child->hasAttributes()) {
+										$resources_attribs = $child->attributes;
+										foreach ($resources_attribs as $res_attr) {
+											if ($res_attr->type == XML_ATTRIBUTE_NODE) {
+												$this->manifest['resources'][$res_attr->name] = $res_attr->value;
+											}
 										}
 									}
-									$resources_nodes = $children[$b]->children();
-									$i = 0;
-									foreach ($resources_nodes as $c => $dummy) {
-										/*
-										$my_res = scorm::parse_items($resources_nodes[$c]);
-										scorm::parse_items_get_refurls($resources_nodes[$c], $refurls);
-										if (count($my_res) > 0) {
-											$manifest['resources'][$i] = $my_res;
-										}
-										*/
-										$oResource = new scormResource('manifest', $resources_nodes[$c]);
-										if ($oResource->identifier != '') {
-											$this->resources[$oResource->identifier] = $oResource;
-											$i++;
+									if ($child->hasChildNodes()) {
+										$resources_nodes = $child->childNodes;
+										$i = 0;
+										foreach ($resources_nodes as $res_node) {
+											$oResource = new scormResource('manifest', $res_node);
+											if ($oResource->identifier != '') {
+												$this->resources[$oResource->identifier] = $oResource;
+												$i++;
+											}
 										}
 									}
 									// Contains links to physical resources.
@@ -205,141 +201,17 @@ class scorm extends learnpath {
 						}
 					}
 				}
-				unset($doc);
-			} elseif ($v==5) {
-				if ($this->debug > 0) { error_log('In scorm::parse_manifest() - Parsing using PHP5 method', 0); }
-				$doc = new DOMDocument();
-				$res = $doc->load($file);
-				if ($res === false) {
-					if ($this->debug > 0) { error_log('New LP - In scorm::parse_manifest() - Exception thrown when loading '.$file.' in DOMDocument', 0); }
-					// Throw exception?
-					return null;
-				}
-
-				if (!empty($doc->xmlEncoding)) {
-					$this->manifest_encoding = strtoupper($doc->xmlEncoding);
-				}
-				if ($this->debug > 1) { error_log('New LP - Called  (encoding:'.$doc->xmlEncoding.' - saved: '.$this->manifest_encoding.')', 0); }
-
-				$root = $doc->documentElement;
-				if ($root->hasAttributes()) {
-					$attributes = $root->attributes;
-					if ($attributes->length !== 0) {
-						foreach($attributes as $attrib) {
-							// <manifest> element attributes
-							$this->manifest[$attrib->name] = $attrib->value;
-						}
-					}
-				}
-				$this->manifest['name'] = $root->tagName;
-				if ($root->hasChildNodes()) {
-					$children = $root->childNodes;
-					if ($children->length !== 0) {
-						foreach($children as $child) {
-							// <manifest> element children (can be <metadata>, <organizations> or <resources> )
-							if ($child->nodeType == XML_ELEMENT_NODE) {
-								switch($child->tagName) {
-									case 'metadata':
-										// Parse items from inside the <metadata> element.
-										$this->metadata = new scormMetadata('manifest',$child);
-										break;
-									case 'organizations':
-										// Contains the course structure - this element appears 1 and only 1 time in a package imsmanifest. It contains at least one 'organization' sub-element.
-										$orgs_attribs = $child->attributes;
-										foreach($orgs_attribs as $orgs_attrib) {
-											// Attributes of the <organizations> element.
-											if ($orgs_attrib->nodeType == XML_ATTRIBUTE_NODE) {
-												$this->manifest['organizations'][$orgs_attrib->name] = $orgs_attrib->value;
-											}
-										}
-										$orgs_nodes = $child->childNodes;
-										$i = 0;
-										$found_an_org = false;
-										foreach ($orgs_nodes as $orgnode) {
-											// <organization> elements - can contain <item>, <metadata> and <title>
-											// Here we are at the 'organization' level. There might be several organization tags but
-											// there is generally only one.
-											// There are generally three children nodes we are looking for inside and organization:
-											// -title
-											// -item (may contain other item tags or may appear several times inside organization)
-											// -metadata (relative to the organization)
-											$found_an_org = false;
-											switch($orgnode->nodeType) {
-												case XML_TEXT_NODE:
-													// Ignore here.
-													break;
-												case XML_ATTRIBUTE_NODE:
-													// Just in case there would be interesting attributes inside the organization tag. There shouldn't
-													// as this is a node-level, not a data level.
-													//$manifest['organizations'][$i][$orgnode->name] = $orgnode->value;
-													//$found_an_org = true;
-													break;
-												case XML_ELEMENT_NODE:
-													// <item>, <metadata> or <title> (or attributes)
-													$organizations_attributes = $orgnode->attributes;
-													foreach ($organizations_attributes as $orgs_attr) {
-														$this->organizations_att[$orgs_attr->name] = $orgs_attr->value;
-													}
-													$oOrganization = new scormOrganization('manifest',$orgnode,$this->manifest_encoding);
-													if ($oOrganization->identifier != '') {
-														$name = $oOrganization->get_name();
-														if (empty($name)) {
-															// If the org title is empty, use zip file name.
-															$myname = $this->zipname;
-															if ($this->lastzipnameindex != 0) {
-																$myname = $myname + $this->lastzipnameindex;
-																$this->lastzipnameindex++;
-															}
-															$oOrganization->set_name($this->zipname);
-														}
-														$this->organizations[$oOrganization->identifier] = $oOrganization;
-													}
-													break;
-											}
-										}
-										break;
-									case 'resources':
-										if ($child->hasAttributes()) {
-											$resources_attribs = $child->attributes;
-											foreach ($resources_attribs as $res_attr) {
-												if ($res_attr->type == XML_ATTRIBUTE_NODE) {
-													$this->manifest['resources'][$res_attr->name] = $res_attr->value;
-												}
-											}
-										}
-										if ($child->hasChildNodes()) {
-											$resources_nodes = $child->childNodes;
-											$i = 0;
-											foreach ($resources_nodes as $res_node) {
-												$oResource = new scormResource('manifest', $res_node);
-												if ($oResource->identifier != '') {
-													$this->resources[$oResource->identifier] = $oResource;
-													$i++;
-												}
-											}
-										}
-										// Contains links to physical resources.
-										break;
-									case 'manifest':
-										// Only for sub-manifests.
-										break;
-								}
-							}
-						}
-					}
-				}
-				unset($doc);
-			} else {
-				if ($this->debug > 0) { error_log('In scorm::parse_manifest() - PHP version is not 4 nor 5, cannot parse', 0); }
-				$this->set_error_msg("Parsing impossible because PHP version is not 4 nor 5");
-				return null;
 			}
+			unset($doc);
+
+			// End parsing using PHP5 DOMXML methods.
+
 		} else {
 			if ($this->debug > 1) { error_log('New LP - Could not open/read file '.$file, 0); }
 			$this->set_error_msg("File $file could not be read");
 			return null;
 		}
-		// TODO: close the DOM handler
+		// TODO: Close the DOM handler.
 		return $this->manifest;
 	}
 

+ 87 - 186
main/newscorm/scormItem.class.php

@@ -35,82 +35,92 @@ class scormItem extends learnpathItem {
 	 * @param	string	Type of construction needed ('db' or 'manifest', default = 'manifest')
 	 * @param	mixed	Depending on the type given, DB id for the lp_item or reference to the DOM element
 	 */
-	public function __construct($type='manifest',&$element) {
+	public function __construct($type = 'manifest', &$element) {
 		if (isset($element)) {
 
-			$v = substr(phpversion(), 0, 1);
-			if ($v == 4) {
-				switch ($type) {
-					case 'db':
-						parent::__construct($element,api_get_user_id());
-						$this->scorm_contact = false;
-						// TODO: Implement this way of metadata object creation.
-						return false;
-					case 'manifest': // Do the same as the default.
-					default:
-					 	// if ($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function.
-					 	$children = $element->children();
-						foreach($children as $a => $dummy) {
-					 		$child =& $children[$a];
-					 		switch($child->type) {
-					 			case XML_ELEMENT_NODE:
-									switch($child->tagname) {
-					 					case 'title':
-							 				$tmp_children = $child->children();
-							 				if (count($tmp_children) == 1 && $tmp_children[0]->content != '') {
-							 					$this->title = $tmp_children[0]->content;
-							 				}
-							 				break;
-					 					case 'maxtimeallowed':
-							 				$tmp_children = $child->children();
-							 				if (count($tmp_children) == 1 && $tmp_children[0]->content != '') {
-							 					$this->max_time_allowed = $tmp_children[0]->content;
-							 				}
-							 				break;
-										case 'prerequisites':
-							 				$tmp_children = $child->children();
-							 				if (count($tmp_children) == 1 && $tmp_children[0]->content != '') {
-							 					$this->prereq_string = $tmp_children[0]->content;
-							 				}
-							 				break;
-										case 'timelimitaction':
-							 				$tmp_children = $child->children();
-							 				if (count($tmp_children) == 1 && $tmp_children[0]->content != '') {
-							 					$this->timelimitaction = $tmp_children[0]->content;
-							 				}
-							 				break;
-										case 'datafromlms':
-							 				$tmp_children = $child->children();
-							 				if (count($tmp_children) == 1 && $tmp_children[0]->content != '') {
-							 					$this->datafromlms = $tmp_children[0]->content;
-							 				}
-							 				break;
-										case 'masteryscore':
-							 				$tmp_children = $child->children();
-							 				if (count($tmp_children) == 1 && $tmp_children[0]->content != '') {
-							 					$this->mastery_score = $tmp_children[0]->content;
-							 				}
-							 				break;
-					 					case 'item':
-					 						$oItem = new scormItem('manifest', $child);
-					 						if ($oItem->identifier != ''){
-					 							$this->sub_items[$oItem->identifier] = $oItem;
-					 						}
-											break;
-					 					case 'metadata':
-					 						$this->metadata = new scormMetadata('manifest', $child);
-					 						break;
-					 				}
-					 				break;
-					 			case XML_TEXT_NODE:
-					 				// This case is actually treated by looking into ELEMENT_NODEs above.
-					 				break;
-					 		}
-					 	}
-					 	$attributes = $element->attributes();
+			// Parsing using PHP5 DOMXML methods.
+
+			switch ($type) {
+				case 'db':
+					parent::__construct($element,api_get_user_id());
+					$this->scorm_contact = false;
+					// TODO: Implement this way of metadata object creation.
+					return false;
+				case 'manifest': // Do the same as the default.
+				default:
+				 	//if ($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function.
+				 	$children = $element->childNodes;
+					foreach ($children as $child) {
+				 		switch ($child->nodeType) {
+				 			case XML_ELEMENT_NODE:
+								switch ($child->tagName) {
+				 					case 'title':
+						 				$tmp_children = $child->childNodes;
+						 				if ($tmp_children->length == 1 && $child->firstChild->nodeValue != '') {
+						 					$this->title = $child->firstChild->nodeValue;
+						 				}
+						 				break;
+						 			case 'max_score':
+					 					if ($tmp_children->length == 1 && $child->firstChild->nodeValue != '') {
+						 					$this->max_score = $child->firstChild->nodeValue;
+						 				}
+						 				break;
+				 					case 'maxtimeallowed':
+				 					case 'adlcp:maxtimeallowed':
+						 				$tmp_children = $child->childNodes;
+						 				if ($tmp_children->length == 1 && $child->firstChild->nodeValue != '') {
+						 					$this->max_time_allowed = $child->firstChild->nodeValue;
+						 				}
+						 				break;
+									case 'prerequisites':
+									case 'adlcp:prerequisites':
+						 				$tmp_children = $child->childNodes;
+						 				if ($tmp_children->length == 1 && $child->firstChild->nodeValue != '') {
+						 					$this->prereq_string = $child->firstChild->nodeValue;
+						 				}
+						 				break;
+									case 'timelimitaction':
+									case 'adlcp:timelimitaction':
+						 				$tmp_children = $child->childNodes;
+						 				if ($tmp_children->length == 1 && $child->firstChild->nodeValue != '') {
+						 					$this->timelimitaction = $child->firstChild->nodeValue;
+						 				}
+						 				break;
+									case 'datafromlms':
+									case 'adlcp:datafromlms':
+									case 'adlcp:launchdata': //in some cases (Wouters)
+						 				$tmp_children = $child->childNodes;
+						 				if ($tmp_children->length == 1 && $child->firstChild->nodeValue != '') {
+						 					$this->datafromlms = $child->firstChild->nodeValue;
+						 				}
+						 				break;
+									case 'masteryscore':
+									case 'adlcp:masteryscore':
+						 				$tmp_children = $child->childNodes;
+						 				if ($tmp_children->length == 1 && $child->firstChild->nodeValue != '') {
+						 					$this->mastery_score = $child->firstChild->nodeValue;
+						 				}
+						 				break;
+				 					case 'item':
+				 						$oItem = new scormItem('manifest',$child);
+				 						if ($oItem->identifier != '') {
+				 							$this->sub_items[$oItem->identifier] = $oItem;
+				 						}
+										break;
+				 					case 'metadata':
+				 						$this->metadata = new scormMetadata('manifest', $child);
+				 						break;
+				 				}
+				 				break;
+				 			case XML_TEXT_NODE:
+				 				// This case is actually treated by looking into ELEMENT_NODEs above.
+				 				break;
+				 		}
+				 	}
+				 	if ($element->hasAttributes()) {
+					 	$attributes = $element->attributes;
 					 	//$keep_href = '';
-					 	foreach ($attributes as $a1 => $dummy) {
-					 		$attrib =& $attributes[$a1];
+					 	foreach ($attributes as $attrib) {
 					 		switch($attrib->name){
 					 			case 'identifier':
 					 				$this->identifier = $attrib->value;
@@ -126,121 +136,12 @@ class scormItem extends learnpathItem {
 					 				break;
 					 		}
 					 	}
-						return true;
+				 	}
+					return true;
+			}
 
-				}
-			} elseif ($v == 5) {
-				// Parsing using PHP5 DOMXML methods.
-				switch ($type) {
-					case 'db':
-						parent::__construct($element,api_get_user_id());
-						$this->scorm_contact = false;
-						//TODO: Implement this way of metadata object creation.
-						return false;
-					case 'manifest': // Do the same as the default.
-					default:
-					 	//if ($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function.
-					 	$children = $element->childNodes;
-						foreach ($children as $child) {
-					 		switch ($child->nodeType) {
-					 			case XML_ELEMENT_NODE:
-									switch ($child->tagName) {
-					 					case 'title':
-							 				$tmp_children = $child->childNodes;
-							 				//if (count($tmp_children) == 1 && $tmp_children[0]->textContent != '') {
-							 				if ($tmp_children->length == 1 && $child->firstChild->nodeValue != '') {
-							 					$this->title = $child->firstChild->nodeValue;
-							 				}
-							 				break;
-							 			case 'max_score':
-						 					if ($tmp_children->length == 1 && $child->firstChild->nodeValue != '') {
-							 					$this->max_score = $child->firstChild->nodeValue;
-							 				}
-							 				break;
-					 					case 'maxtimeallowed':
-					 					case 'adlcp:maxtimeallowed':
-							 				$tmp_children = $child->childNodes;
-							 				//if (count($tmp_children) == 1 && $tmp_children[0]->textContent != '') {
-							 				if ($tmp_children->length == 1 && $child->firstChild->nodeValue != '') {
-							 					$this->max_time_allowed = $child->firstChild->nodeValue;
-							 				}
-							 				break;
-										case 'prerequisites':
-										case 'adlcp:prerequisites':
-							 				$tmp_children = $child->childNodes;
-							 				//if (count($tmp_children) == 1 && $tmp_children[0]->textContent != '') {
-							 				if ($tmp_children->length == 1 && $child->firstChild->nodeValue != '') {
-							 					$this->prereq_string = $child->firstChild->nodeValue;
-							 				}
-							 				break;
-										case 'timelimitaction':
-										case 'adlcp:timelimitaction':
-							 				$tmp_children = $child->childNodes;
-							 				//if (count($tmp_children) == 1 && $tmp_children[0]->textContent != '') {
-							 				if ($tmp_children->length == 1 && $child->firstChild->nodeValue != '') {
-							 					$this->timelimitaction = $child->firstChild->nodeValue;
-							 				}
-							 				break;
-										case 'datafromlms':
-										case 'adlcp:datafromlms':
-										case 'adlcp:launchdata': //in some cases (Wouters)
-							 				$tmp_children = $child->childNodes;
-							 				//if (count($tmp_children) == 1 && $tmp_children[0]->textContent != '') {
-							 				if ($tmp_children->length == 1 && $child->firstChild->nodeValue != '') {
-							 					$this->datafromlms = $child->firstChild->nodeValue;
-							 				}
-							 				break;
-										case 'masteryscore':
-										case 'adlcp:masteryscore':
-							 				$tmp_children = $child->childNodes;
-							 				//if (count($tmp_children) == 1 && $tmp_children[0]->textContent != '') {
-							 				if ($tmp_children->length == 1 && $child->firstChild->nodeValue != '') {
-							 					$this->mastery_score = $child->firstChild->nodeValue;
-							 				}
-							 				break;
-					 					case 'item':
-					 						$oItem = new scormItem('manifest',$child);
-					 						if ($oItem->identifier != '') {
-					 							$this->sub_items[$oItem->identifier] = $oItem;
-					 						}
-											break;
-					 					case 'metadata':
-					 						$this->metadata = new scormMetadata('manifest', $child);
-					 						break;
-					 				}
-					 				break;
-					 			case XML_TEXT_NODE:
-					 				// This case is actually treated by looking into ELEMENT_NODEs above.
-					 				break;
-					 		}
-					 	}
-					 	if ($element->hasAttributes()) {
-						 	$attributes = $element->attributes;
-						 	//$keep_href = '';
-						 	foreach ($attributes as $attrib) {
-						 		switch($attrib->name){
-						 			case 'identifier':
-						 				$this->identifier = $attrib->value;
-						 				break;
-						 			case 'identifierref':
-						 				$this->identifierref = $attrib->value;
-						 				break;
-						 			case 'isvisible':
-						 				$this->isvisible = $attrib->value;
-						 				break;
-						 			case 'parameters':
-						 				$this->parameters = $attrib->value;
-						 				break;
-						 		}
-						 	}
-					 	}
-						return true;
+			// End parsing using PHP5 DOMXML methods.
 
-				}
-			} else {
-				// Cannot parse because not PHP4 nor PHP5... We should not even be here anyway...
-				return false;
-			}
 		}
 		return false;
 	}

+ 68 - 151
main/newscorm/scormMetadata.class.php

@@ -28,160 +28,77 @@ class scormMetadata {
 	 */
 	public function __construct($type = 'manifest', &$element) {
 		if (isset($element)) {
-			$v = substr(phpversion(), 0, 1);
-			if ($v == 4) {
-				switch ($type) {
-					case 'db':
-						// TODO: Implement this way of metadata object creation
-						return false;
-						//break;
-					case 'manifest': // Do the same as the default.
-					 	//if ($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function.
-					 	$children = $element->children();
-						foreach ($children as $a => $dummy) {
-					 		$child =& $children[$a];
-					 		switch ($child->type) {
-					 			case XML_ELEMENT_NODE:
-									// Could be 'lom', 'schema', 'schemaversion' or 'location'.
-					 				switch ($child->tagname) {
-					 					case 'lom':
-					 						$childchildren = $child->children();
-					 						foreach ($childchildren as $index => $dummy) {
-					 							$my_elem = $childchildren[$index];
-					 							// There is generally only one child here.
-					 							//$this->lom[] = $my_elem->content;
-					 							$this->lom = $my_elem->content;
-					 						}
-					 						break;
-					 					case 'schema':
-					 						$childchildren = $child->children();
-					 						foreach ($childchildren as $index => $dummy) {
-					 							$my_elem = $childchildren[$index];
-					 							// There is generally only one child here.
-					 							//$this->schema[] = $my_elem->content;
-					 							$this->schema = $my_elem->content;
-					 						}
-					 						break;
-					 					case 'schemaversion':
-					 						$childchildren = $child->children();
-					 						foreach ($childchildren as $index => $dummy) {
-					 							$my_elem = $childchildren[$index];
-					 							// There is generally only one child here.
-					 							//$this->schemaversion[] = $my_elem->content;
-					 							$this->schemaversion = $my_elem->content;
-					 						}
-					 						break;
-					 					case 'location':
-					 						$childchildren = $child->children();
-					 						foreach ($childchildren as $index => $dummy) {
-					 							$my_elem = $childchildren[$index];
-					 							// There is generally only one child here.
-					 							//$this->location[] = $my_elem->content;
-					 							$this->location = $my_elem->content;
-					 						}
-					 						break;
-					 				}
-					 				break;
-					 			case XML_TEXT_NODE:
-					 				if (trim($child->content) != '') {
-					 					if (count($children == 1)) {
-					 						// If this is the only child at this level and it is a content... save differently.
-					 						$this->text = $child->content;
-					 					} else {
-					 						$this->text[$element->tagname] = $child->content;
-					 					}
-					 				}
-					 				break;
-					 		}
-					 	}
-					 	$attributes = $element->attributes();
-					 	//$keep_href = '';
-					 	if (is_array($attributes)) {
-						 	foreach ($attributes as $a1 => $dummy) {
-						 		$attrib =& $attributes[$a1];
-						 		if (trim($attrib->value) != '') {
-						 			$this->attribs[$attrib->name] = $attrib->value;
-						 		}
-						 	}
-					 	}
-						return true;
-						//break;
-				}
-			} elseif ($v == 5) {
-				// Parsing using PHP5 DOMXML methods.
-				switch ($type) {
-					case 'db':
-						// TODO: Implement this way of metadata object creation.
-						return false;
-						//break;
-					case 'manifest': // Do the same as the default.
-					 	$children = $element->childNodes;
-						foreach ($children as $child) {
-					 		switch ($child->nodeType) {
-					 			case XML_ELEMENT_NODE:
-									// Could be 'lom','schema','schemaversion' or 'location'.
-					 				switch ($child->tagName) {
-					 					case 'lom':
-					 						$childchildren = $child->childNodes;
-					 						foreach ($childchildren as $childchild) {
-					 							//$this->lom = $childchild->textContent;
-					 							$this->lom = $childchild->nodeValue;
-					 						}
-					 						break;
-					 					case 'schema':
-					 						$childchildren = $child->childNodes;
-					 						foreach ($childchildren as $childchild) {
-					 							// There is generally only one child here.
-					 							//$this->schema = $childchildren[$index]->textContent;
-					 							$this->schema = $childchild->nodeValue;
-					 						}
-					 						break;
-					 					case 'schemaversion':
-					 						$childchildren = $child->childNodes;
-					 						foreach ($childchildren as $childchild) {
-					 							// There is generally only one child here.
-					 							//$this->schemaversion = $childchildren[$index]->textContent;
-					 							$this->schemaversion = $childchild->nodeValue;
-					 						}
-					 						break;
-					 					case 'location':
-					 						$childchildren = $child->childNodes;
-					 						foreach ($childchildren as $childchild) {
-					 							// There is generally only one child here.
-					 							//$this->location = $childchildren[$index]->textContent;
-					 							$this->location = $childchild->nodeValue;
-					 						}
-					 						break;
-					 				}
-					 				break;
-					 			case XML_TEXT_NODE:
-					 				if (trim($child->textContent) != '') {
-					 					if (count($children == 1)) {
-					 						// If this is the only child at this level and it is a content... save differently.
-					 						$this->text = $child->textContent;
-					 					} else {
-					 						$this->text[$element->tagName] = $child->textContent;
-					 					}
-					 				}
-					 				break;
+
+			// Parsing using PHP5 DOMXML methods.
+
+			switch ($type) {
+				case 'db':
+					// TODO: Implement this way of metadata object creation.
+					return false;
+					//break;
+				case 'manifest': // Do the same as the default.
+				 	$children = $element->childNodes;
+					foreach ($children as $child) {
+				 		switch ($child->nodeType) {
+				 			case XML_ELEMENT_NODE:
+								// Could be 'lom', 'schema', 'schemaversion' or 'location'.
+				 				switch ($child->tagName) {
+				 					case 'lom':
+				 						$childchildren = $child->childNodes;
+				 						foreach ($childchildren as $childchild) {
+				 							$this->lom = $childchild->nodeValue;
+				 						}
+				 						break;
+				 					case 'schema':
+				 						$childchildren = $child->childNodes;
+				 						foreach ($childchildren as $childchild) {
+				 							// There is generally only one child here.
+				 							$this->schema = $childchild->nodeValue;
+				 						}
+				 						break;
+				 					case 'schemaversion':
+				 						$childchildren = $child->childNodes;
+				 						foreach ($childchildren as $childchild) {
+				 							// There is generally only one child here.
+				 							$this->schemaversion = $childchild->nodeValue;
+				 						}
+				 						break;
+				 					case 'location':
+				 						$childchildren = $child->childNodes;
+				 						foreach ($childchildren as $childchild) {
+				 							// There is generally only one child here.
+				 							$this->location = $childchild->nodeValue;
+				 						}
+				 						break;
+				 				}
+				 				break;
+				 			case XML_TEXT_NODE:
+				 				if (trim($child->textContent) != '') {
+				 					if (count($children == 1)) {
+				 						// If this is the only child at this level and it is a content... save differently.
+				 						$this->text = $child->textContent;
+				 					} else {
+				 						$this->text[$element->tagName] = $child->textContent;
+				 					}
+				 				}
+				 				break;
+				 		}
+				 	}
+				 	$attributes = $element->attributes;
+				 	//$keep_href = '';
+				 	if (is_array($attributes)) {
+					 	foreach ($attributes as $attrib) {
+					 		if (trim($attrib->value) != ''){
+					 			$this->attribs[$attrib->name] = $attrib->value;
 					 		}
 					 	}
-					 	$attributes = $element->attributes;
-					 	//$keep_href = '';
-					 	if (is_array($attributes)) {
-						 	foreach ($attributes as $attrib) {
-						 		if (trim($attrib->value) != ''){
-						 			$this->attribs[$attrib->name] = $attrib->value;
-						 		}
-						 	}
-					 	}
-						return true;
-						//break;
-				}
-			} else {
-				// Cannot parse because not PHP4 nor PHP5... We should not even be here anyway...
-				return false;
+				 	}
+					return true;
+					//break;
 			}
+
+			// End parsing using PHP5 DOMXML methods.
+
 		}
 		return false;
 	}

+ 45 - 96
main/newscorm/scormOrganization.class.php

@@ -16,6 +16,7 @@ class scormOrganization {
 	public $title = '';
 	public $items = array();
 	public $metadata;
+
 	/**
 	 * Class constructor. Depending of the type of construction called ('db' or 'manifest'), will create a scormOrganization
 	 * object from database records or from the DOM element given as parameter
@@ -24,46 +25,46 @@ class scormOrganization {
 	 */
 	public function __construct($type = 'manifest', &$element, $scorm_charset = 'UTF-8') {
 		if (isset($element))	{
-			$v = substr(phpversion(), 0, 1);
-			if ($v == 4) {
-				switch ($type) {
-					case 'db':
-						// TODO: Implement this way of metadata object creation
-						return false;
-					case 'manifest': // Do the same as the default.
-					default:
-					 	//if ($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function
-					 	$children = $element->children();
-						foreach ($children as $a => $dummy) {
-					 		$child =& $children[$a];
-					 		switch ($child->type) {
-					 			case XML_ELEMENT_NODE:
-									switch ($child->tagname) {
-					 					case 'item':
-					 						$oItem = new scormItem('manifest', $child);
-					 						if ($oItem->identifier != '') {
-												$this->items[$oItem->identifier] = $oItem;
-					 						}
-											break;
-					 					case 'metadata':
-					 						$this->metadata = new scormMetadata('manifest', $child);
-					 						break;
-					 					case 'title':
-							 				$tmp_children = $child->children();
-							 				if (count($tmp_children) == 1 && $tmp_children[0]->content != '') {
-							 					$this->title = $tmp_children[0]->content;
-							 				}
-							 				break;
-					 				}
-					 				break;
-					 			case XML_TEXT_NODE:
-					 				break;
-					 		}
-					 	}
-					 	$attributes = $element->attributes();
+
+			// Parsing using PHP5 DOMXML methods.
+
+			switch ($type) {
+				case 'db':
+					// TODO: Implement this way of metadata object creation.
+					return false;
+				case 'manifest': // Do the same as the default.
+				default:
+				 	//if ($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function.
+				 	$children = $element->childNodes;
+					foreach ($children as $child) {
+				 		switch ($child->nodeType) {
+				 			case XML_ELEMENT_NODE:
+								switch ($child->tagName) {
+				 					case 'item':
+				 						$oItem = new scormItem('manifest', $child);
+				 						if ($oItem->identifier != '') {
+											$this->items[$oItem->identifier] = $oItem;
+				 						}
+										break;
+				 					case 'metadata':
+				 						$this->metadata = new scormMetadata('manifest', $child);
+				 						break;
+				 					case 'title':
+						 				$tmp_children = $child->childNodes;
+						 				if ($tmp_children->length == 1 && $child->firstChild->nodeValue != '') {
+						 					$this->title = html_entity_decode(html_entity_decode($child->firstChild->nodeValue, ENT_QUOTES, $scorm_charset)); // TODO: This conversion from html-entities looks strange.
+						 				}
+						 				break;
+				 				}
+				 				break;
+				 			case XML_TEXT_NODE:
+				 				break;
+				 		}
+				 	}
+					if ($element->hasAttributes()) {
+					 	$attributes = $element->attributes;
 					 	//$keep_href = '';
-					 	foreach ($attributes as $a1 => $dummy) {
-					 		$attrib =& $attributes[$a1];
+					 	foreach ($attributes as $attrib) {
 					 		switch ($attrib->name) {
 					 			case 'identifier':
 					 				$this->identifier = $attrib->value;
@@ -73,64 +74,12 @@ class scormOrganization {
 					 				break;
 					 		}
 					 	}
-						return true;
-
-				}
-			} elseif ($v == 5) {
-				// Parsing using PHP5 DOMXML methods.
-				switch ($type) {
-					case 'db':
-						// TODO: Implement this way of metadata object creation.
-						return false;
-					case 'manifest': // Do the same as the default.
-					default:
-					 	//if($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function.
-					 	$children = $element->childNodes;
-						foreach ($children as $child) {
-					 		switch ($child->nodeType) {
-					 			case XML_ELEMENT_NODE:
-									switch ($child->tagName) {
-					 					case 'item':
-					 						$oItem = new scormItem('manifest', $child);
-					 						if ($oItem->identifier != '') {
-												$this->items[$oItem->identifier] = $oItem;
-					 						}
-											break;
-					 					case 'metadata':
-					 						$this->metadata = new scormMetadata('manifest', $child);
-					 						break;
-					 					case 'title':
-							 				$tmp_children = $child->childNodes;
-							 				if ($tmp_children->length == 1 && $child->firstChild->nodeValue != '') {
-							 					$this->title = html_entity_decode(html_entity_decode($child->firstChild->nodeValue, ENT_QUOTES, $scorm_charset)); // TODO: This conversion from html-entities looks strange.
-							 				}
-							 				break;
-					 				}
-					 				break;
-					 			case XML_TEXT_NODE:
-					 				break;
-					 		}
-					 	}
-						if ($element->hasAttributes()) {
-						 	$attributes = $element->attributes;
-						 	//$keep_href = '';
-						 	foreach ($attributes as $attrib) {
-						 		switch ($attrib->name) {
-						 			case 'identifier':
-						 				$this->identifier = $attrib->value;
-						 				break;
-						 			case 'structure':
-						 				$this->structure = $attrib->value;
-						 				break;
-						 		}
-						 	}
-						}
-						return true;
-				}
-			} else {
-				// Cannot parse because not PHP4 nor PHP5... We should not even be here anyway...
-				return false;
+					}
+					return true;
 			}
+
+			// End parsing using PHP5 DOMXML methods.
+
 		}
 		return false;
 	}

+ 50 - 118
main/newscorm/scormResource.class.php

@@ -37,141 +37,73 @@ class scormResource {
 		echo "</pre><br />\n";
 		*/
 		if (isset($element)) {
-			$v = substr(phpversion(), 0, 1);
-			if ($v == 4) {
-				switch ($type) {
-					case 'db':
-						// TODO: Implement this way of metadata object creation.
-						return false;
-					case 'manifest': //do the same as the default
-					default:
-						//if ($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function.
-						$children = $element->children();
-						foreach ($children as $a => $dummy) {
-							$child =& $children[$a];
-							switch ($child->type) {
+
+			// Parsing using PHP5 DOMXML methods.
+
+			switch ($type) {
+				case 'db':
+					// TODO: Implement this way of metadata object creation.
+					return false;
+				case 'manifest': // Do the same as the default.
+				default:
+					//if ($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function.
+					$children = $element->childNodes;
+					if (is_array($children)) {
+						foreach ($children as $child) {
+							switch ($child->nodeType) {
 								case XML_ELEMENT_NODE:
-									switch ($child->tagname) {
+									switch ($child->tagName) {
 										case 'file':
 											//echo "Child is a file tag<br />\n";
-											$this->files[] = $child->get_attribute('href');
-											//var_dump($this->files);
-											//ignoring file metadata
-											//files[] array contains all <file href='x'> tags one by one
+											$this->files[] = $child->getAttribute('href');
 											break;
 										case 'metadata':
 											//echo "Child is a metadata tag<br />\n";
 											$this->metadata = new scormMetadata('manifest', $child);
 											break;
 										case 'dependency':
-											//echo "Child is a dependency tag<br />\n";
-											//need to get identifierref attribute inside dependency node
-											//dependencies[] array represents all <dependency identifierref='x'> tags united
-											$this->dependencies[] = $child->get_attribute('identifierref');
+											// Need to get identifierref attribute inside dependency node.
+											// dependencies[] array represents all <dependency identifierref='x'> tags united.
+											$this->dependencies[] = $child->getAttribute('identifierref');
 											break;
 									}
 									break;
 							}
 						}
-						$attributes = $element->attributes();
-						//$keep_href = '';
-						if (count($attributes) > 0) { // In some cases we get here with an empty attributes array.
-						//TODO find when and why we get such a case (empty array)
-							foreach ($attributes as $a1 => $dummy) {
-								$attrib =& $attributes[$a1];
-								switch ($attrib->name) {
-									case 'identifier':
-										$this->identifier = $attrib->value;
-										break;
-									case 'type':
-										if (!empty($attrib->value)) {
-											$this->type = $attrib->value;
-										}
-										break;
-									case 'scormtype':
-										if (!empty($attrib->value)) {
-											$this->scormtype = $attrib->value;
-										}
-										break;
-									case 'base':
-										$this->base = $attrib->value;
-										break;
-									case 'href':
-										$this->href = $attrib->value;
-										break;
-								}
-							}
-						}
-						return true;
-
-				}
-			} elseif ($v == 5) {
-				// Parsing using PHP5 DOMXML methods.
-				switch($type){
-					case 'db':
-						// TODO: Implement this way of metadata object creation.
-						return false;
-					case 'manifest': // Do the same as the default.
-					default:
-						//if ($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function.
-						$children = $element->childNodes;
-						if (is_array($children)) {
-							foreach ($children as $child) {
-								switch ($child->nodeType) {
-									case XML_ELEMENT_NODE:
-										switch ($child->tagName) {
-											case 'file':
-												//echo "Child is a file tag<br />\n";
-												$this->files[] = $child->getAttribute('href');
-												break;
-											case 'metadata':
-												//echo "Child is a metadata tag<br />\n";
-												$this->metadata = new scormMetadata('manifest', $child);
-												break;
-											case 'dependency':
-												// Need to get identifierref attribute inside dependency node.
-												// dependencies[] array represents all <dependency identifierref='x'> tags united.
-												$this->dependencies[] = $child->getAttribute('identifierref');
-												break;
-										}
-										break;
-								}
-							}
-						}
-						//$keep_href = '';
-						if ($element->hasAttributes()){ //in some cases we get here with an empty attributes array
-						// TODO: Find when and why we get such a case (empty array).
-							$attributes = $element->attributes;
-							foreach ($attributes as $attrib) {
-								switch ($attrib->name) {
-									case 'identifier':
-										$this->identifier = $attrib->value;
-										break;
-									case 'type':
-										if (!empty($attrib->value)) {
-											$this->type = $attrib->value;
-										}
-										break;
-									case 'scormtype':
-										if (!empty($attrib->value)) {
-											$this->scormtype = $attrib->value;
-										}
-										break;
-									case 'base':
-										$this->base = $attrib->value;
-										break;
-									case 'href':
-										$this->href = $attrib->value;
-										break;
-								}
+					}
+					//$keep_href = '';
+					if ($element->hasAttributes()){ //in some cases we get here with an empty attributes array
+					// TODO: Find when and why we get such a case (empty array).
+						$attributes = $element->attributes;
+						foreach ($attributes as $attrib) {
+							switch ($attrib->name) {
+								case 'identifier':
+									$this->identifier = $attrib->value;
+									break;
+								case 'type':
+									if (!empty($attrib->value)) {
+										$this->type = $attrib->value;
+									}
+									break;
+								case 'scormtype':
+									if (!empty($attrib->value)) {
+										$this->scormtype = $attrib->value;
+									}
+									break;
+								case 'base':
+									$this->base = $attrib->value;
+									break;
+								case 'href':
+									$this->href = $attrib->value;
+									break;
 							}
 						}
-						return true;
-				}
-			} else {
-				// Cannot parse because not PHP4 nor PHP5... We should not even be here anyway...
-				return false;
+					}
+					return true;
 			}
+
+			// End parsing using PHP5 DOMXML methods.
+
 		}
 		return false;
 	}