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