2011-03-02 12:35:20 +09: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/
|
|
|
|
*/
|
|
|
|
|
2019-06-02 21:46:39 +09:00
|
|
|
if (!defined('GNUSOCIAL')) {
|
|
|
|
exit(1);
|
|
|
|
}
|
2011-03-02 12:35:20 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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/
|
|
|
|
*/
|
2015-02-18 21:37:06 +09:00
|
|
|
class UserdirectoryAction extends ManagedAction
|
2011-03-02 12:35:20 +09:00
|
|
|
{
|
2011-03-03 13:21:15 +09:00
|
|
|
/**
|
2011-03-05 10:55:56 +09:00
|
|
|
* The page we're on
|
|
|
|
*
|
|
|
|
* @var integer
|
2011-03-03 13:21:15 +09:00
|
|
|
*/
|
2011-03-05 18:55:52 +09:00
|
|
|
public $page;
|
2011-03-02 12:35:20 +09:00
|
|
|
|
2011-03-03 13:21:15 +09:00
|
|
|
/**
|
2011-03-05 18:55:52 +09:00
|
|
|
* What to filter the search results by
|
2011-03-05 10:55:56 +09:00
|
|
|
*
|
|
|
|
* @var string
|
2011-03-03 13:21:15 +09:00
|
|
|
*/
|
2011-03-05 18:55:52 +09: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 12:35:20 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Title of the page
|
|
|
|
*
|
|
|
|
* @return string Title of the page
|
|
|
|
*/
|
2019-06-02 21:46:39 +09:00
|
|
|
public function title()
|
2011-03-02 12:35:20 +09:00
|
|
|
{
|
2011-06-05 18:44:01 +09:00
|
|
|
// @todo fixme: This looks kinda gross
|
2011-03-02 12:35:20 +09:00
|
|
|
|
2011-03-03 13:21:15 +09:00
|
|
|
if ($this->filter == 'all') {
|
2011-03-02 12:35:20 +09:00
|
|
|
if ($this->page != 1) {
|
2011-06-05 18:44:01 +09:00
|
|
|
// TRANS: Page title for user directory. %d is a page number.
|
2011-03-07 15:07:42 +09:00
|
|
|
return(sprintf(_m('User Directory, page %d'), $this->page));
|
2011-03-02 12:35:20 +09:00
|
|
|
}
|
2011-06-05 18:44:01 +09:00
|
|
|
// TRANS: Page title for user directory.
|
2011-03-07 15:07:42 +09:00
|
|
|
return _m('User directory');
|
2019-06-02 21:46:39 +09:00
|
|
|
} elseif ($this->page == 1) {
|
2011-03-02 12:35:20 +09:00
|
|
|
return sprintf(
|
2011-06-05 18:44:01 +09:00
|
|
|
// TRANS: Page title for user directory. %s is the applied filter.
|
2011-03-07 15:07:42 +09:00
|
|
|
_m('User directory - %s'),
|
|
|
|
strtoupper($this->filter)
|
2011-03-02 12:35:20 +09:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return sprintf(
|
2011-06-05 18:44:01 +09:00
|
|
|
// TRANS: Page title for user directory.
|
|
|
|
// TRANS: %1$s is the applied filter, %2$d is a page number.
|
|
|
|
_m('User directory - %1$s, page %2$d'),
|
2011-03-07 15:07:42 +09:00
|
|
|
strtoupper($this->filter),
|
2011-03-02 12:35:20 +09:00
|
|
|
$this->page
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instructions for use
|
|
|
|
*
|
|
|
|
* @return instructions for use
|
|
|
|
*/
|
2019-06-02 21:46:39 +09:00
|
|
|
public function getInstructions()
|
2011-03-02 12:35:20 +09:00
|
|
|
{
|
2011-03-07 15:07:42 +09:00
|
|
|
// TRANS: %%site.name%% is the name of the StatusNet site.
|
2011-06-05 18:44:01 +09:00
|
|
|
return _m('Search for people on %%site.name%% by their name, '
|
2019-06-02 21:46:39 +09:00
|
|
|
. 'location, or interests. Separate the terms by spaces; '
|
|
|
|
. ' they must be 3 characters or more.');
|
2011-03-02 12:35:20 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is this page read-only?
|
|
|
|
*
|
|
|
|
* @return boolean true
|
|
|
|
*/
|
2019-06-02 21:46:39 +09:00
|
|
|
public function isReadOnly($args)
|
2011-03-02 12:35:20 +09:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-02-18 21:37:06 +09:00
|
|
|
protected function doPreparation()
|
2011-03-02 12:35:20 +09:00
|
|
|
{
|
2011-03-05 18:55:52 +09: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 14:12:24 +09:00
|
|
|
|
2011-03-02 12:35:20 +09:00
|
|
|
common_set_returnto($this->selfUrl());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the page notice
|
|
|
|
*
|
|
|
|
* Shows instructions for the page
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-06-02 21:46:39 +09:00
|
|
|
public function showPageNotice()
|
2011-03-02 12:35:20 +09:00
|
|
|
{
|
|
|
|
$instr = $this->getInstructions();
|
|
|
|
$output = common_markup_to_html($instr);
|
|
|
|
|
|
|
|
$this->elementStart('div', 'instructions');
|
|
|
|
$this->raw($output);
|
|
|
|
$this->elementEnd('div');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Content area
|
|
|
|
*
|
|
|
|
* Shows the list of popular notices
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-06-02 21:46:39 +09:00
|
|
|
public function showContent()
|
2011-03-02 12:35:20 +09:00
|
|
|
{
|
2011-03-05 18:55:52 +09:00
|
|
|
$this->showForm();
|
2011-03-02 12:35:20 +09:00
|
|
|
|
2019-06-02 21:46:39 +09:00
|
|
|
$this->elementStart('div', ['id' => 'profile_directory']);
|
2011-03-03 13:21:15 +09:00
|
|
|
|
2019-06-02 21:46:39 +09:00
|
|
|
$alphaNav = new AlphaNav($this, false, false, ['0-9', 'All']);
|
2011-03-02 12:35:20 +09:00
|
|
|
$alphaNav->show();
|
|
|
|
|
2011-03-05 18:55:52 +09:00
|
|
|
$profile = null;
|
2011-03-02 12:35:20 +09:00
|
|
|
$profile = $this->getUsers();
|
|
|
|
$cnt = 0;
|
|
|
|
|
|
|
|
if (!empty($profile)) {
|
2011-03-04 14:12:24 +09:00
|
|
|
$profileList = new SortableSubscriptionList(
|
2011-03-02 12:35:20 +09:00
|
|
|
$profile,
|
|
|
|
common_current_user(),
|
|
|
|
$this
|
|
|
|
);
|
|
|
|
|
|
|
|
$cnt = $profileList->show();
|
2011-03-05 18:55:52 +09:00
|
|
|
$profile->free();
|
2011-03-02 12:35:20 +09:00
|
|
|
|
|
|
|
if (0 == $cnt) {
|
|
|
|
$this->showEmptyListMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-02 21:46:39 +09:00
|
|
|
$args = [];
|
2011-03-05 18:55:52 +09:00
|
|
|
if (isset($this->q)) {
|
|
|
|
$args['q'] = $this->q;
|
2012-06-19 12:21:57 +09:00
|
|
|
} elseif (isset($this->filter) && $this->filter != 'all') {
|
2011-03-05 18:55:52 +09:00
|
|
|
$args['filter'] = $this->filter;
|
|
|
|
}
|
2014-10-20 23:24:53 +09:00
|
|
|
|
|
|
|
if (isset($this->sort)) {
|
|
|
|
$args['sort'] = $this->sort;
|
2019-06-02 21:46:39 +09:00
|
|
|
}
|
2014-10-20 23:24:53 +09:00
|
|
|
if (!empty($this->reverse)) {
|
|
|
|
$args['reverse'] = $this->reverse;
|
|
|
|
}
|
2011-03-05 18:55:52 +09:00
|
|
|
|
2011-03-03 13:21:15 +09:00
|
|
|
$this->pagination(
|
|
|
|
$this->page > 1,
|
|
|
|
$cnt > PROFILES_PER_PAGE,
|
|
|
|
$this->page,
|
|
|
|
'userdirectory',
|
2011-03-05 18:55:52 +09:00
|
|
|
$args
|
2011-03-03 13:21:15 +09:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->elementEnd('div');
|
2011-03-02 12:35:20 +09:00
|
|
|
}
|
|
|
|
|
2019-06-02 21:46:39 +09:00
|
|
|
public function showForm($error=null)
|
2011-03-05 18:55:52 +09:00
|
|
|
{
|
2019-06-02 21:46:39 +09:00
|
|
|
$this->elementStart('form',
|
|
|
|
['method' => 'get',
|
|
|
|
'id' => 'form_search',
|
|
|
|
'class' => 'form_settings',
|
|
|
|
'action' => common_local_url('userdirectory')]);
|
2011-03-05 18:55:52 +09:00
|
|
|
|
|
|
|
$this->elementStart('fieldset');
|
|
|
|
|
2011-06-05 18:44:01 +09:00
|
|
|
// TRANS: Fieldset legend.
|
2011-03-31 05:30:23 +09:00
|
|
|
$this->element('legend', null, _m('Search site'));
|
2011-03-05 18:55:52 +09:00
|
|
|
$this->elementStart('ul', 'form_data');
|
|
|
|
$this->elementStart('li');
|
|
|
|
|
2011-06-05 18:44:01 +09:00
|
|
|
// TRANS: Field label for user directory filter.
|
2011-03-31 05:30:23 +09:00
|
|
|
$this->input('q', _m('Keyword(s)'), $this->q);
|
2011-03-05 18:55:52 +09:00
|
|
|
|
2011-06-05 18:44:01 +09:00
|
|
|
// TRANS: Button text.
|
2019-06-02 21:46:39 +09:00
|
|
|
$this->submit('search', _m('BUTTON', 'Search'));
|
2011-03-05 18:55:52 +09:00
|
|
|
$this->elementEnd('li');
|
|
|
|
$this->elementEnd('ul');
|
|
|
|
$this->elementEnd('fieldset');
|
|
|
|
$this->elementEnd('form');
|
|
|
|
}
|
|
|
|
|
2011-03-02 12:35:20 +09:00
|
|
|
/*
|
2011-03-05 10:55:56 +09:00
|
|
|
* Get users filtered by the current filter, sort key,
|
|
|
|
* sort order, and page
|
2011-03-02 12:35:20 +09:00
|
|
|
*/
|
2019-06-02 21:46:39 +09:00
|
|
|
public function getUsers()
|
2011-03-02 12:35:20 +09:00
|
|
|
{
|
|
|
|
$profile = new Profile();
|
|
|
|
|
2015-02-18 21:37:06 +09:00
|
|
|
// Comment this out or disable to get global profile searches
|
2019-06-02 21:46:39 +09:00
|
|
|
$profile->joinAdd(['id', 'user:id']);
|
2015-02-18 21:37:06 +09:00
|
|
|
|
2011-03-05 10:25:58 +09:00
|
|
|
$offset = ($this->page - 1) * PROFILES_PER_PAGE;
|
|
|
|
$limit = PROFILES_PER_PAGE + 1;
|
2011-03-03 13:21:15 +09:00
|
|
|
|
2015-02-18 21:37:06 +09:00
|
|
|
if (!empty($this->q)) {
|
2019-06-02 21:46:39 +09:00
|
|
|
// 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();
|
2011-03-05 18:55:52 +09:00
|
|
|
} else {
|
|
|
|
// User is browsing via AlphaNav
|
|
|
|
|
2015-02-18 21:37:06 +09:00
|
|
|
switch ($this->filter) {
|
2011-03-08 07:32:14 +09:00
|
|
|
case 'all':
|
|
|
|
// NOOP
|
|
|
|
break;
|
|
|
|
case '0-9':
|
2015-02-18 21:37:06 +09:00
|
|
|
$profile->whereAdd(sprintf('LEFT(%1$s.%2$s, 1) BETWEEN %3$s AND %4$s',
|
2019-06-02 21:46:39 +09:00
|
|
|
$profile->escapedTableName(),
|
|
|
|
'nickname',
|
|
|
|
$profile->_quote("0"),
|
|
|
|
$profile->_quote("9")));
|
2011-03-08 07:32:14 +09:00
|
|
|
break;
|
|
|
|
default:
|
2015-02-18 21:37:06 +09:00
|
|
|
$profile->whereAdd(sprintf('LEFT(LOWER(%1$s.%2$s), 1) = %3$s',
|
2019-06-02 21:46:39 +09:00
|
|
|
$profile->escapedTableName(),
|
|
|
|
'nickname',
|
|
|
|
$profile->_quote($this->filter)));
|
2011-03-05 18:55:52 +09:00
|
|
|
}
|
|
|
|
|
2015-02-18 21:37:06 +09:00
|
|
|
$order = sprintf('%1$s.%2$s %3$s, %1$s.%4$s ASC',
|
2019-06-02 21:46:39 +09:00
|
|
|
$profile->escapedTableName(),
|
|
|
|
$this->getSortKey('nickname'),
|
|
|
|
$this->reverse ? 'DESC' : 'ASC',
|
|
|
|
'nickname');
|
2015-02-18 21:37:06 +09:00
|
|
|
$profile->orderBy($order);
|
|
|
|
$profile->limit($offset, $limit);
|
2011-03-03 13:21:15 +09:00
|
|
|
|
2015-02-18 21:37:06 +09:00
|
|
|
$profile->find();
|
2011-03-05 18:55:52 +09:00
|
|
|
}
|
2011-03-02 12:35:20 +09:00
|
|
|
|
|
|
|
return $profile;
|
|
|
|
}
|
|
|
|
|
2011-03-04 14:12:24 +09:00
|
|
|
/**
|
|
|
|
* Filter the sort parameter
|
|
|
|
*
|
|
|
|
* @return string a column name for sorting
|
|
|
|
*/
|
2019-06-02 21:46:39 +09:00
|
|
|
public function getSortKey($def='nickname')
|
2011-03-04 14:12:24 +09:00
|
|
|
{
|
|
|
|
switch ($this->sort) {
|
|
|
|
case 'nickname':
|
|
|
|
case 'created':
|
|
|
|
return $this->sort;
|
|
|
|
default:
|
|
|
|
return 'nickname';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-02 12:35:20 +09:00
|
|
|
/**
|
|
|
|
* Show a nice message when there's no search results
|
|
|
|
*/
|
2019-06-02 21:46:39 +09:00
|
|
|
public function showEmptyListMessage()
|
2011-03-02 12:35:20 +09:00
|
|
|
{
|
2011-03-07 15:07:42 +09:00
|
|
|
if (!empty($this->filter) && ($this->filter != 'all')) {
|
2019-06-02 21:46:39 +09:00
|
|
|
$this->element('p',
|
|
|
|
'error',
|
|
|
|
sprintf(
|
|
|
|
// TRANS: Empty list message for user directory.
|
|
|
|
_m('No users starting with %s'),
|
|
|
|
$this->filter));
|
2011-03-07 15:07:42 +09:00
|
|
|
} else {
|
2011-06-05 18:44:01 +09:00
|
|
|
// TRANS: Empty list message for user directory.
|
2011-03-31 05:30:23 +09:00
|
|
|
$this->element('p', 'error', _m('No results.'));
|
2011-06-05 18:44:01 +09:00
|
|
|
// TRANS: Standard search suggestions shown when a search does not give any results.
|
|
|
|
$message = _m("* Make sure all words are spelled correctly.
|
2011-03-07 15:07:42 +09:00
|
|
|
* Try different keywords.
|
|
|
|
* Try more general keywords.
|
2011-06-05 18:44:01 +09:00
|
|
|
* Try fewer keywords.");
|
|
|
|
$message .= "\n";
|
|
|
|
|
2011-03-07 15:07:42 +09:00
|
|
|
$this->elementStart('div', 'help instructions');
|
|
|
|
$this->raw(common_markup_to_html($message));
|
|
|
|
$this->elementEnd('div');
|
|
|
|
}
|
2011-03-02 12:35:20 +09:00
|
|
|
}
|
|
|
|
}
|