]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/galleryaction.php
Merge commit 'refs/merge-requests/199' of git://gitorious.org/statusnet/mainline...
[quix0rs-gnu-social.git] / lib / galleryaction.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2008, 2009, StatusNet, 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('STATUSNET') && !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 // @todo FIXME: Class documentation missing.
31 class GalleryAction extends ProfileAction
32 {
33     var $profile = 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         }
55
56         $this->user = User::getKV('nickname', $nickname);
57
58         if (!$this->user) {
59             // TRANS: Client error displayed when trying to perform a gallery action with an unknown user.
60             $this->clientError(_('No such user.'), 404);
61         }
62
63         $this->profile = $this->user->getProfile();
64
65         if (!$this->profile) {
66             // TRANS: Error message displayed when referring to a user without a profile.
67             $this->serverError(_('User has no profile.'));
68         }
69
70         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
71
72         $this->tag = $this->trimmed('tag');
73         $this->q   = $this->trimmed('q');
74
75         return true;
76     }
77
78     function isReadOnly($args)
79     {
80         return true;
81     }
82
83     function handle($args)
84     {
85         parent::handle($args);
86
87                 // Post from the tag dropdown; redirect to a GET
88
89                 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
90                     common_redirect($this->selfUrl(), 303);
91                 }
92
93         $this->showPage();
94     }
95
96     function showContent()
97     {
98         $this->showTagsDropdown();
99     }
100
101     function showTagsDropdown()
102     {
103         $tag = $this->trimmed('tag');
104
105         $tags = $this->getAllTags();
106
107         $content = array();
108
109         foreach ($tags as $t) {
110             $content[$t] = $t;
111         }
112         if ($tags) {
113             $this->elementStart('dl', array('id' => 'filter_tags'));
114             $this->element('dt', null, _('Tags'));
115             $this->elementStart('dd');
116             $this->elementStart('ul');
117             $this->elementStart('li', array('id' => 'filter_tags_all',
118                                              'class' => 'child_1'));
119             $this->element('a',
120                            array('href' =>
121                                  common_local_url($this->trimmed('action'),
122                                                   array('nickname' =>
123                                                         $this->user->nickname))),
124                            // TRANS: List element on gallery action page to show all tags.
125                            _m('TAGS','All'));
126             $this->elementEnd('li');
127             $this->elementStart('li', array('id'=>'filter_tags_item'));
128             $this->elementStart('form', array('name' => 'bytag',
129                                                'id' => 'form_filter_bytag',
130                                               'action' => common_path('?action=' . $this->trimmed('action')),
131                                                'method' => 'post'));
132             $this->elementStart('fieldset');
133             // TRANS: Fieldset legend on gallery action page.
134             $this->element('legend', null, _('Select tag to filter'));
135             // TRANS: Dropdown field label on gallery action page for a list containing tags.
136             $this->dropdown('tag', _('Tag'), $content,
137                             // TRANS: Dropdown field title on gallery action page for a list containing tags.
138                             _('Choose a tag to narrow list.'), false, $tag);
139             $this->hidden('nickname', $this->user->nickname);
140             // TRANS: Submit button text on gallery action page.
141             $this->submit('submit', _m('BUTTON','Go'));
142             $this->elementEnd('fieldset');
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     function getTags($lst, $usr)
153     {
154         $profile_tag = new Notice_tag();
155         $profile_tag->query('SELECT DISTINCT(tag) ' .
156                             'FROM profile_tag, subscription ' .
157                             'WHERE tagger = ' . $this->profile->id . ' ' .
158                             'AND ' . $usr . ' = ' . $this->profile->id . ' ' .
159                             'AND ' . $lst . ' = tagged ' .
160                             'AND tagger != tagged');
161         $tags = array();
162         while ($profile_tag->fetch()) {
163             $tags[] = $profile_tag->tag;
164         }
165         $profile_tag->free();
166         return $tags;
167     }
168
169     function getAllTags()
170     {
171         return array();
172     }
173
174     function showProfileBlock()
175     {
176         $block = new AccountProfileBlock($this, $this->profile);
177         $block->show();
178     }
179 }