4 use Friendica\Core\Config;
5 use Friendica\Core\PConfig;
6 use Friendica\Database\DBM;
8 function community_init(App $a)
11 unset($_SESSION['theme']);
12 unset($_SESSION['mobile-theme']);
16 function community_content(App $a, $update = 0)
20 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
21 notice(t('Public access denied.') . EOL);
25 $page_style = Config::get('system', 'community_page_style');
28 $content = $a->argv[1];
30 // When only the global community is allowed, we use this as default
31 $content = $page_style == CP_GLOBAL_COMMUNITY ? 'global' : 'local';
34 if (!in_array($content, ['local', 'global'])) {
35 notice(t('Community option not available.') . EOL);
39 // Check if we are allowed to display the content to visitors
41 $available = $page_style == CP_USERS_AND_GLOBAL;
44 $available = ($page_style == CP_USERS_ON_SERVER) && ($content == 'local');
48 $available = ($page_style == CP_GLOBAL_COMMUNITY) && ($content == 'global');
52 notice(t('Not available.') . EOL);
57 require_once 'include/bbcode.php';
58 require_once 'include/security.php';
59 require_once 'include/conversation.php';
64 if (local_user() || in_array($page_style, [CP_USERS_AND_GLOBAL, CP_USERS_ON_SERVER])) {
66 'label' => t('Community'),
67 'url' => 'community/local',
68 'sel' => $content == 'local' ? 'active' : '',
69 'title' => t('Posts from local users on this server'),
70 'id' => 'community-local-tab',
75 if (local_user() || in_array($page_style, [CP_USERS_AND_GLOBAL, CP_GLOBAL_COMMUNITY])) {
77 'label' => t('Global Timeline'),
78 'url' => 'community/global',
79 'sel' => $content == 'global' ? 'active' : '',
80 'title' => t('Posts from users of the federated network'),
81 'id' => 'community-global-tab',
86 $tab_tpl = get_markup_template('common_tabs.tpl');
87 $o .= replace_macros($tab_tpl, array('$tabs' => $tabs));
89 nav_set_selected('community');
92 if (Config::get('system', 'comment_public')) {
93 // check if we serve a mobile device and get the user settings
96 $itemspage_network = PConfig::get(local_user(), 'system', 'itemspage_mobile_network', 20);
98 $itemspage_network = PConfig::get(local_user(), 'system', 'itemspage_network', 40);
101 // now that we have the user settings, see if the theme forces
102 // a maximum item number which is lower then the user choice
103 if (($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network)) {
104 $itemspage_network = $a->force_max_items;
107 $a->set_pager_itemspage($itemspage_network);
110 $r = community_getitems($a->pager['start'], $a->pager['itemspage'], $content);
112 if (!DBM::is_result($r)) {
113 info(t('No results.') . EOL);
117 $maxpostperauthor = (int) Config::get('system', 'max_author_posts_community_page');
119 if (($maxpostperauthor != 0) && ($content == 'local')) {
121 $previousauthor = "";
126 foreach ($r as $item) {
127 if ($previousauthor == $item["author-link"]) {
132 $previousauthor = $item["author-link"];
134 if (($numposts < $maxpostperauthor) && (count($s) < $a->pager['itemspage'])) {
138 if (count($s) < $a->pager['itemspage']) {
139 $r = community_getitems($a->pager['start'] + ($count * $a->pager['itemspage']), $a->pager['itemspage'], $content);
141 } while ((count($s) < $a->pager['itemspage']) && ( ++$count < 50) && (count($r) > 0));
146 $o .= conversation($a, $s, 'community', $update);
149 $o .= alt_pager($a, count($r));
152 $t = get_markup_template("community.tpl");
153 return replace_macros($t, array(
156 '$show_global_community_hint' => ($content == 'global') && Config::get('system', 'show_global_community_hint'),
157 '$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.")
161 function community_getitems($start, $itemspage, $content)
163 if ($content == 'local') {
164 $r = dba::p("SELECT " . item_fieldlists() . " FROM `thread`
165 INNER JOIN `user` ON `user`.`uid` = `thread`.`uid` AND NOT `user`.`hidewall`
166 INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
167 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
168 AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''" .
169 item_joins() . " AND `contact`.`self`
170 WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
171 AND NOT `thread`.`private` AND `thread`.`wall`
172 ORDER BY `thread`.`received` DESC LIMIT " . intval($start) . ", " . intval($itemspage)
174 return dba::inArray($r);
175 } elseif ($content == 'global') {
176 $r = dba::p("SELECT " . item_fieldlists() . " FROM `thread`
177 INNER JOIN `item` ON `item`.`id` = `thread`.`iid` " . item_joins() .
178 "WHERE `thread`.`uid` = 0 AND `verb` = ?
179 ORDER BY `thread`.`created` DESC LIMIT " . intval($start) . ", " . intval($itemspage),
182 return dba::inArray($r);
185 // Should never happen