4 use Friendica\Core\Config;
5 use Friendica\Core\PConfig;
6 use Friendica\Database\DBM;
8 function community_init(App $a) {
10 unset($_SESSION['theme']);
11 unset($_SESSION['mobile-theme']);
15 function community_content(App $a, $update = 0) {
18 if (Config::get('system','block_public') && !local_user() && !remote_user()) {
19 notice(t('Public access denied.') . EOL);
23 $page_style = Config::get('system','community_page_style');
26 $content = $a->argv[1];
28 // When only the global community is allowed, we use this as default
29 $content = $page_style == CP_GLOBAL_COMMUNITY ? 'global' : 'local';
32 if (!in_array($content, ['local', 'global'])) {
33 notice(t('Community option not available.') . EOL);
37 // Check if we are allowed to display the content to visitors
39 $available = $page_style == CP_USERS_AND_GLOBAL;
42 $available = ($page_style == CP_USERS_ON_SERVER) && ($content == 'local');
46 $available = ($page_style == CP_GLOBAL_COMMUNITY) && ($content == 'global');
50 notice(t('Not available.') . EOL);
55 require_once 'include/bbcode.php';
56 require_once 'include/security.php';
57 require_once 'include/conversation.php';
62 if (local_user() || in_array($page_style, [CP_USERS_AND_GLOBAL, CP_USERS_ON_SERVER])) {
63 $tabs[] = array('label'=>t('Community'),
64 'url' => 'community/local',
65 'sel' => $content == 'local' ? 'active' : '',
66 'title' => t('Posts from local users on this server'),
67 'id' => 'community-local-tab',
71 if (local_user() || in_array($page_style, [CP_USERS_AND_GLOBAL, CP_GLOBAL_COMMUNITY])) {
72 $tabs[] = array('label' => t('Global Timeline'),
73 'url' => 'community/global',
74 'sel' => $content == 'global' ? 'active' : '',
75 'title' => t('Posts from users of the federated network'),
76 'id' => 'community-global-tab',
80 $tab_tpl = get_markup_template('common_tabs.tpl');
81 $o .= replace_macros($tab_tpl, array('$tabs' => $tabs));
83 nav_set_selected('community');
86 if (Config::get('system', 'comment_public')) {
87 // check if we serve a mobile device and get the user settings
90 $itemspage_network = PConfig::get(local_user(),'system','itemspage_mobile_network', 20);
92 $itemspage_network = PConfig::get(local_user(),'system','itemspage_network', 40);
95 // now that we have the user settings, see if the theme forces
96 // a maximum item number which is lower then the user choice
97 if (($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network)) {
98 $itemspage_network = $a->force_max_items;
101 $a->set_pager_itemspage($itemspage_network);
104 $r = community_getitems($a->pager['start'], $a->pager['itemspage'], $content);
106 if (!DBM::is_result($r)) {
107 info(t('No results.') . EOL);
111 $maxpostperauthor = Config::get('system','max_author_posts_community_page');
113 if (($maxpostperauthor != 0) && ($content == 'local')) {
115 $previousauthor = "";
120 foreach ($r AS $row=>$item) {
121 if ($previousauthor == $item["author-link"]) {
126 $previousauthor = $item["author-link"];
128 if (($numposts < $maxpostperauthor) && (sizeof($s) < $a->pager['itemspage'])) {
132 if (sizeof($s) < $a->pager['itemspage']) {
133 $r = community_getitems($a->pager['start'] + ($count * $a->pager['itemspage']), $a->pager['itemspage'], $content);
135 } while ((sizeof($s) < $a->pager['itemspage']) && (++$count < 50) && (sizeof($r) > 0));
140 $o .= conversation($a, $s, 'community', $update);
143 $o .= alt_pager($a, count($r));
146 $t = get_markup_template("community.tpl");
147 return replace_macros($t, array(
150 '$show_global_community_hint' => ($content == 'global') && Config::get('system', 'show_global_community_hint'),
151 '$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.")
155 function community_getitems($start, $itemspage, $content) {
156 if ($content == 'local') {
157 $r = dba::p("SELECT ".item_fieldlists()." FROM `thread`
158 INNER JOIN `user` ON `user`.`uid` = `thread`.`uid` AND NOT `user`.`hidewall`
159 INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
160 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
161 AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''".
162 item_joins()." AND `contact`.`self`
163 WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
164 AND NOT `thread`.`private` AND `thread`.`wall`
165 ORDER BY `thread`.`received` DESC LIMIT ".intval($start).", ".intval($itemspage)
167 return dba::inArray($r);
168 } elseif ($content == 'global') {
169 $r = dba::p("SELECT ".item_fieldlists()." FROM `thread`
170 INNER JOIN `item` ON `item`.`id` = `thread`.`iid` ".item_joins().
171 "WHERE `thread`.`uid` = 0 AND `verb` = ?
172 ORDER BY `thread`.`created` DESC LIMIT ".intval($start).", ".intval($itemspage),
175 return dba::inArray($r);
178 // Should never happen