3 * @file mod/community.php
6 use Friendica\Content\Nav;
7 use Friendica\Core\Config;
8 use Friendica\Core\L10n;
9 use Friendica\Core\PConfig;
10 use Friendica\Database\DBM;
12 function community_init(App $a)
15 unset($_SESSION['theme']);
16 unset($_SESSION['mobile-theme']);
20 function community_content(App $a, $update = 0)
24 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
25 notice(L10n::t('Public access denied.') . EOL);
29 $page_style = Config::get('system', 'community_page_style');
32 $content = $a->argv[1];
34 if (!empty(Config::get('system', 'singleuser'))) {
35 // On single user systems only the global page does make sense
38 // When only the global community is allowed, we use this as default
39 $content = $page_style == CP_GLOBAL_COMMUNITY ? 'global' : 'local';
43 if (!in_array($content, ['local', 'global'])) {
44 notice(L10n::t('Community option not available.') . EOL);
48 // Check if we are allowed to display the content to visitors
50 $available = $page_style == CP_USERS_AND_GLOBAL;
53 $available = ($page_style == CP_USERS_ON_SERVER) && ($content == 'local');
57 $available = ($page_style == CP_GLOBAL_COMMUNITY) && ($content == 'global');
61 notice(L10n::t('Not available.') . EOL);
66 require_once 'include/bbcode.php';
67 require_once 'include/security.php';
68 require_once 'include/conversation.php';
73 if ((local_user() || in_array($page_style, [CP_USERS_AND_GLOBAL, CP_USERS_ON_SERVER])) && empty(Config::get('system', 'singleuser'))) {
75 'label' => L10n::t('Local Community'),
76 'url' => 'community/local',
77 'sel' => $content == 'local' ? 'active' : '',
78 'title' => L10n::t('Posts from local users on this server'),
79 'id' => 'community-local-tab',
84 if (local_user() || in_array($page_style, [CP_USERS_AND_GLOBAL, CP_GLOBAL_COMMUNITY])) {
86 'label' => L10n::t('Global Community'),
87 'url' => 'community/global',
88 'sel' => $content == 'global' ? 'active' : '',
89 'title' => L10n::t('Posts from users of the whole federated network'),
90 'id' => 'community-global-tab',
95 $tab_tpl = get_markup_template('common_tabs.tpl');
96 $o .= replace_macros($tab_tpl, ['$tabs' => $tabs]);
98 Nav::setSelected('community');
100 // We need the editor here to be able to reshare an item.
104 'allow_location' => $a->user['allow_location'],
105 'default_location' => $a->user['default-location'],
106 'nickname' => $a->user['nickname'],
107 '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'),
108 'acl' => populate_acl($a->user, true),
110 'visitor' => 'block',
111 'profile_uid' => local_user(),
113 $o .= status_editor($a, $x, 0, true);
117 // check if we serve a mobile device and get the user settings accordingly
119 $itemspage_network = PConfig::get(local_user(), 'system', 'itemspage_mobile_network', 20);
121 $itemspage_network = PConfig::get(local_user(), 'system', 'itemspage_network', 40);
124 // now that we have the user settings, see if the theme forces
125 // a maximum item number which is lower then the user choice
126 if (($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network)) {
127 $itemspage_network = $a->force_max_items;
130 $a->set_pager_itemspage($itemspage_network);
132 $r = community_getitems($a->pager['start'], $a->pager['itemspage'], $content);
134 if (!DBM::is_result($r)) {
135 info(L10n::t('No results.') . EOL);
139 $maxpostperauthor = (int) Config::get('system', 'max_author_posts_community_page');
141 if (($maxpostperauthor != 0) && ($content == 'local')) {
143 $previousauthor = "";
148 foreach ($r as $item) {
149 if ($previousauthor == $item["author-link"]) {
154 $previousauthor = $item["author-link"];
156 if (($numposts < $maxpostperauthor) && (count($s) < $a->pager['itemspage'])) {
160 if (count($s) < $a->pager['itemspage']) {
161 $r = community_getitems($a->pager['start'] + ($count * $a->pager['itemspage']), $a->pager['itemspage'], $content);
163 } while ((count($s) < $a->pager['itemspage']) && ( ++$count < 50) && (count($r) > 0));
168 $o .= conversation($a, $s, 'community', $update);
171 $o .= alt_pager($a, count($r));
174 $t = get_markup_template("community.tpl");
175 return replace_macros($t, [
178 '$show_global_community_hint' => ($content == 'global') && Config::get('system', 'show_global_community_hint'),
179 '$global_community_hint' => L10n::t("This community stream shows all public posts received by this node. They may not reflect the opinions of this node’s users.")
183 function community_getitems($start, $itemspage, $content)
185 if ($content == 'local') {
186 $r = dba::p("SELECT `item`.`uri`, `item`.`author-link` FROM `thread`
187 INNER JOIN `user` ON `user`.`uid` = `thread`.`uid` AND NOT `user`.`hidewall`
188 INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
189 WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
190 AND NOT `thread`.`private` AND `thread`.`wall` AND `thread`.`origin`
191 ORDER BY `thread`.`commented` DESC LIMIT " . intval($start) . ", " . intval($itemspage)
193 return dba::inArray($r);
194 } elseif ($content == 'global') {
195 $r = dba::p("SELECT `uri` FROM `thread`
196 INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
197 WHERE `thread`.`uid` = 0
198 ORDER BY `thread`.`commented` DESC LIMIT " . intval($start) . ", " . intval($itemspage));
199 return dba::inArray($r);
202 // Should never happen