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: /* n@1284: This looks for files that pass the filtering response n@1284: The filtering system uses key-value pairs n@1284: The key is double encoded using a '-'. The first part is the ID of the item to filter, n@1284: the second is the method: n@1284: min - Minimum Inclusive n@1284: max - Maximum Inclusive n@1284: exclude-# - exclude, followed by a number to uniquely add, (will create a triple [], ignore the third as random) n@1284: */ n@1284: $keys = []; n@1284: $waet_url = null; n@1284: foreach ($_GET as $key => $value) { n@1284: $key = explode("-",$key); n@1284: if ($key[0] == "url") { n@1284: $waet_url = $value; n@1284: } else { n@1284: $v_pair = [$key[1],$value]; n@1284: if(array_key_exists($key[0],$keys)) { n@1284: // We have some data n@1284: array_push($keys[$key[0]],$v_pair); n@1284: } else { n@1284: // Create new key data n@1284: $keys[$key[0]] = [$v_pair]; n@1284: } n@1284: } n@1284: } n@1284: n@1284: $files = []; 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: // First we must check the URLs match n@1284: $waet = $xml_object->waet[0]; n@1284: if (urldecode($waet["url"])==$waet_url) { n@1284: // It is part of the dataset, so now perform checks n@1284: $continue = true; n@1284: foreach($keys as $keyId => $keyArr) { n@1284: $elem = $xml_object->xpath("//*[@ref='".$keyId."']"); n@1284: $elem = $elem[0]; // Can only be one. n@1284: switch ($elem["type"]) { n@1284: case "number": n@1284: // Number, we must check for min/max n@1284: $value = (real)$elem->response; n@1284: foreach ($keyArr as $keyCheck) { n@1284: if ($keyCheck[0] == 'min' && $value < $keyCheck[1]) { n@1284: $continue = false; n@1284: break; n@1284: } else if ($keyCheck[0] == 'max' && $value > $keyCheck[1]) { n@1284: $continue = false; n@1284: break; n@1284: } n@1284: } n@1284: break; n@1284: case "checkbox": n@1284: // Will have an array of n@1284: foreach ($elem->response as $response) { n@1284: foreach ($keyArr as $keyCheck) { n@1284: if ($response["name"] == $keyCheck[1]) { n@1284: if($response["checked"] == "true" && $keyCheck[0] == "exclude") { n@1284: $continue = false; n@1284: break; n@1284: } n@1284: } n@1284: } n@1284: if($continue == false) { n@1284: break; n@1284: } n@1284: } n@1284: break; n@1284: case "radio": n@1284: foreach ($keyArr as $keyCheck) { n@1284: if ($keyCheck[0] == "exclude" && $elem->response["name"] == $keyCheck[1]) { n@1284: n@1284: $continue = false; n@1284: break; n@1284: } n@1284: } n@1284: break; n@1284: default: n@1284: break; n@1284: } n@1284: if ($continue == false) { n@1284: break; n@1284: } n@1284: } n@1284: if ($continue) { n@1284: array_push($files,rel2abs($filename,"http://".$_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'])); n@1284: } n@1284: } n@1284: } n@1284: } n@1284: } n@1284: if (count($files) == 0) { n@1284: echo '{"urls": []}'; n@1284: } else { n@1284: echo '{"urls": ["'.implode('","',$files).'"]}'; n@1284: } n@1284: n@1284: ?>