]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/profileaction.php
Merge branch '0.8.x' of git@gitorious.org:+laconica-developers/laconica/dev into...
[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 OwnerDesignAction
51 {
52     var $page    = null;
53     var $profile = null;
54     var $tag     = 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->tag = $this->trimmed('tag');
89         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
90         common_set_returnto($this->selfUrl());
91         return true;
92     }
93
94     function showSections()
95     {
96         $this->showSubscriptions();
97         $this->showSubscribers();
98         $this->showGroups();
99         $this->showStatistics();
100     }
101
102     function showSubscriptions()
103     {
104         $profile = $this->user->getSubscriptions(0, PROFILES_PER_MINILIST + 1);
105
106         $this->elementStart('div', array('id' => 'entity_subscriptions',
107                                          'class' => 'section'));
108
109         $this->element('h2', null, _('Subscriptions'));
110
111         if ($profile) {
112             $pml = new ProfileMiniList($profile, $this);
113             $cnt = $pml->show();
114             if ($cnt == 0) {
115                 $this->element('p', null, _('(None)'));
116             }
117         }
118
119         if ($cnt > PROFILES_PER_MINILIST) {
120             $this->elementStart('p');
121             $this->element('a', array('href' => common_local_url('subscriptions',
122                                                                  array('nickname' => $this->profile->nickname)),
123                                       'class' => 'more'),
124                            _('All subscriptions'));
125             $this->elementEnd('p');
126         }
127
128         $this->elementEnd('div');
129     }
130
131     function showSubscribers()
132     {
133         $profile = $this->user->getSubscribers(0, PROFILES_PER_MINILIST + 1);
134
135         $this->elementStart('div', array('id' => 'entity_subscribers',
136                                          'class' => 'section'));
137
138         $this->element('h2', null, _('Subscribers'));
139
140         if ($profile) {
141             $pml = new ProfileMiniList($profile, $this);
142             $cnt = $pml->show();
143             if ($cnt == 0) {
144                 $this->element('p', null, _('(None)'));
145             }
146         }
147
148         if ($cnt > PROFILES_PER_MINILIST) {
149             $this->elementStart('p');
150             $this->element('a', array('href' => common_local_url('subscribers',
151                                                                  array('nickname' => $this->profile->nickname)),
152                                       'class' => 'more'),
153                            _('All subscribers'));
154             $this->elementEnd('p');
155         }
156
157         $this->elementEnd('div');
158     }
159
160     function showStatistics()
161     {
162         // XXX: WORM cache this
163         $subs = new Subscription();
164         $subs->subscriber = $this->profile->id;
165         $subs_count = (int) $subs->count() - 1;
166
167         $subbed = new Subscription();
168         $subbed->subscribed = $this->profile->id;
169         $subbed_count = (int) $subbed->count() - 1;
170
171         $notices = new Notice();
172         $notices->profile_id = $this->profile->id;
173         $notice_count = (int) $notices->count();
174
175         $this->elementStart('div', array('id' => 'entity_statistics',
176                                          'class' => 'section'));
177
178         $this->element('h2', null, _('Statistics'));
179
180         // Other stats...?
181         $this->elementStart('dl', 'entity_user-id');
182         $this->element('dt', null, _('User ID'));
183         $this->element('dd', null, $this->profile->id);
184         $this->elementEnd('dl');
185
186         $this->elementStart('dl', 'entity_member-since');
187         $this->element('dt', null, _('Member since'));
188         $this->element('dd', null, date('j M Y',
189                                         strtotime($this->profile->created)));
190         $this->elementEnd('dl');
191
192         $this->elementStart('dl', 'entity_subscriptions');
193         $this->elementStart('dt');
194         $this->element('a', array('href' => common_local_url('subscriptions',
195                                                              array('nickname' => $this->profile->nickname))),
196                        _('Subscriptions'));
197         $this->elementEnd('dt');
198         $this->element('dd', null, (is_int($subs_count)) ? $subs_count : '0');
199         $this->elementEnd('dl');
200
201         $this->elementStart('dl', 'entity_subscribers');
202         $this->elementStart('dt');
203         $this->element('a', array('href' => common_local_url('subscribers',
204                                                              array('nickname' => $this->profile->nickname))),
205                        _('Subscribers'));
206         $this->elementEnd('dt');
207         $this->element('dd', 'subscribers', (is_int($subbed_count)) ? $subbed_count : '0');
208         $this->elementEnd('dl');
209
210         $this->elementStart('dl', 'entity_notices');
211         $this->element('dt', null, _('Notices'));
212         $this->element('dd', null, (is_int($notice_count)) ? $notice_count : '0');
213         $this->elementEnd('dl');
214
215         $this->elementEnd('div');
216     }
217
218     function showGroups()
219     {
220         $groups = $this->user->getGroups(0, GROUPS_PER_MINILIST + 1);
221
222         $this->elementStart('div', array('id' => 'entity_groups',
223                                          'class' => 'section'));
224
225         $this->element('h2', null, _('Groups'));
226
227         if ($groups) {
228             $gml = new GroupMiniList($groups, $this->user, $this);
229             $cnt = $gml->show();
230             if ($cnt == 0) {
231                 $this->element('p', null, _('(None)'));
232             }
233         }
234
235         if ($cnt > GROUPS_PER_MINILIST) {
236             $this->elementStart('p');
237             $this->element('a', array('href' => common_local_url('usergroups',
238                                                                  array('nickname' => $this->profile->nickname)),
239                                       'class' => 'more'),
240                            _('All groups'));
241             $this->elementEnd('p');
242         }
243
244         $this->elementEnd('div');
245     }
246 }
247