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