Browse Source

Send JSON-encoded posts instead of form-encoded.

Micropub form-encoded requests can't have nested objects like ate[type]=[h-food]
pull/10/head
Marty McGuire 1 year ago
parent
commit
060c5ca323
2 changed files with 23 additions and 23 deletions
  1. 19
    18
      controllers/controllers.php
  2. 4
    5
      lib/helpers.php

+ 19
- 18
controllers/controllers.php View File

@@ -249,28 +249,29 @@ $app->post('/post', function() use($app) {
if($user->micropub_endpoint) {
$text_content = 'Just ' . $verb . ': ' . $entry->content;

$mp_request = array(
'h' => 'entry',
'published' => $published,
'created' => $published,
'location' => k($params, 'location'),
'summary' => $text_content
$mp_properties = array(
'published' => [$published],
'created' => [$published],
'summary' => [$text_content]
);
if($entry->photo_url) {
$mp_request['photo'] = $entry->photo_url;
$location = k($params, 'location');
if($location) {
$mp_properties['location'] = [$location];
}
if($user->enable_array_micropub) {
$mp_request[$verb] = [
'type' => 'h-food',
'properties' => [
'name' => $entry->content
]
];
} else {
$mp_request['p3k-food'] = $entry->content;
$mp_request['p3k-type'] = $type;
if($entry->photo_url) {
$mp_properties['photo'] = [$entry->photo_url];
}
$mp_properties[$verb] = [[
'type' => ['h-food'],
'properties' => [
'name' => $entry->content
]
]];

$mp_request = array(
'type' => ['h-entry'],
'properties' => $mp_properties
);
$r = micropub_post($user->micropub_endpoint, $mp_request, $user->access_token);
$request = $r['request'];
$response = $r['response'];

+ 4
- 5
lib/helpers.php View File

@@ -100,13 +100,12 @@ function micropub_post($endpoint, $params, $access_token) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer ' . $access_token
'Authorization: Bearer ' . $access_token,
'Content-Type: application/json',
'Accept: application/json'
));
curl_setopt($ch, CURLOPT_POST, true);
$post = http_build_query(array_merge(array(
'access_token' => $access_token,
'h' => 'entry'
), $params));
$post = json_encode($params);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);

Loading…
Cancel
Save