$user = User::staticGet('nickname', $nickname);
if (!$user) {
- $this->no_such_user();
+ $this->client_error(_('No such user.'));
return;
}
$profile = $user->getProfile();
if (!$profile) {
- common_server_error(_t('User record exists without profile.'));
+ common_server_error(_('User has no profile.'));
return;
}
# Looks like we're good; show the header
- common_show_header($profile->nickname . _t(" and friends"));
+ common_show_header(sprintf(_("%s and friends"), $profile->nickname),
+ array($this, 'show_header'), $user,
+ array($this, 'show_top'));
- $cur = common_current_user();
-
- if ($cur && $profile->id == $cur->id) {
- common_notice_form();
- }
+ $this->show_notices($user);
- $this->show_notices($profile);
-
common_show_footer();
}
- function show_notices($profile) {
-
- $notice = DB_DataObject::factory('notice');
-
- # XXX: chokety and bad
-
- $notice->whereAdd('EXISTS (SELECT subscribed from subscription where subscriber = '.$profile->id.' and subscribed = notice.profile_id)', 'OR');
- $notice->whereAdd('profile_id = ' . $profile->id, 'OR');
-
- $notice->orderBy('created DESC');
+ function show_header($user) {
+ common_element('link', array('rel' => 'alternate',
+ 'href' => common_local_url('allrss', array('nickname' =>
+ $user->nickname)),
+ 'type' => 'application/rss+xml',
+ 'title' => sprintf(_('Feed for friends of %s'), $user->nickname)));
+ }
- $page = $this->arg('page') || 1;
+ function show_top($user) {
+ $cur = common_current_user();
- $notice->limit((($page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE);
+ if ($cur && $cur->id == $user->id) {
+ common_notice_form('all');
+ }
- $notice->find();
+ $this->views_menu();
+ }
- common_element_start('div', 'notices width100');
- common_element('h2', 'notices', _t('Notices'));
+ function show_notices($user) {
- while ($notice->fetch()) {
+ $page = $this->trimmed('page');
+ if (!$page) {
+ $page = 1;
+ }
+
+ $notice = $user->noticesWithFriends(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
+
+ common_element_start('ul', array('id' => 'notices'));
+
+ $cnt = 0;
+
+ while ($notice->fetch() && $cnt <= NOTICES_PER_PAGE) {
+ $cnt++;
+
+ if ($cnt > NOTICES_PER_PAGE) {
+ break;
+ }
+
$this->show_notice($notice);
}
+ common_element_end('ul');
- # XXX: show a link for the next page
- common_element_end('div');
+ common_pagination($page > 1, $cnt > NOTICES_PER_PAGE,
+ $page, 'all', array('nickname' => $user->nickname));
}
}