<?php
+/*
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, Controlez-Vous, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+if (!defined('LACONICA')) { exit(1); }
define('SUBSCRIPTIONS_PER_ROW', 5);
define('SUBSCRIPTIONS', 80);
parent::handle($args);
- $nickname = $this->arg('profile');
- $profile = Profile::staticGet('nickname', strtolower($nickname));
-
- if (!$profile) {
- $this->no_such_user();
- }
-
- $user = User::staticGet($profile->id);
-
+ $nickname = common_canonicalize_nickname($this->arg('profile'));
+ $user = User::staticGet('nickname', $nickname);
+
if (!$user) {
- // remote profile
$this->no_such_user();
+ }
+
+ $profile = $user->getProfile();
+
+ if (!$profile) {
+ common_server_error(_t('User record exists without profile.'));
}
# Looks like we're good; show the header
common_show_header($profile->nickname);
+
+ $cur = common_current_user();
- if ($profile->id == current_user()->id) {
+ if ($cur && $profile->id == $cur->id) {
$this->notice_form();
}
$this->show_profile($profile);
$this->show_last_notice($profile);
+
+ if ($cur) {
+ if ($cur->isSubscribed($profile)) {
+ $this->show_unsubscribe_form($profile);
+ } else {
+ $this->show_subscribe_form($profile);
+ }
+ }
$this->show_statistics($profile);
-
+
$this->show_subscriptions($profile);
$this->show_notices($profile);
function show_profile($profile) {
common_start_element('div', 'profile');
+ $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
+ if ($avatar) {
+ common_element('img', array('src' => $avatar->url,
+ 'class' => 'avatar profile',
+ 'width' => AVATAR_PROFILE_SIZE,
+ 'height' => AVATAR_PROFILE_SIZE,
+ 'title' => $profile->nickname));
+ }
common_element('span', 'nickname', $profile->nickname);
if ($profile->fullname) {
if ($profile->homepage) {
common_element('div', 'bio', $profile->bio);
}
}
+
+ function show_subscribe_form($profile) {
+ common_start_element('form', array('id' => 'subscribe', 'method' => 'POST',
+ 'action' => common_local_url('subscribe')));
+ common_element('input', array('id' => 'subscribeto',
+ 'name' => 'subscribeto',
+ 'type' => 'hidden',
+ 'value' => $profile->nickname));
+ common_element('input', array('type' => 'submit'), _t('subscribe'));
+ common_end_element('form');
+ }
+
+ function show_unsubscribe_form($profile) {
+ common_start_element('form', array('id' => 'unsubscribe', 'method' => 'POST',
+ 'action' => common_local_url('unsubscribe')));
+ common_element('input', array('id' => 'unsubscribeto',
+ 'name' => 'unsubscribeto',
+ 'type' => 'hidden',
+ 'value' => $profile->nickname));
+ common_element('input', array('type' => 'submit'), _t('unsubscribe'));
+ common_end_element('form');
+ }
function show_subscriptions($profile) {
-
- # XXX: add a limit
+ # XXX: add a limit
$subs = $profile->getLink('id', 'subscription', 'subscriber');
-
common_start_element('div', 'subscriptions');
$cnt = 0;
$subs->nickname,
'href' => $subs->profileurl,
'class' => 'subscription'));
- common_element('img', array('src' => $subs->avatar,
- 'class' => 'avatar'));
+ $avatar = $subs->getAvatar(AVATAR_MINI_SIZE);
+ common_element('img', array('src' => (($avatar) ? $avatar->url : DEFAULT_MINI_AVATAR),
+ 'width' => AVATAR_MINI_SIZE,
+ 'height' => AVATAR_MINI_SIZE,
+ 'class' => 'avatar mini'));
common_end_element('a');
if ($cnt % SUBSCRIPTIONS_PER_ROW == 0) {
}
common_element('a', array('href' => common_local_url('subscriptions',
- array('profile' => $profile->nickname))
+ array('profile' => $profile->nickname)),
'class' => 'moresubscriptions'),
_t('All subscriptions'));
-
+
common_end_element('div');
}
while ($notice->fetch()) {
# FIXME: URL, image, video, audio
- common_element('span', array('class' => 'content'), $notice->content);
+ common_element('span', array('class' => 'content'),
+ $notice->content);
common_element('span', array('class' => 'date'),
common_date_string($notice->created));
}