n@650: 0; $abs=preg_replace($re, '/', $abs, -1, $n)) {} n@650: n@650: /* absolute URL is ready! */ n@650: return $scheme.'://'.$abs; n@650: } n@650: n@650: // XML Saves location - assumes it will be saves/ n@650: $data = []; n@650: $saves = glob("../saves/*.xml"); n@650: if (is_array($saves)) n@650: { n@650: foreach($saves as $filename) { n@650: $xml_string = file_get_contents($filename, FILE_TEXT); n@650: $xml_object = simplexml_load_string($xml_string); n@650: if ($xml_object) { n@650: $filename = rel2abs($filename,"http://".$_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']); n@650: $waet = $xml_object->waet[0]; n@650: $testName = urldecode($waet["url"]); n@650: if(array_key_exists($testName,$data)) { n@650: // Key exists n@650: array_push($data[$testName],$filename); n@650: } else { n@650: // Key does not exist n@650: $data[$testName] = [$filename]; n@650: } n@650: } n@650: } n@650: } n@650: n@650: // Now read the format response n@650: $format = "JSON"; n@650: if (array_key_exists("format",$_GET)) { n@650: $format = $_GET["format"]; n@650: } n@650: switch($format) { n@650: case "JSON": n@650: // Return JSON n@650: $doc_root = '{"tests": ['; n@650: $keys = array_keys($data); n@650: $numTests = count($data); n@650: for ($testIndex = 0; $testIndex < $numTests; $testIndex++) { n@650: $test_root = '{"testName": "'.$keys[$testIndex].'", "files": ['; n@650: $numFiles = count($data[$keys[$testIndex]]); n@650: for ($countIndex=0; $countIndex < $numFiles; $countIndex++) { n@650: $test_root = $test_root.'"'.$data[$keys[$testIndex]][$countIndex].'"'; n@650: if ($countIndex == $numFiles-1) { n@650: $test_root = $test_root.']}'; n@650: } else { n@650: $test_root = $test_root.','; n@650: } n@650: } n@650: $doc_root = $doc_root.$test_root; n@650: if ($testIndex == $numTests-1) { n@650: $doc_root = $doc_root.']}'; n@650: } else { n@650: $doc_root = $doc_root.','; n@650: } n@650: } n@650: echo $doc_root; n@650: break; n@650: default: n@650: echo '{"error": "format can only be JSON"}'; n@650: } n@650: n@650: ?>