]> git.mxchange.org Git - friendica.git/blobdiff - src/Security/OAuth1/OAuthUtil.php
Merge pull request #12928 from jsoref/spelling
[friendica.git] / src / Security / OAuth1 / OAuthUtil.php
index 7f6fbadffe270a65291a036bc2b34fda27439255..06847eceb3002b76d387ad1c02de69187ac0989b 100644 (file)
@@ -1,4 +1,23 @@
 <?php
+/**
+ * @copyright Copyright (C) 2010-2023, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
 
 namespace Friendica\Security\OAuth1;
 
@@ -116,7 +135,7 @@ class OAuthUtil
                        $value     = isset($split[1]) ? OAuthUtil::urldecode_rfc3986($split[1]) : '';
 
                        if (isset($parsed_parameters[$parameter])) {
-                               // We have already recieved parameter(s) with this name, so add to the list
+                               // We have already received parameter(s) with this name, so add to the list
                                // of parameters with this name
 
                                if (is_scalar($parsed_parameters[$parameter])) {
@@ -135,32 +154,9 @@ class OAuthUtil
 
        public static function build_http_query($params)
        {
-               if (!$params) return '';
-
-               // Urlencode both keys and values
-               $keys   = OAuthUtil::urlencode_rfc3986(array_keys($params));
-               $values = OAuthUtil::urlencode_rfc3986(array_values($params));
-               $params = array_combine($keys, $values);
-
                // Parameters are sorted by name, using lexicographical byte value ordering.
                // Ref: Spec: 9.1.1 (1)
                uksort($params, 'strcmp');
-
-               $pairs = [];
-               foreach ($params as $parameter => $value) {
-                       if (is_array($value)) {
-                               // If two or more parameters share the same name, they are sorted by their value
-                               // Ref: Spec: 9.1.1 (1)
-                               natsort($value);
-                               foreach ($value as $duplicate_value) {
-                                       $pairs[] = $parameter . '=' . $duplicate_value;
-                               }
-                       } else {
-                               $pairs[] = $parameter . '=' . $value;
-                       }
-               }
-               // For each parameter, the name is separated from the corresponding value by an '=' character (ASCII code 61)
-               // Each name-value pair is separated by an '&' character (ASCII code 38)
-               return implode('&', $pairs);
+               return http_build_query($params, '', null, PHP_QUERY_RFC3986);
        }
 }