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 if (!empty(Config::get('system','singleuser'))) {
31 // On single user systems only the global page does make sense
34 // When only the global community is allowed, we use this as default
35 $content = $page_style == CP_GLOBAL_COMMUNITY ? 'global' : 'local';
39 if (!in_array($content, ['local', 'global'])) {
40 notice(t('Community option not available.') . EOL);
44 // Check if we are allowed to display the content to visitors
46 $available = $page_style == CP_USERS_AND_GLOBAL;
49 $available = ($page_style == CP_USERS_ON_SERVER) && ($content == 'local');
53 $available = ($page_style == CP_GLOBAL_COMMUNITY) && ($content == 'global');
57 notice(t('Not available.') . EOL);
62 require_once 'include/bbcode.php';
63 require_once 'include/security.php';
64 require_once 'include/conversation.php';
69 if ((local_user() || in_array($page_style, [CP_USERS_AND_GLOBAL, CP_USERS_ON_SERVER])) && empty(Config::get('system','singleuser'))) {
71 'label' => t('Community'),
72 'url' => 'community/local',
73 'sel' => $content == 'local' ? 'active' : '',
74 'title' => t('Posts from local users on this server'),
75 'id' => 'community-local-tab',
80 if (local_user() || in_array($page_style, [CP_USERS_AND_GLOBAL, CP_GLOBAL_COMMUNITY])) {
82 'label' => t('Global Timeline'),
83 'url' => 'community/global',
84 'sel' => $content == 'global' ? 'active' : '',
85 'title' => t('Posts from users of the federated network'),
86 'id' => 'community-global-tab',
91 $tab_tpl = get_markup_template('common_tabs.tpl');
92 $o .= replace_macros($tab_tpl, array('$tabs' => $tabs));
94 nav_set_selected('community');
96 // We need the editor here to be able to reshare an item.
100 'allow_location' => $a->user['allow_location'],
101 'default_location' => $a->user['default-location'],
102 'nickname' => $a->user['nickname'],
103 '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'),
104 'acl' => populate_acl($a->user, true),
106 'visitor' => 'block',
107 'profile_uid' => local_user(),
109 $o .= status_editor($a, $x, 0, true);
113 if (Config::get('system', 'comment_public')) {
114 // check if we serve a mobile device and get the user settings
117 $itemspage_network = PConfig::get(local_user(), 'system', 'itemspage_mobile_network', 20);
119 $itemspage_network = PConfig::get(local_user(), 'system', 'itemspage_network', 40);
122 // now that we have the user settings, see if the theme forces
123 // a maximum item number which is lower then the user choice
124 if (($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network)) {
125 $itemspage_network = $a->force_max_items;
128 $a->set_pager_itemspage($itemspage_network);
131 $r = community_getitems($a->pager['start'], $a->pager['itemspage'], $content);
133 if (!DBM::is_result($r)) {
134 info(t('No results.') . EOL);
138 $maxpostperauthor = (int) Config::get('system', 'max_author_posts_community_page');
140 if (($maxpostperauthor != 0) && ($content == 'local')) {
142 $previousauthor = "";
147 foreach ($r as $item) {
148 if ($previousauthor == $item["author-link"]) {
153 $previousauthor = $item["author-link"];
155 if (($numposts < $maxpostperauthor) && (count($s) < $a->pager['itemspage'])) {
159 if (count($s) < $a->pager['itemspage']) {
160 $r = community_getitems($a->pager['start'] + ($count * $a->pager['itemspage']), $a->pager['itemspage'], $content);
162 } while ((count($s) < $a->pager['itemspage']) && ( ++$count < 50) && (count($r) > 0));
167 $o .= conversation($a, $s, 'community', $update);
170 $o .= alt_pager($a, count($r));
173 $t = get_markup_template("community.tpl");
174 return replace_macros($t, array(
177 '$show_global_community_hint' => ($content == 'global') && Config::get('system', 'show_global_community_hint'),
178 '$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.")
182 function community_getitems($start, $itemspage, $content)
184 if ($content == 'local') {
185 $r = dba::p("SELECT " . item_fieldlists() . " FROM `thread`
186 INNER JOIN `user` ON `user`.`uid` = `thread`.`uid` AND NOT `user`.`hidewall`
187 INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
188 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
189 AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''" .
190 item_joins() . " AND `contact`.`self`
191 WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
192 AND NOT `thread`.`private` AND `thread`.`wall`
193 ORDER BY `thread`.`received` DESC LIMIT " . intval($start) . ", " . intval($itemspage)
195 return dba::inArray($r);
196 } elseif ($content == 'global') {
197 $r = dba::p("SELECT " . item_fieldlists() . " FROM `thread`
198 INNER JOIN `item` ON `item`.`id` = `thread`.`iid` " . item_joins() .
199 "WHERE `thread`.`uid` = 0 AND `verb` = ?
200 ORDER BY `thread`.`created` DESC LIMIT " . intval($start) . ", " . intval($itemspage),
203 return dba::inArray($r);
206 // Should never happen