123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379 |
- <?php
- if (!defined('GNUSOCIAL')) {
- exit(1);
- }
- class GroupdirectoryAction extends ManagedAction
- {
- protected $redirectAfterLogin = true;
-
-
- public $page;
-
- public $filter;
-
- public $sort;
-
- public $reverse;
-
- public $q;
-
- public function title()
- {
-
- if ($this->filter == 'all') {
- if ($this->page != 1) {
-
- return(sprintf(_m('Group Directory, page %d'), $this->page));
- }
-
- return _m('Group directory');
- } elseif ($this->page == 1) {
- return sprintf(
-
-
- _m('Group directory - %s'),
- strtoupper($this->filter)
- );
- } else {
- return sprintf(
-
-
- _m('Group directory - %1$s, page %2$d'),
- strtoupper($this->filter),
- $this->page
- );
- }
- }
-
- public function getInstructions()
- {
-
- return _m("After you join a group you can send messages to all other members\n".
- "using the syntax \"!groupname\".\n\n".
- "Browse groups, or search for groups by their name, location or topic.\n".
- "Separate the terms by spaces; they must be three characters or more.") . "\n";
- }
-
- public function isReadOnly($args)
- {
- return true;
- }
- protected function doPreparation()
- {
- $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');
- }
-
- public function showPageNotice()
- {
- $instr = $this->getInstructions();
- $output = common_markup_to_html($instr);
- $this->elementStart('div', 'instructions');
- $this->raw($output);
- $this->elementEnd('div');
- }
-
- public function showContent()
- {
- if (common_logged_in()) {
- $this->elementStart('p',
- ['id' => 'new_group']);
- $this->element('a',
- ['href' => common_local_url('newgroup'),
- 'class' => 'more'],
-
- _m('Create a new group'));
- $this->elementEnd('p');
- }
- $this->showForm();
- $this->elementStart('div', ['id' => 'profile_directory']);
-
- $alphaNav = new AlphaNav($this, false, false, ['0-9', 'All']);
- $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();
- }
- }
- $args = [];
- if (isset($this->q)) {
- $args['q'] = $this->q;
- } else {
- $args['filter'] = $this->filter;
- }
- $this->pagination(
- $this->page > 1,
- $cnt > PROFILES_PER_PAGE,
- $this->page,
- 'groupdirectory',
- $args
- );
- $this->elementEnd('div');
- }
- public function showForm($error=null)
- {
- $this->elementStart('form',
- ['method' => 'get',
- 'id' => 'form_search',
- 'class' => 'form_settings',
- 'action' => common_local_url('groupdirectory')]);
- $this->elementStart('fieldset');
-
- $this->element('legend', null, _m('Search groups'));
- $this->elementStart('ul', 'form_data');
- $this->elementStart('li');
-
- $this->input('q', _m('Keyword(s)'), $this->q);
-
- $this->submit('search', _m('BUTTON', 'Search'));
- $this->elementEnd('li');
- $this->elementEnd('ul');
- $this->elementEnd('fieldset');
- $this->elementEnd('form');
- }
-
- public function getGroups()
- {
- $group = new User_group();
-
- $group->joinAdd(['id', 'local_group:group_id']);
- $order = false;
- if (!empty($this->q)) {
- $wheres = ['nickname', 'fullname', 'homepage', 'description', 'location'];
- foreach ($wheres as $where) {
-
- $group->whereAdd(sprintf('LOWER(%1$s.%2$s) LIKE LOWER("%%%3$s%%")',
- $group->escapedTableName(),
- $where,
- $group->escape($this->q)),
- 'OR');
- }
- $order = sprintf('%1$s.%2$s %3$s',
- $group->escapedTableName(),
- $this->getSortKey('created'),
- $this->reverse ? 'DESC' : 'ASC');
- } else {
-
- switch ($this->filter) {
- case 'all':
-
- break;
- case '0-9':
- $group->whereAdd(sprintf('LEFT(%1$s.%2$s, 1) BETWEEN %3$s AND %4$s',
- $group->escapedTableName(),
- 'nickname',
- $group->_quote("0"),
- $group->_quote("9")));
- break;
- default:
- $group->whereAdd(sprintf('LEFT(LOWER(%1$s.%2$s), 1) = %3$s',
- $group->escapedTableName(),
- 'nickname',
- $group->_quote($this->filter)));
- }
- $order = sprintf('%1$s.%2$s %3$s, %1$s.%4$s ASC',
- $group->escapedTableName(),
- $this->getSortKey('nickname'),
- $this->reverse ? 'DESC' : 'ASC',
- 'nickname');
- }
- $offset = ($this->page-1) * PROFILES_PER_PAGE;
- $limit = PROFILES_PER_PAGE + 1;
- $group->selectAdd();
- $group->selectAdd('profile_id');
- $group->orderBy($order);
- $group->limit($offset, $limit);
- $group->find();
- return Profile::multiGet('id', $group->fetchAll('profile_id'));
- }
-
- public function getSortKey($def='created')
- {
- switch ($this->sort) {
- case 'nickname':
- case 'created':
- return $this->sort;
- default:
- return $def;
- }
- }
-
- public function showEmptyListMessage()
- {
- if (!empty($this->filter) && ($this->filter != 'all')) {
- $this->element('p',
- 'error',
- sprintf(
-
-
- _m('No groups starting with %s.'),
- $this->filter));
- } else {
-
- $this->element('p', 'error', _m('No results.'));
-
- $message = _m("* Make sure all words are spelled correctly.\n".
- "* Try different keywords.\n".
- "* Try more general keywords.\n".
- "* Try fewer keywords.");
- $this->elementStart('div', 'help instructions');
- $this->raw(common_markup_to_html($message));
- $this->elementEnd('div');
- }
- }
- public function showSections()
- {
- $gbp = new GroupsByPostsSection($this);
- $gbp->show();
- $gbm = new GroupsByMembersSection($this);
- $gbm->show();
- }
- }
|