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;
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');
33 if ($page_style == CP_NO_INTERNAL_COMMUNITY) {
34 notice(L10n::t('Access denied.') . EOL);
39 $content = $a->argv[1];
41 if (!empty(Config::get('system', 'singleuser'))) {
42 // On single user systems only the global page does make sense
45 // When only the global community is allowed, we use this as default
46 $content = $page_style == CP_GLOBAL_COMMUNITY ? 'global' : 'local';
50 if (!in_array($content, ['local', 'global'])) {
51 notice(L10n::t('Community option not available.') . EOL);
55 // Check if we are allowed to display the content to visitors
57 $available = $page_style == CP_USERS_AND_GLOBAL;
60 $available = ($page_style == CP_USERS_ON_SERVER) && ($content == 'local');
64 $available = ($page_style == CP_GLOBAL_COMMUNITY) && ($content == 'global');
68 notice(L10n::t('Not available.') . EOL);
73 require_once 'include/security.php';
74 require_once 'include/conversation.php';
79 if ((local_user() || in_array($page_style, [CP_USERS_AND_GLOBAL, CP_USERS_ON_SERVER])) && empty(Config::get('system', 'singleuser'))) {
81 'label' => L10n::t('Local Community'),
82 'url' => 'community/local',
83 'sel' => $content == 'local' ? 'active' : '',
84 'title' => L10n::t('Posts from local users on this server'),
85 'id' => 'community-local-tab',
90 if (local_user() || in_array($page_style, [CP_USERS_AND_GLOBAL, CP_GLOBAL_COMMUNITY])) {
92 'label' => L10n::t('Global Community'),
93 'url' => 'community/global',
94 'sel' => $content == 'global' ? 'active' : '',
95 'title' => L10n::t('Posts from users of the whole federated network'),
96 'id' => 'community-global-tab',
101 $tab_tpl = get_markup_template('common_tabs.tpl');
102 $o .= replace_macros($tab_tpl, ['$tabs' => $tabs]);
104 Nav::setSelected('community');
106 // We need the editor here to be able to reshare an item.
110 'allow_location' => $a->user['allow_location'],
111 'default_location' => $a->user['default-location'],
112 'nickname' => $a->user['nickname'],
113 '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'),
114 'acl' => ACL::getFullSelectorHTML($a->user, true),
116 'visitor' => 'block',
117 'profile_uid' => local_user(),
119 $o .= status_editor($a, $x, 0, true);
123 // check if we serve a mobile device and get the user settings accordingly
125 $itemspage_network = PConfig::get(local_user(), 'system', 'itemspage_mobile_network', 20);
127 $itemspage_network = PConfig::get(local_user(), 'system', 'itemspage_network', 40);
130 // now that we have the user settings, see if the theme forces
131 // a maximum item number which is lower then the user choice
132 if (($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network)) {
133 $itemspage_network = $a->force_max_items;
136 $a->set_pager_itemspage($itemspage_network);
138 $r = community_getitems($a->pager['start'], $a->pager['itemspage'], $content);
140 if (!DBA::isResult($r)) {
141 info(L10n::t('No results.') . EOL);
145 $maxpostperauthor = (int) Config::get('system', 'max_author_posts_community_page');
147 if (($maxpostperauthor != 0) && ($content == 'local')) {
149 $previousauthor = "";
154 foreach ($r as $item) {
155 if ($previousauthor == $item["author-link"]) {
160 $previousauthor = $item["author-link"];
162 if (($numposts < $maxpostperauthor) && (count($s) < $a->pager['itemspage'])) {
166 if (count($s) < $a->pager['itemspage']) {
167 $r = community_getitems($a->pager['start'] + ($count * $a->pager['itemspage']), $a->pager['itemspage'], $content);
169 } while ((count($s) < $a->pager['itemspage']) && ( ++$count < 50) && (count($r) > 0));
174 $o .= conversation($a, $s, 'community', $update, false, 'commented', local_user());
177 $o .= alt_pager($a, count($r));
180 $t = get_markup_template("community.tpl");
181 return replace_macros($t, [
184 '$show_global_community_hint' => ($content == 'global') && Config::get('system', 'show_global_community_hint'),
185 '$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.")
189 function community_getitems($start, $itemspage, $content)
191 if ($content == 'local') {
192 $r = DBA::p("SELECT `item`.`uri`, `author`.`url` AS `author-link` FROM `thread`
193 INNER JOIN `user` ON `user`.`uid` = `thread`.`uid` AND NOT `user`.`hidewall`
194 INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
195 INNER JOIN `contact` AS `author` ON `author`.`id`=`item`.`author-id`
196 WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
197 AND NOT `thread`.`private` AND `thread`.`wall` AND `thread`.`origin`
198 ORDER BY `thread`.`commented` DESC LIMIT ?, ?", $start, $itemspage);
199 return DBA::toArray($r);
200 } elseif ($content == 'global') {
201 $r = DBA::p("SELECT `uri` FROM `thread`
202 INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
203 INNER JOIN `contact` AS `author` ON `author`.`id`=`item`.`author-id`
204 WHERE `thread`.`uid` = 0 AND NOT `author`.`hidden` AND NOT `author`.`blocked`
205 ORDER BY `thread`.`commented` DESC LIMIT ?, ?", $start, $itemspage);
206 return DBA::toArray($r);
209 // Should never happen