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\DBA;
13 use Friendica\Database\DBM;
15 function community_init(App $a)
18 unset($_SESSION['theme']);
19 unset($_SESSION['mobile-theme']);
23 function community_content(App $a, $update = 0)
27 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
28 notice(L10n::t('Public access denied.') . EOL);
32 $page_style = Config::get('system', 'community_page_style');
34 if ($page_style == CP_NO_INTERNAL_COMMUNITY) {
35 notice(L10n::t('Access denied.') . EOL);
40 $content = $a->argv[1];
42 if (!empty(Config::get('system', 'singleuser'))) {
43 // On single user systems only the global page does make sense
46 // When only the global community is allowed, we use this as default
47 $content = $page_style == CP_GLOBAL_COMMUNITY ? 'global' : 'local';
51 if (!in_array($content, ['local', 'global'])) {
52 notice(L10n::t('Community option not available.') . EOL);
56 // Check if we are allowed to display the content to visitors
58 $available = $page_style == CP_USERS_AND_GLOBAL;
61 $available = ($page_style == CP_USERS_ON_SERVER) && ($content == 'local');
65 $available = ($page_style == CP_GLOBAL_COMMUNITY) && ($content == 'global');
69 notice(L10n::t('Not available.') . EOL);
74 require_once 'include/security.php';
75 require_once 'include/conversation.php';
80 if ((local_user() || in_array($page_style, [CP_USERS_AND_GLOBAL, CP_USERS_ON_SERVER])) && empty(Config::get('system', 'singleuser'))) {
82 'label' => L10n::t('Local Community'),
83 'url' => 'community/local',
84 'sel' => $content == 'local' ? 'active' : '',
85 'title' => L10n::t('Posts from local users on this server'),
86 'id' => 'community-local-tab',
91 if (local_user() || in_array($page_style, [CP_USERS_AND_GLOBAL, CP_GLOBAL_COMMUNITY])) {
93 'label' => L10n::t('Global Community'),
94 'url' => 'community/global',
95 'sel' => $content == 'global' ? 'active' : '',
96 'title' => L10n::t('Posts from users of the whole federated network'),
97 'id' => 'community-global-tab',
102 $tab_tpl = get_markup_template('common_tabs.tpl');
103 $o .= replace_macros($tab_tpl, ['$tabs' => $tabs]);
105 Nav::setSelected('community');
107 // We need the editor here to be able to reshare an item.
111 'allow_location' => $a->user['allow_location'],
112 'default_location' => $a->user['default-location'],
113 'nickname' => $a->user['nickname'],
114 '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'),
115 'acl' => ACL::getFullSelectorHTML($a->user, true),
117 'visitor' => 'block',
118 'profile_uid' => local_user(),
120 $o .= status_editor($a, $x, 0, true);
124 // check if we serve a mobile device and get the user settings accordingly
126 $itemspage_network = PConfig::get(local_user(), 'system', 'itemspage_mobile_network', 20);
128 $itemspage_network = PConfig::get(local_user(), 'system', 'itemspage_network', 40);
131 // now that we have the user settings, see if the theme forces
132 // a maximum item number which is lower then the user choice
133 if (($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network)) {
134 $itemspage_network = $a->force_max_items;
137 $a->set_pager_itemspage($itemspage_network);
139 $r = community_getitems($a->pager['start'], $a->pager['itemspage'], $content);
141 if (!DBM::is_result($r)) {
142 info(L10n::t('No results.') . EOL);
146 $maxpostperauthor = (int) Config::get('system', 'max_author_posts_community_page');
148 if (($maxpostperauthor != 0) && ($content == 'local')) {
150 $previousauthor = "";
155 foreach ($r as $item) {
156 if ($previousauthor == $item["author-link"]) {
161 $previousauthor = $item["author-link"];
163 if (($numposts < $maxpostperauthor) && (count($s) < $a->pager['itemspage'])) {
167 if (count($s) < $a->pager['itemspage']) {
168 $r = community_getitems($a->pager['start'] + ($count * $a->pager['itemspage']), $a->pager['itemspage'], $content);
170 } while ((count($s) < $a->pager['itemspage']) && ( ++$count < 50) && (count($r) > 0));
175 $o .= conversation($a, $s, 'community', $update, false, 'commented', local_user());
178 $o .= alt_pager($a, count($r));
181 $t = get_markup_template("community.tpl");
182 return replace_macros($t, [
185 '$show_global_community_hint' => ($content == 'global') && Config::get('system', 'show_global_community_hint'),
186 '$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.")
190 function community_getitems($start, $itemspage, $content)
192 if ($content == 'local') {
193 $r = DBA::p("SELECT `item`.`uri`, `author`.`url` AS `author-link` FROM `thread`
194 INNER JOIN `user` ON `user`.`uid` = `thread`.`uid` AND NOT `user`.`hidewall`
195 INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
196 INNER JOIN `contact` AS `author` ON `author`.`id`=`item`.`author-id`
197 WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
198 AND NOT `thread`.`private` AND `thread`.`wall` AND `thread`.`origin`
199 ORDER BY `thread`.`commented` DESC LIMIT " . intval($start) . ", " . intval($itemspage)
201 return DBA::toArray($r);
202 } elseif ($content == 'global') {
203 $r = DBA::p("SELECT `uri` FROM `thread`
204 INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
205 INNER JOIN `contact` AS `author` ON `author`.`id`=`item`.`author-id`
206 WHERE `thread`.`uid` = 0 AND NOT `author`.`hidden` AND NOT `author`.`blocked`
207 ORDER BY `thread`.`commented` DESC LIMIT " . intval($start) . ", " . intval($itemspage));
208 return DBA::toArray($r);
211 // Should never happen