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