]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/GNUsocialPhotos/actions/editphoto.php
Updating uploaded photos
[quix0rs-gnu-social.git] / plugins / GNUsocialPhotos / actions / editphoto.php
1 <?php
2 /**
3  * GNU Social
4  * Copyright (C) 2010, Free Software Foundation, Inc.
5  *
6  * PHP version 5
7  *
8  * LICENCE:
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.
13  *
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.
18  *
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/>.
21  *
22  * @category  Widget
23  * @package   GNU Social
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
29  */
30
31 if (!defined('STATUSNET')) {
32     exit(1);
33 }
34
35 class EditphotoAction extends Action
36 {
37     var $user = null;
38
39     function prepare($args)
40     {
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);
46         return true;
47     }
48
49     function handle($args)
50     {
51         parent::handle($args);
52         if($_SERVER['REQUEST_METHOD'] == 'POST') {
53             $this->handlePost();
54         }
55         $this->showPage();
56     }
57
58     function title()
59     {
60         return _m('Upload Photos');
61     }
62
63     function showContent()
64     {
65         if($this->user->profile_id != $this->photo->profile_id) {
66             $this->element('p', array(), _('You are not authorized to edit this photo.'));
67         } else {
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');
84             $this->element('br');            
85         }
86     }
87
88     function handlePost()
89     {
90
91         common_log(LOG_INFO, 'handlPost()!');
92
93         if ($this->arg('update')) {
94             $this->updatePhoto();
95         }
96     }
97
98     function showForm($msg, $success=false)
99     {
100         $this->msg = $msg;
101         $this->success = $success;
102
103 //        $this->showPage();
104     }
105
106     function albumList() 
107     {
108         $cur = common_current_user();
109         $album = new GNUsocialPhotoAlbum();
110         $album->user_id = $cur->id;
111
112         $albumlist = array();
113         if (!$album->find()) {
114             GNUsocialPhotoAlbum::newAlbum($cur->id, 'Default');
115         }
116         while ($album->fetch()) {
117             $albumlist[$album->album_id] = $album->album_name;
118         }
119         return $albumlist;
120     }
121
122     function updatePhoto()
123     {
124         $cur = common_current_user();
125         if($this->user->profile_id != $this->photo->profile_id) {
126             return;
127         }
128
129         $this->photo->title = $this->trimmed('phototitle');
130         $this->photo->photo_description = $this->trimmed('photo_description');
131
132         $profile_id = $cur->id;
133        
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!'));
137             return;
138         }
139         $this->photo->album_id = $album->album_id;
140         if ($this->photo->validate())
141             $this->photo->update();
142         else {
143             $this->showForm(_('Error: The photo data is not valid.'));
144             return;
145         }
146         $this->showForm(_('Success!'));
147
148     }
149
150 }