3 * @file mod/community.php
6 use Friendica\Content\Nav;
7 use Friendica\Core\Config;
8 use Friendica\Core\PConfig;
9 use Friendica\Database\DBM;
11 function community_init(App $a)
14 unset($_SESSION['theme']);
15 unset($_SESSION['mobile-theme']);
19 function community_content(App $a, $update = 0)
23 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
24 notice(t('Public access denied.') . EOL);
28 $page_style = Config::get('system', 'community_page_style');
31 $content = $a->argv[1];
33 if (!empty(Config::get('system','singleuser'))) {
34 // On single user systems only the global page does make sense
37 // When only the global community is allowed, we use this as default
38 $content = $page_style == CP_GLOBAL_COMMUNITY ? 'global' : 'local';
42 if (!in_array($content, ['local', 'global'])) {
43 notice(t('Community option not available.') . EOL);
47 // Check if we are allowed to display the content to visitors
49 $available = $page_style == CP_USERS_AND_GLOBAL;
52 $available = ($page_style == CP_USERS_ON_SERVER) && ($content == 'local');
56 $available = ($page_style == CP_GLOBAL_COMMUNITY) && ($content == 'global');
60 notice(t('Not available.') . EOL);
65 require_once 'include/bbcode.php';
66 require_once 'include/security.php';
67 require_once 'include/conversation.php';
72 if ((local_user() || in_array($page_style, [CP_USERS_AND_GLOBAL, CP_USERS_ON_SERVER])) && empty(Config::get('system','singleuser'))) {
74 'label' => t('Community'),
75 'url' => 'community/local',
76 'sel' => $content == 'local' ? 'active' : '',
77 'title' => t('Posts from local users on this server'),
78 'id' => 'community-local-tab',
83 if (local_user() || in_array($page_style, [CP_USERS_AND_GLOBAL, CP_GLOBAL_COMMUNITY])) {
85 'label' => t('Global Timeline'),
86 'url' => 'community/global',
87 'sel' => $content == 'global' ? 'active' : '',
88 'title' => t('Posts from users of the federated network'),
89 'id' => 'community-global-tab',
94 $tab_tpl = get_markup_template('common_tabs.tpl');
95 $o .= replace_macros($tab_tpl, ['$tabs' => $tabs]);
97 Nav::setSelected('community');
99 // We need the editor here to be able to reshare an item.
103 'allow_location' => $a->user['allow_location'],
104 'default_location' => $a->user['default-location'],
105 'nickname' => $a->user['nickname'],
106 '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'),
107 'acl' => populate_acl($a->user, true),
109 'visitor' => 'block',
110 'profile_uid' => local_user(),
112 $o .= status_editor($a, $x, 0, true);
116 if (Config::get('system', 'comment_public')) {
117 // check if we serve a mobile device and get the user settings
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);
134 $r = community_getitems($a->pager['start'], $a->pager['itemspage'], $content);
136 if (!DBM::is_result($r)) {
137 info(t('No results.') . EOL);
141 $maxpostperauthor = (int) Config::get('system', 'max_author_posts_community_page');
143 if (($maxpostperauthor != 0) && ($content == 'local')) {
145 $previousauthor = "";
150 foreach ($r as $item) {
151 if ($previousauthor == $item["author-link"]) {
156 $previousauthor = $item["author-link"];
158 if (($numposts < $maxpostperauthor) && (count($s) < $a->pager['itemspage'])) {
162 if (count($s) < $a->pager['itemspage']) {
163 $r = community_getitems($a->pager['start'] + ($count * $a->pager['itemspage']), $a->pager['itemspage'], $content);
165 } while ((count($s) < $a->pager['itemspage']) && ( ++$count < 50) && (count($r) > 0));
170 $o .= conversation($a, $s, 'community', $update);
173 $o .= alt_pager($a, count($r));
176 $t = get_markup_template("community.tpl");
177 return replace_macros($t, [
180 '$show_global_community_hint' => ($content == 'global') && Config::get('system', 'show_global_community_hint'),
181 '$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.")
185 function community_getitems($start, $itemspage, $content)
187 if ($content == 'local') {
188 $r = dba::p("SELECT " . item_fieldlists() . " FROM `thread`
189 INNER JOIN `user` ON `user`.`uid` = `thread`.`uid` AND NOT `user`.`hidewall`
190 INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
191 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
192 AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''" .
193 item_joins() . " AND `contact`.`self`
194 WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
195 AND NOT `thread`.`private` AND `thread`.`wall`
196 ORDER BY `thread`.`commented` DESC LIMIT " . intval($start) . ", " . intval($itemspage)
198 return dba::inArray($r);
199 } elseif ($content == 'global') {
200 $r = dba::p("SELECT " . item_fieldlists() . " FROM `thread`
201 INNER JOIN `item` ON `item`.`id` = `thread`.`iid` " . item_joins() .
202 "WHERE `thread`.`uid` = 0 AND `verb` = ?
203 ORDER BY `thread`.`commented` DESC LIMIT " . intval($start) . ", " . intval($itemspage),
206 return dba::inArray($r);
209 // Should never happen