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 return _m('Upload Photos');
63 function showContent()
65 if($this->user->profile_id != $this->photo->profile_id) {
66 $this->element('p', array(), _('You are not authorized to edit this photo.'));
68 $this->element('img', array('src' => $this->photo->uri));
69 $this->elementStart('form', array('method' => 'post',
70 'action' => '/editphoto/' . $this->photo->id));
71 $this->elementStart('ul', 'form_data');
72 $this->elementStart('li');
73 $this->input('phototitle', _("Title"), $this->photo->title, _("The title of the photo. (Optional)"));
74 $this->elementEnd('li');
75 $this->elementStart('li');
76 $this->textarea('photo_description', _("Description"), $this->photo->photo_description, _("A description of the photo. (Optional)"));
77 $this->elementEnd('li');
78 $this->elementStart('li');
79 $this->dropdown('album', _("Album"), $this->albumList(), _("The album in which to place this photo"), false, $this->photo->album_id);
80 $this->elementEnd('li');
81 $this->elementEnd('ul');
82 $this->submit('update', _('Update'));
83 $this->elementEnd('form');
91 common_log(LOG_INFO, 'handlPost()!');
93 if ($this->arg('update')) {
98 function showForm($msg, $success=false)
101 $this->success = $success;
103 // $this->showPage();
108 $cur = common_current_user();
109 $album = new GNUsocialPhotoAlbum();
110 $album->user_id = $cur->id;
112 $albumlist = array();
113 if (!$album->find()) {
114 GNUsocialPhotoAlbum::newAlbum($cur->id, 'Default');
116 while ($album->fetch()) {
117 $albumlist[$album->album_id] = $album->album_name;
122 function updatePhoto()
124 $cur = common_current_user();
125 if($this->user->profile_id != $this->photo->profile_id) {
129 $this->photo->title = $this->trimmed('phototitle');
130 $this->photo->photo_description = $this->trimmed('photo_description');
132 $profile_id = $cur->id;
134 $album = GNUsocialPhotoAlbum::staticGet('album_id', $this->trimmed('album'));
135 if ($album->profile_id != $profile_id) {
136 $this->showForm(_('Error: This is not your album!'));
139 $this->photo->album_id = $album->album_id;
140 if ($this->photo->validate())
141 $this->photo->update();
143 $this->showForm(_('Error: The photo data is not valid.'));
146 $this->showForm(_('Success!'));