]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/galleryaction.php
Merge branch 'master' of /var/www/trunk
[quix0rs-gnu-social.git] / lib / galleryaction.php
1 <?php
2 /**
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('LACONICA')) {
21     exit(1);
22 }
23
24 require_once INSTALLDIR.'/lib/profilelist.php';
25
26 // 10x8
27
28 define('AVATARS_PER_PAGE', 80);
29
30 class GalleryAction extends Action
31 {
32     var $profile = null;
33     var $user = null;
34     var $page = null;
35
36     function prepare($args)
37     {
38         parent::prepare($args);
39
40         // FIXME very similar code below
41
42         $nickname_arg = $this->arg('nickname');
43         $nickname = common_canonical_nickname($nickname_arg);
44
45         // Permanent redirect on non-canonical nickname
46
47         if ($nickname_arg != $nickname) {
48             $args = array('nickname' => $nickname);
49             if ($this->arg('page') && $this->arg('page') != 1) {
50                 $args['page'] = $this->arg['page'];
51             }
52             common_redirect(common_local_url('subscriptions', $args), 301);
53             return false;
54         }
55
56         $this->user = User::staticGet('nickname', $nickname);
57
58         if (!$this->user) {
59             $this->clientError(_('No such user.'), 404);
60             return false;
61         }
62
63         $this->profile = $this->user->getProfile();
64
65         if (!$this->profile) {
66             $this->serverError(_('User has no profile.'));
67             return false;
68         }
69
70         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
71
72         return true;
73     }
74
75     function isReadOnly()
76     {
77         return true;
78     }
79
80     function handle($args)
81     {
82         parent::handle($args);
83
84                 # Post from the tag dropdown; redirect to a GET
85
86                 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
87                     common_redirect($this->self_url(), 307);
88             return;
89                 }
90
91         $this->showPage();
92     }
93
94     function showLocalNav()
95     {
96         $nav = new SubGroupNav($this, $this->user);
97         $nav->show();
98     }
99
100     function showContent()
101     {
102         $this->showTagsDropdown();
103     }
104
105     function showTagsDropdown()
106     {
107         $tag = $this->trimmed('tag');
108
109         $tags = $this->getAllTags();
110
111         $content = array();
112
113         foreach ($tags as $t) {
114             $content[$t] = $t;
115         }
116         if ($tags) {
117             $this->elementStart('dl', array('id'=>'filter_tags'));
118             $this->element('dt', null, _('Filter tags'));
119             $this->elementStart('dd');
120             $this->elementStart('ul');
121             $this->elementStart('li', array('id' => 'filter_tags_all',
122                                              'class' => 'child_1'));
123             $this->element('a',
124                            array('href' =>
125                                  common_local_url($this->trimmed('action'),
126                                                   array('nickname' =>
127                                                         $profile->nickname))),
128                            _('All'));
129             $this->elementEnd('li');
130             $this->elementStart('li', array('id'=>'filter_tags_item'));
131             $this->elementStart('form', array('name' => 'bytag',
132                                                'id' => 'bytag',
133                                                'method' => 'post'));
134             $this->dropdown('tag', _('Tag'), $content,
135                             _('Choose a tag to narrow list'), false, $tag);
136             $this->submit('go', _('Go'));
137             $this->elementEnd('form');
138             $this->elementEnd('li');
139             $this->elementEnd('ul');
140             $this->elementEnd('dd');
141             $this->elementEnd('dl');
142         }
143     }
144
145     // Get list of tags we tagged other users with
146
147     function getTags($lst, $usr)
148     {
149         $profile_tag = new Notice_tag();
150         $profile_tag->query('SELECT DISTINCT(tag) ' .
151                             'FROM profile_tag, subscription ' .
152                             'WHERE tagger = ' . $this->profile->id . ' ' .
153                             'AND ' . $usr . ' = ' . $this->profile->id . ' ' .
154                             'AND ' . $lst . ' = tagged ' .
155                             'AND tagger != tagged');
156         $tags = array();
157         while ($profile_tag->fetch()) {
158             $tags[] = $profile_tag->tag;
159         }
160         $profile_tag->free();
161         return $tags;
162     }
163
164     function getAllTags()
165     {
166         return array();
167     }
168 }