4 * Copyright (C) 2011, Free Software Foundation, Inc.
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 * @author Ian Denhardt <ian@zenhack.net>
24 * @copyright 2011 Free Software Foundation, Inc.
25 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28 if(!defined('STATUSNET')){
32 class NewphotoAction extends Action
36 function prepare($args)
38 parent::prepare($args);
39 $this->user = common_current_user();
41 if(empty($this->user)){
42 throw new ClientException(_('Must be logged in to post a photo'),
47 $this->checkSessionToken();
53 function handle($args)
55 parent::handle($args);
57 if ($this->isPost()) {
58 $this->handlePost($args);
64 function handlePost($args)
68 // Workaround for PHP returning empty $_POST and $_FILES when POST
69 // length > post_max_size in php.ini
72 && ($_SERVER['CONTENT_LENGTH'] > 0)
74 $msg = _('The server was unable to handle that much POST ' .
75 'data (%s bytes) due to its current configuration.');
76 $this->showForm(sprintf($msg, $_SERVER['CONTENT_LENGTH']));
80 $profile = $this->user->getProfile();
84 ToSelector::fillOptions($this, $options);
87 $this->handleUpload();
88 } catch (Exception $e) {
89 $this->showForm($e->getMessage());
94 common_redirect($photo->uri, 303);
99 $imagefile = ImageFile::fromUpload('photo_upload');
101 if($imagefile === null) {
102 throw new Exception(_('No file uploaded'));
105 $title = $this->trimmed('title');
106 $description = $this->trimmed('description');
108 $new_filename = UUID::gen() . image_type_to_extension($imagefile->type);
109 move_uploaded_file($imagefile->filepath, INSTALLDIR . '/file/' . $new_filename);
111 // XXX: we should be using https where we can. TODO: detect whether the server
113 $photo_uri = 'http://' . common_config('site', 'server') . '/file/'
115 $thumb_uri = $photo_uri;
118 $photo = Photo::saveNew($profile, $photo_uri, $thumb_uri, $title,
119 $description, $options);
123 function showContent()
125 $form = new NewPhotoForm();