Browse Source

Merge branch 'master' of github.com:aaronpk/Quill

pull/96/head
Aaron Parecki 7 years ago
parent
commit
ecb0724049
No known key found for this signature in database GPG Key ID: 276C2817346D6056
  1. 2
      composer.json
  2. 2
      controllers/micropub.php
  3. 16
      lib/helpers.php

2
composer.json

@ -11,7 +11,7 @@
"abraham/twitteroauth": "*",
"andreyco/instagram": "3.*",
"ezyang/htmlpurifier": "4.*",
"p3k/multipart": "*",
"p3k/multipart": ">=0.2.0",
"tantek/cassis": "*",
"p3k/timezone": "*",
"gajus/dindent": "^2.0"

2
controllers/micropub.php

@ -52,7 +52,7 @@ $app->post('/micropub/multipart', function() use($app) {
if(!$error) {
$file_path = $file['tmp_name'];
correct_photo_rotation($file_path);
$r = micropub_post_for_user($user, $_POST, $file_path);
$r = micropub_post_for_user($user, $_POST, $file);
} else {
$r = array('error' => $error);
}

16
lib/helpers.php

@ -83,9 +83,9 @@ if(!function_exists('http_build_url')) {
}
}
function micropub_post_for_user(&$user, $params, $file_path = NULL, $json = false) {
function micropub_post_for_user(&$user, $params, $file = NULL, $json = false) {
// Now send to the micropub endpoint
$r = micropub_post($user->micropub_endpoint, $params, $user->micropub_access_token, $file_path, $json);
$r = micropub_post($user->micropub_endpoint, $params, $user->micropub_access_token, $file, $json);
$user->last_micropub_response = substr(json_encode($r), 0, 1024);
$user->last_micropub_response_date = date('Y-m-d H:i:s');
@ -104,9 +104,9 @@ function micropub_post_for_user(&$user, $params, $file_path = NULL, $json = fals
return $r;
}
function micropub_media_post_for_user(&$user, $file_path) {
function micropub_media_post_for_user(&$user, $file) {
// Send to the media endpoint
$r = micropub_post($user->micropub_media_endpoint, [], $user->micropub_access_token, $file_path, true, 'file');
$r = micropub_post($user->micropub_media_endpoint, [], $user->micropub_access_token, $file, true, 'file');
// Check the response and look for a "Location" header containing the URL
if($r['response'] && preg_match('/Location: (.+)/', $r['response'], $match)) {
@ -118,11 +118,15 @@ function micropub_media_post_for_user(&$user, $file_path) {
return $r;
}
function micropub_post($endpoint, $params, $access_token, $file_path = NULL, $json = false, $file_prop = 'photo') {
function micropub_post($endpoint, $params, $access_token, $file = NULL, $json = false, $file_prop = 'photo') {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_POST, true);
$file_path = $file['tmp_name'];
$file_content = file_get_contents($file_path) . self::EOL;
$filename = $file['name'];
// Send the access token in both the header and post body to support more clients
// https://github.com/aaronpk/Quill/issues/4
// http://indiewebcamp.com/irc/2015-02-14#t1423955287064
@ -150,7 +154,7 @@ function micropub_post($endpoint, $params, $access_token, $file_path = NULL, $js
$mimetype = finfo_file($finfo, $file_path);
$multipart = new p3k\Multipart();
$multipart->addArray($params);
$multipart->addFile($file_prop, $file_path, $mimetype);
$multipart->addFile($file_prop, $filename, $mimetype, $file_content);
$post = $multipart->data();
$httpheaders[] = 'Content-Type: ' . $multipart->contentType();
}

Loading…
Cancel
Save