Completed
Pull Request — master (#313)
by Thomas
18:19 queued 08:41
created
htdocs/okapi/services/logs/logs.php 1 patch
Braces   +24 added lines, -11 removed lines patch added patch discarded remove patch
@@ -24,19 +24,31 @@  discard block
 block discarded – undo
24 24
     public static function call(OkapiRequest $request)
25 25
     {
26 26
         $cache_code = $request->get_parameter('cache_code');
27
-        if (!$cache_code) throw new ParamMissing('cache_code');
27
+        if (!$cache_code) {
28
+            throw new ParamMissing('cache_code');
29
+        }
28 30
         $fields = $request->get_parameter('fields');
29
-        if (!$fields) $fields = "uuid|date|user|type|comment";
31
+        if (!$fields) {
32
+            $fields = "uuid|date|user|type|comment";
33
+        }
30 34
 
31 35
         $offset = $request->get_parameter('offset');
32
-        if (!$offset) $offset = "0";
33
-        if ((((int)$offset) != $offset) || ((int)$offset) < 0)
34
-            throw new InvalidParam('offset', "Expecting non-negative integer.");
36
+        if (!$offset) {
37
+            $offset = "0";
38
+        }
39
+        if ((((int)$offset) != $offset) || ((int)$offset) < 0) {
40
+                    throw new InvalidParam('offset', "Expecting non-negative integer.");
41
+        }
35 42
         $limit = $request->get_parameter('limit');
36
-        if (!$limit) $limit = "none";
37
-        if ($limit == "none") $limit = "999999999";
38
-        if ((((int)$limit) != $limit) || ((int)$limit) < 0)
39
-            throw new InvalidParam('limit', "Expecting non-negative integer or 'none'.");
43
+        if (!$limit) {
44
+            $limit = "none";
45
+        }
46
+        if ($limit == "none") {
47
+            $limit = "999999999";
48
+        }
49
+        if ((((int)$limit) != $limit) || ((int)$limit) < 0) {
50
+                    throw new InvalidParam('limit', "Expecting non-negative integer or 'none'.");
51
+        }
40 52
 
41 53
         # Check if code exists and retrieve cache ID (this will throw
42 54
         # a proper exception on invalid code).
@@ -64,8 +76,9 @@  discard block
 block discarded – undo
64 76
         $internal_request->skip_limits = true;
65 77
         $logs = OkapiServiceRunner::call('services/logs/entries', $internal_request);
66 78
         $results = array();
67
-        foreach ($log_uuids as $log_uuid)
68
-            $results[] = $logs[$log_uuid];
79
+        foreach ($log_uuids as $log_uuid) {
80
+                    $results[] = $logs[$log_uuid];
81
+        }
69 82
 
70 83
         /* Handle OCPL's "access logs" feature. */
71 84
 
Please login to merge, or discard this patch.
htdocs/okapi/services/users/by_username.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@
 block discarded – undo
32 32
         # Catch pipe chars here, because services/users/by_usernames would split up the name.
33 33
         # OC databases do not contain user names with pipe chars.
34 34
 
35
-        if (strstr($username,'|'))
35
+        if (strstr($username, '|'))
36 36
             throw new InvalidParam('username', "There is no user by this username.");
37 37
         $fields = $request->get_parameter('fields');
38 38
 
Please login to merge, or discard this patch.
Braces   +9 added lines, -5 removed lines patch added patch discarded remove patch
@@ -26,14 +26,17 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
htdocs/okapi/services/users/by_internal_id.php 1 patch
Braces   +6 added lines, -3 removed lines patch added patch discarded remove patch
@@ -23,7 +23,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
htdocs/okapi/services/oauth/authorize.php 1 patch
Braces   +9 added lines, -5 removed lines patch added patch discarded remove patch
@@ -21,13 +21,17 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
htdocs/okapi/services/attrs/attribute.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@
 block discarded – undo
30 30
 
31 31
         $acode = $request->get_parameter('acode');
32 32
         if ($acode === null) throw new ParamMissing('acode');
33
-        if (strstr($acode,'|')) throw new InvalidParam('acode', "Only a single A-code must be supplied.");
33
+        if (strstr($acode, '|')) throw new InvalidParam('acode', "Only a single A-code must be supplied.");
34 34
 
35 35
         $langpref = $request->get_parameter('langpref');
36 36
         if (!$langpref) $langpref = "en";
Please login to merge, or discard this patch.
Braces   +16 added lines, -7 removed lines patch added patch discarded remove patch
@@ -29,17 +29,27 @@  discard block
 block discarded – undo
29 29
         # Read the parameters.
30 30
 
31 31
         $acode = $request->get_parameter('acode');
32
-        if ($acode === null) throw new ParamMissing('acode');
33
-        if (strstr($acode,'|')) throw new InvalidParam('acode', "Only a single A-code must be supplied.");
32
+        if ($acode === null) {
33
+            throw new ParamMissing('acode');
34
+        }
35
+        if (strstr($acode,'|')) {
36
+            throw new InvalidParam('acode', "Only a single A-code must be supplied.");
37
+        }
34 38
 
35 39
         $langpref = $request->get_parameter('langpref');
36
-        if (!$langpref) $langpref = "en";
40
+        if (!$langpref) {
41
+            $langpref = "en";
42
+        }
37 43
 
38 44
         $fields = $request->get_parameter('fields');
39
-        if (!$fields) $fields = "name";
45
+        if (!$fields) {
46
+            $fields = "name";
47
+        }
40 48
 
41 49
         $forward_compatible = $request->get_parameter('forward_compatible');
42
-        if (!$forward_compatible) $forward_compatible = "true";
50
+        if (!$forward_compatible) {
51
+            $forward_compatible = "true";
52
+        }
43 53
 
44 54
         # Pass them all to the attributes method.
45 55
 
@@ -52,8 +62,7 @@  discard block
 block discarded – undo
52 62
         $results = OkapiServiceRunner::call('services/attrs/attributes',
53 63
             new OkapiInternalRequest($request->consumer, $request->token, $params));
54 64
         $result = $results[$acode];
55
-        if ($result === null)
56
-        {
65
+        if ($result === null) {
57 66
             /* Note, this can happen only when $forward_compatible is false. */
58 67
             throw new InvalidParam('acode', "Unknown A-code.");
59 68
         }
Please login to merge, or discard this patch.
htdocs/okapi/facade.php 1 patch
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -78,8 +78,9 @@  discard block
 block discarded – undo
78 78
         );
79 79
         $request->i_want_OkapiResponse = true;
80 80
         $request->perceive_as_http_request = true;
81
-        if (isset($_SERVER['HTTP_IF_NONE_MATCH']))
82
-            $request->etag = $_SERVER['HTTP_IF_NONE_MATCH'];
81
+        if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
82
+                    $request->etag = $_SERVER['HTTP_IF_NONE_MATCH'];
83
+        }
83 84
         $response = OkapiServiceRunner::call($service_name, $request);
84 85
         $response->display();
85 86
     }
@@ -118,8 +119,9 @@  discard block
 block discarded – undo
118 119
      */
119 120
     public static function schedule_geocache_check($cache_codes)
120 121
     {
121
-        if (!is_array($cache_codes))
122
-            $cache_codes = array($cache_codes);
122
+        if (!is_array($cache_codes)) {
123
+                    $cache_codes = array($cache_codes);
124
+        }
123 125
         Db::execute("
124 126
             update caches
125 127
             set okapi_syncbase = now()
Please login to merge, or discard this patch.
htdocs/okapi/lib/oc_session.php 1 patch
Braces   +12 added lines, -8 removed lines patch added patch discarded remove patch
@@ -12,18 +12,22 @@
 block discarded – undo
12 12
     public static function get_user_id()
13 13
     {
14 14
         static $cached_result = false;
15
-        if ($cached_result !== false)
16
-            return $cached_result;
15
+        if ($cached_result !== false) {
16
+                    return $cached_result;
17
+        }
17 18
 
18 19
         $cookie_name = Settings::get('OC_COOKIE_NAME');
19
-        if (!isset($_COOKIE[$cookie_name]))
20
-            return null;
20
+        if (!isset($_COOKIE[$cookie_name])) {
21
+                    return null;
22
+        }
21 23
         $OC_data = unserialize(base64_decode($_COOKIE[$cookie_name]));
22
-        if (!isset($OC_data['sessionid']))
23
-            return null;
24
+        if (!isset($OC_data['sessionid'])) {
25
+                    return null;
26
+        }
24 27
         $OC_sessionid = $OC_data['sessionid'];
25
-        if (!$OC_sessionid)
26
-            return null;
28
+        if (!$OC_sessionid) {
29
+                    return null;
30
+        }
27 31
 
28 32
         return Db::select_value("select user_id from sys_sessions where uuid='".Db::escape_string($OC_sessionid)."'");
29 33
     }
Please login to merge, or discard this patch.
htdocs/okapi/views/changelog_helper.inc.php 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@
 block discarded – undo
34 34
                 );
35 35
                 $context = stream_context_create($opts);
36 36
                 $changes_xml = file_get_contents(
37
-                     # TODO: load from OKAPI repo
37
+                        # TODO: load from OKAPI repo
38 38
                     'https://raw.githubusercontent.com/opencaching/okapi/master/etc/changes.xml',
39 39
                     false, $context
40 40
                 );
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
                     throw new ErrorException();
44 44
                 }
45 45
                 Cache::set($cache_key, $changes_xml, 3600);
46
-                Cache::set($cache_backup_key, $changes_xml, 3600*24*30);
46
+                Cache::set($cache_backup_key, $changes_xml, 3600 * 24 * 30);
47 47
             }
48 48
             catch (Exception $e)
49 49
             {
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 
52 52
                 $changes_xml = Cache::get($cache_backup_key);
53 53
                 if ($changes_xml) {
54
-                    Cache::set($cache_key, $changes_xml, 3600*12);
54
+                    Cache::set($cache_key, $changes_xml, 3600 * 12);
55 55
                 }
56 56
             }
57 57
         }
Please login to merge, or discard this patch.
Braces   +5 added lines, -12 removed lines patch added patch discarded remove patch
@@ -20,12 +20,10 @@  discard block
 block discarded – undo
20 20
         $changes_xml = Cache::get($cache_key);
21 21
         $changelog = null;
22 22
 
23
-        if (!$changes_xml)
24
-        {
23
+        if (!$changes_xml) {
25 24
             # Download the current changelog.
26 25
 
27
-            try
28
-            {
26
+            try {
29 27
                 $opts = array(
30 28
                     'http' => array(
31 29
                         'method' => "GET",
@@ -44,9 +42,7 @@  discard block
 block discarded – undo
44 42
                 }
45 43
                 Cache::set($cache_key, $changes_xml, 3600);
46 44
                 Cache::set($cache_backup_key, $changes_xml, 3600*24*30);
47
-            }
48
-            catch (Exception $e)
49
-            {
45
+            } catch (Exception $e) {
50 46
                 # GitHub failed on us. User backup list, if available.
51 47
 
52 48
                 $changes_xml = Cache::get($cache_backup_key);
@@ -64,14 +60,11 @@  discard block
 block discarded – undo
64 60
         $this->unavailable_changes = array();
65 61
         $this->available_changes = array();
66 62
 
67
-        if (!$changelog)
68
-        {
63
+        if (!$changelog) {
69 64
             # We could not retreive the changelog from Github, and there was
70 65
             # no backup key or it expired. Probably we are on a developer
71 66
             # machine. The template will output some error message.
72
-        }
73
-        else
74
-        {
67
+        } else {
75 68
             $commits = array();
76 69
             $versions = array();
77 70
 
Please login to merge, or discard this patch.
htdocs/okapi/views/method_call.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -20,9 +20,10 @@
 block discarded – undo
20 20
     {
21 21
         require_once($GLOBALS['rootpath'].'okapi/service_runner.php');
22 22
 
23
-        if (!OkapiServiceRunner::exists($methodname))
24
-            throw new BadRequest("Method '$methodname' does not exist. ".
23
+        if (!OkapiServiceRunner::exists($methodname)) {
24
+                    throw new BadRequest("Method '$methodname' does not exist. ".
25 25
                 "See OKAPI docs at ".Settings::get('SITE_URL')."okapi/");
26
+        }
26 27
         $options = OkapiServiceRunner::options($methodname);
27 28
         $request = new OkapiHttpRequest($options);
28 29
         return OkapiServiceRunner::call($methodname, $request);
Please login to merge, or discard this patch.