]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/GNUsocialPhotos/actions/photos.php
Usability with photos tab
[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  * @copyright 2010 Free Software Foundation, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 require_once INSTALLDIR.'/lib/personalgroupnav.php';
35
36 class PhotosAction extends Action
37 {
38     var $user = null;
39
40     function prepare($args)
41     {
42         parent::prepare($args);
43
44         $args = $this->returnToArgs();
45         $username = $args[1]['nickname'];
46         if (common_valid_profile_tag($username) == 0) {
47             $this->user = null;
48         } else {
49             $this->user = Profile::staticGet('nickname', $username);
50         }
51         return true;
52     }
53
54     function handle($args)
55     {
56         parent::handle($args);
57         $this->showPage();
58     }
59
60     function title()
61     {
62         if (empty($this->user)) {
63             return _m('No such user.');
64         } else {
65             return sprintf(_m("%s's Photos."), $this->user->nickname);
66         }
67     }
68
69     function showLocalNav()
70     {
71         $nav = new PersonalGroupNav($this);
72         $nav->show();
73     }
74
75     function showContent()
76     {
77         if(empty($this->user)) {
78             return;
79         }
80         $page = $_GET['pageid'];
81         if (!filter_var($page, FILTER_VALIDATE_INT)){
82             $page = 1;
83         }
84    
85         //TODO choice of available albums by user.
86         //Currently based on fact that each user can only have one album.
87         $album = GNUSocialPhotoAlbum::staticGet('profile_id', $this->user->id);
88         $photos = GNUsocialPhoto::getGalleryPage($page, $album->album_id, 9);
89
90         if ($page > 1) { 
91             $this->element('a', array('href' => 'photos?pageid=' . ($page-1)), 'Previous page');
92         }
93         if (GNUsocialPhoto::getGalleryPage($page+1, $album->album_id, 9)) {
94             $this->element('a', array('href' => 'photos?pageid=' . ($page+1) ), 'Next page');
95         }
96
97         $this->elementStart('ul', array('class' => 'photothumbs'));
98         foreach ($photos as $photo) {
99             $this->elementStart('li');
100             $this->elementStart('a', array('href' => $photo->getPageLink()));
101             $this->element('img', array('src' => $photo->thumb_uri));
102             $this->elementEnd('a');
103             $this->elementEnd('li');
104         }
105         $this->elementEnd('ul');
106     }
107 }