]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Conversation/Community.php
Hide own contacts
[friendica.git] / src / Module / Conversation / Community.php
index ccd9554b8aa4a9051f9bcea2979bc5bccb210ee3..75a8e158ac85652fa32bb14a9aa8aee64ce5811c 100644 (file)
@@ -51,7 +51,7 @@ class Community extends BaseModule
 
                $tabs = [];
 
-               if ((local_user() || in_array(self::$page_style, [CP_USERS_AND_GLOBAL, CP_USERS_ON_SERVER])) && empty(DI::config()->get('system', 'singleuser'))) {
+               if ((Session::isAuthenticated() || in_array(self::$page_style, [CP_USERS_AND_GLOBAL, CP_USERS_ON_SERVER])) && empty(DI::config()->get('system', 'singleuser'))) {
                        $tabs[] = [
                                'label' => DI::l10n()->t('Local Community'),
                                'url' => 'community/local',
@@ -62,7 +62,7 @@ class Community extends BaseModule
                        ];
                }
 
-               if (local_user() || in_array(self::$page_style, [CP_USERS_AND_GLOBAL, CP_GLOBAL_COMMUNITY])) {
+               if (Session::isAuthenticated() || in_array(self::$page_style, [CP_USERS_AND_GLOBAL, CP_GLOBAL_COMMUNITY])) {
                        $tabs[] = [
                                'label' => DI::l10n()->t('Global Community'),
                                'url' => 'community/global',
@@ -81,12 +81,12 @@ class Community extends BaseModule
                $items = self::getItems();
 
                if (!DBA::isResult($items)) {
-                       info(DI::l10n()->t('No results.'));
+                       notice(DI::l10n()->t('No results.'));
                        return $o;
                }
 
                // We need the editor here to be able to reshare an item.
-               if (local_user()) {
+               if (Session::isAuthenticated()) {
                        $x = [
                                'is_owner' => true,
                                'allow_location' => DI::app()->user['allow_location'],
@@ -113,6 +113,40 @@ class Community extends BaseModule
 
                $o .= $pager->renderMinimal(count($items));
 
+               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 Accounts'),
+                       '$person'       => DI::l10n()->t('Personal Accounts'),
+                       '$organisation' => DI::l10n()->t('Organisation Accounts'),
+                       '$news'         => DI::l10n()->t('News Accounts'),
+                       '$community'    => DI::l10n()->t('Communities'),
+               ]);
+
+               if (local_user() && DI::config()->get('system', 'community_no_sharer')) {
+                       $path = self::$content . ($parameters['accounttype'] ? '/' . $parameters['accounttype'] : '');
+                       $query_parameters = [];
+       
+                       if (!empty($_GET['since_id'])) {
+                               $query_parameters['since_id'] = $_GET['since_id'];
+                       }
+                       if (!empty($_GET['max_id'])) {
+                               $query_parameters['max_id'] = $_GET['max_id'];
+                       }
+       
+                       $path_all = $path . (!empty($query_parameters) ? '?' . http_build_query($query_parameters) : '');
+                       $path_no_sharer = $path . '?' . http_build_query(array_merge($query_parameters, ['no_sharer' => true]));
+                       DI::page()['aside'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('widget/community_sharer.tpl'), [
+                               '$title'           => DI::l10n()->t('Own Contacts'),
+                               '$path_all'        => $path_all,
+                               '$path_no_sharer'  => $path_no_sharer,
+                               '$no_sharer'       => !empty($_REQUEST['no_sharer']),
+                               '$all'             => DI::l10n()->t('Include'),
+                               '$no_sharer_label' => DI::l10n()->t('Hide'),
+                       ]);
+               }
+
                if (Feature::isEnabled(local_user(), 'trending_tags')) {
                        DI::page()['aside'] .= TrendingTags::getHTML(self::$content);
                }
@@ -179,7 +213,7 @@ class Community extends BaseModule
                }
 
                // Check if we are allowed to display the content to visitors
-               if (!local_user()) {
+               if (!Session::isAuthenticated()) {
                        $available = self::$page_style == CP_USERS_AND_GLOBAL;
 
                        if (!$available) {
@@ -195,11 +229,12 @@ class Community extends BaseModule
                        }
                }
 
-               // check if we serve a mobile device and get the user settings accordingly
                if (DI::mode()->isMobile()) {
-                       self::$itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network', 20);
+                       self::$itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network',
+                               DI::config()->get('system', 'itemspage_network_mobile'));
                } else {
-                       self::$itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_network', 40);
+                       self::$itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_network',
+                               DI::config()->get('system', 'itemspage_network'));
                }
 
                // now that we have the user settings, see if the theme forces
@@ -272,64 +307,45 @@ class Community extends BaseModule
         * @param $itemspage
         * @return array
         * @throws \Exception
+        * @TODO Move to repository/factory
         */
        private static function selectItems($since_id, $max_id, $itemspage)
        {
                $r = false;
 
                if (self::$content == 'local') {
-                       $values = [];
-
-                       $sql_accounttype = '';
-                       $sql_boundaries = '';
                        if (!is_null(self::$accounttype)) {
-                               $sql_accounttype = " AND `user`.`account-type` = ?";
-                               $values[] = [self::$accounttype];
-                       }
-
-                       if (isset($since_id)) {
-                               $sql_boundaries .= " AND `thread`.`commented` > ?";
-                               $values[] = $since_id;
-                       }
-
-                       if (isset($max_id)) {
-                               $sql_boundaries .= " AND `thread`.`commented` < ?";
-                               $values[] = $max_id;
+                               $condition = ["`wall` AND `origin` AND `private` = ? AND `owner`.`contact-type` = ?", Item::PUBLIC, self::$accounttype];
+                       } else {
+                               $condition = ["`wall` AND `origin` AND `private` = ?", Item::PUBLIC];
                        }
-
-                       $values[] = $itemspage;
-
-                       /// @todo Use "unsearchable" here as well (instead of "hidewall")
-                       $r = DBA::p("SELECT `item`.`uri`, `author`.`url` AS `author-link`, `thread`.`commented` FROM `thread`
-                       STRAIGHT_JOIN `user` ON `user`.`uid` = `thread`.`uid` AND NOT `user`.`hidewall`
-                       STRAIGHT_JOIN `item` ON `item`.`id` = `thread`.`iid`
-                       STRAIGHT_JOIN `contact` AS `author` ON `author`.`id`=`item`.`author-id`
-                       WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
-                       AND NOT `thread`.`private` AND `thread`.`wall` AND `thread`.`origin`
-                       $sql_accounttype
-                       $sql_boundaries
-                       ORDER BY `thread`.`commented` DESC
-                       LIMIT ?", $values);
                } elseif (self::$content == 'global') {
                        if (!is_null(self::$accounttype)) {
-                               $condition = ["`uid` = ? AND NOT `author`.`unsearchable` AND NOT `owner`.`unsearchable` AND `owner`.`contact-type` = ?", 0, self::$accounttype];
+                               $condition = ["`uid` = ? AND `private` = ? AND `owner`.`contact-type` = ?", 0, Item::PUBLIC, self::$accounttype];
                        } else {
-                               $condition = ["`uid` = ? AND NOT `author`.`unsearchable` AND NOT `owner`.`unsearchable`", 0];
+                               $condition = ["`uid` = ? AND `private` = ?", 0, Item::PUBLIC];
                        }
+               } else {
+                       return [];
+               }
 
-                       if (isset($max_id)) {
-                               $condition[0] .= " AND `commented` < ?";
-                               $condition[] = $max_id;
-                       }
+               if (local_user() && !empty($_REQUEST['no_sharer'])) {
+                       $condition[0] .= " AND NOT EXISTS (SELECT `uri-id` FROM `thread` AS t1 WHERE `t1`.`uri-id` = `thread`.`uri-id` AND `t1`.`uid` = ?)";
+                       $condition[] = local_user();
+               }
 
-                       if (isset($since_id)) {
-                               $condition[0] .= " AND `commented` > ?";
-                               $condition[] = $since_id;
-                       }
+               if (isset($max_id)) {
+                       $condition[0] .= " AND `commented` < ?";
+                       $condition[] = $max_id;
+               }
 
-                       $r = Item::selectThreadForUser(0, ['uri', 'commented'], $condition, ['order' => ['commented' => true], 'limit' => $itemspage]);
+               if (isset($since_id)) {
+                       $condition[0] .= " AND `commented` > ?";
+                       $condition[] = $since_id;
                }
 
+               $r = Item::selectThreadForUser(0, ['uri', 'commented', 'author-link'], $condition, ['order' => ['commented' => true], 'limit' => $itemspage]);
+
                return DBA::toArray($r);
        }
 }