]> git.mxchange.org Git - friendica.git/blobdiff - mod/community.php
Merge pull request #4243 from MrPetovan/task/switch-to-array-new-style
[friendica.git] / mod / community.php
index 1f5f848cc0641fc706c896ca9d3c655695379abf..cfd2087d9762a804bad85d90b3d63956e77c5755 100644 (file)
@@ -27,8 +27,13 @@ function community_content(App $a, $update = 0)
        if ($a->argc > 1) {
                $content = $a->argv[1];
        } else {
-               // When only the global community is allowed, we use this as default
-               $content = $page_style == CP_GLOBAL_COMMUNITY ? 'global' : 'local';
+               if (!empty(Config::get('system','singleuser'))) {
+                       // On single user systems only the global page does make sense
+                       $content = 'global';
+               } else {
+                       // When only the global community is allowed, we use this as default
+                       $content = $page_style == CP_GLOBAL_COMMUNITY ? 'global' : 'local';
+               }
        }
 
        if (!in_array($content, ['local', 'global'])) {
@@ -61,32 +66,48 @@ function community_content(App $a, $update = 0)
        if (!$update) {
                $tabs = [];
 
-               if (local_user() || in_array($page_style, [CP_USERS_AND_GLOBAL, CP_USERS_ON_SERVER])) {
-                       $tabs[] = array(
+               if ((local_user() || in_array($page_style, [CP_USERS_AND_GLOBAL, CP_USERS_ON_SERVER])) && empty(Config::get('system','singleuser'))) {
+                       $tabs[] = [
                                'label' => t('Community'),
                                'url' => 'community/local',
                                'sel' => $content == 'local' ? 'active' : '',
                                'title' => t('Posts from local users on this server'),
                                'id' => 'community-local-tab',
                                'accesskey' => 'l'
-                       );
+                       ];
                }
 
                if (local_user() || in_array($page_style, [CP_USERS_AND_GLOBAL, CP_GLOBAL_COMMUNITY])) {
-                       $tabs[] = array(
+                       $tabs[] = [
                                'label' => t('Global Timeline'),
                                'url' => 'community/global',
                                'sel' => $content == 'global' ? 'active' : '',
                                'title' => t('Posts from users of the federated network'),
                                'id' => 'community-global-tab',
                                'accesskey' => 'g'
-                       );
+                       ];
                }
 
                $tab_tpl = get_markup_template('common_tabs.tpl');
-               $o .= replace_macros($tab_tpl, array('$tabs' => $tabs));
+               $o .= replace_macros($tab_tpl, ['$tabs' => $tabs]);
 
                nav_set_selected('community');
+
+               // We need the editor here to be able to reshare an item.
+               if (local_user()) {
+                       $x = [
+                               'is_owner' => true,
+                               'allow_location' => $a->user['allow_location'],
+                               'default_location' => $a->user['default-location'],
+                               'nickname' => $a->user['nickname'],
+                               'lockstate' => (is_array($a->user) && (strlen($a->user['allow_cid']) || strlen($a->user['allow_gid']) || strlen($a->user['deny_cid']) || strlen($a->user['deny_gid'])) ? 'lock' : 'unlock'),
+                               'acl' => populate_acl($a->user, true),
+                               'bang' => '',
+                               'visitor' => 'block',
+                               'profile_uid' => local_user(),
+                       ];
+                       $o .= status_editor($a, $x, 0, true);
+               }
        }
 
        if (Config::get('system', 'comment_public')) {
@@ -120,7 +141,7 @@ function community_content(App $a, $update = 0)
                $count = 1;
                $previousauthor = "";
                $numposts = 0;
-               $s = array();
+               $s = [];
 
                do {
                        foreach ($r as $item) {
@@ -150,12 +171,12 @@ function community_content(App $a, $update = 0)
        }
 
        $t = get_markup_template("community.tpl");
-       return replace_macros($t, array(
+       return replace_macros($t, [
                '$content' => $o,
                '$header' => '',
                '$show_global_community_hint' => ($content == 'global') && Config::get('system', 'show_global_community_hint'),
                '$global_community_hint' => t("This community stream shows all public posts received by this node. They may not reflect the opinions of this node’s users.")
-       ));
+       ]);
 }
 
 function community_getitems($start, $itemspage, $content)
@@ -169,19 +190,19 @@ function community_getitems($start, $itemspage, $content)
                        item_joins() . " AND `contact`.`self`
                        WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
                        AND NOT `thread`.`private` AND `thread`.`wall`
-                       ORDER BY `thread`.`received` DESC LIMIT " . intval($start) . ", " . intval($itemspage)
+                       ORDER BY `thread`.`commented` DESC LIMIT " . intval($start) . ", " . intval($itemspage)
                );
                return dba::inArray($r);
        } elseif ($content == 'global') {
                $r = dba::p("SELECT " . item_fieldlists() . " FROM `thread`
                        INNER JOIN `item` ON `item`.`id` = `thread`.`iid` " . item_joins() .
                                "WHERE `thread`.`uid` = 0 AND `verb` = ?
-                       ORDER BY `thread`.`created` DESC LIMIT " . intval($start) . ", " . intval($itemspage),
+                       ORDER BY `thread`.`commented` DESC LIMIT " . intval($start) . ", " . intval($itemspage),
                        ACTIVITY_POST
                );
                return dba::inArray($r);
        }
 
        // Should never happen
-       return array();
+       return [];
 }