Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/updraftp.../vendor/eher/oauth/src/Eher/OAuth
File: Util.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Eher\OAuth;
[2] Fix | Delete
[3] Fix | Delete
class Util {
[4] Fix | Delete
public static function urlencode_rfc3986($input) {
[5] Fix | Delete
if (is_array($input)) {
[6] Fix | Delete
return array_map(array('Eher\OAuth\Util', 'urlencode_rfc3986'), $input);
[7] Fix | Delete
} else if (is_scalar($input)) {
[8] Fix | Delete
return str_replace(
[9] Fix | Delete
'+',
[10] Fix | Delete
' ',
[11] Fix | Delete
str_replace('%7E', '~', rawurlencode($input))
[12] Fix | Delete
);
[13] Fix | Delete
} else {
[14] Fix | Delete
return '';
[15] Fix | Delete
}
[16] Fix | Delete
}
[17] Fix | Delete
[18] Fix | Delete
[19] Fix | Delete
// This decode function isn't taking into consideration the above
[20] Fix | Delete
// modifications to the encoding process. However, this method doesn't
[21] Fix | Delete
// seem to be used anywhere so leaving it as is.
[22] Fix | Delete
public static function urldecode_rfc3986($string) {
[23] Fix | Delete
return urldecode($string);
[24] Fix | Delete
}
[25] Fix | Delete
[26] Fix | Delete
// Utility function for turning the Authorization: header into
[27] Fix | Delete
// parameters, has to do some unescaping
[28] Fix | Delete
// Can filter out any non-oauth parameters if needed (default behaviour)
[29] Fix | Delete
// May 28th, 2010 - method updated to tjerk.meesters for a speed improvement.
[30] Fix | Delete
// see http://code.google.com/p/oauth/issues/detail?id=163
[31] Fix | Delete
public static function split_header($header, $only_allow_oauth_parameters = true) {
[32] Fix | Delete
$params = array();
[33] Fix | Delete
if (preg_match_all('/('.($only_allow_oauth_parameters ? 'oauth_' : '').'[a-z_-]*)=(:?"([^"]*)"|([^,]*))/', $header, $matches)) {
[34] Fix | Delete
foreach ($matches[1] as $i => $h) {
[35] Fix | Delete
$params[$h] = Util::urldecode_rfc3986(empty($matches[3][$i]) ? $matches[4][$i] : $matches[3][$i]);
[36] Fix | Delete
}
[37] Fix | Delete
if (isset($params['realm'])) {
[38] Fix | Delete
unset($params['realm']);
[39] Fix | Delete
}
[40] Fix | Delete
}
[41] Fix | Delete
return $params;
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
// helper to try to sort out headers for people who aren't running apache
[45] Fix | Delete
public static function get_headers() {
[46] Fix | Delete
if (function_exists('apache_request_headers')) {
[47] Fix | Delete
// we need this to get the actual Authorization: header
[48] Fix | Delete
// because apache tends to tell us it doesn't exist
[49] Fix | Delete
$headers = apache_request_headers();
[50] Fix | Delete
[51] Fix | Delete
// sanitize the output of apache_request_headers because
[52] Fix | Delete
// we always want the keys to be Cased-Like-This and arh()
[53] Fix | Delete
// returns the headers in the same case as they are in the
[54] Fix | Delete
// request
[55] Fix | Delete
$out = array();
[56] Fix | Delete
foreach ($headers AS $key => $value) {
[57] Fix | Delete
$key = str_replace(
[58] Fix | Delete
" ",
[59] Fix | Delete
"-",
[60] Fix | Delete
ucwords(strtolower(str_replace("-", " ", $key)))
[61] Fix | Delete
);
[62] Fix | Delete
$out[$key] = $value;
[63] Fix | Delete
}
[64] Fix | Delete
} else {
[65] Fix | Delete
// otherwise we don't have apache and are just going to have to hope
[66] Fix | Delete
// that $_SERVER actually contains what we need
[67] Fix | Delete
$out = array();
[68] Fix | Delete
if( isset($_SERVER['CONTENT_TYPE']) )
[69] Fix | Delete
$out['Content-Type'] = $_SERVER['CONTENT_TYPE'];
[70] Fix | Delete
if( isset($_ENV['CONTENT_TYPE']) )
[71] Fix | Delete
$out['Content-Type'] = $_ENV['CONTENT_TYPE'];
[72] Fix | Delete
[73] Fix | Delete
foreach ($_SERVER as $key => $value) {
[74] Fix | Delete
if (substr($key, 0, 5) == "HTTP_") {
[75] Fix | Delete
// this is chaos, basically it is just there to capitalize the first
[76] Fix | Delete
// letter of every word that is not an initial HTTP and strip HTTP
[77] Fix | Delete
// code from przemek
[78] Fix | Delete
$key = str_replace(
[79] Fix | Delete
" ",
[80] Fix | Delete
"-",
[81] Fix | Delete
ucwords(strtolower(str_replace("_", " ", substr($key, 5))))
[82] Fix | Delete
);
[83] Fix | Delete
$out[$key] = $value;
[84] Fix | Delete
}
[85] Fix | Delete
}
[86] Fix | Delete
}
[87] Fix | Delete
return $out;
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
// This function takes a input like a=b&a=c&d=e and returns the parsed
[91] Fix | Delete
// parameters like this
[92] Fix | Delete
// array('a' => array('b','c'), 'd' => 'e')
[93] Fix | Delete
public static function parse_parameters( $input ) {
[94] Fix | Delete
if (!isset($input) || !$input) return array();
[95] Fix | Delete
[96] Fix | Delete
$pairs = explode('&', $input);
[97] Fix | Delete
[98] Fix | Delete
$parsed_parameters = array();
[99] Fix | Delete
foreach ($pairs as $pair) {
[100] Fix | Delete
$split = explode('=', $pair, 2);
[101] Fix | Delete
$parameter = Util::urldecode_rfc3986($split[0]);
[102] Fix | Delete
$value = isset($split[1]) ? Util::urldecode_rfc3986($split[1]) : '';
[103] Fix | Delete
[104] Fix | Delete
if (isset($parsed_parameters[$parameter])) {
[105] Fix | Delete
// We have already recieved parameter(s) with this name, so add to the list
[106] Fix | Delete
// of parameters with this name
[107] Fix | Delete
[108] Fix | Delete
if (is_scalar($parsed_parameters[$parameter])) {
[109] Fix | Delete
// This is the first duplicate, so transform scalar (string) into an array
[110] Fix | Delete
// so we can add the duplicates
[111] Fix | Delete
$parsed_parameters[$parameter] = array($parsed_parameters[$parameter]);
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
$parsed_parameters[$parameter][] = $value;
[115] Fix | Delete
} else {
[116] Fix | Delete
$parsed_parameters[$parameter] = $value;
[117] Fix | Delete
}
[118] Fix | Delete
}
[119] Fix | Delete
return $parsed_parameters;
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
public static function build_http_query($params) {
[123] Fix | Delete
if (!$params) return '';
[124] Fix | Delete
[125] Fix | Delete
// Urlencode both keys and values
[126] Fix | Delete
$keys = Util::urlencode_rfc3986(array_keys($params));
[127] Fix | Delete
$values = Util::urlencode_rfc3986(array_values($params));
[128] Fix | Delete
$params = array_combine($keys, $values);
[129] Fix | Delete
[130] Fix | Delete
// Parameters are sorted by name, using lexicographical byte value ordering.
[131] Fix | Delete
// Ref: Spec: 9.1.1 (1)
[132] Fix | Delete
uksort($params, 'strcmp');
[133] Fix | Delete
[134] Fix | Delete
$pairs = array();
[135] Fix | Delete
foreach ($params as $parameter => $value) {
[136] Fix | Delete
if (is_array($value)) {
[137] Fix | Delete
// If two or more parameters share the same name, they are sorted by their value
[138] Fix | Delete
// Ref: Spec: 9.1.1 (1)
[139] Fix | Delete
// June 12th, 2010 - changed to sort because of issue 164 by hidetaka
[140] Fix | Delete
sort($value, SORT_STRING);
[141] Fix | Delete
foreach ($value as $duplicate_value) {
[142] Fix | Delete
$pairs[] = $parameter . '=' . $duplicate_value;
[143] Fix | Delete
}
[144] Fix | Delete
} else {
[145] Fix | Delete
$pairs[] = $parameter . '=' . $value;
[146] Fix | Delete
}
[147] Fix | Delete
}
[148] Fix | Delete
// For each parameter, the name is separated from the corresponding value by an '=' character (ASCII code 61)
[149] Fix | Delete
// Each name-value pair is separated by an '&' character (ASCII code 38)
[150] Fix | Delete
return implode('&', $pairs);
[151] Fix | Delete
}
[152] Fix | Delete
}
[153] Fix | Delete
[154] Fix | Delete
[155] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function