diff options
author | Aaron Parecki <aaron@parecki.com> | 2016-04-07 15:57:42 -0700 |
---|---|---|
committer | Aaron Parecki <aaron@parecki.com> | 2016-04-07 15:57:42 -0700 |
commit | 9e817943acfb4c8a8b5824cd7a87a21a654a7fb1 (patch) | |
tree | dc16ffe24f3174d2a78ae46fdc26b889c2e5d9f5 /controllers/controllers.php | |
parent | 1e1039846dc202931bfa822bd52d7cdf451b2d22 (diff) |
integrates photo uploading in the main note interface
Quill corrects the photo rotation based on exif data since iOS tends to take landscape photos and set the rotation bit when holding it in portrait mode.
Diffstat (limited to 'controllers/controllers.php')
-rw-r--r-- | controllers/controllers.php | 89 |
1 files changed, 41 insertions, 48 deletions
diff --git a/controllers/controllers.php b/controllers/controllers.php index 95d3aa5..b27c73e 100644 --- a/controllers/controllers.php +++ b/controllers/controllers.php @@ -384,20 +384,6 @@ function create_favorite(&$user, $url) { return $r; } -function create_photo(&$user, $params, $file) { - $error = validate_photo($file); - - if(!$error) { - $file_path = $file['tmp_name']; - $micropub_request = array('content' => $params['note_content']); - $r = micropub_post_for_user($user, $micropub_request, $file_path); - } else { - $r = array('error' => $error); - } - - return $r; -} - function create_repost(&$user, $url) { $micropub_request = array( 'repost-of' => $url @@ -452,40 +438,6 @@ $app->post('/favorite', function() use($app) { } }); -$app->post('/photo', function() use($app) { - if($user=require_login($app)) { - - // var_dump($app->request()->post()); - // - // Since $app->request()->post() with multipart is always - // empty (bug in Slim?) We're using the raw $_POST here - // until this gets fixed. - // PHP empties everything in $_POST if the file upload size exceeds - // that is why we have to test if the variables exist first. - - $note_content = isset($_POST['note_content']) ? $_POST['note_content'] : null; - $params = array('note_content' => $note_content); - $file = isset($_FILES['note_photo']) ? $_FILES['note_photo'] : null; - - $r = create_photo($user, $params, $file); - - // Populate the error if there was no location header. - if(empty($r['location']) && empty($r['error'])) { - $r['error'] = "No 'Location' header in response."; - } - - $html = render('photo', array( - 'title' => 'Photo posted', - 'note_content' => $params['note_content'], - 'location' => (isset($r['location']) ? $r['location'] : null), - 'error' => (isset($r['error']) ? $r['error'] : null), - 'response' => (isset($r['response']) ? htmlspecialchars($r['response']) : null), - 'authorizing' => false - )); - $app->response()->body($html); - } -}); - $app->post('/repost', function() use($app) { if($user=require_login($app)) { $params = $app->request()->params(); @@ -530,6 +482,47 @@ $app->post('/micropub/post', function() use($app) { } }); +$app->post('/micropub/multipart', function() use($app) { + if($user=require_login($app)) { + // var_dump($app->request()->post()); + // + // Since $app->request()->post() with multipart is always + // empty (bug in Slim?) We're using the raw $_POST here. + // PHP empties everything in $_POST if the file upload size exceeds + // that is why we have to test if the variables exist first. + + $file = isset($_FILES['photo']) ? $_FILES['photo'] : null; + + if($file) { + $error = validate_photo($file); + + unset($_POST['null']); + + if(!$error) { + $file_path = $file['tmp_name']; + correct_photo_rotation($file_path); + $r = micropub_post_for_user($user, $_POST, $file_path); + } else { + $r = array('error' => $error); + } + } else { + unset($_POST['null']); + $r = micropub_post_for_user($user, $_POST); + } + + // Populate the error if there was no location header. + if(empty($r['location']) && empty($r['error'])) { + $r['error'] = "No 'Location' header in response."; + } + + $app->response()->body(json_encode(array( + 'response' => (isset($r['response']) ? htmlspecialchars($r['response']) : null), + 'location' => (isset($r['location']) ? $r['location'] : null), + 'error' => (isset($r['error']) ? $r['error'] : null), + ))); + } +}); + $app->post('/micropub/postjson', function() use($app) { if($user=require_login($app)) { $params = $app->request()->params(); |