forked from GNUsocial/gnu-social
* Integrate search input box
* Fix ordering
This commit is contained in:
parent
5f1a795b73
commit
5d22f969a1
@ -112,18 +112,18 @@ class DirectoryPlugin extends Plugin
|
|||||||
*/
|
*/
|
||||||
function onRouterInitialized($m)
|
function onRouterInitialized($m)
|
||||||
{
|
{
|
||||||
$m->connect(
|
|
||||||
'directory/users/:filter',
|
|
||||||
array('action' => 'userdirectory'),
|
|
||||||
array('filter' => '[0-9a-zA-Z_]{1,64}')
|
|
||||||
);
|
|
||||||
|
|
||||||
$m->connect(
|
$m->connect(
|
||||||
'directory/users',
|
'directory/users',
|
||||||
array('action' => 'userdirectory'),
|
array('action' => 'userdirectory'),
|
||||||
array('filter' => 'all')
|
array('filter' => 'all')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$m->connect(
|
||||||
|
'directory/users/:filter',
|
||||||
|
array('action' => 'userdirectory'),
|
||||||
|
array('filter' => '[0-9a-zA-Z_]{1,64}')
|
||||||
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,14 +50,35 @@ class UserdirectoryAction extends Action
|
|||||||
*
|
*
|
||||||
* @var integer
|
* @var integer
|
||||||
*/
|
*/
|
||||||
protected $page = null;
|
public $page;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* what to filter the search results by
|
* What to filter the search results by
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $filter = null;
|
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Title of the page
|
* Title of the page
|
||||||
@ -120,11 +141,11 @@ class UserdirectoryAction extends Action
|
|||||||
{
|
{
|
||||||
parent::prepare($args);
|
parent::prepare($args);
|
||||||
|
|
||||||
$this->page = ($this->arg('page')) ? ($this->arg('page') + 0) : 1;
|
$this->page = ($this->arg('page')) ? ($this->arg('page') + 0) : 1;
|
||||||
$filter = $this->arg('filter');
|
$this->filter = $this->arg('filter', 'all');
|
||||||
$this->filter = isset($filter) ? $filter : 'all';
|
$this->reverse = $this->boolean('reverse');
|
||||||
$this->sort = $this->arg('sort');
|
$this->q = $this->trimmed('q');
|
||||||
$this->order = $this->boolean('asc'); // ascending or decending
|
$this->sort = $this->arg('sort', 'nickname');
|
||||||
|
|
||||||
common_set_returnto($this->selfUrl());
|
common_set_returnto($this->selfUrl());
|
||||||
|
|
||||||
@ -185,15 +206,14 @@ class UserdirectoryAction extends Action
|
|||||||
*/
|
*/
|
||||||
function showContent()
|
function showContent()
|
||||||
{
|
{
|
||||||
// XXX Need search bar
|
$this->showForm();
|
||||||
|
|
||||||
$this->elementStart('div', array('id' => 'user_directory'));
|
$this->elementStart('div', array('id' => 'user_directory'));
|
||||||
|
|
||||||
$alphaNav = new AlphaNav($this, true, array('All'));
|
$alphaNav = new AlphaNav($this, true, array('All'));
|
||||||
$alphaNav->show();
|
$alphaNav->show();
|
||||||
|
|
||||||
// XXX Maybe use a more specialized version of ProfileList here
|
$profile = null;
|
||||||
|
|
||||||
$profile = $this->getUsers();
|
$profile = $this->getUsers();
|
||||||
$cnt = 0;
|
$cnt = 0;
|
||||||
|
|
||||||
@ -205,55 +225,116 @@ class UserdirectoryAction extends Action
|
|||||||
);
|
);
|
||||||
|
|
||||||
$cnt = $profileList->show();
|
$cnt = $profileList->show();
|
||||||
|
$profile->free();
|
||||||
|
|
||||||
if (0 == $cnt) {
|
if (0 == $cnt) {
|
||||||
$this->showEmptyListMessage();
|
$this->showEmptyListMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$args = array();
|
||||||
|
if (isset($this->q)) {
|
||||||
|
$args['q'] = $this->q;
|
||||||
|
} else {
|
||||||
|
$args['filter'] = $this->filter;
|
||||||
|
}
|
||||||
|
|
||||||
$this->pagination(
|
$this->pagination(
|
||||||
$this->page > 1,
|
$this->page > 1,
|
||||||
$cnt > PROFILES_PER_PAGE,
|
$cnt > PROFILES_PER_PAGE,
|
||||||
$this->page,
|
$this->page,
|
||||||
'userdirectory',
|
'userdirectory',
|
||||||
array('filter' => $this->filter)
|
$args
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->elementEnd('div');
|
$this->elementEnd('div');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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');
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get users filtered by the current filter, sort key,
|
* Get users filtered by the current filter, sort key,
|
||||||
* sort order, and page
|
* sort order, and page
|
||||||
*/
|
*/
|
||||||
function getUsers()
|
function getUsers()
|
||||||
{
|
{
|
||||||
|
|
||||||
$profile = new Profile();
|
$profile = new Profile();
|
||||||
|
|
||||||
$offset = ($this->page - 1) * PROFILES_PER_PAGE;
|
$offset = ($this->page - 1) * PROFILES_PER_PAGE;
|
||||||
$limit = PROFILES_PER_PAGE + 1;
|
$limit = PROFILES_PER_PAGE + 1;
|
||||||
$sort = $this->getSortKey();
|
|
||||||
$sql = 'SELECT profile.* FROM profile, user WHERE profile.id = user.id';
|
|
||||||
|
|
||||||
if ($this->filter != 'all') {
|
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';
|
||||||
|
|
||||||
|
if ($this->filter != 'all') {
|
||||||
|
$sql .= sprintf(
|
||||||
|
' AND LEFT(LOWER(profile.nickname), 1) = \'%s\'',
|
||||||
|
$this->filter
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$sql .= sprintf(
|
$sql .= sprintf(
|
||||||
' AND LEFT(LOWER(profile.nickname), 1) = \'%s\'',
|
' ORDER BY profile.%s %s, profile.nickname ASC LIMIT %d, %d',
|
||||||
$this->filter
|
$sort,
|
||||||
|
$this->reverse ? 'DESC' : 'ASC',
|
||||||
|
$offset,
|
||||||
|
$limit
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$profile->query($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql .= sprintf(
|
|
||||||
' ORDER BY profile.%s %s, profile.nickname DESC LIMIT %d, %d',
|
|
||||||
$sort,
|
|
||||||
($this->order) ? 'ASC' : 'DESC',
|
|
||||||
$offset,
|
|
||||||
$limit
|
|
||||||
);
|
|
||||||
|
|
||||||
$profile->query($sql);
|
|
||||||
|
|
||||||
return $profile;
|
return $profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ th.current {
|
|||||||
background-position: 60% 2px;
|
background-position: 60% 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
th.current.asc {
|
th.current.reverse {
|
||||||
background-image: url(../images/control_arrow_up.gif);
|
background-image: url(../images/control_arrow_up.gif);
|
||||||
background-repeat: no-repeat;
|
background-repeat: no-repeat;
|
||||||
background-position: 60% 2px;
|
background-position: 60% 2px;
|
||||||
|
@ -121,8 +121,8 @@ class AlphaNav extends Widget
|
|||||||
}
|
}
|
||||||
|
|
||||||
// sort order
|
// sort order
|
||||||
if (!empty($this->action->order)) {
|
if ($this->action->reverse) {
|
||||||
$params['asc'] = 'true';
|
$params['reverse'] = 'true';
|
||||||
}
|
}
|
||||||
|
|
||||||
$current = $this->action->arg('filter');
|
$current = $this->action->arg('filter');
|
||||||
|
@ -68,16 +68,16 @@ class SortableSubscriptionList extends SubscriptionList
|
|||||||
);
|
);
|
||||||
|
|
||||||
foreach ($tableHeaders as $id => $label) {
|
foreach ($tableHeaders as $id => $label) {
|
||||||
$attrs = array('id' => $id);
|
|
||||||
|
|
||||||
|
$attrs = array('id' => $id);
|
||||||
$current = (!empty($this->action->sort) && $this->action->sort == $id);
|
$current = (!empty($this->action->sort) && $this->action->sort == $id);
|
||||||
|
|
||||||
if ($current || empty($this->action->sort) && $id == 'nickname') {
|
if ($current || empty($this->action->sort) && $id == 'nickname') {
|
||||||
$attrs['class'] = 'current';
|
$attrs['class'] = 'current';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($current && !$this->action->boolean('asc')) {
|
if ($current && $this->action->reverse) {
|
||||||
$attrs['class'] .= ' asc';
|
$attrs['class'] .= ' reverse';
|
||||||
$attrs['class'] = trim($attrs['class']);
|
$attrs['class'] = trim($attrs['class']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,8 +86,12 @@ class SortableSubscriptionList extends SubscriptionList
|
|||||||
$linkAttrs = array();
|
$linkAttrs = array();
|
||||||
$params = array('sort' => $id);
|
$params = array('sort' => $id);
|
||||||
|
|
||||||
if ($current && !$this->action->boolean('asc')) {
|
if (!empty($this->action->q)) {
|
||||||
$params['asc'] = "true";
|
$params['q'] = $this->action->q;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($current && !$this->action->reverse) {
|
||||||
|
$params['reverse'] = 'true';
|
||||||
}
|
}
|
||||||
|
|
||||||
$args = array();
|
$args = array();
|
||||||
@ -108,7 +112,7 @@ class SortableSubscriptionList extends SubscriptionList
|
|||||||
|
|
||||||
$this->out->element('th', array('id' => 'subscriptions'), 'Subscriptions');
|
$this->out->element('th', array('id' => 'subscriptions'), 'Subscriptions');
|
||||||
$this->out->element('th', array('id' => 'notices'), 'Notices');
|
$this->out->element('th', array('id' => 'notices'), 'Notices');
|
||||||
//$this->out->element('th', array('id' => 'controls'), 'Controls');
|
$this->out->element('th', array('id' => 'controls'), null);
|
||||||
|
|
||||||
$this->out->elementEnd('tr');
|
$this->out->elementEnd('tr');
|
||||||
$this->out->elementEnd('thead');
|
$this->out->elementEnd('thead');
|
||||||
|
Loading…
Reference in New Issue
Block a user