3 define('SUBSCRIPTIONS_PER_ROW', 5);
4 define('SUBSCRIPTIONS', 80);
6 class ShowstreamAction extends StreamAction {
8 function handle($args) {
10 parent::handle($args);
12 $nickname = $this->arg('profile');
13 $profile = Profile::staticGet('nickname', strtolower($nickname));
16 $this->no_such_user();
19 $user = User::staticGet($profile->id);
23 $this->no_such_user();
26 # Looks like we're good; show the header
28 common_show_header($profile->nickname);
30 if ($profile->id == current_user()->id) {
34 $this->show_profile($profile);
36 $this->show_last_notice($profile);
38 $this->show_statistics($profile);
40 $this->show_subscriptions($profile);
42 $this->show_notices($profile);
47 function no_such_user() {
48 common_user_error('No such user');
51 function notice_form() {
52 common_start_element('form', array('id' => 'newnotice', 'method' => 'POST',
53 'action' => common_local_url('newnotice')));
54 common_element('textarea', array('rows' => 4, 'cols' => 80, 'id' => 'content'));
55 common_element('input', array('type' => 'submit'), 'Send');
56 common_end_element('form');
59 function show_profile($profile) {
60 common_start_element('div', 'profile');
61 common_element('span', 'nickname', $profile->nickname);
62 if ($profile->fullname) {
63 if ($profile->homepage) {
64 common_element('a', array('href' => $profile->homepage,
65 'class' => 'fullname'),
68 common_element('span', 'fullname', $profile->fullname);
71 if ($profile->location) {
72 common_element('span', 'location', $profile->location);
75 common_element('div', 'bio', $profile->bio);
79 function show_subscriptions($profile) {
83 $subs = $profile->getLink('id', 'subscription', 'subscriber');
85 common_start_element('div', 'subscriptions');
89 while ($subs->fetch()) {
91 if ($cnt % SUBSCRIPTIONS_PER_ROW == 1) {
92 common_start_element('div', 'row');
95 common_start_element('a', array('title' => $subs->fullname ||
97 'href' => $subs->profileurl,
98 'class' => 'subscription'));
99 common_element('img', array('src' => $subs->avatar,
100 'class' => 'avatar'));
101 common_end_element('a');
103 if ($cnt % SUBSCRIPTIONS_PER_ROW == 0) {
104 common_end_element('div');
107 if ($cnt == SUBSCRIPTIONS) {
112 common_element('a', array('href' => common_local_url('subscriptions',
113 array('profile' => $profile->nickname))
114 'class' => 'moresubscriptions'),
115 _t('All subscriptions'));
117 common_end_element('div');
120 function show_statistics($profile) {
122 // XXX: WORM cache this
123 $subs = DB_DataObject::factory('subscription');
124 $subs->subscriber = $profile->id;
125 $subs_count = $subs->count();
127 $subbed = DB_DataObject::factory('subscription');
128 $subbed->subscribed = $profile->id;
129 $subbed_count = $subbed->count();
131 $notices = DB_DataObject::factory('notice');
132 $notice->profile_id = $profile->id;
133 $notice_count = $notice->count();
136 common_start_element('dl', 'statistics');
137 common_element('dt', _t('Subscriptions'));
138 common_element('dd', $subs_count);
139 common_element('dt', _t('Subscribers'));
140 common_element('dd', $subbed_count);
141 common_element('dt', _t('Notices'));
142 common_element('dd', $notice_count);
143 common_end_element('dl');
146 function show_notices($profile) {
148 $notice = DB_DataObject::factory('notice');
149 $notice->profile_id = $profile->id;
151 $notice->orderBy('created DESC');
153 $page = $this->arg('page') || 1;
155 $notice->limit((($page-1)*NOTICES_PER_PAGE) + 1, NOTICES_PER_PAGE);
159 common_start_element('div', 'notices');
161 while ($notice->fetch()) {
162 $this->show_notice($notice);
165 common_end_element('div');
168 function show_last_notice($profile) {
169 $notice = DB_DataObject::factory('notice');
170 $notice->profile_id = $profile->id;
171 $notice->orderBy('created DESC');
172 $notice->limit(1, 1);
175 while ($notice->fetch()) {
176 # FIXME: URL, image, video, audio
177 common_element('span', array('class' => 'content'), $notice->content);
178 common_element('span', array('class' => 'date'),
179 common_date_string($notice->created));