3 * @file mod/community.php
7 use Friendica\Content\Nav;
8 use Friendica\Core\ACL;
9 use Friendica\Core\Config;
10 use Friendica\Core\L10n;
11 use Friendica\Core\PConfig;
12 use Friendica\Database\DBM;
14 function community_init(App $a)
17 unset($_SESSION['theme']);
18 unset($_SESSION['mobile-theme']);
22 function community_content(App $a, $update = 0)
26 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
27 notice(L10n::t('Public access denied.') . EOL);
31 $page_style = Config::get('system', 'community_page_style');
34 $content = $a->argv[1];
36 if (!empty(Config::get('system', 'singleuser'))) {
37 // On single user systems only the global page does make sense
40 // When only the global community is allowed, we use this as default
41 $content = $page_style == CP_GLOBAL_COMMUNITY ? 'global' : 'local';
45 if (!in_array($content, ['local', 'global'])) {
46 notice(L10n::t('Community option not available.') . EOL);
50 // Check if we are allowed to display the content to visitors
52 $available = $page_style == CP_USERS_AND_GLOBAL;
55 $available = ($page_style == CP_USERS_ON_SERVER) && ($content == 'local');
59 $available = ($page_style == CP_GLOBAL_COMMUNITY) && ($content == 'global');
63 notice(L10n::t('Not available.') . EOL);
68 require_once 'include/security.php';
69 require_once 'include/conversation.php';
74 if ((local_user() || in_array($page_style, [CP_USERS_AND_GLOBAL, CP_USERS_ON_SERVER])) && empty(Config::get('system', 'singleuser'))) {
76 'label' => L10n::t('Local Community'),
77 'url' => 'community/local',
78 'sel' => $content == 'local' ? 'active' : '',
79 'title' => L10n::t('Posts from local users on this server'),
80 'id' => 'community-local-tab',
85 if (local_user() || in_array($page_style, [CP_USERS_AND_GLOBAL, CP_GLOBAL_COMMUNITY])) {
87 'label' => L10n::t('Global Community'),
88 'url' => 'community/global',
89 'sel' => $content == 'global' ? 'active' : '',
90 'title' => L10n::t('Posts from users of the whole federated network'),
91 'id' => 'community-global-tab',
96 $tab_tpl = get_markup_template('common_tabs.tpl');
97 $o .= replace_macros($tab_tpl, ['$tabs' => $tabs]);
99 Nav::setSelected('community');
101 // We need the editor here to be able to reshare an item.
105 'allow_location' => $a->user['allow_location'],
106 'default_location' => $a->user['default-location'],
107 'nickname' => $a->user['nickname'],
108 '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'),
109 'acl' => ACL::getFullSelectorHTML($a->user, true),
111 'visitor' => 'block',
112 'profile_uid' => local_user(),
114 $o .= status_editor($a, $x, 0, true);
118 // check if we serve a mobile device and get the user settings accordingly
120 $itemspage_network = PConfig::get(local_user(), 'system', 'itemspage_mobile_network', 20);
122 $itemspage_network = PConfig::get(local_user(), 'system', 'itemspage_network', 40);
125 // now that we have the user settings, see if the theme forces
126 // a maximum item number which is lower then the user choice
127 if (($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network)) {
128 $itemspage_network = $a->force_max_items;
131 $a->set_pager_itemspage($itemspage_network);
133 $r = community_getitems($a->pager['start'], $a->pager['itemspage'], $content);
135 if (!DBM::is_result($r)) {
136 info(L10n::t('No results.') . EOL);
140 $maxpostperauthor = (int) Config::get('system', 'max_author_posts_community_page');
142 if (($maxpostperauthor != 0) && ($content == 'local')) {
144 $previousauthor = "";
149 foreach ($r as $item) {
150 if ($previousauthor == $item["author-link"]) {
155 $previousauthor = $item["author-link"];
157 if (($numposts < $maxpostperauthor) && (count($s) < $a->pager['itemspage'])) {
161 if (count($s) < $a->pager['itemspage']) {
162 $r = community_getitems($a->pager['start'] + ($count * $a->pager['itemspage']), $a->pager['itemspage'], $content);
164 } while ((count($s) < $a->pager['itemspage']) && ( ++$count < 50) && (count($r) > 0));
169 $o .= conversation($a, $s, 'community', $update);
172 $o .= alt_pager($a, count($r));
175 $t = get_markup_template("community.tpl");
176 return replace_macros($t, [
179 '$show_global_community_hint' => ($content == 'global') && Config::get('system', 'show_global_community_hint'),
180 '$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.")
184 function community_getitems($start, $itemspage, $content)
186 if ($content == 'local') {
187 $r = dba::p("SELECT `item`.`uri`, `item`.`author-link` FROM `thread`
188 INNER JOIN `user` ON `user`.`uid` = `thread`.`uid` AND NOT `user`.`hidewall`
189 INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
190 WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
191 AND NOT `thread`.`private` AND `thread`.`wall` AND `thread`.`origin`
192 ORDER BY `thread`.`commented` DESC LIMIT " . intval($start) . ", " . intval($itemspage)
194 return dba::inArray($r);
195 } elseif ($content == 'global') {
196 $r = dba::p("SELECT `uri` FROM `thread`
197 INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
198 INNER JOIN `contact` AS `author` ON `author`.`id`=`item`.`author-id`
199 WHERE `thread`.`uid` = 0 AND NOT `author`.`hidden` AND NOT `author`.`blocked`
200 ORDER BY `thread`.`commented` DESC LIMIT " . intval($start) . ", " . intval($itemspage));
201 return dba::inArray($r);
204 // Should never happen