/
filter.php
67 lines (55 loc) · 1.59 KB
/
filter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
* letöltések szűrése
*
* @author Kolesár András <kolesar@turistautak.hu>
* @since 2014.06.09
*
*/
function bbox ($bounding, $filter) {
// bounding box
if ($bounding == '') {
if (!$filter) throw new Exception('no bbox');
$bbox = null;
} else {
$bbox = explode(',', $bounding);
if (count($bbox) != 4) throw new Exception('invalid bbox syntax');
if ($bbox[0]>=$bbox[2] || $bbox[1]>=$bbox[3]) throw new Exception('invalid bbox');
foreach ($bbox as $coord) if (!is_numeric($coord)) throw new Exception('invalid bbox');
$area = ($bbox[2]-$bbox[0])*($bbox[3]-$bbox[1]);
if (!$filter && $area>0.25) throw new Exception('bbox too large');
}
return $bbox;
}
function typeFilter ($types, $names) {
// előkészítjük a szűrőfeltételt
if (!is_array($types)) $types = array($types);
// értelmezzük a szűréseket
$codes = array();
foreach ($types as $type) {
if (is_numeric($type)) {
$codes[] = $type;
} else if (preg_match('/^0x([0-9a-f]+)$/i', $type, $regs)) {
$codes[] = hexdec($regs[1]);
} else {
$code = array_search(deaccent($type), deaccent($names));
if ($code !== false && is_numeric($code)) $codes[] = $code;
}
}
return $codes;
}
function deaccent ($string) {
if (is_array($string)) {
foreach ($string as $k=>$v) {
$out[$k] = deaccent($v);
}
return $out;
} else {
return str_replace(
array('á', 'é', 'í', 'ó', 'ú', 'ö', 'ő', 'ü', 'ű',
'Á', 'É', 'Í', 'Ó', 'Ú', 'Ö', 'Ő', 'Ü', 'Ű'),
array('a', 'e', 'i', 'o', 'u', 'o', 'o', 'u', 'u',
'A', 'E', 'I', 'O', 'U', 'O', 'O', 'U', 'U'),
$string);
}
}