Browse Source

support micropub endpoints with query strings

pull/10/head
Aaron Parecki 9 years ago
parent
commit
526ba056a9
1 changed files with 23 additions and 1 deletions
  1. +23
    -1
      lib/helpers.php

+ 23
- 1
lib/helpers.php View File

@ -81,6 +81,20 @@ function get_timezone($lat, $lng) {
return null; 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) { function micropub_post($endpoint, $params, $access_token) {
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endpoint); curl_setopt($ch, CURLOPT_URL, $endpoint);
@ -109,8 +123,16 @@ function micropub_post($endpoint, $params, $access_token) {
} }
function micropub_get($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(); $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( curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer ' . $access_token 'Authorization: Bearer ' . $access_token
)); ));

Loading…
Cancel
Save