From 3b186e1bae91ae0030c8eeb58fdfbc114dfd0b84 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Wed, 2 Mar 2011 20:21:15 -0800 Subject: [PATCH] * Fix pagination * Add some more elements for styling * Add initial CSS --- plugins/Directory/DirectoryPlugin.php | 40 +++++++++++++++++---- plugins/Directory/actions/userdirectory.php | 39 ++++++++++++++------ plugins/Directory/css/directory.css | 34 ++++++++++++++++++ plugins/Directory/lib/alphanav.php | 37 ++++++++++++++++--- 4 files changed, 129 insertions(+), 21 deletions(-) create mode 100644 plugins/Directory/css/directory.css diff --git a/plugins/Directory/DirectoryPlugin.php b/plugins/Directory/DirectoryPlugin.php index 0ff2ea76bf..aaa33a1ec1 100644 --- a/plugins/Directory/DirectoryPlugin.php +++ b/plugins/Directory/DirectoryPlugin.php @@ -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,13 +108,39 @@ 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; + } + /** * Modify the public local nav to add a link to the user directory * diff --git a/plugins/Directory/actions/userdirectory.php b/plugins/Directory/actions/userdirectory.php index e4c8f673ed..7e9f20c369 100644 --- a/plugins/Directory/actions/userdirectory.php +++ b/plugins/Directory/actions/userdirectory.php @@ -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; - $limit = PROFILES_PER_PAGE + 1; + $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; diff --git a/plugins/Directory/css/directory.css b/plugins/Directory/css/directory.css new file mode 100644 index 0000000000..3778525a84 --- /dev/null +++ b/plugins/Directory/css/directory.css @@ -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; +} diff --git a/plugins/Directory/lib/alphanav.php b/plugins/Directory/lib/alphanav.php index 228237bfed..6829f3d2c3 100644 --- a/plugins/Directory/lib/alphanav.php +++ b/plugins/Directory/lib/alphanav.php @@ -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'); } } -- 2.39.5