2011-03-02 03:35:20 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* StatusNet, the distributed open-source microblogging tool
|
|
|
|
*
|
|
|
|
* Output a user directory
|
|
|
|
*
|
|
|
|
* PHP version 5
|
|
|
|
*
|
|
|
|
* LICENCE: 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/>.
|
|
|
|
*
|
|
|
|
* @category Public
|
|
|
|
* @package StatusNet
|
|
|
|
* @author Zach Copley <zach@status.net>
|
|
|
|
* @copyright 2011 StatusNet, Inc.
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
|
|
|
* @link http://status.net/
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!defined('STATUSNET'))
|
|
|
|
{
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
require_once INSTALLDIR . '/lib/publicgroupnav.php';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* User directory
|
|
|
|
*
|
|
|
|
* @category Personal
|
|
|
|
* @package StatusNet
|
|
|
|
* @author Zach Copley <zach@status.net>
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
|
|
|
* @link http://status.net/
|
|
|
|
*/
|
|
|
|
class UserdirectoryAction extends Action
|
|
|
|
{
|
2011-03-03 04:21:15 +00:00
|
|
|
/**
|
2011-03-05 01:55:56 +00:00
|
|
|
* The page we're on
|
|
|
|
*
|
|
|
|
* @var integer
|
2011-03-03 04:21:15 +00:00
|
|
|
*/
|
2011-03-05 09:55:52 +00:00
|
|
|
public $page;
|
2011-03-02 03:35:20 +00:00
|
|
|
|
2011-03-03 04:21:15 +00:00
|
|
|
/**
|
2011-03-05 09:55:52 +00:00
|
|
|
* What to filter the search results by
|
2011-03-05 01:55:56 +00:00
|
|
|
*
|
|
|
|
* @var string
|
2011-03-03 04:21:15 +00:00
|
|
|
*/
|
2011-03-05 09:55:52 +00:00
|
|
|
public $filter;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Column to sort by
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $sort;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* How to order search results, ascending or descending
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $reverse;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Query
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $q;
|
2011-03-02 03:35:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Title of the page
|
|
|
|
*
|
|
|
|
* @return string Title of the page
|
|
|
|
*/
|
|
|
|
function title()
|
|
|
|
{
|
|
|
|
// @fixme: This looks kinda gross
|
|
|
|
|
2011-03-03 04:21:15 +00:00
|
|
|
if ($this->filter == 'all') {
|
2011-03-02 03:35:20 +00:00
|
|
|
if ($this->page != 1) {
|
2011-03-07 06:07:42 +00:00
|
|
|
return(sprintf(_m('User Directory, page %d'), $this->page));
|
2011-03-02 03:35:20 +00:00
|
|
|
}
|
2011-03-07 06:07:42 +00:00
|
|
|
return _m('User directory');
|
|
|
|
} else if ($this->page == 1) {
|
2011-03-02 03:35:20 +00:00
|
|
|
return sprintf(
|
2011-03-07 06:07:42 +00:00
|
|
|
_m('User directory - %s'),
|
|
|
|
strtoupper($this->filter)
|
2011-03-02 03:35:20 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return sprintf(
|
2011-03-07 06:07:42 +00:00
|
|
|
_m('User directory - %s, page %d'),
|
|
|
|
strtoupper($this->filter),
|
2011-03-02 03:35:20 +00:00
|
|
|
$this->page
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instructions for use
|
|
|
|
*
|
|
|
|
* @return instructions for use
|
|
|
|
*/
|
|
|
|
function getInstructions()
|
|
|
|
{
|
2011-03-07 06:07:42 +00:00
|
|
|
// TRANS: %%site.name%% is the name of the StatusNet site.
|
|
|
|
return _(
|
|
|
|
'Search for people on %%site.name%% by their name, '
|
|
|
|
. 'location, or interests. Separate the terms by spaces; '
|
|
|
|
. ' they must be 3 characters or more.'
|
|
|
|
);
|
2011-03-02 03:35:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is this page read-only?
|
|
|
|
*
|
|
|
|
* @return boolean true
|
|
|
|
*/
|
|
|
|
function isReadOnly($args)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Take arguments for running
|
|
|
|
*
|
|
|
|
* @param array $args $_REQUEST args
|
|
|
|
*
|
|
|
|
* @return boolean success flag
|
|
|
|
*/
|
|
|
|
function prepare($args)
|
|
|
|
{
|
|
|
|
parent::prepare($args);
|
|
|
|
|
2011-03-05 09:55:52 +00:00
|
|
|
$this->page = ($this->arg('page')) ? ($this->arg('page') + 0) : 1;
|
|
|
|
$this->filter = $this->arg('filter', 'all');
|
|
|
|
$this->reverse = $this->boolean('reverse');
|
|
|
|
$this->q = $this->trimmed('q');
|
|
|
|
$this->sort = $this->arg('sort', 'nickname');
|
2011-03-04 05:12:24 +00:00
|
|
|
|
2011-03-02 03:35:20 +00:00
|
|
|
common_set_returnto($this->selfUrl());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle request
|
|
|
|
*
|
|
|
|
* Shows the page
|
|
|
|
*
|
|
|
|
* @param array $args $_REQUEST args; handled in prepare()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function handle($args)
|
|
|
|
{
|
|
|
|
parent::handle($args);
|
|
|
|
$this->showPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the page notice
|
|
|
|
*
|
|
|
|
* Shows instructions for the page
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function showPageNotice()
|
|
|
|
{
|
|
|
|
$instr = $this->getInstructions();
|
|
|
|
$output = common_markup_to_html($instr);
|
|
|
|
|
|
|
|
$this->elementStart('div', 'instructions');
|
|
|
|
$this->raw($output);
|
|
|
|
$this->elementEnd('div');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Local navigation
|
|
|
|
*
|
|
|
|
* This page is part of the public group, so show that.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function showLocalNav()
|
|
|
|
{
|
|
|
|
$nav = new PublicGroupNav($this);
|
|
|
|
$nav->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Content area
|
|
|
|
*
|
|
|
|
* Shows the list of popular notices
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function showContent()
|
|
|
|
{
|
2011-03-05 09:55:52 +00:00
|
|
|
$this->showForm();
|
2011-03-02 03:35:20 +00:00
|
|
|
|
2011-03-03 04:21:15 +00:00
|
|
|
$this->elementStart('div', array('id' => 'user_directory'));
|
|
|
|
|
2011-03-07 22:32:14 +00:00
|
|
|
$alphaNav = new AlphaNav($this, false, false, array('0-9', 'All'));
|
2011-03-02 03:35:20 +00:00
|
|
|
$alphaNav->show();
|
|
|
|
|
2011-03-05 09:55:52 +00:00
|
|
|
$profile = null;
|
2011-03-02 03:35:20 +00:00
|
|
|
$profile = $this->getUsers();
|
|
|
|
$cnt = 0;
|
|
|
|
|
|
|
|
if (!empty($profile)) {
|
2011-03-04 05:12:24 +00:00
|
|
|
$profileList = new SortableSubscriptionList(
|
2011-03-02 03:35:20 +00:00
|
|
|
$profile,
|
|
|
|
common_current_user(),
|
|
|
|
$this
|
|
|
|
);
|
|
|
|
|
|
|
|
$cnt = $profileList->show();
|
2011-03-05 09:55:52 +00:00
|
|
|
$profile->free();
|
2011-03-02 03:35:20 +00:00
|
|
|
|
|
|
|
if (0 == $cnt) {
|
|
|
|
$this->showEmptyListMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-05 09:55:52 +00:00
|
|
|
$args = array();
|
|
|
|
if (isset($this->q)) {
|
|
|
|
$args['q'] = $this->q;
|
|
|
|
} else {
|
|
|
|
$args['filter'] = $this->filter;
|
|
|
|
}
|
|
|
|
|
2011-03-03 04:21:15 +00:00
|
|
|
$this->pagination(
|
|
|
|
$this->page > 1,
|
|
|
|
$cnt > PROFILES_PER_PAGE,
|
|
|
|
$this->page,
|
|
|
|
'userdirectory',
|
2011-03-05 09:55:52 +00:00
|
|
|
$args
|
2011-03-03 04:21:15 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->elementEnd('div');
|
2011-03-02 03:35:20 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-03-05 09:55:52 +00:00
|
|
|
function showForm($error=null)
|
|
|
|
{
|
|
|
|
$this->elementStart(
|
|
|
|
'form',
|
|
|
|
array(
|
|
|
|
'method' => 'get',
|
|
|
|
'id' => 'form_search',
|
|
|
|
'class' => 'form_settings',
|
|
|
|
'action' => common_local_url('userdirectory')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->elementStart('fieldset');
|
|
|
|
|
|
|
|
$this->element('legend', null, _('Search site'));
|
|
|
|
$this->elementStart('ul', 'form_data');
|
|
|
|
$this->elementStart('li');
|
|
|
|
|
|
|
|
$this->input('q', _('Keyword(s)'), $this->q);
|
|
|
|
|
|
|
|
$this->submit('search', _m('BUTTON','Search'));
|
|
|
|
$this->elementEnd('li');
|
|
|
|
$this->elementEnd('ul');
|
|
|
|
$this->elementEnd('fieldset');
|
|
|
|
$this->elementEnd('form');
|
|
|
|
}
|
|
|
|
|
2011-03-02 03:35:20 +00:00
|
|
|
/*
|
2011-03-05 01:55:56 +00:00
|
|
|
* Get users filtered by the current filter, sort key,
|
|
|
|
* sort order, and page
|
2011-03-02 03:35:20 +00:00
|
|
|
*/
|
|
|
|
function getUsers()
|
|
|
|
{
|
|
|
|
$profile = new Profile();
|
|
|
|
|
2011-03-05 01:25:58 +00:00
|
|
|
$offset = ($this->page - 1) * PROFILES_PER_PAGE;
|
|
|
|
$limit = PROFILES_PER_PAGE + 1;
|
2011-03-03 04:21:15 +00:00
|
|
|
|
2011-03-05 09:55:52 +00:00
|
|
|
if (isset($this->q)) {
|
|
|
|
// User is searching via query
|
|
|
|
$search_engine = $profile->getSearchEngine('profile');
|
|
|
|
|
|
|
|
$mode = 'reverse_chron';
|
|
|
|
|
|
|
|
if ($this->sort == 'nickname') {
|
|
|
|
if ($this->reverse) {
|
|
|
|
$mode = 'nickname_desc';
|
|
|
|
} else {
|
|
|
|
$mode = 'nickname_asc';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ($this->reverse) {
|
|
|
|
$mode = 'chron';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$search_engine->set_sort_mode($mode);
|
|
|
|
$search_engine->limit($offset, $limit);
|
|
|
|
$search_engine->query($this->q);
|
|
|
|
|
|
|
|
$profile->find();
|
|
|
|
} else {
|
|
|
|
// User is browsing via AlphaNav
|
|
|
|
$sort = $this->getSortKey();
|
|
|
|
$sql = 'SELECT profile.* FROM profile, user WHERE profile.id = user.id';
|
|
|
|
|
2011-03-07 22:32:14 +00:00
|
|
|
switch($this->filter)
|
|
|
|
{
|
|
|
|
case 'all':
|
|
|
|
// NOOP
|
|
|
|
break;
|
|
|
|
case '0-9':
|
|
|
|
$sql .=
|
|
|
|
' AND LEFT(profile.nickname, 1) BETWEEN \'0\' AND \'9\'';
|
|
|
|
break;
|
|
|
|
default:
|
2011-03-05 09:55:52 +00:00
|
|
|
$sql .= sprintf(
|
|
|
|
' AND LEFT(LOWER(profile.nickname), 1) = \'%s\'',
|
|
|
|
$this->filter
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-03-05 01:25:58 +00:00
|
|
|
$sql .= sprintf(
|
2011-03-05 09:55:52 +00:00
|
|
|
' ORDER BY profile.%s %s, profile.nickname ASC LIMIT %d, %d',
|
|
|
|
$sort,
|
|
|
|
$this->reverse ? 'DESC' : 'ASC',
|
|
|
|
$offset,
|
|
|
|
$limit
|
2011-03-02 03:35:20 +00:00
|
|
|
);
|
2011-03-03 04:21:15 +00:00
|
|
|
|
2011-03-05 09:55:52 +00:00
|
|
|
$profile->query($sql);
|
|
|
|
}
|
2011-03-02 03:35:20 +00:00
|
|
|
|
|
|
|
return $profile;
|
|
|
|
}
|
|
|
|
|
2011-03-04 05:12:24 +00:00
|
|
|
/**
|
|
|
|
* Filter the sort parameter
|
|
|
|
*
|
|
|
|
* @return string a column name for sorting
|
|
|
|
*/
|
|
|
|
function getSortKey()
|
|
|
|
{
|
|
|
|
switch ($this->sort) {
|
|
|
|
case 'nickname':
|
|
|
|
return $this->sort;
|
|
|
|
break;
|
|
|
|
case 'created':
|
|
|
|
return $this->sort;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 'nickname';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-02 03:35:20 +00:00
|
|
|
/**
|
|
|
|
* Show a nice message when there's no search results
|
|
|
|
*/
|
|
|
|
function showEmptyListMessage()
|
|
|
|
{
|
2011-03-07 06:07:42 +00:00
|
|
|
if (!empty($this->filter) && ($this->filter != 'all')) {
|
|
|
|
$this->element(
|
|
|
|
'p',
|
|
|
|
'error',
|
|
|
|
sprintf(
|
|
|
|
_m('No users starting with %s'),
|
|
|
|
$this->filter
|
|
|
|
)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$this->element('p', 'error', _('No results.'));
|
|
|
|
$message = _m(<<<E_O_T
|
|
|
|
* Make sure all words are spelled correctly.
|
|
|
|
* Try different keywords.
|
|
|
|
* Try more general keywords.
|
|
|
|
* Try fewer keywords.
|
|
|
|
E_O_T
|
|
|
|
);
|
|
|
|
$this->elementStart('div', 'help instructions');
|
|
|
|
$this->raw(common_markup_to_html($message));
|
|
|
|
$this->elementEnd('div');
|
|
|
|
}
|
2011-03-02 03:35:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|