3 * StatusNet, the distributed open-source microblogging tool
5 * Common parent of Personal and Profile actions
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.
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.
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/>.
24 * @author Evan Prodromou <evan@status.net>
25 * @author Sarven Capadisli <csarven@status.net>
26 * @copyright 2008-2011 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28 * @link http://status.net/
31 if (!defined('GNUSOCIAL')) { exit(1); }
34 * Profile action common superclass
36 * Abstracts out common code from profile and personal tabs
40 * @author Evan Prodromou <evan@status.net>
41 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
42 * @link http://status.net/
44 abstract class ProfileAction extends ManagedAction
49 protected $target = null; // Profile that we're showing
51 protected function prepare(array $args=array())
53 // this will call ->doPreparation() which lower classes can use
54 parent::prepare($args);
56 if ($this->target->hasRole(Profile_role::SILENCED)
57 && (!$this->scoped instanceof Profile || !$this->scoped->hasRight(Right::SILENCEUSER))) {
58 throw new ClientException(_('This profile has been silenced by site moderators'), 403);
61 // backwards compatibility until all actions are fixed to use $this->target
62 $this->profile = $this->target;
64 $this->tag = $this->trimmed('tag');
65 $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
66 common_set_returnto($this->selfUrl());
68 // fetch the actual stream stuff
69 $this->profileActionPreparation();
74 public function getTarget()
79 function isReadOnly($args)
84 function showSections()
86 $this->showSubscriptions();
87 $this->showSubscribers();
90 $this->showStatistics();
94 * Convenience function for common pattern of links to subscription/groups sections.
96 * @param string $actionClass
97 * @param string $title
98 * @param string $cssClass
100 private function statsSectionLink($actionClass, $title, $cssClass='')
102 $this->element('a', array('href' => common_local_url($actionClass,
103 array('nickname' => $this->target->getNickname())),
104 'class' => $cssClass),
108 function showSubscriptions()
110 $this->elementStart('div', array('id' => 'entity_subscriptions',
111 'class' => 'section'));
112 if (Event::handle('StartShowSubscriptionsMiniList', array($this))) {
113 $this->elementStart('h2');
114 // TRANS: H2 text for user subscription statistics.
115 $this->statsSectionLink('subscriptions', _('Following'));
117 $this->text($this->target->subscriptionCount());
118 $this->elementEnd('h2');
121 $profile = $this->target->getSubscribed(0, PROFILES_PER_MINILIST + 1);
122 $pml = new ProfileMiniList($profile, $this);
124 } catch (NoResultException $e) {
125 // TRANS: Text for user subscription statistics if the user has no subscription
126 $this->element('p', null, _('(None)'));
129 Event::handle('EndShowSubscriptionsMiniList', array($this));
131 $this->elementEnd('div');
134 function showSubscribers()
136 $this->elementStart('div', array('id' => 'entity_subscribers',
137 'class' => 'section'));
139 if (Event::handle('StartShowSubscribersMiniList', array($this))) {
141 $this->elementStart('h2');
142 // TRANS: H2 text for user subscriber statistics.
143 $this->statsSectionLink('subscribers', _('Followers'));
145 $this->text($this->target->subscriberCount());
146 $this->elementEnd('h2');
149 $profile = $this->target->getSubscribers(0, PROFILES_PER_MINILIST + 1);
150 $sml = new SubscribersMiniList($profile, $this);
152 } catch (NoResultException $e) {
153 // TRANS: Text for user subscriber statistics if user has no subscribers.
154 $this->element('p', null, _('(None)'));
157 Event::handle('EndShowSubscribersMiniList', array($this));
160 $this->elementEnd('div');
163 function showStatistics()
165 $notice_count = $this->target->noticeCount();
166 $age_days = (time() - strtotime($this->target->created)) / 86400;
168 // Rather than extrapolating out to a bajillion...
171 $daily_count = round($notice_count / $age_days);
173 $this->elementStart('div', array('id' => 'entity_statistics',
174 'class' => 'section'));
176 // TRANS: H2 text for user statistics.
177 $this->element('h2', null, _('Statistics'));
179 $profile = $this->target;
180 $actionParams = array('nickname' => $profile->nickname);
184 // TRANS: Label for user statistics.
185 'label' => _('User ID'),
186 'value' => $profile->id,
189 'id' => 'member-since',
190 // TRANS: Label for user statistics.
191 'label' => _('Member since'),
192 'value' => date('j M Y', strtotime($profile->created))
196 // TRANS: Label for user statistics.
197 'label' => _('Notices'),
198 'value' => $notice_count,
201 'id' => 'daily_notices',
202 // TRANS: Label for user statistics.
203 // TRANS: Average count of posts made per day since account registration.
204 'label' => _('Daily average'),
205 'value' => $daily_count
209 // Give plugins a chance to add stats entries
210 Event::handle('ProfileStats', array($profile, &$stats));
212 foreach ($stats as $row) {
213 $this->showStatsRow($row);
215 $this->elementEnd('div');
218 private function showStatsRow($row)
220 $this->elementStart('dl', 'entity_' . $row['id']);
221 $this->elementStart('dt');
222 if (!empty($row['link'])) {
223 $this->element('a', array('href' => $row['link']), $row['label']);
225 $this->text($row['label']);
227 $this->elementEnd('dt');
228 $this->element('dd', null, $row['value']);
229 $this->elementEnd('dl');
232 function showGroups()
234 $groups = $this->target->getGroups(0, GROUPS_PER_MINILIST + 1);
236 $this->elementStart('div', array('id' => 'entity_groups',
237 'class' => 'section'));
238 if (Event::handle('StartShowGroupsMiniList', array($this))) {
239 $this->elementStart('h2');
240 // TRANS: H2 text for user group membership statistics.
241 $this->statsSectionLink('usergroups', _('Groups'));
243 $this->text($this->target->getGroupCount());
244 $this->elementEnd('h2');
246 if ($groups instanceof User_group) {
247 $gml = new GroupMiniList($groups, $this->target, $this);
250 // TRANS: Text for user user group membership statistics if user is not a member of any group.
251 $this->element('p', null, _('(None)'));
254 Event::handle('EndShowGroupsMiniList', array($this));
256 $this->elementEnd('div');
261 $lists = $this->target->getLists($this->scoped);
264 $this->elementStart('div', array('id' => 'entity_lists',
265 'class' => 'section'));
267 if (Event::handle('StartShowListsMiniList', array($this))) {
269 $url = common_local_url('peopletagsbyuser',
270 array('nickname' => $this->target->getNickname()));
272 $this->elementStart('h2');
274 array('href' => $url),
275 // TRANS: H2 text for user list membership statistics.
278 $this->text($lists->N);
279 $this->elementEnd('h2');
281 $this->elementStart('ul');
286 while ($lists->fetch()) {
287 if (!empty($lists->mainpage)) {
288 $url = $lists->mainpage;
290 $url = common_local_url('showprofiletag',
291 array('tagger' => $this->target->getNickname(),
292 'tag' => $lists->tag));
300 $this->element('a', array('href' => $url),
304 $this->elementEnd('ul');
306 Event::handle('EndShowListsMiniList', array($this));
308 $this->elementEnd('div');
313 class SubscribersMiniList extends ProfileMiniList
315 function newListItem($profile)
317 return new SubscribersMiniListItem($profile, $this->action);
321 class SubscribersMiniListItem extends ProfileMiniListItem
323 function linkAttributes()
325 $aAttrs = parent::linkAttributes();
326 if (common_config('nofollow', 'subscribers')) {
327 $aAttrs['rel'] .= ' nofollow';