annotate scripts/comment_parser.php @ 1107:6ac36f0fb2cd

Starting server side scripts. WIP, stash
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Wed, 17 Feb 2016 12:10:55 +0000
parents
children d85e219a5eeb
rev   line source
n@1107 1 <?php
n@1107 2 // Comment Parser for PHP
n@1107 3
n@1107 4 // XML Saves location - assumes it will be saves/
n@1107 5 $saves = glob("../saves/*.xml");
n@1107 6 $comment_struct = new SimpleXMLElement('<waetprocess/>');
n@1107 7 if (is_array($saves))
n@1107 8 {
n@1107 9 foreach($saves as $filename) {
n@1107 10 $xml_string = file_get_contents($filename, FILE_TEXT);
n@1107 11 $xml_object = simplexml_load_string($xml_string);
n@1107 12 $test_struct = $comment_struct->addChild("test");
n@1107 13 if ($xml_object == false) {
n@1107 14 echo "<h1>FATAL</h1> <span>could not parse file ".$filename.": </span>";
n@1107 15 foreach(libxml_get_errors() as $error) {
n@1107 16 echo "<br>", $error->message;
n@1107 17 }
n@1107 18 } else {
n@1107 19 // Iterate over each audioHolder node
n@1107 20 foreach($xml_object->page as $pageInstance)
n@1107 21 {
n@1107 22 $page_struct = $test_struct->addChild("page");
n@1107 23 // Get the page-id and attach
n@1107 24 $page_struct->addAttribute("page-id",$pageInstance['id']);
n@1107 25
n@1107 26 // Get the audioelements of the page
n@1107 27 foreach($pageInstance->audioelement as $fragment)
n@1107 28 {
n@1107 29 $fragment_struct = $page_struct->addChild("audioelement");
n@1107 30 // Get the element-id and attach
n@1107 31 $page_struct->addAttribute("element-id",$fragment['id']);
n@1107 32 $page_struct->addAttribute("presented-id",$fragment['presentedId']);
n@1107 33 $page_struct->addAttribute("url",$fragment['url']);
n@1107 34 // Append the comment data
n@1107 35 echo "<p>Comment: ".$fragement->comment."</p>";
n@1107 36 $comment = $fragment_struct->addChild("comment");
n@1107 37 }
n@1107 38 }
n@1107 39 }
n@1107 40 }
n@1107 41 // Now we have a sub <xml> containing all comment data
n@1107 42 echo $comment_struct->asXML();
n@1107 43 } else {
n@1107 44 echo "FATAL - No saved XML files discovered";
n@1107 45 }
n@1107 46 ?>