]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/galleryaction.php
Merge branch '0.7.x' into utf8
[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     var $tag = null;
36
37     function prepare($args)
38     {
39         parent::prepare($args);
40
41         // FIXME very similar code below
42
43         $nickname_arg = $this->arg('nickname');
44         $nickname = common_canonical_nickname($nickname_arg);
45
46         // Permanent redirect on non-canonical nickname
47
48         if ($nickname_arg != $nickname) {
49             $args = array('nickname' => $nickname);
50             if ($this->arg('page') && $this->arg('page') != 1) {
51                 $args['page'] = $this->arg['page'];
52             }
53             common_redirect(common_local_url($this->trimmed('action'), $args), 301);
54             return false;
55         }
56
57         $this->user = User::staticGet('nickname', $nickname);
58
59         if (!$this->user) {
60             $this->clientError(_('No such user.'), 404);
61             return false;
62         }
63
64         $this->profile = $this->user->getProfile();
65
66         if (!$this->profile) {
67             $this->serverError(_('User has no profile.'));
68             return false;
69         }
70
71         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
72
73         $this->tag = $this->trimmed('tag');
74         $this->q   = $this->trimmed('q');
75
76         return true;
77     }
78
79     function isReadOnly($args)
80     {
81         return true;
82     }
83
84     function handle($args)
85     {
86         parent::handle($args);
87
88                 # Post from the tag dropdown; redirect to a GET
89
90                 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
91                     common_redirect($this->selfUrl(), 303);
92             return;
93                 }
94
95         $this->showPage();
96     }
97
98     function showLocalNav()
99     {
100         $nav = new SubGroupNav($this, $this->user);
101         $nav->show();
102     }
103
104     function showContent()
105     {
106         $this->showTagsDropdown();
107     }
108
109     function showTagsDropdown()
110     {
111         $tag = $this->trimmed('tag');
112
113         $tags = $this->getAllTags();
114
115         $content = array();
116
117         foreach ($tags as $t) {
118             $content[$t] = $t;
119         }
120         if ($tags) {
121             $this->elementStart('dl', array('id'=>'filter_tags'));
122             $this->element('dt', null, _('Filter tags'));
123             $this->elementStart('dd');
124             $this->elementStart('ul');
125             $this->elementStart('li', array('id' => 'filter_tags_all',
126                                              'class' => 'child_1'));
127             $this->element('a',
128                            array('href' =>
129                                  common_local_url($this->trimmed('action'),
130                                                   array('nickname' =>
131                                                         $this->user->nickname))),
132                            _('All'));
133             $this->elementEnd('li');
134             $this->elementStart('li', array('id'=>'filter_tags_item'));
135             $this->elementStart('form', array('name' => 'bytag',
136                                                'id' => 'bytag',
137                                                'action' => common_path('?action=' . $this->trimmed('action')),
138                                                'method' => 'post'));
139             $this->dropdown('tag', _('Tag'), $content,
140                             _('Choose a tag to narrow list'), false, $tag);
141             $this->hidden('nickname', $this->user->nickname);
142             $this->submit('submit', _('Go'));
143             $this->elementEnd('form');
144             $this->elementEnd('li');
145             $this->elementEnd('ul');
146             $this->elementEnd('dd');
147             $this->elementEnd('dl');
148         }
149     }
150
151     // Get list of tags we tagged other users with
152
153     function getTags($lst, $usr)
154     {
155         $profile_tag = new Notice_tag();
156         $profile_tag->query('SELECT DISTINCT(tag) ' .
157                             'FROM profile_tag, subscription ' .
158                             'WHERE tagger = ' . $this->profile->id . ' ' .
159                             'AND ' . $usr . ' = ' . $this->profile->id . ' ' .
160                             'AND ' . $lst . ' = tagged ' .
161                             'AND tagger != tagged');
162         $tags = array();
163         while ($profile_tag->fetch()) {
164             $tags[] = $profile_tag->tag;
165         }
166         $profile_tag->free();
167         return $tags;
168     }
169
170     function getAllTags()
171     {
172         return array();
173     }
174 }