<?php
+
/*
* Laconica - a distributed open-source microblogging tool
* Copyright (C) 2008, Controlez-Vous, Inc.
if (!defined('LACONICA')) { exit(1); }
+require_once(INSTALLDIR.'/lib/profilelist.php');
+
# 10x8
define('AVATARS_PER_PAGE', 80);
function handle($args) {
parent::handle($args);
- $nickname = $this->arg('nickname');
- $profile = Profile::staticGet('nickname', $nickname);
- if (!$profile) {
+
+ $nickname = common_canonical_nickname($this->arg('nickname'));
+ $user = User::staticGet('nickname', $nickname);
+
+ if (!$user) {
$this->no_such_user();
return;
}
- $user = User::staticGet($profile->id);
- if (!$user) {
- $this->no_such_user();
+
+ $profile = $user->getProfile();
+
+ if (!$profile) {
+ $this->server_error(_('User without matching profile in system.'));
return;
}
+
$page = $this->arg('page');
+
if (!$page) {
$page = 1;
}
+
+ $display = $this->arg('display');
+
+ if (!$display) {
+ $display = 'list';
+ }
+
common_show_header($profile->nickname . ": " . $this->gallery_type(),
NULL, $profile,
array($this, 'show_top'));
- $this->show_gallery($profile, $page);
+
+ $this->display_links($profile, $page, $display);
+
+ $this->show_gallery($profile, $page, $display);
common_show_footer();
}
$this->get_instructions($profile));
}
- function show_gallery($profile, $page) {
+ function show_gallery($profile, $page, $display='list') {
- $subs = new Subscription();
+ $other = new Profile();
+
+ list($lst, $usr) = $this->fields();
- $this->define_subs($subs, $profile);
+ $per_page = ($display == 'list') ? PROFILES_PER_PAGE : AVATARS_PER_PAGE;
- $subs->orderBy('created DESC');
-
- # We ask for an extra one to know if we need to do another page
-
- $subs->limit((($page-1)*AVATARS_PER_PAGE), AVATARS_PER_PAGE + 1);
+ $offset = ($page-1)*$per_page;
+ $limit = $per_page + 1;
+
+ if (common_config('db','type') == 'pgsql') {
+ $lim = ' LIMIT ' . $limit . ' OFFSET ' . $offset;
+ } else {
+ $lim = ' LIMIT ' . $offset . ', ' . $limit;
+ }
- $subs_count = $subs->find();
+ # XXX: memcached results
+
+ $other->query('SELECT profile.* ' .
+ 'FROM profile JOIN subscription ' .
+ 'ON profile.id = subscription.' . $lst . ' ' .
+ 'WHERE ' . $usr . ' = ' . $profile->id . ' ' .
+ 'AND subscriber != subscribed ' .
+ 'ORDER BY subscription.created DESC, profile.id DESC ' .
+ $lim);
+
+ if ($display == 'list') {
+ $profile_list = new ProfileList($other);
+ $cnt = $profile_list->show_list();
+ } else {
+ $cnt = $this->icon_list($other);
+ }
- if ($subs_count == 0) {
- common_element('p', _('Nobody to show!'));
- return;
+ # For building the pagination URLs
+
+ $args = array('nickname' => $profile->nickname);
+
+ if ($display != 'list') {
+ $args['display'] = $display;
}
+
+ common_pagination($page > 1,
+ $cnt > $per_page,
+ $page,
+ $this->trimmed('action'),
+ $args);
+ }
+ function icon_list($other) {
+
common_element_start('ul', $this->div_class());
- for ($idx = 0; $idx < min($subs_count, AVATARS_PER_PAGE); $idx++) {
+ $cnt = 0;
+
+ while ($other->fetch()) {
- $result = $subs->fetch();
-
- if (!$result) {
- common_debug('Ran out of subscribers too early.', __FILE__);
+ $cnt++;
+
+ if ($cnt > AVATARS_PER_PAGE) {
break;
}
-
- $other = Profile::staticGet($this->get_other($subs));
-
+
common_element_start('li');
common_element_start('a', array('title' => ($other->fullname) ?
common_element_end('li');
}
-
+
common_element_end('ul');
-
- common_pagination($page > 1,
- $subs_count > AVATARS_PER_PAGE,
- $page,
- $this->trimmed('action'),
- array('nickname' => $profile->nickname));
+
+ return $cnt;
}
-
+
function gallery_type() {
return NULL;
}
return NULL;
}
- function define_subs(&$subs, &$profile) {
- return;
- }
-
- function get_other(&$subs) {
+ function fields() {
return NULL;
}
function div_class() {
return '';
}
+
+ function display_links($profile, $page, $display) {
+
+ common_element_start('p');
+
+ switch ($display) {
+ case 'list':
+ common_element('span', NULL, _('List'));
+ common_text(' | ');
+ common_element('a', array('href' => common_local_url($this->trimmed('action'),
+ array('display' => 'icons',
+ 'nickname' => $profile->nickname,
+ 'page' => 1 + floor((($page - 1) * PROFILES_PER_PAGE) / AVATARS_PER_PAGE)))),
+ _('Icons'));
+ break;
+ default:
+ common_element('a', array('href' => common_local_url($this->trimmed('action'),
+ array('nickname' => $profile->nickname,
+ 'page' => 1 + floor((($page - 1) * AVATARS_PER_PAGE) / PROFILES_PER_PAGE)))),
+ _('List'));
+ common_text(' | ');
+ common_element('span', NULL, _('Icons'));
+ break;
+ }
+
+ common_element_end('p');
+ }
}
\ No newline at end of file