4 * Copyright (C) 2010, 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/>.
24 * @author Ian Denhardt <ian@zenhack.net>
25 * @copyright 2010 Free Software Foundation, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
29 if (!defined('STATUSNET')) {
33 class PhotouploadAction extends Action
37 function prepare($args)
39 parent::prepare($args);
40 $this->user = common_current_user();
44 function handle($args)
46 parent::handle($args);
47 if($_SERVER['REQUEST_METHOD'] == 'POST') {
55 return _m('Upload Photos');
58 function showContent()
60 if(empty($this->user)) {
61 $this->element('p', array(), 'You are not logged in.');
63 $this->elementStart('form', array('enctype' => 'mutlipart/form-data',
65 'action' => common_local_url('photoupload')));
66 $this->element('input', array('name' => 'photofile',
68 'id' => 'photofile'));
69 $this->submit('upload', _('Upload'));
70 $this->elementEnd('form');
77 common_log(LOG_INFO, 'handlPost()!');
78 // Workaround for PHP returning empty $_POST and $_FILES when POST
79 // length > post_max_size in php.ini
83 && ($_SERVER['CONTENT_LENGTH'] > 0)
85 $msg = _('The server was unable to handle that much POST ' .
86 'data (%s bytes) due to its current configuration.');
88 $this->showForm(sprintf($msg, $_SERVER['CONTENT_LENGTH']));
94 /* $token = $this->trimmed('token');
95 if (!$token || $token != common_session_token()) {
96 $this->showForm(_('There was a problem with your session token. '.
97 'Try again, please.'));
101 if($this->arg('upload')) {
102 $this->uploadPhoto();
106 function uploadPhoto()
108 common_log(LOG_INFO, 'Is this function even getting called?');
109 $cur = common_current_user();
114 $imagefile = ImageFile::fromUpload('photofile');
115 } catch (Exception $e) {
116 $this->showForm($e->getMessage());
119 if ($imagefile === null) {
120 $this->showForm(_('No file uploaded.'));
124 common_log(LOG_INFO, 'upload path : ' . $imagefile->filepath);
126 $filename = $cur->nickname . '-' . common_timestamp() . sha1_file($imagefile->filepath) . '.' . image_type_to_extension($imagefile->type);
127 move_uploaded_file($imagefile->filepath, INSTALLDIR . '/file/' . $filename);
128 photo_make_thumbnail($filename);
129 $photo = new GNUsocialPhoto();
130 $photo->path = '/file/' . $filename;
131 $photo->thumb_path = '/file/thumb.' . $filename;