Mercurial > hg > webaudioevaluationtool
comparison php/get_filtered_count.php @ 2283:169f08dc9634
Fix for #25, PHP uses the array() function rather than the [] initialiser (only supported if PHP >= 5.4)
author | Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk> |
---|---|
date | Fri, 22 Apr 2016 09:34:34 +0100 |
parents | 760719986df3 |
children | d26623bd65e0 |
comparison
equal
deleted
inserted
replaced
2281:185232d01324 | 2283:169f08dc9634 |
---|---|
1 <?php | 1 <?php |
2 //http://stackoverflow.com/questions/4444475/transfrom-relative-path-into-absolute-url-using-php | 2 //http://stackoverflow.com/questions/4444475/transfrom-relative-path-into-absolute-url-using-php |
3 function rel2abs($rel, $base) | 3 include "rel2abs.php"; |
4 { | |
5 /* return if already absolute URL */ | |
6 if (parse_url($rel, PHP_URL_SCHEME) != '' || substr($rel, 0, 2) == '//') return $rel; | |
7 | |
8 /* queries and anchors */ | |
9 if ($rel[0]=='#' || $rel[0]=='?') return $base.$rel; | |
10 | |
11 /* parse base URL and convert to local variables: | |
12 $scheme, $host, $path */ | |
13 extract(parse_url($base)); | |
14 | |
15 /* remove non-directory element from path */ | |
16 $path = preg_replace('#/[^/]*$#', '', $path); | |
17 | |
18 /* destroy path if relative url points to root */ | |
19 if ($rel[0] == '/') $path = ''; | |
20 | |
21 /* dirty absolute URL */ | |
22 $abs = "$host$path/$rel"; | |
23 | |
24 /* replace '//' or '/./' or '/foo/../' with '/' */ | |
25 $re = array('#(/\.?/)#', '#/(?!\.\.)[^/]+/\.\./#'); | |
26 for($n=1; $n>0; $abs=preg_replace($re, '/', $abs, -1, $n)) {} | |
27 | |
28 /* absolute URL is ready! */ | |
29 return $scheme.'://'.$abs; | |
30 } | |
31 | 4 |
32 /* | 5 /* |
33 This looks for files that pass the filtering response | 6 This looks for files that pass the filtering response |
34 The filtering system uses key-value pairs | 7 The filtering system uses key-value pairs |
35 The key is double encoded using a '-'. The first part is the ID of the item to filter, | 8 The key is double encoded using a '-'. The first part is the ID of the item to filter, |
36 the second is the method: | 9 the second is the method: |
37 min - Minimum Inclusive | 10 min - Minimum Inclusive |
38 max - Maximum Inclusive | 11 max - Maximum Inclusive |
39 exclude-# - exclude, followed by a number to uniquely add, (will create a triple [], ignore the third as random) | 12 exclude-# - exclude, followed by a number to uniquely add, (will create a triple [], ignore the third as random) |
40 */ | 13 */ |
41 $keys = []; | 14 $keys = array(); |
42 $waet_url = null; | 15 $waet_url = null; |
43 foreach ($_GET as $key => $value) { | 16 foreach ($_GET as $key => $value) { |
44 $key = explode("-",$key); | 17 $key = explode("-",$key); |
45 if ($key[0] == "url") { | 18 if ($key[0] == "url") { |
46 $waet_url = $value; | 19 $waet_url = $value; |
47 } else { | 20 } else { |
48 $v_pair = [$key[1],$value]; | 21 $v_pair = array($key[1],$value); |
49 if(array_key_exists($key[0],$keys)) { | 22 if(array_key_exists($key[0],$keys)) { |
50 // We have some data | 23 // We have some data |
51 array_push($keys[$key[0]],$v_pair); | 24 array_push($keys[$key[0]],$v_pair); |
52 } else { | 25 } else { |
53 // Create new key data | 26 // Create new key data |
54 $keys[$key[0]] = [$v_pair]; | 27 $keys[$key[0]] = array($v_pair); |
55 } | 28 } |
56 } | 29 } |
57 } | 30 } |
58 | 31 |
59 $files = []; | 32 $files = array(); |
60 $saves = glob("../saves/*.xml"); | 33 $saves = glob("../saves/*.xml"); |
61 if (is_array($saves)) | 34 if (is_array($saves)) |
62 { | 35 { |
63 foreach($saves as $filename) { | 36 foreach($saves as $filename) { |
64 $xml_string = file_get_contents($filename, FILE_TEXT); | 37 $xml_string = file_get_contents($filename, FILE_TEXT); |