diff --git a/mod/network.php b/mod/network.php index 4dfd39cd90..57e4a2ada2 100644 --- a/mod/network.php +++ b/mod/network.php @@ -300,23 +300,7 @@ function network_content(App $a, $update = 0, $parent = 0) $o = ''; } - switch ($a->argv[1] ?? '') { - case 'person': - $account = User::ACCOUNT_TYPE_PERSON; - break; - case 'organisation': - $account = User::ACCOUNT_TYPE_ORGANISATION; - break; - case 'news': - $account = User::ACCOUNT_TYPE_NEWS; - break; - case 'community': - $account = User::ACCOUNT_TYPE_COMMUNITY; - break; - default: - $account = null; - break; - } + $account = User::getAccountTypeByString($a->argv[1] ?? ''); if (!empty($_GET['file'])) { $o .= networkFlatView($a, $update, $account); diff --git a/src/Content/Widget.php b/src/Content/Widget.php index 3e5af2251f..0078e82a53 100644 --- a/src/Content/Widget.php +++ b/src/Content/Widget.php @@ -24,17 +24,13 @@ namespace Friendica\Content; use Friendica\Core\Addon; use Friendica\Core\Protocol; use Friendica\Core\Renderer; -use Friendica\Core\Session; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\FileTag; -use Friendica\Model\GContact; use Friendica\Model\Group; use Friendica\Model\Item; -use Friendica\Model\Profile; use Friendica\Util\DateTimeFormat; -use Friendica\Util\Strings; use Friendica\Util\Temporal; class Widget @@ -526,8 +522,30 @@ class Widget return $o; } + /** + * Display the account types sidebar + * The account type value is added as a parameter to the url + * + * @param string $base Basepath + * @param int $accounttype Acount type + * @return string + */ + public static function accounttypes(string $base, $accounttype) + { + $accounts = [ + ['ref' => 'person', 'name' => DI::l10n()->t('Persons')], + ['ref' => 'organisation', 'name' => DI::l10n()->t('Organisations')], + ['ref' => 'news', 'name' => DI::l10n()->t('News')], + ['ref' => 'community', 'name' => DI::l10n()->t('Forums')], + ]; + + return self::filter('accounttype', DI::l10n()->t('Accounts'), '', + DI::l10n()->t('All'), $base, $accounts, $accounttype); + } + /** * Display the accounts sidebar + * The account type is added to the path * * @param string $base Basepath * @param string $accounttype Acount type (person, organisation, news, community) diff --git a/src/Model/Contact/Relation.php b/src/Model/Contact/Relation.php index e6926df85b..3c95973238 100644 --- a/src/Model/Contact/Relation.php +++ b/src/Model/Contact/Relation.php @@ -469,7 +469,7 @@ class Relation ); return DI::dba()->selectToArray('contact', [], $condition, - ['limit' => [$offset, $count], 'order' => [$shuffle ? 'name' : 'RAND()']] + ['limit' => [$offset, $count], 'order' => [$shuffle ? 'RAND()' : 'name']] ); } @@ -485,8 +485,8 @@ class Relation public static function countAll(int $cid, array $condition = []) { $condition = DBA::mergeConditions($condition, - ['`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`) - OR `id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`)', + ['(`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`) + OR `id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`))', $cid, $cid] ); @@ -507,13 +507,13 @@ class Relation public static function listAll(int $cid, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false) { $condition = DBA::mergeConditions($condition, - ['`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`) - OR `id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`)', + ['(`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`) + OR `id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`))', $cid, $cid] ); return DI::dba()->selectToArray('contact', [], $condition, - ['limit' => [$offset, $count], 'order' => [$shuffle ? 'name' : 'RAND()']] + ['limit' => [$offset, $count], 'order' => [$shuffle ? 'RAND()' : 'name']] ); } @@ -560,7 +560,7 @@ class Relation ); return DI::dba()->selectToArray('contact', [], $condition, - ['limit' => [$offset, $count], 'order' => [$shuffle ? 'name' : 'RAND()']] + ['limit' => [$offset, $count], 'order' => [$shuffle ? 'RAND()' : 'name']] ); } @@ -605,7 +605,7 @@ class Relation ); return DI::dba()->selectToArray('contact', [], $condition, - ['limit' => [$offset, $count], 'order' => [$shuffle ? 'name' : 'RAND()']] + ['limit' => [$offset, $count], 'order' => [$shuffle ? 'RAND()' : 'name']] ); } @@ -650,7 +650,7 @@ class Relation ); return DI::dba()->selectToArray('contact', [], $condition, - ['limit' => [$offset, $count], 'order' => [$shuffle ? 'name' : 'RAND()']] + ['limit' => [$offset, $count], 'order' => [$shuffle ? 'RAND()' : 'name']] ); } } diff --git a/src/Model/User.php b/src/Model/User.php index ee5c35af84..af70c420e6 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -102,6 +102,29 @@ class User private static $owner; + /** + * Returns the numeric account type by their string + * + * @param string $accounttype as string constant + * @return void + */ + public static function getAccountTypeByString(string $accounttype) + { + switch ($accounttype) { + case 'person': + return User::ACCOUNT_TYPE_PERSON; + case 'organisation': + return User::ACCOUNT_TYPE_ORGANISATION; + case 'news': + return User::ACCOUNT_TYPE_NEWS; + case 'community': + return User::ACCOUNT_TYPE_COMMUNITY; + default: + return null; + break; + } + } + /** * Fetch the system account * diff --git a/src/Module/Contact.php b/src/Module/Contact.php index 85b3bb4239..8a7be5c893 100644 --- a/src/Module/Contact.php +++ b/src/Module/Contact.php @@ -37,6 +37,7 @@ use Friendica\Core\Worker; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model; +use Friendica\Model\User; use Friendica\Module\Security\Login; use Friendica\Network\HTTPException\BadRequestException; use Friendica\Network\HTTPException\NotFoundException; @@ -260,6 +261,9 @@ class Contact extends BaseModule $rel = Strings::escapeTags(trim($_GET['rel'] ?? '')); $group = Strings::escapeTags(trim($_GET['group'] ?? '')); + $accounttype = $_GET['accounttype'] ?? ''; + $accounttypeid = User::getAccountTypeByString($accounttype); + $page = DI::page(); $page->registerFooterScript(Theme::getPathForFile('asset/typeahead.js/dist/typeahead.bundle.js')); @@ -339,6 +343,7 @@ class Contact extends BaseModule $findpeople_widget = ''; $follow_widget = ''; + $account_widget = ''; $networks_widget = ''; $rel_widget = ''; @@ -356,12 +361,13 @@ class Contact extends BaseModule $follow_widget = Widget::follow(); } + $account_widget = Widget::accounttypes($_SERVER['REQUEST_URI'], $accounttype); $networks_widget = Widget::networks($_SERVER['REQUEST_URI'], $nets); $rel_widget = Widget::contactRels($_SERVER['REQUEST_URI'], $rel); $groups_widget = Widget::groups($_SERVER['REQUEST_URI'], $group); } - DI::page()['aside'] .= $vcard_widget . $findpeople_widget . $follow_widget . $groups_widget . $networks_widget . $rel_widget; + DI::page()['aside'] .= $vcard_widget . $findpeople_widget . $follow_widget . $account_widget . $groups_widget . $networks_widget . $rel_widget; $tpl = Renderer::getMarkupTemplate('contacts-head.tpl'); DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl, [ @@ -664,6 +670,11 @@ class Contact extends BaseModule break; } + if (isset($accounttypeid)) { + $sql_extra .= " AND `contact-type` = ?"; + $sql_values[] = $accounttypeid; + } + $searching = false; $search_hdr = null; if ($search) { diff --git a/src/Module/Contact/Contacts.php b/src/Module/Contact/Contacts.php index e328b978ce..e38d7acfce 100644 --- a/src/Module/Contact/Contacts.php +++ b/src/Module/Contact/Contacts.php @@ -4,10 +4,11 @@ namespace Friendica\Module\Contact; use Friendica\BaseModule; use Friendica\Content\Pager; +use Friendica\Content\Widget; use Friendica\Core\Renderer; -use Friendica\Core\Session; use Friendica\DI; use Friendica\Model; +use Friendica\Model\User; use Friendica\Module; use Friendica\Network\HTTPException; @@ -23,6 +24,8 @@ class Contacts extends BaseModule $cid = $parameters['id']; $type = $parameters['type'] ?? 'all'; + $accounttype = $_GET['accounttype'] ?? ''; + $accounttypeid = User::getAccountTypeByString($accounttype); if (!$cid) { throw new HTTPException\BadRequestException(DI::l10n()->t('Invalid contact.')); @@ -44,6 +47,10 @@ class Contacts extends BaseModule 'failed' => false, ]; + if (isset($accounttypeid)) { + $condition['contact-type'] = $accounttypeid; + } + $noresult_label = DI::l10n()->t('No known contacts.'); switch ($type) { @@ -57,10 +64,6 @@ class Contacts extends BaseModule $total = Model\Contact\Relation::countMutuals($cid, $condition); break; case 'common': - $condition = [ - 'NOT `self` AND NOT `blocked` AND NOT `hidden` AND `id` != ?', - $localContactId, - ]; $total = Model\Contact\Relation::countCommon($localContactId, $cid, $condition); $noresult_label = DI::l10n()->t('No common contacts.'); break; @@ -119,6 +122,8 @@ class Contacts extends BaseModule '$paginate' => $pager->renderFull($total), ]); + DI::page()['aside'] .= Widget::accounttypes($_SERVER['REQUEST_URI'], $accounttype); + return $o; } } diff --git a/src/Module/Conversation/Community.php b/src/Module/Conversation/Community.php index ae108dd918..f9eeaa6fd9 100644 --- a/src/Module/Conversation/Community.php +++ b/src/Module/Conversation/Community.php @@ -192,23 +192,7 @@ class Community extends BaseModule throw new HTTPException\ForbiddenException(DI::l10n()->t('Access denied.')); } - switch ($parameters['accounttype'] ?? '') { - case 'person': - self::$accounttype = User::ACCOUNT_TYPE_PERSON; - break; - case 'organisation': - self::$accounttype = User::ACCOUNT_TYPE_ORGANISATION; - break; - case 'news': - self::$accounttype = User::ACCOUNT_TYPE_NEWS; - break; - case 'community': - self::$accounttype = User::ACCOUNT_TYPE_COMMUNITY; - break; - default: - self::$accounttype = null; - break; - } + self::$accounttype = User::getAccountTypeByString($parameters['accounttype'] ?? ''); self::$content = $parameters['content'] ?? ''; if (!self::$content) {