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(array $args=array())
41 parent::prepare($args);
42 $args = $this->returnToArgs();
43 $this->user = common_current_user();
44 $this->photoid = $args[1]['photoid'];
45 $this->photo = GNUsocialPhoto::getKV('id', $this->photoid);
49 function handle(array $args=array())
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.'));
80 if(!empty($this->msg)) {
81 $class = ($this->success) ? 'success' : 'error';
82 $this->element('p', array('class' => $class), $this->msg);
85 $this->element('img', array('src' => $this->photo->uri));
86 $this->elementStart('form', array('method' => 'post',
87 'action' => '/editphoto/' . $this->photo->id));
88 $this->elementStart('ul', 'form_data');
89 $this->elementStart('li');
90 $this->input('phototitle', _("Title"), $this->photo->title, _("The title of the photo. (Optional)"));
91 $this->elementEnd('li');
92 $this->elementStart('li');
93 $this->textarea('photo_description', _("Description"), $this->photo->photo_description, _("A description of the photo. (Optional)"));
94 $this->elementEnd('li');
95 $this->elementStart('li');
96 $this->dropdown('album', _("Album"), $this->albumList(), _("The album in which to place this photo"), false, $this->photo->album_id);
97 $this->elementEnd('li');
98 $this->elementEnd('ul');
99 $this->submit('update', _('Update'));
100 $this->elementEnd('form');
101 $this->element('br');
102 $this->elementStart('form', array('method' => 'post',
103 'action' => '/editphoto/' . $this->photo->id));
104 $this->element('input', array('type' => 'submit',
106 'value' => _('Delete Photo'),
109 'onclick' => 'return confirm(\'Are you sure you would like to delete this photo?\')'));
110 $this->elementEnd('form');
114 function handlePost()
117 common_log(LOG_INFO, 'handlPost()!');
119 if ($this->photo->album_id == 0) {
120 $this->element('p', array(), _('This photo does not exist or was deleted.'));
124 if ($this->user->profile_id != $this->photo->profile_id) {
125 $this->element('p', array(), _('You are not authorized to edit this photo.'));
129 if ($this->arg('update')) {
130 $this->updatePhoto();
132 if ($this->arg('delete')) {
133 $this->deletePhoto();
137 function showForm($msg, $success=false)
140 $this->success = $success;
142 // $this->showPage();
147 $cur = common_current_user();
148 $album = new GNUsocialPhotoAlbum();
149 $album->user_id = $cur->id;
151 $albumlist = array();
152 if (!$album->find()) {
153 GNUsocialPhotoAlbum::newAlbum($cur->id, 'Default');
155 while ($album->fetch()) {
156 $albumlist[$album->album_id] = $album->album_name;
161 function updatePhoto()
163 $cur = common_current_user();
164 $this->photo->title = $this->trimmed('phototitle');
165 $this->photo->photo_description = $this->trimmed('photo_description');
167 $profile_id = $cur->id;
169 $album = GNUsocialPhotoAlbum::getKV('album_id', $this->trimmed('album'));
170 if ($album->profile_id != $profile_id) {
171 $this->showForm(_('Error: This is not your album!'));
174 $this->photo->album_id = $album->album_id;
175 if ($this->photo->validate())
176 $this->photo->update();
178 $this->showForm(_('Error: The photo data is not valid.'));
181 common_redirect('/photo/' . $this->photo->id, '303');
182 // common_redirect exits
185 function deletePhoto()
188 $oldalbum = $this->album_id;
190 $notice = Notice::getKV('id', $this->photo->notice_id);
192 $this->photo->delete();
194 if (Event::handle('StartDeleteOwnNotice', array($this->user, $notice))) {
196 Event::handle('EndDeleteOwnNotice', array($this->user, $notice));
198 $this->showForm(_('Success!'));
199 common_redirect('/' . $this->user->nickname . '/photos/' . $oldalbum, '303');