*/
class DirectoryPlugin extends Plugin
{
+
+ private $dir = null;
+
/**
* Initializer for this plugin
*
*/
function initialize()
{
+ $this->dir = dirname(__FILE__);
return true;
}
*/
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:
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
*
*/
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;
/**
{
// @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));
}
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;
{
// XXX Need search bar
+ $this->elementStart('div', array('id' => 'user_directory'));
+
$alphaNav = new AlphaNav($this, true, array('All'));
$alphaNav->show();
}
}
- $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');
}
*/
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;
--- /dev/null
+/* 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;
+}
{
$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');
}
}