annotate scripts/comment_parser.php @ 519:2bde74ae8396 Dev_main

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