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