From 526ba056a9014308a315491b2e2f27f00d0733cf Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Tue, 28 Jul 2015 17:43:50 -0700 Subject: [PATCH] support micropub endpoints with query strings --- lib/helpers.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/helpers.php b/lib/helpers.php index dd11448..8542215 100644 --- a/lib/helpers.php +++ b/lib/helpers.php @@ -81,6 +81,20 @@ function get_timezone($lat, $lng) { return null; } +if(!function_exists('http_build_url')) { + function http_build_url($parsed_url) { + $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : ''; + $host = isset($parsed_url['host']) ? $parsed_url['host'] : ''; + $port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : ''; + $user = isset($parsed_url['user']) ? $parsed_url['user'] : ''; + $pass = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : ''; + $pass = ($user || $pass) ? "$pass@" : ''; + $path = isset($parsed_url['path']) ? $parsed_url['path'] : ''; + $query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : ''; + $fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : ''; + return "$scheme$user$pass$host$port$path$query$fragment"; + } +} function micropub_post($endpoint, $params, $access_token) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $endpoint); @@ -109,8 +123,16 @@ function micropub_post($endpoint, $params, $access_token) { } function micropub_get($endpoint, $params, $access_token) { + $url = parse_url($endpoint); + if(!k($url, 'query')) { + $url['query'] = http_build_query($params); + } else { + $url['query'] .= '&' . http_build_query($params); + } + $endpoint = http_build_url($url); + $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $endpoint . '?' . http_build_query($params)); + curl_setopt($ch, CURLOPT_URL, $endpoint); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Authorization: Bearer ' . $access_token ));