Initial go at a site directory plugin
This commit is contained in:
parent
5bf0c9f610
commit
cb49ea88d3
159
plugins/Directory/DirectoryPlugin.php
Normal file
159
plugins/Directory/DirectoryPlugin.php
Normal file
@ -0,0 +1,159 @@
|
||||
<?php
|
||||
/**
|
||||
* StatusNet - the distributed open-source microblogging tool
|
||||
* Copyright (C) 2011, StatusNet, Inc.
|
||||
*
|
||||
* Adds a user directory
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @category Plugin
|
||||
* @package StatusNet
|
||||
* @author Zach Copely <zach@status.net>
|
||||
* @copyright 2011 StatusNet, Inc.
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
|
||||
* @link http://status.net/
|
||||
*/
|
||||
|
||||
if (!defined('STATUSNET')) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Directory plugin main class
|
||||
*
|
||||
* @category Plugin
|
||||
* @package StatusNet
|
||||
* @author Zach Copley <zach@status.net>
|
||||
* @copyright 2011 StatusNet, Inc.
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
|
||||
* @link http://status.net/
|
||||
*/
|
||||
class DirectoryPlugin extends Plugin
|
||||
{
|
||||
/**
|
||||
* Initializer for this plugin
|
||||
*
|
||||
* @return boolean hook value; true means continue processing,
|
||||
* false means stop.
|
||||
*/
|
||||
function initialize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleanup for this plugin.
|
||||
*
|
||||
* @return boolean hook value; true means continue processing,
|
||||
* false means stop.
|
||||
*/
|
||||
function cleanup()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load related modules when needed
|
||||
*
|
||||
* @param string $cls Name of the class to be loaded
|
||||
*
|
||||
* @return boolean hook value; true means continue processing,
|
||||
* false means stop.
|
||||
*/
|
||||
function onAutoload($cls)
|
||||
{
|
||||
$dir = dirname(__FILE__);
|
||||
|
||||
// common_debug("class = $cls");
|
||||
|
||||
switch ($cls)
|
||||
{
|
||||
case 'UserdirectoryAction':
|
||||
include_once $dir
|
||||
. '/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
|
||||
return false;
|
||||
case 'AlphaNav':
|
||||
include_once $dir
|
||||
. '/lib/' . strtolower($cls) . '.php';
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Map URLs to actions
|
||||
*
|
||||
* @param Net_URL_Mapper $m path-to-action mapper
|
||||
*
|
||||
* @return boolean hook value; true means continue processing,
|
||||
* false means stop.
|
||||
*/
|
||||
function onRouterInitialized($m)
|
||||
{
|
||||
$m->connect(
|
||||
'main/directory',
|
||||
array('action' => 'userdirectory')
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify the public local nav to add a link to the user directory
|
||||
*
|
||||
* @param Action $action The current action handler. Use this to
|
||||
* do any output.
|
||||
*
|
||||
* @return boolean hook value; true means continue processing,
|
||||
* false means stop.
|
||||
*
|
||||
* @see Action
|
||||
*/
|
||||
function onEndPublicGroupNav($nav)
|
||||
{
|
||||
// XXX: Maybe this should go under search instead?
|
||||
|
||||
$actionName = $nav->action->trimmed('action');
|
||||
|
||||
$nav->out->menuItem(
|
||||
common_local_url('userdirectory'),
|
||||
_('Directory'),
|
||||
_('User Directory'),
|
||||
$actionName == 'userdirectory',
|
||||
'nav_directory'
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Version info
|
||||
*/
|
||||
function onPluginVersion(&$versions)
|
||||
{
|
||||
$versions[] = array(
|
||||
'name' => 'Directory',
|
||||
'version' => STATUSNET_VERSION,
|
||||
'author' => 'Zach Copley',
|
||||
'homepage' => 'http://status.net/wiki/Plugin:Directory',
|
||||
'rawdescription' => _m('Add a user directory.')
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
241
plugins/Directory/actions/userdirectory.php
Normal file
241
plugins/Directory/actions/userdirectory.php
Normal file
@ -0,0 +1,241 @@
|
||||
<?php
|
||||
/**
|
||||
* StatusNet, the distributed open-source microblogging tool
|
||||
*
|
||||
* Output a user directory
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENCE: This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @category Public
|
||||
* @package StatusNet
|
||||
* @author Zach Copley <zach@status.net>
|
||||
* @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 <zach@status.net>
|
||||
* @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
|
||||
{
|
||||
/* Page we're on */
|
||||
protected $page = null;
|
||||
|
||||
/* 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
|
||||
|
||||
$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));
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* 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();
|
||||
|
||||
if ($this->filter != 'All') {
|
||||
$profile->whereAdd(
|
||||
sprintf('LEFT(UPPER(nickname), 1) = \'%s\'', $this->filter)
|
||||
);
|
||||
}
|
||||
$profile->orderBy('created DESC, nickname');
|
||||
$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');
|
||||
}
|
||||
|
||||
}
|
107
plugins/Directory/lib/alphanav.php
Normal file
107
plugins/Directory/lib/alphanav.php
Normal file
@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/**
|
||||
* StatusNet, the distributed open-source microblogging tool
|
||||
*
|
||||
* Widget to display an alphabet menu
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENCE: This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @category Widget
|
||||
* @package StatusNet
|
||||
* @author Zach Copley <zach@status.net>
|
||||
* @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') && !defined('LACONICA')) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a fancy alphabet letter navigation menu
|
||||
*
|
||||
* @category Widget
|
||||
* @package StatusNet
|
||||
* @author Zach Copley <zach@status.net>
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||
* @link http://status.net/
|
||||
*
|
||||
* @see HTMLOutputter
|
||||
*/
|
||||
|
||||
class AlphaNav extends Widget
|
||||
{
|
||||
protected $action = null;
|
||||
protected $filters = array();
|
||||
|
||||
/**
|
||||
* Prepare the widget for use
|
||||
*
|
||||
* @param Action $action the current action
|
||||
* @param boolean $numbers whether to output 0..9
|
||||
* @param Array $prepend array of filters to prepend
|
||||
* @param Array $append array of filters to append
|
||||
*/
|
||||
function __construct(
|
||||
$action = null,
|
||||
$numbers = false,
|
||||
$prepend = false,
|
||||
$append = false
|
||||
)
|
||||
{
|
||||
parent::__construct($action);
|
||||
|
||||
$this->action = $action;
|
||||
|
||||
if ($prepend) {
|
||||
$this->filters = array_merge($prepend, $this->filters);
|
||||
}
|
||||
|
||||
if ($numbers) {
|
||||
$this->filters = array_merge($this->filters, range(0, 9));
|
||||
}
|
||||
|
||||
if ($append) {
|
||||
$this->filters = array_merge($this->filters, $append);
|
||||
}
|
||||
|
||||
$this->filters = array_merge($this->filters, range('A', 'Z'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the widget
|
||||
*
|
||||
* Emit the HTML for the widget, using the configured outputter.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
function show()
|
||||
{
|
||||
$actionName = $this->action->trimmed('action');
|
||||
|
||||
foreach ($this->filters as $filter) {
|
||||
$href = common_local_url(
|
||||
$actionName,
|
||||
null,
|
||||
array('filter' => $filter)
|
||||
);
|
||||
$this->action->element('a', array('href' => $href), $filter);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user