]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/galleryaction.php
83245df211c194477ccc53c75f7cbc86c7c5ad86
[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('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 OwnerDesignAction
31 {
32     var $profile = null;
33     var $page = null;
34     var $tag = 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($this->trimmed('action'), $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         $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             return;
92                 }
93
94         $this->showPage();
95     }
96
97     function showLocalNav()
98     {
99         $nav = new SubGroupNav($this, $this->user);
100         $nav->show();
101     }
102
103     function showContent()
104     {
105         $this->showTagsDropdown();
106     }
107
108     function showTagsDropdown()
109     {
110         $tag = $this->trimmed('tag');
111
112         $tags = $this->getAllTags();
113
114         $content = array();
115
116         foreach ($tags as $t) {
117             $content[$t] = $t;
118         }
119         if ($tags) {
120             $this->elementStart('dl', array('id'=>'filter_tags'));
121             $this->element('dt', null, _('Filter tags'));
122             $this->elementStart('dd');
123             $this->elementStart('ul');
124             $this->elementStart('li', array('id' => 'filter_tags_all',
125                                              'class' => 'child_1'));
126             $this->element('a',
127                            array('href' =>
128                                  common_local_url($this->trimmed('action'),
129                                                   array('nickname' =>
130                                                         $this->user->nickname))),
131                            _('All'));
132             $this->elementEnd('li');
133             $this->elementStart('li', array('id'=>'filter_tags_item'));
134             $this->elementStart('form', array('name' => 'bytag',
135                                                'id' => 'bytag',
136                                                'action' => common_path('?action=' . $this->trimmed('action')),
137                                                'method' => 'post'));
138             $this->dropdown('tag', _('Tag'), $content,
139                             _('Choose a tag to narrow list'), false, $tag);
140             $this->hidden('nickname', $this->user->nickname);
141             $this->submit('submit', _('Go'));
142             $this->elementEnd('form');
143             $this->elementEnd('li');
144             $this->elementEnd('ul');
145             $this->elementEnd('dd');
146             $this->elementEnd('dl');
147         }
148     }
149
150     // Get list of tags we tagged other users with
151
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 }