2011-04-13 08:10:10 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* StatusNet, the distributed open-source microblogging tool
|
|
|
|
*
|
|
|
|
* Output a group 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/
|
|
|
|
*/
|
|
|
|
|
2019-06-02 13:46:39 +01:00
|
|
|
if (!defined('GNUSOCIAL')) {
|
|
|
|
exit(1);
|
|
|
|
}
|
2011-04-13 08:10:10 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Group directory
|
|
|
|
*
|
|
|
|
* @category Directory
|
|
|
|
* @package StatusNet
|
|
|
|
* @author Zach Copley <zach@status.net>
|
2015-02-18 10:08:11 +00:00
|
|
|
* @author Mikael Nordfeldth <mmn@hethane.se>
|
2011-04-13 08:10:10 +01:00
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
|
|
|
* @link http://status.net/
|
|
|
|
*/
|
2015-02-18 10:15:30 +00:00
|
|
|
class GroupdirectoryAction extends ManagedAction
|
2011-04-13 08:10:10 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The page we're on
|
|
|
|
*
|
|
|
|
* @var integer
|
|
|
|
*/
|
|
|
|
public $page;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* What to filter the search results by
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $filter;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Column to sort by
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $sort;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* How to order search results, ascending or descending
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $reverse;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Query
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $q;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Title of the page
|
|
|
|
*
|
|
|
|
* @return string Title of the page
|
|
|
|
*/
|
2019-06-02 13:46:39 +01:00
|
|
|
public function title()
|
2011-04-13 08:10:10 +01:00
|
|
|
{
|
|
|
|
// @fixme: This looks kinda gross
|
|
|
|
|
|
|
|
if ($this->filter == 'all') {
|
|
|
|
if ($this->page != 1) {
|
2011-04-15 08:55:09 +01:00
|
|
|
// TRANS: Title for group directory page. %d is a page number.
|
2011-04-13 08:10:10 +01:00
|
|
|
return(sprintf(_m('Group Directory, page %d'), $this->page));
|
|
|
|
}
|
2011-04-15 08:55:09 +01:00
|
|
|
// TRANS: Title for group directory page.
|
2011-04-13 08:10:10 +01:00
|
|
|
return _m('Group directory');
|
2019-06-02 13:46:39 +01:00
|
|
|
} elseif ($this->page == 1) {
|
2011-04-13 08:10:10 +01:00
|
|
|
return sprintf(
|
2011-04-15 08:55:09 +01:00
|
|
|
// TRANS: Title for group directory page when it is filtered.
|
|
|
|
// TRANS: %s is the filter string.
|
2011-04-13 08:10:10 +01:00
|
|
|
_m('Group directory - %s'),
|
|
|
|
strtoupper($this->filter)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return sprintf(
|
2011-04-15 08:55:09 +01:00
|
|
|
// TRANS: Title for group directory page when it is filtered.
|
|
|
|
// TRANS: %1$s is the filter string, %2$d is a page number.
|
|
|
|
_m('Group directory - %1$s, page %2$d'),
|
2011-04-13 08:10:10 +01:00
|
|
|
strtoupper($this->filter),
|
|
|
|
$this->page
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instructions for use
|
|
|
|
*
|
|
|
|
* @return instructions for use
|
|
|
|
*/
|
2019-06-02 13:46:39 +01:00
|
|
|
public function getInstructions()
|
2011-04-13 08:10:10 +01:00
|
|
|
{
|
2011-04-15 08:55:09 +01:00
|
|
|
// TRANS: Page instructions.
|
|
|
|
return _m("After you join a group you can send messages to all other members\n".
|
|
|
|
"using the syntax \"!groupname\".\n\n".
|
2011-08-27 19:51:10 +01:00
|
|
|
"Browse groups, or search for groups by their name, location or topic.\n".
|
2011-05-05 11:41:10 +01:00
|
|
|
"Separate the terms by spaces; they must be three characters or more.") . "\n";
|
2011-04-13 08:10:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is this page read-only?
|
|
|
|
*
|
|
|
|
* @return boolean true
|
|
|
|
*/
|
2019-06-02 13:46:39 +01:00
|
|
|
public function isReadOnly($args)
|
2011-04-13 08:10:10 +01:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-02-18 10:15:30 +00:00
|
|
|
protected function doPreparation()
|
2011-04-13 08:10:10 +01:00
|
|
|
{
|
|
|
|
$this->page = ($this->arg('page')) ? ($this->arg('page') + 0) : 1;
|
|
|
|
$this->filter = $this->arg('filter', 'all');
|
|
|
|
$this->reverse = $this->boolean('reverse');
|
|
|
|
$this->q = $this->trimmed('q');
|
|
|
|
$this->sort = $this->arg('sort', 'nickname');
|
|
|
|
|
|
|
|
common_set_returnto($this->selfUrl());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the page notice
|
|
|
|
*
|
|
|
|
* Shows instructions for the page
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-06-02 13:46:39 +01:00
|
|
|
public function showPageNotice()
|
2011-04-13 08:10:10 +01:00
|
|
|
{
|
|
|
|
$instr = $this->getInstructions();
|
|
|
|
$output = common_markup_to_html($instr);
|
|
|
|
|
|
|
|
$this->elementStart('div', 'instructions');
|
|
|
|
$this->raw($output);
|
|
|
|
$this->elementEnd('div');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Content area
|
|
|
|
*
|
2011-04-14 00:43:28 +01:00
|
|
|
* Shows the groups
|
2011-04-13 08:10:10 +01:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-06-02 13:46:39 +01:00
|
|
|
public function showContent()
|
2011-04-13 08:10:10 +01:00
|
|
|
{
|
2011-04-14 00:43:28 +01:00
|
|
|
if (common_logged_in()) {
|
2019-06-02 13:46:39 +01:00
|
|
|
$this->elementStart('p',
|
|
|
|
['id' => 'new_group']);
|
|
|
|
$this->element('a',
|
|
|
|
['href' => common_local_url('newgroup'),
|
|
|
|
'class' => 'more'],
|
|
|
|
// TRANS: Link to create a new group on the group list page.
|
|
|
|
_m('Create a new group'));
|
2011-04-14 00:43:28 +01:00
|
|
|
$this->elementEnd('p');
|
|
|
|
}
|
|
|
|
|
2011-04-13 08:10:10 +01:00
|
|
|
$this->showForm();
|
|
|
|
|
2019-06-02 13:46:39 +01:00
|
|
|
$this->elementStart('div', ['id' => 'profile_directory']);
|
2011-04-13 08:10:10 +01:00
|
|
|
|
2011-04-15 08:55:09 +01:00
|
|
|
// @todo FIXME: Does "All" need i18n here?
|
2019-06-02 13:46:39 +01:00
|
|
|
$alphaNav = new AlphaNav($this, false, false, ['0-9', 'All']);
|
2011-04-13 08:10:10 +01:00
|
|
|
$alphaNav->show();
|
|
|
|
|
|
|
|
$group = null;
|
|
|
|
$group = $this->getGroups();
|
|
|
|
$cnt = 0;
|
|
|
|
|
|
|
|
if (!empty($group)) {
|
|
|
|
$groupList = new SortableGroupList(
|
|
|
|
$group,
|
|
|
|
common_current_user(),
|
|
|
|
$this
|
|
|
|
);
|
|
|
|
|
|
|
|
$cnt = $groupList->show();
|
|
|
|
$group->free();
|
|
|
|
|
|
|
|
if (0 == $cnt) {
|
|
|
|
$this->showEmptyListMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-02 13:46:39 +01:00
|
|
|
$args = [];
|
2011-04-13 08:10:10 +01:00
|
|
|
if (isset($this->q)) {
|
|
|
|
$args['q'] = $this->q;
|
|
|
|
} else {
|
|
|
|
$args['filter'] = $this->filter;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->pagination(
|
|
|
|
$this->page > 1,
|
2011-04-13 23:08:12 +01:00
|
|
|
$cnt > PROFILES_PER_PAGE,
|
2011-04-13 08:10:10 +01:00
|
|
|
$this->page,
|
|
|
|
'groupdirectory',
|
|
|
|
$args
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->elementEnd('div');
|
|
|
|
}
|
|
|
|
|
2019-06-02 13:46:39 +01:00
|
|
|
public function showForm($error=null)
|
2011-04-13 08:10:10 +01:00
|
|
|
{
|
2019-06-02 13:46:39 +01:00
|
|
|
$this->elementStart('form',
|
|
|
|
['method' => 'get',
|
|
|
|
'id' => 'form_search',
|
|
|
|
'class' => 'form_settings',
|
|
|
|
'action' => common_local_url('groupdirectory')]);
|
2011-04-13 08:10:10 +01:00
|
|
|
|
|
|
|
$this->elementStart('fieldset');
|
|
|
|
|
2011-04-15 08:55:09 +01:00
|
|
|
// TRANS: Fieldset legend.
|
2011-04-13 08:10:10 +01:00
|
|
|
$this->element('legend', null, _m('Search groups'));
|
|
|
|
$this->elementStart('ul', 'form_data');
|
|
|
|
$this->elementStart('li');
|
|
|
|
|
2011-04-15 08:55:09 +01:00
|
|
|
// TRANS: Field label for input of one or more keywords.
|
2011-04-13 08:10:10 +01:00
|
|
|
$this->input('q', _m('Keyword(s)'), $this->q);
|
|
|
|
|
2011-04-15 08:55:09 +01:00
|
|
|
// TRANS: Button text for searching group directory.
|
2019-06-02 13:46:39 +01:00
|
|
|
$this->submit('search', _m('BUTTON', 'Search'));
|
2011-04-13 08:10:10 +01:00
|
|
|
$this->elementEnd('li');
|
|
|
|
$this->elementEnd('ul');
|
|
|
|
$this->elementEnd('fieldset');
|
|
|
|
$this->elementEnd('form');
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get groups filtered by the current filter, sort key,
|
|
|
|
* sort order, and page
|
|
|
|
*/
|
2019-06-02 13:46:39 +01:00
|
|
|
public function getGroups()
|
2011-04-13 08:10:10 +01:00
|
|
|
{
|
|
|
|
$group = new User_group();
|
|
|
|
|
2015-02-18 11:17:26 +00:00
|
|
|
// Disable this to get global group searches
|
2019-06-02 13:46:39 +01:00
|
|
|
$group->joinAdd(['id', 'local_group:group_id']);
|
2011-04-13 08:10:10 +01:00
|
|
|
|
2015-02-18 11:17:26 +00:00
|
|
|
$order = false;
|
2015-02-18 10:08:11 +00:00
|
|
|
|
2015-02-18 11:17:26 +00:00
|
|
|
if (!empty($this->q)) {
|
2019-06-02 13:46:39 +01:00
|
|
|
$wheres = ['nickname', 'fullname', 'homepage', 'description', 'location'];
|
2015-02-18 10:08:11 +00:00
|
|
|
foreach ($wheres as $where) {
|
2015-02-18 11:17:26 +00:00
|
|
|
// Double % because of sprintf
|
|
|
|
$group->whereAdd(sprintf('LOWER(%1$s.%2$s) LIKE LOWER("%%%3$s%%")',
|
2019-06-02 13:46:39 +01:00
|
|
|
$group->escapedTableName(),
|
|
|
|
$where,
|
|
|
|
$group->escape($this->q)),
|
|
|
|
'OR');
|
2015-02-18 10:08:11 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 11:17:26 +00:00
|
|
|
$order = sprintf('%1$s.%2$s %3$s',
|
2019-06-02 13:46:39 +01:00
|
|
|
$group->escapedTableName(),
|
|
|
|
$this->getSortKey('created'),
|
|
|
|
$this->reverse ? 'DESC' : 'ASC');
|
2011-04-13 08:10:10 +01:00
|
|
|
} else {
|
|
|
|
// User is browsing via AlphaNav
|
|
|
|
|
2019-06-02 13:46:39 +01:00
|
|
|
switch ($this->filter) {
|
2011-04-13 08:10:10 +01:00
|
|
|
case 'all':
|
|
|
|
// NOOP
|
|
|
|
break;
|
|
|
|
case '0-9':
|
2015-02-18 11:17:26 +00:00
|
|
|
$group->whereAdd(sprintf('LEFT(%1$s.%2$s, 1) BETWEEN %3$s AND %4$s',
|
2019-06-02 13:46:39 +01:00
|
|
|
$group->escapedTableName(),
|
|
|
|
'nickname',
|
|
|
|
$group->_quote("0"),
|
|
|
|
$group->_quote("9")));
|
2011-04-13 08:10:10 +01:00
|
|
|
break;
|
|
|
|
default:
|
2015-02-18 11:17:26 +00:00
|
|
|
$group->whereAdd(sprintf('LEFT(LOWER(%1$s.%2$s), 1) = %3$s',
|
2019-06-02 13:46:39 +01:00
|
|
|
$group->escapedTableName(),
|
|
|
|
'nickname',
|
|
|
|
$group->_quote($this->filter)));
|
2011-04-13 08:10:10 +01:00
|
|
|
}
|
|
|
|
|
2015-02-18 11:17:26 +00:00
|
|
|
$order = sprintf('%1$s.%2$s %3$s, %1$s.%4$s ASC',
|
2019-06-02 13:46:39 +01:00
|
|
|
$group->escapedTableName(),
|
|
|
|
$this->getSortKey('nickname'),
|
|
|
|
$this->reverse ? 'DESC' : 'ASC',
|
|
|
|
'nickname');
|
2011-04-13 08:10:10 +01:00
|
|
|
}
|
|
|
|
|
2015-02-18 11:17:26 +00:00
|
|
|
$offset = ($this->page-1) * PROFILES_PER_PAGE;
|
|
|
|
$limit = PROFILES_PER_PAGE + 1;
|
|
|
|
|
2016-01-07 11:35:52 +00:00
|
|
|
$group->selectAdd();
|
|
|
|
$group->selectAdd('profile_id');
|
2015-02-18 11:17:26 +00:00
|
|
|
$group->orderBy($order);
|
|
|
|
$group->limit($offset, $limit);
|
|
|
|
|
2015-02-18 10:08:11 +00:00
|
|
|
$group->find();
|
|
|
|
|
2016-01-07 11:35:52 +00:00
|
|
|
return Profile::multiGet('id', $group->fetchAll('profile_id'));
|
2011-04-13 08:10:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Filter the sort parameter
|
|
|
|
*
|
|
|
|
* @return string a column name for sorting
|
|
|
|
*/
|
2019-06-02 13:46:39 +01:00
|
|
|
public function getSortKey($def='created')
|
2011-04-13 08:10:10 +01:00
|
|
|
{
|
|
|
|
switch ($this->sort) {
|
|
|
|
case 'nickname':
|
|
|
|
case 'created':
|
|
|
|
return $this->sort;
|
|
|
|
default:
|
2015-02-18 11:17:26 +00:00
|
|
|
return $def;
|
2011-04-13 08:10:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show a nice message when there's no search results
|
|
|
|
*/
|
2019-06-02 13:46:39 +01:00
|
|
|
public function showEmptyListMessage()
|
2011-04-13 08:10:10 +01:00
|
|
|
{
|
|
|
|
if (!empty($this->filter) && ($this->filter != 'all')) {
|
2019-06-02 13:46:39 +01:00
|
|
|
$this->element('p',
|
|
|
|
'error',
|
|
|
|
sprintf(
|
|
|
|
// TRANS: Empty list message for searching group directory.
|
|
|
|
// TRANS: %s is the search string.
|
|
|
|
_m('No groups starting with %s.'),
|
|
|
|
$this->filter));
|
2011-04-13 08:10:10 +01:00
|
|
|
} else {
|
2011-04-15 08:55:09 +01:00
|
|
|
// TRANS: Empty list message for searching group directory.
|
2011-04-13 08:10:10 +01:00
|
|
|
$this->element('p', 'error', _m('No results.'));
|
2011-04-15 08:55:09 +01:00
|
|
|
// TRANS: Help text for searching group directory.
|
|
|
|
$message = _m("* Make sure all words are spelled correctly.\n".
|
|
|
|
"* Try different keywords.\n".
|
|
|
|
"* Try more general keywords.\n".
|
|
|
|
"* Try fewer keywords.");
|
2011-04-13 08:10:10 +01:00
|
|
|
$this->elementStart('div', 'help instructions');
|
|
|
|
$this->raw(common_markup_to_html($message));
|
|
|
|
$this->elementEnd('div');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-02 13:46:39 +01:00
|
|
|
public function showSections()
|
2011-04-13 08:10:10 +01:00
|
|
|
{
|
|
|
|
$gbp = new GroupsByPostsSection($this);
|
|
|
|
$gbp->show();
|
|
|
|
$gbm = new GroupsByMembersSection($this);
|
|
|
|
$gbm->show();
|
|
|
|
}
|
|
|
|
}
|