@@ -18,7 +18,7 @@ |
||
18 | 18 | |
19 | 19 | // database names |
20 | 20 | $dbname = 'opencaching'; |
21 | -$tmpdbname = 'octmp'; // empty db with CREATE and DROP privileges |
|
21 | +$tmpdbname = 'octmp'; // empty db with CREATE and DROP privileges |
|
22 | 22 | |
23 | 23 | // common developer system settings |
24 | 24 | require 'settings-dev.inc.php'; |
@@ -1,6 +1,6 @@ |
||
1 | 1 | #!/usr/bin/php -q |
2 | 2 | <?php |
3 | - /*************************************************************************** |
|
3 | + /*************************************************************************** |
|
4 | 4 | * For license information see doc/license.txt |
5 | 5 | * |
6 | 6 | * Unicode Reminder メモ |
@@ -8,8 +8,8 @@ discard block |
||
8 | 8 | * Load current stored procs and triggers into database. |
9 | 9 | ***************************************************************************/ |
10 | 10 | |
11 | -$opt['rootpath'] = __DIR__ . '/../../../'; |
|
12 | -require $opt['rootpath'] . 'lib2/cli.inc.php'; |
|
11 | +$opt['rootpath'] = __DIR__.'/../../../'; |
|
12 | +require $opt['rootpath'].'lib2/cli.inc.php'; |
|
13 | 13 | |
14 | 14 | if ($opt['db']['maintenance_user'] == '') { |
15 | 15 | die("ERROR: \$opt['db']['maintenance_user'] is not set in config2/settings.inc.php\n"); |
@@ -18,10 +18,10 @@ discard block |
||
18 | 18 | // retrieve DB password |
19 | 19 | if ($opt['db']['maintenance_password'] == '') { |
20 | 20 | if (in_array('--flush', $argv)) { |
21 | - echo "\nenter DB " . $opt['db']['maintenance_user'] . " password:\n"; |
|
21 | + echo "\nenter DB ".$opt['db']['maintenance_user']." password:\n"; |
|
22 | 22 | flush(); |
23 | 23 | } else { |
24 | - echo 'enter DB ' . $opt['db']['maintenance_user'] . ' password: '; |
|
24 | + echo 'enter DB '.$opt['db']['maintenance_user'].' password: '; |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | $fh = fopen('php://stdin', 'r'); |
@@ -44,13 +44,13 @@ discard block |
||
44 | 44 | // include the requested maintain version file |
45 | 45 | $dbsv = in_array('--dbsv', $argv); |
46 | 46 | if ($dbsv) { |
47 | - $versionfile = 'maintain-' . $argv[$dbsv + 1] . '.inc.php'; |
|
48 | - if (!file_exists(__DIR__ . '/' . $versionfile)) { |
|
49 | - die($versionfile . " not found\n"); |
|
47 | + $versionfile = 'maintain-'.$argv[$dbsv + 1].'.inc.php'; |
|
48 | + if (!file_exists(__DIR__.'/'.$versionfile)) { |
|
49 | + die($versionfile." not found\n"); |
|
50 | 50 | } else { |
51 | 51 | require $versionfile; |
52 | 52 | } |
53 | - @unlink($opt['rootpath'] . 'cache2/dbsv-running'); |
|
53 | + @unlink($opt['rootpath'].'cache2/dbsv-running'); |
|
54 | 54 | } else { |
55 | 55 | require 'maintain-current.inc.php'; |
56 | 56 | } |
@@ -88,8 +88,9 @@ |
||
88 | 88 | $tpl->assign('coordW3W2', $coord->getW3W($w3w_langs[1])); |
89 | 89 | $lang2_name = sql_value("SELECT `name` FROM `languages` WHERE `short`='&1'", '', $w3w_langs[1]); |
90 | 90 | $tpl->assign('W3Wlang2', $translate->t($lang2_name, '', '', 0)); |
91 | -} else |
|
91 | +} else { |
|
92 | 92 | $tpl->assign('coordW3W2', false); |
93 | +} |
|
93 | 94 | |
94 | 95 | // wp gesetzt? |
95 | 96 | $wp = isset($_REQUEST['wp']) ? $_REQUEST['wp'] : ''; |
@@ -5,7 +5,7 @@ |
||
5 | 5 | * Unicode Reminder メモ |
6 | 6 | ***************************************************************************/ |
7 | 7 | |
8 | -require __DIR__ . '/lib2/web.inc.php'; |
|
8 | +require __DIR__.'/lib2/web.inc.php'; |
|
9 | 9 | |
10 | 10 | $tpl->name = 'coordinates'; |
11 | 11 | $tpl->popup = true; |
@@ -19,6 +19,9 @@ discard block |
||
19 | 19 | return $this->userCountry; |
20 | 20 | } |
21 | 21 | |
22 | + /** |
|
23 | + * @param string $userCountry |
|
24 | + */ |
|
22 | 25 | public function set_userCountry($userCountry) |
23 | 26 | { |
24 | 27 | $this->userCountry = $userCountry; |
@@ -98,7 +101,7 @@ discard block |
||
98 | 101 | * |
99 | 102 | * @param array $args numeric array containing the parameter for "sql_slave" |
100 | 103 | * |
101 | - * @return object mysql result used by smarty assign_rs |
|
104 | + * @return resource mysql result used by smarty assign_rs |
|
102 | 105 | */ |
103 | 106 | private function cacheRs($args = null) |
104 | 107 | { |
@@ -150,7 +153,7 @@ discard block |
||
150 | 153 | * |
151 | 154 | * @param array $args numeric array containing the parameter for "sql_slave" |
152 | 155 | * |
153 | - * @return object mysql result used by smarty assign_rs |
|
156 | + * @return resource mysql result used by smarty assign_rs |
|
154 | 157 | */ |
155 | 158 | private function eventRs($args = null) |
156 | 159 | { |
@@ -221,7 +224,7 @@ discard block |
||
221 | 224 | * |
222 | 225 | * @param array $args numeric array containing the parameter for "sql_slave" |
223 | 226 | * |
224 | - * @return object mysql result used by smarty assign_rs |
|
227 | + * @return resource mysql result used by smarty assign_rs |
|
225 | 228 | */ |
226 | 229 | private function ratingRs($args = null) |
227 | 230 | { |
@@ -51,11 +51,11 @@ discard block |
||
51 | 51 | public function rsForSmarty($type, $args = null) |
52 | 52 | { |
53 | 53 | // check type |
54 | - if (method_exists($this, strtolower($type) . 'Rs')) { |
|
54 | + if (method_exists($this, strtolower($type).'Rs')) { |
|
55 | 55 | return call_user_func( |
56 | 56 | [ |
57 | 57 | $this, |
58 | - $type . 'Rs' |
|
58 | + $type.'Rs' |
|
59 | 59 | ], |
60 | 60 | $args |
61 | 61 | ); |
@@ -78,11 +78,11 @@ discard block |
||
78 | 78 | public function feedForSmarty($type, $items = null, $url = null, $timeout = null, $includetext = null) |
79 | 79 | { |
80 | 80 | // check type |
81 | - if (method_exists($this, strtolower($type) . 'Feed')) { |
|
81 | + if (method_exists($this, strtolower($type).'Feed')) { |
|
82 | 82 | return call_user_func( |
83 | 83 | [ |
84 | 84 | $this, |
85 | - $type . 'Feed' |
|
85 | + $type.'Feed' |
|
86 | 86 | ], |
87 | 87 | $items, |
88 | 88 | $url, |
@@ -203,6 +203,9 @@ |
||
203 | 203 | return $str; |
204 | 204 | } |
205 | 205 | |
206 | +/** |
|
207 | + * @param string $str |
|
208 | + */ |
|
206 | 209 | function lf2crlf($str) |
207 | 210 | { |
208 | 211 | return str_replace("\r\r\n", "\r\n", str_replace("\n", "\r\n", $str)); |
@@ -116,10 +116,10 @@ discard block |
||
116 | 116 | |
117 | 117 | if ($r['html'] == 0) { |
118 | 118 | $thisline = mb_ereg_replace('{htmlwarn}', '', $thisline); |
119 | - $thisline = mb_ereg_replace('{desc}', decodeEntities(strip_tags($r['desc'])) . $license, $thisline); |
|
119 | + $thisline = mb_ereg_replace('{desc}', decodeEntities(strip_tags($r['desc'])).$license, $thisline); |
|
120 | 120 | } else { |
121 | 121 | $thisline = mb_ereg_replace('{htmlwarn}', " ($converted_from_html)", $thisline); |
122 | - $thisline = mb_ereg_replace('{desc}', html2txt($r['desc']) . $license, $thisline); |
|
122 | + $thisline = mb_ereg_replace('{desc}', html2txt($r['desc']).$license, $thisline); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | $thisline = mb_ereg_replace('{type}', $r['type'], $thisline); |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | $thislog = mb_ereg_replace('{text}', html2txt($rLog['text']), $thislog); |
198 | 198 | } |
199 | 199 | |
200 | - $logentries .= $thislog . "\n"; |
|
200 | + $logentries .= $thislog."\n"; |
|
201 | 201 | } |
202 | 202 | $thisline = mb_ereg_replace('{logs}', $logentries, $thisline); |
203 | 203 | |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | if (!$bUseZip) { |
206 | 206 | echo $thisline; |
207 | 207 | } else { |
208 | - $phpzip->add_data($r['waypoint'] . '.txt', $thisline); |
|
208 | + $phpzip->add_data($r['waypoint'].'.txt', $thisline); |
|
209 | 209 | } |
210 | 210 | } |
211 | 211 | mysql_free_result($rs); |
@@ -3,19 +3,14 @@ |
||
3 | 3 | namespace okapi\services\caches\formatters\garmin; |
4 | 4 | |
5 | 5 | |
6 | -use okapi\Okapi; |
|
7 | 6 | use okapi\Cache; |
8 | -use okapi\Settings; |
|
9 | -use okapi\OkapiRequest; |
|
10 | -use okapi\OkapiHttpResponse; |
|
7 | +use okapi\InvalidParam; |
|
11 | 8 | use okapi\OkapiInternalRequest; |
9 | +use okapi\OkapiRequest; |
|
12 | 10 | use okapi\OkapiServiceRunner; |
13 | 11 | use okapi\OkapiZIPHttpResponse; |
14 | -use okapi\BadRequest; |
|
15 | 12 | use okapi\ParamMissing; |
16 | -use okapi\InvalidParam; |
|
17 | -use okapi\OkapiAccessToken; |
|
18 | -use okapi\services\caches\search\SearchAssistant; |
|
13 | +use okapi\Settings; |
|
19 | 14 | |
20 | 15 | use \Exception; |
21 | 16 | use \clsTbsZip; |
@@ -60,14 +60,14 @@ discard block |
||
60 | 60 | # also include image references (actual images will be added as separate files later) |
61 | 61 | # and personal data (if the method was invoked using Level 3 Authentication). |
62 | 62 | |
63 | - switch($format) { |
|
63 | + switch ($format) { |
|
64 | 64 | case 'gpx' : |
65 | - $data_filename = "Garmin/GPX/opencaching".time().rand(100000,999999).".gpx"; |
|
65 | + $data_filename = "Garmin/GPX/opencaching".time().rand(100000, 999999).".gpx"; |
|
66 | 66 | $data_method = 'services/caches/formatters/gpx'; |
67 | 67 | $data_use_compression = true; |
68 | 68 | break; |
69 | 69 | case 'ggz' : |
70 | - $data_filename = "Garmin/GGZ/opencaching".time().rand(100000,999999).".ggz"; |
|
70 | + $data_filename = "Garmin/GGZ/opencaching".time().rand(100000, 999999).".ggz"; |
|
71 | 71 | $data_method = 'services/caches/formatters/ggz'; |
72 | 72 | $data_use_compression = false; |
73 | 73 | break; |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | } |
127 | 127 | } |
128 | 128 | if (!$tmp) |
129 | - continue; # unsupported file extension |
|
129 | + continue; # unsupported file extension |
|
130 | 130 | |
131 | 131 | if ($img['is_spoiler']) { |
132 | 132 | $zippath = $dir."/Spoilers/".$img['unique_caption'].".jpg"; |
@@ -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 | } |
@@ -2,21 +2,11 @@ |
||
2 | 2 | |
3 | 3 | namespace okapi\services\caches\map; |
4 | 4 | |
5 | -use Exception; |
|
6 | -use okapi\Okapi; |
|
7 | -use okapi\Settings; |
|
8 | -use okapi\Cache; |
|
9 | 5 | use okapi\Db; |
10 | -use okapi\OkapiRequest; |
|
11 | -use okapi\OkapiHttpResponse; |
|
12 | -use okapi\ParamMissing; |
|
13 | 6 | use okapi\InvalidParam; |
14 | -use okapi\BadRequest; |
|
15 | -use okapi\DoesNotExist; |
|
16 | -use okapi\OkapiInternalRequest; |
|
17 | 7 | use okapi\OkapiInternalConsumer; |
8 | +use okapi\OkapiInternalRequest; |
|
18 | 9 | use okapi\OkapiServiceRunner; |
19 | - |
|
20 | 10 | use okapi\services\caches\map\TileTree; |
21 | 11 | |
22 | 12 | require_once 'tiletree.inc.php'; |
@@ -145,8 +145,8 @@ discard block |
||
145 | 145 | |
146 | 146 | $z21x = $row[1]; |
147 | 147 | $z21y = $row[2]; |
148 | - $ex = $z21x >> 8; # initially, z21x / <tile width> |
|
149 | - $ey = $z21y >> 8; # initially, z21y / <tile height> |
|
148 | + $ex = $z21x >> 8; # initially, z21x / <tile width> |
|
149 | + $ey = $z21y >> 8; # initially, z21y / <tile height> |
|
150 | 150 | for ($zoom = 21; $zoom >= 0; $zoom--, $ex >>= 1, $ey >>= 1) |
151 | 151 | { |
152 | 152 | # ($ex, $ey) points to the "exact match" tile. We need to determine |
@@ -154,9 +154,9 @@ discard block |
||
154 | 154 | # go with the simple approach and check all 1+8 bordering tiles. |
155 | 155 | |
156 | 156 | $tiles_in_this_region = array(); |
157 | - for ($x=$ex-1; $x<=$ex+1; $x++) |
|
158 | - for ($y=$ey-1; $y<=$ey+1; $y++) |
|
159 | - if (($x >= 0) && ($x < 1<<$zoom) && ($y >= 0) && ($y < 1<<$zoom)) |
|
157 | + for ($x = $ex - 1; $x <= $ex + 1; $x++) |
|
158 | + for ($y = $ey - 1; $y <= $ey + 1; $y++) |
|
159 | + if (($x >= 0) && ($x < 1 << $zoom) && ($y >= 0) && ($y < 1 << $zoom)) |
|
160 | 160 | $tiles_in_this_region[] = array($x, $y); |
161 | 161 | |
162 | 162 | foreach ($tiles_in_this_region as $coords) |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | list($x, $y) = $coords; |
165 | 165 | |
166 | 166 | $scale = 8 + 21 - $zoom; |
167 | - $margin = 1 << ($scale - 3); # 32px of current $zoom level, measured in z21 pixels. |
|
167 | + $margin = 1 << ($scale - 3); # 32px of current $zoom level, measured in z21 pixels. |
|
168 | 168 | |
169 | 169 | $left_z21x = ($x << $scale) - $margin; |
170 | 170 | $right_z21x = (($x + 1) << $scale) + $margin; |
@@ -29,14 +29,13 @@ discard block |
||
29 | 29 | # changelog. The format of $changelog is described in the replicate module |
30 | 30 | # (NOT the entire response, just the "changelog" key). |
31 | 31 | |
32 | - foreach ($changelog as $c) |
|
33 | - { |
|
34 | - if ($c['object_type'] == 'geocache') |
|
35 | - { |
|
36 | - if ($c['change_type'] == 'replace') |
|
37 | - self::handle_geocache_replace($c); |
|
38 | - else |
|
39 | - self::handle_geocache_delete($c); |
|
32 | + foreach ($changelog as $c) { |
|
33 | + if ($c['object_type'] == 'geocache') { |
|
34 | + if ($c['change_type'] == 'replace') { |
|
35 | + self::handle_geocache_replace($c); |
|
36 | + } else { |
|
37 | + self::handle_geocache_delete($c); |
|
38 | + } |
|
40 | 39 | } |
41 | 40 | } |
42 | 41 | } |
@@ -90,25 +89,21 @@ discard block |
||
90 | 89 | # Compute the new row for okapi_tile_caches. Compare with the old one. |
91 | 90 | |
92 | 91 | $theirs = TileTree::generate_short_row($cache); |
93 | - if (!$ours) |
|
94 | - { |
|
92 | + if (!$ours) { |
|
95 | 93 | # Aaah, a new geocache! How nice... ;) |
96 | 94 | |
97 | 95 | self::add_geocache_to_cached_tiles($theirs); |
98 | - } |
|
99 | - elseif (($ours[1] != $theirs[1]) || ($ours[2] != $theirs[2])) # z21x & z21y fields |
|
96 | + } elseif (($ours[1] != $theirs[1]) || ($ours[2] != $theirs[2])) { |
|
97 | + # z21x & z21y fields |
|
100 | 98 | { |
101 | 99 | # Location changed. |
102 | 100 | |
103 | 101 | self::remove_geocache_from_cached_tiles($ours[0]); |
104 | - self::add_geocache_to_cached_tiles($theirs); |
|
105 | 102 | } |
106 | - elseif ($ours != $theirs) |
|
107 | - { |
|
103 | + self::add_geocache_to_cached_tiles($theirs); |
|
104 | + } elseif ($ours != $theirs) { |
|
108 | 105 | self::update_geocache_attributes_in_cached_tiles($theirs); |
109 | - } |
|
110 | - else |
|
111 | - { |
|
106 | + } else { |
|
112 | 107 | # No need to update anything. This is very common (i.e. when the |
113 | 108 | # cache was simply found, not actually changed). Replicate module generates |
114 | 109 | # many updates which do not influence our cache. |
@@ -147,20 +142,21 @@ discard block |
||
147 | 142 | $z21y = $row[2]; |
148 | 143 | $ex = $z21x >> 8; # initially, z21x / <tile width> |
149 | 144 | $ey = $z21y >> 8; # initially, z21y / <tile height> |
150 | - for ($zoom = 21; $zoom >= 0; $zoom--, $ex >>= 1, $ey >>= 1) |
|
151 | - { |
|
145 | + for ($zoom = 21; $zoom >= 0; $zoom--, $ex >>= 1, $ey >>= 1) { |
|
152 | 146 | # ($ex, $ey) points to the "exact match" tile. We need to determine |
153 | 147 | # tile-range to check for "just outside the border" tiles. We will |
154 | 148 | # go with the simple approach and check all 1+8 bordering tiles. |
155 | 149 | |
156 | 150 | $tiles_in_this_region = array(); |
157 | - for ($x=$ex-1; $x<=$ex+1; $x++) |
|
158 | - for ($y=$ey-1; $y<=$ey+1; $y++) |
|
159 | - if (($x >= 0) && ($x < 1<<$zoom) && ($y >= 0) && ($y < 1<<$zoom)) |
|
151 | + for ($x=$ex-1; $x<=$ex+1; $x++) { |
|
152 | + for ($y=$ey-1; |
|
153 | + } |
|
154 | + $y<=$ey+1; $y++) { |
|
155 | + if (($x >= 0) && ($x < 1<<$zoom) && ($y >= 0) && ($y < 1<<$zoom)) |
|
160 | 156 | $tiles_in_this_region[] = array($x, $y); |
157 | + } |
|
161 | 158 | |
162 | - foreach ($tiles_in_this_region as $coords) |
|
163 | - { |
|
159 | + foreach ($tiles_in_this_region as $coords) { |
|
164 | 160 | list($x, $y) = $coords; |
165 | 161 | |
166 | 162 | $scale = 8 + 21 - $zoom; |
@@ -171,14 +167,18 @@ discard block |
||
171 | 167 | $top_z21y = ($y << $scale) - $margin; |
172 | 168 | $bottom_z21y = (($y + 1) << $scale) + $margin; |
173 | 169 | |
174 | - if ($z21x < $left_z21x) |
|
175 | - continue; |
|
176 | - if ($z21x > $right_z21x) |
|
177 | - continue; |
|
178 | - if ($z21y < $top_z21y) |
|
179 | - continue; |
|
180 | - if ($z21y > $bottom_z21y) |
|
181 | - continue; |
|
170 | + if ($z21x < $left_z21x) { |
|
171 | + continue; |
|
172 | + } |
|
173 | + if ($z21x > $right_z21x) { |
|
174 | + continue; |
|
175 | + } |
|
176 | + if ($z21y < $top_z21y) { |
|
177 | + continue; |
|
178 | + } |
|
179 | + if ($z21y > $bottom_z21y) { |
|
180 | + continue; |
|
181 | + } |
|
182 | 182 | |
183 | 183 | # We found a match. Store it for later. |
184 | 184 | |
@@ -191,8 +191,7 @@ discard block |
||
191 | 191 | # only the cached ones. |
192 | 192 | |
193 | 193 | $alternatives_escaped = array(); |
194 | - foreach ($tiles_to_update as $coords) |
|
195 | - { |
|
194 | + foreach ($tiles_to_update as $coords) { |
|
196 | 195 | list($z, $x, $y) = $coords; |
197 | 196 | $alternatives_escaped[] = "( |
198 | 197 | z = '".Db::escape_string($z)."' |
@@ -200,8 +199,7 @@ discard block |
||
200 | 199 | and y = '".Db::escape_string($y)."' |
201 | 200 | )"; |
202 | 201 | } |
203 | - if (count($alternatives_escaped) > 0) |
|
204 | - { |
|
202 | + if (count($alternatives_escaped) > 0) { |
|
205 | 203 | Db::execute(" |
206 | 204 | replace into okapi_tile_caches ( |
207 | 205 | z, x, y, cache_id, z21x, z21y, status, type, rating, flags, name_crc |
@@ -2,15 +2,15 @@ |
||
2 | 2 | |
3 | 3 | namespace okapi\services\caches\search; |
4 | 4 | |
5 | -use okapi\Okapi; |
|
5 | +use Exception; |
|
6 | +use okapi\BadRequest; |
|
6 | 7 | use okapi\Db; |
8 | +use okapi\InvalidParam; |
|
9 | +use okapi\Okapi; |
|
7 | 10 | use okapi\OkapiInternalRequest; |
8 | -use okapi\OkapiServiceRunner; |
|
9 | 11 | use okapi\OkapiRequest; |
10 | -use okapi\InvalidParam; |
|
11 | -use okapi\BadRequest; |
|
12 | +use okapi\OkapiServiceRunner; |
|
12 | 13 | use okapi\Settings; |
13 | -use Exception; |
|
14 | 14 | |
15 | 15 | class SearchAssistant |
16 | 16 | { |
@@ -682,7 +682,7 @@ |
||
682 | 682 | # To avoid join errors, put each of the $where_conds in extra paranthesis. |
683 | 683 | |
684 | 684 | $tmp = array(); |
685 | - foreach($where_conds as $cond) |
|
685 | + foreach ($where_conds as $cond) |
|
686 | 686 | $tmp[] = "(".$cond.")"; |
687 | 687 | $where_conds = $tmp; |
688 | 688 | unset($tmp); |
@@ -95,8 +95,7 @@ discard block |
||
95 | 95 | # At the beginning we have to set up some "magic e$Xpressions". |
96 | 96 | # We will use them to make our query run on both OCPL and OCDE databases. |
97 | 97 | |
98 | - if (Settings::get('OC_BRANCH') == 'oc.pl') |
|
99 | - { |
|
98 | + if (Settings::get('OC_BRANCH') == 'oc.pl') { |
|
100 | 99 | # OCPL's 'caches' table contains some fields which OCDE's does not |
101 | 100 | # (topratings, founds, notfounds, last_found, votes, score). If |
102 | 101 | # we're being run on OCPL installation, we will simply use them. |
@@ -107,9 +106,7 @@ discard block |
||
107 | 106 | $X_LAST_FOUND = 'caches.last_found'; |
108 | 107 | $X_VOTES = 'caches.votes'; |
109 | 108 | $X_SCORE = 'caches.score'; |
110 | - } |
|
111 | - else |
|
112 | - { |
|
109 | + } else { |
|
113 | 110 | # OCDE holds this data in a separate table. Additionally, OCDE |
114 | 111 | # does not provide a rating system (votes and score fields). |
115 | 112 | # If we're being run on OCDE database, we will include this |
@@ -131,55 +128,44 @@ discard block |
||
131 | 128 | # type |
132 | 129 | # |
133 | 130 | |
134 | - if ($tmp = $this->request->get_parameter('type')) |
|
135 | - { |
|
131 | + if ($tmp = $this->request->get_parameter('type')) { |
|
136 | 132 | $operator = "in"; |
137 | - if ($tmp[0] == '-') |
|
138 | - { |
|
133 | + if ($tmp[0] == '-') { |
|
139 | 134 | $tmp = substr($tmp, 1); |
140 | 135 | $operator = "not in"; |
141 | 136 | } |
142 | 137 | $types = array(); |
143 | - foreach (explode("|", $tmp) as $name) |
|
144 | - { |
|
145 | - try |
|
146 | - { |
|
138 | + foreach (explode("|", $tmp) as $name) { |
|
139 | + try { |
|
147 | 140 | $id = Okapi::cache_type_name2id($name); |
148 | 141 | $types[] = $id; |
149 | - } |
|
150 | - catch (Exception $e) |
|
151 | - { |
|
142 | + } catch (Exception $e) { |
|
152 | 143 | throw new InvalidParam('type', "'$name' is not a valid cache type."); |
153 | 144 | } |
154 | 145 | } |
155 | - if (count($types) > 0) |
|
156 | - $where_conds[] = "caches.type $operator ('".implode("','", array_map('\okapi\Db::escape_string', $types))."')"; |
|
157 | - else if ($operator == "in") |
|
158 | - $where_conds[] = "false"; |
|
146 | + if (count($types) > 0) { |
|
147 | + $where_conds[] = "caches.type $operator ('".implode("','", array_map('\okapi\Db::escape_string', $types))."')"; |
|
148 | + } else if ($operator == "in") { |
|
149 | + $where_conds[] = "false"; |
|
150 | + } |
|
159 | 151 | } |
160 | 152 | |
161 | 153 | # |
162 | 154 | # size2 |
163 | 155 | # |
164 | 156 | |
165 | - if ($tmp = $this->request->get_parameter('size2')) |
|
166 | - { |
|
157 | + if ($tmp = $this->request->get_parameter('size2')) { |
|
167 | 158 | $operator = "in"; |
168 | - if ($tmp[0] == '-') |
|
169 | - { |
|
159 | + if ($tmp[0] == '-') { |
|
170 | 160 | $tmp = substr($tmp, 1); |
171 | 161 | $operator = "not in"; |
172 | 162 | } |
173 | 163 | $types = array(); |
174 | - foreach (explode("|", $tmp) as $name) |
|
175 | - { |
|
176 | - try |
|
177 | - { |
|
164 | + foreach (explode("|", $tmp) as $name) { |
|
165 | + try { |
|
178 | 166 | $id = Okapi::cache_size2_to_sizeid($name); |
179 | 167 | $types[] = $id; |
180 | - } |
|
181 | - catch (Exception $e) |
|
182 | - { |
|
168 | + } catch (Exception $e) { |
|
183 | 169 | throw new InvalidParam('size2', "'$name' is not a valid cache size."); |
184 | 170 | } |
185 | 171 | } |
@@ -191,16 +177,14 @@ discard block |
||
191 | 177 | # |
192 | 178 | |
193 | 179 | $tmp = $this->request->get_parameter('status'); |
194 | - if ($tmp == null) $tmp = "Available"; |
|
180 | + if ($tmp == null) { |
|
181 | + $tmp = "Available"; |
|
182 | + } |
|
195 | 183 | $codes = array(); |
196 | - foreach (explode("|", $tmp) as $name) |
|
197 | - { |
|
198 | - try |
|
199 | - { |
|
184 | + foreach (explode("|", $tmp) as $name) { |
|
185 | + try { |
|
200 | 186 | $codes[] = Okapi::cache_status_name2id($name); |
201 | - } |
|
202 | - catch (Exception $e) |
|
203 | - { |
|
187 | + } catch (Exception $e) { |
|
204 | 188 | throw new InvalidParam('status', "'$name' is not a valid cache status."); |
205 | 189 | } |
206 | 190 | } |
@@ -210,26 +194,23 @@ discard block |
||
210 | 194 | # owner_uuid |
211 | 195 | # |
212 | 196 | |
213 | - if ($tmp = $this->request->get_parameter('owner_uuid')) |
|
214 | - { |
|
197 | + if ($tmp = $this->request->get_parameter('owner_uuid')) { |
|
215 | 198 | $operator = "in"; |
216 | - if ($tmp[0] == '-') |
|
217 | - { |
|
199 | + if ($tmp[0] == '-') { |
|
218 | 200 | $tmp = substr($tmp, 1); |
219 | 201 | $operator = "not in"; |
220 | 202 | } |
221 | - try |
|
222 | - { |
|
203 | + try { |
|
223 | 204 | $users = OkapiServiceRunner::call("services/users/users", new OkapiInternalRequest( |
224 | 205 | $this->request->consumer, null, array('user_uuids' => $tmp, 'fields' => 'internal_id'))); |
225 | - } |
|
226 | - catch (InvalidParam $e) # invalid uuid |
|
206 | + } catch (InvalidParam $e) # invalid uuid |
|
227 | 207 | { |
228 | 208 | throw new InvalidParam('owner_uuid', $e->whats_wrong_about_it); |
229 | 209 | } |
230 | 210 | $user_ids = array(); |
231 | - foreach ($users as $user) |
|
232 | - $user_ids[] = $user['internal_id']; |
|
211 | + foreach ($users as $user) { |
|
212 | + $user_ids[] = $user['internal_id']; |
|
213 | + } |
|
233 | 214 | $where_conds[] = "caches.user_id $operator ('".implode("','", array_map('\okapi\Db::escape_string', $user_ids))."')"; |
234 | 215 | } |
235 | 216 | |
@@ -237,27 +218,26 @@ discard block |
||
237 | 218 | # terrain, difficulty, size, rating - these are similar, we'll do them in a loop |
238 | 219 | # |
239 | 220 | |
240 | - foreach (array('terrain', 'difficulty', 'size', 'rating') as $param_name) |
|
241 | - { |
|
242 | - if ($tmp = $this->request->get_parameter($param_name)) |
|
243 | - { |
|
244 | - if (!preg_match("/^[1-5]-[1-5](\|X)?$/", $tmp)) |
|
245 | - throw new InvalidParam($param_name, "'$tmp'"); |
|
221 | + foreach (array('terrain', 'difficulty', 'size', 'rating') as $param_name) { |
|
222 | + if ($tmp = $this->request->get_parameter($param_name)) { |
|
223 | + if (!preg_match("/^[1-5]-[1-5](\|X)?$/", $tmp)) { |
|
224 | + throw new InvalidParam($param_name, "'$tmp'"); |
|
225 | + } |
|
246 | 226 | list($min, $max) = explode("-", $tmp); |
247 | - if (strpos($max, "|X") !== false) |
|
248 | - { |
|
227 | + if (strpos($max, "|X") !== false) { |
|
249 | 228 | $max = $max[0]; |
250 | 229 | $allow_null = true; |
251 | 230 | } else { |
252 | 231 | $allow_null = false; |
253 | 232 | } |
254 | - if ($min > $max) |
|
255 | - throw new InvalidParam($param_name, "'$tmp'"); |
|
256 | - switch ($param_name) |
|
257 | - { |
|
233 | + if ($min > $max) { |
|
234 | + throw new InvalidParam($param_name, "'$tmp'"); |
|
235 | + } |
|
236 | + switch ($param_name) { |
|
258 | 237 | case 'terrain': |
259 | - if ($allow_null) |
|
260 | - throw new InvalidParam($param_name, "The '|X' suffix is not allowed here."); |
|
238 | + if ($allow_null) { |
|
239 | + throw new InvalidParam($param_name, "The '|X' suffix is not allowed here."); |
|
240 | + } |
|
261 | 241 | if (($min == 1) && ($max == 5)) { |
262 | 242 | /* no extra condition necessary */ |
263 | 243 | } else { |
@@ -265,8 +245,9 @@ discard block |
||
265 | 245 | } |
266 | 246 | break; |
267 | 247 | case 'difficulty': |
268 | - if ($allow_null) |
|
269 | - throw new InvalidParam($param_name, "The '|X' suffix is not allowed here."); |
|
248 | + if ($allow_null) { |
|
249 | + throw new InvalidParam($param_name, "The '|X' suffix is not allowed here."); |
|
250 | + } |
|
270 | 251 | if (($min == 1) && ($max == 5)) { |
271 | 252 | /* no extra condition necessary */ |
272 | 253 | } else { |
@@ -288,8 +269,7 @@ discard block |
||
288 | 269 | } |
289 | 270 | break; |
290 | 271 | case 'rating': |
291 | - if (Settings::get('OC_BRANCH') == 'oc.pl') |
|
292 | - { |
|
272 | + if (Settings::get('OC_BRANCH') == 'oc.pl') { |
|
293 | 273 | if (($min == 1) && ($max == 5) && $allow_null) { |
294 | 274 | /* no extra condition necessary */ |
295 | 275 | } else { |
@@ -299,9 +279,7 @@ discard block |
||
299 | 279 | $where_conds[] = "($X_SCORE >= $min and $X_SCORE < $max and $X_VOTES >= 3)". |
300 | 280 | ($allow_null ? " or ($X_VOTES < 3)" : ""); |
301 | 281 | } |
302 | - } |
|
303 | - else |
|
304 | - { |
|
282 | + } else { |
|
305 | 283 | # OCDE does not support rating. We will ignore this parameter. |
306 | 284 | } |
307 | 285 | break; |
@@ -313,22 +291,23 @@ discard block |
||
313 | 291 | # min_rcmds |
314 | 292 | # |
315 | 293 | |
316 | - if ($tmp = $this->request->get_parameter('min_rcmds')) |
|
317 | - { |
|
318 | - if ($tmp[strlen($tmp) - 1] == '%') |
|
319 | - { |
|
294 | + if ($tmp = $this->request->get_parameter('min_rcmds')) { |
|
295 | + if ($tmp[strlen($tmp) - 1] == '%') { |
|
320 | 296 | $tmp = substr($tmp, 0, strlen($tmp) - 1); |
321 | - if (!is_numeric($tmp)) |
|
322 | - throw new InvalidParam('min_rcmds', "'$tmp'"); |
|
297 | + if (!is_numeric($tmp)) { |
|
298 | + throw new InvalidParam('min_rcmds', "'$tmp'"); |
|
299 | + } |
|
323 | 300 | $tmp = intval($tmp); |
324 | - if ($tmp > 100 || $tmp < 0) |
|
325 | - throw new InvalidParam('min_rcmds', "'$tmp'"); |
|
301 | + if ($tmp > 100 || $tmp < 0) { |
|
302 | + throw new InvalidParam('min_rcmds', "'$tmp'"); |
|
303 | + } |
|
326 | 304 | $tmp = floatval($tmp) / 100.0; |
327 | 305 | $where_conds[] = "$X_TOPRATINGS >= $X_FOUNDS * '".Db::escape_string($tmp)."'"; |
328 | 306 | $where_conds[] = "$X_FOUNDS > 0"; |
329 | 307 | } |
330 | - if (!is_numeric($tmp)) |
|
331 | - throw new InvalidParam('min_rcmds', "'$tmp'"); |
|
308 | + if (!is_numeric($tmp)) { |
|
309 | + throw new InvalidParam('min_rcmds', "'$tmp'"); |
|
310 | + } |
|
332 | 311 | $where_conds[] = "$X_TOPRATINGS >= '".Db::escape_string($tmp)."'"; |
333 | 312 | } |
334 | 313 | |
@@ -336,10 +315,10 @@ discard block |
||
336 | 315 | # min_founds |
337 | 316 | # |
338 | 317 | |
339 | - if ($tmp = $this->request->get_parameter('min_founds')) |
|
340 | - { |
|
341 | - if (!is_numeric($tmp)) |
|
342 | - throw new InvalidParam('min_founds', "'$tmp'"); |
|
318 | + if ($tmp = $this->request->get_parameter('min_founds')) { |
|
319 | + if (!is_numeric($tmp)) { |
|
320 | + throw new InvalidParam('min_founds', "'$tmp'"); |
|
321 | + } |
|
343 | 322 | $where_conds[] = "$X_FOUNDS >= '".Db::escape_string($tmp)."'"; |
344 | 323 | } |
345 | 324 | |
@@ -348,10 +327,10 @@ discard block |
||
348 | 327 | # may be '0' for FTF hunts |
349 | 328 | # |
350 | 329 | |
351 | - if (!is_null($tmp = $this->request->get_parameter('max_founds'))) |
|
352 | - { |
|
353 | - if (!is_numeric($tmp)) |
|
354 | - throw new InvalidParam('max_founds', "'$tmp'"); |
|
330 | + if (!is_null($tmp = $this->request->get_parameter('max_founds'))) { |
|
331 | + if (!is_numeric($tmp)) { |
|
332 | + throw new InvalidParam('max_founds', "'$tmp'"); |
|
333 | + } |
|
355 | 334 | $where_conds[] = "$X_FOUNDS <= '".Db::escape_string($tmp)."'"; |
356 | 335 | } |
357 | 336 | |
@@ -359,27 +338,27 @@ discard block |
||
359 | 338 | # modified_since |
360 | 339 | # |
361 | 340 | |
362 | - if ($tmp = $this->request->get_parameter('modified_since')) |
|
363 | - { |
|
341 | + if ($tmp = $this->request->get_parameter('modified_since')) { |
|
364 | 342 | $timestamp = strtotime($tmp); |
365 | - if ($timestamp) |
|
366 | - $where_conds[] = "unix_timestamp(caches.last_modified) > '".Db::escape_string($timestamp)."'"; |
|
367 | - else |
|
368 | - throw new InvalidParam('modified_since', "'$tmp' is not in a valid format or is not a valid date."); |
|
343 | + if ($timestamp) { |
|
344 | + $where_conds[] = "unix_timestamp(caches.last_modified) > '".Db::escape_string($timestamp)."'"; |
|
345 | + } else { |
|
346 | + throw new InvalidParam('modified_since', "'$tmp' is not in a valid format or is not a valid date."); |
|
347 | + } |
|
369 | 348 | } |
370 | 349 | |
371 | 350 | # |
372 | 351 | # found_status |
373 | 352 | # |
374 | 353 | |
375 | - if ($tmp = $this->request->get_parameter('found_status')) |
|
376 | - { |
|
377 | - if ($this->request->token == null) |
|
378 | - throw new InvalidParam('found_status', "Might be used only for requests signed with an Access Token."); |
|
379 | - if (!in_array($tmp, array('found_only', 'notfound_only', 'either'))) |
|
380 | - throw new InvalidParam('found_status', "'$tmp'"); |
|
381 | - if ($tmp != 'either') |
|
382 | - { |
|
354 | + if ($tmp = $this->request->get_parameter('found_status')) { |
|
355 | + if ($this->request->token == null) { |
|
356 | + throw new InvalidParam('found_status', "Might be used only for requests signed with an Access Token."); |
|
357 | + } |
|
358 | + if (!in_array($tmp, array('found_only', 'notfound_only', 'either'))) { |
|
359 | + throw new InvalidParam('found_status', "'$tmp'"); |
|
360 | + } |
|
361 | + if ($tmp != 'either') { |
|
383 | 362 | $found_cache_ids = self::get_found_cache_ids(array($this->request->token->user_id)); |
384 | 363 | $operator = ($tmp == 'found_only') ? "in" : "not in"; |
385 | 364 | $where_conds[] = "caches.cache_id $operator ('".implode("','", array_map('\okapi\Db::escape_string', $found_cache_ids))."')"; |
@@ -390,12 +369,12 @@ discard block |
||
390 | 369 | # found_by |
391 | 370 | # |
392 | 371 | |
393 | - if ($tmp = $this->request->get_parameter('found_by')) |
|
394 | - { |
|
372 | + if ($tmp = $this->request->get_parameter('found_by')) { |
|
395 | 373 | try { |
396 | 374 | $users = OkapiServiceRunner::call("services/users/users", new OkapiInternalRequest( |
397 | 375 | $this->request->consumer, null, array('user_uuids' => $tmp, 'fields' => 'internal_id'))); |
398 | - } catch (InvalidParam $e) { # invalid uuid |
|
376 | + } catch (InvalidParam $e) { |
|
377 | +# invalid uuid |
|
399 | 378 | throw new InvalidParam('found_by', $e->whats_wrong_about_it); |
400 | 379 | } |
401 | 380 | $internal_user_ids = array_map(create_function('$user', 'return $user["internal_id"];'), $users); |
@@ -407,12 +386,12 @@ discard block |
||
407 | 386 | # not_found_by |
408 | 387 | # |
409 | 388 | |
410 | - if ($tmp = $this->request->get_parameter('not_found_by')) |
|
411 | - { |
|
389 | + if ($tmp = $this->request->get_parameter('not_found_by')) { |
|
412 | 390 | try { |
413 | 391 | $users = OkapiServiceRunner::call("services/users/users", new OkapiInternalRequest( |
414 | 392 | $this->request->consumer, null, array('user_uuids' => $tmp, 'fields' => 'internal_id'))); |
415 | - } catch (InvalidParam $e) { # invalid uuid |
|
393 | + } catch (InvalidParam $e) { |
|
394 | +# invalid uuid |
|
416 | 395 | throw new InvalidParam('not_found_by', $e->whats_wrong_about_it); |
417 | 396 | } |
418 | 397 | $internal_user_ids = array_map(create_function('$user', 'return $user["internal_id"];'), $users); |
@@ -424,21 +403,20 @@ discard block |
||
424 | 403 | # watched_only |
425 | 404 | # |
426 | 405 | |
427 | - if ($tmp = $this->request->get_parameter('watched_only')) |
|
428 | - { |
|
429 | - if ($this->request->token == null) |
|
430 | - throw new InvalidParam('watched_only', "Might be used only for requests signed with an Access Token."); |
|
431 | - if (!in_array($tmp, array('true', 'false'))) |
|
432 | - throw new InvalidParam('watched_only', "'$tmp'"); |
|
433 | - if ($tmp == 'true') |
|
434 | - { |
|
406 | + if ($tmp = $this->request->get_parameter('watched_only')) { |
|
407 | + if ($this->request->token == null) { |
|
408 | + throw new InvalidParam('watched_only', "Might be used only for requests signed with an Access Token."); |
|
409 | + } |
|
410 | + if (!in_array($tmp, array('true', 'false'))) { |
|
411 | + throw new InvalidParam('watched_only', "'$tmp'"); |
|
412 | + } |
|
413 | + if ($tmp == 'true') { |
|
435 | 414 | $watched_cache_ids = Db::select_column(" |
436 | 415 | select cache_id |
437 | 416 | from cache_watches |
438 | 417 | where user_id = '".Db::escape_string($this->request->token->user_id)."' |
439 | 418 | "); |
440 | - if (Settings::get('OC_BRANCH') == 'oc.de') |
|
441 | - { |
|
419 | + if (Settings::get('OC_BRANCH') == 'oc.de') { |
|
442 | 420 | $watched_cache_ids = array_merge($watched_cache_ids, Db::select_column(" |
443 | 421 | select cache_id |
444 | 422 | from cache_list_items cli, cache_list_watches clw |
@@ -455,33 +433,35 @@ discard block |
||
455 | 433 | # |
456 | 434 | |
457 | 435 | $ignored_status = 'either'; |
458 | - if ($tmp = $this->request->get_parameter('exclude_ignored')) |
|
459 | - { |
|
460 | - if ($this->request->token == null) |
|
461 | - throw new InvalidParam('exclude_ignored', "Might be used only for requests signed with an Access Token."); |
|
462 | - if ($tmp == 'true') |
|
463 | - $ignored_status = 'notignored_only'; |
|
464 | - elseif ($tmp != 'false') |
|
465 | - throw new InvalidParam('exclude_ignored', "'$tmp'"); |
|
466 | - } |
|
467 | - if ($tmp = $this->request->get_parameter('ignored_status')) |
|
468 | - { |
|
469 | - if ($this->request->token == null) |
|
470 | - throw new InvalidParam('ignored_status', "Might be used only for requests signed with an Access Token."); |
|
471 | - if (!in_array($tmp, array('ignored_only', 'notignored_only', 'either'))) |
|
472 | - throw new InvalidParam('ignored_status', "'$tmp'"); |
|
436 | + if ($tmp = $this->request->get_parameter('exclude_ignored')) { |
|
437 | + if ($this->request->token == null) { |
|
438 | + throw new InvalidParam('exclude_ignored', "Might be used only for requests signed with an Access Token."); |
|
439 | + } |
|
440 | + if ($tmp == 'true') { |
|
441 | + $ignored_status = 'notignored_only'; |
|
442 | + } elseif ($tmp != 'false') { |
|
443 | + throw new InvalidParam('exclude_ignored', "'$tmp'"); |
|
444 | + } |
|
445 | + } |
|
446 | + if ($tmp = $this->request->get_parameter('ignored_status')) { |
|
447 | + if ($this->request->token == null) { |
|
448 | + throw new InvalidParam('ignored_status', "Might be used only for requests signed with an Access Token."); |
|
449 | + } |
|
450 | + if (!in_array($tmp, array('ignored_only', 'notignored_only', 'either'))) { |
|
451 | + throw new InvalidParam('ignored_status', "'$tmp'"); |
|
452 | + } |
|
473 | 453 | if ($tmp != 'either') { |
474 | - if ($tmp == 'ignored_only' && $ignored_status == 'notignored_only') |
|
475 | - $ignored_status = 'none'; |
|
476 | - else |
|
477 | - $ignored_status = $tmp; |
|
454 | + if ($tmp == 'ignored_only' && $ignored_status == 'notignored_only') { |
|
455 | + $ignored_status = 'none'; |
|
456 | + } else { |
|
457 | + $ignored_status = $tmp; |
|
458 | + } |
|
478 | 459 | } |
479 | 460 | } |
480 | 461 | |
481 | - if ($ignored_status == 'none') |
|
482 | - $where_conds[] = 'false'; |
|
483 | - elseif ($ignored_status != 'either') |
|
484 | - { |
|
462 | + if ($ignored_status == 'none') { |
|
463 | + $where_conds[] = 'false'; |
|
464 | + } elseif ($ignored_status != 'either') { |
|
485 | 465 | $ignored_cache_ids = Db::select_column(" |
486 | 466 | select cache_id |
487 | 467 | from cache_ignore |
@@ -495,27 +475,29 @@ discard block |
||
495 | 475 | # exclude_my_own |
496 | 476 | # |
497 | 477 | |
498 | - if ($tmp = $this->request->get_parameter('exclude_my_own')) |
|
499 | - { |
|
500 | - if ($this->request->token == null) |
|
501 | - throw new InvalidParam('exclude_my_own', "Might be used only for requests signed with an Access Token."); |
|
502 | - if (!in_array($tmp, array('true', 'false'))) |
|
503 | - throw new InvalidParam('exclude_my_own', "'$tmp'"); |
|
504 | - if ($tmp == 'true') |
|
505 | - $where_conds[] = "caches.user_id != '".Db::escape_string($this->request->token->user_id)."'"; |
|
478 | + if ($tmp = $this->request->get_parameter('exclude_my_own')) { |
|
479 | + if ($this->request->token == null) { |
|
480 | + throw new InvalidParam('exclude_my_own', "Might be used only for requests signed with an Access Token."); |
|
481 | + } |
|
482 | + if (!in_array($tmp, array('true', 'false'))) { |
|
483 | + throw new InvalidParam('exclude_my_own', "'$tmp'"); |
|
484 | + } |
|
485 | + if ($tmp == 'true') { |
|
486 | + $where_conds[] = "caches.user_id != '".Db::escape_string($this->request->token->user_id)."'"; |
|
487 | + } |
|
506 | 488 | } |
507 | 489 | |
508 | 490 | # |
509 | 491 | # name |
510 | 492 | # |
511 | 493 | |
512 | - if ($tmp = $this->request->get_parameter('name')) |
|
513 | - { |
|
494 | + if ($tmp = $this->request->get_parameter('name')) { |
|
514 | 495 | # WRTODO: Make this more user-friendly. See: |
515 | 496 | # https://github.com/opencaching/okapi/issues/121 |
516 | 497 | |
517 | - if (strlen($tmp) > 100) |
|
518 | - throw new InvalidParam('name', "Maximum length of 'name' parameter is 100 characters"); |
|
498 | + if (strlen($tmp) > 100) { |
|
499 | + throw new InvalidParam('name', "Maximum length of 'name' parameter is 100 characters"); |
|
500 | + } |
|
519 | 501 | $tmp = str_replace("*", "%", str_replace("%", "%%", $tmp)); |
520 | 502 | $where_conds[] = "caches.name LIKE '".Db::escape_string($tmp)."'"; |
521 | 503 | } |
@@ -524,12 +506,11 @@ discard block |
||
524 | 506 | # with_trackables_only |
525 | 507 | # |
526 | 508 | |
527 | - if ($tmp = $this->request->get_parameter('with_trackables_only')) |
|
528 | - { |
|
529 | - if (!in_array($tmp, array('true', 'false'), 1)) |
|
530 | - throw new InvalidParam('with_trackables_only', "'$tmp'"); |
|
531 | - if ($tmp == 'true') |
|
532 | - { |
|
509 | + if ($tmp = $this->request->get_parameter('with_trackables_only')) { |
|
510 | + if (!in_array($tmp, array('true', 'false'), 1)) { |
|
511 | + throw new InvalidParam('with_trackables_only', "'$tmp'"); |
|
512 | + } |
|
513 | + if ($tmp == 'true') { |
|
533 | 514 | $where_conds[] = " |
534 | 515 | caches.wp_oc in ( |
535 | 516 | select distinct wp |
@@ -543,12 +524,11 @@ discard block |
||
543 | 524 | # ftf_hunter |
544 | 525 | # |
545 | 526 | |
546 | - if ($tmp = $this->request->get_parameter('ftf_hunter')) |
|
547 | - { |
|
548 | - if (!in_array($tmp, array('true', 'false'), 1)) |
|
549 | - throw new InvalidParam('ftf_hunter', "'$tmp'"); |
|
550 | - if ($tmp == 'true') |
|
551 | - { |
|
527 | + if ($tmp = $this->request->get_parameter('ftf_hunter')) { |
|
528 | + if (!in_array($tmp, array('true', 'false'), 1)) { |
|
529 | + throw new InvalidParam('ftf_hunter', "'$tmp'"); |
|
530 | + } |
|
531 | + if ($tmp == 'true') { |
|
552 | 532 | $where_conds[] = "$X_FOUNDS = 0"; |
553 | 533 | } |
554 | 534 | } |
@@ -558,8 +538,7 @@ discard block |
||
558 | 538 | # |
559 | 539 | |
560 | 540 | $join_powertrails = false; |
561 | - if ($tmp = $this->request->get_parameter('powertrail_only')) |
|
562 | - { |
|
541 | + if ($tmp = $this->request->get_parameter('powertrail_only')) { |
|
563 | 542 | if ($tmp === 'true') { |
564 | 543 | $join_powertrails = true; |
565 | 544 | } elseif ($tmp === 'false') { |
@@ -594,8 +573,7 @@ discard block |
||
594 | 573 | # set_and |
595 | 574 | # |
596 | 575 | |
597 | - if ($tmp = $this->request->get_parameter('set_and')) |
|
598 | - { |
|
576 | + if ($tmp = $this->request->get_parameter('set_and')) { |
|
599 | 577 | # Check if the set exists. |
600 | 578 | |
601 | 579 | $exists = Db::select_value(" |
@@ -603,8 +581,9 @@ discard block |
||
603 | 581 | from okapi_search_sets |
604 | 582 | where id = '".Db::escape_string($tmp)."' |
605 | 583 | "); |
606 | - if (!$exists) |
|
607 | - throw new InvalidParam('set_and', "Couldn't find a set by given ID."); |
|
584 | + if (!$exists) { |
|
585 | + throw new InvalidParam('set_and', "Couldn't find a set by given ID."); |
|
586 | + } |
|
608 | 587 | $extra_tables[] = "okapi_search_results osr_and"; |
609 | 588 | $where_conds[] = "osr_and.cache_id = caches.cache_id"; |
610 | 589 | $where_conds[] = "osr_and.set_id = '".Db::escape_string($tmp)."'"; |
@@ -615,34 +594,43 @@ discard block |
||
615 | 594 | # |
616 | 595 | |
617 | 596 | $limit = $this->request->get_parameter('limit'); |
618 | - if ($limit == null) $limit = "100"; |
|
619 | - if (!is_numeric($limit)) |
|
620 | - throw new InvalidParam('limit', "'$limit'"); |
|
621 | - if ($limit < 1 || (($limit > 500) && (!$this->request->skip_limits))) |
|
622 | - throw new InvalidParam( |
|
597 | + if ($limit == null) { |
|
598 | + $limit = "100"; |
|
599 | + } |
|
600 | + if (!is_numeric($limit)) { |
|
601 | + throw new InvalidParam('limit', "'$limit'"); |
|
602 | + } |
|
603 | + if ($limit < 1 || (($limit > 500) && (!$this->request->skip_limits))) { |
|
604 | + throw new InvalidParam( |
|
623 | 605 | 'limit', |
624 | 606 | $this->request->skip_limits |
625 | 607 | ? "Cannot be lower than 1." |
626 | 608 | : "Has to be between 1 and 500." |
627 | 609 | ); |
610 | + } |
|
628 | 611 | |
629 | 612 | # |
630 | 613 | # offset |
631 | 614 | # |
632 | 615 | |
633 | 616 | $offset = $this->request->get_parameter('offset'); |
634 | - if ($offset == null) $offset = "0"; |
|
635 | - if (!is_numeric($offset)) |
|
636 | - throw new InvalidParam('offset', "'$offset'"); |
|
637 | - if (($offset + $limit > 500) && (!$this->request->skip_limits)) |
|
638 | - throw new BadRequest("The sum of offset and limit may not exceed 500."); |
|
639 | - if ($offset < 0 || (($offset > 499) && (!$this->request->skip_limits))) |
|
640 | - throw new InvalidParam( |
|
617 | + if ($offset == null) { |
|
618 | + $offset = "0"; |
|
619 | + } |
|
620 | + if (!is_numeric($offset)) { |
|
621 | + throw new InvalidParam('offset', "'$offset'"); |
|
622 | + } |
|
623 | + if (($offset + $limit > 500) && (!$this->request->skip_limits)) { |
|
624 | + throw new BadRequest("The sum of offset and limit may not exceed 500."); |
|
625 | + } |
|
626 | + if ($offset < 0 || (($offset > 499) && (!$this->request->skip_limits))) { |
|
627 | + throw new InvalidParam( |
|
641 | 628 | 'offset', |
642 | 629 | $this->request->skip_limits |
643 | 630 | ? "Cannot be lower than 0." |
644 | 631 | : "Has to be between 0 and 499." |
645 | 632 | ); |
633 | + } |
|
646 | 634 | |
647 | 635 | # |
648 | 636 | # order_by |
@@ -650,21 +638,18 @@ discard block |
||
650 | 638 | |
651 | 639 | $order_clauses = array(); |
652 | 640 | $order_by = $this->request->get_parameter('order_by'); |
653 | - if ($order_by != null) |
|
654 | - { |
|
641 | + if ($order_by != null) { |
|
655 | 642 | $order_by = explode('|', $order_by); |
656 | - foreach ($order_by as $field) |
|
657 | - { |
|
643 | + foreach ($order_by as $field) { |
|
658 | 644 | $dir = 'asc'; |
659 | - if ($field[0] == '-') |
|
660 | - { |
|
645 | + if ($field[0] == '-') { |
|
661 | 646 | $dir = 'desc'; |
662 | 647 | $field = substr($field, 1); |
648 | + } elseif ($field[0] == '+') { |
|
649 | + $field = substr($field, 1); |
|
663 | 650 | } |
664 | - elseif ($field[0] == '+') |
|
665 | - $field = substr($field, 1); # ignore leading "+" |
|
666 | - switch ($field) |
|
667 | - { |
|
651 | + # ignore leading "+" |
|
652 | + switch ($field) { |
|
668 | 653 | case 'code': $cl = "caches.wp_oc"; break; |
669 | 654 | case 'name': $cl = "caches.name"; break; |
670 | 655 | case 'founds': $cl = "$X_FOUNDS"; break; |
@@ -682,8 +667,9 @@ discard block |
||
682 | 667 | # To avoid join errors, put each of the $where_conds in extra paranthesis. |
683 | 668 | |
684 | 669 | $tmp = array(); |
685 | - foreach($where_conds as $cond) |
|
686 | - $tmp[] = "(".$cond.")"; |
|
670 | + foreach($where_conds as $cond) { |
|
671 | + $tmp[] = "(".$cond.")"; |
|
672 | + } |
|
687 | 673 | $where_conds = $tmp; |
688 | 674 | unset($tmp); |
689 | 675 | |
@@ -697,8 +683,7 @@ discard block |
||
697 | 683 | 'extra_joins' => $extra_joins, |
698 | 684 | ); |
699 | 685 | |
700 | - if ($this->search_params === NULL) |
|
701 | - { |
|
686 | + if ($this->search_params === NULL) { |
|
702 | 687 | $this->search_params = $ret_array; |
703 | 688 | } else { |
704 | 689 | $this->search_params = array_merge_recursive($this->search_params, $ret_array); |
@@ -738,8 +723,7 @@ discard block |
||
738 | 723 | limit ".($this->search_params['offset']).", ".($this->search_params['limit'] + 1)."; |
739 | 724 | "); |
740 | 725 | |
741 | - if (count($cache_codes) > $this->search_params['limit']) |
|
742 | - { |
|
726 | + if (count($cache_codes) > $this->search_params['limit']) { |
|
743 | 727 | $more = true; |
744 | 728 | array_pop($cache_codes); # get rid of the one above the limit |
745 | 729 | } else { |
@@ -767,18 +751,17 @@ discard block |
||
767 | 751 | public function prepare_location_search_params() |
768 | 752 | { |
769 | 753 | $location_source = $this->request->get_parameter('location_source'); |
770 | - if (!$location_source) |
|
771 | - $location_source = 'default-coords'; |
|
754 | + if (!$location_source) { |
|
755 | + $location_source = 'default-coords'; |
|
756 | + } |
|
772 | 757 | |
773 | 758 | # Make sure location_source has prefix alt_wpt: |
774 | - if ($location_source != 'default-coords' && strncmp($location_source, 'alt_wpt:', 8) != 0) |
|
775 | - { |
|
759 | + if ($location_source != 'default-coords' && strncmp($location_source, 'alt_wpt:', 8) != 0) { |
|
776 | 760 | throw new InvalidParam('location_source', '\''.$location_source.'\''); |
777 | 761 | } |
778 | 762 | |
779 | 763 | # Make sure we have sufficient authorization |
780 | - if ($location_source == 'alt_wpt:user-coords' && $this->request->token == null) |
|
781 | - { |
|
764 | + if ($location_source == 'alt_wpt:user-coords' && $this->request->token == null) { |
|
782 | 765 | throw new BadRequest("Level 3 Authentication is required to access 'alt_wpt:user-coords'."); |
783 | 766 | } |
784 | 767 | |
@@ -787,14 +770,12 @@ discard block |
||
787 | 770 | $location_source = 'default-coords'; |
788 | 771 | } |
789 | 772 | |
790 | - if ($location_source == 'default-coords') |
|
791 | - { |
|
773 | + if ($location_source == 'default-coords') { |
|
792 | 774 | $this->longitude_expr = 'caches.longitude'; |
793 | 775 | $this->latitude_expr = 'caches.latitude'; |
794 | 776 | } else { |
795 | 777 | $extra_joins = null; |
796 | - if (Settings::get('OC_BRANCH') == 'oc.pl') |
|
797 | - { |
|
778 | + if (Settings::get('OC_BRANCH') == 'oc.pl') { |
|
798 | 779 | $this->longitude_expr = 'ifnull(cache_mod_cords.longitude, caches.longitude)'; |
799 | 780 | $this->latitude_expr = 'ifnull(cache_mod_cords.latitude, caches.latitude)'; |
800 | 781 | $extra_joins = array(" |
@@ -818,8 +799,7 @@ discard block |
||
818 | 799 | $location_extra_sql = array( |
819 | 800 | 'extra_joins' => $extra_joins |
820 | 801 | ); |
821 | - if ($this->search_params === NULL) |
|
822 | - { |
|
802 | + if ($this->search_params === NULL) { |
|
823 | 803 | $this->search_params = $location_extra_sql; |
824 | 804 | } else { |
825 | 805 | $this->search_params = array_merge_recursive($this->search_params, $location_extra_sql); |
@@ -26,10 +26,10 @@ discard block |
||
26 | 26 | public function __construct(OkapiRequest $request) |
27 | 27 | { |
28 | 28 | $this->request = $request; |
29 | - $this->longitude_expr = NULL; |
|
30 | - $this->latitude_expr = NULL; |
|
31 | - $this->location_extra_sql = NULL; |
|
32 | - $this->search_params = NULL; |
|
29 | + $this->longitude_expr = null; |
|
30 | + $this->latitude_expr = null; |
|
31 | + $this->location_extra_sql = null; |
|
32 | + $this->search_params = null; |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
@@ -697,7 +697,7 @@ discard block |
||
697 | 697 | 'extra_joins' => $extra_joins, |
698 | 698 | ); |
699 | 699 | |
700 | - if ($this->search_params === NULL) |
|
700 | + if ($this->search_params === null) |
|
701 | 701 | { |
702 | 702 | $this->search_params = $ret_array; |
703 | 703 | } else { |
@@ -818,7 +818,7 @@ discard block |
||
818 | 818 | $location_extra_sql = array( |
819 | 819 | 'extra_joins' => $extra_joins |
820 | 820 | ); |
821 | - if ($this->search_params === NULL) |
|
821 | + if ($this->search_params === null) |
|
822 | 822 | { |
823 | 823 | $this->search_params = $location_extra_sql; |
824 | 824 | } else { |
@@ -2,9 +2,8 @@ |
||
2 | 2 | |
3 | 3 | namespace okapi\services\logs\images\delete; |
4 | 4 | |
5 | -use Exception; |
|
6 | -use okapi\Okapi; |
|
7 | 5 | use okapi\Db; |
6 | +use okapi\Okapi; |
|
8 | 7 | use okapi\OkapiRequest; |
9 | 8 | use okapi\Settings; |
10 | 9 | use okapi\services\logs\images\LogImagesCommon; |
@@ -41,12 +41,9 @@ |
||
41 | 41 | # OCDE sequence numbers may have gaps. So we do not need to adjust |
42 | 42 | # any numbers after deleting from table 'pictures'. |
43 | 43 | |
44 | - if (Settings::get('OC_BRANCH') == 'oc.de') |
|
45 | - { |
|
44 | + if (Settings::get('OC_BRANCH') == 'oc.de') { |
|
46 | 45 | # OCDE does all the housekeeping by triggers |
47 | - } |
|
48 | - else |
|
49 | - { |
|
46 | + } else { |
|
50 | 47 | Db::execute(" |
51 | 48 | INSERT INTO removed_objects ( |
52 | 49 | localID, uuid, type, removed_date, node |