]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/profilelist.php
include action in tags
[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         var $owner = NULL;
29         var $action = NULL;
30         
31         function __construct($profile, $owner=NULL, $action=NULL) {
32                 $this->profile = $profile;
33                 $this->owner = $owner;
34                 $this->action = $action;
35         }
36         
37         function show_list() {
38                 
39                 common_element_start('ul', array('id' => 'profiles', 'class' => 'profile_list'));
40
41                 $cnt = 0;
42                 
43                 while ($this->profile->fetch()) {
44                         $cnt++;
45                         if($cnt > PROFILES_PER_PAGE) {
46                                 break;
47                         }
48                         $this->show();
49                 }
50                 
51                 common_element_end('ul');
52                 
53                 return $cnt;
54         }
55         
56         function show() {
57
58                 $this->profile = $this->profile;
59                 
60                 common_element_start('li', array('class' => 'profile_single',
61                                                                                  'id' => 'profile-' . $this->profile->id));
62                 
63                 $user = common_current_user();
64                 if ($user && $user->id != $this->profile->id) {
65                         # XXX: special-case for user looking at own
66                         # subscriptions page
67                         if ($user->isSubscribed($this->profile)) {
68                                 common_unsubscribe_form($this->profile);
69                         } else {
70                                 common_subscribe_form($this->profile);
71                         }
72                 }
73                 
74                 $avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE);
75                 common_element_start('a', array('href' => $this->profile->profileurl));
76                 common_element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_STREAM_SIZE),
77                                                                         'class' => 'avatar stream',
78                                                                         'width' => AVATAR_STREAM_SIZE,
79                                                                         'height' => AVATAR_STREAM_SIZE,
80                                                                         'alt' =>
81                                                                         ($this->profile->fullname) ? $this->profile->fullname :
82                                                                         $this->profile->nickname));
83                 common_element_end('a');
84                 common_element_start('p');
85                 common_element_start('a', array('href' => $this->profile->profileurl,
86                                                                                 'class' => 'nickname'));
87                 common_raw($this->highlight($this->profile->nickname));
88                 common_element_end('a');
89                 if ($this->profile->fullname) {
90                         common_text(' | ');
91                         common_element_start('span', 'fullname');
92                         common_raw($this->highlight($this->profile->fullname));
93                         common_element_end('span');
94                 }
95                 if ($this->profile->location) {
96                         common_text(' | ');
97                         common_element_start('span', 'location');
98                         common_raw($this->highlight($this->profile->location));
99                         common_element_end('span');
100                 }
101                 common_element_end('p');
102                 if ($this->profile->homepage) {
103                         common_element_start('p', 'website');
104                         common_element_start('a', array('href' => $this->profile->homepage));
105                         common_raw($this->highlight($this->profile->homepage));
106                         common_element_end('a');
107                         common_element_end('p');
108                 }
109                 if ($this->profile->bio) {
110                         common_element_start('p', 'bio');
111                         common_raw($this->highlight($this->profile->bio));
112                         common_element_end('p');
113                 }
114
115                 # If we're on a list with an owner (subscriptions or subscribers)...
116                 
117                 if ($this->owner) {
118                         # Get tags
119                         $tags = Profile_tag::getTags($this->owner->id, $this->profile->id);
120                         
121                         common_element_start('div', 'tags_user');
122                         common_element_start('dl');
123                         common_element_start('dt');
124                         if ($user->id == $this->owner->id) {
125                                 common_element('a', array('href' => common_local_url('tagother',
126                                                                                                                                          array('id' => $this->profile->id))),
127                                                            _('Tags'));
128                         } else {
129                                 common_text(_('Tags'));
130                         }
131                         common_text(":");
132                         common_element_end('dt');
133                         common_element_start('dd');
134                         if ($tags) {
135                                 common_element_start('ul', 'tags xoxo');
136                                 foreach ($tags as $tag) {
137                                         common_element_start('li');
138                                         common_element('a', array('rel' => 'tag',
139                                                                                           'href' => common_local_url($this->action,
140                                                                                                                                                  array('nickname' => $this->owner->nickname,
141                                                                                                                                                            'tag' => $tag))),
142                                                                    $tag);
143                                         common_element_end('li');
144                                 }
145                                 common_element_end('ul');
146                         } else {
147                                 common_text(_('(none)'));
148                         }
149                         common_element_end('dd');
150                         common_element_end('dl');
151                         common_element_end('div');
152                 }
153
154                 if ($user) {
155                         $action = NULL;                 
156                         if ($user->isSubscribed($this->profile)) {
157                                 $action = 'subscriptions';
158                         } else if (Subscription::pkeyGet(array('subscriber' => $this->profile->id,
159                                                                                                    'subscribed' => $user->id))) {
160                                 $action = 'subscribers';
161                         }
162                 }
163                 
164                 common_element_end('li');
165         }
166
167         function highlight($text) {
168                 return htmlspecialchars($text);
169         }
170 }