@@ -192,7 +192,7 @@ |
||
192 | 192 | * loads attribute values from the cache. If they are not present in the |
193 | 193 | * cache, it will read and parse them from attribute-definitions.xml file. |
194 | 194 | */ |
195 | - private static function init_from_cache($allow_refreshing=true) |
|
195 | + private static function init_from_cache($allow_refreshing = true) |
|
196 | 196 | { |
197 | 197 | if (self::$attr_dict !== null) |
198 | 198 | { |
@@ -49,21 +49,17 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public static function refresh_now() |
51 | 51 | { |
52 | - try |
|
53 | - { |
|
52 | + try { |
|
54 | 53 | $path = $GLOBALS['rootpath']."okapi/services/attrs/attribute-definitions.xml"; |
55 | 54 | $xml = file_get_contents($path); |
56 | 55 | self::refresh_from_string($xml); |
57 | - } |
|
58 | - catch (Exception $e) |
|
59 | - { |
|
56 | + } catch (Exception $e) { |
|
60 | 57 | # Failed to read or parse the file (i.e. after a syntax error was |
61 | 58 | # commited). Let's check when the last successful parse occured. |
62 | 59 | |
63 | 60 | self::init_from_cache(false); |
64 | 61 | |
65 | - if (self::$attr_dict === null) |
|
66 | - { |
|
62 | + if (self::$attr_dict === null) { |
|
67 | 63 | # That's bad! We don't have ANY copy of the data AND we failed |
68 | 64 | # to parse it. We will use a fake, empty data. |
69 | 65 | |
@@ -99,8 +95,7 @@ discard block |
||
99 | 95 | # Build cache attributes dictionary |
100 | 96 | |
101 | 97 | $all_internal_ids = array(); |
102 | - foreach ($doc->attr as $attrnode) |
|
103 | - { |
|
98 | + foreach ($doc->attr as $attrnode) { |
|
104 | 99 | $attr = array( |
105 | 100 | 'acode' => (string)$attrnode['acode'], |
106 | 101 | 'gc_equivs' => array(), |
@@ -109,47 +104,45 @@ discard block |
||
109 | 104 | 'descriptions' => array(), |
110 | 105 | 'is_discontinued' => true |
111 | 106 | ); |
112 | - foreach ($attrnode->groundspeak as $gsnode) |
|
113 | - { |
|
107 | + foreach ($attrnode->groundspeak as $gsnode) { |
|
114 | 108 | $attr['gc_equivs'][] = array( |
115 | 109 | 'id' => (int)$gsnode['id'], |
116 | 110 | 'inc' => in_array((string)$gsnode['inc'], array("true", "1")) ? 1 : 0, |
117 | 111 | 'name' => (string)$gsnode['name'] |
118 | 112 | ); |
119 | 113 | } |
120 | - foreach ($attrnode->opencaching as $ocnode) |
|
121 | - { |
|
114 | + foreach ($attrnode->opencaching as $ocnode) { |
|
122 | 115 | /* If it is used by at least one OC site, then it's NOT discontinued. */ |
123 | 116 | $attr['is_discontinued'] = false; |
124 | 117 | |
125 | - if ((string)$ocnode['schema'] == $my_schema) |
|
126 | - { |
|
118 | + if ((string)$ocnode['schema'] == $my_schema) { |
|
127 | 119 | /* It is used by THIS OC site. */ |
128 | 120 | |
129 | 121 | $internal_id = (int)$ocnode['id']; |
130 | - if (isset($all_internal_ids[$internal_id])) |
|
131 | - throw new Exception("The internal attribute ".$internal_id. |
|
122 | + if (isset($all_internal_ids[$internal_id])) { |
|
123 | + throw new Exception("The internal attribute ".$internal_id. |
|
132 | 124 | " has multiple assigments to OKAPI attributes."); |
125 | + } |
|
133 | 126 | $all_internal_ids[$internal_id] = true; |
134 | - if (!is_null($attr['internal_id'])) |
|
135 | - throw new Exception("There are multiple internal IDs for the ". |
|
127 | + if (!is_null($attr['internal_id'])) { |
|
128 | + throw new Exception("There are multiple internal IDs for the ". |
|
136 | 129 | $attr['acode']." attribute."); |
130 | + } |
|
137 | 131 | $attr['internal_id'] = $internal_id; |
138 | 132 | } |
139 | 133 | } |
140 | - foreach ($attrnode->lang as $langnode) |
|
141 | - { |
|
134 | + foreach ($attrnode->lang as $langnode) { |
|
142 | 135 | $lang = (string)$langnode['id']; |
143 | - foreach ($langnode->name as $namenode) |
|
144 | - { |
|
145 | - if (isset($attr['names'][$lang])) |
|
146 | - throw new Exception("Duplicate ".$lang." name of attribute ".$attr['acode']); |
|
136 | + foreach ($langnode->name as $namenode) { |
|
137 | + if (isset($attr['names'][$lang])) { |
|
138 | + throw new Exception("Duplicate ".$lang." name of attribute ".$attr['acode']); |
|
139 | + } |
|
147 | 140 | $attr['names'][$lang] = (string)$namenode; |
148 | 141 | } |
149 | - foreach ($langnode->desc as $descnode) |
|
150 | - { |
|
151 | - if (isset($attr['descriptions'][$lang])) |
|
152 | - throw new Exception("Duplicate ".$lang." description of attribute ".$attr['acode']); |
|
142 | + foreach ($langnode->desc as $descnode) { |
|
143 | + if (isset($attr['descriptions'][$lang])) { |
|
144 | + throw new Exception("Duplicate ".$lang." description of attribute ".$attr['acode']); |
|
145 | + } |
|
153 | 146 | $xml = $descnode->asxml(); /* contains "<desc>" and "</desc>" */ |
154 | 147 | $innerxml = preg_replace("/(^[^>]+>)|(<[^<]+$)/us", "", $xml); |
155 | 148 | $attr['descriptions'][$lang] = self::cleanup_string($innerxml); |
@@ -194,25 +187,20 @@ discard block |
||
194 | 187 | */ |
195 | 188 | private static function init_from_cache($allow_refreshing=true) |
196 | 189 | { |
197 | - if (self::$attr_dict !== null) |
|
198 | - { |
|
190 | + if (self::$attr_dict !== null) { |
|
199 | 191 | /* Already initialized. */ |
200 | 192 | return; |
201 | 193 | } |
202 | 194 | $cache_key = "attrhelper/dict#".Okapi::$git_revision.self::cache_key_suffix(); |
203 | 195 | $cachedvalue = Cache::get($cache_key); |
204 | - if ($cachedvalue === null) |
|
205 | - { |
|
196 | + if ($cachedvalue === null) { |
|
206 | 197 | # I.e. after Okapi::$git_revision is changed, or cache got invalidated. |
207 | 198 | |
208 | - if ($allow_refreshing) |
|
209 | - { |
|
199 | + if ($allow_refreshing) { |
|
210 | 200 | self::refresh_now(); |
211 | 201 | self::init_from_cache(false); |
212 | 202 | return; |
213 | - } |
|
214 | - else |
|
215 | - { |
|
203 | + } else { |
|
216 | 204 | $cachedvalue = array( |
217 | 205 | 'attr_dict' => array(), |
218 | 206 | ); |
@@ -244,17 +232,18 @@ discard block |
||
244 | 232 | public static function get_internal_id_to_acode_mapping() |
245 | 233 | { |
246 | 234 | static $mapping = null; |
247 | - if ($mapping !== null) |
|
248 | - return $mapping; |
|
235 | + if ($mapping !== null) { |
|
236 | + return $mapping; |
|
237 | + } |
|
249 | 238 | |
250 | 239 | $cache_key = "attrhelper/id2acode/".Okapi::$git_revision.self::cache_key_suffix(); |
251 | 240 | $mapping = Cache::get($cache_key); |
252 | - if (!$mapping) |
|
253 | - { |
|
241 | + if (!$mapping) { |
|
254 | 242 | self::init_from_cache(); |
255 | 243 | $mapping = array(); |
256 | - foreach (self::$attr_dict as $acode => &$attr_ref) |
|
257 | - $mapping[$attr_ref['internal_id']] = $acode; |
|
244 | + foreach (self::$attr_dict as $acode => &$attr_ref) { |
|
245 | + $mapping[$attr_ref['internal_id']] = $acode; |
|
246 | + } |
|
258 | 247 | Cache::set($cache_key, $mapping, self::ttl()); |
259 | 248 | } |
260 | 249 | return $mapping; |
@@ -267,18 +256,17 @@ discard block |
||
267 | 256 | public static function get_acode_to_name_mapping($langpref) |
268 | 257 | { |
269 | 258 | static $mapping = null; |
270 | - if ($mapping !== null) |
|
271 | - return $mapping; |
|
259 | + if ($mapping !== null) { |
|
260 | + return $mapping; |
|
261 | + } |
|
272 | 262 | |
273 | 263 | $cache_key = md5(serialize(array("attrhelper/acode2name", $langpref, |
274 | 264 | Okapi::$git_revision, self::cache_key_suffix()))); |
275 | 265 | $mapping = Cache::get($cache_key); |
276 | - if (!$mapping) |
|
277 | - { |
|
266 | + if (!$mapping) { |
|
278 | 267 | self::init_from_cache(); |
279 | 268 | $mapping = array(); |
280 | - foreach (self::$attr_dict as $acode => &$attr_ref) |
|
281 | - { |
|
269 | + foreach (self::$attr_dict as $acode => &$attr_ref) { |
|
282 | 270 | $mapping[$acode] = Okapi::pick_best_language( |
283 | 271 | $attr_ref['names'], $langpref); |
284 | 272 | } |
@@ -90,7 +90,7 @@ |
||
90 | 90 | # Fill some other fields (not kept in the cached attrdict). |
91 | 91 | |
92 | 92 | $attr['is_locally_used'] = ($attr['internal_id'] !== null); |
93 | - $attr['is_deprecated'] = $attr['is_discontinued']; // deprecated and undocumetned field, see issue 70 |
|
93 | + $attr['is_deprecated'] = $attr['is_discontinued']; // deprecated and undocumetned field, see issue 70 |
|
94 | 94 | |
95 | 95 | # Add to results. |
96 | 96 |
@@ -35,26 +35,35 @@ discard block |
||
35 | 35 | # Read the parameters. |
36 | 36 | |
37 | 37 | $acodes = $request->get_parameter('acodes'); |
38 | - if (!$acodes) throw new ParamMissing('acodes'); |
|
38 | + if (!$acodes) { |
|
39 | + throw new ParamMissing('acodes'); |
|
40 | + } |
|
39 | 41 | $acodes = explode("|", $acodes); |
40 | 42 | |
41 | 43 | $langpref = $request->get_parameter('langpref'); |
42 | - if (!$langpref) $langpref = "en"; |
|
44 | + if (!$langpref) { |
|
45 | + $langpref = "en"; |
|
46 | + } |
|
43 | 47 | $langpref = explode("|", $langpref); |
44 | 48 | |
45 | 49 | $fields = $request->get_parameter('fields'); |
46 | - if (!$fields) $fields = "name"; |
|
50 | + if (!$fields) { |
|
51 | + $fields = "name"; |
|
52 | + } |
|
47 | 53 | $fields = explode("|", $fields); |
48 | - foreach ($fields as $field) |
|
49 | - { |
|
50 | - if (!in_array($field, self::$valid_field_names)) |
|
51 | - throw new InvalidParam('fields', "'$field' is not a valid field code."); |
|
54 | + foreach ($fields as $field) { |
|
55 | + if (!in_array($field, self::$valid_field_names)) { |
|
56 | + throw new InvalidParam('fields', "'$field' is not a valid field code."); |
|
57 | + } |
|
52 | 58 | } |
53 | 59 | |
54 | 60 | $forward_compatible = $request->get_parameter('forward_compatible'); |
55 | - if (!$forward_compatible) $forward_compatible = "true"; |
|
56 | - if (!in_array($forward_compatible, array("true", "false"))) |
|
57 | - throw new InvalidParam('forward_compatible'); |
|
61 | + if (!$forward_compatible) { |
|
62 | + $forward_compatible = "true"; |
|
63 | + } |
|
64 | + if (!in_array($forward_compatible, array("true", "false"))) { |
|
65 | + throw new InvalidParam('forward_compatible'); |
|
66 | + } |
|
58 | 67 | $forward_compatible = ($forward_compatible == "true"); |
59 | 68 | |
60 | 69 | # Load the attributes (all of them). |
@@ -66,8 +75,7 @@ discard block |
||
66 | 75 | # to the results. |
67 | 76 | |
68 | 77 | $results = array(); |
69 | - foreach ($acodes as $acode) |
|
70 | - { |
|
78 | + foreach ($acodes as $acode) { |
|
71 | 79 | /* Please note, that the $attr variable from the $attrdict dictionary |
72 | 80 | * below is NOT fully compatible with the interface of the "attribute" |
73 | 81 | * method. Some of $attr's fields are private and should not be exposed, |
@@ -101,8 +109,7 @@ discard block |
||
101 | 109 | # in the $attrdict because currently we have no way of knowing then they |
102 | 110 | # change.) |
103 | 111 | |
104 | - if (in_array('local_icon_url', $fields)) |
|
105 | - { |
|
112 | + if (in_array('local_icon_url', $fields)) { |
|
106 | 113 | $tmp = Db::select_all(" |
107 | 114 | select id, icon_large |
108 | 115 | from cache_attrib |
@@ -133,8 +140,9 @@ discard block |
||
133 | 140 | continue; |
134 | 141 | } |
135 | 142 | $clean_row = array(); |
136 | - foreach ($fields as $field) |
|
137 | - $clean_row[$field] = $attr_ref[$field]; |
|
143 | + foreach ($fields as $field) { |
|
144 | + $clean_row[$field] = $attr_ref[$field]; |
|
145 | + } |
|
138 | 146 | $attr_ref = $clean_row; |
139 | 147 | } |
140 | 148 |
@@ -30,13 +30,19 @@ discard block |
||
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 |
@@ -45,8 +51,7 @@ discard block |
||
45 | 51 | require_once 'attr_helper.inc.php'; |
46 | 52 | $attrdict = AttrHelper::get_attrdict(); |
47 | 53 | $acodes = array(); |
48 | - foreach ($attrdict as $acode => &$attr_ref) |
|
49 | - { |
|
54 | + foreach ($attrdict as $acode => &$attr_ref) { |
|
50 | 55 | if ($only_locally_used && ($attr_ref['internal_id'] === null)) { |
51 | 56 | /* Skip. */ |
52 | 57 | continue; |
@@ -148,7 +148,7 @@ |
||
148 | 148 | array( |
149 | 149 | 'uuid' => $row['uuid'], |
150 | 150 | 'url' => $row['url'], |
151 | - 'thumb_url' => Settings::get('SITE_URL') . 'thumbs.php?'.$object_type_param.'uuid=' . $row['uuid'], |
|
151 | + 'thumb_url' => Settings::get('SITE_URL').'thumbs.php?'.$object_type_param.'uuid='.$row['uuid'], |
|
152 | 152 | 'caption' => $row['title'], |
153 | 153 | 'is_spoiler' => ($row['spoiler'] ? true : false), |
154 | 154 | ); |
@@ -31,35 +31,38 @@ 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'); |
|
35 | - if ($log_uuids === "") |
|
36 | - { |
|
34 | + if ($log_uuids === null) { |
|
35 | + throw new ParamMissing('log_uuids'); |
|
36 | + } |
|
37 | + if ($log_uuids === "") { |
|
37 | 38 | $log_uuids = array(); |
39 | + } else { |
|
40 | + $log_uuids = explode("|", $log_uuids); |
|
38 | 41 | } |
39 | - else |
|
40 | - $log_uuids = explode("|", $log_uuids); |
|
41 | 42 | |
42 | - if ((count($log_uuids) > 500) && (!$request->skip_limits)) |
|
43 | - throw new InvalidParam('log_uuids', "Maximum allowed number of referenced ". |
|
43 | + if ((count($log_uuids) > 500) && (!$request->skip_limits)) { |
|
44 | + throw new InvalidParam('log_uuids', "Maximum allowed number of referenced ". |
|
44 | 45 | "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)."); |
|
46 | + } |
|
47 | + if (count($log_uuids) != count(array_unique($log_uuids))) { |
|
48 | + throw new InvalidParam('log_uuids', "Duplicate UUIDs detected (make sure each UUID is referenced only once)."); |
|
49 | + } |
|
47 | 50 | $fields = $request->get_parameter('fields'); |
48 | - if (!$fields) $fields = "date|user|type|comment"; |
|
51 | + if (!$fields) { |
|
52 | + $fields = "date|user|type|comment"; |
|
53 | + } |
|
49 | 54 | $fields = explode("|", $fields); |
50 | - foreach ($fields as $field) |
|
51 | - if (!in_array($field, self::$valid_field_names)) |
|
55 | + foreach ($fields as $field) { |
|
56 | + if (!in_array($field, self::$valid_field_names)) |
|
52 | 57 | throw new InvalidParam('fields', "'$field' is not a valid field code."); |
58 | + } |
|
53 | 59 | |
54 | - if (Settings::get('OC_BRANCH') == 'oc.de') |
|
55 | - { |
|
60 | + if (Settings::get('OC_BRANCH') == 'oc.de') { |
|
56 | 61 | $teamentry_field = 'cl.oc_team_comment'; |
57 | 62 | $ratingdate_condition = 'and cr.rating_date=cl.date'; |
58 | 63 | $needs_maintenance_SQL = 'cl.needs_maintenance'; |
59 | 64 | $listing_is_outdated_SQL = 'cl.listing_outdated'; |
60 | - } |
|
61 | - else |
|
62 | - { |
|
65 | + } else { |
|
63 | 66 | $teamentry_field = '(cl.type=12)'; |
64 | 67 | $ratingdate_condition = ''; |
65 | 68 | $needs_maintenance_SQL = 'IF(cl.type=5, 2, IF(cl.type=6, 1, 0))'; |
@@ -96,8 +99,7 @@ discard block |
||
96 | 99 | $results = array(); |
97 | 100 | $log_id2uuid = array(); /* Maps logs' internal_ids to uuids */ |
98 | 101 | $flag_options = array('null', 'false', 'true'); |
99 | - while ($row = Db::fetch_assoc($rs)) |
|
100 | - { |
|
102 | + while ($row = Db::fetch_assoc($rs)) { |
|
101 | 103 | $results[$row['uuid']] = array( |
102 | 104 | 'uuid' => $row['uuid'], |
103 | 105 | 'cache_code' => $row['cache_code'], |
@@ -122,8 +124,7 @@ discard block |
||
122 | 124 | |
123 | 125 | # fetch images |
124 | 126 | |
125 | - if (in_array('images', $fields)) |
|
126 | - { |
|
127 | + if (in_array('images', $fields)) { |
|
127 | 128 | # For OCPL log entry images, pictures.seq currently is always = 1, |
128 | 129 | # while OCDE uses it for ordering the images. |
129 | 130 | |
@@ -142,8 +143,7 @@ discard block |
||
142 | 143 | } else { |
143 | 144 | $object_type_param = ''; |
144 | 145 | } |
145 | - while ($row = Db::fetch_assoc($rs)) |
|
146 | - { |
|
146 | + while ($row = Db::fetch_assoc($rs)) { |
|
147 | 147 | $results[$log_id2uuid[$row['object_id']]]['images'][] = |
148 | 148 | array( |
149 | 149 | 'uuid' => $row['uuid'], |
@@ -158,22 +158,25 @@ discard block |
||
158 | 158 | |
159 | 159 | # Check which UUIDs were not found and mark them with null. |
160 | 160 | |
161 | - foreach ($log_uuids as $log_uuid) |
|
162 | - if (!isset($results[$log_uuid])) |
|
161 | + foreach ($log_uuids as $log_uuid) { |
|
162 | + if (!isset($results[$log_uuid])) |
|
163 | 163 | $results[$log_uuid] = null; |
164 | + } |
|
164 | 165 | |
165 | 166 | # Remove unwanted fields. |
166 | 167 | |
167 | - foreach (self::$valid_field_names as $field) |
|
168 | - if (!in_array($field, $fields)) |
|
168 | + foreach (self::$valid_field_names as $field) { |
|
169 | + if (!in_array($field, $fields)) |
|
169 | 170 | foreach ($results as &$result_ref) |
170 | 171 | unset($result_ref[$field]); |
172 | + } |
|
171 | 173 | |
172 | 174 | # Order the results in the same order as the input codes were given. |
173 | 175 | |
174 | 176 | $ordered_results = array(); |
175 | - foreach ($log_uuids as $log_uuid) |
|
176 | - $ordered_results[$log_uuid] = $results[$log_uuid]; |
|
177 | + foreach ($log_uuids as $log_uuid) { |
|
178 | + $ordered_results[$log_uuid] = $results[$log_uuid]; |
|
179 | + } |
|
177 | 180 | |
178 | 181 | return Okapi::formatted_response($request, $ordered_results); |
179 | 182 | } |
@@ -24,21 +24,31 @@ discard block |
||
24 | 24 | public static function call(OkapiRequest $request) |
25 | 25 | { |
26 | 26 | $user_uuid = $request->get_parameter('user_uuid'); |
27 | - if (!$user_uuid) throw new ParamMissing('user_uuid'); |
|
27 | + if (!$user_uuid) { |
|
28 | + throw new ParamMissing('user_uuid'); |
|
29 | + } |
|
28 | 30 | $limit = $request->get_parameter('limit'); |
29 | - if (!$limit) $limit = "20"; |
|
30 | - if (!is_numeric($limit)) |
|
31 | - throw new InvalidParam('limit', "'$limit'"); |
|
31 | + if (!$limit) { |
|
32 | + $limit = "20"; |
|
33 | + } |
|
34 | + if (!is_numeric($limit)) { |
|
35 | + throw new InvalidParam('limit', "'$limit'"); |
|
36 | + } |
|
32 | 37 | $limit = intval($limit); |
33 | - if (($limit < 1) || ($limit > 1000)) |
|
34 | - throw new InvalidParam('limit', "Has to be in range 1..1000."); |
|
38 | + if (($limit < 1) || ($limit > 1000)) { |
|
39 | + throw new InvalidParam('limit', "Has to be in range 1..1000."); |
|
40 | + } |
|
35 | 41 | $offset = $request->get_parameter('offset'); |
36 | - if (!$offset) $offset = "0"; |
|
37 | - if (!is_numeric($offset)) |
|
38 | - throw new InvalidParam('offset', "'$offset'"); |
|
42 | + if (!$offset) { |
|
43 | + $offset = "0"; |
|
44 | + } |
|
45 | + if (!is_numeric($offset)) { |
|
46 | + throw new InvalidParam('offset', "'$offset'"); |
|
47 | + } |
|
39 | 48 | $offset = intval($offset); |
40 | - if ($offset < 0) |
|
41 | - throw new InvalidParam('offset', "'$offset'"); |
|
49 | + if ($offset < 0) { |
|
50 | + throw new InvalidParam('offset', "'$offset'"); |
|
51 | + } |
|
42 | 52 | |
43 | 53 | # Check if user exists and retrieve user's ID (this will throw |
44 | 54 | # a proper exception on invalid UUID). |
@@ -60,8 +70,7 @@ discard block |
||
60 | 70 | limit $offset, $limit |
61 | 71 | "); |
62 | 72 | $results = array(); |
63 | - while ($row = Db::fetch_assoc($rs)) |
|
64 | - { |
|
73 | + while ($row = Db::fetch_assoc($rs)) { |
|
65 | 74 | $results[] = array( |
66 | 75 | 'uuid' => $row['uuid'], |
67 | 76 | 'date' => date('c', $row['date']), |
@@ -19,7 +19,9 @@ discard block |
||
19 | 19 | * the Consumer did anything wrong (it's the user who did). This exception shouldn't |
20 | 20 | * be used outside of this file. |
21 | 21 | */ |
22 | -class CannotPublishException extends Exception {} |
|
22 | +class CannotPublishException extends Exception |
|
23 | +{ |
|
24 | +} |
|
23 | 25 | |
24 | 26 | class WebService |
25 | 27 | { |
@@ -60,8 +62,9 @@ discard block |
||
60 | 62 | |
61 | 63 | $is_spoiler = $request->get_parameter('is_spoiler'); |
62 | 64 | if ($is_spoiler !== null) { |
63 | - if (!in_array($is_spoiler, array('true', 'false'))) |
|
64 | - throw new InvalidParam('is_spoiler'); |
|
65 | + if (!in_array($is_spoiler, array('true', 'false'))) { |
|
66 | + throw new InvalidParam('is_spoiler'); |
|
67 | + } |
|
65 | 68 | } |
66 | 69 | |
67 | 70 | $position = LogImagesCommon::validate_position($request); |
@@ -98,10 +101,8 @@ discard block |
||
98 | 101 | } |
99 | 102 | |
100 | 103 | # update position |
101 | - if ($position !== null) |
|
102 | - { |
|
103 | - if (Settings::get('OC_BRANCH') == 'oc.pl') |
|
104 | - { |
|
104 | + if ($position !== null) { |
|
105 | + if (Settings::get('OC_BRANCH') == 'oc.pl') { |
|
105 | 106 | # OCPL as no arbitrary log picture ordering => ignore position parameter |
106 | 107 | # and return the picture's current position. |
107 | 108 | |
@@ -111,9 +112,7 @@ discard block |
||
111 | 112 | order by date_created |
112 | 113 | "); |
113 | 114 | $position = array_search($image_uuid, $image_uuids); |
114 | - } |
|
115 | - else |
|
116 | - { |
|
115 | + } else { |
|
117 | 116 | list($position, $seq) = LogImagesCommon::prepare_position( |
118 | 117 | $log_internal_id, |
119 | 118 | $position, |
@@ -125,8 +124,7 @@ discard block |
||
125 | 124 | select seq from pictures where uuid = '".$image_uuid_escaped."' |
126 | 125 | "); |
127 | 126 | |
128 | - if ($seq != $old_seq) |
|
129 | - { |
|
127 | + if ($seq != $old_seq) { |
|
130 | 128 | # First move the edited picture to the end, to make space for rotating. |
131 | 129 | # Remember that we have no transactions at OC.de. If something goes wrong, |
132 | 130 | # the image will stay at the end of the list. |
@@ -204,11 +202,12 @@ discard block |
||
204 | 202 | # This is the "real" entry point. A wrapper for the _call method. |
205 | 203 | |
206 | 204 | $langpref = $request->get_parameter('langpref'); |
207 | - if (!$langpref) $langpref = "en"; |
|
205 | + if (!$langpref) { |
|
206 | + $langpref = "en"; |
|
207 | + } |
|
208 | 208 | Okapi::gettext_domain_init(explode("|", $langpref)); |
209 | 209 | |
210 | - try |
|
211 | - { |
|
210 | + try { |
|
212 | 211 | $position = self::_call($request); |
213 | 212 | $result = array( |
214 | 213 | 'success' => true, |
@@ -216,9 +215,7 @@ discard block |
||
216 | 215 | 'position' => $position |
217 | 216 | ); |
218 | 217 | Okapi::gettext_domain_restore(); |
219 | - } |
|
220 | - catch (CannotPublishException $e) |
|
221 | - { |
|
218 | + } catch (CannotPublishException $e) { |
|
222 | 219 | Okapi::gettext_domain_restore(); |
223 | 220 | $result = array( |
224 | 221 | 'success' => false, |
@@ -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 | } |
@@ -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 | ?> |
@@ -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 | ?> |