* Fix pagination
* Add some more elements for styling * Add initial CSS
This commit is contained in:
parent
09c90edbb5
commit
3b186e1bae
@ -44,6 +44,9 @@ if (!defined('STATUSNET')) {
|
||||
*/
|
||||
class DirectoryPlugin extends Plugin
|
||||
{
|
||||
|
||||
private $dir = null;
|
||||
|
||||
/**
|
||||
* Initializer for this plugin
|
||||
*
|
||||
@ -52,6 +55,7 @@ class DirectoryPlugin extends Plugin
|
||||
*/
|
||||
function initialize()
|
||||
{
|
||||
$this->dir = dirname(__FILE__);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -76,18 +80,16 @@ class DirectoryPlugin extends Plugin
|
||||
*/
|
||||
function onAutoload($cls)
|
||||
{
|
||||
$dir = dirname(__FILE__);
|
||||
|
||||
// common_debug("class = $cls");
|
||||
|
||||
switch ($cls)
|
||||
{
|
||||
case 'UserdirectoryAction':
|
||||
include_once $dir
|
||||
include_once $this->dir
|
||||
. '/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
|
||||
return false;
|
||||
case 'AlphaNav':
|
||||
include_once $dir
|
||||
include_once $this->dir
|
||||
. '/lib/' . strtolower($cls) . '.php';
|
||||
return false;
|
||||
default:
|
||||
@ -106,10 +108,36 @@ class DirectoryPlugin extends Plugin
|
||||
function onRouterInitialized($m)
|
||||
{
|
||||
$m->connect(
|
||||
'main/directory',
|
||||
array('action' => 'userdirectory')
|
||||
'directory/users/:filter',
|
||||
array('action' => 'userdirectory'),
|
||||
array('filter' => '[0-9a-zA-Z_]{1,64}')
|
||||
);
|
||||
|
||||
$m->connect(
|
||||
'directory/users',
|
||||
array('action' => 'userdirectory'),
|
||||
array('filter' => 'all')
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Link in a styelsheet for the onboarding actions
|
||||
*
|
||||
* @param Action $action Action being shown
|
||||
*
|
||||
* @return boolean hook flag
|
||||
*/
|
||||
function onEndShowStatusNetStyles($action)
|
||||
{
|
||||
if (in_array(
|
||||
$action->trimmed('action'),
|
||||
array('userdirectory'))
|
||||
) {
|
||||
$action->cssLink($this->path('css/directory.css'));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -45,10 +45,14 @@ require_once INSTALLDIR . '/lib/publicgroupnav.php';
|
||||
*/
|
||||
class UserdirectoryAction extends Action
|
||||
{
|
||||
/* Page we're on */
|
||||
/**
|
||||
* @var $page integer the page we're on
|
||||
*/
|
||||
protected $page = null;
|
||||
|
||||
/* What to filter the search results by */
|
||||
/**
|
||||
* @var $filter string what to filter the search results by
|
||||
*/
|
||||
protected $filter = null;
|
||||
|
||||
/**
|
||||
@ -60,7 +64,7 @@ class UserdirectoryAction extends Action
|
||||
{
|
||||
// @fixme: This looks kinda gross
|
||||
|
||||
if ($this->filter == 'All') {
|
||||
if ($this->filter == 'all') {
|
||||
if ($this->page != 1) {
|
||||
return(sprintf(_m('All users, page %d'), $this->page));
|
||||
}
|
||||
@ -115,7 +119,7 @@ class UserdirectoryAction extends Action
|
||||
parent::prepare($args);
|
||||
|
||||
$this->page = ($this->arg('page')) ? ($this->arg('page') + 0) : 1;
|
||||
$this->filter = $this->arg('filter') ? $this->arg('filter') : 'All';
|
||||
$this->filter = $this->arg('filter') ? $this->arg('filter') : 'all';
|
||||
common_set_returnto($this->selfUrl());
|
||||
|
||||
return true;
|
||||
@ -177,6 +181,8 @@ class UserdirectoryAction extends Action
|
||||
{
|
||||
// XXX Need search bar
|
||||
|
||||
$this->elementStart('div', array('id' => 'user_directory'));
|
||||
|
||||
$alphaNav = new AlphaNav($this, true, array('All'));
|
||||
$alphaNav->show();
|
||||
|
||||
@ -199,9 +205,15 @@ class UserdirectoryAction extends Action
|
||||
}
|
||||
}
|
||||
|
||||
$this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
|
||||
$this->page, 'userdirectory',
|
||||
array('filter' => $this->filter));
|
||||
$this->pagination(
|
||||
$this->page > 1,
|
||||
$cnt > PROFILES_PER_PAGE,
|
||||
$this->page,
|
||||
'userdirectory',
|
||||
array('filter' => $this->filter)
|
||||
);
|
||||
|
||||
$this->elementEnd('div');
|
||||
|
||||
}
|
||||
|
||||
@ -210,17 +222,22 @@ class UserdirectoryAction extends Action
|
||||
*/
|
||||
function getUsers()
|
||||
{
|
||||
$offset = ($this->page-1) * PROFILES_PER_PAGE;
|
||||
$offset = ($this->page - 1) * PROFILES_PER_PAGE;
|
||||
$limit = PROFILES_PER_PAGE + 1;
|
||||
|
||||
$profile = new Profile();
|
||||
|
||||
if ($this->filter != 'All') {
|
||||
// XXX Any chance of SQL injection here?
|
||||
|
||||
if ($this->filter != 'all') {
|
||||
$profile->whereAdd(
|
||||
sprintf('LEFT(UPPER(nickname), 1) = \'%s\'', $this->filter)
|
||||
sprintf('LEFT(lower(nickname), 1) = \'%s\'', $this->filter)
|
||||
);
|
||||
}
|
||||
|
||||
$profile->orderBy('created DESC, nickname');
|
||||
$profile->limit($limit, $offset);
|
||||
|
||||
$profile->find();
|
||||
|
||||
return $profile;
|
||||
|
34
plugins/Directory/css/directory.css
Normal file
34
plugins/Directory/css/directory.css
Normal file
@ -0,0 +1,34 @@
|
||||
/* CSS file for the Directory plugin */
|
||||
|
||||
div#user_directory div.alpha_nav {
|
||||
overflow: hidden;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* XXX: this needs serious CSS foo */
|
||||
div#user_directory div.alpha_nav > a {
|
||||
border-left: 1px solid #000;
|
||||
padding-left: 2px;
|
||||
}
|
||||
div#user_directory div.alpha_nav > a.first {
|
||||
border-left: none;
|
||||
}
|
||||
|
||||
div#user_directory div.alpha_nav a:link {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
div#user_directory div.alpha_nav a:visited {
|
||||
text-decoration: none;
|
||||
}
|
||||
div#user_directory div.alpha_nav a:active {
|
||||
text-decoration: none;
|
||||
}
|
||||
div#user_directory div.alpha_nav a:hover {
|
||||
text-decoration: underline; color: blue;
|
||||
}
|
||||
|
||||
div#user_directory div.alpha_nav a.current {
|
||||
background-color:#9BB43E;
|
||||
}
|
@ -94,14 +94,43 @@ class AlphaNav extends Widget
|
||||
{
|
||||
$actionName = $this->action->trimmed('action');
|
||||
|
||||
foreach ($this->filters as $filter) {
|
||||
$this->action->elementStart('div', array('class' => 'alpha_nav'));
|
||||
|
||||
for ($i = 0, $size = sizeof($this->filters); $i < $size; $i++) {
|
||||
|
||||
$filter = $this->filters[$i];
|
||||
$classes = '';
|
||||
|
||||
// Add some classes for styling
|
||||
if ($i == 0) {
|
||||
$classes .= 'first '; // first filter in the list
|
||||
} elseif ($i == $size - 1) {
|
||||
$classes .= 'last '; // last filter in the list
|
||||
}
|
||||
|
||||
$href = common_local_url(
|
||||
$actionName,
|
||||
null,
|
||||
array('filter' => $filter)
|
||||
array('filter' => strtolower($filter))
|
||||
);
|
||||
$this->action->element('a', array('href' => $href), $filter);
|
||||
|
||||
$params = array('href' => $href);
|
||||
$current = $this->action->arg('filter');
|
||||
|
||||
// Highlight the selected filter. If there is no selected
|
||||
// filter, highlight the first filter in the list
|
||||
if (empty($current) && $i == 0
|
||||
|| $current === strtolower($filter)) {
|
||||
$classes .= 'current ';
|
||||
}
|
||||
|
||||
if (!empty($classes)) {
|
||||
$params['class'] = trim($classes);
|
||||
}
|
||||
|
||||
$this->action->element('a', $params, $filter);
|
||||
}
|
||||
|
||||
$this->action->elementEnd('div');
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user