@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | throw new ParamMissing('center'); |
35 | 35 | $parts = explode('|', $tmp); |
36 | 36 | if (count($parts) != 2) |
37 | - throw new InvalidParam('center', "Expecting 2 pipe-separated parts, got ".count($parts)."."); |
|
37 | + throw new InvalidParam('center', "Expecting 2 pipe-separated parts, got " . count($parts) . "."); |
|
38 | 38 | foreach ($parts as &$part_ref) |
39 | 39 | { |
40 | 40 | if (!preg_match("/^-?[0-9]+(\.?[0-9]*)$/", $part_ref)) |
@@ -70,27 +70,27 @@ discard block |
||
70 | 70 | { |
71 | 71 | if (!preg_match("/^-?[0-9]+(\.?[0-9]*)$/", $tmp)) |
72 | 72 | throw new InvalidParam('radius', "'$tmp' is not a valid float number."); |
73 | - $radius = floatval($tmp); # is given in kilometers |
|
73 | + $radius = floatval($tmp); # is given in kilometers |
|
74 | 74 | if ($radius <= 0) |
75 | 75 | throw new InvalidParam('radius', "Has to be a positive number."); |
76 | 76 | |
77 | 77 | # Apply a latitude-range prefilter if it looks promising. |
78 | 78 | # See https://github.com/opencaching/okapi/issues/363 for more info. |
79 | 79 | |
80 | - $optimization_radius = 100; # in kilometers, optimized for Opencaching.de |
|
80 | + $optimization_radius = 100; # in kilometers, optimized for Opencaching.de |
|
81 | 81 | $km2degrees_upper_estimate_factor = 0.01; |
82 | 82 | |
83 | 83 | if ($radius <= $optimization_radius) |
84 | 84 | { |
85 | 85 | $radius_degrees = $radius * $km2degrees_upper_estimate_factor; |
86 | 86 | $where_conds[] = " |
87 | - caches.latitude >= '".Db::escape_string($center_lat - $radius_degrees)."' |
|
88 | - and caches.latitude <= '".Db::escape_string($center_lat + $radius_degrees)."' |
|
87 | + caches.latitude >= '".Db::escape_string($center_lat - $radius_degrees) . "' |
|
88 | + and caches.latitude <= '".Db::escape_string($center_lat + $radius_degrees) . "' |
|
89 | 89 | "; |
90 | 90 | } |
91 | 91 | |
92 | - $radius *= 1000; # convert from kilometers to meters |
|
93 | - $where_conds[] = "$distance_formula <= '".Db::escape_string($radius)."'"; |
|
92 | + $radius *= 1000; # convert from kilometers to meters |
|
93 | + $where_conds[] = "$distance_formula <= '" . Db::escape_string($radius) . "'"; |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | $search_params = $search_assistant->get_search_params(); |
@@ -30,22 +30,27 @@ discard block |
||
30 | 30 | # It's much easier to grasp their meaning this way. |
31 | 31 | |
32 | 32 | $tmp = $request->get_parameter('center'); |
33 | - if (!$tmp) |
|
34 | - throw new ParamMissing('center'); |
|
33 | + if (!$tmp) { |
|
34 | + throw new ParamMissing('center'); |
|
35 | + } |
|
35 | 36 | $parts = explode('|', $tmp); |
36 | - if (count($parts) != 2) |
|
37 | - throw new InvalidParam('center', "Expecting 2 pipe-separated parts, got ".count($parts)."."); |
|
37 | + if (count($parts) != 2) { |
|
38 | + throw new InvalidParam('center', "Expecting 2 pipe-separated parts, got ".count($parts)."."); |
|
39 | + } |
|
38 | 40 | foreach ($parts as &$part_ref) |
39 | 41 | { |
40 | - if (!preg_match("/^-?[0-9]+(\.?[0-9]*)$/", $part_ref)) |
|
41 | - throw new InvalidParam('center', "'$part_ref' is not a valid float number."); |
|
42 | + if (!preg_match("/^-?[0-9]+(\.?[0-9]*)$/", $part_ref)) { |
|
43 | + throw new InvalidParam('center', "'$part_ref' is not a valid float number."); |
|
44 | + } |
|
42 | 45 | $part_ref = floatval($part_ref); |
43 | 46 | } |
44 | 47 | list($center_lat, $center_lon) = $parts; |
45 | - if ($center_lat > 90 || $center_lat < -90) |
|
46 | - throw new InvalidParam('center', "Latitudes have to be within -90..90 range."); |
|
47 | - if ($center_lon > 180 || $center_lon < -180) |
|
48 | - throw new InvalidParam('center', "Longitudes have to be within -180..180 range."); |
|
48 | + if ($center_lat > 90 || $center_lat < -90) { |
|
49 | + throw new InvalidParam('center', "Latitudes have to be within -90..90 range."); |
|
50 | + } |
|
51 | + if ($center_lon > 180 || $center_lon < -180) { |
|
52 | + throw new InvalidParam('center', "Longitudes have to be within -180..180 range."); |
|
53 | + } |
|
49 | 54 | |
50 | 55 | # |
51 | 56 | # In the method description, we promised to return caches ordered by the *rough* |
@@ -68,11 +73,13 @@ discard block |
||
68 | 73 | $radius = null; |
69 | 74 | if ($tmp = $request->get_parameter('radius')) |
70 | 75 | { |
71 | - if (!preg_match("/^-?[0-9]+(\.?[0-9]*)$/", $tmp)) |
|
72 | - throw new InvalidParam('radius', "'$tmp' is not a valid float number."); |
|
76 | + if (!preg_match("/^-?[0-9]+(\.?[0-9]*)$/", $tmp)) { |
|
77 | + throw new InvalidParam('radius', "'$tmp' is not a valid float number."); |
|
78 | + } |
|
73 | 79 | $radius = floatval($tmp); # is given in kilometers |
74 | - if ($radius <= 0) |
|
75 | - throw new InvalidParam('radius', "Has to be a positive number."); |
|
80 | + if ($radius <= 0) { |
|
81 | + throw new InvalidParam('radius', "Has to be a positive number."); |
|
82 | + } |
|
76 | 83 | |
77 | 84 | # Apply a latitude-range prefilter if it looks promising. |
78 | 85 | # See https://github.com/opencaching/okapi/issues/363 for more info. |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | select cache_id, wp_oc |
122 | 122 | from caches |
123 | 123 | where |
124 | - cache_id in ('".implode("','", array_map('\okapi\Db::escape_string', $internal_ids))."') |
|
124 | + cache_id in ('".implode("','", array_map('\okapi\Db::escape_string', $internal_ids)) . "') |
|
125 | 125 | and status in (1,2,3) |
126 | 126 | "); |
127 | 127 | $dict = array(); |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | select uuid, wp_oc |
146 | 146 | from caches |
147 | 147 | where |
148 | - uuid in ('".implode("','", array_map('\okapi\Db::escape_string', $uuids))."') |
|
148 | + uuid in ('".implode("','", array_map('\okapi\Db::escape_string', $uuids)) . "') |
|
149 | 149 | and status in (1,2,3) |
150 | 150 | "); |
151 | 151 | $dict = array(); |
@@ -33,45 +33,56 @@ discard block |
||
33 | 33 | if ($host == null) |
34 | 34 | { |
35 | 35 | $host = parse_url(Settings::get('SITE_URL'), PHP_URL_HOST); |
36 | - if (strpos($host, "www.") === 0) |
|
37 | - $host = substr($host, 4); |
|
36 | + if (strpos($host, "www.") === 0) { |
|
37 | + $host = substr($host, 4); |
|
38 | + } |
|
38 | 39 | $length = strlen($host); |
39 | 40 | } |
40 | 41 | |
41 | 42 | # Parse the URL |
42 | 43 | |
43 | 44 | $uri = parse_url($url); |
44 | - if ($uri == false) |
|
45 | - return null; |
|
46 | - if ((!isset($uri['scheme'])) || (!in_array($uri['scheme'], array('http', 'https')))) |
|
47 | - return null; |
|
48 | - if ((!isset($uri['host'])) || (substr($uri['host'], -$length) != $host)) |
|
49 | - return null; |
|
50 | - if (!isset($uri['path'])) |
|
51 | - return null; |
|
45 | + if ($uri == false) { |
|
46 | + return null; |
|
47 | + } |
|
48 | + if ((!isset($uri['scheme'])) || (!in_array($uri['scheme'], array('http', 'https')))) { |
|
49 | + return null; |
|
50 | + } |
|
51 | + if ((!isset($uri['host'])) || (substr($uri['host'], -$length) != $host)) { |
|
52 | + return null; |
|
53 | + } |
|
54 | + if (!isset($uri['path'])) { |
|
55 | + return null; |
|
56 | + } |
|
52 | 57 | if (preg_match("#^/(O[A-Z][A-Z0-9]{4,5})$#", $uri['path'], $matches)) |
53 | 58 | { |
54 | 59 | # Some servers allow "http://oc.xx/<cache_code>" shortcut. |
55 | 60 | return array('cache_code', $matches[1]); |
56 | 61 | } |
57 | 62 | $parts = array(); |
58 | - if (isset($uri['query'])) |
|
59 | - $parts = array_merge($parts, explode('&', $uri['query'])); |
|
60 | - if (isset($uri['fragment'])) |
|
61 | - $parts = array_merge($parts, explode('&', $uri['fragment'])); |
|
63 | + if (isset($uri['query'])) { |
|
64 | + $parts = array_merge($parts, explode('&', $uri['query'])); |
|
65 | + } |
|
66 | + if (isset($uri['fragment'])) { |
|
67 | + $parts = array_merge($parts, explode('&', $uri['fragment'])); |
|
68 | + } |
|
62 | 69 | foreach ($parts as $param) |
63 | 70 | { |
64 | 71 | $item = explode('=', $param, 2); |
65 | - if (count($item) != 2) |
|
66 | - continue; |
|
72 | + if (count($item) != 2) { |
|
73 | + continue; |
|
74 | + } |
|
67 | 75 | $key = $item[0]; |
68 | 76 | $value = $item[1]; |
69 | - if ($key == 'wp') |
|
70 | - return array('cache_code', $value); |
|
71 | - if ($key == 'cacheid') |
|
72 | - return array('internal_id', $value); |
|
73 | - if ($key == 'uuid') |
|
74 | - return array('uuid', $value); |
|
77 | + if ($key == 'wp') { |
|
78 | + return array('cache_code', $value); |
|
79 | + } |
|
80 | + if ($key == 'cacheid') { |
|
81 | + return array('internal_id', $value); |
|
82 | + } |
|
83 | + if ($key == 'uuid') { |
|
84 | + return array('uuid', $value); |
|
85 | + } |
|
75 | 86 | } |
76 | 87 | return null; |
77 | 88 | } |
@@ -81,13 +92,17 @@ discard block |
||
81 | 92 | # Retrieve the list of URLs to check. |
82 | 93 | |
83 | 94 | $tmp = $request->get_parameter('urls'); |
84 | - if (!$tmp) |
|
85 | - throw new ParamMissing('urls'); |
|
95 | + if (!$tmp) { |
|
96 | + throw new ParamMissing('urls'); |
|
97 | + } |
|
86 | 98 | $urls = explode('|', $tmp); |
87 | 99 | $as_dict = $request->get_parameter('as_dict'); |
88 | - if (!$as_dict) $as_dict = 'false'; |
|
89 | - if (!in_array($as_dict, array('true', 'false'))) |
|
90 | - throw new InvalidParam('as_dict'); |
|
100 | + if (!$as_dict) { |
|
101 | + $as_dict = 'false'; |
|
102 | + } |
|
103 | + if (!in_array($as_dict, array('true', 'false'))) { |
|
104 | + throw new InvalidParam('as_dict'); |
|
105 | + } |
|
91 | 106 | $as_dict = ($as_dict == 'true'); |
92 | 107 | |
93 | 108 | # Generate the lists of keys. |
@@ -101,16 +116,18 @@ discard block |
||
101 | 116 | foreach ($urls as &$url_ref) |
102 | 117 | { |
103 | 118 | $key = self::get_cache_key($url_ref); |
104 | - if ($key != null) |
|
105 | - $urls_with[$key[0]][$url_ref] = $key[1]; |
|
106 | - else |
|
107 | - $results[$url_ref] = null; |
|
119 | + if ($key != null) { |
|
120 | + $urls_with[$key[0]][$url_ref] = $key[1]; |
|
121 | + } else { |
|
122 | + $results[$url_ref] = null; |
|
123 | + } |
|
108 | 124 | } |
109 | 125 | |
110 | 126 | # Include 'cache_code' references. |
111 | 127 | |
112 | - foreach ($urls_with['cache_code'] as $url => $cache_code) |
|
113 | - $results[$url] = $cache_code; |
|
128 | + foreach ($urls_with['cache_code'] as $url => $cache_code) { |
|
129 | + $results[$url] = $cache_code; |
|
130 | + } |
|
114 | 131 | |
115 | 132 | # Include 'internal_id' references. |
116 | 133 | |
@@ -125,14 +142,16 @@ discard block |
||
125 | 142 | and status in (1,2,3) |
126 | 143 | "); |
127 | 144 | $dict = array(); |
128 | - while ($row = Db::fetch_assoc($rs)) |
|
129 | - $dict[$row['cache_id']] = $row['wp_oc']; |
|
145 | + while ($row = Db::fetch_assoc($rs)) { |
|
146 | + $dict[$row['cache_id']] = $row['wp_oc']; |
|
147 | + } |
|
130 | 148 | foreach ($urls_with['internal_id'] as $url => $internal_id) |
131 | 149 | { |
132 | - if (isset($dict[$internal_id])) |
|
133 | - $results[$url] = $dict[$internal_id]; |
|
134 | - else |
|
135 | - $results[$url] = null; |
|
150 | + if (isset($dict[$internal_id])) { |
|
151 | + $results[$url] = $dict[$internal_id]; |
|
152 | + } else { |
|
153 | + $results[$url] = null; |
|
154 | + } |
|
136 | 155 | } |
137 | 156 | } |
138 | 157 | |
@@ -149,27 +168,30 @@ discard block |
||
149 | 168 | and status in (1,2,3) |
150 | 169 | "); |
151 | 170 | $dict = array(); |
152 | - while ($row = Db::fetch_assoc($rs)) |
|
153 | - $dict[$row['uuid']] = $row['wp_oc']; |
|
171 | + while ($row = Db::fetch_assoc($rs)) { |
|
172 | + $dict[$row['uuid']] = $row['wp_oc']; |
|
173 | + } |
|
154 | 174 | foreach ($urls_with['uuid'] as $url => $uuid) |
155 | 175 | { |
156 | - if (isset($dict[$uuid])) |
|
157 | - $results[$url] = $dict[$uuid]; |
|
158 | - else |
|
159 | - $results[$url] = null; |
|
176 | + if (isset($dict[$uuid])) { |
|
177 | + $results[$url] = $dict[$uuid]; |
|
178 | + } else { |
|
179 | + $results[$url] = null; |
|
180 | + } |
|
160 | 181 | } |
161 | 182 | } |
162 | 183 | |
163 | 184 | # Format the results according to the 'as_dict' parameter. |
164 | 185 | |
165 | - if ($as_dict) |
|
166 | - return Okapi::formatted_response($request, $results); |
|
167 | - else |
|
186 | + if ($as_dict) { |
|
187 | + return Okapi::formatted_response($request, $results); |
|
188 | + } else |
|
168 | 189 | { |
169 | 190 | $cache_codes = array(); |
170 | - foreach ($results as $url => $cache_code) |
|
171 | - if ($cache_code != null) |
|
191 | + foreach ($results as $url => $cache_code) { |
|
192 | + if ($cache_code != null) |
|
172 | 193 | $cache_codes[$cache_code] = true; |
194 | + } |
|
173 | 195 | $flattened = array('results' => array_keys($cache_codes)); |
174 | 196 | return Okapi::formatted_response($request, $flattened); |
175 | 197 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | throw new ParamMissing('bbox'); |
35 | 35 | $parts = explode('|', $tmp); |
36 | 36 | if (count($parts) != 4) |
37 | - throw new InvalidParam('bbox', "Expecting 4 pipe-separated parts, got ".count($parts)."."); |
|
37 | + throw new InvalidParam('bbox', "Expecting 4 pipe-separated parts, got " . count($parts) . "."); |
|
38 | 38 | foreach ($parts as &$part_ref) |
39 | 39 | { |
40 | 40 | if (!preg_match("/^-?[0-9]+(\.?[0-9]*)$/", $part_ref)) |
@@ -61,15 +61,15 @@ discard block |
||
61 | 61 | $lat = $search_assistant->get_latitude_expr(); |
62 | 62 | $lon = $search_assistant->get_longitude_expr(); |
63 | 63 | $where_conds[] = "( |
64 | - $lat >= '".Db::escape_string($bbsouth)."' |
|
65 | - and $lat < '".Db::escape_string($bbnorth)."' |
|
64 | + $lat >= '" . Db::escape_string($bbsouth) . "' |
|
65 | + and $lat < '" . Db::escape_string($bbnorth) . "' |
|
66 | 66 | )"; |
67 | 67 | if ($bbeast > $bbwest) |
68 | 68 | { |
69 | 69 | # Easy one. |
70 | 70 | $where_conds[] = "( |
71 | - $lon >= '".Db::escape_string($bbwest)."' |
|
72 | - and $lon < '".Db::escape_string($bbeast)."' |
|
71 | + $lon >= '" . Db::escape_string($bbwest) . "' |
|
72 | + and $lon < '" . Db::escape_string($bbeast) . "' |
|
73 | 73 | )"; |
74 | 74 | } |
75 | 75 | else |
@@ -77,8 +77,8 @@ discard block |
||
77 | 77 | # We'll have to assume that this bbox goes through the 180-degree meridian. |
78 | 78 | # For example, $bbwest = 179 and $bbeast = -179. |
79 | 79 | $where_conds[] = "( |
80 | - $lon >= '".Db::escape_string($bbwest)."' |
|
81 | - or $lon < '".Db::escape_string($bbeast)."' |
|
80 | + $lon >= '" . Db::escape_string($bbwest) . "' |
|
81 | + or $lon < '" . Db::escape_string($bbeast) . "' |
|
82 | 82 | )"; |
83 | 83 | } |
84 | 84 |
@@ -30,26 +30,33 @@ discard block |
||
30 | 30 | # It's much easier to grasp their meaning this way. |
31 | 31 | |
32 | 32 | $tmp = $request->get_parameter('bbox'); |
33 | - if (!$tmp) |
|
34 | - throw new ParamMissing('bbox'); |
|
33 | + if (!$tmp) { |
|
34 | + throw new ParamMissing('bbox'); |
|
35 | + } |
|
35 | 36 | $parts = explode('|', $tmp); |
36 | - if (count($parts) != 4) |
|
37 | - throw new InvalidParam('bbox', "Expecting 4 pipe-separated parts, got ".count($parts)."."); |
|
37 | + if (count($parts) != 4) { |
|
38 | + throw new InvalidParam('bbox', "Expecting 4 pipe-separated parts, got ".count($parts)."."); |
|
39 | + } |
|
38 | 40 | foreach ($parts as &$part_ref) |
39 | 41 | { |
40 | - if (!preg_match("/^-?[0-9]+(\.?[0-9]*)$/", $part_ref)) |
|
41 | - throw new InvalidParam('bbox', "'$part_ref' is not a valid float number."); |
|
42 | + if (!preg_match("/^-?[0-9]+(\.?[0-9]*)$/", $part_ref)) { |
|
43 | + throw new InvalidParam('bbox', "'$part_ref' is not a valid float number."); |
|
44 | + } |
|
42 | 45 | $part_ref = floatval($part_ref); |
43 | 46 | } |
44 | 47 | list($bbsouth, $bbwest, $bbnorth, $bbeast) = $parts; |
45 | - if ($bbnorth <= $bbsouth) |
|
46 | - throw new InvalidParam('bbox', "Northern edge must be situated to the north of the southern edge."); |
|
47 | - if ($bbeast == $bbwest) |
|
48 | - throw new InvalidParam('bbox', "Eastern edge longitude is the same as the western one."); |
|
49 | - if ($bbnorth > 90 || $bbnorth < -90 || $bbsouth > 90 || $bbsouth < -90) |
|
50 | - throw new InvalidParam('bbox', "Latitudes have to be within -90..90 range."); |
|
51 | - if ($bbeast > 180 || $bbeast < -180 || $bbwest > 180 || $bbwest < -180) |
|
52 | - throw new InvalidParam('bbox', "Longitudes have to be within -180..180 range."); |
|
48 | + if ($bbnorth <= $bbsouth) { |
|
49 | + throw new InvalidParam('bbox', "Northern edge must be situated to the north of the southern edge."); |
|
50 | + } |
|
51 | + if ($bbeast == $bbwest) { |
|
52 | + throw new InvalidParam('bbox', "Eastern edge longitude is the same as the western one."); |
|
53 | + } |
|
54 | + if ($bbnorth > 90 || $bbnorth < -90 || $bbsouth > 90 || $bbsouth < -90) { |
|
55 | + throw new InvalidParam('bbox', "Latitudes have to be within -90..90 range."); |
|
56 | + } |
|
57 | + if ($bbeast > 180 || $bbeast < -180 || $bbwest > 180 || $bbwest < -180) { |
|
58 | + throw new InvalidParam('bbox', "Longitudes have to be within -180..180 range."); |
|
59 | + } |
|
53 | 60 | |
54 | 61 | # Construct SQL conditions for the specified bounding box. |
55 | 62 | |
@@ -71,8 +78,7 @@ discard block |
||
71 | 78 | $lon >= '".Db::escape_string($bbwest)."' |
72 | 79 | and $lon < '".Db::escape_string($bbeast)."' |
73 | 80 | )"; |
74 | - } |
|
75 | - else |
|
81 | + } else |
|
76 | 82 | { |
77 | 83 | # We'll have to assume that this bbox goes through the 180-degree meridian. |
78 | 84 | # For example, $bbwest = 179 and $bbeast = -179. |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | } |
154 | 154 | } |
155 | 155 | if (count($types) > 0) |
156 | - $where_conds[] = "caches.type $operator ('".implode("','", array_map('\okapi\Db::escape_string', $types))."')"; |
|
156 | + $where_conds[] = "caches.type $operator ('" . implode("','", array_map('\okapi\Db::escape_string', $types)) . "')"; |
|
157 | 157 | else if ($operator == "in") |
158 | 158 | $where_conds[] = "false"; |
159 | 159 | } |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | throw new InvalidParam('size2', "'$name' is not a valid cache size."); |
184 | 184 | } |
185 | 185 | } |
186 | - $where_conds[] = "caches.size $operator ('".implode("','", array_map('\okapi\Db::escape_string', $types))."')"; |
|
186 | + $where_conds[] = "caches.size $operator ('" . implode("','", array_map('\okapi\Db::escape_string', $types)) . "')"; |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | # |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | throw new InvalidParam('status', "'$name' is not a valid cache status."); |
205 | 205 | } |
206 | 206 | } |
207 | - $where_conds[] = "caches.status in ('".implode("','", array_map('\okapi\Db::escape_string', $codes))."')"; |
|
207 | + $where_conds[] = "caches.status in ('" . implode("','", array_map('\okapi\Db::escape_string', $codes)) . "')"; |
|
208 | 208 | |
209 | 209 | # |
210 | 210 | # owner_uuid |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | $user_ids = array(); |
231 | 231 | foreach ($users as $user) |
232 | 232 | $user_ids[] = $user['internal_id']; |
233 | - $where_conds[] = "caches.user_id $operator ('".implode("','", array_map('\okapi\Db::escape_string', $user_ids))."')"; |
|
233 | + $where_conds[] = "caches.user_id $operator ('" . implode("','", array_map('\okapi\Db::escape_string', $user_ids)) . "')"; |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | # |
@@ -282,8 +282,8 @@ discard block |
||
282 | 282 | # 'other' size caches will NOT be included (user must use the |
283 | 283 | # 'size2' parameter to search these). 'nano' caches will be |
284 | 284 | # included whenever 'micro' caches are included ($min=1). |
285 | - $where_conds[] = "(caches.size between $min+1 and $max+1)". |
|
286 | - ($allow_null ? " or caches.size=7" : ""). |
|
285 | + $where_conds[] = "(caches.size between $min+1 and $max+1)" . |
|
286 | + ($allow_null ? " or caches.size=7" : "") . |
|
287 | 287 | (($min == 1) ? " or caches.size=8" : ""); |
288 | 288 | } |
289 | 289 | break; |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | $divisors = array(-999, -1.0, 0.1, 1.4, 2.2, 999); |
297 | 297 | $min = $divisors[$min - 1]; |
298 | 298 | $max = $divisors[$max]; |
299 | - $where_conds[] = "($X_SCORE >= $min and $X_SCORE < $max and $X_VOTES >= 3)". |
|
299 | + $where_conds[] = "($X_SCORE >= $min and $X_SCORE < $max and $X_VOTES >= 3)" . |
|
300 | 300 | ($allow_null ? " or ($X_VOTES < 3)" : ""); |
301 | 301 | } |
302 | 302 | } |
@@ -324,12 +324,12 @@ discard block |
||
324 | 324 | if ($tmp > 100 || $tmp < 0) |
325 | 325 | throw new InvalidParam('min_rcmds', "'$tmp'"); |
326 | 326 | $tmp = floatval($tmp) / 100.0; |
327 | - $where_conds[] = "$X_TOPRATINGS >= $X_FOUNDS * '".Db::escape_string($tmp)."'"; |
|
327 | + $where_conds[] = "$X_TOPRATINGS >= $X_FOUNDS * '" . Db::escape_string($tmp) . "'"; |
|
328 | 328 | $where_conds[] = "$X_FOUNDS > 0"; |
329 | 329 | } |
330 | 330 | if (!is_numeric($tmp)) |
331 | 331 | throw new InvalidParam('min_rcmds', "'$tmp'"); |
332 | - $where_conds[] = "$X_TOPRATINGS >= '".Db::escape_string($tmp)."'"; |
|
332 | + $where_conds[] = "$X_TOPRATINGS >= '" . Db::escape_string($tmp) . "'"; |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | # |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | { |
341 | 341 | if (!is_numeric($tmp)) |
342 | 342 | throw new InvalidParam('min_founds', "'$tmp'"); |
343 | - $where_conds[] = "$X_FOUNDS >= '".Db::escape_string($tmp)."'"; |
|
343 | + $where_conds[] = "$X_FOUNDS >= '" . Db::escape_string($tmp) . "'"; |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | # |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | { |
353 | 353 | if (!is_numeric($tmp)) |
354 | 354 | throw new InvalidParam('max_founds', "'$tmp'"); |
355 | - $where_conds[] = "$X_FOUNDS <= '".Db::escape_string($tmp)."'"; |
|
355 | + $where_conds[] = "$X_FOUNDS <= '" . Db::escape_string($tmp) . "'"; |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | # |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | { |
364 | 364 | $timestamp = strtotime($tmp); |
365 | 365 | if ($timestamp) |
366 | - $where_conds[] = "unix_timestamp(caches.last_modified) > '".Db::escape_string($timestamp)."'"; |
|
366 | + $where_conds[] = "unix_timestamp(caches.last_modified) > '" . Db::escape_string($timestamp) . "'"; |
|
367 | 367 | else |
368 | 368 | throw new InvalidParam('modified_since', "'$tmp' is not in a valid format or is not a valid date."); |
369 | 369 | } |
@@ -382,7 +382,7 @@ discard block |
||
382 | 382 | { |
383 | 383 | $found_cache_ids = self::get_found_cache_ids(array($this->request->token->user_id)); |
384 | 384 | $operator = ($tmp == 'found_only') ? "in" : "not in"; |
385 | - $where_conds[] = "caches.cache_id $operator ('".implode("','", array_map('\okapi\Db::escape_string', $found_cache_ids))."')"; |
|
385 | + $where_conds[] = "caches.cache_id $operator ('" . implode("','", array_map('\okapi\Db::escape_string', $found_cache_ids)) . "')"; |
|
386 | 386 | } |
387 | 387 | } |
388 | 388 | |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | } |
401 | 401 | $internal_user_ids = array_map(create_function('$user', 'return $user["internal_id"];'), $users); |
402 | 402 | $found_cache_ids = self::get_found_cache_ids($internal_user_ids); |
403 | - $where_conds[] = "caches.cache_id in ('".implode("','", array_map('\okapi\Db::escape_string', $found_cache_ids))."')"; |
|
403 | + $where_conds[] = "caches.cache_id in ('" . implode("','", array_map('\okapi\Db::escape_string', $found_cache_ids)) . "')"; |
|
404 | 404 | } |
405 | 405 | |
406 | 406 | # |
@@ -417,7 +417,7 @@ discard block |
||
417 | 417 | } |
418 | 418 | $internal_user_ids = array_map(create_function('$user', 'return $user["internal_id"];'), $users); |
419 | 419 | $found_cache_ids = self::get_found_cache_ids($internal_user_ids); |
420 | - $where_conds[] = "caches.cache_id not in ('".implode("','", array_map('\okapi\Db::escape_string', $found_cache_ids))."')"; |
|
420 | + $where_conds[] = "caches.cache_id not in ('" . implode("','", array_map('\okapi\Db::escape_string', $found_cache_ids)) . "')"; |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | # |
@@ -435,7 +435,7 @@ discard block |
||
435 | 435 | $watched_cache_ids = Db::select_column(" |
436 | 436 | select cache_id |
437 | 437 | from cache_watches |
438 | - where user_id = '".Db::escape_string($this->request->token->user_id)."' |
|
438 | + where user_id = '".Db::escape_string($this->request->token->user_id) . "' |
|
439 | 439 | "); |
440 | 440 | if (Settings::get('OC_BRANCH') == 'oc.de') |
441 | 441 | { |
@@ -443,10 +443,10 @@ discard block |
||
443 | 443 | select cache_id |
444 | 444 | from cache_list_items cli, cache_list_watches clw |
445 | 445 | where cli.cache_list_id = clw.cache_list_id |
446 | - and clw.user_id = '".Db::escape_string($this->request->token->user_id)."' |
|
446 | + and clw.user_id = '".Db::escape_string($this->request->token->user_id) . "' |
|
447 | 447 | ")); |
448 | 448 | } |
449 | - $where_conds[] = "caches.cache_id in ('".implode("','", array_map('\okapi\Db::escape_string', $watched_cache_ids))."')"; |
|
449 | + $where_conds[] = "caches.cache_id in ('" . implode("','", array_map('\okapi\Db::escape_string', $watched_cache_ids)) . "')"; |
|
450 | 450 | } |
451 | 451 | } |
452 | 452 | |
@@ -485,10 +485,10 @@ discard block |
||
485 | 485 | $ignored_cache_ids = Db::select_column(" |
486 | 486 | select cache_id |
487 | 487 | from cache_ignore |
488 | - where user_id = '".Db::escape_string($this->request->token->user_id)."' |
|
488 | + where user_id = '".Db::escape_string($this->request->token->user_id) . "' |
|
489 | 489 | "); |
490 | 490 | $not = ($ignored_status == 'notignored_only' ? 'not' : ''); |
491 | - $where_conds[] = "caches.cache_id ".$not." in ('".implode("','", array_map('\okapi\Db::escape_string', $ignored_cache_ids))."')"; |
|
491 | + $where_conds[] = "caches.cache_id " . $not . " in ('" . implode("','", array_map('\okapi\Db::escape_string', $ignored_cache_ids)) . "')"; |
|
492 | 492 | } |
493 | 493 | |
494 | 494 | # |
@@ -502,7 +502,7 @@ discard block |
||
502 | 502 | if (!in_array($tmp, array('true', 'false'))) |
503 | 503 | throw new InvalidParam('exclude_my_own', "'$tmp'"); |
504 | 504 | if ($tmp == 'true') |
505 | - $where_conds[] = "caches.user_id != '".Db::escape_string($this->request->token->user_id)."'"; |
|
505 | + $where_conds[] = "caches.user_id != '" . Db::escape_string($this->request->token->user_id) . "'"; |
|
506 | 506 | } |
507 | 507 | |
508 | 508 | # |
@@ -517,7 +517,7 @@ discard block |
||
517 | 517 | if (strlen($tmp) > 100) |
518 | 518 | throw new InvalidParam('name', "Maximum length of 'name' parameter is 100 characters"); |
519 | 519 | $tmp = str_replace("*", "%", str_replace("%", "%%", $tmp)); |
520 | - $where_conds[] = "caches.name LIKE '".Db::escape_string($tmp)."'"; |
|
520 | + $where_conds[] = "caches.name LIKE '" . Db::escape_string($tmp) . "'"; |
|
521 | 521 | } |
522 | 522 | |
523 | 523 | # |
@@ -580,9 +580,9 @@ discard block |
||
580 | 580 | $where_conds[] = "PowerTrail.id = powerTrail_caches.powerTrailId"; |
581 | 581 | $where_conds[] = 'PowerTrail.status = 1'; |
582 | 582 | if ($powertrail_ids) { |
583 | - $where_conds[] = "PowerTrail.id in ('".implode( |
|
583 | + $where_conds[] = "PowerTrail.id in ('" . implode( |
|
584 | 584 | "','", array_map('\okapi\Db::escape_string', explode("|", $powertrail_ids)) |
585 | - )."')"; |
|
585 | + ) . "')"; |
|
586 | 586 | } |
587 | 587 | } else { |
588 | 588 | $where_conds[] = "0=1"; |
@@ -601,13 +601,13 @@ discard block |
||
601 | 601 | $exists = Db::select_value(" |
602 | 602 | select 1 |
603 | 603 | from okapi_search_sets |
604 | - where id = '".Db::escape_string($tmp)."' |
|
604 | + where id = '".Db::escape_string($tmp) . "' |
|
605 | 605 | "); |
606 | 606 | if (!$exists) |
607 | 607 | throw new InvalidParam('set_and', "Couldn't find a set by given ID."); |
608 | 608 | $extra_tables[] = "okapi_search_results osr_and"; |
609 | 609 | $where_conds[] = "osr_and.cache_id = caches.cache_id"; |
610 | - $where_conds[] = "osr_and.set_id = '".Db::escape_string($tmp)."'"; |
|
610 | + $where_conds[] = "osr_and.set_id = '" . Db::escape_string($tmp) . "'"; |
|
611 | 611 | } |
612 | 612 | |
613 | 613 | # |
@@ -682,8 +682,8 @@ discard block |
||
682 | 682 | # To avoid join errors, put each of the $where_conds in extra paranthesis. |
683 | 683 | |
684 | 684 | $tmp = array(); |
685 | - foreach($where_conds as $cond) |
|
686 | - $tmp[] = "(".$cond.")"; |
|
685 | + foreach ($where_conds as $cond) |
|
686 | + $tmp[] = "(" . $cond . ")"; |
|
687 | 687 | $where_conds = $tmp; |
688 | 688 | unset($tmp); |
689 | 689 | |
@@ -718,7 +718,7 @@ discard block |
||
718 | 718 | public function get_common_search_result() |
719 | 719 | { |
720 | 720 | $tables = array_merge( |
721 | - array('caches '.$this->search_params['caches_indexhint']), |
|
721 | + array('caches ' . $this->search_params['caches_indexhint']), |
|
722 | 722 | $this->search_params['extra_tables'] |
723 | 723 | ); |
724 | 724 | $where_conds = array_merge( |
@@ -731,11 +731,11 @@ discard block |
||
731 | 731 | |
732 | 732 | $cache_codes = Db::select_column(" |
733 | 733 | select caches.wp_oc |
734 | - from ".implode(", ", $tables)." ". |
|
735 | - implode(" ", $this->search_params['extra_joins'])." |
|
736 | - where ".implode(" and ", $where_conds)." |
|
737 | - ".((count($this->search_params['order_by']) > 0) ? "order by ".implode(", ", $this->search_params['order_by']) : "")." |
|
738 | - limit ".($this->search_params['offset']).", ".($this->search_params['limit'] + 1)."; |
|
734 | + from ".implode(", ", $tables) . " " . |
|
735 | + implode(" ", $this->search_params['extra_joins']) . " |
|
736 | + where ".implode(" and ", $where_conds) . " |
|
737 | + ".((count($this->search_params['order_by']) > 0) ? "order by " . implode(", ", $this->search_params['order_by']) : "") . " |
|
738 | + limit ".($this->search_params['offset']) . ", " . ($this->search_params['limit'] + 1) . "; |
|
739 | 739 | "); |
740 | 740 | |
741 | 741 | if (count($cache_codes) > $this->search_params['limit']) |
@@ -773,7 +773,7 @@ discard block |
||
773 | 773 | # Make sure location_source has prefix alt_wpt: |
774 | 774 | if ($location_source != 'default-coords' && strncmp($location_source, 'alt_wpt:', 8) != 0) |
775 | 775 | { |
776 | - throw new InvalidParam('location_source', '\''.$location_source.'\''); |
|
776 | + throw new InvalidParam('location_source', '\'' . $location_source . '\''); |
|
777 | 777 | } |
778 | 778 | |
779 | 779 | # Make sure we have sufficient authorization |
@@ -800,7 +800,7 @@ discard block |
||
800 | 800 | $extra_joins = array(" |
801 | 801 | left join cache_mod_cords |
802 | 802 | on cache_mod_cords.cache_id = caches.cache_id |
803 | - and cache_mod_cords.user_id = '".Db::escape_string($this->request->token->user_id)."' |
|
803 | + and cache_mod_cords.user_id = '".Db::escape_string($this->request->token->user_id) . "' |
|
804 | 804 | "); |
805 | 805 | } else { |
806 | 806 | # oc.de |
@@ -809,7 +809,7 @@ discard block |
||
809 | 809 | $extra_joins = array(" |
810 | 810 | left join coordinates |
811 | 811 | on coordinates.cache_id = caches.cache_id |
812 | - and coordinates.user_id = '".Db::escape_string($this->request->token->user_id)."' |
|
812 | + and coordinates.user_id = '".Db::escape_string($this->request->token->user_id) . "' |
|
813 | 813 | and coordinates.type = 2 |
814 | 814 | and coordinates.longitude != 0 |
815 | 815 | and coordinates.latitude != 0 |
@@ -855,12 +855,12 @@ discard block |
||
855 | 855 | select cache_id |
856 | 856 | from cache_logs |
857 | 857 | where |
858 | - user_id in ('".implode("','", array_map('\okapi\Db::escape_string', $internal_user_ids))."') |
|
858 | + user_id in ('".implode("','", array_map('\okapi\Db::escape_string', $internal_user_ids)) . "') |
|
859 | 859 | and type in ( |
860 | - '".Db::escape_string(Okapi::logtypename2id("Found it"))."', |
|
861 | - '".Db::escape_string(Okapi::logtypename2id("Attended"))."' |
|
860 | + '".Db::escape_string(Okapi::logtypename2id("Found it")) . "', |
|
861 | + '".Db::escape_string(Okapi::logtypename2id("Attended")) . "' |
|
862 | 862 | ) |
863 | - and ".((Settings::get('OC_BRANCH') == 'oc.pl') ? "deleted = 0" : "true")." |
|
863 | + and ".((Settings::get('OC_BRANCH') == 'oc.pl') ? "deleted = 0" : "true") . " |
|
864 | 864 | "); |
865 | 865 | } |
866 | 866 | } |
@@ -107,8 +107,7 @@ discard block |
||
107 | 107 | $X_LAST_FOUND = 'caches.last_found'; |
108 | 108 | $X_VOTES = 'caches.votes'; |
109 | 109 | $X_SCORE = 'caches.score'; |
110 | - } |
|
111 | - else |
|
110 | + } else |
|
112 | 111 | { |
113 | 112 | # OCDE holds this data in a separate table. Additionally, OCDE |
114 | 113 | # does not provide a rating system (votes and score fields). |
@@ -146,16 +145,16 @@ discard block |
||
146 | 145 | { |
147 | 146 | $id = Okapi::cache_type_name2id($name); |
148 | 147 | $types[] = $id; |
149 | - } |
|
150 | - catch (Exception $e) |
|
148 | + } catch (Exception $e) |
|
151 | 149 | { |
152 | 150 | throw new InvalidParam('type', "'$name' is not a valid cache type."); |
153 | 151 | } |
154 | 152 | } |
155 | - if (count($types) > 0) |
|
156 | - $where_conds[] = "caches.type $operator ('".implode("','", array_map('\okapi\Db::escape_string', $types))."')"; |
|
157 | - else if ($operator == "in") |
|
158 | - $where_conds[] = "false"; |
|
153 | + if (count($types) > 0) { |
|
154 | + $where_conds[] = "caches.type $operator ('".implode("','", array_map('\okapi\Db::escape_string', $types))."')"; |
|
155 | + } else if ($operator == "in") { |
|
156 | + $where_conds[] = "false"; |
|
157 | + } |
|
159 | 158 | } |
160 | 159 | |
161 | 160 | # |
@@ -177,8 +176,7 @@ discard block |
||
177 | 176 | { |
178 | 177 | $id = Okapi::cache_size2_to_sizeid($name); |
179 | 178 | $types[] = $id; |
180 | - } |
|
181 | - catch (Exception $e) |
|
179 | + } catch (Exception $e) |
|
182 | 180 | { |
183 | 181 | throw new InvalidParam('size2', "'$name' is not a valid cache size."); |
184 | 182 | } |
@@ -191,15 +189,16 @@ discard block |
||
191 | 189 | # |
192 | 190 | |
193 | 191 | $tmp = $this->request->get_parameter('status'); |
194 | - if ($tmp == null) $tmp = "Available"; |
|
192 | + if ($tmp == null) { |
|
193 | + $tmp = "Available"; |
|
194 | + } |
|
195 | 195 | $codes = array(); |
196 | 196 | foreach (explode("|", $tmp) as $name) |
197 | 197 | { |
198 | 198 | try |
199 | 199 | { |
200 | 200 | $codes[] = Okapi::cache_status_name2id($name); |
201 | - } |
|
202 | - catch (Exception $e) |
|
201 | + } catch (Exception $e) |
|
203 | 202 | { |
204 | 203 | throw new InvalidParam('status', "'$name' is not a valid cache status."); |
205 | 204 | } |
@@ -222,14 +221,14 @@ discard block |
||
222 | 221 | { |
223 | 222 | $users = OkapiServiceRunner::call("services/users/users", new OkapiInternalRequest( |
224 | 223 | $this->request->consumer, null, array('user_uuids' => $tmp, 'fields' => 'internal_id'))); |
225 | - } |
|
226 | - catch (InvalidParam $e) # invalid uuid |
|
224 | + } catch (InvalidParam $e) # invalid uuid |
|
227 | 225 | { |
228 | 226 | throw new InvalidParam('owner_uuid', $e->whats_wrong_about_it); |
229 | 227 | } |
230 | 228 | $user_ids = array(); |
231 | - foreach ($users as $user) |
|
232 | - $user_ids[] = $user['internal_id']; |
|
229 | + foreach ($users as $user) { |
|
230 | + $user_ids[] = $user['internal_id']; |
|
231 | + } |
|
233 | 232 | $where_conds[] = "caches.user_id $operator ('".implode("','", array_map('\okapi\Db::escape_string', $user_ids))."')"; |
234 | 233 | } |
235 | 234 | |
@@ -241,8 +240,9 @@ discard block |
||
241 | 240 | { |
242 | 241 | if ($tmp = $this->request->get_parameter($param_name)) |
243 | 242 | { |
244 | - if (!preg_match("/^[1-5]-[1-5](\|X)?$/", $tmp)) |
|
245 | - throw new InvalidParam($param_name, "'$tmp'"); |
|
243 | + if (!preg_match("/^[1-5]-[1-5](\|X)?$/", $tmp)) { |
|
244 | + throw new InvalidParam($param_name, "'$tmp'"); |
|
245 | + } |
|
246 | 246 | list($min, $max) = explode("-", $tmp); |
247 | 247 | if (strpos($max, "|X") !== false) |
248 | 248 | { |
@@ -251,13 +251,15 @@ discard block |
||
251 | 251 | } else { |
252 | 252 | $allow_null = false; |
253 | 253 | } |
254 | - if ($min > $max) |
|
255 | - throw new InvalidParam($param_name, "'$tmp'"); |
|
254 | + if ($min > $max) { |
|
255 | + throw new InvalidParam($param_name, "'$tmp'"); |
|
256 | + } |
|
256 | 257 | switch ($param_name) |
257 | 258 | { |
258 | 259 | case 'terrain': |
259 | - if ($allow_null) |
|
260 | - throw new InvalidParam($param_name, "The '|X' suffix is not allowed here."); |
|
260 | + if ($allow_null) { |
|
261 | + throw new InvalidParam($param_name, "The '|X' suffix is not allowed here."); |
|
262 | + } |
|
261 | 263 | if (($min == 1) && ($max == 5)) { |
262 | 264 | /* no extra condition necessary */ |
263 | 265 | } else { |
@@ -265,8 +267,9 @@ discard block |
||
265 | 267 | } |
266 | 268 | break; |
267 | 269 | case 'difficulty': |
268 | - if ($allow_null) |
|
269 | - throw new InvalidParam($param_name, "The '|X' suffix is not allowed here."); |
|
270 | + if ($allow_null) { |
|
271 | + throw new InvalidParam($param_name, "The '|X' suffix is not allowed here."); |
|
272 | + } |
|
270 | 273 | if (($min == 1) && ($max == 5)) { |
271 | 274 | /* no extra condition necessary */ |
272 | 275 | } else { |
@@ -299,8 +302,7 @@ discard block |
||
299 | 302 | $where_conds[] = "($X_SCORE >= $min and $X_SCORE < $max and $X_VOTES >= 3)". |
300 | 303 | ($allow_null ? " or ($X_VOTES < 3)" : ""); |
301 | 304 | } |
302 | - } |
|
303 | - else |
|
305 | + } else |
|
304 | 306 | { |
305 | 307 | # OCDE does not support rating. We will ignore this parameter. |
306 | 308 | } |
@@ -318,17 +320,20 @@ discard block |
||
318 | 320 | if ($tmp[strlen($tmp) - 1] == '%') |
319 | 321 | { |
320 | 322 | $tmp = substr($tmp, 0, strlen($tmp) - 1); |
321 | - if (!is_numeric($tmp)) |
|
322 | - throw new InvalidParam('min_rcmds', "'$tmp'"); |
|
323 | + if (!is_numeric($tmp)) { |
|
324 | + throw new InvalidParam('min_rcmds', "'$tmp'"); |
|
325 | + } |
|
323 | 326 | $tmp = intval($tmp); |
324 | - if ($tmp > 100 || $tmp < 0) |
|
325 | - throw new InvalidParam('min_rcmds', "'$tmp'"); |
|
327 | + if ($tmp > 100 || $tmp < 0) { |
|
328 | + throw new InvalidParam('min_rcmds', "'$tmp'"); |
|
329 | + } |
|
326 | 330 | $tmp = floatval($tmp) / 100.0; |
327 | 331 | $where_conds[] = "$X_TOPRATINGS >= $X_FOUNDS * '".Db::escape_string($tmp)."'"; |
328 | 332 | $where_conds[] = "$X_FOUNDS > 0"; |
329 | 333 | } |
330 | - if (!is_numeric($tmp)) |
|
331 | - throw new InvalidParam('min_rcmds', "'$tmp'"); |
|
334 | + if (!is_numeric($tmp)) { |
|
335 | + throw new InvalidParam('min_rcmds', "'$tmp'"); |
|
336 | + } |
|
332 | 337 | $where_conds[] = "$X_TOPRATINGS >= '".Db::escape_string($tmp)."'"; |
333 | 338 | } |
334 | 339 | |
@@ -338,8 +343,9 @@ discard block |
||
338 | 343 | |
339 | 344 | if ($tmp = $this->request->get_parameter('min_founds')) |
340 | 345 | { |
341 | - if (!is_numeric($tmp)) |
|
342 | - throw new InvalidParam('min_founds', "'$tmp'"); |
|
346 | + if (!is_numeric($tmp)) { |
|
347 | + throw new InvalidParam('min_founds', "'$tmp'"); |
|
348 | + } |
|
343 | 349 | $where_conds[] = "$X_FOUNDS >= '".Db::escape_string($tmp)."'"; |
344 | 350 | } |
345 | 351 | |
@@ -350,8 +356,9 @@ discard block |
||
350 | 356 | |
351 | 357 | if (!is_null($tmp = $this->request->get_parameter('max_founds'))) |
352 | 358 | { |
353 | - if (!is_numeric($tmp)) |
|
354 | - throw new InvalidParam('max_founds', "'$tmp'"); |
|
359 | + if (!is_numeric($tmp)) { |
|
360 | + throw new InvalidParam('max_founds', "'$tmp'"); |
|
361 | + } |
|
355 | 362 | $where_conds[] = "$X_FOUNDS <= '".Db::escape_string($tmp)."'"; |
356 | 363 | } |
357 | 364 | |
@@ -362,10 +369,11 @@ discard block |
||
362 | 369 | if ($tmp = $this->request->get_parameter('modified_since')) |
363 | 370 | { |
364 | 371 | $timestamp = strtotime($tmp); |
365 | - if ($timestamp) |
|
366 | - $where_conds[] = "unix_timestamp(caches.last_modified) > '".Db::escape_string($timestamp)."'"; |
|
367 | - else |
|
368 | - throw new InvalidParam('modified_since', "'$tmp' is not in a valid format or is not a valid date."); |
|
372 | + if ($timestamp) { |
|
373 | + $where_conds[] = "unix_timestamp(caches.last_modified) > '".Db::escape_string($timestamp)."'"; |
|
374 | + } else { |
|
375 | + throw new InvalidParam('modified_since', "'$tmp' is not in a valid format or is not a valid date."); |
|
376 | + } |
|
369 | 377 | } |
370 | 378 | |
371 | 379 | # |
@@ -374,10 +382,12 @@ discard block |
||
374 | 382 | |
375 | 383 | if ($tmp = $this->request->get_parameter('found_status')) |
376 | 384 | { |
377 | - if ($this->request->token == null) |
|
378 | - throw new InvalidParam('found_status', "Might be used only for requests signed with an Access Token."); |
|
379 | - if (!in_array($tmp, array('found_only', 'notfound_only', 'either'))) |
|
380 | - throw new InvalidParam('found_status', "'$tmp'"); |
|
385 | + if ($this->request->token == null) { |
|
386 | + throw new InvalidParam('found_status', "Might be used only for requests signed with an Access Token."); |
|
387 | + } |
|
388 | + if (!in_array($tmp, array('found_only', 'notfound_only', 'either'))) { |
|
389 | + throw new InvalidParam('found_status', "'$tmp'"); |
|
390 | + } |
|
381 | 391 | if ($tmp != 'either') |
382 | 392 | { |
383 | 393 | $found_cache_ids = self::get_found_cache_ids(array($this->request->token->user_id)); |
@@ -426,10 +436,12 @@ discard block |
||
426 | 436 | |
427 | 437 | if ($tmp = $this->request->get_parameter('watched_only')) |
428 | 438 | { |
429 | - if ($this->request->token == null) |
|
430 | - throw new InvalidParam('watched_only', "Might be used only for requests signed with an Access Token."); |
|
431 | - if (!in_array($tmp, array('true', 'false'))) |
|
432 | - throw new InvalidParam('watched_only', "'$tmp'"); |
|
439 | + if ($this->request->token == null) { |
|
440 | + throw new InvalidParam('watched_only', "Might be used only for requests signed with an Access Token."); |
|
441 | + } |
|
442 | + if (!in_array($tmp, array('true', 'false'))) { |
|
443 | + throw new InvalidParam('watched_only', "'$tmp'"); |
|
444 | + } |
|
433 | 445 | if ($tmp == 'true') |
434 | 446 | { |
435 | 447 | $watched_cache_ids = Db::select_column(" |
@@ -457,30 +469,35 @@ discard block |
||
457 | 469 | $ignored_status = 'either'; |
458 | 470 | if ($tmp = $this->request->get_parameter('exclude_ignored')) |
459 | 471 | { |
460 | - if ($this->request->token == null) |
|
461 | - throw new InvalidParam('exclude_ignored', "Might be used only for requests signed with an Access Token."); |
|
462 | - if ($tmp == 'true') |
|
463 | - $ignored_status = 'notignored_only'; |
|
464 | - elseif ($tmp != 'false') |
|
465 | - throw new InvalidParam('exclude_ignored', "'$tmp'"); |
|
472 | + if ($this->request->token == null) { |
|
473 | + throw new InvalidParam('exclude_ignored', "Might be used only for requests signed with an Access Token."); |
|
474 | + } |
|
475 | + if ($tmp == 'true') { |
|
476 | + $ignored_status = 'notignored_only'; |
|
477 | + } elseif ($tmp != 'false') { |
|
478 | + throw new InvalidParam('exclude_ignored', "'$tmp'"); |
|
479 | + } |
|
466 | 480 | } |
467 | 481 | if ($tmp = $this->request->get_parameter('ignored_status')) |
468 | 482 | { |
469 | - if ($this->request->token == null) |
|
470 | - throw new InvalidParam('ignored_status', "Might be used only for requests signed with an Access Token."); |
|
471 | - if (!in_array($tmp, array('ignored_only', 'notignored_only', 'either'))) |
|
472 | - throw new InvalidParam('ignored_status', "'$tmp'"); |
|
483 | + if ($this->request->token == null) { |
|
484 | + throw new InvalidParam('ignored_status', "Might be used only for requests signed with an Access Token."); |
|
485 | + } |
|
486 | + if (!in_array($tmp, array('ignored_only', 'notignored_only', 'either'))) { |
|
487 | + throw new InvalidParam('ignored_status', "'$tmp'"); |
|
488 | + } |
|
473 | 489 | if ($tmp != 'either') { |
474 | - if ($tmp == 'ignored_only' && $ignored_status == 'notignored_only') |
|
475 | - $ignored_status = 'none'; |
|
476 | - else |
|
477 | - $ignored_status = $tmp; |
|
490 | + if ($tmp == 'ignored_only' && $ignored_status == 'notignored_only') { |
|
491 | + $ignored_status = 'none'; |
|
492 | + } else { |
|
493 | + $ignored_status = $tmp; |
|
494 | + } |
|
478 | 495 | } |
479 | 496 | } |
480 | 497 | |
481 | - if ($ignored_status == 'none') |
|
482 | - $where_conds[] = 'false'; |
|
483 | - elseif ($ignored_status != 'either') |
|
498 | + if ($ignored_status == 'none') { |
|
499 | + $where_conds[] = 'false'; |
|
500 | + } elseif ($ignored_status != 'either') |
|
484 | 501 | { |
485 | 502 | $ignored_cache_ids = Db::select_column(" |
486 | 503 | select cache_id |
@@ -497,12 +514,15 @@ discard block |
||
497 | 514 | |
498 | 515 | if ($tmp = $this->request->get_parameter('exclude_my_own')) |
499 | 516 | { |
500 | - if ($this->request->token == null) |
|
501 | - throw new InvalidParam('exclude_my_own', "Might be used only for requests signed with an Access Token."); |
|
502 | - if (!in_array($tmp, array('true', 'false'))) |
|
503 | - throw new InvalidParam('exclude_my_own', "'$tmp'"); |
|
504 | - if ($tmp == 'true') |
|
505 | - $where_conds[] = "caches.user_id != '".Db::escape_string($this->request->token->user_id)."'"; |
|
517 | + if ($this->request->token == null) { |
|
518 | + throw new InvalidParam('exclude_my_own', "Might be used only for requests signed with an Access Token."); |
|
519 | + } |
|
520 | + if (!in_array($tmp, array('true', 'false'))) { |
|
521 | + throw new InvalidParam('exclude_my_own', "'$tmp'"); |
|
522 | + } |
|
523 | + if ($tmp == 'true') { |
|
524 | + $where_conds[] = "caches.user_id != '".Db::escape_string($this->request->token->user_id)."'"; |
|
525 | + } |
|
506 | 526 | } |
507 | 527 | |
508 | 528 | # |
@@ -514,8 +534,9 @@ discard block |
||
514 | 534 | # WRTODO: Make this more user-friendly. See: |
515 | 535 | # https://github.com/opencaching/okapi/issues/121 |
516 | 536 | |
517 | - if (strlen($tmp) > 100) |
|
518 | - throw new InvalidParam('name', "Maximum length of 'name' parameter is 100 characters"); |
|
537 | + if (strlen($tmp) > 100) { |
|
538 | + throw new InvalidParam('name', "Maximum length of 'name' parameter is 100 characters"); |
|
539 | + } |
|
519 | 540 | $tmp = str_replace("*", "%", str_replace("%", "%%", $tmp)); |
520 | 541 | $where_conds[] = "caches.name LIKE '".Db::escape_string($tmp)."'"; |
521 | 542 | } |
@@ -526,8 +547,9 @@ discard block |
||
526 | 547 | |
527 | 548 | if ($tmp = $this->request->get_parameter('with_trackables_only')) |
528 | 549 | { |
529 | - if (!in_array($tmp, array('true', 'false'), 1)) |
|
530 | - throw new InvalidParam('with_trackables_only', "'$tmp'"); |
|
550 | + if (!in_array($tmp, array('true', 'false'), 1)) { |
|
551 | + throw new InvalidParam('with_trackables_only', "'$tmp'"); |
|
552 | + } |
|
531 | 553 | if ($tmp == 'true') |
532 | 554 | { |
533 | 555 | $where_conds[] = " |
@@ -545,8 +567,9 @@ discard block |
||
545 | 567 | |
546 | 568 | if ($tmp = $this->request->get_parameter('ftf_hunter')) |
547 | 569 | { |
548 | - if (!in_array($tmp, array('true', 'false'), 1)) |
|
549 | - throw new InvalidParam('ftf_hunter', "'$tmp'"); |
|
570 | + if (!in_array($tmp, array('true', 'false'), 1)) { |
|
571 | + throw new InvalidParam('ftf_hunter', "'$tmp'"); |
|
572 | + } |
|
550 | 573 | if ($tmp == 'true') |
551 | 574 | { |
552 | 575 | $where_conds[] = "$X_FOUNDS = 0"; |
@@ -603,8 +626,9 @@ discard block |
||
603 | 626 | from okapi_search_sets |
604 | 627 | where id = '".Db::escape_string($tmp)."' |
605 | 628 | "); |
606 | - if (!$exists) |
|
607 | - throw new InvalidParam('set_and', "Couldn't find a set by given ID."); |
|
629 | + if (!$exists) { |
|
630 | + throw new InvalidParam('set_and', "Couldn't find a set by given ID."); |
|
631 | + } |
|
608 | 632 | $extra_tables[] = "okapi_search_results osr_and"; |
609 | 633 | $where_conds[] = "osr_and.cache_id = caches.cache_id"; |
610 | 634 | $where_conds[] = "osr_and.set_id = '".Db::escape_string($tmp)."'"; |
@@ -615,34 +639,43 @@ discard block |
||
615 | 639 | # |
616 | 640 | |
617 | 641 | $limit = $this->request->get_parameter('limit'); |
618 | - if ($limit == null) $limit = "100"; |
|
619 | - if (!is_numeric($limit)) |
|
620 | - throw new InvalidParam('limit', "'$limit'"); |
|
621 | - if ($limit < 1 || (($limit > 500) && (!$this->request->skip_limits))) |
|
622 | - throw new InvalidParam( |
|
642 | + if ($limit == null) { |
|
643 | + $limit = "100"; |
|
644 | + } |
|
645 | + if (!is_numeric($limit)) { |
|
646 | + throw new InvalidParam('limit', "'$limit'"); |
|
647 | + } |
|
648 | + if ($limit < 1 || (($limit > 500) && (!$this->request->skip_limits))) { |
|
649 | + throw new InvalidParam( |
|
623 | 650 | 'limit', |
624 | 651 | $this->request->skip_limits |
625 | 652 | ? "Cannot be lower than 1." |
626 | 653 | : "Has to be between 1 and 500." |
627 | 654 | ); |
655 | + } |
|
628 | 656 | |
629 | 657 | # |
630 | 658 | # offset |
631 | 659 | # |
632 | 660 | |
633 | 661 | $offset = $this->request->get_parameter('offset'); |
634 | - if ($offset == null) $offset = "0"; |
|
635 | - if (!is_numeric($offset)) |
|
636 | - throw new InvalidParam('offset', "'$offset'"); |
|
637 | - if (($offset + $limit > 500) && (!$this->request->skip_limits)) |
|
638 | - throw new BadRequest("The sum of offset and limit may not exceed 500."); |
|
639 | - if ($offset < 0 || (($offset > 499) && (!$this->request->skip_limits))) |
|
640 | - throw new InvalidParam( |
|
662 | + if ($offset == null) { |
|
663 | + $offset = "0"; |
|
664 | + } |
|
665 | + if (!is_numeric($offset)) { |
|
666 | + throw new InvalidParam('offset', "'$offset'"); |
|
667 | + } |
|
668 | + if (($offset + $limit > 500) && (!$this->request->skip_limits)) { |
|
669 | + throw new BadRequest("The sum of offset and limit may not exceed 500."); |
|
670 | + } |
|
671 | + if ($offset < 0 || (($offset > 499) && (!$this->request->skip_limits))) { |
|
672 | + throw new InvalidParam( |
|
641 | 673 | 'offset', |
642 | 674 | $this->request->skip_limits |
643 | 675 | ? "Cannot be lower than 0." |
644 | 676 | : "Has to be between 0 and 499." |
645 | 677 | ); |
678 | + } |
|
646 | 679 | |
647 | 680 | # |
648 | 681 | # order_by |
@@ -660,9 +693,10 @@ discard block |
||
660 | 693 | { |
661 | 694 | $dir = 'desc'; |
662 | 695 | $field = substr($field, 1); |
696 | + } elseif ($field[0] == '+') { |
|
697 | + $field = substr($field, 1); |
|
663 | 698 | } |
664 | - elseif ($field[0] == '+') |
|
665 | - $field = substr($field, 1); # ignore leading "+" |
|
699 | + # ignore leading "+" |
|
666 | 700 | switch ($field) |
667 | 701 | { |
668 | 702 | case 'code': $cl = "caches.wp_oc"; break; |
@@ -682,8 +716,9 @@ discard block |
||
682 | 716 | # To avoid join errors, put each of the $where_conds in extra paranthesis. |
683 | 717 | |
684 | 718 | $tmp = array(); |
685 | - foreach($where_conds as $cond) |
|
686 | - $tmp[] = "(".$cond.")"; |
|
719 | + foreach($where_conds as $cond) { |
|
720 | + $tmp[] = "(".$cond.")"; |
|
721 | + } |
|
687 | 722 | $where_conds = $tmp; |
688 | 723 | unset($tmp); |
689 | 724 | |
@@ -767,8 +802,9 @@ discard block |
||
767 | 802 | public function prepare_location_search_params() |
768 | 803 | { |
769 | 804 | $location_source = $this->request->get_parameter('location_source'); |
770 | - if (!$location_source) |
|
771 | - $location_source = 'default-coords'; |
|
805 | + if (!$location_source) { |
|
806 | + $location_source = 'default-coords'; |
|
807 | + } |
|
772 | 808 | |
773 | 809 | # Make sure location_source has prefix alt_wpt: |
774 | 810 | if ($location_source != 'default-coords' && strncmp($location_source, 'alt_wpt:', 8) != 0) |
@@ -68,8 +68,8 @@ discard block |
||
68 | 68 | } |
69 | 69 | catch (BadRequest $e) |
70 | 70 | { |
71 | - throw new InvalidParam('search_params', "Search method responded with the ". |
|
72 | - "following error message: ".$e->getMessage()); |
|
71 | + throw new InvalidParam('search_params', "Search method responded with the " . |
|
72 | + "following error message: " . $e->getMessage()); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | # Run retrieval method |
@@ -81,8 +81,8 @@ discard block |
||
81 | 81 | } |
82 | 82 | catch (BadRequest $e) |
83 | 83 | { |
84 | - throw new InvalidParam('retr_params', "Retrieval method responded with the ". |
|
85 | - "following error message: ".$e->getMessage()); |
|
84 | + throw new InvalidParam('retr_params', "Retrieval method responded with the " . |
|
85 | + "following error message: " . $e->getMessage()); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | if ($wrap) |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | if (is_numeric($val) || is_string($val)) |
116 | 116 | $dict[$key] = (string)$val; |
117 | 117 | else |
118 | - throw new BadRequest("Invalid value format for key: ".$key); |
|
118 | + throw new BadRequest("Invalid value format for key: " . $key); |
|
119 | 119 | } |
120 | 120 | } |
121 | 121 | } |
@@ -24,40 +24,52 @@ discard block |
||
24 | 24 | { |
25 | 25 | # Check search method |
26 | 26 | $search_method = $request->get_parameter('search_method'); |
27 | - if (!$search_method) |
|
28 | - throw new ParamMissing('search_method'); |
|
29 | - if (strpos($search_method, "services/caches/search/") !== 0) |
|
30 | - throw new InvalidParam('search_method', "Should begin with 'services/caches/search/'."); |
|
31 | - if (!OkapiServiceRunner::exists($search_method)) |
|
32 | - throw new InvalidParam('search_method', "Method does not exist: '$search_method'"); |
|
27 | + if (!$search_method) { |
|
28 | + throw new ParamMissing('search_method'); |
|
29 | + } |
|
30 | + if (strpos($search_method, "services/caches/search/") !== 0) { |
|
31 | + throw new InvalidParam('search_method', "Should begin with 'services/caches/search/'."); |
|
32 | + } |
|
33 | + if (!OkapiServiceRunner::exists($search_method)) { |
|
34 | + throw new InvalidParam('search_method', "Method does not exist: '$search_method'"); |
|
35 | + } |
|
33 | 36 | $search_params = $request->get_parameter('search_params'); |
34 | - if (!$search_params) |
|
35 | - throw new ParamMissing('search_params'); |
|
37 | + if (!$search_params) { |
|
38 | + throw new ParamMissing('search_params'); |
|
39 | + } |
|
36 | 40 | $search_params = json_decode($search_params, true); |
37 | - if (!is_array($search_params)) |
|
38 | - throw new InvalidParam('search_params', "Should be a JSON-encoded dictionary"); |
|
41 | + if (!is_array($search_params)) { |
|
42 | + throw new InvalidParam('search_params', "Should be a JSON-encoded dictionary"); |
|
43 | + } |
|
39 | 44 | |
40 | 45 | # Check retrieval method |
41 | 46 | $retr_method = $request->get_parameter('retr_method'); |
42 | - if (!$retr_method) |
|
43 | - throw new ParamMissing('retr_method'); |
|
44 | - if (!OkapiServiceRunner::exists($retr_method)) |
|
45 | - throw new InvalidParam('retr_method', "Method does not exist: '$retr_method'"); |
|
47 | + if (!$retr_method) { |
|
48 | + throw new ParamMissing('retr_method'); |
|
49 | + } |
|
50 | + if (!OkapiServiceRunner::exists($retr_method)) { |
|
51 | + throw new InvalidParam('retr_method', "Method does not exist: '$retr_method'"); |
|
52 | + } |
|
46 | 53 | $retr_params = $request->get_parameter('retr_params'); |
47 | - if (!$retr_params) |
|
48 | - throw new ParamMissing('retr_params'); |
|
54 | + if (!$retr_params) { |
|
55 | + throw new ParamMissing('retr_params'); |
|
56 | + } |
|
49 | 57 | $retr_params = json_decode($retr_params, true); |
50 | - if (!is_array($retr_params)) |
|
51 | - throw new InvalidParam('retr_params', "Should be a JSON-encoded dictionary"); |
|
58 | + if (!is_array($retr_params)) { |
|
59 | + throw new InvalidParam('retr_params', "Should be a JSON-encoded dictionary"); |
|
60 | + } |
|
52 | 61 | |
53 | 62 | self::map_values_to_strings($search_params); |
54 | 63 | self::map_values_to_strings($retr_params); |
55 | 64 | |
56 | 65 | # Wrapped? |
57 | 66 | $wrap = $request->get_parameter('wrap'); |
58 | - if ($wrap == null) throw new ParamMissing('wrap'); |
|
59 | - if (!in_array($wrap, array('true', 'false'))) |
|
60 | - throw new InvalidParam('wrap'); |
|
67 | + if ($wrap == null) { |
|
68 | + throw new ParamMissing('wrap'); |
|
69 | + } |
|
70 | + if (!in_array($wrap, array('true', 'false'))) { |
|
71 | + throw new InvalidParam('wrap'); |
|
72 | + } |
|
61 | 73 | $wrap = ($wrap == 'true'); |
62 | 74 | |
63 | 75 | # Run search method |
@@ -65,8 +77,7 @@ discard block |
||
65 | 77 | { |
66 | 78 | $search_result = OkapiServiceRunner::call($search_method, new OkapiInternalRequest( |
67 | 79 | $request->consumer, $request->token, $search_params)); |
68 | - } |
|
69 | - catch (BadRequest $e) |
|
80 | + } catch (BadRequest $e) |
|
70 | 81 | { |
71 | 82 | throw new InvalidParam('search_params', "Search method responded with the ". |
72 | 83 | "following error message: ".$e->getMessage()); |
@@ -78,8 +89,7 @@ discard block |
||
78 | 89 | $retr_result = OkapiServiceRunner::call($retr_method, new OkapiInternalRequest( |
79 | 90 | $request->consumer, $request->token, array_merge($retr_params, |
80 | 91 | array('cache_codes' => implode("|", $search_result['results']))))); |
81 | - } |
|
82 | - catch (BadRequest $e) |
|
92 | + } catch (BadRequest $e) |
|
83 | 93 | { |
84 | 94 | throw new InvalidParam('retr_params', "Retrieval method responded with the ". |
85 | 95 | "following error message: ".$e->getMessage()); |
@@ -89,21 +99,23 @@ discard block |
||
89 | 99 | { |
90 | 100 | # $retr_result might be a PHP object, but also might be a binary response |
91 | 101 | # (e.g. a GPX file). |
92 | - if ($retr_result instanceof OkapiHttpResponse) |
|
93 | - $result = array('results' => $retr_result->get_body()); |
|
94 | - else |
|
95 | - $result = array('results' => $retr_result); |
|
96 | - foreach ($search_result as $key => &$value_ref) |
|
97 | - if ($key != 'results') |
|
102 | + if ($retr_result instanceof OkapiHttpResponse) { |
|
103 | + $result = array('results' => $retr_result->get_body()); |
|
104 | + } else { |
|
105 | + $result = array('results' => $retr_result); |
|
106 | + } |
|
107 | + foreach ($search_result as $key => &$value_ref) { |
|
108 | + if ($key != 'results') |
|
98 | 109 | $result[$key] = $value_ref; |
110 | + } |
|
99 | 111 | return Okapi::formatted_response($request, $result); |
100 | - } |
|
101 | - else |
|
112 | + } else |
|
102 | 113 | { |
103 | - if ($retr_result instanceof OkapiHttpResponse) |
|
104 | - return $retr_result; |
|
105 | - else |
|
106 | - return Okapi::formatted_response($request, $retr_result); |
|
114 | + if ($retr_result instanceof OkapiHttpResponse) { |
|
115 | + return $retr_result; |
|
116 | + } else { |
|
117 | + return Okapi::formatted_response($request, $retr_result); |
|
118 | + } |
|
107 | 119 | } |
108 | 120 | } |
109 | 121 | |
@@ -112,10 +124,11 @@ discard block |
||
112 | 124 | foreach (array_keys($dict) as $key) |
113 | 125 | { |
114 | 126 | $val = $dict[$key]; |
115 | - if (is_numeric($val) || is_string($val)) |
|
116 | - $dict[$key] = (string)$val; |
|
117 | - else |
|
118 | - throw new BadRequest("Invalid value format for key: ".$key); |
|
127 | + if (is_numeric($val) || is_string($val)) { |
|
128 | + $dict[$key] = (string)$val; |
|
129 | + } else { |
|
130 | + throw new BadRequest("Invalid value format for key: ".$key); |
|
131 | + } |
|
119 | 132 | } |
120 | 133 | } |
121 | 134 | } |
@@ -46,16 +46,16 @@ discard block |
||
46 | 46 | Db::execute(" |
47 | 47 | insert ignore into cache_watches (cache_id, user_id) |
48 | 48 | values ( |
49 | - '".Db::escape_string($geocache['internal_id'])."', |
|
50 | - '".Db::escape_string($request->token->user_id)."' |
|
49 | + '".Db::escape_string($geocache['internal_id']) . "', |
|
50 | + '".Db::escape_string($request->token->user_id) . "' |
|
51 | 51 | ); |
52 | 52 | "); |
53 | 53 | elseif ($tmp == 'false') |
54 | 54 | Db::execute(" |
55 | 55 | delete from cache_watches |
56 | 56 | where |
57 | - cache_id = '".Db::escape_string($geocache['internal_id'])."' |
|
58 | - and user_id = '".Db::escape_string($request->token->user_id)."'; |
|
57 | + cache_id = '".Db::escape_string($geocache['internal_id']) . "' |
|
58 | + and user_id = '".Db::escape_string($request->token->user_id) . "'; |
|
59 | 59 | "); |
60 | 60 | } |
61 | 61 | |
@@ -69,16 +69,16 @@ discard block |
||
69 | 69 | Db::execute(" |
70 | 70 | insert ignore into cache_ignore (cache_id, user_id) |
71 | 71 | values ( |
72 | - '".Db::escape_string($geocache['internal_id'])."', |
|
73 | - '".Db::escape_string($request->token->user_id)."' |
|
72 | + '".Db::escape_string($geocache['internal_id']) . "', |
|
73 | + '".Db::escape_string($request->token->user_id) . "' |
|
74 | 74 | ); |
75 | 75 | "); |
76 | 76 | elseif ($tmp == 'false') |
77 | 77 | Db::execute(" |
78 | 78 | delete from cache_ignore |
79 | 79 | where |
80 | - cache_id = '".Db::escape_string($geocache['internal_id'])."' |
|
81 | - and user_id = '".Db::escape_string($request->token->user_id)."' |
|
80 | + cache_id = '".Db::escape_string($geocache['internal_id']) . "' |
|
81 | + and user_id = '".Db::escape_string($request->token->user_id) . "' |
|
82 | 82 | "); |
83 | 83 | } |
84 | 84 |
@@ -31,8 +31,9 @@ discard block |
||
31 | 31 | # on it - this will also throw a proper exception if it doesn't exist. |
32 | 32 | |
33 | 33 | $cache_code = $request->get_parameter('cache_code'); |
34 | - if ($cache_code == null) |
|
35 | - throw new ParamMissing('cache_code'); |
|
34 | + if ($cache_code == null) { |
|
35 | + throw new ParamMissing('cache_code'); |
|
36 | + } |
|
36 | 37 | $geocache = OkapiServiceRunner::call('services/caches/geocache', new OkapiInternalRequest( |
37 | 38 | $request->consumer, $request->token, array('cache_code' => $cache_code, 'fields' => 'internal_id'))); |
38 | 39 | |
@@ -40,46 +41,50 @@ discard block |
||
40 | 41 | |
41 | 42 | if ($tmp = $request->get_parameter('watched')) |
42 | 43 | { |
43 | - if (!in_array($tmp, array('true', 'false', 'unchanged'))) |
|
44 | - throw new InvalidParam('watched', $tmp); |
|
45 | - if ($tmp == 'true') |
|
46 | - Db::execute(" |
|
44 | + if (!in_array($tmp, array('true', 'false', 'unchanged'))) { |
|
45 | + throw new InvalidParam('watched', $tmp); |
|
46 | + } |
|
47 | + if ($tmp == 'true') { |
|
48 | + Db::execute(" |
|
47 | 49 | insert ignore into cache_watches (cache_id, user_id) |
48 | 50 | values ( |
49 | 51 | '".Db::escape_string($geocache['internal_id'])."', |
50 | 52 | '".Db::escape_string($request->token->user_id)."' |
51 | 53 | ); |
52 | 54 | "); |
53 | - elseif ($tmp == 'false') |
|
54 | - Db::execute(" |
|
55 | + } elseif ($tmp == 'false') { |
|
56 | + Db::execute(" |
|
55 | 57 | delete from cache_watches |
56 | 58 | where |
57 | 59 | cache_id = '".Db::escape_string($geocache['internal_id'])."' |
58 | 60 | and user_id = '".Db::escape_string($request->token->user_id)."'; |
59 | 61 | "); |
62 | + } |
|
60 | 63 | } |
61 | 64 | |
62 | 65 | # ignored |
63 | 66 | |
64 | 67 | if ($tmp = $request->get_parameter('ignored')) |
65 | 68 | { |
66 | - if (!in_array($tmp, array('true', 'false', 'unchanged'))) |
|
67 | - throw new InvalidParam('ignored', $tmp); |
|
68 | - if ($tmp == 'true') |
|
69 | - Db::execute(" |
|
69 | + if (!in_array($tmp, array('true', 'false', 'unchanged'))) { |
|
70 | + throw new InvalidParam('ignored', $tmp); |
|
71 | + } |
|
72 | + if ($tmp == 'true') { |
|
73 | + Db::execute(" |
|
70 | 74 | insert ignore into cache_ignore (cache_id, user_id) |
71 | 75 | values ( |
72 | 76 | '".Db::escape_string($geocache['internal_id'])."', |
73 | 77 | '".Db::escape_string($request->token->user_id)."' |
74 | 78 | ); |
75 | 79 | "); |
76 | - elseif ($tmp == 'false') |
|
77 | - Db::execute(" |
|
80 | + } elseif ($tmp == 'false') { |
|
81 | + Db::execute(" |
|
78 | 82 | delete from cache_ignore |
79 | 83 | where |
80 | 84 | cache_id = '".Db::escape_string($geocache['internal_id'])."' |
81 | 85 | and user_id = '".Db::escape_string($request->token->user_id)."' |
82 | 86 | "); |
87 | + } |
|
83 | 88 | } |
84 | 89 | |
85 | 90 | $result = array( |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | if ((!preg_match("/^[0-9]+$/", $issue_id)) || (strlen($issue_id) > 6)) |
32 | 32 | throw new InvalidParam('issue_id'); |
33 | 33 | |
34 | - $cache_key = "apiref/issue#".$issue_id; |
|
34 | + $cache_key = "apiref/issue#" . $issue_id; |
|
35 | 35 | $result = Cache::get($cache_key); |
36 | 36 | if ($result == null) |
37 | 37 | { |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | $extra_headers[] = "Accept: application/vnd.github.v3.html+json"; |
44 | 44 | $extra_headers[] = "User-Agent: https://github.com/opencaching/okapi/"; |
45 | 45 | if (Settings::get('GITHUB_ACCESS_TOKEN')) { |
46 | - $extra_headers[] = "Authorization: token ".Settings::get('GITHUB_ACCESS_TOKEN'); |
|
46 | + $extra_headers[] = "Authorization: token " . Settings::get('GITHUB_ACCESS_TOKEN'); |
|
47 | 47 | } |
48 | 48 | $opts = array( |
49 | 49 | 'http' => array( |
@@ -58,8 +58,8 @@ discard block |
||
58 | 58 | } |
59 | 59 | catch (ErrorException $e) |
60 | 60 | { |
61 | - throw new BadRequest("Sorry, we could not retrieve issue stats from the GitHub site. ". |
|
62 | - "This is probably due to a temporary connection problem. Try again later or contact ". |
|
61 | + throw new BadRequest("Sorry, we could not retrieve issue stats from the GitHub site. " . |
|
62 | + "This is probably due to a temporary connection problem. Try again later or contact " . |
|
63 | 63 | "us if this seems permanent."); |
64 | 64 | } |
65 | 65 |
@@ -26,10 +26,12 @@ discard block |
||
26 | 26 | public static function call(OkapiRequest $request) |
27 | 27 | { |
28 | 28 | $issue_id = $request->get_parameter('issue_id'); |
29 | - if (!$issue_id) |
|
30 | - throw new ParamMissing('issue_id'); |
|
31 | - if ((!preg_match("/^[0-9]+$/", $issue_id)) || (strlen($issue_id) > 6)) |
|
32 | - throw new InvalidParam('issue_id'); |
|
29 | + if (!$issue_id) { |
|
30 | + throw new ParamMissing('issue_id'); |
|
31 | + } |
|
32 | + if ((!preg_match("/^[0-9]+$/", $issue_id)) || (strlen($issue_id) > 6)) { |
|
33 | + throw new InvalidParam('issue_id'); |
|
34 | + } |
|
33 | 35 | |
34 | 36 | $cache_key = "apiref/issue#".$issue_id; |
35 | 37 | $result = Cache::get($cache_key); |
@@ -55,8 +57,7 @@ discard block |
||
55 | 57 | $context = stream_context_create($opts); |
56 | 58 | $json = file_get_contents("https://api.github.com/repos/opencaching/okapi/issues/$issue_id", |
57 | 59 | false, $context); |
58 | - } |
|
59 | - catch (ErrorException $e) |
|
60 | + } catch (ErrorException $e) |
|
60 | 61 | { |
61 | 62 | throw new BadRequest("Sorry, we could not retrieve issue stats from the GitHub site. ". |
62 | 63 | "This is probably due to a temporary connection problem. Try again later or contact ". |
@@ -26,7 +26,7 @@ |
||
26 | 26 | { |
27 | 27 | $methodnames = OkapiServiceRunner::$all_names; |
28 | 28 | sort($methodnames); |
29 | - $cache_key = "api_ref/method_index#".md5(implode("#", $methodnames)); |
|
29 | + $cache_key = "api_ref/method_index#" . md5(implode("#", $methodnames)); |
|
30 | 30 | $results = Cache::get($cache_key); |
31 | 31 | if ($results == null) |
32 | 32 | { |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | 'is_deprecated' => (isset($attrs['class']) && (strpos($attrs['class'], 'deprecated') !== false)), |
31 | 31 | 'class' => 'public', |
32 | 32 | 'description' => |
33 | - (isset($attrs['default']) ? ("<p>Default value: <b>".$attrs['default']."</b></p>") : ""). |
|
33 | + (isset($attrs['default']) ? ("<p>Default value: <b>" . $attrs['default'] . "</b></p>") : "") . |
|
34 | 34 | self::get_inner_xml($arg_node), |
35 | 35 | |
36 | 36 | ); |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | switch ($plugin_name) { |
97 | 97 | case 'docurl': |
98 | 98 | $fragment = $arr[1]; |
99 | - return Settings::get('SITE_URL')."okapi/introduction.html#".$fragment; |
|
99 | + return Settings::get('SITE_URL') . "okapi/introduction.html#" . $fragment; |
|
100 | 100 | case 'methodref': |
101 | 101 | case 'methodargref': |
102 | 102 | case 'methodretref': |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | $result = ''; |
105 | 105 | if ($elements[0] != '') |
106 | 106 | { |
107 | - $result .= Settings::get('SITE_URL')."okapi/".$elements[0].'.html'; |
|
107 | + $result .= Settings::get('SITE_URL') . "okapi/" . $elements[0] . '.html'; |
|
108 | 108 | } |
109 | 109 | if (count($elements) > 1) |
110 | 110 | { |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | } |
122 | 122 | return $result; |
123 | 123 | default: |
124 | - throw new Exception("Unknown plugin: ".$input); |
|
124 | + throw new Exception("Unknown plugin: " . $input); |
|
125 | 125 | } |
126 | 126 | } |
127 | 127 | |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | $result = array( |
143 | 143 | 'name' => $methodname, |
144 | 144 | 'short_name' => end($exploded), |
145 | - 'ref_url' => Settings::get('SITE_URL')."okapi/$methodname.html", |
|
145 | + 'ref_url' => Settings::get('SITE_URL') . "okapi/$methodname.html", |
|
146 | 146 | 'auth_options' => array( |
147 | 147 | 'min_auth_level' => $options['min_auth_level'], |
148 | 148 | 'oauth_consumer' => $options['min_auth_level'] >= 2, |
@@ -184,15 +184,15 @@ discard block |
||
184 | 184 | continue; |
185 | 185 | if (($include_list === null) && (count($exclude_list) == 0)) |
186 | 186 | { |
187 | - $arg['description'] = "<i>Inherited from <a href='".$referenced_method_info['ref_url']. |
|
188 | - "#arg_". $arg['name'] . "'>".$referenced_method_info['name']."</a> method.</i>"; |
|
187 | + $arg['description'] = "<i>Inherited from <a href='" . $referenced_method_info['ref_url'] . |
|
188 | + "#arg_" . $arg['name'] . "'>" . $referenced_method_info['name'] . "</a> method.</i>"; |
|
189 | 189 | } |
190 | 190 | elseif ( |
191 | 191 | (($include_list === null) || in_array($arg['name'], $include_list)) |
192 | 192 | && (!in_array($arg['name'], $exclude_list)) |
193 | 193 | ) { |
194 | - $arg['description'] = "<i>Same as in the <a href='".$referenced_method_info['ref_url']. |
|
195 | - "#arg_". $arg['name'] . "'>".$referenced_method_info['name']."</a> method.</i>"; |
|
194 | + $arg['description'] = "<i>Same as in the <a href='" . $referenced_method_info['ref_url'] . |
|
195 | + "#arg_" . $arg['name'] . "'>" . $referenced_method_info['name'] . "</a> method.</i>"; |
|
196 | 196 | } else { |
197 | 197 | continue; |
198 | 198 | } |
@@ -207,21 +207,21 @@ discard block |
||
207 | 207 | 'is_required' => false, |
208 | 208 | 'is_deprecated' => false, |
209 | 209 | 'class' => 'common-formatting', |
210 | - 'description' => "<i>Standard <a href='".Settings::get('SITE_URL')."okapi/introduction.html#common-formatting'>common formatting</a> argument.</i>" |
|
210 | + 'description' => "<i>Standard <a href='" . Settings::get('SITE_URL') . "okapi/introduction.html#common-formatting'>common formatting</a> argument.</i>" |
|
211 | 211 | ); |
212 | 212 | $result['arguments'][] = array( |
213 | 213 | 'name' => 'callback', |
214 | 214 | 'is_required' => false, |
215 | 215 | 'is_deprecated' => false, |
216 | 216 | 'class' => 'common-formatting', |
217 | - 'description' => "<i>Standard <a href='".Settings::get('SITE_URL')."okapi/introduction.html#common-formatting'>common formatting</a> argument.</i>" |
|
217 | + 'description' => "<i>Standard <a href='" . Settings::get('SITE_URL') . "okapi/introduction.html#common-formatting'>common formatting</a> argument.</i>" |
|
218 | 218 | ); |
219 | 219 | } |
220 | 220 | foreach ($result['arguments'] as &$arg_ref) |
221 | 221 | if ($arg_ref['is_deprecated']) |
222 | 222 | $arg_ref['class'] .= " deprecated"; |
223 | 223 | if (!$docs->returns) |
224 | - throw new Exception("Missing <returns> element in the $methodname.xml file. ". |
|
224 | + throw new Exception("Missing <returns> element in the $methodname.xml file. " . |
|
225 | 225 | "If your method does not return anything, you should document in nonetheless."); |
226 | 226 | $result['returns'] = self::get_inner_xml($docs->returns); |
227 | 227 | return Okapi::formatted_response($request, $result); |
@@ -128,15 +128,19 @@ discard block |
||
128 | 128 | public static function call(OkapiRequest $request) |
129 | 129 | { |
130 | 130 | $methodname = $request->get_parameter('name'); |
131 | - if (!$methodname) |
|
132 | - throw new ParamMissing('name'); |
|
133 | - if (!preg_match("#^services/[0-9a-z_/]*$#", $methodname)) |
|
134 | - throw new InvalidParam('name'); |
|
135 | - if (!OkapiServiceRunner::exists($methodname)) |
|
136 | - throw new InvalidParam('name', "Method does not exist: '$methodname'."); |
|
131 | + if (!$methodname) { |
|
132 | + throw new ParamMissing('name'); |
|
133 | + } |
|
134 | + if (!preg_match("#^services/[0-9a-z_/]*$#", $methodname)) { |
|
135 | + throw new InvalidParam('name'); |
|
136 | + } |
|
137 | + if (!OkapiServiceRunner::exists($methodname)) { |
|
138 | + throw new InvalidParam('name', "Method does not exist: '$methodname'."); |
|
139 | + } |
|
137 | 140 | $options = OkapiServiceRunner::options($methodname); |
138 | - if (!isset($options['min_auth_level'])) |
|
139 | - throw new Exception("Method $methodname is missing a required 'min_auth_level' option!"); |
|
141 | + if (!isset($options['min_auth_level'])) { |
|
142 | + throw new Exception("Method $methodname is missing a required 'min_auth_level' option!"); |
|
143 | + } |
|
140 | 144 | $docs = simplexml_load_string(OkapiServiceRunner::docs($methodname)); |
141 | 145 | $exploded = explode("/", $methodname); |
142 | 146 | $result = array( |
@@ -149,23 +153,30 @@ discard block |
||
149 | 153 | 'oauth_token' => $options['min_auth_level'] >= 3, |
150 | 154 | ) |
151 | 155 | ); |
152 | - if (!$docs->brief) |
|
153 | - throw new Exception("Missing <brief> element in the $methodname.xml file."); |
|
154 | - if ($docs->brief != self::get_inner_xml($docs->brief)) |
|
155 | - throw new Exception("The <brief> element may not contain HTML markup ($methodname.xml)."); |
|
156 | - if (strlen($docs->brief) > 80) |
|
157 | - throw new Exception("The <brief> description may not be longer than 80 characters ($methodname.xml)."); |
|
158 | - if (strpos($docs->brief, "\n") !== false) |
|
159 | - throw new Exception("The <brief> element may not contain new-lines ($methodname.xml)."); |
|
160 | - if (substr(trim($docs->brief), -1) == '.') |
|
161 | - throw new Exception("The <brief> element should not end with a dot ($methodname.xml)."); |
|
156 | + if (!$docs->brief) { |
|
157 | + throw new Exception("Missing <brief> element in the $methodname.xml file."); |
|
158 | + } |
|
159 | + if ($docs->brief != self::get_inner_xml($docs->brief)) { |
|
160 | + throw new Exception("The <brief> element may not contain HTML markup ($methodname.xml)."); |
|
161 | + } |
|
162 | + if (strlen($docs->brief) > 80) { |
|
163 | + throw new Exception("The <brief> description may not be longer than 80 characters ($methodname.xml)."); |
|
164 | + } |
|
165 | + if (strpos($docs->brief, "\n") !== false) { |
|
166 | + throw new Exception("The <brief> element may not contain new-lines ($methodname.xml)."); |
|
167 | + } |
|
168 | + if (substr(trim($docs->brief), -1) == '.') { |
|
169 | + throw new Exception("The <brief> element should not end with a dot ($methodname.xml)."); |
|
170 | + } |
|
162 | 171 | $result['brief_description'] = self::get_inner_xml($docs->brief); |
163 | - if ($docs->{'issue-id'}) |
|
164 | - $result['issue_id'] = (string)$docs->{'issue-id'}; |
|
165 | - else |
|
166 | - $result['issue_id'] = null; |
|
167 | - if (!$docs->desc) |
|
168 | - throw new Exception("Missing <desc> element in the $methodname.xml file."); |
|
172 | + if ($docs->{'issue-id'}) { |
|
173 | + $result['issue_id'] = (string)$docs->{'issue-id'}; |
|
174 | + } else { |
|
175 | + $result['issue_id'] = null; |
|
176 | + } |
|
177 | + if (!$docs->desc) { |
|
178 | + throw new Exception("Missing <desc> element in the $methodname.xml file."); |
|
179 | + } |
|
169 | 180 | $result['description'] = self::get_inner_xml($docs->desc); |
170 | 181 | $result['arguments'] = array(); |
171 | 182 | foreach ($docs->req as $arg) { $result['arguments'][] = self::arg_desc($arg); } |
@@ -180,14 +191,14 @@ discard block |
||
180 | 191 | $exclude_list = isset($attrs['except']) ? explode("|", $attrs['except']) : array(); |
181 | 192 | foreach ($referenced_method_info['arguments'] as $arg) |
182 | 193 | { |
183 | - if ($arg['class'] == 'common-formatting') |
|
184 | - continue; |
|
194 | + if ($arg['class'] == 'common-formatting') { |
|
195 | + continue; |
|
196 | + } |
|
185 | 197 | if (($include_list === null) && (count($exclude_list) == 0)) |
186 | 198 | { |
187 | 199 | $arg['description'] = "<i>Inherited from <a href='".$referenced_method_info['ref_url']. |
188 | 200 | "#arg_". $arg['name'] . "'>".$referenced_method_info['name']."</a> method.</i>"; |
189 | - } |
|
190 | - elseif ( |
|
201 | + } elseif ( |
|
191 | 202 | (($include_list === null) || in_array($arg['name'], $include_list)) |
192 | 203 | && (!in_array($arg['name'], $exclude_list)) |
193 | 204 | ) { |
@@ -217,12 +228,14 @@ discard block |
||
217 | 228 | 'description' => "<i>Standard <a href='".Settings::get('SITE_URL')."okapi/introduction.html#common-formatting'>common formatting</a> argument.</i>" |
218 | 229 | ); |
219 | 230 | } |
220 | - foreach ($result['arguments'] as &$arg_ref) |
|
221 | - if ($arg_ref['is_deprecated']) |
|
231 | + foreach ($result['arguments'] as &$arg_ref) { |
|
232 | + if ($arg_ref['is_deprecated']) |
|
222 | 233 | $arg_ref['class'] .= " deprecated"; |
223 | - if (!$docs->returns) |
|
224 | - throw new Exception("Missing <returns> element in the $methodname.xml file. ". |
|
234 | + } |
|
235 | + if (!$docs->returns) { |
|
236 | + throw new Exception("Missing <returns> element in the $methodname.xml file. ". |
|
225 | 237 | "If your method does not return anything, you should document in nonetheless."); |
238 | + } |
|
226 | 239 | $result['returns'] = self::get_inner_xml($docs->returns); |
227 | 240 | return Okapi::formatted_response($request, $result); |
228 | 241 | } |