. * * @category Public * @package StatusNet * @author Zach Copley * @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 * @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 { /** * @var $page integer the page we're on */ protected $page = null; /** * @var $filter string what to filter the search results by */ protected $filter = null; /** * Title of the page * * @return string Title of the page */ function title() { // @fixme: This looks kinda gross if ($this->filter == 'all') { if ($this->page != 1) { return(sprintf(_m('All users, page %d'), $this->page)); } return _m('All users'); } if ($this->page == 1) { return sprintf( _m('Users with nicknames beginning with %s'), $this->filter ); } else { return sprintf( _m('Users with nicknames starting with %s, page %d'), $this->filter, $this->page ); } } /** * Instructions for use * * @return instructions for use */ function getInstructions() { return _('User directory'); } /** * 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 * * @todo move queries from showContent() to here */ function prepare($args) { parent::prepare($args); $this->page = ($this->arg('page')) ? ($this->arg('page') + 0) : 1; $this->filter = $this->arg('filter') ? $this->arg('filter') : 'all'; 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() { // XXX Need search bar $this->elementStart('div', array('id' => 'user_directory')); $alphaNav = new AlphaNav($this, true, array('All')); $alphaNav->show(); // XXX Maybe use a more specialized version of ProfileList here $profile = $this->getUsers(); $cnt = 0; if (!empty($profile)) { $profileList = new SubscriptionList( $profile, common_current_user(), $this ); $cnt = $profileList->show(); if (0 == $cnt) { $this->showEmptyListMessage(); } } $this->pagination( $this->page > 1, $cnt > PROFILES_PER_PAGE, $this->page, 'userdirectory', array('filter' => $this->filter) ); $this->elementEnd('div'); } /* * Get users filtered by the current filter and page */ function getUsers() { $offset = ($this->page - 1) * PROFILES_PER_PAGE; $limit = PROFILES_PER_PAGE + 1; $profile = new Profile(); // XXX Any chance of SQL injection here? if ($this->filter != 'all') { $profile->whereAdd( sprintf('LEFT(lower(nickname), 1) = \'%s\'', $this->filter) ); } $profile->orderBy('created DESC, nickname'); $profile->limit($limit, $offset); $profile->find(); return $profile; } /** * Show a nice message when there's no search results */ function showEmptyListMessage() { $message = sprintf(_m('No users starting with %s'), $this->filter); $this->elementStart('div', 'guide'); $this->raw(common_markup_to_html($message)); $this->elementEnd('div'); } }