@@ -31,25 +31,32 @@ discard block |
||
31 | 31 | public static function call(OkapiRequest $request) |
32 | 32 | { |
33 | 33 | $log_uuids = $request->get_parameter('log_uuids'); |
34 | - if ($log_uuids === null) throw new ParamMissing('log_uuids'); |
|
34 | + if ($log_uuids === null) { |
|
35 | + throw new ParamMissing('log_uuids'); |
|
36 | + } |
|
35 | 37 | if ($log_uuids === "") |
36 | 38 | { |
37 | 39 | $log_uuids = array(); |
40 | + } else { |
|
41 | + $log_uuids = explode("|", $log_uuids); |
|
38 | 42 | } |
39 | - else |
|
40 | - $log_uuids = explode("|", $log_uuids); |
|
41 | 43 | |
42 | - if ((count($log_uuids) > 500) && (!$request->skip_limits)) |
|
43 | - throw new InvalidParam('log_uuids', "Maximum allowed number of referenced ". |
|
44 | + if ((count($log_uuids) > 500) && (!$request->skip_limits)) { |
|
45 | + throw new InvalidParam('log_uuids', "Maximum allowed number of referenced ". |
|
44 | 46 | "log entries is 500. You provided ".count($log_uuids)." UUIDs."); |
45 | - if (count($log_uuids) != count(array_unique($log_uuids))) |
|
46 | - throw new InvalidParam('log_uuids', "Duplicate UUIDs detected (make sure each UUID is referenced only once)."); |
|
47 | + } |
|
48 | + if (count($log_uuids) != count(array_unique($log_uuids))) { |
|
49 | + throw new InvalidParam('log_uuids', "Duplicate UUIDs detected (make sure each UUID is referenced only once)."); |
|
50 | + } |
|
47 | 51 | $fields = $request->get_parameter('fields'); |
48 | - if (!$fields) $fields = "date|user|type|comment"; |
|
52 | + if (!$fields) { |
|
53 | + $fields = "date|user|type|comment"; |
|
54 | + } |
|
49 | 55 | $fields = explode("|", $fields); |
50 | - foreach ($fields as $field) |
|
51 | - if (!in_array($field, self::$valid_field_names)) |
|
56 | + foreach ($fields as $field) { |
|
57 | + if (!in_array($field, self::$valid_field_names)) |
|
52 | 58 | throw new InvalidParam('fields', "'$field' is not a valid field code."); |
59 | + } |
|
53 | 60 | |
54 | 61 | if (Settings::get('OC_BRANCH') == 'oc.de') |
55 | 62 | { |
@@ -57,8 +64,7 @@ discard block |
||
57 | 64 | $ratingdate_condition = 'and cr.rating_date=cl.date'; |
58 | 65 | $needs_maintenance_SQL = 'cl.needs_maintenance'; |
59 | 66 | $listing_is_outdated_SQL = 'cl.listing_outdated'; |
60 | - } |
|
61 | - else |
|
67 | + } else |
|
62 | 68 | { |
63 | 69 | $teamentry_field = '(cl.type=12)'; |
64 | 70 | $ratingdate_condition = ''; |
@@ -158,22 +164,25 @@ discard block |
||
158 | 164 | |
159 | 165 | # Check which UUIDs were not found and mark them with null. |
160 | 166 | |
161 | - foreach ($log_uuids as $log_uuid) |
|
162 | - if (!isset($results[$log_uuid])) |
|
167 | + foreach ($log_uuids as $log_uuid) { |
|
168 | + if (!isset($results[$log_uuid])) |
|
163 | 169 | $results[$log_uuid] = null; |
170 | + } |
|
164 | 171 | |
165 | 172 | # Remove unwanted fields. |
166 | 173 | |
167 | - foreach (self::$valid_field_names as $field) |
|
168 | - if (!in_array($field, $fields)) |
|
174 | + foreach (self::$valid_field_names as $field) { |
|
175 | + if (!in_array($field, $fields)) |
|
169 | 176 | foreach ($results as &$result_ref) |
170 | 177 | unset($result_ref[$field]); |
178 | + } |
|
171 | 179 | |
172 | 180 | # Order the results in the same order as the input codes were given. |
173 | 181 | |
174 | 182 | $ordered_results = array(); |
175 | - foreach ($log_uuids as $log_uuid) |
|
176 | - $ordered_results[$log_uuid] = $results[$log_uuid]; |
|
183 | + foreach ($log_uuids as $log_uuid) { |
|
184 | + $ordered_results[$log_uuid] = $results[$log_uuid]; |
|
185 | + } |
|
177 | 186 | |
178 | 187 | return Okapi::formatted_response($request, $ordered_results); |
179 | 188 | } |
@@ -23,14 +23,18 @@ discard block |
||
23 | 23 | public static function call(OkapiRequest $request) |
24 | 24 | { |
25 | 25 | $internal_ids = $request->get_parameter('internal_ids'); |
26 | - if (!$internal_ids) throw new ParamMissing('internal_ids'); |
|
26 | + if (!$internal_ids) { |
|
27 | + throw new ParamMissing('internal_ids'); |
|
28 | + } |
|
27 | 29 | $internal_ids = explode("|", $internal_ids); |
28 | - if (count($internal_ids) > 500) |
|
29 | - throw new InvalidParam('internal_ids', "Maximum allowed number of referenced users ". |
|
30 | + if (count($internal_ids) > 500) { |
|
31 | + throw new InvalidParam('internal_ids', "Maximum allowed number of referenced users ". |
|
30 | 32 | "is 500. You provided ".count($internal_ids)." references."); |
33 | + } |
|
31 | 34 | $fields = $request->get_parameter('fields'); |
32 | - if (!$fields) |
|
33 | - throw new ParamMissing('fields'); |
|
35 | + if (!$fields) { |
|
36 | + throw new ParamMissing('fields'); |
|
37 | + } |
|
34 | 38 | |
35 | 39 | # There's no need to validate the fields parameter as the 'users' |
36 | 40 | # method does this (it will raise a proper exception on invalid values). |
@@ -57,10 +61,11 @@ discard block |
||
57 | 61 | $results = array(); |
58 | 62 | foreach ($internal_ids as $internal_id) |
59 | 63 | { |
60 | - if (!isset($internalid2useruuid[$internal_id])) |
|
61 | - $results[$internal_id] = null; |
|
62 | - else |
|
63 | - $results[$internal_id] = $id_results[$internalid2useruuid[$internal_id]]; |
|
64 | + if (!isset($internalid2useruuid[$internal_id])) { |
|
65 | + $results[$internal_id] = null; |
|
66 | + } else { |
|
67 | + $results[$internal_id] = $id_results[$internalid2useruuid[$internal_id]]; |
|
68 | + } |
|
64 | 69 | } |
65 | 70 | |
66 | 71 | return Okapi::formatted_response($request, $results); |
@@ -26,14 +26,17 @@ discard block |
||
26 | 26 | public static function call(OkapiRequest $request) |
27 | 27 | { |
28 | 28 | $username = $request->get_parameter('username'); |
29 | - if (!$username) throw new ParamMissing('username'); |
|
29 | + if (!$username) { |
|
30 | + throw new ParamMissing('username'); |
|
31 | + } |
|
30 | 32 | |
31 | 33 | # Fix for issue 339: |
32 | 34 | # Catch pipe chars here, because services/users/by_usernames would split up the name. |
33 | 35 | # OC databases do not contain user names with pipe chars. |
34 | 36 | |
35 | - if (strstr($username,'|')) |
|
36 | - throw new InvalidParam('username', "There is no user by this username."); |
|
37 | + if (strstr($username,'|')) { |
|
38 | + throw new InvalidParam('username', "There is no user by this username."); |
|
39 | + } |
|
37 | 40 | $fields = $request->get_parameter('fields'); |
38 | 41 | |
39 | 42 | # There's no need to validate the fields parameter. |
@@ -42,8 +45,9 @@ discard block |
||
42 | 45 | $request->consumer, $request->token, array('usernames' => $username, |
43 | 46 | 'fields' => $fields))); |
44 | 47 | $result = $results[$username]; |
45 | - if ($result == null) |
|
46 | - throw new InvalidParam('username', "There is no user by this username."); |
|
48 | + if ($result == null) { |
|
49 | + throw new InvalidParam('username', "There is no user by this username."); |
|
50 | + } |
|
47 | 51 | return Okapi::formatted_response($request, $result); |
48 | 52 | } |
49 | 53 | } |
@@ -23,7 +23,9 @@ discard block |
||
23 | 23 | public static function call(OkapiRequest $request) |
24 | 24 | { |
25 | 25 | $internal_id = $request->get_parameter('internal_id'); |
26 | - if (!$internal_id) throw new ParamMissing('internal_id'); |
|
26 | + if (!$internal_id) { |
|
27 | + throw new ParamMissing('internal_id'); |
|
28 | + } |
|
27 | 29 | $fields = $request->get_parameter('fields'); |
28 | 30 | |
29 | 31 | # There's no need to validate the fields parameter. |
@@ -32,8 +34,9 @@ discard block |
||
32 | 34 | $request->consumer, $request->token, array('internal_ids' => $internal_id, |
33 | 35 | 'fields' => $fields))); |
34 | 36 | $result = $results[$internal_id]; |
35 | - if ($result == null) |
|
36 | - throw new InvalidParam('internal_id', "There is no user by this internal_id."); |
|
37 | + if ($result == null) { |
|
38 | + throw new InvalidParam('internal_id', "There is no user by this internal_id."); |
|
39 | + } |
|
37 | 40 | return Okapi::formatted_response($request, $result); |
38 | 41 | } |
39 | 42 | } |
@@ -24,14 +24,18 @@ discard block |
||
24 | 24 | public static function call(OkapiRequest $request) |
25 | 25 | { |
26 | 26 | $usernames = $request->get_parameter('usernames'); |
27 | - if (!$usernames) throw new ParamMissing('usernames'); |
|
27 | + if (!$usernames) { |
|
28 | + throw new ParamMissing('usernames'); |
|
29 | + } |
|
28 | 30 | $usernames = explode("|", $usernames); |
29 | - if (count($usernames) > 500) |
|
30 | - throw new InvalidParam('usernames', "Maximum allowed number of referenced users ". |
|
31 | + if (count($usernames) > 500) { |
|
32 | + throw new InvalidParam('usernames', "Maximum allowed number of referenced users ". |
|
31 | 33 | "is 500. You provided ".count($usernames)." usernames."); |
34 | + } |
|
32 | 35 | $fields = $request->get_parameter('fields'); |
33 | - if (!$fields) |
|
34 | - throw new ParamMissing('fields'); |
|
36 | + if (!$fields) { |
|
37 | + throw new ParamMissing('fields'); |
|
38 | + } |
|
35 | 39 | |
36 | 40 | # There's no need to validate the fields parameter as the 'users' |
37 | 41 | # method does this (it will raise a proper exception on invalid values). |
@@ -65,10 +69,11 @@ discard block |
||
65 | 69 | $results = array(); |
66 | 70 | foreach ($usernames as $username) |
67 | 71 | { |
68 | - if (!isset($lower_username2useruuid[mb_strtolower($username, 'utf-8')])) |
|
69 | - $results[$username] = null; |
|
70 | - else |
|
71 | - $results[$username] = $id_results[$lower_username2useruuid[mb_strtolower($username, 'utf-8')]]; |
|
72 | + if (!isset($lower_username2useruuid[mb_strtolower($username, 'utf-8')])) { |
|
73 | + $results[$username] = null; |
|
74 | + } else { |
|
75 | + $results[$username] = $id_results[$lower_username2useruuid[mb_strtolower($username, 'utf-8')]]; |
|
76 | + } |
|
72 | 77 | } |
73 | 78 | |
74 | 79 | return Okapi::formatted_response($request, $results); |
@@ -28,18 +28,23 @@ discard block |
||
28 | 28 | public static function call(OkapiRequest $request) |
29 | 29 | { |
30 | 30 | $user_uuids = $request->get_parameter('user_uuids'); |
31 | - if (!$user_uuids) throw new ParamMissing('user_uuids'); |
|
31 | + if (!$user_uuids) { |
|
32 | + throw new ParamMissing('user_uuids'); |
|
33 | + } |
|
32 | 34 | $user_uuids = explode("|", $user_uuids); |
33 | - if (count($user_uuids) > 500) |
|
34 | - throw new InvalidParam('user_uuids', "Maximum allowed number of referenced users ". |
|
35 | + if (count($user_uuids) > 500) { |
|
36 | + throw new InvalidParam('user_uuids', "Maximum allowed number of referenced users ". |
|
35 | 37 | "is 500. You provided ".count($user_uuids)." user IDs."); |
38 | + } |
|
36 | 39 | $fields = $request->get_parameter('fields'); |
37 | - if (!$fields) |
|
38 | - throw new ParamMissing('fields'); |
|
40 | + if (!$fields) { |
|
41 | + throw new ParamMissing('fields'); |
|
42 | + } |
|
39 | 43 | $fields = explode("|", $fields); |
40 | - foreach ($fields as $field) |
|
41 | - if (!in_array($field, self::$valid_field_names)) |
|
44 | + foreach ($fields as $field) { |
|
45 | + if (!in_array($field, self::$valid_field_names)) |
|
42 | 46 | throw new InvalidParam('fields', "'$field' is not a valid field code."); |
47 | + } |
|
43 | 48 | $rs = Db::query(" |
44 | 49 | select user_id, uuid, username, admin, latitude, longitude, date_created |
45 | 50 | from user |
@@ -115,8 +120,7 @@ discard block |
||
115 | 120 | from user |
116 | 121 | where user_id in ('".implode("','", array_map('\okapi\Db::escape_string', array_keys($id2uuid)))."') |
117 | 122 | "); |
118 | - } |
|
119 | - else |
|
123 | + } else |
|
120 | 124 | { |
121 | 125 | # OCDE stores user stats in 'stat_user' table. |
122 | 126 | |
@@ -153,8 +157,9 @@ discard block |
||
153 | 157 | group by user_id |
154 | 158 | "); |
155 | 159 | $rcmds_counts = array(); |
156 | - while ($row = Db::fetch_assoc($rs)) |
|
157 | - $rcmds_counts[$row['user_id']] = $row['rcmds_given']; |
|
160 | + while ($row = Db::fetch_assoc($rs)) { |
|
161 | + $rcmds_counts[$row['user_id']] = $row['rcmds_given']; |
|
162 | + } |
|
158 | 163 | foreach ($extras as $user_id => &$extra_ref) |
159 | 164 | { |
160 | 165 | $extra_ref['rcmds_given'] = isset($rcmds_counts[$user_id]) ? 0 + $rcmds_counts[$user_id] : 0; |
@@ -165,18 +170,21 @@ discard block |
||
165 | 170 | |
166 | 171 | foreach (array('caches_found', 'caches_notfound', 'caches_hidden', 'rcmds_given') as $field) |
167 | 172 | { |
168 | - if (!in_array($field, $fields)) |
|
169 | - continue; |
|
170 | - foreach ($results as $uuid => &$result_ref) |
|
171 | - $result_ref[$field] = $extras[$uuid2id[$uuid]][$field]; |
|
173 | + if (!in_array($field, $fields)) { |
|
174 | + continue; |
|
175 | + } |
|
176 | + foreach ($results as $uuid => &$result_ref) { |
|
177 | + $result_ref[$field] = $extras[$uuid2id[$uuid]][$field]; |
|
178 | + } |
|
172 | 179 | } |
173 | 180 | } |
174 | 181 | |
175 | 182 | # Check which user IDs were not found and mark them with null. |
176 | 183 | |
177 | - foreach ($user_uuids as $user_uuid) |
|
178 | - if (!isset($results[$user_uuid])) |
|
184 | + foreach ($user_uuids as $user_uuid) { |
|
185 | + if (!isset($results[$user_uuid])) |
|
179 | 186 | $results[$user_uuid] = null; |
187 | + } |
|
180 | 188 | |
181 | 189 | return Okapi::formatted_response($request, $results); |
182 | 190 | } |
@@ -33,8 +33,7 @@ discard block |
||
33 | 33 | $tmp = OkapiServiceRunner::call('services/users/by_internal_id', new OkapiInternalRequest( |
34 | 34 | $request->consumer, null, array('internal_id' => $request->token->user_id, 'fields' => 'uuid'))); |
35 | 35 | $user_uuid = $tmp['uuid']; |
36 | - } |
|
37 | - else |
|
36 | + } else |
|
38 | 37 | { |
39 | 38 | throw new BadRequest("You must either: 1. supply the user_uuid argument, or " |
40 | 39 | ."2. sign your request with an Access Token."); |
@@ -49,8 +48,9 @@ discard block |
||
49 | 48 | $request->consumer, $request->token, array('user_uuids' => $user_uuid, |
50 | 49 | 'fields' => $fields))); |
51 | 50 | $result = $results[$user_uuid]; |
52 | - if ($result == null) |
|
53 | - throw new InvalidParam('user_uuid', "There is no user by this ID."); |
|
51 | + if ($result == null) { |
|
52 | + throw new InvalidParam('user_uuid', "There is no user by this ID."); |
|
53 | + } |
|
54 | 54 | return Okapi::formatted_response($request, $result); |
55 | 55 | } |
56 | 56 | } |
@@ -21,13 +21,17 @@ |
||
21 | 21 | public static function call(OkapiRequest $request) |
22 | 22 | { |
23 | 23 | $token_key = $request->get_parameter('oauth_token'); |
24 | - if (!$token_key) |
|
25 | - throw new ParamMissing("oauth_token"); |
|
24 | + if (!$token_key) { |
|
25 | + throw new ParamMissing("oauth_token"); |
|
26 | + } |
|
26 | 27 | $langpref = $request->get_parameter('langpref'); |
27 | 28 | $interactivity = $request->get_parameter('interactivity'); |
28 | - if (!$interactivity) $interactivity = 'minimal'; |
|
29 | - if (!in_array($interactivity, array('minimal', 'confirm_user'))) |
|
30 | - throw new InvalidParam('interactivity', $interactivity); |
|
29 | + if (!$interactivity) { |
|
30 | + $interactivity = 'minimal'; |
|
31 | + } |
|
32 | + if (!in_array($interactivity, array('minimal', 'confirm_user'))) { |
|
33 | + throw new InvalidParam('interactivity', $interactivity); |
|
34 | + } |
|
31 | 35 | |
32 | 36 | # Redirect to the "apps" folder. This is done there (not here) |
33 | 37 | # because: 1) we don't want any cookie or session-handling |
@@ -30,13 +30,19 @@ |
||
30 | 30 | # Read the parameters. |
31 | 31 | |
32 | 32 | $langpref = $request->get_parameter('langpref'); |
33 | - if (!$langpref) $langpref = "en"; |
|
33 | + if (!$langpref) { |
|
34 | + $langpref = "en"; |
|
35 | + } |
|
34 | 36 | |
35 | 37 | $fields = $request->get_parameter('fields'); |
36 | - if (!$fields) $fields = "name"; |
|
38 | + if (!$fields) { |
|
39 | + $fields = "name"; |
|
40 | + } |
|
37 | 41 | |
38 | 42 | $only_locally_used = $request->get_parameter('only_locally_used'); |
39 | - if (!$only_locally_used) $only_locally_used = "false"; |
|
43 | + if (!$only_locally_used) { |
|
44 | + $only_locally_used = "false"; |
|
45 | + } |
|
40 | 46 | $only_locally_used = ($only_locally_used == "true"); |
41 | 47 | |
42 | 48 | # Get the list of attributes and filter the A-codes based on the |