]> git.mxchange.org Git - friendica.git/commitdiff
Issue 9366: filter account types on the network page
authorMichael <heluecht@pirati.ca>
Mon, 5 Oct 2020 16:48:28 +0000 (16:48 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 5 Oct 2020 16:48:28 +0000 (16:48 +0000)
mod/network.php
src/Content/Widget.php
src/Module/Conversation/Community.php
static/dbstructure.config.php
static/dbview.config.php
view/templates/widget/accounts.tpl [new file with mode: 0644]
view/templates/widget/community_accounts.tpl [deleted file]

index 23e03d03b0b724e133359050cdfff3fee13c383b..e117ad8c00f640813bba9cead4a18744262b95aa 100644 (file)
@@ -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;
        }
index a7ce52cc466107f8ecaa1cbf1b9eb7c3ad799d24..3e5af2251f1cfc88db5dbe03b4de9e5edaf3a972 100644 (file)
@@ -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'),
+               ]);     
+       }
 }
index 88093c83ad68c7aa2a53307984483e8bf88dbcef..24ee56f6c93f2d223ef1cf055ced3ebee80c4792 100644 (file)
@@ -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;
index 7e69ec034cf201aef76f3fe0b4aaec47d6ecaffe..f8613324891b2bd101f7ddd8bd63fa096f1eb85e 100755 (executable)
@@ -54,7 +54,7 @@
 use Friendica\Database\DBA;
 
 if (!defined('DB_UPDATE_VERSION')) {
-       define('DB_UPDATE_VERSION', 1369);
+       define('DB_UPDATE_VERSION', 1370);
 }
 
 return [
index eb9870e772f8deccf0d0a222d6123906e2a6255d..ff8600b3da32ac61da6461cf3df4ca77c95398f3 100755 (executable)
@@ -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 (file)
index 0000000..84a7fc3
--- /dev/null
@@ -0,0 +1,18 @@
+<span id="sidebar-accounts-inflated" class="widget fakelink" onclick="openCloseWidget('sidebar-accounts', 'sidebar-accounts-inflated');">
+       <h3>{{$title}}</h3>
+</span>
+<div id="sidebar-accounts" class="widget">
+       <span class="fakelink" onclick="openCloseWidget('sidebar-accounts', 'sidebar-accounts-inflated');">
+               <h3>{{$title}}</h3>
+       </span>
+       <ul class="sidebar-accounts-ul">
+               <li role="menuitem" class="sidebar-accounts-li{{if !$accounttype}} selected{{/if}}"><a href="{{$content}}">{{$all}}</a></li>
+               <li role="menuitem" class="sidebar-accounts-li{{if $accounttype == 'person'}} selected{{/if}}"><a href="{{$content}}/person">{{$person}}</a></li>
+               <li role="menuitem" class="sidebar-accounts-li{{if $accounttype == 'organisation'}} selected{{/if}}"><a href="{{$content}}/organisation">{{$organisation}}</a></li>
+               <li role="menuitem" class="sidebar-accounts-li{{if $accounttype == 'news'}} selected{{/if}}"><a href="{{$content}}/news">{{$news}}</a></li>
+               <li role="menuitem" class="sidebar-accounts-li{{if $accounttype == 'community'}} selected{{/if}}"><a href="{{$content}}/community">{{$community}}</a></li>
+       </ul>
+</div>
+<script>
+initWidget('sidebar-accounts', 'sidebar-accounts-inflated');
+</script>
diff --git a/view/templates/widget/community_accounts.tpl b/view/templates/widget/community_accounts.tpl
deleted file mode 100644 (file)
index 7af3c88..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-<span id="sidebar-community-accounts-inflated" class="widget fakelink" onclick="openCloseWidget('sidebar-community-accounts', 'sidebar-community-accounts-inflated');">
-       <h3>{{$title}}</h3>
-</span>
-<div id="sidebar-community-accounts" class="widget">
-       <span class="fakelink" onclick="openCloseWidget('sidebar-community-accounts', 'sidebar-community-accounts-inflated');">
-               <h3>{{$title}}</h3>
-       </span>
-       <ul class="sidebar-community-accounts-ul">
-               <li role="menuitem" class="sidebar-community-accounts-li{{if !$accounttype}} selected{{/if}}"><a href="community/{{$content}}">{{$all}}</a></li>
-               <li role="menuitem" class="sidebar-community-accounts-li{{if $accounttype == 'person'}} selected{{/if}}"><a href="community/{{$content}}/person">{{$person}}</a></li>
-               <li role="menuitem" class="sidebar-community-accounts-li{{if $accounttype == 'organisation'}} selected{{/if}}"><a href="community/{{$content}}/organisation">{{$organisation}}</a></li>
-               <li role="menuitem" class="sidebar-community-accounts-li{{if $accounttype == 'news'}} selected{{/if}}"><a href="community/{{$content}}/news">{{$news}}</a></li>
-               <li role="menuitem" class="sidebar-community-accounts-li{{if $accounttype == 'community'}} selected{{/if}}"><a href="community/{{$content}}/community">{{$community}}</a></li>
-       </ul>
-</div>
-<script>
-initWidget('sidebar-community-accounts', 'sidebar-community-accounts-inflated');
-</script>