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 * @author Sean Corbett <sean@gnu.org>
26 * @author Max Shinn <trombonechamp@gmail.com>
27 * @copyright 2010 Free Software Foundation, Inc.
28 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
31 if (!defined('STATUSNET')) {
35 class EditphotoAction extends Action
39 function prepare($args)
41 parent::prepare($args);
42 $args = $this->returnToArgs();
43 $this->user = common_current_user();
44 $this->photoid = $args[1]['photoid'];
45 $this->photo = GNUsocialPhoto::staticGet('id', $this->photoid);
49 function handle($args)
51 parent::handle($args);
52 if($_SERVER['REQUEST_METHOD'] == 'POST') {
60 if ($this->photo->title)
61 return _m('Edit photo - ' . $this->photo->title);
63 return _m('Edit photo');
66 function showContent()
69 if ($this->photo->album_id == 0) {
70 $this->element('p', array(), _('This photo does not exist or was deleted.'));
74 if ($this->user->profile_id != $this->photo->profile_id) {
75 $this->element('p', array(), _('You are not authorized to edit this photo.'));
79 $this->element('img', array('src' => $this->photo->uri));
80 $this->elementStart('form', array('method' => 'post',
81 'action' => '/editphoto/' . $this->photo->id));
82 $this->elementStart('ul', 'form_data');
83 $this->elementStart('li');
84 $this->input('phototitle', _("Title"), $this->photo->title, _("The title of the photo. (Optional)"));
85 $this->elementEnd('li');
86 $this->elementStart('li');
87 $this->textarea('photo_description', _("Description"), $this->photo->photo_description, _("A description of the photo. (Optional)"));
88 $this->elementEnd('li');
89 $this->elementStart('li');
90 $this->dropdown('album', _("Album"), $this->albumList(), _("The album in which to place this photo"), false, $this->photo->album_id);
91 $this->elementEnd('li');
92 $this->elementEnd('ul');
93 $this->submit('update', _('Update'));
94 $this->elementEnd('form');
96 $this->elementStart('form', array('method' => 'post',
97 'action' => '/editphoto/' . $this->photo->id));
98 $this->element('input', array('type' => 'submit',
100 'value' => _('Delete Photo'),
103 'onclick' => 'return confirm(\'Are you sure you would like to delete this photo?\')'));
104 $this->elementEnd('form');
108 function handlePost()
111 common_log(LOG_INFO, 'handlPost()!');
113 if ($this->photo->album_id == 0) {
114 $this->element('p', array(), _('This photo does not exist or was deleted.'));
118 if ($this->user->profile_id != $this->photo->profile_id) {
119 $this->element('p', array(), _('You are not authorized to edit this photo.'));
123 if ($this->arg('update')) {
124 $this->updatePhoto();
126 if ($this->arg('delete')) {
127 $this->deletePhoto();
131 function showForm($msg, $success=false)
134 $this->success = $success;
136 // $this->showPage();
141 $cur = common_current_user();
142 $album = new GNUsocialPhotoAlbum();
143 $album->user_id = $cur->id;
145 $albumlist = array();
146 if (!$album->find()) {
147 GNUsocialPhotoAlbum::newAlbum($cur->id, 'Default');
149 while ($album->fetch()) {
150 $albumlist[$album->album_id] = $album->album_name;
155 function updatePhoto()
157 $cur = common_current_user();
158 $this->photo->title = $this->trimmed('phototitle');
159 $this->photo->photo_description = $this->trimmed('photo_description');
161 $profile_id = $cur->id;
163 $album = GNUsocialPhotoAlbum::staticGet('album_id', $this->trimmed('album'));
164 if ($album->profile_id != $profile_id) {
165 $this->showForm(_('Error: This is not your album!'));
168 $this->photo->album_id = $album->album_id;
169 if ($this->photo->validate())
170 $this->photo->update();
172 $this->showForm(_('Error: The photo data is not valid.'));
175 $this->showForm(_('Success!'));
179 function deletePhoto()
181 $this->photo->title = "";
182 $this->photo->photo_description = "";
183 $this->photo->profile_id = 0;
184 $this->photo->album_id = 0;
185 $this->photo->uri = "";
186 $this->photo->thumb_uri = "";
188 if ($this->photo->validate())
189 $this->photo->update();
191 $this->showForm(_('Error: The photo data is not valid.'));
194 $this->showForm(_('Success!'));