We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

showstream.php 6.8 KB
Newer Older
Evan Prodromou's avatar
Evan Prodromou committed
1
<?php
Evan Prodromou's avatar
Evan Prodromou committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/* 
 * 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/>.
 */

Evan Prodromou's avatar
Evan Prodromou committed
20
if (!defined('LACONICA')) { exit(1); }
Evan Prodromou's avatar
Evan Prodromou committed
21

Evan Prodromou's avatar
Evan Prodromou committed
22 23
require_once(INSTALLDIR.'/lib/stream.php');

Evan Prodromou's avatar
Evan Prodromou committed
24 25 26 27 28 29 30 31 32
define('SUBSCRIPTIONS_PER_ROW', 5);
define('SUBSCRIPTIONS', 80);

class ShowstreamAction extends StreamAction {

	function handle($args) {
		
		parent::handle($args);

33
		$nickname = common_canonical_nickname($this->arg('nickname'));
Evan Prodromou's avatar
Evan Prodromou committed
34 35
		$user = User::staticGet('nickname', $nickname);

Evan Prodromou's avatar
Evan Prodromou committed
36 37
		if (!$user) {
			$this->no_such_user();
Evan Prodromou's avatar
Evan Prodromou committed
38 39 40 41 42 43
		} 

		$profile = $user->getProfile();

		if (!$profile) {
			common_server_error(_t('User record exists without profile.'));
Evan Prodromou's avatar
Evan Prodromou committed
44 45 46 47 48
		}
		
		# Looks like we're good; show the header
		
		common_show_header($profile->nickname);
Evan Prodromou's avatar
Evan Prodromou committed
49 50

		$cur = common_current_user();
Evan Prodromou's avatar
Evan Prodromou committed
51
		
Evan Prodromou's avatar
Evan Prodromou committed
52
		if ($cur && $profile->id == $cur->id) {
Evan Prodromou's avatar
Evan Prodromou committed
53 54
			$this->notice_form();
		}
Evan Prodromou's avatar
Evan Prodromou committed
55
	
Evan Prodromou's avatar
Evan Prodromou committed
56
		$this->show_profile($profile);
Evan Prodromou's avatar
Evan Prodromou committed
57

Evan Prodromou's avatar
Evan Prodromou committed
58
		$this->show_last_notice($profile);
Evan Prodromou's avatar
Evan Prodromou committed
59 60 61 62 63 64 65 66

		if ($cur) {
			if ($cur->isSubscribed($profile)) {
				$this->show_unsubscribe_form($profile);
			} else {
				$this->show_subscribe_form($profile);
			}
		}
Evan Prodromou's avatar
Evan Prodromou committed
67 68
		
		$this->show_statistics($profile);
Evan Prodromou's avatar
Evan Prodromou committed
69

Evan Prodromou's avatar
Evan Prodromou committed
70 71 72 73 74
		$this->show_subscriptions($profile);
		
		$this->show_notices($profile);
		
		common_show_footer();
Evan Prodromou's avatar
Evan Prodromou committed
75
	}
Evan Prodromou's avatar
Evan Prodromou committed
76 77 78
	
	function no_such_user() {
		common_user_error('No such user');
Evan Prodromou's avatar
Evan Prodromou committed
79 80
	}
	
Evan Prodromou's avatar
Evan Prodromou committed
81
	function notice_form() {
82
		common_element_start('form', array('id' => 'newnotice', 'method' => 'POST',
Evan Prodromou's avatar
Evan Prodromou committed
83 84 85
										   'action' => common_local_url('newnotice')));
		common_element('textarea', array('rows' => 4, 'cols' => 80, 'id' => 'content'));
		common_element('input', array('type' => 'submit'), 'Send');
86
		common_element_end('form');
Evan Prodromou's avatar
Evan Prodromou committed
87
	}
Evan Prodromou's avatar
Evan Prodromou committed
88
	
Evan Prodromou's avatar
Evan Prodromou committed
89
	function show_profile($profile) {
90
		common_element_start('div', 'profile');
Evan Prodromou's avatar
Evan Prodromou committed
91 92 93 94 95 96 97 98
		$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));
		}
Evan Prodromou's avatar
Evan Prodromou committed
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
		common_element('span', 'nickname', $profile->nickname);
		if ($profile->fullname) {
			if ($profile->homepage) {
				common_element('a', array('href' => $profile->homepage, 
										  'class' => 'fullname'),
							   $profile->fullname);
			} else {
				common_element('span', 'fullname', $profile->fullname);
			}
		}
		if ($profile->location) {
			common_element('span', 'location', $profile->location);
		}
		if ($profile->bio) {
			common_element('div', 'bio', $profile->bio);
		}
	}
Evan Prodromou's avatar
Evan Prodromou committed
116 117

	function show_subscribe_form($profile) {
118
		common_element_start('form', array('id' => 'subscribe', 'method' => 'POST',
Evan Prodromou's avatar
Evan Prodromou committed
119 120 121 122 123 124
										   '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'));
125
		common_element_end('form');
Evan Prodromou's avatar
Evan Prodromou committed
126 127 128
	}

	function show_unsubscribe_form($profile) {
129
		common_element_start('form', array('id' => 'unsubscribe', 'method' => 'POST',
Evan Prodromou's avatar
Evan Prodromou committed
130 131 132 133 134 135
										   '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'));
136
		common_element_end('form');
Evan Prodromou's avatar
Evan Prodromou committed
137
	}
Evan Prodromou's avatar
Evan Prodromou committed
138
	
Evan Prodromou's avatar
Evan Prodromou committed
139 140
	function show_subscriptions($profile) {
		
Evan Prodromou's avatar
Evan Prodromou committed
141
		# XXX: add a limit
Evan Prodromou's avatar
Evan Prodromou committed
142
		$subs = $profile->getLink('id', 'subscription', 'subscriber');
143
		common_element_start('div', 'subscriptions');
Evan Prodromou's avatar
Evan Prodromou committed
144 145 146 147 148 149
		
		$cnt = 0;
		
		while ($subs->fetch()) {
			$cnt++;
			if ($cnt % SUBSCRIPTIONS_PER_ROW == 1) {
150
				common_element_start('div', 'row');
Evan Prodromou's avatar
Evan Prodromou committed
151 152
			}

153
			common_element_start('a', array('title' => $subs->fullname ||
Evan Prodromou's avatar
Evan Prodromou committed
154 155 156
											           $subs->nickname,
											'href' => $subs->profileurl,
											'class' => 'subscription'));
Evan Prodromou's avatar
Evan Prodromou committed
157 158 159 160 161
			$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'));
162
			common_element_end('a');
Evan Prodromou's avatar
Evan Prodromou committed
163 164
			
			if ($cnt % SUBSCRIPTIONS_PER_ROW == 0) {
165
				common_element_end('div');
Evan Prodromou's avatar
Evan Prodromou committed
166 167 168 169 170 171 172 173
			}
			
			if ($cnt == SUBSCRIPTIONS) {
				break;
			}
		}

		common_element('a', array('href' => common_local_url('subscriptions', 
174
															 array('nickname' => $profile->nickname)),
Evan Prodromou's avatar
Evan Prodromou committed
175 176
								  'class' => 'moresubscriptions'),
					   _t('All subscriptions'));
Evan Prodromou's avatar
Evan Prodromou committed
177

178
		common_element_end('div');
Evan Prodromou's avatar
Evan Prodromou committed
179 180
	}

Evan Prodromou's avatar
Evan Prodromou committed
181
	function show_statistics($profile) {
Evan Prodromou's avatar
Evan Prodromou committed
182

Evan Prodromou's avatar
Evan Prodromou committed
183 184 185 186 187 188 189 190 191 192
		// XXX: WORM cache this
		$subs = DB_DataObject::factory('subscription');
		$subs->subscriber = $profile->id;
		$subs_count = $subs->count();
		
		$subbed = DB_DataObject::factory('subscription');
		$subbed->subscribed = $profile->id;
		$subbed_count = $subbed->count();
		
		$notices = DB_DataObject::factory('notice');
Evan Prodromou's avatar
Evan Prodromou committed
193 194
		$notices->profile_id = $profile->id;
		$notice_count = $notices->count();
Evan Prodromou's avatar
Evan Prodromou committed
195 196
		
		# Other stats...?
197
		common_element_start('dl', 'statistics');
Evan Prodromou's avatar
Evan Prodromou committed
198 199 200 201 202 203
		common_element('dt', _t('Subscriptions'));
		common_element('dd', $subs_count);
		common_element('dt', _t('Subscribers'));
		common_element('dd', $subbed_count);
		common_element('dt', _t('Notices'));
		common_element('dd', $notice_count);
204
		common_element_end('dl');
Evan Prodromou's avatar
Evan Prodromou committed
205 206 207
	}
	
	function show_notices($profile) {
Evan Prodromou's avatar
Evan Prodromou committed
208

Evan Prodromou's avatar
Evan Prodromou committed
209 210 211 212 213 214 215 216 217 218 219
		$notice = DB_DataObject::factory('notice');
		$notice->profile_id = $profile->id;
		
		$notice->orderBy('created DESC');
		
		$page = $this->arg('page') || 1;
		
		$notice->limit((($page-1)*NOTICES_PER_PAGE) + 1, NOTICES_PER_PAGE);
		
		$notice->find();

220
		common_element_start('div', 'notices');
Evan Prodromou's avatar
Evan Prodromou committed
221 222 223 224 225
		
		while ($notice->fetch()) {
			$this->show_notice($notice);
		}
		
226
		common_element_end('div');
Evan Prodromou's avatar
Evan Prodromou committed
227 228 229 230 231 232 233 234 235 236 237
	}
	
	function show_last_notice($profile) {
		$notice = DB_DataObject::factory('notice');
		$notice->profile_id = $profile->id;
		$notice->orderBy('created DESC');
		$notice->limit(1, 1);
		$notice->find();
		
		while ($notice->fetch()) {
			# FIXME: URL, image, video, audio
Evan Prodromou's avatar
Evan Prodromou committed
238 239
			common_element('span', array('class' => 'content'), 
						   $notice->content);
Evan Prodromou's avatar
Evan Prodromou committed
240 241 242 243 244
			common_element('span', array('class' => 'date'),
						   common_date_string($notice->created));
		}
	}
}