From 6c3ffb75a6d4e26c0d1d781b783514aeb3b480e4 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 5 Oct 2020 16:48:28 +0000 Subject: [PATCH] Issue 9366: filter account types on the network page --- mod/network.php | 42 ++++++++++++++++++-- src/Content/Widget.php | 21 ++++++++++ src/Module/Conversation/Community.php | 12 +----- static/dbstructure.config.php | 2 +- static/dbview.config.php | 4 ++ view/templates/widget/accounts.tpl | 18 +++++++++ view/templates/widget/community_accounts.tpl | 18 --------- 7 files changed, 84 insertions(+), 33 deletions(-) create mode 100644 view/templates/widget/accounts.tpl delete mode 100644 view/templates/widget/community_accounts.tpl diff --git a/mod/network.php b/mod/network.php index 23e03d03b0..e117ad8c00 100644 --- a/mod/network.php +++ b/mod/network.php @@ -36,6 +36,7 @@ use Friendica\Model\Group; use Friendica\Model\Item; use Friendica\Model\Post\Category; use Friendica\Model\Profile; +use Friendica\Model\User; use Friendica\Module\Contact as ModuleContact; use Friendica\Module\Security\Login; use Friendica\Util\DateTimeFormat; @@ -131,6 +132,13 @@ function network_init(App $a) DI::page()['aside'] = ''; } + if (in_array($a->argv[1], ['person', 'organisation', 'news', 'community'])) { + $accounttype = $a->argv[1]; + } else { + $accounttype = ''; + } + + DI::page()['aside'] .= Widget::accounts('network', $accounttype); DI::page()['aside'] .= Group::sidebarWidget('network/0', 'network', 'standard', $group_id); DI::page()['aside'] .= ForumManager::widget(local_user(), $cid); DI::page()['aside'] .= Widget::postedByYear('network', local_user(), false); @@ -292,10 +300,28 @@ 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; + } + if (!empty($_GET['file'])) { - $o .= networkFlatView($a, $update); + $o .= networkFlatView($a, $update, $account); } else { - $o .= networkThreadedView($a, $update, $parent); + $o .= networkThreadedView($a, $update, $parent, $account); } if (!$update && ($o === '')) { @@ -315,7 +341,7 @@ function network_content(App $a, $update = 0, $parent = 0) * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @global Pager $pager */ -function networkFlatView(App $a, $update = 0) +function networkFlatView(App $a, $update, $account) { global $pager; // Rawmode is used for fetching new content at the end of the page @@ -383,6 +409,10 @@ function networkFlatView(App $a, $update = 0) networkSetSeen(['unseen' => true, 'uid' => local_user()]); } + if (!empty($account)) { + $item_condition['contact-type'] = $account; + } + $result = Item::selectForUser(local_user(), [], $item_condition, $item_params); $items = Item::inArray($result); $o .= networkConversation($a, $items, $pager, 'network-new', $update); @@ -401,7 +431,7 @@ function networkFlatView(App $a, $update = 0) * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @global Pager $pager */ -function networkThreadedView(App $a, $update, $parent) +function networkThreadedView(App $a, $update, $parent, $account) { /// @TODO this will have to be converted to a static property of the converted Module\Network class global $pager; @@ -507,6 +537,10 @@ function networkThreadedView(App $a, $update, $parent) $conditionFields = ['uid' => local_user()]; $conditionStrings = []; + if (!empty($account)) { + $conditionFields['contact-type'] = $account; + } + if ($star) { $conditionFields['starred'] = true; } diff --git a/src/Content/Widget.php b/src/Content/Widget.php index a7ce52cc46..3e5af2251f 100644 --- a/src/Content/Widget.php +++ b/src/Content/Widget.php @@ -525,4 +525,25 @@ class Widget return $o; } + + /** + * Display the accounts sidebar + * + * @param string $base Basepath + * @param string $accounttype Acount type (person, organisation, news, community) + * @return string + */ + public static function accounts(string $base, string $accounttype) + { + return Renderer::replaceMacros(Renderer::getMarkupTemplate('widget/accounts.tpl'), [ + '$title' => DI::l10n()->t('Accounts'), + '$content' => $base, + '$accounttype' => ($accounttype ?? ''), + '$all' => DI::l10n()->t('All'), + '$person' => DI::l10n()->t('Persons'), + '$organisation' => DI::l10n()->t('Organisations'), + '$news' => DI::l10n()->t('News'), + '$community' => DI::l10n()->t('Forums'), + ]); + } } diff --git a/src/Module/Conversation/Community.php b/src/Module/Conversation/Community.php index 88093c83ad..24ee56f6c9 100644 --- a/src/Module/Conversation/Community.php +++ b/src/Module/Conversation/Community.php @@ -27,6 +27,7 @@ use Friendica\Content\BoundariesPager; use Friendica\Content\Feature; use Friendica\Content\Nav; use Friendica\Content\Text\HTML; +use Friendica\Content\Widget; use Friendica\Content\Widget\TrendingTags; use Friendica\Core\ACL; use Friendica\Core\Renderer; @@ -87,16 +88,7 @@ class Community extends BaseModule Nav::setSelected('community'); - DI::page()['aside'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('widget/community_accounts.tpl'), [ - '$title' => DI::l10n()->t('Accounts'), - '$content' => self::$content, - '$accounttype' => ($parameters['accounttype'] ?? ''), - '$all' => DI::l10n()->t('All'), - '$person' => DI::l10n()->t('Persons'), - '$organisation' => DI::l10n()->t('Organisations'), - '$news' => DI::l10n()->t('News'), - '$community' => DI::l10n()->t('Forums'), - ]); + DI::page()['aside'] .= Widget::accounts('community/' . self::$content, $parameters['accounttype'] ?? ''); if (local_user() && DI::config()->get('system', 'community_no_sharer')) { $path = self::$content; diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php index 7e69ec034c..f861332489 100755 --- a/static/dbstructure.config.php +++ b/static/dbstructure.config.php @@ -54,7 +54,7 @@ use Friendica\Database\DBA; if (!defined('DB_UPDATE_VERSION')) { - define('DB_UPDATE_VERSION', 1369); + define('DB_UPDATE_VERSION', 1370); } return [ diff --git a/static/dbview.config.php b/static/dbview.config.php index eb9870e772..ff8600b3da 100755 --- a/static/dbview.config.php +++ b/static/dbview.config.php @@ -83,6 +83,7 @@ return [ "unseen" => ["item", "unseen"], "gravity" => ["item", "gravity"], "contact-id" => ["item", "contact-id"], + "contact-type" => ["ownercontact", "contact-type"], ], "query" => "FROM `item` INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent` @@ -90,6 +91,7 @@ return [ LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = `thread`.`uid` LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `thread`.`uid` AND `author`.`cid` = `thread`.`author-id` LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `thread`.`uid` AND `owner`.`cid` = `thread`.`owner-id` + LEFT JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `thread`.`owner-id` WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated` AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`) AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`) @@ -110,6 +112,7 @@ return [ "mention" => ["thread", "mention"], "network" => ["thread", "network"], "contact-id" => ["thread", "contact-id"], + "contact-type" => ["ownercontact", "contact-type"], ], "query" => "FROM `thread` STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id` @@ -117,6 +120,7 @@ return [ LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = `thread`.`uid` LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `thread`.`uid` AND `author`.`cid` = `thread`.`author-id` LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `thread`.`uid` AND `owner`.`cid` = `thread`.`owner-id` + LEFT JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `thread`.`owner-id` WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated` AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`) AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`) diff --git a/view/templates/widget/accounts.tpl b/view/templates/widget/accounts.tpl new file mode 100644 index 0000000000..84a7fc305e --- /dev/null +++ b/view/templates/widget/accounts.tpl @@ -0,0 +1,18 @@ + +

{{$title}}

+
+ + diff --git a/view/templates/widget/community_accounts.tpl b/view/templates/widget/community_accounts.tpl deleted file mode 100644 index 7af3c88a3b..0000000000 --- a/view/templates/widget/community_accounts.tpl +++ /dev/null @@ -1,18 +0,0 @@ - -

{{$title}}

-
- -