123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405 |
- <?php
- if (!defined('STATUSNET'))
- {
- exit(1);
- }
- require_once INSTALLDIR . '/lib/publicgroupnav.php';
- class UserdirectoryAction extends Action
- {
-
- public $page;
-
- public $filter;
-
- public $sort;
-
- public $reverse;
-
- public $q;
-
- function title()
- {
-
- if ($this->filter == 'all') {
- if ($this->page != 1) {
-
- return(sprintf(_m('User Directory, page %d'), $this->page));
- }
-
- return _m('User directory');
- } else if ($this->page == 1) {
- return sprintf(
-
- _m('User directory - %s'),
- strtoupper($this->filter)
- );
- } else {
- return sprintf(
-
-
- _m('User directory - %1$s, page %2$d'),
- strtoupper($this->filter),
- $this->page
- );
- }
- }
-
- function getInstructions()
- {
-
- return _m('Search for people on %%site.name%% by their name, '
- . 'location, or interests. Separate the terms by spaces; '
- . ' they must be 3 characters or more.'
- );
- }
-
- function isReadOnly($args)
- {
- return true;
- }
-
- function prepare($args)
- {
- parent::prepare($args);
- $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');
- common_set_returnto($this->selfUrl());
- return true;
- }
-
- function handle($args)
- {
- parent::handle($args);
- $this->showPage();
- }
-
- function showPageNotice()
- {
- $instr = $this->getInstructions();
- $output = common_markup_to_html($instr);
- $this->elementStart('div', 'instructions');
- $this->raw($output);
- $this->elementEnd('div');
- }
-
- function showContent()
- {
- $this->showForm();
- $this->elementStart('div', array('id' => 'profile_directory'));
- $alphaNav = new AlphaNav($this, false, false, array('0-9', 'All'));
- $alphaNav->show();
- $profile = null;
- $profile = $this->getUsers();
- $cnt = 0;
- if (!empty($profile)) {
- $profileList = new SortableSubscriptionList(
- $profile,
- common_current_user(),
- $this
- );
- $cnt = $profileList->show();
- $profile->free();
- if (0 == $cnt) {
- $this->showEmptyListMessage();
- }
- }
- $args = array();
- if (isset($this->q)) {
- $args['q'] = $this->q;
- } elseif (isset($this->filter) && $this->filter != 'all') {
- $args['filter'] = $this->filter;
- }
-
- if (isset($this->sort)) {
- $args['sort'] = $this->sort;
- }
- if (!empty($this->reverse)) {
- $args['reverse'] = $this->reverse;
- }
- $this->pagination(
- $this->page > 1,
- $cnt > PROFILES_PER_PAGE,
- $this->page,
- 'userdirectory',
- $args
- );
- $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, _m('Search site'));
- $this->elementStart('ul', 'form_data');
- $this->elementStart('li');
-
- $this->input('q', _m('Keyword(s)'), $this->q);
-
- $this->submit('search', _m('BUTTON','Search'));
- $this->elementEnd('li');
- $this->elementEnd('ul');
- $this->elementEnd('fieldset');
- $this->elementEnd('form');
- }
-
- function getUsers()
- {
- $profile = new Profile();
- $offset = ($this->page - 1) * PROFILES_PER_PAGE;
- $limit = PROFILES_PER_PAGE + 1;
- if (isset($this->q)) {
-
- $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 {
-
- $sort = $this->getSortKey();
- $sql = 'SELECT profile.* FROM profile, user WHERE profile.id = user.id';
- switch($this->filter)
- {
- case 'all':
-
- break;
- case '0-9':
- $sql .=
- ' AND LEFT(profile.nickname, 1) BETWEEN \'0\' AND \'9\'';
- break;
- default:
- $sql .= sprintf(
- ' AND LEFT(LOWER(profile.nickname), 1) = \'%s\'',
- $this->filter
- );
- }
- $sql .= sprintf(
- ' ORDER BY profile.%s %s, profile.nickname ASC LIMIT %d, %d',
- $sort,
- $this->reverse ? 'DESC' : 'ASC',
- $offset,
- $limit
- );
- $profile->query($sql);
- }
- return $profile;
- }
-
- function getSortKey()
- {
- switch ($this->sort) {
- case 'nickname':
- return $this->sort;
- break;
- case 'created':
- return $this->sort;
- break;
- default:
- return 'nickname';
- }
- }
-
- function showEmptyListMessage()
- {
- 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', _m('No results.'));
-
- $message = _m("* Make sure all words are spelled correctly.
- * Try different keywords.
- * Try more general keywords.
- * Try fewer keywords.");
- $message .= "\n";
- $this->elementStart('div', 'help instructions');
- $this->raw(common_markup_to_html($message));
- $this->elementEnd('div');
- }
- }
- }
|