]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/profilelist.php
show tags that the owner added, not that the current user added
[quix0rs-gnu-social.git] / lib / profilelist.php
1 <?php
2
3 /*
4  * Laconica - a distributed open-source microblogging tool
5  * Copyright (C) 2008, Controlez-Vous, Inc.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 if (!defined('LACONICA')) { exit(1); }
22
23 define('PROFILES_PER_PAGE', 20);
24
25 class ProfileList {
26
27         var $profile = NULL;
28         
29         function __construct($profile, $owner=NULL) {
30                 $this->profile = $profile;
31                 $this->owner = $owner;
32         }
33         
34         function show_list() {
35                 
36                 common_element_start('ul', array('id' => 'profiles'));
37
38                 $cnt = 0;
39                 
40                 while ($this->profile->fetch()) {
41                         $cnt++;
42                         if($cnt > PROFILES_PER_PAGE) {
43                                 break;
44                         }
45                         $this->show();
46                 }
47                 
48                 common_element_end('ul');
49                 
50                 return $cnt;
51         }
52         
53         function show() {
54
55                 $this->profile = $this->profile;
56                 
57                 common_element_start('li', array('class' => 'profile_single',
58                                                                                  'id' => 'profile-' . $this->profile->id));
59                 
60                 $user = common_current_user();
61                 
62                 if ($user && $user->id != $this->profile->id) {
63                         # XXX: special-case for user looking at own
64                         # subscriptions page
65                         if ($user->isSubscribed($this->profile)) {
66                                 common_unsubscribe_form($this->profile);
67                         } else {
68                                 common_subscribe_form($this->profile);
69                         }
70                 }
71                 
72                 $avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE);
73                 common_element_start('a', array('href' => $this->profile->profileurl));
74                 common_element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_STREAM_SIZE),
75                                                                         'class' => 'avatar stream',
76                                                                         'width' => AVATAR_STREAM_SIZE,
77                                                                         'height' => AVATAR_STREAM_SIZE,
78                                                                         'alt' =>
79                                                                         ($this->profile->fullname) ? $this->profile->fullname :
80                                                                         $this->profile->nickname));
81                 common_element_end('a');
82                 common_element_start('p');
83                 common_element_start('a', array('href' => $this->profile->profileurl,
84                                                                                 'class' => 'nickname'));
85                 common_raw($this->highlight($this->profile->nickname));
86                 common_element_end('a');
87                 if ($this->profile->fullname) {
88                         common_text(' | ');
89                         common_element_start('span', 'fullname');
90                         common_raw($this->highlight($this->profile->fullname));
91                         common_element_end('span');
92                 }
93                 if ($this->profile->location) {
94                         common_text(' | ');
95                         common_element_start('span', 'location');
96                         common_raw($this->highlight($this->profile->location));
97                         common_element_end('span');
98                 }
99                 common_element_end('p');
100                 if ($this->profile->homepage) {
101                         common_element_start('p', 'website');
102                         common_element_start('a', array('href' => $this->profile->homepage));
103                         common_raw($this->highlight($this->profile->homepage));
104                         common_element_end('a');
105                         common_element_end('p');
106                 }
107                 if ($this->profile->bio) {
108                         common_element_start('p', 'bio');
109                         common_raw($this->highlight($this->profile->bio));
110                         common_element_end('p');
111                 }
112                 
113                 $tags = Profile_tag::getTags($this->profile->id, $this->profile->id);
114                 
115                 if ($tags) {
116                         common_element_start('p', 'tags');
117                         foreach ($tags as $tag) {
118                                 common_element('a', array('rel' => 'tag',
119                                                                                   'href' => common_local_url('peopletag',
120                                                                                                                                          array('tag' => $tag))),
121                                                            $tag);
122                         }
123                         common_element_end('p');
124                 }
125
126                 if ($this->owner) {
127                         $action = NULL;
128                         
129                         if ($this->owner->isSubscribed($this->profile)) {
130                                 $action = 'subscriptions';
131                         } else if (Subscription::pkeyGet(array('subscriber' => $this->profile->id,
132                                                                                                    'subscribed' => $this->owner->id))) {
133                                 $action = 'subscribers';
134                         }
135                         
136                         
137                         if ($action) {
138                                 $tags = Profile_tag::getTags($this->owner->id, $this->profile->id);
139                                 
140                                 if ($tags) {
141                                         common_element_start('p', 'subtags');
142                                         
143                                         foreach ($tags as $tag) {
144                                                 common_element('a', array('href' => common_local_url($action,
145                                                                                                                                                          array('nickname' => $this->owner->nickname,
146                                                                                                                                                                    'tag' => $tag))),
147                                                                            $tag);
148                                         }
149                                         
150                                         common_element_end('p');
151                                 }
152
153                                 if ($this->owner->id == $user->id) {
154                                         common_element('a', array('href' => common_local_url('tagother',
155                                                                                                                                                  array('id' => $this->profile->id)),
156                                                                                           'class' => 'tagother'),
157                                                                    _('Tag'));
158                                 }
159                         }
160                 }
161                 
162                 common_element_end('li');
163         }
164
165         function highlight($text) {
166                 return htmlspecialchars($text);
167         }
168 }