@@ -20,8 +20,7 @@ |
||
| 20 | 20 | public static function call(OkapiRequest $request) |
| 21 | 21 | { |
| 22 | 22 | $callback = $request->get_parameter('oauth_callback'); |
| 23 | - if (!$callback) |
|
| 24 | - { |
|
| 23 | + if (!$callback) { |
|
| 25 | 24 | # We require the 1.0a flow (throw an error when there is no oauth_callback). |
| 26 | 25 | throw new ParamMissing("oauth_callback"); |
| 27 | 26 | } |
@@ -21,8 +21,7 @@ |
||
| 21 | 21 | public static function call(OkapiRequest $request) |
| 22 | 22 | { |
| 23 | 23 | $verifier = $request->get_parameter('oauth_verifier'); |
| 24 | - if (!$verifier) |
|
| 25 | - { |
|
| 24 | + if (!$verifier) { |
|
| 26 | 25 | # We require the 1.0a flow (throw an error when there is no oauth_verifier). |
| 27 | 26 | throw new ParamMissing("oauth_verifier"); |
| 28 | 27 | } |
@@ -32,22 +32,32 @@ discard block |
||
| 32 | 32 | public static function call(OkapiRequest $request) |
| 33 | 33 | { |
| 34 | 34 | $cache_codes = $request->get_parameter('cache_codes'); |
| 35 | - if ($cache_codes === null) throw new ParamMissing('cache_codes'); |
|
| 35 | + if ($cache_codes === null) { |
|
| 36 | + throw new ParamMissing('cache_codes'); |
|
| 37 | + } |
|
| 36 | 38 | |
| 37 | 39 | # Issue 106 requires us to allow empty list of cache codes to be passed into this method. |
| 38 | 40 | # All of the queries below have to be ready for $cache_codes to be empty! |
| 39 | 41 | |
| 40 | 42 | $langpref = $request->get_parameter('langpref'); |
| 41 | - if (!$langpref) $langpref = "en"; |
|
| 43 | + if (!$langpref) { |
|
| 44 | + $langpref = "en"; |
|
| 45 | + } |
|
| 42 | 46 | $langpref .= "|".Settings::get('SITELANG'); |
| 43 | 47 | $images = $request->get_parameter('images'); |
| 44 | - if (!$images) $images = "all"; |
|
| 45 | - if (!in_array($images, array("none", "all", "spoilers", "nonspoilers"))) |
|
| 46 | - throw new InvalidParam('images'); |
|
| 48 | + if (!$images) { |
|
| 49 | + $images = "all"; |
|
| 50 | + } |
|
| 51 | + if (!in_array($images, array("none", "all", "spoilers", "nonspoilers"))) { |
|
| 52 | + throw new InvalidParam('images'); |
|
| 53 | + } |
|
| 47 | 54 | $format = $request->get_parameter('caches_format'); |
| 48 | - if (!$format) $format = "gpx"; |
|
| 49 | - if (!in_array($format, array("gpx", "ggz"))) |
|
| 50 | - throw new InvalidParam('caches_format'); |
|
| 55 | + if (!$format) { |
|
| 56 | + $format = "gpx"; |
|
| 57 | + } |
|
| 58 | + if (!in_array($format, array("gpx", "ggz"))) { |
|
| 59 | + throw new InvalidParam('caches_format'); |
|
| 60 | + } |
|
| 51 | 61 | |
| 52 | 62 | $location_source = $request->get_parameter('location_source'); |
| 53 | 63 | $location_change_prefix = $request->get_parameter('location_change_prefix'); |
@@ -97,36 +107,37 @@ discard block |
||
| 97 | 107 | $caches = OkapiServiceRunner::call('services/caches/geocaches', new OkapiInternalRequest( |
| 98 | 108 | $request->consumer, $request->token, array('cache_codes' => $cache_codes, |
| 99 | 109 | 'langpref' => $langpref, 'fields' => "images"))); |
| 100 | - if (count($caches) > 50) |
|
| 101 | - throw new InvalidParam('cache_codes', "The maximum number of caches allowed to be downloaded with this method is 50."); |
|
| 102 | - if ($images != 'none') |
|
| 103 | - { |
|
| 110 | + if (count($caches) > 50) { |
|
| 111 | + throw new InvalidParam('cache_codes', "The maximum number of caches allowed to be downloaded with this method is 50."); |
|
| 112 | + } |
|
| 113 | + if ($images != 'none') { |
|
| 104 | 114 | $supported_extensions = array('jpg', 'jpeg', 'gif', 'png', 'bmp'); |
| 105 | - foreach ($caches as $cache_code => $dict) |
|
| 106 | - { |
|
| 115 | + foreach ($caches as $cache_code => $dict) { |
|
| 107 | 116 | $imgs = $dict['images']; |
| 108 | - if (count($imgs) == 0) |
|
| 109 | - continue; |
|
| 117 | + if (count($imgs) == 0) { |
|
| 118 | + continue; |
|
| 119 | + } |
|
| 110 | 120 | $dir = "Garmin/GeocachePhotos/".$cache_code[strlen($cache_code) - 1]; |
| 111 | 121 | $dir .= "/".$cache_code[strlen($cache_code) - 2]; |
| 112 | 122 | $dir .= "/".$cache_code; |
| 113 | - foreach ($imgs as $no => $img) |
|
| 114 | - { |
|
| 115 | - if ($images == 'spoilers' && (!$img['is_spoiler'])) |
|
| 116 | - continue; |
|
| 117 | - if ($images == 'nonspoilers' && $img['is_spoiler']) |
|
| 118 | - continue; |
|
| 123 | + foreach ($imgs as $no => $img) { |
|
| 124 | + if ($images == 'spoilers' && (!$img['is_spoiler'])) { |
|
| 125 | + continue; |
|
| 126 | + } |
|
| 127 | + if ($images == 'nonspoilers' && $img['is_spoiler']) { |
|
| 128 | + continue; |
|
| 129 | + } |
|
| 119 | 130 | $tmp = false; |
| 120 | - foreach ($supported_extensions as $ext) |
|
| 121 | - { |
|
| 122 | - if (strtolower(substr($img['url'], strlen($img['url']) - strlen($ext) - 1)) != ".".$ext) |
|
| 123 | - { |
|
| 131 | + foreach ($supported_extensions as $ext) { |
|
| 132 | + if (strtolower(substr($img['url'], strlen($img['url']) - strlen($ext) - 1)) != ".".$ext) { |
|
| 124 | 133 | $tmp = true; |
| 125 | 134 | continue; |
| 126 | 135 | } |
| 127 | 136 | } |
| 128 | - if (!$tmp) |
|
| 129 | - continue; # unsupported file extension |
|
| 137 | + if (!$tmp) { |
|
| 138 | + continue; |
|
| 139 | + } |
|
| 140 | + # unsupported file extension |
|
| 130 | 141 | |
| 131 | 142 | if ($img['is_spoiler']) { |
| 132 | 143 | $zippath = $dir."/Spoilers/".$img['unique_caption'].".jpg"; |
@@ -142,34 +153,25 @@ discard block |
||
| 142 | 153 | # be accessed locally. But all the files have 'local' set to 1 anyway. |
| 143 | 154 | |
| 144 | 155 | $syspath = Settings::get('IMAGES_DIR')."/".$img['uuid'].".jpg"; |
| 145 | - if (file_exists($syspath)) |
|
| 146 | - { |
|
| 156 | + if (file_exists($syspath)) { |
|
| 147 | 157 | $response->zip->FileAdd($zippath, $syspath, clsTbsZip::TBSZIP_FILE, false); |
| 148 | - } |
|
| 149 | - else |
|
| 150 | - { |
|
| 158 | + } else { |
|
| 151 | 159 | # If file exists, but does not end with ".jpg", we will create |
| 152 | 160 | # JPEG version of it and store it in the cache. |
| 153 | 161 | |
| 154 | 162 | $cache_key = "jpg#".$img['uuid']; |
| 155 | 163 | $jpeg_contents = Cache::get($cache_key); |
| 156 | - if ($jpeg_contents === null) |
|
| 157 | - { |
|
| 158 | - foreach ($supported_extensions as $ext) |
|
| 159 | - { |
|
| 164 | + if ($jpeg_contents === null) { |
|
| 165 | + foreach ($supported_extensions as $ext) { |
|
| 160 | 166 | $syspath_other = Settings::get('IMAGES_DIR')."/".$img['uuid'].".".$ext; |
| 161 | - if (file_exists($syspath_other)) |
|
| 162 | - { |
|
| 163 | - try |
|
| 164 | - { |
|
| 167 | + if (file_exists($syspath_other)) { |
|
| 168 | + try { |
|
| 165 | 169 | $image = imagecreatefromstring(file_get_contents($syspath_other)); |
| 166 | 170 | ob_start(); |
| 167 | 171 | imagejpeg($image); |
| 168 | 172 | $jpeg_contents = ob_get_clean(); |
| 169 | 173 | imagedestroy($image); |
| 170 | - } |
|
| 171 | - catch (Exception $e) |
|
| 172 | - { |
|
| 174 | + } catch (Exception $e) { |
|
| 173 | 175 | # GD couldn't parse the file. We will skip it, and cache |
| 174 | 176 | # the "false" value as the contents. This way, we won't |
| 175 | 177 | # attempt to parse it during the next 24 hours. |
@@ -181,8 +183,10 @@ discard block |
||
| 181 | 183 | } |
| 182 | 184 | } |
| 183 | 185 | } |
| 184 | - if ($jpeg_contents) # This can be "null" *or* "false"! |
|
| 186 | + if ($jpeg_contents) { |
|
| 187 | + # This can be "null" *or* "false"! |
|
| 185 | 188 | $response->zip->FileAdd($zippath, $jpeg_contents, clsTbsZip::TBSZIP_STRING, false); |
| 189 | + } |
|
| 186 | 190 | } |
| 187 | 191 | } |
| 188 | 192 | } |
@@ -27,7 +27,7 @@ |
||
| 27 | 27 | <?php if (isset($c['ratings'])) { |
| 28 | 28 | ?><ratings> |
| 29 | 29 | <?php |
| 30 | - foreach ($c['ratings'] as $rating_key => $rating_val){ |
|
| 30 | + foreach ($c['ratings'] as $rating_key => $rating_val) { |
|
| 31 | 31 | echo "<$rating_key>$rating_val</$rating_key>\n"; |
| 32 | 32 | } |
| 33 | 33 | ?> |
@@ -89,24 +89,30 @@ discard block |
||
| 89 | 89 | # $vars variable which we will use later in the GPS template. |
| 90 | 90 | |
| 91 | 91 | $cache_codes = $request->get_parameter('cache_codes'); |
| 92 | - if ($cache_codes === null) throw new ParamMissing('cache_codes'); |
|
| 92 | + if ($cache_codes === null) { |
|
| 93 | + throw new ParamMissing('cache_codes'); |
|
| 94 | + } |
|
| 93 | 95 | |
| 94 | 96 | # Issue 106 requires us to allow empty list of cache codes to be passed into this method. |
| 95 | 97 | # All of the queries below have to be ready for $cache_codes to be empty! |
| 96 | 98 | |
| 97 | 99 | $langpref = $request->get_parameter('langpref'); |
| 98 | - if (!$langpref) $langpref = "en"; |
|
| 100 | + if (!$langpref) { |
|
| 101 | + $langpref = "en"; |
|
| 102 | + } |
|
| 99 | 103 | $langpref .= "|".Settings::get('SITELANG'); |
| 100 | - foreach (array('ns_ground', 'ns_gsak', 'ns_ox', 'latest_logs', 'alt_wpts', 'mark_found') as $param) |
|
| 101 | - { |
|
| 104 | + foreach (array('ns_ground', 'ns_gsak', 'ns_ox', 'latest_logs', 'alt_wpts', 'mark_found') as $param) { |
|
| 102 | 105 | $val = $request->get_parameter($param); |
| 103 | - if (!$val) $val = "false"; |
|
| 104 | - elseif (!in_array($val, array("true", "false"))) |
|
| 105 | - throw new InvalidParam($param); |
|
| 106 | + if (!$val) { |
|
| 107 | + $val = "false"; |
|
| 108 | + } elseif (!in_array($val, array("true", "false"))) { |
|
| 109 | + throw new InvalidParam($param); |
|
| 110 | + } |
|
| 106 | 111 | $vars[$param] = ($val == "true"); |
| 107 | 112 | } |
| 108 | - if ($vars['latest_logs'] && (!$vars['ns_ground'])) |
|
| 109 | - throw new BadRequest("In order for 'latest_logs' to work you have to also include 'ns_ground' extensions."); |
|
| 113 | + if ($vars['latest_logs'] && (!$vars['ns_ground'])) { |
|
| 114 | + throw new BadRequest("In order for 'latest_logs' to work you have to also include 'ns_ground' extensions."); |
|
| 115 | + } |
|
| 110 | 116 | |
| 111 | 117 | $tmp = $request->get_parameter('my_notes'); |
| 112 | 118 | $vars['my_notes'] = array(); |
@@ -134,72 +140,86 @@ discard block |
||
| 134 | 140 | } |
| 135 | 141 | |
| 136 | 142 | $images = $request->get_parameter('images'); |
| 137 | - if (!$images) $images = 'descrefs:nonspoilers'; |
|
| 138 | - if (!in_array($images, array('none', 'descrefs:thumblinks', 'descrefs:nonspoilers', 'descrefs:all', 'ox:all'))) |
|
| 139 | - throw new InvalidParam('images', "'$images'"); |
|
| 143 | + if (!$images) { |
|
| 144 | + $images = 'descrefs:nonspoilers'; |
|
| 145 | + } |
|
| 146 | + if (!in_array($images, array('none', 'descrefs:thumblinks', 'descrefs:nonspoilers', 'descrefs:all', 'ox:all'))) { |
|
| 147 | + throw new InvalidParam('images', "'$images'"); |
|
| 148 | + } |
|
| 140 | 149 | $vars['images'] = $images; |
| 141 | 150 | |
| 142 | 151 | $tmp = $request->get_parameter('attrs'); |
| 143 | - if (!$tmp) $tmp = 'desc:text'; |
|
| 152 | + if (!$tmp) { |
|
| 153 | + $tmp = 'desc:text'; |
|
| 154 | + } |
|
| 144 | 155 | $tmp = explode("|", $tmp); |
| 145 | 156 | $vars['attrs'] = array(); |
| 146 | - foreach ($tmp as $elem) |
|
| 147 | - { |
|
| 157 | + foreach ($tmp as $elem) { |
|
| 148 | 158 | if ($elem == 'none') { |
| 149 | 159 | /* pass */ |
| 150 | 160 | } elseif (in_array($elem, array('desc:text', 'ox:tags', 'gc:attrs', 'gc_ocde:attrs'))) { |
| 151 | - if ($elem == 'gc_ocde:attrs' && Settings::get('OC_BRANCH') != 'oc.de') |
|
| 152 | - $vars['attrs'][] = 'gc:attrs'; |
|
| 153 | - else |
|
| 154 | - $vars['attrs'][] = $elem; |
|
| 161 | + if ($elem == 'gc_ocde:attrs' && Settings::get('OC_BRANCH') != 'oc.de') { |
|
| 162 | + $vars['attrs'][] = 'gc:attrs'; |
|
| 163 | + } else { |
|
| 164 | + $vars['attrs'][] = $elem; |
|
| 165 | + } |
|
| 155 | 166 | } else { |
| 156 | 167 | throw new InvalidParam('attrs', "Invalid list entry: '$elem'"); |
| 157 | 168 | } |
| 158 | 169 | } |
| 159 | 170 | |
| 160 | 171 | $protection_areas = $request->get_parameter('protection_areas'); |
| 161 | - if (!$protection_areas || $protection_areas == 'desc:auto') |
|
| 162 | - { |
|
| 163 | - if (Settings::get('OC_BRANCH') == 'oc.de') $protection_areas = 'desc:text'; |
|
| 164 | - else $protection_areas = 'none'; |
|
| 172 | + if (!$protection_areas || $protection_areas == 'desc:auto') { |
|
| 173 | + if (Settings::get('OC_BRANCH') == 'oc.de') { |
|
| 174 | + $protection_areas = 'desc:text'; |
|
| 175 | + } else { |
|
| 176 | + $protection_areas = 'none'; |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + if (!in_array($protection_areas, array('none', 'desc:text'))) { |
|
| 180 | + throw new InvalidParam('protection_areas',"'$protection_areas'"); |
|
| 165 | 181 | } |
| 166 | - if (!in_array($protection_areas, array('none', 'desc:text'))) |
|
| 167 | - throw new InvalidParam('protection_areas',"'$protection_areas'"); |
|
| 168 | 182 | $vars['protection_areas'] = $protection_areas; |
| 169 | 183 | |
| 170 | 184 | $tmp = $request->get_parameter('trackables'); |
| 171 | - if (!$tmp) $tmp = 'none'; |
|
| 172 | - if (!in_array($tmp, array('none', 'desc:list', 'desc:count'))) |
|
| 173 | - throw new InvalidParam('trackables', "'$tmp'"); |
|
| 185 | + if (!$tmp) { |
|
| 186 | + $tmp = 'none'; |
|
| 187 | + } |
|
| 188 | + if (!in_array($tmp, array('none', 'desc:list', 'desc:count'))) { |
|
| 189 | + throw new InvalidParam('trackables', "'$tmp'"); |
|
| 190 | + } |
|
| 174 | 191 | $vars['trackables'] = $tmp; |
| 175 | 192 | |
| 176 | 193 | $tmp = $request->get_parameter('recommendations'); |
| 177 | - if (!$tmp) $tmp = 'none'; |
|
| 178 | - if (!in_array($tmp, array('none', 'desc:count'))) |
|
| 179 | - throw new InvalidParam('recommendations', "'$tmp'"); |
|
| 194 | + if (!$tmp) { |
|
| 195 | + $tmp = 'none'; |
|
| 196 | + } |
|
| 197 | + if (!in_array($tmp, array('none', 'desc:count'))) { |
|
| 198 | + throw new InvalidParam('recommendations', "'$tmp'"); |
|
| 199 | + } |
|
| 180 | 200 | $vars['recommendations'] = $tmp; |
| 181 | 201 | |
| 182 | 202 | $lpc = $request->get_parameter('lpc'); |
| 183 | - if ($lpc === null) $lpc = 10; # will be checked in services/caches/geocaches call |
|
| 203 | + if ($lpc === null) { |
|
| 204 | + $lpc = 10; |
|
| 205 | + } |
|
| 206 | + # will be checked in services/caches/geocaches call |
|
| 184 | 207 | |
| 185 | 208 | $user_uuid = $request->get_parameter('user_uuid'); |
| 186 | 209 | |
| 187 | 210 | # location_source (part 1 of 2) |
| 188 | 211 | |
| 189 | 212 | $location_source = $request->get_parameter('location_source'); |
| 190 | - if (!$location_source) |
|
| 191 | - { |
|
| 213 | + if (!$location_source) { |
|
| 192 | 214 | $location_source = 'default-coords'; |
| 193 | 215 | } |
| 194 | 216 | # Make sure location_source has prefix alt_wpt: |
| 195 | - if ($location_source != 'default-coords' && strncmp($location_source, 'alt_wpt:', 8) != 0) |
|
| 196 | - { |
|
| 217 | + if ($location_source != 'default-coords' && strncmp($location_source, 'alt_wpt:', 8) != 0) { |
|
| 197 | 218 | throw new InvalidParam('location_source', '\''.$location_source.'\''); |
| 198 | 219 | } |
| 199 | 220 | |
| 200 | 221 | # Make sure we have sufficient authorization |
| 201 | - if ($location_source == 'alt_wpt:user-coords' && $request->token == null) |
|
| 202 | - { |
|
| 222 | + if ($location_source == 'alt_wpt:user-coords' && $request->token == null) { |
|
| 203 | 223 | throw new BadRequest("Level 3 Authentication is required to access 'alt_wpt:user-coords'."); |
| 204 | 224 | } |
| 205 | 225 | |
@@ -208,24 +228,32 @@ discard block |
||
| 208 | 228 | $fields = 'code|name|location|date_created|url|type|status|size|size2|oxsize'. |
| 209 | 229 | '|difficulty|terrain|description|hint2|rating|owner|url|internal_id'. |
| 210 | 230 | '|protection_areas|short_description'; |
| 211 | - if ($vars['images'] != 'none') |
|
| 212 | - $fields .= "|images"; |
|
| 213 | - if (count($vars['attrs']) > 0) |
|
| 214 | - $fields .= "|attrnames|attr_acodes|needs_maintenance"; |
|
| 215 | - if ($vars['trackables'] == 'desc:list') |
|
| 216 | - $fields .= "|trackables"; |
|
| 217 | - elseif ($vars['trackables'] == 'desc:count') |
|
| 218 | - $fields .= "|trackables_count"; |
|
| 219 | - if ($vars['alt_wpts'] == 'true' || $location_source != 'default-coords') |
|
| 220 | - $fields .= "|alt_wpts"; |
|
| 221 | - if ($vars['recommendations'] != 'none') |
|
| 222 | - $fields .= "|recommendations|founds"; |
|
| 223 | - if (count($vars['my_notes']) > 0) |
|
| 224 | - $fields .= "|my_notes"; |
|
| 225 | - if ($vars['latest_logs']) |
|
| 226 | - $fields .= "|latest_logs"; |
|
| 227 | - if ($vars['mark_found']) |
|
| 228 | - $fields .= "|is_found"; |
|
| 231 | + if ($vars['images'] != 'none') { |
|
| 232 | + $fields .= "|images"; |
|
| 233 | + } |
|
| 234 | + if (count($vars['attrs']) > 0) { |
|
| 235 | + $fields .= "|attrnames|attr_acodes|needs_maintenance"; |
|
| 236 | + } |
|
| 237 | + if ($vars['trackables'] == 'desc:list') { |
|
| 238 | + $fields .= "|trackables"; |
|
| 239 | + } elseif ($vars['trackables'] == 'desc:count') { |
|
| 240 | + $fields .= "|trackables_count"; |
|
| 241 | + } |
|
| 242 | + if ($vars['alt_wpts'] == 'true' || $location_source != 'default-coords') { |
|
| 243 | + $fields .= "|alt_wpts"; |
|
| 244 | + } |
|
| 245 | + if ($vars['recommendations'] != 'none') { |
|
| 246 | + $fields .= "|recommendations|founds"; |
|
| 247 | + } |
|
| 248 | + if (count($vars['my_notes']) > 0) { |
|
| 249 | + $fields .= "|my_notes"; |
|
| 250 | + } |
|
| 251 | + if ($vars['latest_logs']) { |
|
| 252 | + $fields .= "|latest_logs"; |
|
| 253 | + } |
|
| 254 | + if ($vars['mark_found']) { |
|
| 255 | + $fields .= "|is_found"; |
|
| 256 | + } |
|
| 229 | 257 | |
| 230 | 258 | $vars['caches'] = OkapiServiceRunner::call( |
| 231 | 259 | 'services/caches/geocaches', new OkapiInternalRequest( |
@@ -261,8 +289,7 @@ discard block |
||
| 261 | 289 | $vars['cache_GPX_types'] = self::$cache_GPX_types; |
| 262 | 290 | $vars['cache_GPX_sizes'] = self::$cache_GPX_sizes; |
| 263 | 291 | |
| 264 | - if (count($vars['attrs']) > 0) |
|
| 265 | - { |
|
| 292 | + if (count($vars['attrs']) > 0) { |
|
| 266 | 293 | /* The user asked for some kind of attribute output. We'll fetch all |
| 267 | 294 | * the data we MAY need. This is often far too much, but thanks to |
| 268 | 295 | * caching, it will work fast. */ |
@@ -281,10 +308,8 @@ discard block |
||
| 281 | 308 | |
| 282 | 309 | $vars['gc_attrs'] = in_array('gc:attrs', $vars['attrs']); |
| 283 | 310 | $vars['gc_ocde_attrs'] = in_array('gc_ocde:attrs', $vars['attrs']); |
| 284 | - if ($vars['gc_attrs'] || $vars['gc_ocde_attrs']) |
|
| 285 | - { |
|
| 286 | - if ($vars['gc_ocde_attrs']) |
|
| 287 | - { |
|
| 311 | + if ($vars['gc_attrs'] || $vars['gc_ocde_attrs']) { |
|
| 312 | + if ($vars['gc_ocde_attrs']) { |
|
| 288 | 313 | # As this is an OCDE compatibility feature, we use the same Pseudo-GS |
| 289 | 314 | # attribute names here as OCDE. Note that this code is specific to OCDE |
| 290 | 315 | # database; OCPL stores attribute names in a different way and may use |
@@ -297,14 +322,11 @@ discard block |
||
| 297 | 322 | $attr_dict = AttrHelper::get_attrdict(); |
| 298 | 323 | } |
| 299 | 324 | |
| 300 | - foreach ($vars['caches'] as &$cache_ref) |
|
| 301 | - { |
|
| 325 | + foreach ($vars['caches'] as &$cache_ref) { |
|
| 302 | 326 | $cache_ref['gc_attrs'] = array(); |
| 303 | - foreach ($cache_ref['attr_acodes'] as $acode) |
|
| 304 | - { |
|
| 327 | + foreach ($cache_ref['attr_acodes'] as $acode) { |
|
| 305 | 328 | $has_gc_equivs = false; |
| 306 | - foreach ($vars['attr_index'][$acode]['gc_equivs'] as $gc) |
|
| 307 | - { |
|
| 329 | + foreach ($vars['attr_index'][$acode]['gc_equivs'] as $gc) { |
|
| 308 | 330 | # The assignment via GC-ID as array key will prohibit duplicate |
| 309 | 331 | # GC attributes, which can result from |
| 310 | 332 | # - assigning the same GC ID to multiple A-Codes, |
@@ -313,8 +335,7 @@ discard block |
||
| 313 | 335 | $cache_ref['gc_attrs'][$gc['id']] = $gc; |
| 314 | 336 | $has_gc_equivs = true; |
| 315 | 337 | } |
| 316 | - if (!$has_gc_equivs && $vars['gc_ocde_attrs']) |
|
| 317 | - { |
|
| 338 | + if (!$has_gc_equivs && $vars['gc_ocde_attrs']) { |
|
| 318 | 339 | # Generate an OCDE pseudo-GS attribute; |
| 319 | 340 | # see https://github.com/opencaching/okapi/issues/190 and |
| 320 | 341 | # https://github.com/opencaching/okapi/issues/271. |
@@ -329,8 +350,7 @@ discard block |
||
| 329 | 350 | ); |
| 330 | 351 | } |
| 331 | 352 | } |
| 332 | - if ($cache_ref['needs_maintenance']) |
|
| 333 | - { |
|
| 353 | + if ($cache_ref['needs_maintenance']) { |
|
| 334 | 354 | # export NM cache flag as GC attribute #42 |
| 335 | 355 | $cache_ref['gc_attrs']['42'] = array( |
| 336 | 356 | 'inc' => 1, |
@@ -342,12 +362,11 @@ discard block |
||
| 342 | 362 | |
| 343 | 363 | # As the 'needs maintenance' flag is usually transported as attribute in |
| 344 | 364 | # GPX files, we add it also to desc:text attribs. |
| 345 | - if (in_array('desc:text', $vars['attrs'])) |
|
| 346 | - { |
|
| 347 | - foreach ($vars['caches'] as &$cache_ref) |
|
| 348 | - { |
|
| 349 | - if ($cache_ref['needs_maintenance']) |
|
| 350 | - $cache_ref['attrnames'][] = 'Needs maintenance'; |
|
| 365 | + if (in_array('desc:text', $vars['attrs'])) { |
|
| 366 | + foreach ($vars['caches'] as &$cache_ref) { |
|
| 367 | + if ($cache_ref['needs_maintenance']) { |
|
| 368 | + $cache_ref['attrnames'][] = 'Needs maintenance'; |
|
| 369 | + } |
|
| 351 | 370 | } |
| 352 | 371 | } |
| 353 | 372 | } |
@@ -363,38 +382,35 @@ discard block |
||
| 363 | 382 | * from the database here. */ |
| 364 | 383 | |
| 365 | 384 | $dict = array(); |
| 366 | - foreach ($vars['caches'] as &$cache_ref) |
|
| 367 | - { |
|
| 385 | + foreach ($vars['caches'] as &$cache_ref) { |
|
| 368 | 386 | $dict[$cache_ref['owner']['uuid']] = true; |
| 369 | - if (isset($cache_ref['latest_logs'])) |
|
| 370 | - foreach ($cache_ref['latest_logs'] as &$log_ref) |
|
| 387 | + if (isset($cache_ref['latest_logs'])) { |
|
| 388 | + foreach ($cache_ref['latest_logs'] as &$log_ref) |
|
| 371 | 389 | $dict[$log_ref['user']['uuid']] = true; |
| 390 | + } |
|
| 372 | 391 | } |
| 373 | 392 | $rs = Db::query(" |
| 374 | 393 | select uuid, user_id |
| 375 | 394 | from user |
| 376 | 395 | where uuid in ('".implode("','", array_map('\okapi\Db::escape_string', array_keys($dict)))."') |
| 377 | 396 | "); |
| 378 | - while ($row = Db::fetch_assoc($rs)) |
|
| 379 | - $dict[$row['uuid']] = $row['user_id']; |
|
| 397 | + while ($row = Db::fetch_assoc($rs)) { |
|
| 398 | + $dict[$row['uuid']] = $row['user_id']; |
|
| 399 | + } |
|
| 380 | 400 | $vars['user_uuid_to_internal_id'] = &$dict; |
| 381 | 401 | unset($dict); |
| 382 | 402 | |
| 383 | 403 | # location_source (part 2 of 2) |
| 384 | 404 | |
| 385 | - if ($location_source != 'default-coords') |
|
| 386 | - { |
|
| 405 | + if ($location_source != 'default-coords') { |
|
| 387 | 406 | $location_change_prefix = $request->get_parameter('location_change_prefix'); |
| 388 | 407 | if (!$location_change_prefix) { |
| 389 | 408 | $location_change_prefix = '# '; |
| 390 | 409 | } |
| 391 | 410 | # lets find requested coords |
| 392 | - foreach ($vars['caches'] as &$cache_ref) |
|
| 393 | - { |
|
| 394 | - foreach ($cache_ref['alt_wpts'] as $alt_wpt_key => $alt_wpt) |
|
| 395 | - { |
|
| 396 | - if ('alt_wpt:'.$alt_wpt['type'] == $location_source) |
|
| 397 | - { |
|
| 411 | + foreach ($vars['caches'] as &$cache_ref) { |
|
| 412 | + foreach ($cache_ref['alt_wpts'] as $alt_wpt_key => $alt_wpt) { |
|
| 413 | + if ('alt_wpt:'.$alt_wpt['type'] == $location_source) { |
|
| 398 | 414 | # Switch locations between primary wpt and alternate wpt. |
| 399 | 415 | # Also alter the cache name and make sure to append a proper |
| 400 | 416 | # notice. |
@@ -418,8 +434,7 @@ discard block |
||
| 418 | 434 | # remove current alt waypoint |
| 419 | 435 | unset($cache_ref['alt_wpts'][$alt_wpt_key]); |
| 420 | 436 | # add original location as alternate |
| 421 | - if ($vars['alt_wpts']) |
|
| 422 | - { |
|
| 437 | + if ($vars['alt_wpts']) { |
|
| 423 | 438 | $cache_ref['alt_wpts'][] = array( |
| 424 | 439 | 'name' => $cache_ref['code'].'-DEFAULT-COORDS', |
| 425 | 440 | 'location' => $original_location, |
@@ -444,8 +459,7 @@ discard block |
||
| 444 | 459 | |
| 445 | 460 | $ggz_entries = array(); |
| 446 | 461 | |
| 447 | - foreach ($vars['caches'] as &$cache_ref) |
|
| 448 | - { |
|
| 462 | + foreach ($vars['caches'] as &$cache_ref) { |
|
| 449 | 463 | # Every $cache_ref will also be holding a reference to its entry. |
| 450 | 464 | # Note, that more attributes are added while processing gpsfile.tpl.php! |
| 451 | 465 | |
@@ -464,13 +478,14 @@ discard block |
||
| 464 | 478 | |
| 465 | 479 | $ggz_entry['ratings'] = array(); |
| 466 | 480 | $ratings_ref = &$ggz_entry['ratings']; |
| 467 | - if (isset($cache_ref['rating'])){ |
|
| 481 | + if (isset($cache_ref['rating'])) { |
|
| 468 | 482 | $ratings_ref['awesomeness'] = $cache_ref['rating']; |
| 469 | 483 | } |
| 470 | 484 | $ratings_ref['difficulty'] = $cache_ref['difficulty']; |
| 471 | 485 | if (!isset($cache_ref['size'])) { |
| 472 | 486 | $ratings_ref['size'] = 0; // Virtual, Event |
| 473 | - } else if ($cache_ref['oxsize'] !== null) { // is this ox size one-to-one? |
|
| 487 | + } else if ($cache_ref['oxsize'] !== null) { |
|
| 488 | +// is this ox size one-to-one? |
|
| 474 | 489 | $ratings_ref['size'] = $cache_ref['oxsize']; |
| 475 | 490 | } |
| 476 | 491 | $ratings_ref['terrain'] = $cache_ref['terrain']; |
@@ -40,14 +40,16 @@ discard block |
||
| 40 | 40 | <urlname><?= Okapi::xmlescape($c['name']) ?></urlname> |
| 41 | 41 | <sym><?= ($vars['mark_found'] && $c['is_found']) ? "Geocache Found" : "Geocache" ?></sym> |
| 42 | 42 | <type>Geocache|<?= $vars['cache_GPX_types'][$c['type']] ?></type> |
| 43 | - <?php if ($vars['ns_ground']) { /* Does user want us to include Groundspeak's <cache> element? */ ?> |
|
| 43 | + <?php if ($vars['ns_ground']) { |
|
| 44 | +/* Does user want us to include Groundspeak's <cache> element? */ ?> |
|
| 44 | 45 | <groundspeak:cache archived="<?= ($c['status'] == 'Archived') ? "True" : "False" ?>" available="<?= ($c['status'] == 'Available') ? "True" : "False" ?>" id="<?= $c['internal_id'] ?>" xmlns:groundspeak="http://www.groundspeak.com/cache/1/0/1"> |
| 45 | 46 | <groundspeak:name><?= Okapi::xmlescape(isset($c['name_2']) ? $c['name_2'] : $c['name']) ?></groundspeak:name> |
| 46 | 47 | <groundspeak:placed_by><?= Okapi::xmlescape($c['owner']['username']) ?></groundspeak:placed_by> |
| 47 | 48 | <groundspeak:owner id="<?= $vars['user_uuid_to_internal_id'][$c['owner']['uuid']] ?>"><?= Okapi::xmlescape($c['owner']['username']) ?></groundspeak:owner> |
| 48 | 49 | <groundspeak:type><?= $vars['cache_GPX_types'][$c['type']] ?></groundspeak:type> |
| 49 | 50 | <groundspeak:container><?= $vars['cache_GPX_sizes'][$c['size2']] ?></groundspeak:container> |
| 50 | - <?php if ($vars['gc_attrs'] || $vars['gc_ocde_attrs']) { /* Does user want us to include groundspeak:attributes? */ ?> |
|
| 51 | + <?php if ($vars['gc_attrs'] || $vars['gc_ocde_attrs']) { |
|
| 52 | +/* Does user want us to include groundspeak:attributes? */ ?> |
|
| 51 | 53 | <groundspeak:attributes> |
| 52 | 54 | <?php |
| 53 | 55 | foreach ($c['gc_attrs'] as $gc_id => $gc_attr) { |
@@ -71,23 +73,28 @@ discard block |
||
| 71 | 73 | <p> |
| 72 | 74 | <a href="<?= $c['url'] ?>"><?= Okapi::xmlescape($c['name']) ?></a> |
| 73 | 75 | <?= _("hidden by") ?> <a href='<?= $c['owner']['profile_url'] ?>'><?= Okapi::xmlescape($c['owner']['username']) ?></a><br/> |
| 74 | - <?php if ($vars['recommendations'] == 'desc:count') { /* Does user want us to include recommendations count? */ ?> |
|
| 76 | + <?php if ($vars['recommendations'] == 'desc:count') { |
|
| 77 | +/* Does user want us to include recommendations count? */ ?> |
|
| 75 | 78 | <?= sprintf(ngettext("%d recommendation", "%d recommendations", $c['recommendations']), $c['recommendations']) ?> |
| 76 | 79 | (<?= sprintf(ngettext("found %d time", "found %d times", $c['founds']), $c['founds']) ?>). |
| 77 | 80 | <?php } ?> |
| 78 | - <?php if ($vars['trackables'] == 'desc:count') { /* Does user want us to include trackables count? */ ?> |
|
| 81 | + <?php if ($vars['trackables'] == 'desc:count') { |
|
| 82 | +/* Does user want us to include trackables count? */ ?> |
|
| 79 | 83 | <?= sprintf(ngettext("%d trackable", "%d trackables", $c['trackables_count']), $c['trackables_count']) ?>. |
| 80 | 84 | <?php } ?> |
| 81 | 85 | </p> |
| 82 | - <?php if ((in_array('desc:text', $vars['my_notes'])) && ($c['my_notes'] != null)) { /* Does user want us to include personal notes? */ ?> |
|
| 86 | + <?php if ((in_array('desc:text', $vars['my_notes'])) && ($c['my_notes'] != null)) { |
|
| 87 | +/* Does user want us to include personal notes? */ ?> |
|
| 83 | 88 | <p><b><?= _("Personal notes") ?>:</b><br><?= Okapi::xmlescape(nl2br($c['my_notes'])) ?></p> |
| 84 | 89 | <?php } ?> |
| 85 | 90 | |
| 86 | - <?php if (in_array('desc:text', $vars['attrs']) && count($c['attrnames']) > 0) { /* Does user want us to include attributes? */ ?> |
|
| 91 | + <?php if (in_array('desc:text', $vars['attrs']) && count($c['attrnames']) > 0) { |
|
| 92 | +/* Does user want us to include attributes? */ ?> |
|
| 87 | 93 | <p><?= _("Attributes") ?>:</p> |
| 88 | 94 | <ul><li><?= implode("</li><li>", $c['attrnames']) ?></li></ul> |
| 89 | 95 | <?php } ?> |
| 90 | - <?php if ($vars['trackables'] == 'desc:list' && count($c['trackables']) > 0) { /* Does user want us to include trackables list? */ ?> |
|
| 96 | + <?php if ($vars['trackables'] == 'desc:list' && count($c['trackables']) > 0) { |
|
| 97 | +/* Does user want us to include trackables list? */ ?> |
|
| 91 | 98 | <p><?= _("Trackables") ?>:</p> |
| 92 | 99 | <ul> |
| 93 | 100 | <?php foreach ($c['trackables'] as $t) { ?> |
@@ -96,7 +103,8 @@ discard block |
||
| 96 | 103 | </ul> |
| 97 | 104 | <?php } ?> |
| 98 | 105 | <?= Okapi::xmlescape($c['description']) ?> |
| 99 | - <?php if ((strpos($vars['images'], "descrefs:") === 0) && count($c['images']) > 0) { /* Does user want us to include <img> references in cache descriptions? */ |
|
| 106 | + <?php if ((strpos($vars['images'], "descrefs:") === 0) && count($c['images']) > 0) { |
|
| 107 | +/* Does user want us to include <img> references in cache descriptions? */ |
|
| 100 | 108 | if ($vars['images'] == "descrefs:thumblinks") { ?> |
| 101 | 109 | <h2><?= _("Images") ?> (<?= count($c['images']) ?>)</h2> |
| 102 | 110 | <div> |
@@ -109,9 +117,12 @@ discard block |
||
| 109 | 117 | # We will split images into two subcategories: spoilers and nonspoilers. |
| 110 | 118 | $spoilers = array(); |
| 111 | 119 | $nonspoilers = array(); |
| 112 | - foreach ($c['images'] as $img) |
|
| 113 | - if ($img['is_spoiler']) $spoilers[] = $img; |
|
| 114 | - else $nonspoilers[] = $img; |
|
| 120 | + foreach ($c['images'] as $img) { |
|
| 121 | + if ($img['is_spoiler']) $spoilers[] = $img; |
|
| 122 | + } |
|
| 123 | + else { |
|
| 124 | + $nonspoilers[] = $img; |
|
| 125 | + } |
|
| 115 | 126 | ?> |
| 116 | 127 | <?php if (count($nonspoilers) > 0) { ?> |
| 117 | 128 | <h2><?= _("Images") ?> (<?= count($nonspoilers) ?>)</h2> |
@@ -129,7 +140,8 @@ discard block |
||
| 129 | 140 | <?php } ?> |
| 130 | 141 | <?php } ?> |
| 131 | 142 | <?php } ?> |
| 132 | - <?php if ((strpos($vars['images'], "ox:") === 0) && count($c['images']) > 0) { /* Include image descriptions (for ox:image numbers)? */ ?> |
|
| 143 | + <?php if ((strpos($vars['images'], "ox:") === 0) && count($c['images']) > 0) { |
|
| 144 | +/* Include image descriptions (for ox:image numbers)? */ ?> |
|
| 133 | 145 | <p><?= _("Image descriptions") ?>:</p> |
| 134 | 146 | <ul> |
| 135 | 147 | <?php foreach ($c['images'] as $no => $img) { ?> |
@@ -147,10 +159,12 @@ discard block |
||
| 147 | 159 | <?php } ?> |
| 148 | 160 | </groundspeak:long_description> |
| 149 | 161 | <groundspeak:encoded_hints><?= Okapi::xmlescape($c['hint2']) ?></groundspeak:encoded_hints> |
| 150 | - <?php if ((in_array('gc:personal_note', $vars['my_notes'])) && ($c['my_notes'] != null)) { /* Does user want us to include personal notes? -> Issue 294 */ ?> |
|
| 162 | + <?php if ((in_array('gc:personal_note', $vars['my_notes'])) && ($c['my_notes'] != null)) { |
|
| 163 | +/* Does user want us to include personal notes? -> Issue 294 */ ?> |
|
| 151 | 164 | <groundspeak:personal_note><?= Okapi::xmlescape($c['my_notes']) ?></groundspeak:personal_note> |
| 152 | 165 | <?php } ?> |
| 153 | - <?php if ($vars['latest_logs']) { /* Does user want us to include latest log entries? */ ?> |
|
| 166 | + <?php if ($vars['latest_logs']) { |
|
| 167 | +/* Does user want us to include latest log entries? */ ?> |
|
| 154 | 168 | <groundspeak:logs> |
| 155 | 169 | <?php foreach ($c['latest_logs'] as $log) { ?> |
| 156 | 170 | <groundspeak:log id="<?= $log['internal_id'] ?>"> |
@@ -164,7 +178,8 @@ discard block |
||
| 164 | 178 | <?php } ?> |
| 165 | 179 | </groundspeak:cache> |
| 166 | 180 | <?php } ?> |
| 167 | - <?php if ($vars['ns_ox']) { /* Does user want us to include Garmin's <opencaching> element? */ ?> |
|
| 181 | + <?php if ($vars['ns_ox']) { |
|
| 182 | +/* Does user want us to include Garmin's <opencaching> element? */ ?> |
|
| 168 | 183 | <ox:opencaching xmlns:ox="http://www.opencaching.com/xmlschemas/opencaching/1/0"> |
| 169 | 184 | <ox:ratings> |
| 170 | 185 | <?php if ($c['rating'] !== null) { ?><ox:awesomeness><?= $c['rating'] ?></ox:awesomeness><?php } ?> |
@@ -172,10 +187,12 @@ discard block |
||
| 172 | 187 | <?php if ($c['oxsize'] !== null) { ?><ox:size><?= $c['oxsize'] ?></ox:size><?php } ?> |
| 173 | 188 | <ox:terrain><?= $c['terrain'] ?></ox:terrain> |
| 174 | 189 | </ox:ratings> |
| 175 | - <?php if (in_array('ox:tags', $vars['attrs']) && count($c['attrnames']) > 0) { /* Does user want us to include ox:tags? */ ?> |
|
| 190 | + <?php if (in_array('ox:tags', $vars['attrs']) && count($c['attrnames']) > 0) { |
|
| 191 | +/* Does user want us to include ox:tags? */ ?> |
|
| 176 | 192 | <ox:tags><ox:tag><?= implode("</ox:tag><ox:tag>", $c['attrnames']) ?></ox:tag></ox:tags> |
| 177 | 193 | <?php } ?> |
| 178 | - <?php if ((strpos($vars['images'], "ox:") === 0) && count($c['images']) > 0) { /* Does user want us to include ox:image references? */ ?> |
|
| 194 | + <?php if ((strpos($vars['images'], "ox:") === 0) && count($c['images']) > 0) { |
|
| 195 | +/* Does user want us to include ox:image references? */ ?> |
|
| 179 | 196 | <ox:images> |
| 180 | 197 | <?php foreach ($c['images'] as $no => $img) { ?> |
| 181 | 198 | <ox:image> |
@@ -220,7 +237,7 @@ discard block |
||
| 220 | 237 | <?php } ?> |
| 221 | 238 | </wpt> |
| 222 | 239 | <?php |
| 223 | - if (isset($wpt_ref['ggz_entry'])){ |
|
| 240 | + if (isset($wpt_ref['ggz_entry'])) { |
|
| 224 | 241 | $wpt_ref['ggz_entry']['file_len'] = ob_get_length() - $wpt_ref['ggz_entry']['file_pos']; |
| 225 | 242 | } |
| 226 | 243 | ?> |
@@ -24,19 +24,33 @@ discard block |
||
| 24 | 24 | public static function call(OkapiRequest $request) |
| 25 | 25 | { |
| 26 | 26 | $cache_code = $request->get_parameter('cache_code'); |
| 27 | - if (!$cache_code) throw new ParamMissing('cache_code'); |
|
| 28 | - if (strpos($cache_code, "|") !== false) throw new InvalidParam('cache_code'); |
|
| 27 | + if (!$cache_code) { |
|
| 28 | + throw new ParamMissing('cache_code'); |
|
| 29 | + } |
|
| 30 | + if (strpos($cache_code, "|") !== false) { |
|
| 31 | + throw new InvalidParam('cache_code'); |
|
| 32 | + } |
|
| 29 | 33 | $langpref = $request->get_parameter('langpref'); |
| 30 | - if (!$langpref) $langpref = "en"; |
|
| 34 | + if (!$langpref) { |
|
| 35 | + $langpref = "en"; |
|
| 36 | + } |
|
| 31 | 37 | $langpref .= "|".Settings::get('SITELANG'); |
| 32 | 38 | $fields = $request->get_parameter('fields'); |
| 33 | - if (!$fields) $fields = "code|name|location|type|status"; |
|
| 39 | + if (!$fields) { |
|
| 40 | + $fields = "code|name|location|type|status"; |
|
| 41 | + } |
|
| 34 | 42 | $log_fields = $request->get_parameter('log_fields'); |
| 35 | - if (!$log_fields) $log_fields = "uuid|date|user|type|comment"; |
|
| 43 | + if (!$log_fields) { |
|
| 44 | + $log_fields = "uuid|date|user|type|comment"; |
|
| 45 | + } |
|
| 36 | 46 | $lpc = $request->get_parameter('lpc'); |
| 37 | - if (!$lpc) $lpc = 10; |
|
| 47 | + if (!$lpc) { |
|
| 48 | + $lpc = 10; |
|
| 49 | + } |
|
| 38 | 50 | $attribution_append = $request->get_parameter('attribution_append'); |
| 39 | - if (!$attribution_append) $attribution_append = 'full'; |
|
| 51 | + if (!$attribution_append) { |
|
| 52 | + $attribution_append = 'full'; |
|
| 53 | + } |
|
| 40 | 54 | $params = array( |
| 41 | 55 | 'cache_codes' => $cache_code, |
| 42 | 56 | 'langpref' => $langpref, |
@@ -46,11 +60,13 @@ discard block |
||
| 46 | 60 | 'log_fields' => $log_fields |
| 47 | 61 | ); |
| 48 | 62 | $my_location = $request->get_parameter('my_location'); |
| 49 | - if ($my_location) |
|
| 50 | - $params['my_location'] = $my_location; |
|
| 63 | + if ($my_location) { |
|
| 64 | + $params['my_location'] = $my_location; |
|
| 65 | + } |
|
| 51 | 66 | $user_uuid = $request->get_parameter('user_uuid'); |
| 52 | - if ($user_uuid) |
|
| 53 | - $params['user_uuid'] = $user_uuid; |
|
| 67 | + if ($user_uuid) { |
|
| 68 | + $params['user_uuid'] = $user_uuid; |
|
| 69 | + } |
|
| 54 | 70 | |
| 55 | 71 | # There's no need to validate the fields/lpc parameters as the 'geocaches' |
| 56 | 72 | # method does this (it will raise a proper exception on invalid values). |
@@ -58,8 +74,7 @@ discard block |
||
| 58 | 74 | $results = OkapiServiceRunner::call('services/caches/geocaches', new OkapiInternalRequest( |
| 59 | 75 | $request->consumer, $request->token, $params)); |
| 60 | 76 | $result = $results[$cache_code]; |
| 61 | - if ($result === null) |
|
| 62 | - { |
|
| 77 | + if ($result === null) { |
|
| 63 | 78 | # Two errors messages (for OCDE). Makeshift solution for issue #350. |
| 64 | 79 | |
| 65 | 80 | $exists = Db::select_value(" |
@@ -24,98 +24,104 @@ |
||
| 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 |
| 64 | - try |
|
| 65 | - { |
|
| 76 | + try { |
|
| 66 | 77 | $search_result = OkapiServiceRunner::call($search_method, new OkapiInternalRequest( |
| 67 | 78 | $request->consumer, $request->token, $search_params)); |
| 68 | - } |
|
| 69 | - catch (BadRequest $e) |
|
| 70 | - { |
|
| 79 | + } catch (BadRequest $e) { |
|
| 71 | 80 | throw new InvalidParam('search_params', "Search method responded with the ". |
| 72 | 81 | "following error message: ".$e->getMessage()); |
| 73 | 82 | } |
| 74 | 83 | |
| 75 | 84 | # Run retrieval method |
| 76 | - try |
|
| 77 | - { |
|
| 85 | + try { |
|
| 78 | 86 | $retr_result = OkapiServiceRunner::call($retr_method, new OkapiInternalRequest( |
| 79 | 87 | $request->consumer, $request->token, array_merge($retr_params, |
| 80 | 88 | array('cache_codes' => implode("|", $search_result['results']))))); |
| 81 | - } |
|
| 82 | - catch (BadRequest $e) |
|
| 83 | - { |
|
| 89 | + } catch (BadRequest $e) { |
|
| 84 | 90 | throw new InvalidParam('retr_params', "Retrieval method responded with the ". |
| 85 | 91 | "following error message: ".$e->getMessage()); |
| 86 | 92 | } |
| 87 | 93 | |
| 88 | - if ($wrap) |
|
| 89 | - { |
|
| 94 | + if ($wrap) { |
|
| 90 | 95 | # $retr_result might be a PHP object, but also might be a binary response |
| 91 | 96 | # (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') |
|
| 97 | + if ($retr_result instanceof OkapiHttpResponse) { |
|
| 98 | + $result = array('results' => $retr_result->get_body()); |
|
| 99 | + } else { |
|
| 100 | + $result = array('results' => $retr_result); |
|
| 101 | + } |
|
| 102 | + foreach ($search_result as $key => &$value_ref) { |
|
| 103 | + if ($key != 'results') |
|
| 98 | 104 | $result[$key] = $value_ref; |
| 105 | + } |
|
| 99 | 106 | return Okapi::formatted_response($request, $result); |
| 100 | - } |
|
| 101 | - else |
|
| 102 | - { |
|
| 103 | - if ($retr_result instanceof OkapiHttpResponse) |
|
| 104 | - return $retr_result; |
|
| 105 | - else |
|
| 106 | - return Okapi::formatted_response($request, $retr_result); |
|
| 107 | + } else { |
|
| 108 | + if ($retr_result instanceof OkapiHttpResponse) { |
|
| 109 | + return $retr_result; |
|
| 110 | + } else { |
|
| 111 | + return Okapi::formatted_response($request, $retr_result); |
|
| 112 | + } |
|
| 107 | 113 | } |
| 108 | 114 | } |
| 109 | 115 | |
| 110 | 116 | private static function map_values_to_strings(&$dict) |
| 111 | 117 | { |
| 112 | - foreach (array_keys($dict) as $key) |
|
| 113 | - { |
|
| 118 | + foreach (array_keys($dict) as $key) { |
|
| 114 | 119 | $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); |
|
| 120 | + if (is_numeric($val) || is_string($val)) { |
|
| 121 | + $dict[$key] = (string)$val; |
|
| 122 | + } else { |
|
| 123 | + throw new BadRequest("Invalid value format for key: ".$key); |
|
| 124 | + } |
|
| 119 | 125 | } |
| 120 | 126 | } |
| 121 | 127 | } |
@@ -40,33 +40,41 @@ discard block |
||
| 40 | 40 | public static function call(OkapiRequest $request) |
| 41 | 41 | { |
| 42 | 42 | $cache_codes = $request->get_parameter('cache_codes'); |
| 43 | - if ($cache_codes === null) throw new ParamMissing('cache_codes'); |
|
| 44 | - if ($cache_codes === "") |
|
| 45 | - { |
|
| 43 | + if ($cache_codes === null) { |
|
| 44 | + throw new ParamMissing('cache_codes'); |
|
| 45 | + } |
|
| 46 | + if ($cache_codes === "") { |
|
| 46 | 47 | # Issue 106 requires us to allow empty list of cache codes to be passed into this method. |
| 47 | 48 | # All of the queries below have to be ready for $cache_codes to be empty! |
| 48 | 49 | $cache_codes = array(); |
| 50 | + } else { |
|
| 51 | + $cache_codes = explode("|", $cache_codes); |
|
| 49 | 52 | } |
| 50 | - else |
|
| 51 | - $cache_codes = explode("|", $cache_codes); |
|
| 52 | 53 | |
| 53 | - if ((count($cache_codes) > 500) && (!$request->skip_limits)) |
|
| 54 | - throw new InvalidParam('cache_codes', "Maximum allowed number of referenced ". |
|
| 54 | + if ((count($cache_codes) > 500) && (!$request->skip_limits)) { |
|
| 55 | + throw new InvalidParam('cache_codes', "Maximum allowed number of referenced ". |
|
| 55 | 56 | "caches is 500. You provided ".count($cache_codes)." cache codes."); |
| 56 | - if (count($cache_codes) != count(array_unique($cache_codes))) |
|
| 57 | - throw new InvalidParam('cache_codes', "Duplicate codes detected (make sure each cache is referenced only once)."); |
|
| 57 | + } |
|
| 58 | + if (count($cache_codes) != count(array_unique($cache_codes))) { |
|
| 59 | + throw new InvalidParam('cache_codes', "Duplicate codes detected (make sure each cache is referenced only once)."); |
|
| 60 | + } |
|
| 58 | 61 | |
| 59 | 62 | $langpref = $request->get_parameter('langpref'); |
| 60 | - if (!$langpref) $langpref = "en"; |
|
| 63 | + if (!$langpref) { |
|
| 64 | + $langpref = "en"; |
|
| 65 | + } |
|
| 61 | 66 | $langpref .= "|".Settings::get('SITELANG'); |
| 62 | 67 | $langpref = explode("|", $langpref); |
| 63 | 68 | |
| 64 | 69 | $fields = $request->get_parameter('fields'); |
| 65 | - if (!$fields) $fields = "code|name|location|type|status"; |
|
| 70 | + if (!$fields) { |
|
| 71 | + $fields = "code|name|location|type|status"; |
|
| 72 | + } |
|
| 66 | 73 | $fields = explode("|", $fields); |
| 67 | - foreach ($fields as $field) |
|
| 68 | - if (!in_array($field, self::$valid_field_names)) |
|
| 74 | + foreach ($fields as $field) { |
|
| 75 | + if (!in_array($field, self::$valid_field_names)) |
|
| 69 | 76 | throw new InvalidParam('fields', "'$field' is not a valid field code."); |
| 77 | + } |
|
| 70 | 78 | |
| 71 | 79 | # Some fields need to be temporarily included whenever the "description" |
| 72 | 80 | # or "attribution_note" field are included. That's a little ugly, but |
@@ -79,79 +87,88 @@ discard block |
||
| 79 | 87 | || in_array('hint', $fields) || in_array('hints', $fields) |
| 80 | 88 | || in_array('hint2', $fields) || in_array('hints2', $fields) |
| 81 | 89 | || in_array('attribution_note', $fields) |
| 82 | - ) |
|
| 83 | - { |
|
| 84 | - if (!in_array('owner', $fields)) |
|
| 85 | - { |
|
| 90 | + ) { |
|
| 91 | + if (!in_array('owner', $fields)) { |
|
| 86 | 92 | $fields[] = "owner"; |
| 87 | 93 | $fields_to_remove_later[] = "owner"; |
| 88 | 94 | } |
| 89 | - if (!in_array('internal_id', $fields)) |
|
| 90 | - { |
|
| 95 | + if (!in_array('internal_id', $fields)) { |
|
| 91 | 96 | $fields[] = "internal_id"; |
| 92 | 97 | $fields_to_remove_later[] = "internal_id"; |
| 93 | 98 | } |
| 94 | 99 | } |
| 95 | 100 | |
| 96 | 101 | $attribution_append = $request->get_parameter('attribution_append'); |
| 97 | - if (!$attribution_append) $attribution_append = 'full'; |
|
| 98 | - if (!in_array($attribution_append, array('none', 'static', 'full'))) |
|
| 99 | - throw new InvalidParam('attribution_append'); |
|
| 102 | + if (!$attribution_append) { |
|
| 103 | + $attribution_append = 'full'; |
|
| 104 | + } |
|
| 105 | + if (!in_array($attribution_append, array('none', 'static', 'full'))) { |
|
| 106 | + throw new InvalidParam('attribution_append'); |
|
| 107 | + } |
|
| 100 | 108 | |
| 101 | 109 | $log_fields = $request->get_parameter('log_fields'); |
| 102 | - if (!$log_fields) $log_fields = "uuid|date|user|type|comment"; // validation is done on call |
|
| 110 | + if (!$log_fields) { |
|
| 111 | + $log_fields = "uuid|date|user|type|comment"; |
|
| 112 | + } |
|
| 113 | + // validation is done on call |
|
| 103 | 114 | |
| 104 | 115 | $user_uuid = $request->get_parameter('user_uuid'); |
| 105 | - if ($user_uuid != null) |
|
| 106 | - { |
|
| 116 | + if ($user_uuid != null) { |
|
| 107 | 117 | $user_id = Db::select_value("select user_id from user where uuid='".Db::escape_string($user_uuid)."'"); |
| 108 | - if ($user_id == null) |
|
| 109 | - throw new InvalidParam('user_uuid', "User not found."); |
|
| 110 | - if (($request->token != null) && ($request->token->user_id != $user_id)) |
|
| 111 | - throw new InvalidParam('user_uuid', "User does not match the Access Token used."); |
|
| 118 | + if ($user_id == null) { |
|
| 119 | + throw new InvalidParam('user_uuid', "User not found."); |
|
| 120 | + } |
|
| 121 | + if (($request->token != null) && ($request->token->user_id != $user_id)) { |
|
| 122 | + throw new InvalidParam('user_uuid', "User does not match the Access Token used."); |
|
| 123 | + } |
|
| 124 | + } elseif (($user_uuid == null) && ($request->token != null)) { |
|
| 125 | + $user_id = $request->token->user_id; |
|
| 126 | + } else { |
|
| 127 | + $user_id = null; |
|
| 112 | 128 | } |
| 113 | - elseif (($user_uuid == null) && ($request->token != null)) |
|
| 114 | - $user_id = $request->token->user_id; |
|
| 115 | - else |
|
| 116 | - $user_id = null; |
|
| 117 | 129 | |
| 118 | 130 | $lpc = $request->get_parameter('lpc'); |
| 119 | - if ($lpc === null) $lpc = 10; |
|
| 120 | - if ($lpc == 'all') |
|
| 121 | - $lpc = null; |
|
| 122 | - else |
|
| 123 | - { |
|
| 124 | - if (!is_numeric($lpc)) |
|
| 125 | - throw new InvalidParam('lpc', "Invalid number: '$lpc'"); |
|
| 131 | + if ($lpc === null) { |
|
| 132 | + $lpc = 10; |
|
| 133 | + } |
|
| 134 | + if ($lpc == 'all') { |
|
| 135 | + $lpc = null; |
|
| 136 | + } else { |
|
| 137 | + if (!is_numeric($lpc)) { |
|
| 138 | + throw new InvalidParam('lpc', "Invalid number: '$lpc'"); |
|
| 139 | + } |
|
| 126 | 140 | $lpc = intval($lpc); |
| 127 | - if ($lpc < 0) |
|
| 128 | - throw new InvalidParam('lpc', "Must be a positive value."); |
|
| 141 | + if ($lpc < 0) { |
|
| 142 | + throw new InvalidParam('lpc', "Must be a positive value."); |
|
| 143 | + } |
|
| 129 | 144 | } |
| 130 | 145 | |
| 131 | 146 | if (in_array('distance', $fields) || in_array('bearing', $fields) || in_array('bearing2', $fields) |
| 132 | - || in_array('bearing3', $fields)) |
|
| 133 | - { |
|
| 147 | + || in_array('bearing3', $fields)) { |
|
| 134 | 148 | $tmp = $request->get_parameter('my_location'); |
| 135 | - if (!$tmp) |
|
| 136 | - throw new BadRequest("When using 'distance' or 'bearing' fields, you have to supply 'my_location' parameter."); |
|
| 149 | + if (!$tmp) { |
|
| 150 | + throw new BadRequest("When using 'distance' or 'bearing' fields, you have to supply 'my_location' parameter."); |
|
| 151 | + } |
|
| 137 | 152 | $parts = explode('|', $tmp); |
| 138 | - if (count($parts) != 2) |
|
| 139 | - throw new InvalidParam('my_location', "Expecting 2 pipe-separated parts, got ".count($parts)."."); |
|
| 140 | - foreach ($parts as &$part_ref) |
|
| 141 | - { |
|
| 142 | - if (!preg_match("/^-?[0-9]+(\.?[0-9]*)$/", $part_ref)) |
|
| 143 | - throw new InvalidParam('my_location', "'$part_ref' is not a valid float number."); |
|
| 153 | + if (count($parts) != 2) { |
|
| 154 | + throw new InvalidParam('my_location', "Expecting 2 pipe-separated parts, got ".count($parts)."."); |
|
| 155 | + } |
|
| 156 | + foreach ($parts as &$part_ref) { |
|
| 157 | + if (!preg_match("/^-?[0-9]+(\.?[0-9]*)$/", $part_ref)) { |
|
| 158 | + throw new InvalidParam('my_location', "'$part_ref' is not a valid float number."); |
|
| 159 | + } |
|
| 144 | 160 | $part_ref = floatval($part_ref); |
| 145 | 161 | } |
| 146 | 162 | list($center_lat, $center_lon) = $parts; |
| 147 | - if ($center_lat > 90 || $center_lat < -90) |
|
| 148 | - throw new InvalidParam('current_position', "Latitudes have to be within -90..90 range."); |
|
| 149 | - if ($center_lon > 180 || $center_lon < -180) |
|
| 150 | - throw new InvalidParam('current_position', "Longitudes have to be within -180..180 range."); |
|
| 163 | + if ($center_lat > 90 || $center_lat < -90) { |
|
| 164 | + throw new InvalidParam('current_position', "Latitudes have to be within -90..90 range."); |
|
| 165 | + } |
|
| 166 | + if ($center_lon > 180 || $center_lon < -180) { |
|
| 167 | + throw new InvalidParam('current_position', "Longitudes have to be within -180..180 range."); |
|
| 168 | + } |
|
| 151 | 169 | } |
| 152 | 170 | |
| 153 | - if (Settings::get('OC_BRANCH') == 'oc.de') |
|
| 154 | - { |
|
| 171 | + if (Settings::get('OC_BRANCH') == 'oc.de') { |
|
| 155 | 172 | # DE branch: |
| 156 | 173 | # - Caches do not have ratings. |
| 157 | 174 | # - Total numbers of founds and notfounds are kept in the "stat_caches" table. |
@@ -181,9 +198,7 @@ discard block |
||
| 181 | 198 | wp_oc in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes))."') |
| 182 | 199 | and status in (1,2,3) |
| 183 | 200 | "); |
| 184 | - } |
|
| 185 | - elseif (Settings::get('OC_BRANCH') == 'oc.pl') |
|
| 186 | - { |
|
| 201 | + } elseif (Settings::get('OC_BRANCH') == 'oc.pl') { |
|
| 187 | 202 | # PL branch: |
| 188 | 203 | # - Caches have ratings. |
| 189 | 204 | # - Total numbers of found and notfounds are kept in the "caches" table. |
@@ -218,23 +233,21 @@ discard block |
||
| 218 | 233 | $cacheid2wptcode = array(); |
| 219 | 234 | $owner_ids = array(); |
| 220 | 235 | $outdated_listings = array(); |
| 221 | - while ($row = Db::fetch_assoc($rs)) |
|
| 222 | - { |
|
| 236 | + while ($row = Db::fetch_assoc($rs)) { |
|
| 223 | 237 | $entry = array(); |
| 224 | 238 | $cacheid2wptcode[$row['cache_id']] = $row['wp_oc']; |
| 225 | - foreach ($fields as $field) |
|
| 226 | - { |
|
| 227 | - switch ($field) |
|
| 228 | - { |
|
| 239 | + foreach ($fields as $field) { |
|
| 240 | + switch ($field) { |
|
| 229 | 241 | case 'code': $entry['code'] = $row['wp_oc']; break; |
| 230 | 242 | case 'gc_code': |
| 231 | 243 | $wp_gc = $row['wp_gc_maintained'] ? $row['wp_gc_maintained'] : $row['wp_gc']; |
| 232 | 244 | // OC software allows entering anything here, and that's what users do. |
| 233 | 245 | // We do a formal verification so that only a valid GC code is returned: |
| 234 | - if (preg_match('/^\s*[Gg][Cc][A-Za-z0-9]+\s*$/', $wp_gc)) |
|
| 235 | - $entry['gc_code'] = strtoupper(trim($wp_gc)); |
|
| 236 | - else |
|
| 237 | - $entry['gc_code'] = null; |
|
| 246 | + if (preg_match('/^\s*[Gg][Cc][A-Za-z0-9]+\s*$/', $wp_gc)) { |
|
| 247 | + $entry['gc_code'] = strtoupper(trim($wp_gc)); |
|
| 248 | + } else { |
|
| 249 | + $entry['gc_code'] = null; |
|
| 250 | + } |
|
| 238 | 251 | unset($wp_gc); |
| 239 | 252 | break; |
| 240 | 253 | case 'name': $entry['name'] = $row['name']; break; |
@@ -269,23 +282,26 @@ discard block |
||
| 269 | 282 | case 'is_ignored': /* handled separately */ break; |
| 270 | 283 | case 'founds': $entry['founds'] = $row['founds'] + 0; break; |
| 271 | 284 | case 'notfounds': |
| 272 | - if ($row['type'] != 6) { # non-event |
|
| 285 | + if ($row['type'] != 6) { |
|
| 286 | +# non-event |
|
| 273 | 287 | $entry['notfounds'] = $row['notfounds'] + 0; |
| 274 | - } else { # event |
|
| 288 | + } else { |
|
| 289 | +# event |
|
| 275 | 290 | $entry['notfounds'] = 0; |
| 276 | 291 | } |
| 277 | 292 | break; |
| 278 | 293 | case 'willattends': |
| 279 | - if ($row['type'] == 6) { # event |
|
| 294 | + if ($row['type'] == 6) { |
|
| 295 | +# event |
|
| 280 | 296 | $entry['willattends'] = $row['willattends'] + 0; |
| 281 | - } else { # non-event |
|
| 297 | + } else { |
|
| 298 | +# non-event |
|
| 282 | 299 | $entry['willattends'] = 0; |
| 283 | 300 | } |
| 284 | 301 | break; |
| 285 | 302 | case 'size': |
| 286 | 303 | # Deprecated. Leave it for backward-compatibility. See issue 155. |
| 287 | - switch (Okapi::cache_sizeid_to_size2($row['size'])) |
|
| 288 | - { |
|
| 304 | + switch (Okapi::cache_sizeid_to_size2($row['size'])) { |
|
| 289 | 305 | case 'none': $entry['size'] = null; break; |
| 290 | 306 | case 'nano': $entry['size'] = 1.0; break; # same as micro |
| 291 | 307 | case 'micro': $entry['size'] = 1.0; break; |
@@ -312,12 +328,19 @@ discard block |
||
| 312 | 328 | $entry['trip_distance'] = $row['trip_distance'] === null ? null : round($row['trip_distance'],3); break; |
| 313 | 329 | break; |
| 314 | 330 | case 'rating': |
| 315 | - if ($row['votes'] < 3) $entry['rating'] = null; |
|
| 316 | - elseif ($row['score'] >= 2.2) $entry['rating'] = 5.0; |
|
| 317 | - elseif ($row['score'] >= 1.4) $entry['rating'] = 4.0; |
|
| 318 | - elseif ($row['score'] >= 0.1) $entry['rating'] = 3.0; |
|
| 319 | - elseif ($row['score'] >= -1.0) $entry['rating'] = 2.0; |
|
| 320 | - else $entry['rating'] = 1.0; |
|
| 331 | + if ($row['votes'] < 3) { |
|
| 332 | + $entry['rating'] = null; |
|
| 333 | + } elseif ($row['score'] >= 2.2) { |
|
| 334 | + $entry['rating'] = 5.0; |
|
| 335 | + } elseif ($row['score'] >= 1.4) { |
|
| 336 | + $entry['rating'] = 4.0; |
|
| 337 | + } elseif ($row['score'] >= 0.1) { |
|
| 338 | + $entry['rating'] = 3.0; |
|
| 339 | + } elseif ($row['score'] >= -1.0) { |
|
| 340 | + $entry['rating'] = 2.0; |
|
| 341 | + } else { |
|
| 342 | + $entry['rating'] = 1.0; |
|
| 343 | + } |
|
| 321 | 344 | break; |
| 322 | 345 | case 'rating_votes': $entry['rating_votes'] = $row['votes'] + 0; break; |
| 323 | 346 | case 'recommendations': $entry['recommendations'] = $row['topratings'] + 0; break; |
@@ -352,25 +375,25 @@ discard block |
||
| 352 | 375 | } |
| 353 | 376 | } |
| 354 | 377 | $results[$row['wp_oc']] = $entry; |
| 355 | - if ($row['listing_outdated'] > 0) |
|
| 356 | - $outdated_listings[] = $row['wp_oc']; |
|
| 378 | + if ($row['listing_outdated'] > 0) { |
|
| 379 | + $outdated_listings[] = $row['wp_oc']; |
|
| 380 | + } |
|
| 357 | 381 | } |
| 358 | 382 | Db::free_result($rs); |
| 359 | 383 | |
| 360 | 384 | # owner |
| 361 | 385 | |
| 362 | - if (in_array('owner', $fields) && (count($results) > 0)) |
|
| 363 | - { |
|
| 386 | + if (in_array('owner', $fields) && (count($results) > 0)) { |
|
| 364 | 387 | $rs = Db::query(" |
| 365 | 388 | select user_id, uuid, username |
| 366 | 389 | from user |
| 367 | 390 | where user_id in ('".implode("','", array_map('\okapi\Db::escape_string', array_values($owner_ids)))."') |
| 368 | 391 | "); |
| 369 | 392 | $tmp = array(); |
| 370 | - while ($row = Db::fetch_assoc($rs)) |
|
| 371 | - $tmp[$row['user_id']] = $row; |
|
| 372 | - foreach ($results as $cache_code => &$result_ref) |
|
| 373 | - { |
|
| 393 | + while ($row = Db::fetch_assoc($rs)) { |
|
| 394 | + $tmp[$row['user_id']] = $row; |
|
| 395 | + } |
|
| 396 | + foreach ($results as $cache_code => &$result_ref) { |
|
| 374 | 397 | $row = $tmp[$owner_ids[$cache_code]]; |
| 375 | 398 | $result_ref['owner'] = array( |
| 376 | 399 | 'uuid' => $row['uuid'], |
@@ -382,10 +405,10 @@ discard block |
||
| 382 | 405 | |
| 383 | 406 | # is_found |
| 384 | 407 | |
| 385 | - if (in_array('is_found', $fields)) |
|
| 386 | - { |
|
| 387 | - if ($user_id == null) |
|
| 388 | - throw new BadRequest("Either 'user_uuid' parameter OR Level 3 Authentication is required to access 'is_found' field."); |
|
| 408 | + if (in_array('is_found', $fields)) { |
|
| 409 | + if ($user_id == null) { |
|
| 410 | + throw new BadRequest("Either 'user_uuid' parameter OR Level 3 Authentication is required to access 'is_found' field."); |
|
| 411 | + } |
|
| 389 | 412 | $tmp = Db::select_column(" |
| 390 | 413 | select c.wp_oc |
| 391 | 414 | from |
@@ -401,18 +424,20 @@ discard block |
||
| 401 | 424 | ".((Settings::get('OC_BRANCH') == 'oc.pl') ? "and cl.deleted = 0" : "")." |
| 402 | 425 | "); |
| 403 | 426 | $tmp2 = array(); |
| 404 | - foreach ($tmp as $cache_code) |
|
| 405 | - $tmp2[$cache_code] = true; |
|
| 406 | - foreach ($results as $cache_code => &$result_ref) |
|
| 407 | - $result_ref['is_found'] = isset($tmp2[$cache_code]); |
|
| 427 | + foreach ($tmp as $cache_code) { |
|
| 428 | + $tmp2[$cache_code] = true; |
|
| 429 | + } |
|
| 430 | + foreach ($results as $cache_code => &$result_ref) { |
|
| 431 | + $result_ref['is_found'] = isset($tmp2[$cache_code]); |
|
| 432 | + } |
|
| 408 | 433 | } |
| 409 | 434 | |
| 410 | 435 | # is_not_found |
| 411 | 436 | |
| 412 | - if (in_array('is_not_found', $fields)) |
|
| 413 | - { |
|
| 414 | - if ($user_id == null) |
|
| 415 | - throw new BadRequest("Either 'user_uuid' parameter OR Level 3 Authentication is required to access 'is_not_found' field."); |
|
| 437 | + if (in_array('is_not_found', $fields)) { |
|
| 438 | + if ($user_id == null) { |
|
| 439 | + throw new BadRequest("Either 'user_uuid' parameter OR Level 3 Authentication is required to access 'is_not_found' field."); |
|
| 440 | + } |
|
| 416 | 441 | $tmp = Db::select_column(" |
| 417 | 442 | select c.wp_oc |
| 418 | 443 | from |
@@ -425,18 +450,20 @@ discard block |
||
| 425 | 450 | ".((Settings::get('OC_BRANCH') == 'oc.pl') ? "and cl.deleted = 0" : "")." |
| 426 | 451 | "); |
| 427 | 452 | $tmp2 = array(); |
| 428 | - foreach ($tmp as $cache_code) |
|
| 429 | - $tmp2[$cache_code] = true; |
|
| 430 | - foreach ($results as $cache_code => &$result_ref) |
|
| 431 | - $result_ref['is_not_found'] = isset($tmp2[$cache_code]); |
|
| 453 | + foreach ($tmp as $cache_code) { |
|
| 454 | + $tmp2[$cache_code] = true; |
|
| 455 | + } |
|
| 456 | + foreach ($results as $cache_code => &$result_ref) { |
|
| 457 | + $result_ref['is_not_found'] = isset($tmp2[$cache_code]); |
|
| 458 | + } |
|
| 432 | 459 | } |
| 433 | 460 | |
| 434 | 461 | # is_watched |
| 435 | 462 | |
| 436 | - if (in_array('is_watched', $fields)) |
|
| 437 | - { |
|
| 438 | - if ($request->token == null) |
|
| 439 | - throw new BadRequest("Level 3 Authentication is required to access 'is_watched' field."); |
|
| 463 | + if (in_array('is_watched', $fields)) { |
|
| 464 | + if ($request->token == null) { |
|
| 465 | + throw new BadRequest("Level 3 Authentication is required to access 'is_watched' field."); |
|
| 466 | + } |
|
| 440 | 467 | $tmp = Db::select_column(" |
| 441 | 468 | select c.wp_oc |
| 442 | 469 | from |
@@ -447,12 +474,12 @@ discard block |
||
| 447 | 474 | and cw.user_id = '".Db::escape_string($request->token->user_id)."' |
| 448 | 475 | "); |
| 449 | 476 | $tmp2 = array(); |
| 450 | - foreach ($tmp as $cache_code) |
|
| 451 | - $tmp2[$cache_code] = true; |
|
| 477 | + foreach ($tmp as $cache_code) { |
|
| 478 | + $tmp2[$cache_code] = true; |
|
| 479 | + } |
|
| 452 | 480 | |
| 453 | 481 | # OCDE caches can also be indirectly watched by watching cache lists: |
| 454 | - if (Settings::get('OC_BRANCH') == 'oc.de') |
|
| 455 | - { |
|
| 482 | + if (Settings::get('OC_BRANCH') == 'oc.de') { |
|
| 456 | 483 | $tmp = Db::select_column(" |
| 457 | 484 | select c.wp_oc |
| 458 | 485 | from |
@@ -464,20 +491,22 @@ discard block |
||
| 464 | 491 | and clw.cache_list_id = cli.cache_list_id |
| 465 | 492 | and clw.user_id = '".Db::escape_string($request->token->user_id)."' |
| 466 | 493 | "); |
| 467 | - foreach ($tmp as $cache_code) |
|
| 468 | - $tmp2[$cache_code] = true; |
|
| 494 | + foreach ($tmp as $cache_code) { |
|
| 495 | + $tmp2[$cache_code] = true; |
|
| 496 | + } |
|
| 469 | 497 | } |
| 470 | 498 | |
| 471 | - foreach ($results as $cache_code => &$result_ref) |
|
| 472 | - $result_ref['is_watched'] = isset($tmp2[$cache_code]); |
|
| 499 | + foreach ($results as $cache_code => &$result_ref) { |
|
| 500 | + $result_ref['is_watched'] = isset($tmp2[$cache_code]); |
|
| 501 | + } |
|
| 473 | 502 | } |
| 474 | 503 | |
| 475 | 504 | # is_ignored |
| 476 | 505 | |
| 477 | - if (in_array('is_ignored', $fields)) |
|
| 478 | - { |
|
| 479 | - if ($request->token == null) |
|
| 480 | - throw new BadRequest("Level 3 Authentication is required to access 'is_ignored' field."); |
|
| 506 | + if (in_array('is_ignored', $fields)) { |
|
| 507 | + if ($request->token == null) { |
|
| 508 | + throw new BadRequest("Level 3 Authentication is required to access 'is_ignored' field."); |
|
| 509 | + } |
|
| 481 | 510 | $tmp = Db::select_column(" |
| 482 | 511 | select c.wp_oc |
| 483 | 512 | from |
@@ -488,10 +517,12 @@ discard block |
||
| 488 | 517 | and ci.user_id = '".Db::escape_string($request->token->user_id)."' |
| 489 | 518 | "); |
| 490 | 519 | $tmp2 = array(); |
| 491 | - foreach ($tmp as $cache_code) |
|
| 492 | - $tmp2[$cache_code] = true; |
|
| 493 | - foreach ($results as $cache_code => &$result_ref) |
|
| 494 | - $result_ref['is_ignored'] = isset($tmp2[$cache_code]); |
|
| 520 | + foreach ($tmp as $cache_code) { |
|
| 521 | + $tmp2[$cache_code] = true; |
|
| 522 | + } |
|
| 523 | + foreach ($results as $cache_code => &$result_ref) { |
|
| 524 | + $result_ref['is_ignored'] = isset($tmp2[$cache_code]); |
|
| 525 | + } |
|
| 495 | 526 | } |
| 496 | 527 | |
| 497 | 528 | # Descriptions and hints. |
@@ -499,13 +530,11 @@ discard block |
||
| 499 | 530 | if (in_array('description', $fields) || in_array('descriptions', $fields) |
| 500 | 531 | || in_array('short_description', $fields) || in_array('short_descriptions', $fields) |
| 501 | 532 | || in_array('hint', $fields) || in_array('hints', $fields) |
| 502 | - || in_array('hint2', $fields) || in_array('hints2', $fields)) |
|
| 503 | - { |
|
| 533 | + || in_array('hint2', $fields) || in_array('hints2', $fields)) { |
|
| 504 | 534 | # At first, we will fill all those fields, even if user requested just one |
| 505 | 535 | # of them. We will chop off the unwanted ones at the end. |
| 506 | 536 | |
| 507 | - foreach ($results as &$result_ref) |
|
| 508 | - { |
|
| 537 | + foreach ($results as &$result_ref) { |
|
| 509 | 538 | $result_ref['short_descriptions'] = new ArrayObject(); |
| 510 | 539 | $result_ref['descriptions'] = new ArrayObject(); |
| 511 | 540 | $result_ref['hints'] = new ArrayObject(); |
@@ -519,19 +548,16 @@ discard block |
||
| 519 | 548 | from cache_desc |
| 520 | 549 | where cache_id in ('".implode("','", array_map('\okapi\Db::escape_string', array_keys($cacheid2wptcode)))."') |
| 521 | 550 | "); |
| 522 | - while ($row = Db::fetch_assoc($rs)) |
|
| 523 | - { |
|
| 551 | + while ($row = Db::fetch_assoc($rs)) { |
|
| 524 | 552 | $cache_code = $cacheid2wptcode[$row['cache_id']]; |
| 525 | 553 | // strtolower - ISO 639-1 codes are lowercase |
| 526 | - if ($row['desc']) |
|
| 527 | - { |
|
| 554 | + if ($row['desc']) { |
|
| 528 | 555 | /* Note, that the "owner" and "internal_id" fields are automatically included, |
| 529 | 556 | * whenever the cache description is included. */ |
| 530 | 557 | |
| 531 | 558 | $tmp = Okapi::fix_oc_html($row['desc'], Okapi::OBJECT_TYPE_CACHE); |
| 532 | 559 | |
| 533 | - if (in_array($cache_code, $outdated_listings)) |
|
| 534 | - { |
|
| 560 | + if (in_array($cache_code, $outdated_listings)) { |
|
| 535 | 561 | Okapi::gettext_domain_init(array_merge(array($row['language']), $langpref)); |
| 536 | 562 | $tmp = ( |
| 537 | 563 | "<p style='color:#c00000'><strong>". |
@@ -544,8 +570,7 @@ discard block |
||
| 544 | 570 | Okapi::gettext_domain_restore(); |
| 545 | 571 | } |
| 546 | 572 | |
| 547 | - if ($attribution_append != 'none') |
|
| 548 | - { |
|
| 573 | + if ($attribution_append != 'none') { |
|
| 549 | 574 | $tmp .= "\n<p><em>". |
| 550 | 575 | self::get_cache_attribution_note( |
| 551 | 576 | $row['cache_id'], strtolower($row['language']), $langpref, |
@@ -555,19 +580,16 @@ discard block |
||
| 555 | 580 | } |
| 556 | 581 | $results[$cache_code]['descriptions'][strtolower($row['language'])] = $tmp; |
| 557 | 582 | } |
| 558 | - if ($row['short_desc']) |
|
| 559 | - { |
|
| 583 | + if ($row['short_desc']) { |
|
| 560 | 584 | $results[$cache_code]['short_descriptions'][strtolower($row['language'])] = $row['short_desc']; |
| 561 | 585 | } |
| 562 | - if ($row['hint']) |
|
| 563 | - { |
|
| 586 | + if ($row['hint']) { |
|
| 564 | 587 | $results[$cache_code]['hints'][strtolower($row['language'])] = $row['hint']; |
| 565 | 588 | $results[$cache_code]['hints2'][strtolower($row['language'])] |
| 566 | 589 | = htmlspecialchars_decode(mb_ereg_replace("<br />", "" , $row['hint']), ENT_COMPAT); |
| 567 | 590 | } |
| 568 | 591 | } |
| 569 | - foreach ($results as &$result_ref) |
|
| 570 | - { |
|
| 592 | + foreach ($results as &$result_ref) { |
|
| 571 | 593 | $result_ref['short_description'] = Okapi::pick_best_language($result_ref['short_descriptions'], $langpref); |
| 572 | 594 | $result_ref['description'] = Okapi::pick_best_language($result_ref['descriptions'], $langpref); |
| 573 | 595 | $result_ref['hint'] = Okapi::pick_best_language($result_ref['hints'], $langpref); |
@@ -579,27 +601,30 @@ discard block |
||
| 579 | 601 | foreach (array( |
| 580 | 602 | 'short_description', 'short_descriptions', 'description', 'descriptions', |
| 581 | 603 | 'hint', 'hints', 'hint2', 'hints2' |
| 582 | - ) as $field) |
|
| 583 | - if (!in_array($field, $fields)) |
|
| 604 | + ) as $field) { |
|
| 605 | + if (!in_array($field, $fields)) |
|
| 584 | 606 | foreach ($results as &$result_ref) |
| 585 | 607 | unset($result_ref[$field]); |
| 608 | + } |
|
| 586 | 609 | } |
| 587 | 610 | |
| 588 | 611 | # Images. |
| 589 | 612 | |
| 590 | - if (in_array('images', $fields) || in_array('preview_image', $fields)) |
|
| 591 | - { |
|
| 592 | - if (in_array('images', $fields)) |
|
| 593 | - foreach ($results as &$result_ref) |
|
| 613 | + if (in_array('images', $fields) || in_array('preview_image', $fields)) { |
|
| 614 | + if (in_array('images', $fields)) { |
|
| 615 | + foreach ($results as &$result_ref) |
|
| 594 | 616 | $result_ref['images'] = array(); |
| 595 | - if (in_array('preview_image', $fields)) |
|
| 596 | - foreach ($results as &$result_ref) |
|
| 617 | + } |
|
| 618 | + if (in_array('preview_image', $fields)) { |
|
| 619 | + foreach ($results as &$result_ref) |
|
| 597 | 620 | $result_ref['preview_image'] = null; |
| 621 | + } |
|
| 598 | 622 | |
| 599 | - if (Db::field_exists('pictures', 'mappreview')) |
|
| 600 | - $preview_field = "mappreview"; |
|
| 601 | - else |
|
| 602 | - $preview_field = "0"; |
|
| 623 | + if (Db::field_exists('pictures', 'mappreview')) { |
|
| 624 | + $preview_field = "mappreview"; |
|
| 625 | + } else { |
|
| 626 | + $preview_field = "0"; |
|
| 627 | + } |
|
| 603 | 628 | $rs = Db::query(" |
| 604 | 629 | select object_id, uuid, url, title, spoiler, ".$preview_field." as preview |
| 605 | 630 | from pictures |
@@ -613,11 +638,9 @@ discard block |
||
| 613 | 638 | |
| 614 | 639 | unset($sql); |
| 615 | 640 | $prev_cache_code = null; |
| 616 | - while ($row = Db::fetch_assoc($rs)) |
|
| 617 | - { |
|
| 641 | + while ($row = Db::fetch_assoc($rs)) { |
|
| 618 | 642 | $cache_code = $cacheid2wptcode[$row['object_id']]; |
| 619 | - if ($cache_code != $prev_cache_code) |
|
| 620 | - { |
|
| 643 | + if ($cache_code != $prev_cache_code) { |
|
| 621 | 644 | # Group images together. Images must have unique captions within one cache. |
| 622 | 645 | self::reset_unique_captions(); |
| 623 | 646 | $prev_cache_code = $cache_code; |
@@ -635,26 +658,27 @@ discard block |
||
| 635 | 658 | 'unique_caption' => self::get_unique_caption($row['title']), |
| 636 | 659 | 'is_spoiler' => ($row['spoiler'] ? true : false), |
| 637 | 660 | ); |
| 638 | - if (in_array('images', $fields)) |
|
| 639 | - $results[$cache_code]['images'][] = $image; |
|
| 640 | - if ($row['preview'] != 0 && in_array('preview_image', $fields)) |
|
| 641 | - $results[$cache_code]['preview_image'] = $image; |
|
| 661 | + if (in_array('images', $fields)) { |
|
| 662 | + $results[$cache_code]['images'][] = $image; |
|
| 663 | + } |
|
| 664 | + if ($row['preview'] != 0 && in_array('preview_image', $fields)) { |
|
| 665 | + $results[$cache_code]['preview_image'] = $image; |
|
| 666 | + } |
|
| 642 | 667 | } |
| 643 | 668 | } |
| 644 | 669 | |
| 645 | 670 | # A-codes and attrnames |
| 646 | 671 | |
| 647 | - if (in_array('attr_acodes', $fields) || in_array('attrnames', $fields)) |
|
| 648 | - { |
|
| 672 | + if (in_array('attr_acodes', $fields) || in_array('attrnames', $fields)) { |
|
| 649 | 673 | # Either case, we'll need acodes. If the user didn't want them, |
| 650 | 674 | # remember to remove them later. |
| 651 | 675 | |
| 652 | - if (!in_array('attr_acodes', $fields)) |
|
| 653 | - { |
|
| 676 | + if (!in_array('attr_acodes', $fields)) { |
|
| 654 | 677 | $fields_to_remove_later[] = 'attr_acodes'; |
| 655 | 678 | } |
| 656 | - foreach ($results as &$result_ref) |
|
| 657 | - $result_ref['attr_acodes'] = array(); |
|
| 679 | + foreach ($results as &$result_ref) { |
|
| 680 | + $result_ref['attr_acodes'] = array(); |
|
| 681 | + } |
|
| 658 | 682 | |
| 659 | 683 | # Load internal_attr_id => acode mapping. |
| 660 | 684 | |
@@ -666,12 +690,10 @@ discard block |
||
| 666 | 690 | from caches_attributes |
| 667 | 691 | where cache_id in ('".implode("','", array_map('\okapi\Db::escape_string', array_keys($cacheid2wptcode)))."') |
| 668 | 692 | "); |
| 669 | - while ($row = Db::fetch_assoc($rs)) |
|
| 670 | - { |
|
| 693 | + while ($row = Db::fetch_assoc($rs)) { |
|
| 671 | 694 | $cache_code = $cacheid2wptcode[$row['cache_id']]; |
| 672 | 695 | $attr_internal_id = $row['attrib_id']; |
| 673 | - if (!isset($internal2acode[$attr_internal_id])) |
|
| 674 | - { |
|
| 696 | + if (!isset($internal2acode[$attr_internal_id])) { |
|
| 675 | 697 | # Unknown attribute. Ignore. |
| 676 | 698 | continue; |
| 677 | 699 | } |
@@ -681,24 +703,23 @@ discard block |
||
| 681 | 703 | # Now, each cache object has a list of its acodes. We can get |
| 682 | 704 | # the attrnames now. |
| 683 | 705 | |
| 684 | - if (in_array('attrnames', $fields)) |
|
| 685 | - { |
|
| 706 | + if (in_array('attrnames', $fields)) { |
|
| 686 | 707 | $acode2bestname = AttrHelper::get_acode_to_name_mapping($langpref); |
| 687 | - foreach ($results as &$result_ref) |
|
| 688 | - { |
|
| 708 | + foreach ($results as &$result_ref) { |
|
| 689 | 709 | $result_ref['attrnames'] = array(); |
| 690 | - foreach ($result_ref['attr_acodes'] as $acode) |
|
| 691 | - $result_ref['attrnames'][] = $acode2bestname[$acode]; |
|
| 710 | + foreach ($result_ref['attr_acodes'] as $acode) { |
|
| 711 | + $result_ref['attrnames'][] = $acode2bestname[$acode]; |
|
| 712 | + } |
|
| 692 | 713 | } |
| 693 | 714 | } |
| 694 | 715 | } |
| 695 | 716 | |
| 696 | 717 | # Latest log entries. |
| 697 | 718 | |
| 698 | - if (in_array('latest_logs', $fields)) |
|
| 699 | - { |
|
| 700 | - foreach ($results as &$result_ref) |
|
| 701 | - $result_ref['latest_logs'] = array(); |
|
| 719 | + if (in_array('latest_logs', $fields)) { |
|
| 720 | + foreach ($results as &$result_ref) { |
|
| 721 | + $result_ref['latest_logs'] = array(); |
|
| 722 | + } |
|
| 702 | 723 | |
| 703 | 724 | # Get all log IDs in proper order, then filter out the latest |
| 704 | 725 | # ones. This should be the fastest technique ... |
@@ -728,26 +749,21 @@ discard block |
||
| 728 | 749 | |
| 729 | 750 | $loguuids = array(); |
| 730 | 751 | $log2cache_map = array(); |
| 731 | - if ($lpc !== null) |
|
| 732 | - { |
|
| 752 | + if ($lpc !== null) { |
|
| 733 | 753 | # User wants some of the latest logs. |
| 734 | 754 | $tmp = array(); |
| 735 | - while ($row = Db::fetch_assoc($rs)) |
|
| 736 | - $tmp[$row['cache_id']][] = $row; |
|
| 737 | - foreach ($tmp as $cache_key => &$rowslist_ref) |
|
| 738 | - { |
|
| 739 | - for ($i = 0; $i < min(count($rowslist_ref), $lpc); $i++) |
|
| 740 | - { |
|
| 755 | + while ($row = Db::fetch_assoc($rs)) { |
|
| 756 | + $tmp[$row['cache_id']][] = $row; |
|
| 757 | + } |
|
| 758 | + foreach ($tmp as $cache_key => &$rowslist_ref) { |
|
| 759 | + for ($i = 0; $i < min(count($rowslist_ref), $lpc); $i++) { |
|
| 741 | 760 | $loguuids[] = $rowslist_ref[$i]['uuid']; |
| 742 | 761 | $log2cache_map[$rowslist_ref[$i]['uuid']] = $cacheid2wptcode[$rowslist_ref[$i]['cache_id']]; |
| 743 | 762 | } |
| 744 | 763 | } |
| 745 | - } |
|
| 746 | - else |
|
| 747 | - { |
|
| 764 | + } else { |
|
| 748 | 765 | # User wants ALL logs. |
| 749 | - while ($row = Db::fetch_assoc($rs)) |
|
| 750 | - { |
|
| 766 | + while ($row = Db::fetch_assoc($rs)) { |
|
| 751 | 767 | $loguuids[] = $row['uuid']; |
| 752 | 768 | $log2cache_map[$row['uuid']] = $cacheid2wptcode[$row['cache_id']]; |
| 753 | 769 | } |
@@ -758,10 +774,8 @@ discard block |
||
| 758 | 774 | # We need to retrieve logs/entry for each of the $logids. We do this in groups |
| 759 | 775 | # (there is a limit for log uuids passed to logs/entries method). |
| 760 | 776 | |
| 761 | - try |
|
| 762 | - { |
|
| 763 | - foreach (Okapi::make_groups($loguuids, 500) as $subset) |
|
| 764 | - { |
|
| 777 | + try { |
|
| 778 | + foreach (Okapi::make_groups($loguuids, 500) as $subset) { |
|
| 765 | 779 | $entries = OkapiServiceRunner::call( |
| 766 | 780 | "services/logs/entries", |
| 767 | 781 | new OkapiInternalRequest( |
@@ -771,21 +785,16 @@ discard block |
||
| 771 | 785 | ) |
| 772 | 786 | ) |
| 773 | 787 | ); |
| 774 | - foreach ($subset as $log_uuid) |
|
| 775 | - { |
|
| 776 | - if ($entries[$log_uuid]) |
|
| 777 | - $results[$log2cache_map[$log_uuid]]['latest_logs'][] = $entries[$log_uuid]; |
|
| 788 | + foreach ($subset as $log_uuid) { |
|
| 789 | + if ($entries[$log_uuid]) { |
|
| 790 | + $results[$log2cache_map[$log_uuid]]['latest_logs'][] = $entries[$log_uuid]; |
|
| 791 | + } |
|
| 778 | 792 | } |
| 779 | 793 | } |
| 780 | - } |
|
| 781 | - catch (Exception $e) |
|
| 782 | - { |
|
| 783 | - if (($e instanceof InvalidParam) && ($e->paramName == 'fields')) |
|
| 784 | - { |
|
| 794 | + } catch (Exception $e) { |
|
| 795 | + if (($e instanceof InvalidParam) && ($e->paramName == 'fields')) { |
|
| 785 | 796 | throw new InvalidParam('log_fields', $e->whats_wrong_about_it); |
| 786 | - } |
|
| 787 | - else |
|
| 788 | - { |
|
| 797 | + } else { |
|
| 789 | 798 | /* Something is wrong with OUR code. */ |
| 790 | 799 | throw new Exception($e); |
| 791 | 800 | } |
@@ -794,14 +803,14 @@ discard block |
||
| 794 | 803 | |
| 795 | 804 | # My notes |
| 796 | 805 | |
| 797 | - if (in_array('my_notes', $fields)) |
|
| 798 | - { |
|
| 799 | - if ($request->token == null) |
|
| 800 | - throw new BadRequest("Level 3 Authentication is required to access 'my_notes' field."); |
|
| 801 | - foreach ($results as &$result_ref) |
|
| 802 | - $result_ref['my_notes'] = null; |
|
| 803 | - if (Settings::get('OC_BRANCH') == 'oc.pl') |
|
| 804 | - { |
|
| 806 | + if (in_array('my_notes', $fields)) { |
|
| 807 | + if ($request->token == null) { |
|
| 808 | + throw new BadRequest("Level 3 Authentication is required to access 'my_notes' field."); |
|
| 809 | + } |
|
| 810 | + foreach ($results as &$result_ref) { |
|
| 811 | + $result_ref['my_notes'] = null; |
|
| 812 | + } |
|
| 813 | + if (Settings::get('OC_BRANCH') == 'oc.pl') { |
|
| 805 | 814 | # OCPL uses cache_notes table to store notes. |
| 806 | 815 | |
| 807 | 816 | $rs = Db::query(" |
@@ -812,9 +821,7 @@ discard block |
||
| 812 | 821 | and user_id = '".Db::escape_string($request->token->user_id)."' |
| 813 | 822 | group by cache_id |
| 814 | 823 | "); |
| 815 | - } |
|
| 816 | - else |
|
| 817 | - { |
|
| 824 | + } else { |
|
| 818 | 825 | # OCDE uses coordinates table (with type == 2) to store notes (this is somewhat weird). |
| 819 | 826 | |
| 820 | 827 | $rs = Db::query(" |
@@ -827,15 +834,13 @@ discard block |
||
| 827 | 834 | group by cache_id |
| 828 | 835 | "); |
| 829 | 836 | } |
| 830 | - while ($row = Db::fetch_assoc($rs)) |
|
| 831 | - { |
|
| 837 | + while ($row = Db::fetch_assoc($rs)) { |
|
| 832 | 838 | # This one is plain-text. We may add my_notes_html for those who want it in HTML. |
| 833 | 839 | $results[$cacheid2wptcode[$row['cache_id']]]['my_notes'] = strip_tags($row['desc']); |
| 834 | 840 | } |
| 835 | 841 | } |
| 836 | 842 | |
| 837 | - if (in_array('trackables', $fields)) |
|
| 838 | - { |
|
| 843 | + if (in_array('trackables', $fields)) { |
|
| 839 | 844 | # Currently we support Geokrety only. But this interface should remain |
| 840 | 845 | # compatible. In future, other trackables might be returned the same way. |
| 841 | 846 | |
@@ -852,15 +857,15 @@ discard block |
||
| 852 | 857 | and gkiw.wp in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes))."') |
| 853 | 858 | "); |
| 854 | 859 | $trs = array(); |
| 855 | - while ($row = Db::fetch_assoc($rs)) |
|
| 856 | - $trs[$row['cache_code']][] = $row; |
|
| 857 | - foreach ($results as $cache_code => &$result_ref) |
|
| 858 | - { |
|
| 860 | + while ($row = Db::fetch_assoc($rs)) { |
|
| 861 | + $trs[$row['cache_code']][] = $row; |
|
| 862 | + } |
|
| 863 | + foreach ($results as $cache_code => &$result_ref) { |
|
| 859 | 864 | $result_ref['trackables'] = array(); |
| 860 | - if (!isset($trs[$cache_code])) |
|
| 861 | - continue; |
|
| 862 | - foreach ($trs[$cache_code] as $t) |
|
| 863 | - { |
|
| 865 | + if (!isset($trs[$cache_code])) { |
|
| 866 | + continue; |
|
| 867 | + } |
|
| 868 | + foreach ($trs[$cache_code] as $t) { |
|
| 864 | 869 | $result_ref['trackables'][] = array( |
| 865 | 870 | 'code' => 'GK'.str_pad(strtoupper(dechex($t['gk_id'])), 4, "0", STR_PAD_LEFT), |
| 866 | 871 | 'name' => $t['name'], |
@@ -870,16 +875,13 @@ discard block |
||
| 870 | 875 | } |
| 871 | 876 | unset($trs); |
| 872 | 877 | } |
| 873 | - if (in_array('trackables_count', $fields)) |
|
| 874 | - { |
|
| 875 | - if (in_array('trackables', $fields)) |
|
| 876 | - { |
|
| 878 | + if (in_array('trackables_count', $fields)) { |
|
| 879 | + if (in_array('trackables', $fields)) { |
|
| 877 | 880 | # We already got all trackables data, no need to query database again. |
| 878 | - foreach ($results as $cache_code => &$result_ref) |
|
| 879 | - $result_ref['trackables_count'] = count($result_ref['trackables']); |
|
| 880 | - } |
|
| 881 | - else |
|
| 882 | - { |
|
| 881 | + foreach ($results as $cache_code => &$result_ref) { |
|
| 882 | + $result_ref['trackables_count'] = count($result_ref['trackables']); |
|
| 883 | + } |
|
| 884 | + } else { |
|
| 883 | 885 | $rs = Db::query(" |
| 884 | 886 | select wp as cache_code, count(*) as count |
| 885 | 887 | from gk_item_waypoint |
@@ -887,14 +889,15 @@ discard block |
||
| 887 | 889 | group by wp |
| 888 | 890 | "); |
| 889 | 891 | $tr_counts = new ArrayObject(); |
| 890 | - while ($row = Db::fetch_assoc($rs)) |
|
| 891 | - $tr_counts[$row['cache_code']] = $row['count']; |
|
| 892 | - foreach ($results as $cache_code => &$result_ref) |
|
| 893 | - { |
|
| 894 | - if (isset($tr_counts[$cache_code])) |
|
| 895 | - $result_ref['trackables_count'] = $tr_counts[$cache_code] + 0; |
|
| 896 | - else |
|
| 897 | - $result_ref['trackables_count'] = 0; |
|
| 892 | + while ($row = Db::fetch_assoc($rs)) { |
|
| 893 | + $tr_counts[$row['cache_code']] = $row['count']; |
|
| 894 | + } |
|
| 895 | + foreach ($results as $cache_code => &$result_ref) { |
|
| 896 | + if (isset($tr_counts[$cache_code])) { |
|
| 897 | + $result_ref['trackables_count'] = $tr_counts[$cache_code] + 0; |
|
| 898 | + } else { |
|
| 899 | + $result_ref['trackables_count'] = 0; |
|
| 900 | + } |
|
| 898 | 901 | } |
| 899 | 902 | unset($tr_counts); |
| 900 | 903 | } |
@@ -902,11 +905,9 @@ discard block |
||
| 902 | 905 | |
| 903 | 906 | # Alternate/Additional waypoints. |
| 904 | 907 | |
| 905 | - if (in_array('alt_wpts', $fields)) |
|
| 906 | - { |
|
| 908 | + if (in_array('alt_wpts', $fields)) { |
|
| 907 | 909 | $internal_wpt_type_id2names = array(); |
| 908 | - if (Settings::get('OC_BRANCH') == 'oc.de') |
|
| 909 | - { |
|
| 910 | + if (Settings::get('OC_BRANCH') == 'oc.de') { |
|
| 910 | 911 | $rs = Db::query(" |
| 911 | 912 | select |
| 912 | 913 | ct.id, |
@@ -916,30 +917,28 @@ discard block |
||
| 916 | 917 | coordinates_type ct |
| 917 | 918 | left join sys_trans_text stt on stt.trans_id = ct.trans_id |
| 918 | 919 | "); |
| 919 | - while ($row = Db::fetch_assoc($rs)) |
|
| 920 | - $internal_wpt_type_id2names[$row['id']][$row['language']] = $row['text']; |
|
| 920 | + while ($row = Db::fetch_assoc($rs)) { |
|
| 921 | + $internal_wpt_type_id2names[$row['id']][$row['language']] = $row['text']; |
|
| 922 | + } |
|
| 921 | 923 | Db::free_result($rs); |
| 922 | - } |
|
| 923 | - else |
|
| 924 | - { |
|
| 924 | + } else { |
|
| 925 | 925 | $rs = Db::query(" |
| 926 | 926 | select id, pl, en |
| 927 | 927 | from waypoint_type |
| 928 | 928 | where id > 0 |
| 929 | 929 | "); |
| 930 | - while ($row = Db::fetch_assoc($rs)) |
|
| 931 | - { |
|
| 930 | + while ($row = Db::fetch_assoc($rs)) { |
|
| 932 | 931 | $internal_wpt_type_id2names[$row['id']]['pl'] = $row['pl']; |
| 933 | 932 | $internal_wpt_type_id2names[$row['id']]['en'] = $row['en']; |
| 934 | 933 | } |
| 935 | 934 | } |
| 936 | 935 | |
| 937 | - foreach ($results as &$result_ref) |
|
| 938 | - $result_ref['alt_wpts'] = array(); |
|
| 936 | + foreach ($results as &$result_ref) { |
|
| 937 | + $result_ref['alt_wpts'] = array(); |
|
| 938 | + } |
|
| 939 | 939 | $cache_codes_escaped_and_imploded = "'".implode("','", array_map('\okapi\Db::escape_string', array_keys($cacheid2wptcode)))."'"; |
| 940 | 940 | |
| 941 | - if (Settings::get('OC_BRANCH') == 'oc.pl') |
|
| 942 | - { |
|
| 941 | + if (Settings::get('OC_BRANCH') == 'oc.pl') { |
|
| 943 | 942 | # OCPL uses 'waypoints' table to store additional waypoints and defines |
| 944 | 943 | # waypoint types in 'waypoint_type' table. |
| 945 | 944 | # OCPL also have a special 'status' field to denote a hidden waypoint |
@@ -970,9 +969,7 @@ discard block |
||
| 970 | 969 | and status = 1 |
| 971 | 970 | order by cache_id, stage, `desc` |
| 972 | 971 | "); |
| 973 | - } |
|
| 974 | - else |
|
| 975 | - { |
|
| 972 | + } else { |
|
| 976 | 973 | # OCDE uses 'coordinates' table (with type=1) to store additional waypoints |
| 977 | 974 | # and defines waypoint types in 'coordinates_type' table. |
| 978 | 975 | # All additional waypoints are public. |
@@ -1007,15 +1004,12 @@ discard block |
||
| 1007 | 1004 | "); |
| 1008 | 1005 | } |
| 1009 | 1006 | |
| 1010 | - foreach ($cacheid2waypoints as $cache_id => $waypoints) |
|
| 1011 | - { |
|
| 1007 | + foreach ($cacheid2waypoints as $cache_id => $waypoints) { |
|
| 1012 | 1008 | $cache_code = $cacheid2wptcode[$cache_id]; |
| 1013 | 1009 | $wpt_format = $cache_code."-%0".strlen(count($waypoints))."d"; |
| 1014 | 1010 | $index = 0; |
| 1015 | - foreach ($waypoints as $row) |
|
| 1016 | - { |
|
| 1017 | - if (!isset($internal_wpt_type_id2names[$row['internal_type_id']])) |
|
| 1018 | - { |
|
| 1011 | + foreach ($waypoints as $row) { |
|
| 1012 | + if (!isset($internal_wpt_type_id2names[$row['internal_type_id']])) { |
|
| 1019 | 1013 | # Sanity check. Waypoints of undefined type won't be accessible via OKAPI. |
| 1020 | 1014 | # See issue 219. |
| 1021 | 1015 | continue; |
@@ -1034,11 +1028,9 @@ discard block |
||
| 1034 | 1028 | |
| 1035 | 1029 | # Issue #298 - User coordinates implemented in oc.pl |
| 1036 | 1030 | # Issue #305 - User coordinates implemented in oc.de |
| 1037 | - if ($request->token != null) |
|
| 1038 | - { |
|
| 1031 | + if ($request->token != null) { |
|
| 1039 | 1032 | # Query DB for user provided coordinates |
| 1040 | - if (Settings::get('OC_BRANCH') == 'oc.pl') |
|
| 1041 | - { |
|
| 1033 | + if (Settings::get('OC_BRANCH') == 'oc.pl') { |
|
| 1042 | 1034 | $cacheid2user_coords = Db::select_group_by('cache_id', " |
| 1043 | 1035 | select |
| 1044 | 1036 | cache_id, longitude, latitude |
@@ -1061,11 +1053,9 @@ discard block |
||
| 1061 | 1053 | and latitude != 0 |
| 1062 | 1054 | "); |
| 1063 | 1055 | } |
| 1064 | - foreach ($cacheid2user_coords as $cache_id => $waypoints) |
|
| 1065 | - { |
|
| 1056 | + foreach ($cacheid2user_coords as $cache_id => $waypoints) { |
|
| 1066 | 1057 | $cache_code = $cacheid2wptcode[$cache_id]; |
| 1067 | - foreach ($waypoints as $row) |
|
| 1068 | - { |
|
| 1058 | + foreach ($waypoints as $row) { |
|
| 1069 | 1059 | # there should be only one user waypoint per cache... |
| 1070 | 1060 | $results[$cache_code]['alt_wpts'][] = array( |
| 1071 | 1061 | 'name' => $cache_code.'-USER-COORDS', |
@@ -1085,13 +1075,11 @@ discard block |
||
| 1085 | 1075 | |
| 1086 | 1076 | # Country and/or state. |
| 1087 | 1077 | |
| 1088 | - if (in_array('country', $fields) || in_array('state', $fields)) |
|
| 1089 | - { |
|
| 1078 | + if (in_array('country', $fields) || in_array('state', $fields)) { |
|
| 1090 | 1079 | $countries = array(); |
| 1091 | 1080 | $states = array(); |
| 1092 | 1081 | |
| 1093 | - if (Settings::get('OC_BRANCH') == 'oc.de') |
|
| 1094 | - { |
|
| 1082 | + if (Settings::get('OC_BRANCH') == 'oc.de') { |
|
| 1095 | 1083 | # OCDE: |
| 1096 | 1084 | # - cache_location entries are created by a cronjob *after* listing the |
| 1097 | 1085 | # caches and may not yet exist. |
@@ -1117,8 +1105,9 @@ discard block |
||
| 1117 | 1105 | c.wp_oc in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes))."') |
| 1118 | 1106 | "); |
| 1119 | 1107 | $country_codes2names = array(); |
| 1120 | - while ($row = Db::fetch_assoc($rs)) |
|
| 1121 | - $country_codes2names[$row['country']][$row['language']] = $row['text']; |
|
| 1108 | + while ($row = Db::fetch_assoc($rs)) { |
|
| 1109 | + $country_codes2names[$row['country']][$row['language']] = $row['text']; |
|
| 1110 | + } |
|
| 1122 | 1111 | Db::free_result($rs); |
| 1123 | 1112 | |
| 1124 | 1113 | # get geocache countries and states |
@@ -1133,18 +1122,16 @@ discard block |
||
| 1133 | 1122 | where |
| 1134 | 1123 | c.wp_oc in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes))."') |
| 1135 | 1124 | "); |
| 1136 | - while ($row = Db::fetch_assoc($rs)) |
|
| 1137 | - { |
|
| 1138 | - if (!isset($country_codes2names[$row['country_code']])) |
|
| 1139 | - $countries[$row['cache_code']] = ''; |
|
| 1140 | - else |
|
| 1141 | - $countries[$row['cache_code']] = Okapi::pick_best_language($country_codes2names[$row['country_code']], $langpref); |
|
| 1125 | + while ($row = Db::fetch_assoc($rs)) { |
|
| 1126 | + if (!isset($country_codes2names[$row['country_code']])) { |
|
| 1127 | + $countries[$row['cache_code']] = ''; |
|
| 1128 | + } else { |
|
| 1129 | + $countries[$row['cache_code']] = Okapi::pick_best_language($country_codes2names[$row['country_code']], $langpref); |
|
| 1130 | + } |
|
| 1142 | 1131 | $states[$row['cache_code']] = $row['state']; |
| 1143 | 1132 | } |
| 1144 | 1133 | Db::free_result($rs); |
| 1145 | - } |
|
| 1146 | - else |
|
| 1147 | - { |
|
| 1134 | + } else { |
|
| 1148 | 1135 | # OCPL: |
| 1149 | 1136 | # - cache_location data is entered by the user. |
| 1150 | 1137 | # - The state is in adm3 field. |
@@ -1162,23 +1149,22 @@ discard block |
||
| 1162 | 1149 | c.wp_oc in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes))."') |
| 1163 | 1150 | and c.cache_id = cl.cache_id |
| 1164 | 1151 | "); |
| 1165 | - while ($row = Db::fetch_assoc($rs)) |
|
| 1166 | - { |
|
| 1152 | + while ($row = Db::fetch_assoc($rs)) { |
|
| 1167 | 1153 | $countries[$row['cache_code']] = $row['country']; |
| 1168 | 1154 | $states[$row['cache_code']] = $row['state']; |
| 1169 | 1155 | } |
| 1170 | 1156 | Db::free_result($rs); |
| 1171 | 1157 | } |
| 1172 | 1158 | |
| 1173 | - if (in_array('country', $fields)) |
|
| 1174 | - { |
|
| 1175 | - foreach ($results as $cache_code => &$row_ref) |
|
| 1176 | - $row_ref['country'] = isset($countries[$cache_code]) ? $countries[$cache_code] : null; |
|
| 1159 | + if (in_array('country', $fields)) { |
|
| 1160 | + foreach ($results as $cache_code => &$row_ref) { |
|
| 1161 | + $row_ref['country'] = isset($countries[$cache_code]) ? $countries[$cache_code] : null; |
|
| 1162 | + } |
|
| 1177 | 1163 | } |
| 1178 | - if (in_array('state', $fields)) |
|
| 1179 | - { |
|
| 1180 | - foreach ($results as $cache_code => &$row_ref) |
|
| 1181 | - $row_ref['state'] = isset($states[$cache_code]) ? $states[$cache_code] : null; |
|
| 1164 | + if (in_array('state', $fields)) { |
|
| 1165 | + foreach ($results as $cache_code => &$row_ref) { |
|
| 1166 | + $row_ref['state'] = isset($states[$cache_code]) ? $states[$cache_code] : null; |
|
| 1167 | + } |
|
| 1182 | 1168 | } |
| 1183 | 1169 | unset($countries); |
| 1184 | 1170 | unset($states); |
@@ -1186,27 +1172,25 @@ discard block |
||
| 1186 | 1172 | |
| 1187 | 1173 | # Attribution note |
| 1188 | 1174 | |
| 1189 | - if (in_array('attribution_note', $fields)) |
|
| 1190 | - { |
|
| 1175 | + if (in_array('attribution_note', $fields)) { |
|
| 1191 | 1176 | /* Note, that the "owner" and "internal_id" fields are automatically included, |
| 1192 | 1177 | * whenever the attribution_note is included. */ |
| 1193 | 1178 | |
| 1194 | - foreach ($results as $cache_code => &$result_ref) |
|
| 1195 | - $result_ref['attribution_note'] = |
|
| 1179 | + foreach ($results as $cache_code => &$result_ref) { |
|
| 1180 | + $result_ref['attribution_note'] = |
|
| 1196 | 1181 | self::get_cache_attribution_note( |
| 1197 | 1182 | $result_ref['internal_id'], $langpref[0], $langpref, |
| 1198 | 1183 | $results[$cache_code]['owner'], 'full' |
| 1199 | 1184 | ); |
| 1185 | + } |
|
| 1200 | 1186 | } |
| 1201 | 1187 | |
| 1202 | 1188 | # Protection areas |
| 1203 | 1189 | |
| 1204 | - if (in_array('protection_areas', $fields)) |
|
| 1205 | - { |
|
| 1190 | + if (in_array('protection_areas', $fields)) { |
|
| 1206 | 1191 | $cache_ids_escaped_and_imploded = "'".implode("','", array_map('\okapi\Db::escape_string', array_keys($cacheid2wptcode)))."'"; |
| 1207 | 1192 | |
| 1208 | - if (Settings::get('OC_BRANCH') == 'oc.de') |
|
| 1209 | - { |
|
| 1193 | + if (Settings::get('OC_BRANCH') == 'oc.de') { |
|
| 1210 | 1194 | $rs = Db::query(" |
| 1211 | 1195 | select |
| 1212 | 1196 | c.wp_oc as cache_code, |
@@ -1222,9 +1206,7 @@ discard block |
||
| 1222 | 1206 | group by npa_areas.type_id, npa_areas.name |
| 1223 | 1207 | order by npa_types.ordinal |
| 1224 | 1208 | "); |
| 1225 | - } |
|
| 1226 | - else if (in_array(Okapi::get_oc_schema_code(), array("OCPL", "OCNL"))) |
|
| 1227 | - { |
|
| 1209 | + } else if (in_array(Okapi::get_oc_schema_code(), array("OCPL", "OCNL"))) { |
|
| 1228 | 1210 | # Current OCPL table definitions use collation 'latin1' for parkipl |
| 1229 | 1211 | # and 'utf8' for np_areas. Union needs identical collations. |
| 1230 | 1212 | # To be sure, we convert both to utf8. |
@@ -1255,21 +1237,18 @@ discard block |
||
| 1255 | 1237 | c.cache_id in (".$cache_ids_escaped_and_imploded.") |
| 1256 | 1238 | and cache_npa_areas.npa_id != 0 |
| 1257 | 1239 | "); |
| 1258 | - } |
|
| 1259 | - else |
|
| 1260 | - { |
|
| 1240 | + } else { |
|
| 1261 | 1241 | # OC.US and .UK do not have a 'parkipl' table. |
| 1262 | 1242 | # OC.US has a 'us_parks' table instead. |
| 1263 | 1243 | # Natura 2000 is Europe-only. |
| 1264 | 1244 | $rs = null; |
| 1265 | 1245 | } |
| 1266 | 1246 | |
| 1267 | - foreach ($results as &$result_ref) |
|
| 1268 | - $result_ref['protection_areas'] = array(); |
|
| 1269 | - if ($rs) |
|
| 1270 | - { |
|
| 1271 | - while ($row = Db::fetch_assoc($rs)) |
|
| 1272 | - { |
|
| 1247 | + foreach ($results as &$result_ref) { |
|
| 1248 | + $result_ref['protection_areas'] = array(); |
|
| 1249 | + } |
|
| 1250 | + if ($rs) { |
|
| 1251 | + while ($row = Db::fetch_assoc($rs)) { |
|
| 1273 | 1252 | $results[$row['cache_code']]['protection_areas'][] = array( |
| 1274 | 1253 | 'type' => $row['type'], |
| 1275 | 1254 | 'name' => $row['name'], |
@@ -1280,18 +1259,19 @@ discard block |
||
| 1280 | 1259 | } |
| 1281 | 1260 | |
| 1282 | 1261 | # Check which cache codes were not found and mark them with null. |
| 1283 | - foreach ($cache_codes as $cache_code) |
|
| 1284 | - if (!isset($results[$cache_code])) |
|
| 1262 | + foreach ($cache_codes as $cache_code) { |
|
| 1263 | + if (!isset($results[$cache_code])) |
|
| 1285 | 1264 | $results[$cache_code] = null; |
| 1265 | + } |
|
| 1286 | 1266 | |
| 1287 | - if (count($fields_to_remove_later) > 0) |
|
| 1288 | - { |
|
| 1267 | + if (count($fields_to_remove_later) > 0) { |
|
| 1289 | 1268 | # Some of the fields in $results were added only temporarily |
| 1290 | 1269 | # (the Consumer did not ask for them). We will remove these fields now. |
| 1291 | 1270 | |
| 1292 | - foreach ($results as &$result_ref) |
|
| 1293 | - foreach ($fields_to_remove_later as $field) |
|
| 1271 | + foreach ($results as &$result_ref) { |
|
| 1272 | + foreach ($fields_to_remove_later as $field) |
|
| 1294 | 1273 | unset($result_ref[$field]); |
| 1274 | + } |
|
| 1295 | 1275 | } |
| 1296 | 1276 | |
| 1297 | 1277 | # Order the results in the same order as the input codes were given. |
@@ -1301,8 +1281,9 @@ discard block |
||
| 1301 | 1281 | # so we just have to rewrite it (sequentially). |
| 1302 | 1282 | |
| 1303 | 1283 | $ordered_results = new ArrayObject(); |
| 1304 | - foreach ($cache_codes as $cache_code) |
|
| 1305 | - $ordered_results[$cache_code] = $results[$cache_code]; |
|
| 1284 | + foreach ($cache_codes as $cache_code) { |
|
| 1285 | + $ordered_results[$cache_code] = $results[$cache_code]; |
|
| 1286 | + } |
|
| 1306 | 1287 | |
| 1307 | 1288 | /* Handle OCPL's "access logs" feature. */ |
| 1308 | 1289 | |
@@ -1407,21 +1388,17 @@ discard block |
||
| 1407 | 1388 | $cache_url = $site_url."viewcache.php?cacheid=$cache_id"; |
| 1408 | 1389 | |
| 1409 | 1390 | Okapi::gettext_domain_init(array_merge(array($lang), $langpref)); |
| 1410 | - if (Settings::get('OC_BRANCH') == 'oc.pl') |
|
| 1411 | - { |
|
| 1391 | + if (Settings::get('OC_BRANCH') == 'oc.pl') { |
|
| 1412 | 1392 | # This does not vary on $type (yet). |
| 1413 | 1393 | |
| 1414 | 1394 | $note = sprintf( |
| 1415 | 1395 | _("This <a href='%s'>geocache</a> description comes from the <a href='%s'>%s</a> site."), |
| 1416 | 1396 | $cache_url, $site_url, $site_name |
| 1417 | 1397 | ); |
| 1418 | - } |
|
| 1419 | - else |
|
| 1420 | - { |
|
| 1398 | + } else { |
|
| 1421 | 1399 | # OC.de wants the tld in lowercase here |
| 1422 | 1400 | $site_name = ucfirst(strtolower($site_name)); |
| 1423 | - if ($type == 'full') |
|
| 1424 | - { |
|
| 1401 | + if ($type == 'full') { |
|
| 1425 | 1402 | $note = sprintf( |
| 1426 | 1403 | _( |
| 1427 | 1404 | "© <a href='%s'>%s</a>, <a href='%s'>%s</a>, ". |
@@ -1430,9 +1407,7 @@ discard block |
||
| 1430 | 1407 | ), |
| 1431 | 1408 | $owner['profile_url'], $owner['username'], $cache_url, $site_name, strftime('%x') |
| 1432 | 1409 | ); |
| 1433 | - } |
|
| 1434 | - elseif ($type == 'static') |
|
| 1435 | - { |
|
| 1410 | + } elseif ($type == 'static') { |
|
| 1436 | 1411 | $note = sprintf( |
| 1437 | 1412 | _( |
| 1438 | 1413 | "© <a href='%s'>%s</a>, <a href='%s'>%s</a>, ". |