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');
91 // We need the editor here to be able to reshare an item.
95 'allow_location' => $a->user['allow_location'],
96 'default_location' => $a->user['default-location'],
97 'nickname' => $a->user['nickname'],
98 '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'),
99 'acl' => populate_acl($a->user, true),
101 'visitor' => 'block',
102 'profile_uid' => local_user(),
104 $o .= status_editor($a, $x, 0, true);
108 if (Config::get('system', 'comment_public')) {
109 // check if we serve a mobile device and get the user settings
112 $itemspage_network = PConfig::get(local_user(), 'system', 'itemspage_mobile_network', 20);
114 $itemspage_network = PConfig::get(local_user(), 'system', 'itemspage_network', 40);
117 // now that we have the user settings, see if the theme forces
118 // a maximum item number which is lower then the user choice
119 if (($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network)) {
120 $itemspage_network = $a->force_max_items;
123 $a->set_pager_itemspage($itemspage_network);
126 $r = community_getitems($a->pager['start'], $a->pager['itemspage'], $content);
128 if (!DBM::is_result($r)) {
129 info(t('No results.') . EOL);
133 $maxpostperauthor = (int) Config::get('system', 'max_author_posts_community_page');
135 if (($maxpostperauthor != 0) && ($content == 'local')) {
137 $previousauthor = "";
142 foreach ($r as $item) {
143 if ($previousauthor == $item["author-link"]) {
148 $previousauthor = $item["author-link"];
150 if (($numposts < $maxpostperauthor) && (count($s) < $a->pager['itemspage'])) {
154 if (count($s) < $a->pager['itemspage']) {
155 $r = community_getitems($a->pager['start'] + ($count * $a->pager['itemspage']), $a->pager['itemspage'], $content);
157 } while ((count($s) < $a->pager['itemspage']) && ( ++$count < 50) && (count($r) > 0));
162 $o .= conversation($a, $s, 'community', $update);
165 $o .= alt_pager($a, count($r));
168 $t = get_markup_template("community.tpl");
169 return replace_macros($t, array(
172 '$show_global_community_hint' => ($content == 'global') && Config::get('system', 'show_global_community_hint'),
173 '$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.")
177 function community_getitems($start, $itemspage, $content)
179 if ($content == 'local') {
180 $r = dba::p("SELECT " . item_fieldlists() . " FROM `thread`
181 INNER JOIN `user` ON `user`.`uid` = `thread`.`uid` AND NOT `user`.`hidewall`
182 INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
183 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
184 AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''" .
185 item_joins() . " AND `contact`.`self`
186 WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
187 AND NOT `thread`.`private` AND `thread`.`wall`
188 ORDER BY `thread`.`received` DESC LIMIT " . intval($start) . ", " . intval($itemspage)
190 return dba::inArray($r);
191 } elseif ($content == 'global') {
192 $r = dba::p("SELECT " . item_fieldlists() . " FROM `thread`
193 INNER JOIN `item` ON `item`.`id` = `thread`.`iid` " . item_joins() .
194 "WHERE `thread`.`uid` = 0 AND `verb` = ?
195 ORDER BY `thread`.`created` DESC LIMIT " . intval($start) . ", " . intval($itemspage),
198 return dba::inArray($r);
201 // Should never happen