瀏覽代碼

Merge pull request #10 from martymcguire/h-food-json

Send JSON-encoded posts instead of form-encoded.
pull/17/head
Aaron Parecki 4 年之前
committed by GitHub
父節點
當前提交
fc38fa0f49
沒有發現已知的金鑰在資料庫的簽署中 GPG Key ID: 4AEE18F83AFDEB23
共有 2 個文件被更改,包括 23 次插入23 次删除
  1. +19
    -18
      controllers/controllers.php
  2. +4
    -5
      lib/helpers.php

+ 19
- 18
controllers/controllers.php 查看文件

@ -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 查看文件

@ -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…
取消
儲存