]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/GNUsocialPhotos/actions/photos.php
XSS vulnerability when remote-subscribing
[quix0rs-gnu-social.git] / plugins / GNUsocialPhotos / actions / photos.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 require_once INSTALLDIR.'/lib/personalgroupnav.php';
36
37 class PhotosAction extends Action
38 {
39     var $user = null;
40
41     function prepare($args)
42     {
43         parent::prepare($args);
44
45         $args = $this->returnToArgs();
46         $username = $args[1]['nickname'];
47         $this->albumid = $args[1]['albumid'];
48         if (common_valid_profile_tag($username) == 0) {
49             $this->user = null;
50         } else {
51             $this->user = Profile::getKV('nickname', $username);
52         }
53         return true;
54     }
55
56     function handle($args)
57     {
58         parent::handle($args);
59         $this->showPage();
60     }
61
62     function title()
63     {
64         if (empty($this->user)) {
65             return _m('No such user.');
66         } else {
67             return sprintf(_m("%s's Photos."), $this->user->nickname);
68         }
69     }
70
71     function showLocalNav()
72     {
73         $nav = new PersonalGroupNav($this);
74         $nav->show();
75     }
76
77     function showResizeImagesBox()
78     {
79         $this->elementStart('select', array('onchange' => 'return scalePhotosToSize(this.value)'));
80         $this->element('option', array('value' => ''), "");
81         $this->element('option', array('value' => '60'), _("Thumbnail"));
82         $this->element('option', array('value' => '120'), _("Medium"));
83         $this->element('option', array('value' => '400'), _("Normal"));
84         $this->elementEnd('select');
85     }        
86
87     function showAlbums()
88     {
89         $album = new GNUsocialPhotoAlbum();
90         $album->profile_id = $this->user->id;
91
92         $albums = array();
93         if (!$album->find()) {
94             GNUsocialPhotoAlbum::newAlbum($this->user->id, 'Default');
95         }
96
97         $this->elementStart('div', array('class' => 'galleryheader'));
98         //$this->element('a', array('href' => '#',
99         //                          'onclick' => 'return increasePhotoSize()'), '+');
100         //$this->raw(' | ');
101         //$this->element('a', array('href' => '#',
102         //                          'onclick' => 'return decreasePhotoSize()'), '-');
103
104         $this->showResizeImagesBox();
105         $this->elementEnd('div');
106
107
108
109         while ($album->fetch()) {
110             $this->elementStart('div', array('class' => 'photocontainer'));
111             $this->elementStart('a', array('href' => $album->getPageLink()));
112             $this->element('img', array('src' => $album->getThumbUri(),
113                                         'class' => 'albumingallery'));
114             $this->elementEnd('a');
115             $this->element('h3', array(), $album->album_name);
116             $this->elementEnd('div');
117         }
118         
119     }
120     
121     function showAlbum($album_id)
122     {
123         $album = GNUsocialPhotoAlbum::getKV('album_id', $album_id);
124         if (!$album) {
125             return;
126         }
127
128         $page = $_GET['pageid'];
129         if (!filter_var($page, FILTER_VALIDATE_INT)){
130             $page = 1;
131         }
132
133         $photos = GNUsocialPhoto::getGalleryPage($page, $album->album_id, 9);
134         $this->elementStart('div', array('class' => 'galleryheader'));
135         if ($page > 1) { 
136             $this->element('a', array('href' => $album->getPageLink() . '?pageid=' . ($page-1)), 'Previous page');
137             $this->raw(' | ');
138         }
139         if (GNUsocialPhoto::getGalleryPage($page+1, $album->album_id, 9)) {
140             $this->element('a', array('href' => $album->getPageLink() . '?pageid=' . ($page+1) ), 'Next page');
141             $this->raw(' | ');
142         }
143
144         //$this->element('a', array('href' => '#',
145         //                          'onclick' => 'return increasePhotoSize()'), '+');
146         //$this->raw(' | ');
147         //$this->element('a', array('href' => '#',
148         //                          'onclick' => 'return decreasePhotoSize()'), '-');
149         //$this->raw(' | ');
150
151         $this->showResizeImagesBox();
152         $this->elementEnd('div');
153
154         foreach ($photos as $photo) {
155             $this->elementStart('a', array('href' => $photo->getPageLink()));
156             $this->elementStart('div', array('class' => 'photocontainer'));
157             $this->element('img', array('src' => $photo->thumb_uri,
158                                         'class' => 'photoingallery'));
159             $this->element('div', array('class' => 'phototitle'), $photo->title);
160             $this->elementEnd('div');
161             $this->elementEnd('a');
162         }
163
164     }
165
166
167     function showContent()
168     {
169         if (!empty($this->albumid))
170             $this->showAlbum($this->albumid);
171         else
172             $this->showAlbums();
173     }
174 }