diff options
author | Jeena <spam@jeenaparadies.net> | 2015-07-23 00:32:01 +0200 |
---|---|---|
committer | Jeena <spam@jeenaparadies.net> | 2015-07-24 20:57:54 +0200 |
commit | 85e80df0ba127936f9ba646ba00e25b37ddc2ec4 (patch) | |
tree | 3438827e96ff8b32cffeec79073a8c72c9f062e9 /controllers/controllers.php | |
parent | 91307d4a362a8fab0022aba19ab74bec9cb46f8f (diff) |
Adds possibility to post photos.
With this it is possible to post a photo note with a description, nothing
more. It doesn't move the file in the file system, just posts it from
the temp location to the users server. It also does validate for file size,
content type and max upload size and shows the errors to the user.
If everything goes according to plan the response from the users server
is shown, together with a link with the posted photos URL.
Diffstat (limited to 'controllers/controllers.php')
-rw-r--r-- | controllers/controllers.php | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/controllers/controllers.php b/controllers/controllers.php index b444676..337f780 100644 --- a/controllers/controllers.php +++ b/controllers/controllers.php @@ -127,6 +127,19 @@ $app->get('/favorite', function() use($app) { } }); +$app->get('/photo', function() use($app) { + if($user=require_login($app)) { + $params = $app->request()->params(); + + $html = render('photo', array( + 'title' => 'New Photo', + 'note_content' => '', + 'authorizing' => false + )); + $app->response()->body($html); + } +}); + $app->get('/repost', function() use($app) { if($user=require_login($app)) { $params = $app->request()->params(); @@ -282,6 +295,20 @@ 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 @@ -336,6 +363,40 @@ $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(); |