]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/GNUsocialPhotos/actions/photos.php
Fixed undefined variable while creating new albums
[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::staticGet('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->user_id = $this->user->id;
91
92         $albums = array();
93         if (!$album->find()) {
94             $cur = common_current_user();
95             GNUsocialPhotoAlbum::newAlbum($cur->profile_id, 'Default');
96         }
97
98         $this->elementStart('div', array('class' => 'galleryheader'));
99         //$this->element('a', array('href' => '#',
100         //                          'onclick' => 'return increasePhotoSize()'), '+');
101         //$this->raw(' | ');
102         //$this->element('a', array('href' => '#',
103         //                          'onclick' => 'return decreasePhotoSize()'), '-');
104
105         $this->showResizeImagesBox();
106         $this->elementEnd('div');
107
108
109
110         while ($album->fetch()) {
111             $this->elementStart('div', array('class' => 'photocontainer'));
112             $this->elementStart('a', array('href' => $album->getPageLink()));
113             $this->element('img', array('src' => $album->getThumbUri(),
114                                         'class' => 'albumingallery'));
115             $this->elementEnd('a');
116             $this->element('h3', array(), $album->album_name);
117             $this->elementEnd('div');
118         }
119         
120     }
121     
122     function showAlbum($album_id)
123     {
124         $album = GNUSocialPhotoAlbum::staticGet('album_id', $album_id);
125         if (!$album) {
126             return;
127         }
128
129         $page = $_GET['pageid'];
130         if (!filter_var($page, FILTER_VALIDATE_INT)){
131             $page = 1;
132         }
133
134         $photos = GNUsocialPhoto::getGalleryPage($page, $album->album_id, 9);
135         $this->elementStart('div', array('class' => 'galleryheader'));
136         if ($page > 1) { 
137             $this->element('a', array('href' => $album->getPageLink() . '?pageid=' . ($page-1)), 'Previous page');
138             $this->raw(' | ');
139         }
140         if (GNUsocialPhoto::getGalleryPage($page+1, $album->album_id, 9)) {
141             $this->element('a', array('href' => $album->getPageLink() . '?pageid=' . ($page+1) ), 'Next page');
142             $this->raw(' | ');
143         }
144
145         //$this->element('a', array('href' => '#',
146         //                          'onclick' => 'return increasePhotoSize()'), '+');
147         //$this->raw(' | ');
148         //$this->element('a', array('href' => '#',
149         //                          'onclick' => 'return decreasePhotoSize()'), '-');
150         //$this->raw(' | ');
151
152         $this->showResizeImagesBox();
153         $this->elementEnd('div');
154
155         foreach ($photos as $photo) {
156             $this->elementStart('a', array('href' => $photo->getPageLink()));
157             $this->elementStart('div', array('class' => 'photocontainer'));
158             $this->element('img', array('src' => $photo->thumb_uri,
159                                         'class' => 'photoingallery'));
160             $this->element('div', array('class' => 'phototitle'), $photo->title);
161             $this->elementEnd('div');
162             $this->elementEnd('a');
163         }
164
165     }
166
167
168     function showContent()
169     {
170         if (!empty($this->albumid))
171             $this->showAlbum($this->albumid);
172         else
173             $this->showAlbums();
174     }
175 }