]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/profileaction.php
Merge branch '0.7.x' of git@gitorious.org:laconica/dev into 0.7.x
[quix0rs-gnu-social.git] / lib / profileaction.php
1 <?php
2 /**
3  * Laconica, the distributed open-source microblogging tool
4  *
5  * Common parent of Personal and Profile actions
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Personal
23  * @package   Laconica
24  * @author    Evan Prodromou <evan@controlyourself.ca>
25  * @author    Sarven Capadisli <csarven@controlyourself.ca>
26  * @copyright 2008-2009 Control Yourself, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28  * @link      http://laconi.ca/
29  */
30
31 if (!defined('LACONICA')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR.'/lib/profileminilist.php';
36 require_once INSTALLDIR.'/lib/groupminilist.php';
37
38 /**
39  * Profile action common superclass
40  *
41  * Abstracts out common code from profile and personal tabs
42  *
43  * @category Personal
44  * @package  Laconica
45  * @author   Evan Prodromou <evan@controlyourself.ca>
46  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
47  * @link     http://laconi.ca/
48  */
49
50 class ProfileAction extends Action
51 {
52     var $user = null;
53     var $page = null;
54     var $profile = null;
55
56     function prepare($args)
57     {
58         parent::prepare($args);
59
60         $nickname_arg = $this->arg('nickname');
61         $nickname = common_canonical_nickname($nickname_arg);
62
63         // Permanent redirect on non-canonical nickname
64
65         if ($nickname_arg != $nickname) {
66             $args = array('nickname' => $nickname);
67             if ($this->arg('page') && $this->arg('page') != 1) {
68                 $args['page'] = $this->arg['page'];
69             }
70             common_redirect(common_local_url($this->trimmed('action'), $args), 301);
71             return false;
72         }
73
74         $this->user = User::staticGet('nickname', $nickname);
75
76         if (!$this->user) {
77             $this->clientError(_('No such user.'), 404);
78             return false;
79         }
80
81         $this->profile = $this->user->getProfile();
82
83         if (!$this->profile) {
84             $this->serverError(_('User has no profile.'));
85             return false;
86         }
87
88         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
89
90         common_set_returnto($this->selfUrl());
91
92         return true;
93     }
94
95     function showSections()
96     {
97         $this->showSubscriptions();
98         $this->showSubscribers();
99         $this->showGroups();
100         $this->showStatistics();
101     }
102
103     function showSubscriptions()
104     {
105         $profile = $this->user->getSubscriptions(0, PROFILES_PER_MINILIST + 1);
106
107         $this->elementStart('div', array('id' => 'entity_subscriptions',
108                                          'class' => 'section'));
109
110         $this->element('h2', null, _('Subscriptions'));
111
112         if ($profile) {
113             $pml = new ProfileMiniList($profile, $this->user, $this);
114             $cnt = $pml->show();
115             if ($cnt == 0) {
116                 $this->element('p', null, _('(None)'));
117             }
118         }
119
120         if ($cnt > PROFILES_PER_MINILIST) {
121             $this->elementStart('p');
122             $this->element('a', array('href' => common_local_url('subscriptions',
123                                                                  array('nickname' => $this->profile->nickname)),
124                                       'class' => 'more'),
125                            _('All subscriptions'));
126             $this->elementEnd('p');
127         }
128
129         $this->elementEnd('div');
130     }
131
132     function showSubscribers()
133     {
134         $profile = $this->user->getSubscribers(0, PROFILES_PER_MINILIST + 1);
135
136         $this->elementStart('div', array('id' => 'entity_subscribers',
137                                          'class' => 'section'));
138
139         $this->element('h2', null, _('Subscribers'));
140
141         if ($profile) {
142             $pml = new ProfileMiniList($profile, $this->user, $this);
143             $cnt = $pml->show();
144             if ($cnt == 0) {
145                 $this->element('p', null, _('(None)'));
146             }
147         }
148
149         if ($cnt > PROFILES_PER_MINILIST) {
150             $this->elementStart('p');
151             $this->element('a', array('href' => common_local_url('subscribers',
152                                                                  array('nickname' => $this->profile->nickname)),
153                                       'class' => 'more'),
154                            _('All subscribers'));
155             $this->elementEnd('p');
156         }
157
158         $this->elementEnd('div');
159     }
160
161     function showStatistics()
162     {
163         // XXX: WORM cache this
164         $subs = new Subscription();
165         $subs->subscriber = $this->profile->id;
166         $subs_count = (int) $subs->count() - 1;
167
168         $subbed = new Subscription();
169         $subbed->subscribed = $this->profile->id;
170         $subbed_count = (int) $subbed->count() - 1;
171
172         $notices = new Notice();
173         $notices->profile_id = $this->profile->id;
174         $notice_count = (int) $notices->count();
175
176         $this->elementStart('div', array('id' => 'entity_statistics',
177                                          'class' => 'section'));
178
179         $this->element('h2', null, _('Statistics'));
180
181         // Other stats...?
182         $this->elementStart('dl', 'entity_user-id');
183         $this->element('dt', null, _('User ID'));
184         $this->element('dd', null, $this->profile->id);
185         $this->elementEnd('dl');
186
187         $this->elementStart('dl', 'entity_member-since');
188         $this->element('dt', null, _('Member since'));
189         $this->element('dd', null, date('j M Y',
190                                         strtotime($this->profile->created)));
191         $this->elementEnd('dl');
192
193         $this->elementStart('dl', 'entity_subscriptions');
194         $this->elementStart('dt');
195         $this->element('a', array('href' => common_local_url('subscriptions',
196                                                              array('nickname' => $this->profile->nickname))),
197                        _('Subscriptions'));
198         $this->elementEnd('dt');
199         $this->element('dd', null, (is_int($subs_count)) ? $subs_count : '0');
200         $this->elementEnd('dl');
201
202         $this->elementStart('dl', 'entity_subscribers');
203         $this->elementStart('dt');
204         $this->element('a', array('href' => common_local_url('subscribers',
205                                                              array('nickname' => $this->profile->nickname))),
206                        _('Subscribers'));
207         $this->elementEnd('dt');
208         $this->element('dd', 'subscribers', (is_int($subbed_count)) ? $subbed_count : '0');
209         $this->elementEnd('dl');
210
211         $this->elementStart('dl', 'entity_notices');
212         $this->element('dt', null, _('Notices'));
213         $this->element('dd', null, (is_int($notice_count)) ? $notice_count : '0');
214         $this->elementEnd('dl');
215
216         $this->elementEnd('div');
217     }
218
219     function showGroups()
220     {
221         $groups = $this->user->getGroups(0, GROUPS_PER_MINILIST + 1);
222
223         $this->elementStart('div', array('id' => 'entity_groups',
224                                          'class' => 'section'));
225
226         $this->element('h2', null, _('Groups'));
227
228         if ($groups) {
229             $gml = new GroupMiniList($groups, $this->user, $this);
230             $cnt = $gml->show();
231             if ($cnt == 0) {
232                 $this->element('p', null, _('(None)'));
233             }
234         }
235
236         if ($cnt > GROUPS_PER_MINILIST) {
237             $this->elementStart('p');
238             $this->element('a', array('href' => common_local_url('usergroups',
239                                                                  array('nickname' => $this->profile->nickname)),
240                                       'class' => 'more'),
241                            _('All groups'));
242             $this->elementEnd('p');
243         }
244
245         $this->elementEnd('div');
246     }
247 }