@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | ***************************************************************************/ |
7 | 7 | |
8 | 8 | $disable_verifyemail = true; |
9 | -require __DIR__ . '/lib2/web.inc.php'; |
|
9 | +require __DIR__.'/lib2/web.inc.php'; |
|
10 | 10 | |
11 | 11 | $tpl->name = 'verifyemail'; |
12 | 12 | $tpl->menuitem = MNU_VERIFY_EMAIL; |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | } else { |
29 | 29 | $tpl->assign('emailadr', $user->getEMail()); |
30 | 30 | if ($user->missedDataLicenseMail()) { |
31 | - $tpl->assign('datalicensemail', "<br /><br />" . file_get_contents("resource2/misc/datalicensemail.html")); |
|
31 | + $tpl->assign('datalicensemail', "<br /><br />".file_get_contents("resource2/misc/datalicensemail.html")); |
|
32 | 32 | } |
33 | 33 | $tpl->assign('orgpage', $orgpage); |
34 | 34 | } |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | * |
17 | 17 | ***************************************************************************/ |
18 | 18 | |
19 | -require __DIR__ . '/lib2/web.inc.php'; |
|
19 | +require __DIR__.'/lib2/web.inc.php'; |
|
20 | 20 | |
21 | 21 | $tpl->name = 'picture'; |
22 | 22 | $tpl->menuitem = MNU_CACHES_PICTURE; |
@@ -75,11 +75,11 @@ discard block |
||
75 | 75 | if (isset($_REQUEST['ok'])) { // Ocprop |
76 | 76 | $bError = false; |
77 | 77 | |
78 | - $picture->setSpoiler(isset($_REQUEST['spoiler']) && $_REQUEST['spoiler'] == '1'); // Ocprop |
|
79 | - $picture->setDisplay((isset($_REQUEST['notdisplay']) && $_REQUEST['notdisplay'] == '1') == false); // Ocprop |
|
78 | + $picture->setSpoiler(isset($_REQUEST['spoiler']) && $_REQUEST['spoiler'] == '1'); // Ocprop |
|
79 | + $picture->setDisplay((isset($_REQUEST['notdisplay']) && $_REQUEST['notdisplay'] == '1') == false); // Ocprop |
|
80 | 80 | $picture->setMapPreview(isset($_REQUEST['mappreview']) && $_REQUEST['mappreview'] == '1'); |
81 | 81 | |
82 | - $title = isset($_REQUEST['title']) ? $_REQUEST['title'] : ''; // Ocprop |
|
82 | + $title = isset($_REQUEST['title']) ? $_REQUEST['title'] : ''; // Ocprop |
|
83 | 83 | if ($title == '' || ($picture->getObjectType() == OBJECT_CACHELOG && trim($title) == '')) { |
84 | 84 | $tpl->assign('errortitle', true); |
85 | 85 | $bError = true; |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | } |
136 | 136 | } // try saving as jpg and shrinking if > PICTURE_MAX_LONG_SIDE file |
137 | 137 | else { |
138 | - $picture->setFilenames(mb_strtolower($fname) . '.jpg'); |
|
138 | + $picture->setFilenames(mb_strtolower($fname).'.jpg'); |
|
139 | 139 | if (!$picture->rotate_and_shrink($_FILES['file']['tmp_name'], PICTURE_MAX_LONG_SIDE)) { |
140 | 140 | $bError = true; |
141 | 141 | } |
@@ -34,10 +34,12 @@ discard block |
||
34 | 34 | |
35 | 35 | $uuid = isset($_REQUEST['uuid']) ? $_REQUEST['uuid'] : 0; |
36 | 36 | |
37 | -if ($action == 'add') { // Ocprop |
|
37 | +if ($action == 'add') { |
|
38 | +// Ocprop |
|
38 | 39 | $picture = new picture(); |
39 | 40 | |
40 | - if (isset($_REQUEST['cacheuuid'])) { // Ocprop |
|
41 | + if (isset($_REQUEST['cacheuuid'])) { |
|
42 | +// Ocprop |
|
41 | 43 | $cache = cache::fromUUID($_REQUEST['cacheuuid']); |
42 | 44 | if ($cache === null) { |
43 | 45 | $tpl->error(ERROR_CACHE_NOT_EXISTS); |
@@ -51,7 +53,8 @@ discard block |
||
51 | 53 | $picture->setObjectType(OBJECT_CACHE); |
52 | 54 | |
53 | 55 | $cache = null; |
54 | - } elseif (isset($_REQUEST['loguuid'])) {// Ocprop |
|
56 | + } elseif (isset($_REQUEST['loguuid'])) { |
|
57 | +// Ocprop |
|
55 | 58 | $cachelog = cachelog::fromUUID($_REQUEST['loguuid']); |
56 | 59 | if ($cachelog === null) { |
57 | 60 | $tpl->error(ERROR_CACHELOG_NOT_EXISTS); |
@@ -72,7 +75,8 @@ discard block |
||
72 | 75 | } |
73 | 76 | |
74 | 77 | // uploaded file ok? |
75 | - if (isset($_REQUEST['ok'])) { // Ocprop |
|
78 | + if (isset($_REQUEST['ok'])) { |
|
79 | +// Ocprop |
|
76 | 80 | $bError = false; |
77 | 81 | |
78 | 82 | $picture->setSpoiler(isset($_REQUEST['spoiler']) && $_REQUEST['spoiler'] == '1'); // Ocprop |
@@ -92,7 +96,8 @@ discard block |
||
92 | 96 | $tpl->redirect($picture->getPageLink()); |
93 | 97 | } |
94 | 98 | |
95 | - if (!isset($_FILES['file'])) { // Ocprop |
|
99 | + if (!isset($_FILES['file'])) { |
|
100 | +// Ocprop |
|
96 | 101 | $tpl->assign('errorfile', ERROR_UPLOAD_ERR_NO_FILE); |
97 | 102 | $bError = true; |
98 | 103 | } elseif ($_FILES['file']['error'] == UPLOAD_ERR_NO_FILE) { |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | from okapi_consumers |
14 | 14 | where `key` = '".Db::escape_string($consumer_key)."' |
15 | 15 | "); |
16 | - if (!$row) |
|
17 | - return null; |
|
16 | + if (!$row) { |
|
17 | + return null; |
|
18 | + } |
|
18 | 19 | return new OkapiConsumer($row['key'], $row['secret'], $row['name'], |
19 | 20 | $row['url'], $row['email'], $row['bflags']); |
20 | 21 | } |
@@ -29,10 +30,10 @@ discard block |
||
29 | 30 | and token_type = '".Db::escape_string($token_type)."' |
30 | 31 | and `key` = '".Db::escape_string($token)."' |
31 | 32 | "); |
32 | - if (!$row) |
|
33 | - return null; |
|
34 | - switch ($row['token_type']) |
|
35 | - { |
|
33 | + if (!$row) { |
|
34 | + return null; |
|
35 | + } |
|
36 | + switch ($row['token_type']) { |
|
36 | 37 | case 'request': |
37 | 38 | return new OkapiRequestToken($row['key'], $row['secret'], |
38 | 39 | $row['consumer_key'], $row['callback'], $row['user_id'], |
@@ -57,8 +58,7 @@ discard block |
||
57 | 58 | $timestamp, |
58 | 59 | $nonce |
59 | 60 | ))); |
60 | - try |
|
61 | - { |
|
61 | + try { |
|
62 | 62 | # Time timestamp is saved separately, because we are periodically |
63 | 63 | # removing older nonces from the database (see cronjobs). |
64 | 64 | |
@@ -71,9 +71,7 @@ discard block |
||
71 | 71 | ); |
72 | 72 | "); |
73 | 73 | return null; |
74 | - } |
|
75 | - catch (\Exception $e) |
|
76 | - { |
|
74 | + } catch (\Exception $e) { |
|
77 | 75 | # INSERT failed. This nonce was already used. |
78 | 76 | |
79 | 77 | return $nonce; |
@@ -83,9 +81,8 @@ discard block |
||
83 | 81 | public function new_request_token($consumer, $callback = null) |
84 | 82 | { |
85 | 83 | if ((preg_match("#^[a-z][a-z0-9_.-]*://#", $callback) > 0) || |
86 | - $callback == "oob") |
|
87 | - { /* ok */ } |
|
88 | - else { throw new BadRequest("oauth_callback should begin with lower case <scheme>://, or should equal 'oob'."); } |
|
84 | + $callback == "oob") { |
|
85 | +/* ok */ } else { throw new BadRequest("oauth_callback should begin with lower case <scheme>://, or should equal 'oob'."); } |
|
89 | 86 | $token = new OkapiRequestToken(Okapi::generate_key(20), Okapi::generate_key(40), |
90 | 87 | $consumer->key, $callback, null, Okapi::generate_key(8, true)); |
91 | 88 | Db::execute(" |
@@ -111,12 +108,15 @@ discard block |
||
111 | 108 | |
112 | 109 | public function new_access_token($token, $consumer, $verifier = null) |
113 | 110 | { |
114 | - if ($token->consumer_key != $consumer->key) |
|
115 | - throw new BadRequest("Request Token given is not associated with the Consumer who signed the request."); |
|
116 | - if (!$token->authorized_by_user_id) |
|
117 | - throw new BadRequest("Request Token given has not been authorized."); |
|
118 | - if ($token->verifier != $verifier) |
|
119 | - throw new BadRequest("Invalid verifier."); |
|
111 | + if ($token->consumer_key != $consumer->key) { |
|
112 | + throw new BadRequest("Request Token given is not associated with the Consumer who signed the request."); |
|
113 | + } |
|
114 | + if (!$token->authorized_by_user_id) { |
|
115 | + throw new BadRequest("Request Token given has not been authorized."); |
|
116 | + } |
|
117 | + if ($token->verifier != $verifier) { |
|
118 | + throw new BadRequest("Invalid verifier."); |
|
119 | + } |
|
120 | 120 | |
121 | 121 | # Invalidate the Request Token. |
122 | 122 | |
@@ -138,15 +138,12 @@ discard block |
||
138 | 138 | and user_id = '".Db::escape_string($token->authorized_by_user_id)."' |
139 | 139 | and consumer_key = '".Db::escape_string($consumer->key)."' |
140 | 140 | "); |
141 | - if ($row) |
|
142 | - { |
|
141 | + if ($row) { |
|
143 | 142 | # Use existing Access Token |
144 | 143 | |
145 | 144 | $access_token = new OkapiAccessToken($row['key'], $row['secret'], |
146 | 145 | $consumer->key, $token->authorized_by_user_id); |
147 | - } |
|
148 | - else |
|
149 | - { |
|
146 | + } else { |
|
150 | 147 | # Generate a new Access Token. |
151 | 148 | |
152 | 149 | $access_token = new OkapiAccessToken(Okapi::generate_key(20), Okapi::generate_key(40), |
@@ -71,15 +71,14 @@ discard block |
||
71 | 71 | /** Get method options (is consumer required etc.). */ |
72 | 72 | public static function options($service_name) |
73 | 73 | { |
74 | - if (!self::exists($service_name)) |
|
75 | - throw new Exception(); |
|
74 | + if (!self::exists($service_name)) { |
|
75 | + throw new Exception(); |
|
76 | + } |
|
76 | 77 | require_once($GLOBALS['rootpath']."okapi/$service_name.php"); |
77 | - try |
|
78 | - { |
|
78 | + try { |
|
79 | 79 | return call_user_func(array('\\okapi\\'. |
80 | 80 | str_replace('/', '\\', $service_name).'\\WebService', 'options')); |
81 | - } catch (Exception $e) |
|
82 | - { |
|
81 | + } catch (Exception $e) { |
|
83 | 82 | throw new Exception("Make sure you've declared your WebService class ". |
84 | 83 | "in an valid namespace (".'okapi\\'.str_replace('/', '\\', $service_name)."); ". |
85 | 84 | $e->getMessage()); |
@@ -92,8 +91,9 @@ discard block |
||
92 | 91 | */ |
93 | 92 | public static function docs($service_name) |
94 | 93 | { |
95 | - if (!self::exists($service_name)) |
|
96 | - throw new Exception(); |
|
94 | + if (!self::exists($service_name)) { |
|
95 | + throw new Exception(); |
|
96 | + } |
|
97 | 97 | try { |
98 | 98 | return file_get_contents("$service_name.xml", true); |
99 | 99 | } catch (Exception $e) { |
@@ -114,31 +114,28 @@ discard block |
||
114 | 114 | { |
115 | 115 | Okapi::init_internals(); |
116 | 116 | |
117 | - if (!self::exists($service_name)) |
|
118 | - throw new Exception("Method does not exist: '$service_name'"); |
|
117 | + if (!self::exists($service_name)) { |
|
118 | + throw new Exception("Method does not exist: '$service_name'"); |
|
119 | + } |
|
119 | 120 | |
120 | 121 | $options = self::options($service_name); |
121 | - if ($options['min_auth_level'] >= 2 && $request->consumer == null) |
|
122 | - { |
|
122 | + if ($options['min_auth_level'] >= 2 && $request->consumer == null) { |
|
123 | 123 | throw new Exception("Method '$service_name' called with mismatched OkapiRequest: ". |
124 | 124 | "\$request->consumer MAY NOT be empty for Level 2 and Level 3 methods. Provide ". |
125 | 125 | "a dummy Consumer if you have to."); |
126 | 126 | } |
127 | - if ($options['min_auth_level'] >= 3 && $request->token == null) |
|
128 | - { |
|
127 | + if ($options['min_auth_level'] >= 3 && $request->token == null) { |
|
129 | 128 | throw new Exception("Method '$service_name' called with mismatched OkapiRequest: ". |
130 | 129 | "\$request->token MAY NOT be empty for Level 3 methods."); |
131 | 130 | } |
132 | 131 | |
133 | 132 | $time_started = microtime(true); |
134 | 133 | Okapi::gettext_domain_init(); |
135 | - try |
|
136 | - { |
|
134 | + try { |
|
137 | 135 | require_once($GLOBALS['rootpath']."okapi/$service_name.php"); |
138 | 136 | $response = call_user_func(array('\\okapi\\'. |
139 | 137 | str_replace('/', '\\', $service_name).'\\WebService', 'call'), $request); |
140 | - if ($options['min_auth_level'] >= 3 && $request->token->token_type == "access") |
|
141 | - { |
|
138 | + if ($options['min_auth_level'] >= 3 && $request->token->token_type == "access") { |
|
142 | 139 | Db::execute(" |
143 | 140 | update user set last_login=now() |
144 | 141 | where user_id='".Db::escape_string($request->token->user_id)."' |
@@ -178,18 +175,21 @@ discard block |
||
178 | 175 | if ($request !== null) { |
179 | 176 | $consumer_key = ($request->consumer != null) ? $request->consumer->key : 'anonymous'; |
180 | 177 | $user_id = (($request->token != null) && ($request->token instanceof OkapiAccessToken)) ? $request->token->user_id : -1; |
181 | - if ($request->is_http_request() && ($service_name[0] == 's')) # 's' for "services/", we don't want "extra/" included |
|
178 | + if ($request->is_http_request() && ($service_name[0] == 's')) { |
|
179 | + # 's' for "services/", we don't want "extra/" included |
|
182 | 180 | $calltype = 'http'; |
183 | - else |
|
184 | - $calltype = 'internal'; |
|
181 | + } else { |
|
182 | + $calltype = 'internal'; |
|
183 | + } |
|
185 | 184 | } else { |
186 | 185 | $consumer_key = 'internal'; |
187 | 186 | $user_id = -1; |
188 | 187 | $calltype = 'internal'; |
189 | 188 | } |
190 | 189 | |
191 | - if (Settings::get('OC_BRANCH') == 'oc.de' && $user_id != -1) |
|
192 | - $user_id = 0; |
|
190 | + if (Settings::get('OC_BRANCH') == 'oc.de' && $user_id != -1) { |
|
191 | + $user_id = 0; |
|
192 | + } |
|
193 | 193 | |
194 | 194 | Db::execute(" |
195 | 195 | insert into okapi_stats_temp (`datetime`, consumer_key, user_id, service_name, calltype, runtime) |
@@ -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']), |